AudioQueue:无法读取AudioFileReadPackets中的原始数据

时间:2010-11-23 11:28:13

标签: ios core-audio audioqueueservices

我正在研究与DSP相关的iOS应用。部分工作是将音频数据从outBuffer - > mAudioData复制到用户指定的数组进行数据处理。 read方法如下:

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,似乎他们正在工作...... 我还试图在AudioFileReadPackets()中将outBuffer-&gt; mAudioData替换为testBuffer,但testBuffer原来是一个空数组。

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

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

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

干杯, 曼卡

1 个答案:

答案 0 :(得分:2)

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

SInt16* frames = (SInt16*)inBuffer->mAudioData;