【问题标题】:AudioQueue: Can't read raw data in AudioFileReadPacketsAudioQueue:无法读取 AudioFileReadPackets 中的原始数据
【发布时间】:2011-05-14 10:09:09
【问题描述】:

我正在开发一个与 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,看来他们的问题正在运行... 我还尝试在 AudioFileReadPackets() 中将 outBuffer->mAudioData 替换为 testBuffer,但结果 testBuffer 是一个空数组。

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

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

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

干杯, 曼卡

【问题讨论】:

    标签: ios core-audio audioqueueservices


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-04-14
      • 2018-12-24
      • 2018-09-07
      • 2012-07-01
      • 2020-03-07
      • 1970-01-01
      • 2021-03-22
      • 2018-06-11
      • 2016-02-02
      相关资源
      最近更新 更多