diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index ce0e05ddb..7adb300af 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -522,6 +522,8 @@ extern struct TCommonSettings { , ConsoleType(NDS_CONSOLE_TYPE_FAT) , StylusJitter(false) , backupSave(false) + , SPU_sync_mode(0) + , SPU_sync_method(0) { strcpy(ARM9BIOS, "biosnds9.bin"); strcpy(ARM7BIOS, "biosnds7.bin"); @@ -614,6 +616,9 @@ extern struct TCommonSettings { int manualBackupType; bool backupSave; + int SPU_sync_mode; + int SPU_sync_method; + bool spu_muteChannels[16]; bool spu_captureMuted; bool spu_advanced; diff --git a/desmume/src/SPU.cpp b/desmume/src/SPU.cpp index 715b77e9f..996f21866 100644 --- a/desmume/src/SPU.cpp +++ b/desmume/src/SPU.cpp @@ -217,6 +217,8 @@ int SPU_Init(int coreid, int buffersize) } } + SPU_SetSynchMode(CommonSettings.SPU_sync_mode, CommonSettings.SPU_sync_method); + return SPU_ChangeSoundCore(coreid, buffersize); } diff --git a/desmume/src/commandline.cpp b/desmume/src/commandline.cpp index 84df1fae2..2be2e2deb 100644 --- a/desmume/src/commandline.cpp +++ b/desmume/src/commandline.cpp @@ -44,6 +44,8 @@ CommandLine::CommandLine() , _bios_arm9(NULL) , _bios_arm7(NULL) , _bios_swi(0) +, _spu_sync_mode(-1) +, _spu_sync_method(-1) , _spu_advanced(0) , _num_cores(-1) , _rigorous_timing(0) @@ -93,6 +95,8 @@ void CommandLine::loadCommonOptions() { "bios-arm9", 0, 0, G_OPTION_ARG_FILENAME, &_bios_arm9, "Uses the arm9 bios provided at the specified path", "BIOS_ARM9_PATH"}, { "bios-arm7", 0, 0, G_OPTION_ARG_FILENAME, &_bios_arm7, "Uses the arm7 bios provided at the specified path", "BIOS_ARM7_PATH"}, { "bios-swi", 0, 0, G_OPTION_ARG_INT, &_bios_swi, "Uses SWI from the provided bios files", "BIOS_SWI"}, + { "spu-mode", 0, 0, G_OPTION_ARG_INT, &_spu_sync_mode, "Select SPU Synchronization Mode. 0 - Dual SPU Synch/Asynch (traditional), 1 - Synchronous (sometimes needed for streams) (default 0)", "SPU_MODE"}, + { "spu-method", 0, 0, G_OPTION_ARG_INT, &_spu_sync_method, "Select SPU Synchronizer Method. 0 - N, 1 - Z, 2 - P (default 0)", "SPU_SYNC_METHOD"}, { "spu-advanced", 0, 0, G_OPTION_ARG_INT, &_spu_advanced, "Uses advanced SPU capture functions", "SPU_ADVANCED"}, { "num-cores", 0, 0, G_OPTION_ARG_INT, &_num_cores, "Override numcores detection and use this many", "NUM_CORES"}, { "scanline-filter-a", 0, 0, G_OPTION_ARG_INT, &_scanline_filter_a, "Intensity of fadeout for scanlines filter (topleft) (default 0)", "SCANLINE_FILTER_A"}, @@ -192,6 +196,8 @@ bool CommandLine::parse(int argc,char **argv) if(_bios_arm9) { CommonSettings.UseExtBIOS = true; strcpy(CommonSettings.ARM9BIOS,_bios_arm9); } if(_bios_arm7) { CommonSettings.UseExtBIOS = true; strcpy(CommonSettings.ARM7BIOS,_bios_arm7); } if(_bios_swi) CommonSettings.SWIFromBIOS = true; + if(_spu_sync_mode != -1) CommonSettings.SPU_sync_mode = _spu_sync_mode; + if(_spu_sync_method != -1) CommonSettings.SPU_sync_method = _spu_sync_method; if(_spu_advanced) CommonSettings.spu_advanced = true; if (argc == 2) @@ -219,6 +225,16 @@ bool CommandLine::validate() return false; } + if (_spu_sync_mode < -1 || _spu_sync_mode > 1) { + g_printerr("Invalid parameter\n"); + return false; + } + + if (_spu_sync_method < -1 || _spu_sync_method > 2) { + g_printerr("Invalid parameter\n"); + return false; + } + if (load_slot < -1 || load_slot > 10) { g_printerr("I only know how to load from slots 0-10; -1 means 'do not load savegame' and is default\n"); return false; diff --git a/desmume/src/commandline.h b/desmume/src/commandline.h index 51cd3fc9e..407cd4dac 100644 --- a/desmume/src/commandline.h +++ b/desmume/src/commandline.h @@ -79,6 +79,8 @@ public: GError *error; GOptionContext *ctx; + int _spu_sync_mode; + int _spu_sync_method; private: char* _play_movie_file; char* _record_movie_file; diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index ef7fa95e2..51059d7ed 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -482,8 +482,6 @@ extern bool userTouchesScreen; static int sndcoretype=SNDCORE_DIRECTX; static int sndbuffersize=DESMUME_SAMPLE_RATE*8/60; -static int snd_synchmode=0; -static int snd_synchmethod=0; int sndvolume=100; SoundInterface_struct *SNDCoreList[] = { @@ -3352,13 +3350,11 @@ int _main() sndvolume = GetPrivateProfileInt("Sound","Volume",100, IniName); SPU_SetVolume(sndvolume); - snd_synchmode = GetPrivateProfileInt("Sound","SynchMode",0,IniName); - snd_synchmethod = GetPrivateProfileInt("Sound","SynchMethod",0,IniName); - { - Lock lock; - SPU_SetSynchMode(snd_synchmode,snd_synchmethod); - } - + if (cmdline._spu_sync_mode == -1) + CommonSettings.SPU_sync_mode = GetPrivateProfileInt("Sound","SynchMode",0,IniName); + if (cmdline._spu_sync_method == -1) + CommonSettings.SPU_sync_method = GetPrivateProfileInt("Sound","SynchMethod",0,IniName); + CommonSettings.DebugConsole = GetPrivateProfileBool("Emulation", "DebugConsole", false, IniName); CommonSettings.EnsataEmulation = GetPrivateProfileBool("Emulation", "EnsataEmulation", false, IniName); CommonSettings.UseExtBIOS = GetPrivateProfileBool("BIOS", "UseExtBIOS", false, IniName); @@ -6818,14 +6814,14 @@ static LRESULT CALLBACK SoundSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam } //update the synch mode - CheckDlgItem(hDlg,IDC_SYNCHMODE_DUAL,snd_synchmode==0); - CheckDlgItem(hDlg,IDC_SYNCHMODE_SYNCH,snd_synchmode==1); + CheckDlgItem(hDlg,IDC_SYNCHMODE_DUAL, CommonSettings.SPU_sync_mode==0); + CheckDlgItem(hDlg,IDC_SYNCHMODE_SYNCH,CommonSettings.SPU_sync_mode==1); SoundSettings_updateSynchMode(hDlg); //update the synch method - CheckDlgItem(hDlg,IDC_SYNCHMETHOD_N,snd_synchmethod==0); - CheckDlgItem(hDlg,IDC_SYNCHMETHOD_Z,snd_synchmethod==1); - CheckDlgItem(hDlg,IDC_SYNCHMETHOD_P,snd_synchmethod==2); + CheckDlgItem(hDlg,IDC_SYNCHMETHOD_N, CommonSettings.SPU_sync_method==0); + CheckDlgItem(hDlg,IDC_SYNCHMETHOD_Z, CommonSettings.SPU_sync_method==1); + CheckDlgItem(hDlg,IDC_SYNCHMETHOD_P, CommonSettings.SPU_sync_method==2); //setup interpolation combobox SendDlgItemMessage(hDlg, IDC_SPU_INTERPOLATION_CB, CB_RESETCONTENT, 0, 0); @@ -6905,19 +6901,19 @@ static LRESULT CALLBACK SoundSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam SPU_SetVolume(sndvolume); //save the synch mode - if(IsDlgCheckboxChecked(hDlg,IDC_SYNCHMODE_DUAL)) snd_synchmode = 0; - if(IsDlgCheckboxChecked(hDlg,IDC_SYNCHMODE_SYNCH)) snd_synchmode = 1; - WritePrivateProfileInt("Sound", "SynchMode", snd_synchmode, IniName); + if(IsDlgCheckboxChecked(hDlg,IDC_SYNCHMODE_DUAL)) CommonSettings.SPU_sync_mode = 0; + if(IsDlgCheckboxChecked(hDlg,IDC_SYNCHMODE_SYNCH)) CommonSettings.SPU_sync_mode = 1; + WritePrivateProfileInt("Sound", "SynchMode", CommonSettings.SPU_sync_mode, IniName); //save the synch method - if(IsDlgCheckboxChecked(hDlg,IDC_SYNCHMETHOD_N)) snd_synchmethod = 0; - if(IsDlgCheckboxChecked(hDlg,IDC_SYNCHMETHOD_Z)) snd_synchmethod = 1; - if(IsDlgCheckboxChecked(hDlg,IDC_SYNCHMETHOD_P)) snd_synchmethod = 2; - WritePrivateProfileInt("Sound", "SynchMethod", snd_synchmethod, IniName); + if(IsDlgCheckboxChecked(hDlg,IDC_SYNCHMETHOD_N)) CommonSettings.SPU_sync_method = 0; + if(IsDlgCheckboxChecked(hDlg,IDC_SYNCHMETHOD_Z)) CommonSettings.SPU_sync_method = 1; + if(IsDlgCheckboxChecked(hDlg,IDC_SYNCHMETHOD_P)) CommonSettings.SPU_sync_method = 2; + WritePrivateProfileInt("Sound", "SynchMethod", CommonSettings.SPU_sync_method, IniName); { Lock lock; - SPU_SetSynchMode(snd_synchmode, snd_synchmethod); + SPU_SetSynchMode(CommonSettings.SPU_sync_mode, CommonSettings.SPU_sync_method); } //write interpolation type