ios - 音频队列 : Can't read raw data in AudioFileReadPackets

标签 ios core-audio audioqueueservices

我正在开发与 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 数组吗?

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

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

干杯, 曼卡

最佳答案

我只是在前面放了一个石膏,它似乎起作用了:

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

关于ios - 音频队列 : Can't read raw data in AudioFileReadPackets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4255557/

相关文章:

iphone - 如何?在 TableView 中,如果 NSMutableArray 为空,则显示另一个 Array

iphone - 给定文件和目录生成相对路径的 Objective-C 代码

ios - 同时录制和播放音频

audio - 更改PCM数据中吉他弹拨的持续时间

iphone - 模拟器中的 AudioQueue 回调,但不在设备上

ios - Audio Queue如何停止当前的播放任务并立即开始播放另一个AudioQueueBuffer?

ios - AudioDataPacketCount 返回 ValueUnknown

iphone - 如何将 View 从容器 View 内部移动到另一个容器 View 内部?

iphone - 使所有 UIImageView 指向静态 UIImageView

iphone - 我无法使用 AVAudioPlayer 播放 mp3 文件