Hi, I’m trying to make an audio output selector, but it only works for the first time it chooses one of the available output devices (I’m in windows).
I also have an input selector that works fine. Every time I choose a diferent input it just works, I can several input lines working at once. But when I try to change the output the inputs freezes and stops proceesing.
This is how I change the output:
void changeOutput(string output)
{
auto ctx = ci::audio::master();
auto device = ci::audio::Device::findDeviceByName(output);
if (device)
ci::audio::OutputDeviceNodeRef outputDevice = ctx->createOutputDeviceNode(device);
ctx->setOutput(outputDevice);
}
Where output is sleceted from one of ci::audio::Device::getOutputDevices()
then I try to update the connection of a BufferPlayer node
void updateConnection(){
auto ctx = ci::audio::Context::master();
if (mGain) {
if (mGain->isConnectedToOutput(ctx->getOutput())) {
mGain->disconnect(ctx->getOutput());
}
}
mGain = ctx->makeNode(new ci::audio::GainNode(1.0f));
mSoundBufferPing >> mGain;
mGain >> ctx->getOutput();
ctx->enable();
}
Where:
ci::audio::GainNodeRef mGain;
ci::audio::BufferPlayerNodeRef mSoundBufferPing;
The sound is loaded like this:
void AudioInputSelectApp::loadPing()
{
auto ctx = ci::audio::Context::master();
try {
auto audioTrack = ci::audio::load(ci::loadFile(ci::app::getAssetPath("ping.mp3")), ctx->getSampleRate());
ci::audio::BufferRef buffer = audioTrack->loadBuffer();
mSoundBufferPing = ctx->makeNode(new ci::audio::BufferPlayerNode(buffer));
}
catch (ci::Exception &exc) {
ci::app::console() << "[xumo::AudioModule::loadPing] failed to load sound." << exc.what() << std::endl;
}
ci::app::console() << "[xumo::AudioModule::loadPing] laoaded" << std::endl;
}
Then, this works:
loadPing();
changeOutput("Correct output device name");
updateConnection();
mSoundBufferPing->start();
That plays a sound correctly, but then calling:
changeOutput("Another correct output device name");
updateConnection();
mSoundBufferPing->start();
This doesn’t work anymore.
Anyone knows how to do this?