WASAPI driver will now resample when the device rate != audio/mix_rate

This commit is contained in:
Marcelo Fernandez 2018-03-29 22:56:57 -03:00
parent b704cfa4d5
commit d21a2019f1

View file

@ -151,7 +151,6 @@ Error AudioDriverWASAPI::init_device(bool reinit) {
// Since we're using WASAPI Shared Mode we can't control any of these, we just tag along // Since we're using WASAPI Shared Mode we can't control any of these, we just tag along
wasapi_channels = pwfex->nChannels; wasapi_channels = pwfex->nChannels;
mix_rate = pwfex->nSamplesPerSec;
format_tag = pwfex->wFormatTag; format_tag = pwfex->wFormatTag;
bits_per_sample = pwfex->wBitsPerSample; bits_per_sample = pwfex->wBitsPerSample;
@ -187,7 +186,14 @@ Error AudioDriverWASAPI::init_device(bool reinit) {
} }
} }
hr = audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, 0, 0, pwfex, NULL); DWORD streamflags = AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
if (mix_rate != pwfex->nSamplesPerSec) {
streamflags |= AUDCLNT_STREAMFLAGS_RATEADJUST;
pwfex->nSamplesPerSec = mix_rate;
pwfex->nAvgBytesPerSec = pwfex->nSamplesPerSec * pwfex->nChannels * (pwfex->wBitsPerSample / 8);
}
hr = audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED, streamflags, 0, 0, pwfex, NULL);
ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN); ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN);
event = CreateEvent(NULL, FALSE, FALSE, NULL); event = CreateEvent(NULL, FALSE, FALSE, NULL);
@ -223,10 +229,11 @@ Error AudioDriverWASAPI::finish_device() {
if (audio_client) { if (audio_client) {
if (active) { if (active) {
audio_client->Stop(); audio_client->Stop();
audio_client->Release();
audio_client = NULL;
active = false; active = false;
} }
audio_client->Release();
audio_client = NULL;
} }
if (render_client) { if (render_client) {
@ -244,6 +251,8 @@ Error AudioDriverWASAPI::finish_device() {
Error AudioDriverWASAPI::init() { Error AudioDriverWASAPI::init() {
mix_rate = GLOBAL_DEF("audio/mix_rate", DEFAULT_MIX_RATE);
Error err = init_device(); Error err = init_device();
if (err != OK) { if (err != OK) {
ERR_PRINT("WASAPI: init_device error"); ERR_PRINT("WASAPI: init_device error");