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

发布于 2024-10-04 11:31:26 字数 2015 浏览 2 评论 0原文

我正在开发一个与 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);
}

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

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

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

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

干杯, 曼卡

I'm working on a DSP related iOS app. Part of the work is to copy audio data from outBuffer ->mAudioData to an user-specified array for data processing. The read method is like this:

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.

This process is successful. But when I'm trying to read data from outBuffer->mAudioData, there is always an error saying invalid conversion from 'void* const' to '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);
}

I have gone through several related questions like THIS and THIS, seems theirs are working...
I also tried to replace outBuffer->mAudioData to testBuffer in AudioFileReadPackets(), but the testBuffer turns out to be an empty array.

So is it the right approach? Is there any other way to read the raw data to an int/float array?

Or more generally, how to access an void constant pointer and perform read/write operation to it? (Yeah my C++ is not that strong...)

Any help will be appreciated :-)

Cheers,
Manca

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷炫老祖宗 2024-10-11 11:31:26

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

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

I just put a cast in front and it seemed to work:

SInt16* frames = (SInt16*)inBuffer->mAudioData;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文