diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index 1ec7255fbf..5a8b8ae4f5 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -247,6 +247,7 @@ void PrefsManager::Init() * specify numbers directly.) This is purely a troubleshooting option * and is not honored by all sound drivers. */ m_iSoundWriteAhead = 0; + m_iSoundDevice = ""; m_fSoundVolume = DEFAULT_SOUND_VOLUME; m_iSoundResampleQuality = RageSoundReader_Resample::RESAMP_NORMAL; @@ -441,6 +442,7 @@ void PrefsManager::ReadPrefsFromFile( CString sIni ) ini.GetValue( "Options", "MusicWheelSwitchSpeed", m_iMusicWheelSwitchSpeed ); ini.GetValue( "Options", "SoundDrivers", m_sSoundDrivers ); ini.GetValue( "Options", "SoundWriteAhead", m_iSoundWriteAhead ); + ini.GetValue( "Options", "SoundDevice", m_iSoundDevice ); ini.GetValue( "Options", "MovieDrivers", m_sMovieDrivers ); ini.GetValue( "Options", "EasterEggs", m_bEasterEggs ); ini.GetValue( "Options", "MarvelousTiming", (int&)m_iMarvelousTiming ); @@ -770,6 +772,7 @@ void PrefsManager::SaveGlobalPrefsToDisk() const ini.SetValue( "Options", "SignProfileData", m_bSignProfileData ); ini.SetValue( "Options", "SoundWriteAhead", m_iSoundWriteAhead ); + ini.SetValue( "Options", "SoundDevice", m_iSoundDevice ); ini.SetValue( "Editor", "ShowBGChangesPlay", m_bEditorShowBGChangesPlay ); diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index 15b450927c..01acd3f1c9 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -245,6 +245,7 @@ public: bool m_bSmoothLines; CString m_sSoundDrivers; int m_iSoundWriteAhead; + CString m_iSoundDevice; float m_fSoundVolume; int m_iSoundResampleQuality; CString m_sMovieDrivers; diff --git a/stepmania/src/arch/Sound/ALSA9Helpers.cpp b/stepmania/src/arch/Sound/ALSA9Helpers.cpp index 8a77d03f7a..d3ed53109a 100644 --- a/stepmania/src/arch/Sound/ALSA9Helpers.cpp +++ b/stepmania/src/arch/Sound/ALSA9Helpers.cpp @@ -4,6 +4,7 @@ #include "ALSA9Helpers.h" #include "SDL_utils.h" #include "ALSA9Dynamic.h" +#include "PrefsManager.h" /* int err; must be defined before using this macro */ #define ALSA_CHECK(x) \ @@ -153,6 +154,13 @@ void Alsa9Buf::InitializeErrorHandler() dsnd_lib_error_set_handler( ErrorHandler ); } +static CString DeviceName() +{ + if( !PREFSMAN->m_iSoundDevice.empty() ) + return PREFSMAN->m_iSoundDevice; + return "hw:0"; +} + void Alsa9Buf::GetSoundCardDebugInfo() { static bool done = false; @@ -219,10 +227,11 @@ void Alsa9Buf::GetSoundCardDebugInfo() if( card == 0 ) LOG->Info( "No ALSA sound cards were found."); + + if( !PREFSMAN->m_iSoundDevice.empty() ) + LOG->Info( "ALSA device overridden to \"%s\"", PREFSMAN->m_iSoundDevice.c_str() ); } -static CString DeviceName = "hw:0"; - Alsa9Buf::Alsa9Buf( hw hardware, int channels_ ) { GetSoundCardDebugInfo(); @@ -240,9 +249,9 @@ Alsa9Buf::Alsa9Buf( hw hardware, int channels_ ) /* Open the device. */ int err; // err = dsnd_pcm_open( &pcm, "dmix", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK ); - err = dsnd_pcm_open( &pcm, DeviceName, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK ); + err = dsnd_pcm_open( &pcm, DeviceName(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK ); if (err < 0) - RageException::ThrowNonfatal("dsnd_pcm_open: %s", dsnd_strerror(err)); + RageException::ThrowNonfatal("dsnd_pcm_open(%s): %s", DeviceName().c_str(), dsnd_strerror(err)); if( !SetHWParams() ) { @@ -433,7 +442,7 @@ CString Alsa9Buf::GetHardwareID( CString name ) InitializeErrorHandler(); if( name.empty() ) - name = DeviceName; + name = DeviceName(); snd_ctl_t *handle; int err;