views:

109

answers:

0

Hello Everyone,

I'm building an IPhone Application that records sound. I'm using Audio Queue Services, and everything works great for recording.

The thing is, I'm using AudioFileWritePackets for file writing, and I'm trying to put the same "AAC + ADTS" packets to a network socket.

The resulting file is different since some "headers" or "adts header" might be missing. Any ideas how to write the ADTS header and/or AAC header? Any ideas on this topic would be awesome.

Thank you! Here is my Buffer Handler method:

void Recorder::MyInputBufferHandler(    void *                              inUserData,
                                        AudioQueueRef                       inAQ,
                                        AudioQueueBufferRef                 inBuffer,
                                        const AudioTimeStamp *              inStartTime,
                                        UInt32                              inNumPackets,
                                        const AudioStreamPacketDescription* inPacketDesc)
{
    AQRecorder *aqr = (AQRecorder *)inUserData;
    try {

        if (inNumPackets > 0) {
            // write packets to file
            XThrowIfError(
                            AudioFileWritePackets(aqr->mRecordFile,
                                                  FALSE,
                                                  inBuffer->mAudioDataByteSize,
                                                  inPacketDesc,
                                                  aqr->mRecordPacket,
                                                  &inNumPackets,
                                                  inBuffer->mAudioData),
                            "AudioFileWritePackets failed");

            fprintf(stderr, "Writing.");


            // We write the Net Buffer.
            [aqr->socket_if writeData :(void *)(inBuffer->mAudioData)
                               :inBuffer->mAudioDataByteSize];


            aqr->mRecordPacket += inNumPackets;
        }

        // if we're not stopping, re-enqueue the buffe so that it gets filled again
        if (aqr->IsRunning()) {
            XThrowIfError(AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL), "AudioQueueEnqueueBuffer failed");
        }

    } catch (CAXException e) {
        char buf[256];
        fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
    }
}