From 4f4167e3c77137345d92fff034a3cb193d348f3e Mon Sep 17 00:00:00 2001 From: sukibaby <163092272+sukibaby@users.noreply.github.com> Date: Sat, 4 Jan 2025 10:08:22 -0800 Subject: [PATCH] Fix DirectSound and set it to default on Windows. I've fixed the issues with the DirectSound driver which a number of commits from 2016 attempted to address. Additionally, build testers strongly prefer the fixed DirectSound to WaveOut (the current default driver for Windows) in terms of both game stability and sync stability, so I'm making it the default driver as well. StepMania commit 75a9532 from 2006 had a subtle error, the declaration of len and locked_buf will hide the previous local declaration of these variables. The issues causing the DirectSound driver to be unreliable in terms of sync were due to this. This PR renames the variables from the 2006 commit to prevent this, and also ensures all variables are properly initialized. Renamed `locked_buf` and `len` in `MixerThread` to `locked_buf_init` and `len_init` to avoid shadowing. Prevent use of uninitialized member variables by initializing `m_pPCM`, `m_iSampleRate`, and `m_bShutdownMixerThread` in the constructor. --- src/arch/Sound/RageSoundDriver_DSound_Software.cpp | 13 ++++++------- src/arch/arch_default.h | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/arch/Sound/RageSoundDriver_DSound_Software.cpp b/src/arch/Sound/RageSoundDriver_DSound_Software.cpp index 128cf5a20b..ff7e3cfb22 100644 --- a/src/arch/Sound/RageSoundDriver_DSound_Software.cpp +++ b/src/arch/Sound/RageSoundDriver_DSound_Software.cpp @@ -29,12 +29,12 @@ void RageSoundDriver_DSound_Software::MixerThread() /* Fill a buffer before we start playing, so we don't play whatever junk is * in the buffer. */ - char *locked_buf; - unsigned len; - while( m_pPCM->get_output_buf(&locked_buf, &len, chunksize()) ) + char *locked_buf_init; + unsigned len_init; + while( m_pPCM->get_output_buf(&locked_buf_init, &len_init, chunksize()) ) { - memset( locked_buf, 0, len ); - m_pPCM->release_output_buf(locked_buf, len); + memset( locked_buf_init, 0, len_init ); + m_pPCM->release_output_buf(locked_buf_init, len_init); } /* Start playing. */ @@ -74,9 +74,8 @@ int RageSoundDriver_DSound_Software::MixerThread_start(void *p) } RageSoundDriver_DSound_Software::RageSoundDriver_DSound_Software() + : m_pPCM(nullptr), m_iSampleRate(0), m_bShutdownMixerThread(false) { - m_bShutdownMixerThread = false; - m_pPCM = nullptr; } RString RageSoundDriver_DSound_Software::Init() diff --git a/src/arch/arch_default.h b/src/arch/arch_default.h index 8d3fab9f18..f0f966788c 100644 --- a/src/arch/arch_default.h +++ b/src/arch/arch_default.h @@ -21,7 +21,7 @@ inline const std::vector& GetDefaultMovieDriverList() { } inline const std::vector& GetDefaultSoundDriverList() { - static const std::vector soundDriverList = { "WaveOut", "DirectSound-sw", "WDMKS", "Null" }; + static const std::vector soundDriverList = { "DirectSound-sw", "WaveOut", "WDMKS", "Null" }; return soundDriverList; }