1

我正在开发一个与 DSP 相关的 iOS 应用程序。部分工作是将音频数据从 outBuffer ->mAudioData 复制到用户指定的数组中进行数据处理。读取方法是这样的:

OSStatus result = AudioFileReadPackets(myInfo->mAudioFile,      // The audio file from which packets of audio data are to be read.
                                       false,                   // Set to true to cache the data. Otherwise, set to false.
                                       &numBytes,               // On output, a pointer to the number of bytes actually returned.
                                       myInfo->mPacketDescs,    // A pointer to an array of packet descriptions that have been allocated.
                                       myInfo->mCurrentPacket,  // The packet index of the first packet you want to be returned.
                                       &nPackets,               // On input, a pointer to the number of packets to read. On output, the number of packets actually read.                                           
                                       outBuffer->mAudioData); // A pointer to user-allocated memory.

这个过程是成功的。但是当我试图从 outBuffer->mAudioData 读取数据时,总是会出现一个错误,指出从 'void* const' 到 'SInt16*' 的无效转换:

outBuffer->mAudioDataByteSize = numBytes;       
SInt16 *testBuffer = outBuffer->mAudioData; //Read data from buffer... Error!

for (int i=0; i<numBytes; i++)
{
    UInt16 currentData = testBuffer[i];
    printf("Current data in testbuffer is %d", currentData);
}

我已经经历了几个相关的问题,例如THISTHIS,似乎他们的问题正在工作......我还尝试将 outBuffer->mAudioData 替换为 AudioFileReadPackets() 中的 testBuffer,但 testBuffer 原来是一个空数组。

那么这是正确的方法吗?有没有其他方法可以将原始数据读取到 int/float 数组?

或者更一般地说,如何访问一个 void 常量指针并对它执行读/写操作?(是的,我的 C++ 没那么强……)

任何帮助将不胜感激 :-)

干杯,曼卡

4

1 回答 1

2

我只是在前面放了一个演员,它似乎工作:

SInt16* frames = (SInt16*)inBuffer->mAudioData;
于 2010-12-03T18:46:02.853 回答