实时AudioQueue记录播放 [英] Realtime AudioQueue Record-Playback

查看:113
本文介绍了实时AudioQueue记录播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,
我试图建立一个实时语音交换应用程序。
第一步,我设法将audiodata录制到指定的文件并在录制后播放。
现在我尝试在循环录制后立即更改用于播放audiobuffers的代码。
我的问题是,如何直接从录音Audioqueue中读取Audiodata,而不是从文件中读取(如文档中所示)。
我感谢任何想法,如果需要可以显示代码部分。
提前致谢,
Lukas(来自德国)

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)

推荐答案

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

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);

所以,而不是打电话给 AudioFileReadPackets ,你可以使用memcpy复制记录的数据缓冲区。或者,也可以向播放 AudioQueue 提供指向音频数据缓冲区的指针。当播放继续时,通过缓冲区前进一个 mCurrentPacket 指针。

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.

要记录,你会做一些非常相似的事情。您将写入内存中的缓冲区,而不是写入文件。您首先需要使用 malloc 分配它。然后您的传入 AudioQueue 捕获记录的数据,您将该数据复制到缓冲区。随着更多数据被复制,您将录音头或 mCurrentPacket 推进到新位置。

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.

这篇关于实时AudioQueue记录播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆