From 025d8f4d97e8971067f1111a752b69e93861fdd0 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 2 Nov 2021 01:45:38 -0700 Subject: [PATCH] fix effect sends --- src/FAudioGMS.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/FAudioGMS.c b/src/FAudioGMS.c index aa9c6ed..b1ff286 100644 --- a/src/FAudioGMS.c +++ b/src/FAudioGMS.c @@ -244,7 +244,7 @@ typedef struct FAudioGMS_Device FAudioDeviceDetails deviceDetails; FAudioMasteringVoice *masteringVoice; - FAudioGMS_Voice fauxMasteringVoice; + FAudioGMS_Voice fauxMasteringVoice; F3DAUDIO_LISTENER listener; float spatialDistanceScale; @@ -402,10 +402,10 @@ void FAudioGMS_Init(double spatialDistanceScale, double timestep) if (FAudio_CreateSubmixVoice( device->handle, &device->fauxMasteringVoice.handle, - FAUDIO_DEFAULT_CHANNELS, - FAUDIO_DEFAULT_SAMPLERATE, + device->deviceDetails.OutputFormat.Format.nChannels, + device->deviceDetails.OutputFormat.Format.nSamplesPerSec, + 0, 0, - i, &device->fauxMasteringVoice.sends, NULL ) != 0) @@ -1553,7 +1553,15 @@ static void FAudioGMS_INTERNAL_SetEffectChain(FAudioGMS_Voice* voice, FAudioGMS_ voice->effectSends.pSends = SDL_malloc(sizeof(FAudioSendDescriptor)); voice->effectSends.pSends[0].Flags = 0; - voice->effectSends.pSends[0].pOutputVoice = device->fauxMasteringVoice.handle; + + if (voice == &device->fauxMasteringVoice) + { + voice->effectSends.pSends[0].pOutputVoice = device->masteringVoice; + } + else + { + voice->effectSends.pSends[0].pOutputVoice = device->fauxMasteringVoice.handle; + } FAudio_CreateSubmixVoice( device->handle, @@ -1592,7 +1600,14 @@ static void FAudioGMS_INTERNAL_SetEffectChain(FAudioGMS_Voice* voice, FAudioGMS_ /* Set the instance voice to go through both faux mastering and effect voice for wet/dry */ voice->sends.pSends[0].Flags = 0; - voice->sends.pSends[0].pOutputVoice = device->fauxMasteringVoice.handle; + if (voice == &device->fauxMasteringVoice) + { + voice->sends.pSends[0].pOutputVoice = device->masteringVoice; + } + else + { + voice->sends.pSends[0].pOutputVoice = device->fauxMasteringVoice.handle; + } voice->sends.pSends[1].Flags = 0; voice->sends.pSends[1].pOutputVoice = voice->effectVoice; @@ -1600,7 +1615,7 @@ static void FAudioGMS_INTERNAL_SetEffectChain(FAudioGMS_Voice* voice, FAudioGMS_ FAudioVoice_SetOutputVoices( voice->handle, - &voice->effectSends); + &voice->sends); FAudioGMS_INTERNAL_Voice_SetEffectGain(voice, effectGain); @@ -1629,7 +1644,7 @@ void FAudioGMS_SetMasteringEffectChain(double effectChainID, double effectGain) { RETURN_ON_NULL_DEVICE() FAudioGMS_EffectChain* effectChain = FAudioGMS_INTERNAL_LookupEffectChain((uint32_t)effectChainID); - + if (effectChain != NULL) { FAudioGMS_INTERNAL_SetEffectChain(&device->fauxMasteringVoice, effectChain, effectGain); @@ -1789,7 +1804,6 @@ void FAudioGMS_Destroy() FAudioGMS_INTERNAL_StaticSound_Destroy(device->staticSounds[i]); } - /* FIXME: FAudioGMS_Voice_Destroy call */ FAudioVoice_DestroyVoice(device->fauxMasteringVoice.handle); SDL_free(device->fauxMasteringVoice.sends.pSends);