Question

I am trying to adopt recording part of the Apple example entitled "SpeakHere" to my purposes. Everything seems to fine, but I need to add an option which actually offers 8 bit recording. This is according to the specification not allowed by any audio settings, so I need some kind of conversion from 16 bit. I think I need to place it in the callback function.

// ____________________________________________________________________________________
// AudioQueue callback function, called when an input buffers has been filled.
void AQRecorder::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");
            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));
    }
}

but to be honest don't know how. Any idea will be appreciated.

Was it helpful?

Solution 2

After quite of investigation and trying things, I have found out, that I do not need conversion, but just have to set different format flags.

mRecordFormat.mFormatFlags      = kLinearPCMFormatFlagIsBigEndian;
mRecordFormat.mBitsPerChannel   = 8;

OTHER TIPS

why don't you try to initialize your audio queue with something like that ?

    aqData.mDataFormat.mFormatID = kAudioFormatLinearPCM;        // 2
    aqData.mDataFormat.mSampleRate = 44100.0;                    // 3
    aqData.mDataFormat.mChannelsPerFrame = 1;                    // 4
    aqData.mDataFormat.mBitsPerChannel = 8;                     // 5
    aqData.mDataFormat.mBytesPerPacket =                         // 6
    aqData.mDataFormat.mBytesPerFrame =
    aqData.mDataFormat.mChannelsPerFrame * sizeof (SInt8);
    aqData.mDataFormat.mFramesPerPacket = 1;                     // 7

    AudioFileTypeID fileType = kAudioFileAIFFType;               // 8
    aqData.mDataFormat.mFormatFlags =                            // 9
    kLinearPCMFormatFlagIsBigEndian
    | kLinearPCMFormatFlagIsSignedInteger
    | kLinearPCMFormatFlagIsPacked; 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top