Lukas
Lukas

Reputation: 115

Realtime AudioQueue Record-Playback

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)

Upvotes: 2

Views: 1393

Answers (1)

Max MacLeod
Max MacLeod

Reputation: 26652

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.

Upvotes: 1

Related Questions