From 0d4b66fe980f33e5168e1dba576d5f8ca3ee0edb Mon Sep 17 00:00:00 2001 From: "Skyth (Asilkan)" <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Sun, 26 Jan 2025 13:54:08 +0300 Subject: [PATCH] Apply master volume in audio backend. (#202) --- UnleashedRecomp/apu/driver/sdl2_driver.cpp | 14 ++++++-------- UnleashedRecomp/patches/audio_patches.cpp | 6 +++--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/UnleashedRecomp/apu/driver/sdl2_driver.cpp b/UnleashedRecomp/apu/driver/sdl2_driver.cpp index 7258bbc..5c85e25 100644 --- a/UnleashedRecomp/apu/driver/sdl2_driver.cpp +++ b/UnleashedRecomp/apu/driver/sdl2_driver.cpp @@ -94,6 +94,8 @@ void XAudioRegisterClient(PPCFunc* callback, uint32_t param) void XAudioSubmitFrame(void* samples) { + auto floatSamples = reinterpret_cast*>(samples); + if (g_downMixToStereo) { // 0: left 1.0f, right 0.0f @@ -103,8 +105,6 @@ void XAudioSubmitFrame(void* samples) // 4: left 1.0f, right 0.0f // 5: left 0.0f, right 1.0f - auto floatSamples = reinterpret_cast*>(samples); - std::array audioFrames; for (size_t i = 0; i < XAUDIO_NUM_SAMPLES; i++) @@ -116,22 +116,20 @@ void XAudioSubmitFrame(void* samples) float ch4 = floatSamples[4 * XAUDIO_NUM_SAMPLES + i]; float ch5 = floatSamples[5 * XAUDIO_NUM_SAMPLES + i]; - audioFrames[i * 2 + 0] = ch0 + ch2 * 0.75f + ch4; - audioFrames[i * 2 + 1] = ch1 + ch2 * 0.75f + ch5; + audioFrames[i * 2 + 0] = (ch0 + ch2 * 0.75f + ch4) * Config::MasterVolume; + audioFrames[i * 2 + 1] = (ch1 + ch2 * 0.75f + ch5) * Config::MasterVolume; } SDL_QueueAudio(g_audioDevice, &audioFrames, sizeof(audioFrames)); } else { - auto rawSamples = reinterpret_cast*>(samples); - - std::array audioFrames; + std::array audioFrames; for (size_t i = 0; i < XAUDIO_NUM_SAMPLES; i++) { for (size_t j = 0; j < XAUDIO_NUM_CHANNELS; j++) - audioFrames[i * XAUDIO_NUM_CHANNELS + j] = rawSamples[j * XAUDIO_NUM_SAMPLES + i]; + audioFrames[i * XAUDIO_NUM_CHANNELS + j] = floatSamples[j * XAUDIO_NUM_SAMPLES + i] * Config::MasterVolume; } SDL_QueueAudio(g_audioDevice, &audioFrames, sizeof(audioFrames)); diff --git a/UnleashedRecomp/patches/audio_patches.cpp b/UnleashedRecomp/patches/audio_patches.cpp index af75d3f..7d831b2 100644 --- a/UnleashedRecomp/patches/audio_patches.cpp +++ b/UnleashedRecomp/patches/audio_patches.cpp @@ -52,15 +52,15 @@ void AudioPatches::Update(float deltaTime) } else { - *pMusicVolume = std::lerp(*pMusicVolume, Config::MusicVolume * Config::MasterVolume, time); + *pMusicVolume = std::lerp(*pMusicVolume, Config::MusicVolume, time); } } else { - *pMusicVolume = Config::MusicVolume * Config::MasterVolume; + *pMusicVolume = Config::MusicVolume; } - *pEffectsVolume = Config::EffectsVolume * Config::MasterVolume; + *pEffectsVolume = Config::EffectsVolume; } // Stub volume setter.