无法使用'void * const *'类型的右值初始化'void *'类型的变量

时间:2015-01-09 05:18:02

标签: objective-c c core-audio pointer-arithmetic

我试图在iOS的核心音频中部分提交缓冲区,为了做到这一点,我需要更改传递给memcpy的起始地址。我的代码看起来像这样......

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 *'同   类型' void * const *'

的右值

与" * srcStart"。

一致

1 个答案:

答案 0 :(得分:2)

尝试更改

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

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

这将跳过适当的字节数。