How to use audioDeviceIOCallback, audioDeviceAboutToStart and audioDeviceStopped in a simple audio recorder program


Using Juce, I tried to create a simple audio recorder from the demo runner.
I’ve extracted the AudioRecordingDemo to create audio recorder based on a simple audio project.

When I’m clicking on the start recording button, the sampleRate still have the default value:

void startRecording(const File& file)

		if (sampleRate > 0)
			// Create an OutputStream to write to our destination file...  

sampleRate = 0.0

In the AudioRecordingDemo, the audioDeviceAboutToStart increment the sample rate. But I don’t have any AudioIODevice in my main component.

void audioDeviceAboutToStart(AudioIODevice* device) override
	sampleRate = device->getCurrentSampleRate();


The AudioIODeviceCallback that sets up the input and ouput is also never called in my code. I tried to use it in my MainComponent class without success.

I also tried to make the MainComponent class inherits from the AudioIODeviceCallback :

class MainComponent : public Component,
         private AudioIODeviceCallback,
         private MidiInputCallback

I found this method in the Build a multi-polyphonic synthesiser tutorial.

But when I tried this, I got an overwriting error in the main class.

So here is my problem, how to use the AudioIODeviceCallback, audioDeviceAboutToStart and audioDeviceStopped that are defined in the AudioRecordingDemo class in my project ?

You can find the source code here.


What error did you run into?

That tutorial has everything you need, even if it’s more focussed on MIDI. You should look at the section where you hook an AudioIODeviceCallback up to an audio device:

    audioDeviceManager.addAudioCallback (this);

Have an AudioDeviceManager audioDeviceManager as a member of your class and initialise it.

Once the AudioIODeviceCallback is connected to an audio device, the audio device will call the audioDeviceAboutToStart method.