diff --git a/CMakeLists.txt b/CMakeLists.txt index 66dfae3..ced47f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,8 +65,8 @@ IF (WIN32) # Audio device selection is not mandatory, dummy audio device is used if none are compiled in. # Can also compile support for more than one simultaneously. - set(USE_AUDIO_DS OFF CACHE BOOL "Include support for DirectSound") - set(USE_AUDIO_WASAPI ON CACHE BOOL "Include support for WASAPI Audio") + set(USE_AUDIO_DS ON CACHE BOOL "Include support for DirectSound") + set(USE_AUDIO_WASAPI OFF CACHE BOOL "Include support for WASAPI Audio") # TODO: # set(USE_AUDIO_ASIO OFF CACHE BOOL "Include support for ASIO Audio") diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 54eb656..d17c68b 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -168,7 +168,7 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu if (!src->currentInput) { src->inputQueue->pop(src->currentInput); - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->audioQueuePtr = 0; @@ -183,11 +183,11 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu src->currentInput->decRefCount(); src->currentInput = NULL; } - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->inputQueue->pop(src->currentInput); - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->audioQueuePtr = 0; @@ -202,11 +202,11 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu src->currentInput->decRefCount(); src->currentInput = NULL; } - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->inputQueue->pop(src->currentInput); - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->audioQueuePtr = 0; @@ -223,11 +223,11 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu src->currentInput->decRefCount(); src->currentInput = NULL; } - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->inputQueue->pop(src->currentInput); - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->audioQueuePtr = 0; @@ -326,7 +326,7 @@ void AudioThread::setupDevice(int deviceId) { } else { deviceController[parameters.deviceId]->bindThread(this); } - active = true; + #else if (dac.isStreamOpen()) { if (dac.isStreamRunning()) { @@ -335,16 +335,29 @@ void AudioThread::setupDevice(int deviceId) { dac.closeStream(); } - dac.openStream(¶meters, NULL, RTAUDIO_FLOAT32, sampleRate, &bufferFrames, &audioCallback, (void *) this, &opts); - dac.startStream(); + active = true; + + if (deviceId != -1) { + dac.openStream(¶meters, NULL, RTAUDIO_FLOAT32, sampleRate, &bufferFrames, &audioCallback, (void *) this, &opts); + dac.startStream(); + } else { + AudioThreadInput *dummy; + while (!inputQueue->empty()) { // flush queue + inputQueue->pop(dummy); + if (dummy) { + dummy->decRefCount(); + } + } + } #endif } catch (RtAudioError& e) { e.printMessage(); return; } - - outputDevice = deviceId; + if (deviceId != -1) { + outputDevice = deviceId; + } } int AudioThread::getOutputDevice() { @@ -440,6 +453,7 @@ bool AudioThread::isActive() { } void AudioThread::setActive(bool state) { + #ifdef USE_MIXER AudioThreadInput *dummy; if (state && !active) { @@ -459,8 +473,21 @@ void AudioThread::setActive(bool state) { } } } +#else + if (state && !active && outputDevice != -1) { + active = state; + AudioThreadCommand command; + command.cmd = AudioThreadCommand::AUDIO_THREAD_CMD_SET_DEVICE; + command.int_value = outputDevice; + cmdQueue.push(command); + } else if (active && !state) { + active = state; + AudioThreadCommand command; + command.cmd = AudioThreadCommand::AUDIO_THREAD_CMD_SET_DEVICE; + command.int_value = -1; + } + #endif - active = state; } AudioThreadCommandQueue *AudioThread::getCommandQueue() {