No audio until audio device is toggled

Hi,

I’m facing a rather unusual problem whereby my audio application does not make any sound until the audio device in the app’s AudioDeviceSelector object is toggled.

My MainComponent class has a reference to my Audio class (inheriting from AudioAppComponent), here’s the code in its constructor -

audioDeviceManager.initialiseWithDefaultDevices(0, 2);
setAudioChannels(0, 2);

 audioDeviceManager.addMidiInputCallback(String(), this);

 harmAudioSource.setUsingHarmoniumSample();

 reverbSource.setBypassed(false);
 reverbSource.setParameters(customParameters);

 audioMixer.addInputSource(&reverbSource, false);
 audioMixer.addInputSource(&droneSample.getTransport(), false);

 droneSample.setStarting();

The test tone from the AudioDeviceSelector component appears to come through fine without any issues, however neither my synthesiser nor my sampler make any sound that comes through.

Moreover, the getNextAudioBlock() function does not get called at all until the audio device is toggled.

I would appreciate any advise in this instance.

Thanks!

The first line can be omitted, the second line will call that anyway, and I can’t say for sure, that calling it twice might even be the culprit.

Next thing, did you call prepareToPlay on all your sources?
When they are connected, they usually call prepareToPlay on their source (i.e. audioMixer.prepareToPlay would call droneSample.prepareToPlay and reverbInput.prepareToPlay)

Apart from that it’s guessing without the rest of the implementation.

Interesting would be prepareToPlay and the getNextAudioBlock(), where you pull samples from the audioMixer.

EDIT: just noted, you said it works, when you switch the device. So my hypothesis is:

setAudioChannels() calls prepareToPlay, but the mixerSource is not yet connected.
If you change the order:

    harmAudioSource.setUsingHarmoniumSample();

    reverbSource.setBypassed(false);
    reverbSource.setParameters(customParameters);

    audioMixer.addInputSource(&reverbSource, false);
    audioMixer.addInputSource(&droneSample.getTransport(), false);

    setAudioChannels(0, 2);
    audioDeviceManager.addMidiInputCallback(String(), this);

    droneSample.setStarting();

It could work.

Thanks @daniel

Omitting the first line did indeed start the audio playback straight away, however the problem was that the audio device in my AudioDeviceSelector component did not update - shows no output selected despite the audio coming through built in output.

Moving the lines around in that order unfortunately didn’t seem to make a difference.

Thanks for the help, any further suggestions would be appreciated.

Is the AudioDeviceSelectorComponent referencing the same AudioDeviceManager, or did you accidentally create another one? It can easily happen, if you forget to specify the &

My MainComponent class contains the AudioDeviceSelectorComponent and receives a reference to the AudioDeviceManager from my Audio class. So - Yes, I am referencing the same AudioDeviceManager as far as I can tell.

Hmm, and MainComponent is a AudioAppComponent I presume? You are aware it has it’s own AudioDeviceManager, so if you define your own AudioDeviceManager, you have two.

But you said, yu are sure, there is only one, so I don’t have any further idea unfortunately.

Good luck

I’ve grouped all the audio processes in a separate Audio class which inherits from AudioAppComponent and hence, my MainComponent is just a Component (no audio happens here).

I guess I’ll just have to live with it for now. Thanks for all the help thus far.

But this other AudioAppComponent still has an AudioDeviceManager!

Connect your AudioDeviceSelectorComponent to this public member or instanciate this AudioAppComponent derrived one with the reference to your own AudioDeviceManager.

1 Like

Wow!

I didn’t realise the AudioAppComponent featured a public AudioDeviceManager.

Yep, connected this to the AudioDeviceSelectorComponent and everything works perfectly.

Thanks a ton @daniel !

Glad it works :slight_smile: