我正在开发与 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);
}
我已经回答了几个相关问题,例如 THIS和 THIS ,似乎他们正在工作...... 我还尝试将 AudioFileReadPackets() 中的 outBuffer->mAudioData 替换为 testBuffer,但 testBuffer 结果是一个空数组。
那么这是正确的方法吗?还有其他方法可以将原始数据读取到 int/float 数组吗?
或者更笼统地说,如何访问一个空常量指针并对其执行读/写操作? (是的,我的 C++ 没有那么强...)
任何帮助将不胜感激:-)
干杯, 曼卡
最佳答案
我只是在前面放了一个石膏,它似乎起作用了:
SInt16* frames = (SInt16*)inBuffer->mAudioData;
关于ios - 音频队列 : Can't read raw data in AudioFileReadPackets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4255557/