Passing Microphone Audio Direct to Speakers (AudioSampleBuffer)

Hi all,

I'm new to JUCE but I'm loving what I'm seeing so far and think it's perfect for what I'm working with.  I'm currently playing with the AudioRecordingDemo and AudioPlaybackDemo and trying to modify simple things into them- for example, i'm trying to pass the AudioSampleBuffer created in the RecordingDemo to my speakers (using exclusive mode in WASAPI, modified and working).  My question is, when I debug and look at the deviceManager, it shows both the input/output devices (in order, a generic USB microphone and my speakers). 

I was under the assumption that the outputChannelData was what would ultimately be passed to the speakers and that the zeroing at the end of AudioRecordingDemo::audioDeviceIOCallback() was to prevent audio from being passed, but commenting this code out doesn't affect anything.  How is data passed to the speakers using this method?

Thank you!

 

EDIT: I'll show the method here for those without the code handy.


void audioDeviceIOCallback (const float** inputChannelData, int numInputChannels,
                                float** outputChannelData, int numOutputChannels,
                                int numSamples) override
    {
        const ScopedLock sl (writerLock);
        if (activeWriter != nullptr)
        {
            activeWriter->write (inputChannelData, numSamples);
            // Create an AudioSampleBuffer to wrap our incomming data, note that this does no allocations or copies, it simply references our input data
            const AudioSampleBuffer buffer (const_cast<float**> (inputChannelData), thumbnail.getNumChannels(), numSamples);
            thumbnail.addBlock (nextSampleNum, buffer, 0, numSamples);
            nextSampleNum += numSamples;
        }
        // We need to clear the output buffers, in case they're full of junk..
        for (int i = 0; i < numOutputChannels; ++i)
            if (outputChannelData[i] != nullptr)
                FloatVectorOperations::clear (outputChannelData[i], numSamples);
    }

So, if I understand correctly what you are trying to do...

The audioDeviceIOCallback is called for the input and output channels of one particular device (the one that you have selected). If you want to record audio, that will be your USB microhone. You take its inputChannelData and write it somewhere.

Presumably, the USB microphone does not have any audio output channels, since it's a recording device. So when this function is called, numOutputChannels is zero, there's no outputChannelData, and therefore whether you comment that part out or not does not make any difference.