Save to buffer instead of file when recording aac using Audio Queue Services

My goal is to record audio in AAC format and send it over the network connection as a stream.

I use Audio Queue Services and base my code on the SpeakHere example. I know that it uses the AudioFileWritePackets () function to write to a file.

Here's the callback function:

void MyInputBufferHandler(void* inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer, const AudioTimeStamp * inStartTime, UInt32 inNumPackets, const AudioStreamPacketDescription* inPacketDesc) { Recorder *aqr = (Recorder *)inUserData; if (inNumPackets > 0) { // write packets to file AudioFileWritePackets(aqr->mRecordFile, FALSE, inBuffer->mAudioDataByteSize, inPacketDesc, aqr->mRecordPacket, &inNumPackets, inBuffer->mAudioData); aqr->mRecordPacket += inNumPackets; } // if we're not stopping, re-enqueue the buffe so that it gets filled again if ([aqr IsRunning]) AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL); } 

At first I thought that AudioFileWritePackets works by directly writing the contents of inBuffer->mAudioData . However, when I manually write only the contents of mAudioData to a file, decoding does not work.

When studying and comparing the raw data of what AudioFileWritePackets writes to a file, and I just write mAudioData to a file, they seem to have connected a header to it.

As I cannot understand how AudioFileWritePackets () works, my question is how can I write the recorded sound to the buffer (or stream, if you prefer to call it that) instead of a file, so that I can send it over a network connection later ?

In short, in short, what I need: record audio in aac format and transmit audio over a network connection.

Thanks! I was looking for my head in blue ...

PS: please, if you point me to existing projects, make sure that I need them. It really seems to me that I was looking for all possible projects there>. <

+4
source share
1 answer

All Articles