The current version of allolib does not have a way of detecting changes in the number of available audio devices, or detecting a change of default device. The only way to update the device is to either manually check for a default device change at regular intervals (which could seriously hurt performance), or have the user change the default device when desired. I provide a method of doing the latter.
bool onKeyDown(Keyboard const& k)
function of of the App class. This code is used for handling key presses on the keyboard. We use this function so the user is able to switch the default audio ouptut device by using keyboard shortcuts. In order to do this, inside your class extending al::App
we need to add the following code, if it does not already exist:
bool onKeyDown(al::Keyboard const& k) override {
if (al::ParameterGUI::usingKeyboard()) { // Ignore keys if GUI is using them
return true;
}
// we will be adding more code here as well soon...
// there may be existing code here
}
onKeyDown
function:
if(k.ctrl()) {
int asciiCode = k.key();
if(asciiCode == 100) { // ctrl-d pressed => deactivate current output device
audioIO().close();
}
if(asciiCode == 97) { //ctrl-a pressed => activate the current default output device
configureAudio(48000., 512, 2, 0);
audioIO().start();
}
}
if(k.ctrl()) {
int asciiCode = k.key();
if(asciiCode == 100) {
audioIO().close();
}
if(asciiCode == 97) {
al::AudioDevice dev_out = al::AudioDevice::defaultOutput();
configureAudio(dev_out, dev_out.defaultSampleRate(), 512, dev_out.channelsOutMax(), 0);
audioIO().start()
}
}
The benefit of this code over the previous method is that it will start the current audio device while making sure we configure it with the proper parameters. There is an example in my alloplayground demos repo. You can also use a similar method for switching input devices.
Get the code for this here (the demo is called “tutti”).