2015-01-09 83 views
1

我試圖在iOS的核心音頻中部分文件緩衝區,爲了做到這一點,我需要更改開始我傳遞給memcpy的地址。我的代碼看起來像這樣...無法初始化類型爲'void *'的類型爲'void * const *'的變量

UInt32 bytesToRead = inBuffer->mAudioDataBytesCapacity; 
int srcOffset = 0; 
while (bytesToRead > 0) { 
    UInt32 maxBytesFromCurrentPiece = self.currentAudioPiece.audioData.length - self.currentAudioPieceIndex; 
    //Take the min of what the current piece can provide OR what is needed to be read 
    UInt32 bytesToReadNow = MIN(maxBytesFromCurrentPiece, bytesToRead); 

    NSData *subRange = [self.currentAudioPiece.audioData subdataWithRange:NSMakeRange(self.currentAudioPieceIndex, bytesToReadNow)]; 
    //Copy what you can before continuing loop 

    void *srcStart = (&inBuffer->mAudioData + srcOffset); 
    memcpy(srcStart, subRange.bytes, subRange.length); 
    srcOffset += subRange.length; 
    bytesToRead -= bytesToReadNow; 

Appcode顯示沒有錯誤,但編譯器顯示了這個:

「語義問題」 - 無法 右值初始化類型「無效*」的變量類型'void * const *'

在「* srcStart」的行上。

+0

這條語句中的方括號是什麼NSData * subRange = [self ... mean? –

+0

這是一個Objective-C消息發送表達式,@Vlad。大部分''也是。 –

+0

你爲什麼要在該行上的'inBuffer'上輸入地址? –

回答

2

嘗試改變

void *srcStart = (&inBuffer->mAudioData + srcOffset); 

char *srcStart = ((char *)inBuffer->mAudioData) + srcOffset; 

這將跳過字節的適當數量。

相關問題