I'm using AudioQueue to analyze the audio frequency. I saw the SpeakHere example by Apple.
I know to use the callback function to get the audio data in inbuffer->mAudioData. The question is when I get the audio data, I want to update the spectrum on the UI. The UI is code use Objective-C and the SpeakHere code use C++. I don't know how to call the UI method in the callback function and pass the mAudioData.
Here is 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; aqr->currentQueueBufferRef = inBuffer; try { if (inNumPackets > 0) { // write packets to file XThrowIfError(AudioFileWritePackets(aqr->mRecordFile, FALSE, inBuffer->mAudioDataByteSize, inPacketDesc, aqr->mRecordPacket, &inNumPackets, inBuffer->mAudioData), "AudioFileWritePackets failed"); ***//Here I want to call Objective c Method and pass the value.*** } // 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)); } }