From a67fe271a9fcdecdc3ce65fd94d8a4b9973156b3 Mon Sep 17 00:00:00 2001 From: bgk Date: Fri, 26 Dec 2008 20:11:33 +0000 Subject: [PATCH] Fixed MFC for my previous commit --- src/Sound.cpp | 20 +++++++++-- src/Sound.h | 1 + src/System.h | 2 ++ src/gtk/system.cpp | 8 +++++ src/sdl/SDL.cpp | 8 +++++ src/win32/DirectSound.cpp | 1 + src/win32/MainWndOptions.cpp | 24 +++++++------- src/win32/MainWndTools.cpp | 2 +- src/win32/VBA.cpp | 64 +++++++++--------------------------- src/win32/VBA.h | 2 -- 10 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/Sound.cpp b/src/Sound.cpp index a408a168..91f83ede 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -365,6 +365,7 @@ void flush_samples(Multi_Buffer * buffer) soundResume(); soundDriver->write(soundFinalWave, soundBufferLen); + systemOnWriteDataToSoundBuffer(soundFinalWave, soundBufferLen); } } @@ -469,19 +470,27 @@ static void remake_stereo_buffer() void soundShutdown() { - delete soundDriver; + if (soundDriver) + { + delete soundDriver; + soundDriver = 0; + } + + systemOnSoundShutdown(); } void soundPause() { soundPaused = true; - soundDriver->pause(); + if (soundDriver) + soundDriver->pause(); } void soundResume() { soundPaused = false; - soundDriver->resume(); + if (soundDriver) + soundDriver->resume(); } void soundSetVolume( float volume ) @@ -532,6 +541,11 @@ bool soundInit() return true; } +int soundGetQuality() +{ + return soundQuality; +} + void soundSetQuality(int quality) { if ( soundQuality != quality ) diff --git a/src/Sound.h b/src/Sound.h index 8fe9a154..8e0837c1 100644 --- a/src/Sound.h +++ b/src/Sound.h @@ -36,6 +36,7 @@ void soundShutdown(); //// GBA sound options // Sets sample rate to 44100 / quality +int soundGetQuality(); void soundSetQuality( int quality ); // Sound settings diff --git a/src/System.h b/src/System.h index 543f81b9..e0228f9d 100644 --- a/src/System.h +++ b/src/System.h @@ -67,6 +67,8 @@ extern u32 systemGetClock(); extern void systemMessage(int, const char *, ...); extern void systemSetTitle(const char *); extern SoundDriver * systemSoundInit(); +extern void systemOnWriteDataToSoundBuffer(const u16 * finalWave, int length); +extern void systemOnSoundShutdown(); extern void systemScreenMessage(const char *); extern void systemUpdateMotionSensor(); extern int systemGetSensorX(); diff --git a/src/gtk/system.cpp b/src/gtk/system.cpp index 93796f76..2f1583c9 100644 --- a/src/gtk/system.cpp +++ b/src/gtk/system.cpp @@ -161,6 +161,14 @@ SoundDriver * systemSoundInit() return new SoundSDL(); } +void systemOnSoundShutdown() +{ +} + +void systemOnWriteDataToSoundBuffer(const u16 * finalWave, int length) +{ +} + void debuggerMain() { } diff --git a/src/sdl/SDL.cpp b/src/sdl/SDL.cpp index f37a229b..5e4fb15b 100644 --- a/src/sdl/SDL.cpp +++ b/src/sdl/SDL.cpp @@ -2716,3 +2716,11 @@ SoundDriver * systemSoundInit() return new SoundSDL(); } + +void systemOnSoundShutdown() +{ +} + +void systemOnWriteDataToSoundBuffer(const u16 * finalWave, int length) +{ +} diff --git a/src/win32/DirectSound.cpp b/src/win32/DirectSound.cpp index 1e5872d6..f45f540e 100644 --- a/src/win32/DirectSound.cpp +++ b/src/win32/DirectSound.cpp @@ -10,6 +10,7 @@ #include "../agb/GBA.h" #include "../Globals.h" #include "../Sound.h" +#include "../common/SoundDriver.h" // DirectSound8 #include diff --git a/src/win32/MainWndOptions.cpp b/src/win32/MainWndOptions.cpp index 8e04ad50..3f8d67ee 100644 --- a/src/win32/MainWndOptions.cpp +++ b/src/win32/MainWndOptions.cpp @@ -1531,8 +1531,8 @@ void MainWnd::OnUpdateOptionsEmulatorGameoverrides(CCmdUI* pCmdUI) void MainWnd::OnOptionsSoundHardwareacceleration() { theApp.dsoundDisableHardwareAcceleration = !theApp.dsoundDisableHardwareAcceleration; - systemSoundShutdown(); - systemSoundInit(); + soundShutdown(); + soundInit(); } void MainWnd::OnUpdateOptionsSoundHardwareacceleration(CCmdUI *pCmdUI) @@ -1556,8 +1556,8 @@ void MainWnd::OnOutputapiDirectsound() { if( theApp.audioAPI != DIRECTSOUND ) { theApp.audioAPI = DIRECTSOUND; - systemSoundShutdown(); - systemSoundInit(); + soundShutdown(); + soundInit(); } } @@ -1572,8 +1572,8 @@ void MainWnd::OnOutputapiXaudio2() #ifndef NO_XAUDIO2 if( theApp.audioAPI != XAUDIO2 ) { theApp.audioAPI = XAUDIO2; - systemSoundShutdown(); - systemSoundInit(); + soundShutdown(); + soundInit(); } #endif } @@ -1593,8 +1593,8 @@ void MainWnd::OnOutputapiOpenal() #ifndef NO_OAL if( theApp.audioAPI != OPENAL_SOUND ) { theApp.audioAPI = OPENAL_SOUND; - systemSoundShutdown(); - systemSoundInit(); + soundShutdown(); + soundInit(); } #endif } @@ -1618,7 +1618,7 @@ void MainWnd::OnOutputapiOalconfiguration() dlg.bufferCount = theApp.oalBufferCount; if( dlg.DoModal() == IDOK ) { - systemSoundShutdown(); + soundShutdown(); // do this before changing any values OpenAL // might need for successful cleanup @@ -1631,7 +1631,7 @@ void MainWnd::OnOutputapiOalconfiguration() _tcscpy( theApp.oalDevice, dlg.selectedDevice.GetBuffer() ); theApp.oalBufferCount = dlg.bufferCount; - systemSoundInit(); + soundInit(); } #endif } @@ -1655,13 +1655,13 @@ void MainWnd::OnOutputapiXaudio2config() dlg.m_enable_upmixing = theApp.xa2Upmixing; if( dlg.DoModal() == IDOK ) { - systemSoundShutdown(); + soundShutdown(); theApp.xa2Device = dlg.m_selected_device_index; theApp.xa2BufferCount = dlg.m_buffer_count; theApp.xa2Upmixing = dlg.m_enable_upmixing; - systemSoundInit(); + soundInit(); } #endif } diff --git a/src/win32/MainWndTools.cpp b/src/win32/MainWndTools.cpp index 20495feb..a3ff0754 100644 --- a/src/win32/MainWndTools.cpp +++ b/src/win32/MainWndTools.cpp @@ -397,7 +397,7 @@ void MainWnd::OnToolsRecordStartavirecording() // add audio stream ret = theApp.aviRecorder->CreateAudioStream( 2, - 44100 / soundQuality, + 44100 / soundGetQuality(), 16, this->GetSafeHwnd() ); diff --git a/src/win32/VBA.cpp b/src/win32/VBA.cpp index abea8d73..9f771113 100644 --- a/src/win32/VBA.cpp +++ b/src/win32/VBA.cpp @@ -30,6 +30,7 @@ #include "../dmg/gbGlobals.h" #include "../dmg/gbPrinter.h" #include "../dmg/gbSound.h" +#include "../common/SoundDriver.h" /* Link ---------------------*/ @@ -291,7 +292,6 @@ VBA::VBA() soundRecording = false; soundRecorder = NULL; dsoundDisableHardwareAcceleration = true; - sound = NULL; aviRecording = false; aviRecorder = NULL; painting = false; @@ -960,9 +960,8 @@ void VBA::updateThrottle( unsigned short throttle ) systemFrameSkip = 0; } - if( theApp.sound ) { - theApp.sound->setThrottle( throttle ); - } + soundShutdown(); + soundInit(); } @@ -1235,39 +1234,37 @@ int systemGetSensorY() } -bool systemSoundInit() +SoundDriver * systemSoundInit() { - systemSoundShutdown(); + SoundDriver * drv = 0; + soundShutdown(); switch( theApp.audioAPI ) { case DIRECTSOUND: - theApp.sound = newDirectSound(); + drv = newDirectSound(); break; #ifndef NO_OAL case OPENAL_SOUND: - theApp.sound = newOpenAL(); + drv = newOpenAL(); break; #endif #ifndef NO_XAUDIO2 case XAUDIO2: - theApp.sound = newXAudio2_Output(); + drv = newXAudio2_Output(); break; #endif } - bool retVal = theApp.sound->init(soundQuality); - soundBufferLen = theApp.sound->getBufferLength(); - - if( retVal ) { - theApp.sound->setThrottle( theApp.throttle ); + if( drv ) { + drv->setThrottle( theApp.throttle ); } - return retVal; + return drv; } -void systemSoundShutdown() +void systemOnSoundShutdown() { if( theApp.aviRecorder ) { delete theApp.aviRecorder; @@ -1281,38 +1278,13 @@ void systemSoundShutdown() theApp.soundRecorder = NULL; } theApp.soundRecording = false; - - - if( theApp.sound ) { - delete theApp.sound; - theApp.sound = NULL; - } } - -void systemSoundPause() -{ - if(theApp.sound) - theApp.sound->pause(); -} - -void systemSoundReset() -{ - if(theApp.sound) - theApp.sound->reset(); -} - -void systemSoundResume() -{ - if(theApp.sound) - theApp.sound->resume(); -} - -void systemWriteDataToSoundBuffer() +void systemOnWriteDataToSoundBuffer(const u16 * finalWave, int length) { if( theApp.soundRecording ) { if( theApp.soundRecorder ) { - theApp.soundRecorder->AddSound( (const u8 *)soundFinalWave, soundBufferLen ); + theApp.soundRecorder->AddSound( (const u8 *)finalWave, length ); } else { WAVEFORMATEX format; format.cbSize = 0; @@ -1333,7 +1305,7 @@ void systemWriteDataToSoundBuffer() if( theApp.skipAudioFrames ) { theApp.skipAudioFrames--; } else { - if( false == theApp.aviRecorder->AddAudioFrame( soundFinalWave ) ) { + if( false == theApp.aviRecorder->AddAudioFrame( ( u8 *)finalWave ) ) { systemMessage( IDS_AVI_CANNOT_WRITE_AUDIO, "Cannot write audio frame to AVI file." ); delete theApp.aviRecorder; theApp.aviRecorder = NULL; @@ -1341,10 +1313,6 @@ void systemWriteDataToSoundBuffer() } } } - - if( theApp.sound ) { - theApp.sound->write(soundFinalWave, soundBufferLen); - } } bool systemCanChangeSoundQuality() diff --git a/src/win32/VBA.h b/src/win32/VBA.h index eaa976d8..150eab14 100644 --- a/src/win32/VBA.h +++ b/src/win32/VBA.h @@ -11,7 +11,6 @@ #include "Display.h" #include "Input.h" #include "IUpdate.h" -#include "../common/SoundDriver.h" #include "../System.h" #include "../Util.h" @@ -170,7 +169,6 @@ class VBA : public CWinApp WavWriter *soundRecorder; CString soundRecordName; bool dsoundDisableHardwareAcceleration; - SoundDriver *sound; bool aviRecording; AVIWrite *aviRecorder; CString aviRecordName;