Realtime AudioQueue Record-Playback

怎甘沉沦 提交于 2019-11-30 16:14:20

问题


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)


回答1:


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.



来源:https://stackoverflow.com/questions/4639912/realtime-audioqueue-record-playback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!