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.
# 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")

View File

@ -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(&parameters, NULL, RTAUDIO_FLOAT32, sampleRate, &bufferFrames, &audioCallback, (void *) this, &opts);
dac.startStream();
active = true;
if (deviceId != -1) {
dac.openStream(&parameters, 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() {