Hi everyone,
I’m trying to write an application that can accept microphone input, and play that input back out of the speakers of a Mac after having some effects applied to it. However I have run into a problem where I seem to be able to read audio data in from the mike without any dramas, but nothing comes out of the speakers.
My basic setup:
A HALOutput unit that is connected to a ring buffer An AUConverter Unit that has its input proc set up to read data from the ring buffer A DefaultOutput Unit that is connected to the AUConverter unit
The converter unit and speaker unit are both added into an AudioGraph.
When I run my app, I can see the converter units RenderCallbackProc getting called, and I read the data from the RingBuffer at that time. The code looks like this:
static OSStatus converter_render_proc(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList * ioData) { PNMicrophone* pMicrophone = (PNMicrophone*) inRefCon; // Have we ever logged output timing? (for offset calculation) if (pMicrophone->firstOutputSampleTime < 0.0) { pMicrophone->firstOutputSampleTime = inTimeStamp->mSampleTime; if ((pMicrophone->firstInputSampleTime > 0.0) && (pMicrophone->inToOutSampleTimeOffset < 0.0)) { pMicrophone->inToOutSampleTimeOffset = pMicrophone->firstInputSampleTime - pMicrophone->firstOutputSampleTime; } }
// Copy samples out of ring buffer OSStatus converterProcErr = noErr; //printf("FETCH\n"); converterProcErr = PNRingBuffer_Fetch(pMicrophone->pRingBuffer, ioData, inNumberFrames, inTimeStamp->mSampleTime + pMicrophone->inToOutSampleTimeOffset); return converterProcErr; }
If I read the data in ioData after the fetch, I can see what appears to be correct microphone data coming in (values from 0 to 1, that increase if I make some noise near the microphone). Nevertheless, I don’t hear anything from the speakers. The fact that the Render Proc is called at all suggests to me that the AudioGraph is working just fine and that the speakers are correctly trying to pull data. This would seem to be confirmed by the fact that if I replace the converter unit by an AudioFile unit in my Audio graph, it correctly plays the file out to the speakers.
Is this the right approach? Have I missed a step somewhere? What else can I check to give me some insight into what is going wrong? I’ve been battling against this problem for some time now, and I really can’t think of anything else to try, so any help that you can give would be appreciated.
Allison Newman |