实时音频队列录音回放

发布于 2024-10-10 18:43:08 字数 183 浏览 9 评论 0原文

嘿伙计们, 我正在尝试构建一个用于实时变声的应用程序。 第一步,我设法将音频数据录制到指定文件并在录制后播放。 现在我尝试更改在循环录制音频缓冲区后立即播放音频缓冲区的代码。 我的问题是,如何直接从录音音频队列中读取音频数据,而不是(如文档中所示)从文件中读取音频数据。 我感谢您的任何想法,如果需要,可以显示代码部分。 提前致谢, 卢卡斯(来自德国)

Hey fellows,
Iam trying to build an application for realtime voicechanging.
In a first step I managed to record audiodata to a specified file and to play it after recording.
Now I try to change the code for playing back the audiobuffers right after recording them in loop.
My question is, how it is possible to read the Audiodata directly from the recording Audioqueue and not (like shown in documentation) from a file.
Iam thankful for any ideas and could show code-parts if needed.
Thanks in advance,
Lukas (from Germany)

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

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

发布评论

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

评论(1

白衬杉格子梦 2024-10-17 18:43:08

看一下 SpeakHere 示例。此行提供音频数据:

OSStatus result = AudioFileReadPackets(THIS->GetAudioFileID(), false, &numBytes,     inCompleteAQBuffer->mPacketDescriptions, THIS->GetCurrentPacket(), &nPackets, 
                                       inCompleteAQBuffer->mAudioData);

因此,您可以使用 memcpy 复制录制的数据缓冲区,而不是调用 AudioFileReadPackets。或者,向播放 AudioQueue 提供一个指向音频数据缓冲区的指针。当播放继续时,在缓冲区中前进 mCurrentPacket 指针。

为了录制,您将执行非常类似的操作。您将写入内存中的缓冲区,而不是写入文件。您首先需要使用 malloc 来分配它。然后,您传入的 AudioQueue 捕获记录的数据,您将该数据复制到缓冲区。随着更多数据被复制,您将记录磁头或 mCurrentPacket 前进到新位置。

Have a look at the SpeakHere example. This line sources the audio data:

OSStatus result = AudioFileReadPackets(THIS->GetAudioFileID(), false, &numBytes,     inCompleteAQBuffer->mPacketDescriptions, THIS->GetCurrentPacket(), &nPackets, 
                                       inCompleteAQBuffer->mAudioData);

So, rather than call AudioFileReadPackets, you can just use a memcpy to copy over the recorded data buffer. Or, alternatively, supply to the playback AudioQueue a pointer to the audio data buffer. As playback continues, advance a mCurrentPacket pointer through the buffer.

To record, you'll do something very similar. Rather than writing out to a file, you'll write out to a buffer in memory. You'll first need to allocate that with a malloc. Then are your incoming AudioQueue captures recorded data, you copy that data to the buffer. As more data is copied, you advance the recording head, or mCurrentPacket to a new position.

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