From adf36092f7529b3f8fc090ece7521be0ce9ce792 Mon Sep 17 00:00:00 2001 From: spacy51 Date: Wed, 5 Dec 2007 23:22:37 +0000 Subject: [PATCH] added DirectSound <> OpenAL selection OpenAL can be excluded from build with #define NO_OAL --- VBA.vcproj | 328 ++++++++++++++++++----------------- src/win32/MainWnd.cpp | 4 + src/win32/MainWnd.h | 4 + src/win32/MainWndOptions.cpp | 32 ++++ src/win32/OpenAL.cpp | 8 +- src/win32/Sound.h | 7 + src/win32/VBA.cpp | 27 ++- src/win32/VBA.h | 1 + src/win32/VBA.rc | 13 +- src/win32/resource.h | 4 +- 10 files changed, 259 insertions(+), 169 deletions(-) diff --git a/VBA.vcproj b/VBA.vcproj index 0f5197aa..5a118b86 100644 --- a/VBA.vcproj +++ b/VBA.vcproj @@ -1,7 +1,7 @@ + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - @@ -548,6 +538,16 @@ Outputs=""$(IntDir)\$(InputName).obj"" /> + + + @@ -623,16 +623,6 @@ Outputs=""$(IntDir)\$(InputName).obj"" /> - - - @@ -643,6 +633,16 @@ Outputs=""$(IntDir)\$(InputName).obj"" /> + + + @@ -667,16 +667,6 @@ Outputs=""$(IntDir)\$(InputName).obj"" /> - - - @@ -687,6 +677,16 @@ Outputs=""$(IntDir)\$(InputName).obj"" /> + + + @@ -711,16 +711,6 @@ Outputs=""$(IntDir)\$(InputName).obj"" /> - - - @@ -731,6 +721,16 @@ Outputs=""$(IntDir)\$(InputName).obj"" /> + + + @@ -755,16 +755,6 @@ Outputs=""$(IntDir)\$(InputName).obj"" /> - - - @@ -775,6 +765,16 @@ Outputs=""$(IntDir)\$(InputName).obj"" /> + + + @@ -1379,7 +1379,7 @@ /> + + diff --git a/src/win32/MainWnd.cpp b/src/win32/MainWnd.cpp index 25218483..0bb23604 100644 --- a/src/win32/MainWnd.cpp +++ b/src/win32/MainWnd.cpp @@ -452,6 +452,10 @@ BEGIN_MESSAGE_MAP(MainWnd, CWnd) ON_UPDATE_COMMAND_UI(ID_SKIN_USE, &MainWnd::OnUpdateSkinUse) ON_COMMAND(ID_SKIN_SELECT, &MainWnd::OnSkinSelect) ON_UPDATE_COMMAND_UI(ID_SKIN_SELECT, &MainWnd::OnUpdateSkinSelect) + ON_COMMAND(ID_OUTPUTAPI_DIRECTSOUND, &MainWnd::OnOutputapiDirectsound) + ON_UPDATE_COMMAND_UI(ID_OUTPUTAPI_DIRECTSOUND, &MainWnd::OnUpdateOutputapiDirectsound) + ON_COMMAND(ID_OUTPUTAPI_OPENAL, &MainWnd::OnOutputapiOpenal) + ON_UPDATE_COMMAND_UI(ID_OUTPUTAPI_OPENAL, &MainWnd::OnUpdateOutputapiOpenal) END_MESSAGE_MAP() diff --git a/src/win32/MainWnd.h b/src/win32/MainWnd.h index 0f8ec83e..43605e43 100644 --- a/src/win32/MainWnd.h +++ b/src/win32/MainWnd.h @@ -452,6 +452,10 @@ public: afx_msg void OnUpdateSkinUse(CCmdUI *pCmdUI); afx_msg void OnSkinSelect(); afx_msg void OnUpdateSkinSelect(CCmdUI *pCmdUI); + afx_msg void OnOutputapiDirectsound(); + afx_msg void OnUpdateOutputapiDirectsound(CCmdUI *pCmdUI); + afx_msg void OnOutputapiOpenal(); + afx_msg void OnUpdateOutputapiOpenal(CCmdUI *pCmdUI); }; ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win32/MainWndOptions.cpp b/src/win32/MainWndOptions.cpp index 571d3ec8..07d680f1 100644 --- a/src/win32/MainWndOptions.cpp +++ b/src/win32/MainWndOptions.cpp @@ -1975,3 +1975,35 @@ void MainWnd::OnUpdateSkinSelect(CCmdUI *pCmdUI) ); #endif } + +void MainWnd::OnOutputapiDirectsound() +{ + if( theApp.audioAPI != DIRECTSOUND ) { + theApp.audioAPI = DIRECTSOUND; + systemSoundShutdown(); + systemSoundInit(); + } +} + +void MainWnd::OnUpdateOutputapiDirectsound(CCmdUI *pCmdUI) +{ + pCmdUI->SetCheck( ( theApp.audioAPI == DIRECTSOUND ) ? 1 : 0 ); +} + +void MainWnd::OnOutputapiOpenal() +{ +#ifndef NO_OAL + if( theApp.audioAPI != OPENAL ) { + theApp.audioAPI = OPENAL; + systemSoundShutdown(); + systemSoundInit(); + } +#endif +} + +void MainWnd::OnUpdateOutputapiOpenal(CCmdUI *pCmdUI) +{ +#ifndef NO_OAL + pCmdUI->SetCheck( ( theApp.audioAPI == OPENAL ) ? 1 : 0 ); +#endif +} diff --git a/src/win32/OpenAL.cpp b/src/win32/OpenAL.cpp index c0044dac..2afb03d4 100644 --- a/src/win32/OpenAL.cpp +++ b/src/win32/OpenAL.cpp @@ -15,7 +15,9 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "stdafx.h" // includes VBA.h +#ifndef NO_OAL + +#include "stdafx.h" // includes VBA.h for 'theApp.throttle' // Interface #include "Sound.h" @@ -26,7 +28,7 @@ #pragma comment( lib, "OpenAL32.lib" ) // Windows -#include // for Sleep() and OutputDebugString() +#include // for 'Sleep' function // Internals #include "../Sound.h" @@ -329,3 +331,5 @@ ISound *newOpenAL() winlog( "newOpenAL\n" ); return new OpenAL(); } + +#endif \ No newline at end of file diff --git a/src/win32/Sound.h b/src/win32/Sound.h index 06fb7b09..a87b4fdf 100644 --- a/src/win32/Sound.h +++ b/src/win32/Sound.h @@ -20,6 +20,13 @@ #ifndef VBA_WIN32_SOUND_H #define VBA_WIN32_SOUND_H +enum AUDIO_API { + DIRECTSOUND +#ifndef NO_OAL + , OPENAL +#endif +}; + class ISound { public: diff --git a/src/win32/VBA.cpp b/src/win32/VBA.cpp index b7a8166b..0690d8c8 100644 --- a/src/win32/VBA.cpp +++ b/src/win32/VBA.cpp @@ -108,6 +108,9 @@ extern IDisplay *newDirect3DDisplay(); extern Input *newDirectInput(); extern ISound *newDirectSound(); +#ifndef NO_OAL +extern ISound *newOpenAL(); +#endif extern void remoteStubSignal(int, int); extern void remoteOutput(char *, u32); @@ -274,6 +277,7 @@ VBA::VBA() changingVideoSize = false; pVideoDriverGUID = NULL; renderMethod = DIRECT_DRAW; + audioAPI = DIRECTSOUND; iconic = false; ddrawEmulationOnly = false; ddrawUsingEmulationOnly = false; @@ -1189,7 +1193,18 @@ bool systemSoundInit() if(theApp.sound) delete theApp.sound; - theApp.sound = newDirectSound(); + switch( theApp.audioAPI ) + { + case DIRECTSOUND: + theApp.sound = newDirectSound(); + break; +#ifndef NO_OAL + case OPENAL: + theApp.sound = newOpenAL(); + break; +#endif + } + return theApp.sound->init(); } @@ -1396,6 +1411,15 @@ void VBA::loadSettings() renderMethod = DIRECT_DRAW; } + audioAPI = (AUDIO_API)regQueryDwordValue( "audioAPI", DIRECTSOUND ); + if( ( audioAPI != DIRECTSOUND ) +#ifndef NO_OAL + && ( audioAPI != OPENAL ) +#endif + ) { + audioAPI = DIRECTSOUND; + } + windowPositionX = regQueryDwordValue("windowX", 0); if(windowPositionX < 0) windowPositionX = 0; @@ -2479,6 +2503,7 @@ void VBA::saveSettings() regSetDwordValue("fsFrequency", fsFrequency); regSetDwordValue("renderMethod", renderMethod); + regSetDwordValue( "audioAPI", audioAPI ); regSetDwordValue("windowX", windowPositionX); regSetDwordValue("windowY", windowPositionY); diff --git a/src/win32/VBA.h b/src/win32/VBA.h index 6850ed4f..9cae5d49 100644 --- a/src/win32/VBA.h +++ b/src/win32/VBA.h @@ -152,6 +152,7 @@ class VBA : public CWinApp GUID videoDriverGUID; GUID *pVideoDriverGUID; DISPLAY_TYPE renderMethod; + AUDIO_API audioAPI; bool iconic; bool ddrawEmulationOnly; bool ddrawUsingEmulationOnly; diff --git a/src/win32/VBA.rc b/src/win32/VBA.rc index 0779002f..4b0b1912 100644 --- a/src/win32/VBA.rc +++ b/src/win32/VBA.rc @@ -1654,12 +1654,19 @@ BEGIN END POPUP "&Audio" BEGIN + POPUP "Output API" + BEGIN + MENUITEM "DirectSound", ID_OUTPUTAPI_DIRECTSOUND + MENUITEM " Use &old synchronization", ID_OPTIONS_SOUND_USEOLDSYNCHRONIZATION + MENUITEM SEPARATOR + MENUITEM "OpenAL", ID_OUTPUTAPI_OPENAL + MENUITEM SEPARATOR + MENUITEM "&Sync game to audio", ID_OPTIONS_EMULATOR_SYNCHRONIZE + END + MENUITEM SEPARATOR MENUITEM "&On", ID_OPTIONS_SOUND_ON MENUITEM "O&ff", ID_OPTIONS_SOUND_OFF MENUITEM SEPARATOR - MENUITEM "&Sync game to audio", ID_OPTIONS_EMULATOR_SYNCHRONIZE - MENUITEM "Use &old synchronization", ID_OPTIONS_SOUND_USEOLDSYNCHRONIZATION - MENUITEM SEPARATOR POPUP "&Volume" BEGIN MENUITEM "&Mute", ID_OPTIONS_SOUND_MUTE diff --git a/src/win32/resource.h b/src/win32/resource.h index a805a3ab..60aa37b3 100644 --- a/src/win32/resource.h +++ b/src/win32/resource.h @@ -804,13 +804,15 @@ #define ID_OPTIONS_FILTER_PLUGIN 40343 #define ID_OPTIONS_SELECT_PLUGIN 40344 #define IDC_COMBO_PLUGIN 40345 +#define ID_OUTPUTAPI_DIRECTSOUND 40346 +#define ID_OUTPUTAPI_OPENAL 40347 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 159 -#define _APS_NEXT_COMMAND_VALUE 40343 +#define _APS_NEXT_COMMAND_VALUE 40348 #define _APS_NEXT_CONTROL_VALUE 1269 #define _APS_NEXT_SYMED_VALUE 103 #endif