Destroy / recreate audio thread on demodulator activate / deactivate -- fixes DirectSound issues

This commit is contained in:
Charles J. Cliffe 2015-02-04 18:10:42 -05:00
parent ec3e851354
commit a8070ca953
2 changed files with 42 additions and 15 deletions

View File

@ -65,8 +65,8 @@ IF (WIN32)
# Audio device selection is not mandatory, dummy audio device is used if none are compiled in. # 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. # Can also compile support for more than one simultaneously.
set(USE_AUDIO_DS OFF CACHE BOOL "Include support for DirectSound") set(USE_AUDIO_DS ON CACHE BOOL "Include support for DirectSound")
set(USE_AUDIO_WASAPI ON CACHE BOOL "Include support for WASAPI Audio") set(USE_AUDIO_WASAPI OFF CACHE BOOL "Include support for WASAPI Audio")
# TODO: # TODO:
# set(USE_AUDIO_ASIO OFF CACHE BOOL "Include support for ASIO Audio") # set(USE_AUDIO_ASIO OFF CACHE BOOL "Include support for ASIO Audio")

View File

@ -168,7 +168,7 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
if (!src->currentInput) { if (!src->currentInput) {
src->inputQueue->pop(src->currentInput); src->inputQueue->pop(src->currentInput);
if (src->terminated) { if (src->terminated || !src->active) {
return 1; return 1;
} }
src->audioQueuePtr = 0; src->audioQueuePtr = 0;
@ -183,11 +183,11 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
src->currentInput->decRefCount(); src->currentInput->decRefCount();
src->currentInput = NULL; src->currentInput = NULL;
} }
if (src->terminated) { if (src->terminated || !src->active) {
return 1; return 1;
} }
src->inputQueue->pop(src->currentInput); src->inputQueue->pop(src->currentInput);
if (src->terminated) { if (src->terminated || !src->active) {
return 1; return 1;
} }
src->audioQueuePtr = 0; src->audioQueuePtr = 0;
@ -202,11 +202,11 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
src->currentInput->decRefCount(); src->currentInput->decRefCount();
src->currentInput = NULL; src->currentInput = NULL;
} }
if (src->terminated) { if (src->terminated || !src->active) {
return 1; return 1;
} }
src->inputQueue->pop(src->currentInput); src->inputQueue->pop(src->currentInput);
if (src->terminated) { if (src->terminated || !src->active) {
return 1; return 1;
} }
src->audioQueuePtr = 0; src->audioQueuePtr = 0;
@ -223,11 +223,11 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
src->currentInput->decRefCount(); src->currentInput->decRefCount();
src->currentInput = NULL; src->currentInput = NULL;
} }
if (src->terminated) { if (src->terminated || !src->active) {
return 1; return 1;
} }
src->inputQueue->pop(src->currentInput); src->inputQueue->pop(src->currentInput);
if (src->terminated) { if (src->terminated || !src->active) {
return 1; return 1;
} }
src->audioQueuePtr = 0; src->audioQueuePtr = 0;
@ -326,7 +326,7 @@ void AudioThread::setupDevice(int deviceId) {
} else { } else {
deviceController[parameters.deviceId]->bindThread(this); deviceController[parameters.deviceId]->bindThread(this);
} }
active = true;
#else #else
if (dac.isStreamOpen()) { if (dac.isStreamOpen()) {
if (dac.isStreamRunning()) { if (dac.isStreamRunning()) {
@ -335,16 +335,29 @@ void AudioThread::setupDevice(int deviceId) {
dac.closeStream(); dac.closeStream();
} }
active = true;
if (deviceId != -1) {
dac.openStream(&parameters, NULL, RTAUDIO_FLOAT32, sampleRate, &bufferFrames, &audioCallback, (void *) this, &opts); dac.openStream(&parameters, NULL, RTAUDIO_FLOAT32, sampleRate, &bufferFrames, &audioCallback, (void *) this, &opts);
dac.startStream(); dac.startStream();
} else {
AudioThreadInput *dummy;
while (!inputQueue->empty()) { // flush queue
inputQueue->pop(dummy);
if (dummy) {
dummy->decRefCount();
}
}
}
#endif #endif
} catch (RtAudioError& e) { } catch (RtAudioError& e) {
e.printMessage(); e.printMessage();
return; return;
} }
if (deviceId != -1) {
outputDevice = deviceId; outputDevice = deviceId;
}
} }
int AudioThread::getOutputDevice() { int AudioThread::getOutputDevice() {
@ -440,6 +453,7 @@ bool AudioThread::isActive() {
} }
void AudioThread::setActive(bool state) { void AudioThread::setActive(bool state) {
#ifdef USE_MIXER #ifdef USE_MIXER
AudioThreadInput *dummy; AudioThreadInput *dummy;
if (state && !active) { if (state && !active) {
@ -459,8 +473,21 @@ void AudioThread::setActive(bool state) {
} }
} }
} }
#endif #else
if (state && !active && outputDevice != -1) {
active = state; 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
} }
AudioThreadCommandQueue *AudioThread::getCommandQueue() { AudioThreadCommandQueue *AudioThread::getCommandQueue() {