Audio Callback Wrapping?



I’ve heard thats its possible to wrap an audio callback to another audio callback, so that your program can have just one main callback, i was just wondering how this is done? sorry i’m only just learning all of this stuff.



Sorry, don’t really understand what you mean…?


My lecturer told me about it. He said to use it for my metronome as it doesn’t require any audio inputs. He gave me this code but i can’t get it to work:

in my metronome .h
	bool metroCallback(float** outputChannelData,
					   int totalNumOutputChannels,
					   int numSamples);

in my metronome.cpp
bool metroCallback(float** outputChannelData,
				   int totalNumOutputChannels,
				   int numSamples)

He then said that you could have this called from a main audioCallback in another class dedicated to audio along with the audioTransportSource that i’m also using.

  • Just make your metronome class inherit from AudioProcessor.
  • Override all the methods with relevant (or dummy) values, like for example : virtual bool acceptsMidi() { return false;} and so on.
  • Override processBlock with the code your lecturer gave you.
  • Finally, put this metronome inside an AudioProcessorGraph, add an output node, create an AudioProcessorPlayer and use it as your main callback.


Hey Joe,

The reply from Jules I guess is triggered by the fact that the nomenclature of “audio callback” is that it is the closest function/method you have towards an audio device. Thereby “wrap” loses its meaning, as there can only be one audio callback. OTOH, what functions you call from the “audio callback” is wholly up to you, which is I guess what your lecturer really meant.



I think what he means is that you can register your metronome class with an AudioDeviceManager from another class.
For example if you had your main component which is also an AudioIOCallback which deals with your main audio processing you probably have an instance of AudioDeviceManager inside it and are adding your main callback with

manager.addAudioCallback(this); after you have initialised your manager.

You can then create an instance of your metronome and add it to the same manager so it’s callback will be called after your main one:

metronome = new Metronome(); manager.addAudioCallback(metronome);

Your metronome can then do all it’s sample counting, clicks etc. in it’s own callback and you don’t have to worry about that in your main audio callback.

Obviously as previously mentioned there are many ways of doing this sort of thing and this may not be the ‘best’ but I think it is the simplest.


Thank you, i will try this out.



Hey…just throwing this out there, but writing a ‘1’ followed by a ‘-1’ float value to the audio output stream makes a great ‘tick’ sound…you can’t miss it!