From 437be084a970f1fdd8c7ce4fea60afe5d76a8efd Mon Sep 17 00:00:00 2001 From: bgk Date: Tue, 30 Dec 2008 11:09:37 +0000 Subject: [PATCH] More conversion from sound quality to sample rate. git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@828 a31d4220-a93d-0410-bf67-fe4944624d44 --- src/Sound.cpp | 14 ++++++-------- src/Sound.h | 5 ++--- src/dmg/gbSound.cpp | 12 +++++------- src/dmg/gbSound.h | 3 +-- src/gtk/soundconfig.cpp | 19 +++++++++++-------- src/gtk/window.cpp | 26 +++++++++++++------------- src/gtk/window.h | 13 +++---------- src/sdl/SDL.cpp | 2 +- 8 files changed, 42 insertions(+), 52 deletions(-) diff --git a/src/Sound.cpp b/src/Sound.cpp index 2f7b91d9..101750ba 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -540,26 +540,24 @@ bool soundInit() return true; } -int soundGetQuality() +long soundGetSampleRate() { - return 44100 / soundSampleRate; + return soundSampleRate; } -void soundSetQuality(int quality) +void soundSetSampleRate(long sampleRate) { - long newSampleRate = 44100 / quality; - - if ( soundSampleRate != newSampleRate ) + if ( soundSampleRate != sampleRate ) { if ( systemCanChangeSoundQuality() ) { soundShutdown(); - soundSampleRate = newSampleRate; + soundSampleRate = sampleRate; soundInit(); } else { - soundSampleRate = newSampleRate; + soundSampleRate = sampleRate; } remake_stereo_buffer(); diff --git a/src/Sound.h b/src/Sound.h index 8e0837c1..7c2ef7a8 100644 --- a/src/Sound.h +++ b/src/Sound.h @@ -35,9 +35,8 @@ void soundShutdown(); //// GBA sound options -// Sets sample rate to 44100 / quality -int soundGetQuality(); -void soundSetQuality( int quality ); +long soundGetSampleRate(); +void soundSetSampleRate(long sampleRate); // Sound settings extern bool soundInterpolation; // 1 if PCM should have low-pass filtering diff --git a/src/dmg/gbSound.cpp b/src/dmg/gbSound.cpp index 13e9ebba..7239b02a 100644 --- a/src/dmg/gbSound.cpp +++ b/src/dmg/gbSound.cpp @@ -216,21 +216,19 @@ void gbSoundReset() } } -void gbSoundSetQuality(int quality) +void gbSoundSetSampleRate( long sampleRate ) { - long newSampleRate = 44100 / quality; - - if ( soundSampleRate != newSampleRate ) + if ( soundSampleRate != sampleRate ) { if ( systemCanChangeSoundQuality() ) { soundShutdown(); - soundSampleRate = newSampleRate; + soundSampleRate = sampleRate; soundInit(); } else { - soundSampleRate = newSampleRate; + soundSampleRate = sampleRate; } remake_stereo_buffer(); @@ -367,7 +365,7 @@ static void gbSoundReadGameOld(int version,gzFile gzFile) if ( version >= 7 ) quality = utilReadInt( gzFile ); - gbSoundSetQuality( quality ); + gbSoundSetSampleRate( 44100 / quality ); // Convert to format Gb_Apu uses gb_apu_state_t& s = state.apu; diff --git a/src/dmg/gbSound.h b/src/dmg/gbSound.h index 07834093..47ecf2e4 100644 --- a/src/dmg/gbSound.h +++ b/src/dmg/gbSound.h @@ -7,8 +7,7 @@ //// GB sound options -// Sets sample rate to 44100 / quality -void gbSoundSetQuality( int quality ); +void gbSoundSetSampleRate( long sampleRate ); // Manages declicking mode. When enabled, clicks are reduced. Note that clicks // are normal for GB and GBC sound hardware. diff --git a/src/gtk/soundconfig.cpp b/src/gtk/soundconfig.cpp index 6681cf8f..488d5220 100644 --- a/src/gtk/soundconfig.cpp +++ b/src/gtk/soundconfig.cpp @@ -57,16 +57,17 @@ void SoundConfigDialog::vSetConfig(Config::Section * _poConfig, VBA::Window * _p else m_poVolumeComboBox->set_active(3); - VBA::Window::ESoundQuality eSoundQuality = (VBA::Window::ESoundQuality)m_poConfig->oGetKey("quality"); - switch (eSoundQuality) + long iSoundSampleRate = m_poConfig->oGetKey("sample_rate"); + switch (iSoundSampleRate) { - case VBA::Window::Sound44K: + default: + case 44100: m_poRateComboBox->set_active(2); break; - case VBA::Window::Sound22K: + case 22050: m_poRateComboBox->set_active(1); break; - case VBA::Window::Sound11K: + case 11025: m_poRateComboBox->set_active(0); break; } @@ -110,16 +111,18 @@ void SoundConfigDialog::vOnRateChanged() switch (iRate) { case 0: // 11 KHz - m_poConfig->vSetKey("quality", VBA::Window::Sound11K); + m_poConfig->vSetKey("sample_rate", 11025); break; case 1: // 22 KHz - m_poConfig->vSetKey("quality", VBA::Window::Sound22K); + m_poConfig->vSetKey("sample_rate", 22050); break; case 2: // 44 KHz default: - m_poConfig->vSetKey("quality", VBA::Window::Sound44K); + m_poConfig->vSetKey("sample_rate", 44100); break; } + + m_poWindow->vApplyConfigSoundSampleRate(); } } // namespace VBA diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index b6e9f309..effd2f09 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -91,8 +91,8 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : m_iShowSpeedMax (ShowDetailed), m_iSaveTypeMin (SaveAuto), m_iSaveTypeMax (SaveNone), - m_iSoundQualityMin(Sound44K), - m_iSoundQualityMax(Sound11K), + m_iSoundSampleRateMin(11025), + m_iSoundSampleRateMax(44100), m_fSoundVolumeMin (0.50f), m_fSoundVolumeMax (2.00f), m_iEmulatorTypeMin(EmulatorAuto), @@ -692,9 +692,9 @@ void Window::vInitConfig() // Sound section // m_poSoundConfig = m_oConfig.poAddSection("Sound"); - m_poSoundConfig->vSetKey("mute", false ); - m_poSoundConfig->vSetKey("quality", Sound44K ); - m_poSoundConfig->vSetKey("volume", 1.00f ); + m_poSoundConfig->vSetKey("mute", false ); + m_poSoundConfig->vSetKey("sample_rate", 44100 ); + m_poSoundConfig->vSetKey("volume", 1.00f ); // Input section // @@ -834,11 +834,11 @@ void Window::vCheckConfig() // Sound section // - iValue = m_poSoundConfig->oGetKey("quality"); - iAdjusted = CLAMP(iValue, m_iSoundQualityMin, m_iSoundQualityMax); + iValue = m_poSoundConfig->oGetKey("sample_rate"); + iAdjusted = CLAMP(iValue, m_iSoundSampleRateMin, m_iSoundSampleRateMax); if (iValue != iAdjusted) { - m_poSoundConfig->vSetKey("quality", iAdjusted); + m_poSoundConfig->vSetKey("sample_rate", iAdjusted); } fValue = m_poSoundConfig->oGetKey("volume"); @@ -921,16 +921,16 @@ void Window::vApplyConfigVolume() soundSetVolume(fSoundVolume); } -void Window::vApplyConfigSoundQuality() +void Window::vApplyConfigSoundSampleRate() { - ESoundQuality eSoundQuality = (ESoundQuality)m_poSoundConfig->oGetKey("quality"); + long iSoundSampleRate = m_poSoundConfig->oGetKey("sample_rate"); if (m_eCartridge == CartridgeGBA) { - soundSetQuality(eSoundQuality); + soundSetSampleRate(iSoundSampleRate); } else if (m_eCartridge == CartridgeGB) { - gbSoundSetQuality(eSoundQuality); + gbSoundSetSampleRate(iSoundSampleRate); } } @@ -1076,7 +1076,7 @@ bool Window::bLoadROM(const std::string & _rsFile) emulating = 1; m_bWasEmulating = false; - vApplyConfigSoundQuality(); + vApplyConfigSoundSampleRate(); vUpdateGameSlots(); vHistoryAdd(_rsFile); diff --git a/src/gtk/window.h b/src/gtk/window.h index e91b2810..65912f6f 100644 --- a/src/gtk/window.h +++ b/src/gtk/window.h @@ -61,13 +61,6 @@ public: OutputXvideo }; - enum ESoundQuality - { - Sound44K = 1, - Sound22K = 2, - Sound11K = 4 - }; - // GB/GBA screen sizes const int m_iGBScreenWidth; const int m_iGBScreenHeight; @@ -88,7 +81,7 @@ public: void vApplyConfigScreenArea(); void vApplyConfigMute(); void vApplyConfigVolume(); - void vApplyConfigSoundQuality(); + void vApplyConfigSoundSampleRate(); void vUpdateScreen(); inline ECartridge eGetCartridge() const { return m_eCartridge; } @@ -185,8 +178,8 @@ private: const int m_iShowSpeedMax; const int m_iSaveTypeMin; const int m_iSaveTypeMax; - const int m_iSoundQualityMin; - const int m_iSoundQualityMax; + const int m_iSoundSampleRateMin; + const int m_iSoundSampleRateMax; const float m_fSoundVolumeMin; const float m_fSoundVolumeMax; const int m_iEmulatorTypeMin; diff --git a/src/sdl/SDL.cpp b/src/sdl/SDL.cpp index 86ebc42b..7f84fed4 100644 --- a/src/sdl/SDL.cpp +++ b/src/sdl/SDL.cpp @@ -733,7 +733,7 @@ void sdlReadPreferences(FILE *f) soundQuality = 2; break; } - soundSetQuality(soundQuality); + soundSetSampleRate(44100 / soundQuality); } else if(!strcmp(key, "soundEnable")) { int res = sdlFromHex(value) & 0x30f; soundSetEnable(res);