diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index e12417067..863d7a80e 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -479,6 +479,7 @@ extern struct TCommonSettings { InternalNoise = 0, Sample = 1, Random = 2, + Physical = 3, } micMode; diff --git a/desmume/src/movie.cpp b/desmume/src/movie.cpp index 2f2f663f0..9f2905465 100644 --- a/desmume/src/movie.cpp +++ b/desmume/src/movie.cpp @@ -176,7 +176,7 @@ MovieData::MovieData() void MovieData::truncateAt(int frame) { - if(records.size() > frame) + if((int)records.size() > frame) records.resize(frame); } @@ -868,7 +868,7 @@ bool mov_loadstate(EMUFILE* fp, int size) currMovieData.rerecordCount = currRerecordCount; } - if(currFrameCounter > currMovieData.records.size()) + if(currFrameCounter > (int)currMovieData.records.size()) { // if the frame counter is longer than our current movie, // switch to "finished" mode. diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 8a5cdee30..eef4f5e24 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -146,6 +146,8 @@ const int kGapNDS = 64; // extremely tilted (but some games seem to use this val const int kGapNDS2 = 90; // more normal viewing angle static BOOL OpenCore(const char* filename); +BOOL Mic_DeInit_Physical(); +BOOL Mic_Init_Physical(); //----Recent ROMs menu globals---------- vector RecentRoms; //The list of recent ROM filenames @@ -2059,6 +2061,26 @@ std::string GetPrivateProfileStdString(LPCSTR lpAppName,LPCSTR lpKeyName,LPCSTR return buf; } +static void RefreshMicSettings() +{ + Mic_DeInit_Physical(); + if(CommonSettings.micMode == TCommonSettings::Sample) + { + if(!LoadSample(MicSampleName)) + { + MessageBox(NULL, "Unable to read the mic sample", "DeSmuME", (MB_OK | MB_ICONEXCLAMATION)); + } + } + else + { + LoadSample(NULL); + if(CommonSettings.micMode == TCommonSettings::Physical) + { + Mic_Init_Physical(); + } + } +} + DWORD wmTimerRes; int _main() { @@ -2160,6 +2182,10 @@ int _main() CommonSettings.hud.ShowGraphicalInputDisplay = GetPrivateProfileBool("Display","Display Graphical Input", false, IniName); CommonSettings.hud.ShowLagFrameCounter = GetPrivateProfileBool("Display","Display Lag Counter", false, IniName); CommonSettings.hud.ShowMicrophone = GetPrivateProfileBool("Display","Display Microphone", false, IniName); + + CommonSettings.micMode = (TCommonSettings::MicMode)GetPrivateProfileInt("MicSettings", "MicMode", (int)TCommonSettings::InternalNoise, IniName); + GetPrivateProfileString("MicSettings", "MicSampleFile", "micsample.raw", MicSampleName, MAX_PATH, IniName); + RefreshMicSettings(); video.screengap = GetPrivateProfileInt("Display", "ScreenGap", 0, IniName); SeparationBorderDrag = GetPrivateProfileBool("Display", "Window Split Border Drag", true, IniName); @@ -5082,6 +5108,7 @@ LRESULT CALLBACK MicrophoneSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, CheckDlgButton(hDlg, IDC_USEMICSAMPLE, ((CommonSettings.micMode == TCommonSettings::Sample) ? BST_CHECKED : BST_UNCHECKED)); CheckDlgButton(hDlg, IDC_USEMICRAND, ((CommonSettings.micMode == TCommonSettings::Random) ? BST_CHECKED : BST_UNCHECKED)); CheckDlgButton(hDlg, IDC_USENOISE, ((CommonSettings.micMode == TCommonSettings::InternalNoise) ? BST_CHECKED : BST_UNCHECKED)); + CheckDlgButton(hDlg, IDC_USEPHYSICAL, ((CommonSettings.micMode == TCommonSettings::Physical) ? BST_CHECKED : BST_UNCHECKED)); GetPrivateProfileString("MicSettings", "MicSampleFile", "micsample.raw", MicSampleName, MAX_PATH, IniName); SetDlgItemText(hDlg, IDC_MICSAMPLE, MicSampleName); @@ -5103,31 +5130,23 @@ LRESULT CALLBACK MicrophoneSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, { int val = 0; - if((romloaded)) //|| (val == IDYES)) - { - HWND cur; + HWND cur; - if(IsDlgCheckboxChecked(hDlg, IDC_USEMICSAMPLE)) - CommonSettings.micMode = TCommonSettings::Sample; - else if(IsDlgCheckboxChecked(hDlg, IDC_USEMICRAND)) - CommonSettings.micMode = TCommonSettings::Random; - else if(IsDlgCheckboxChecked(hDlg, IDC_USENOISE)) - CommonSettings.micMode = TCommonSettings::InternalNoise; + if(IsDlgCheckboxChecked(hDlg, IDC_USEMICSAMPLE)) + CommonSettings.micMode = TCommonSettings::Sample; + else if(IsDlgCheckboxChecked(hDlg, IDC_USEMICRAND)) + CommonSettings.micMode = TCommonSettings::Random; + else if(IsDlgCheckboxChecked(hDlg, IDC_USENOISE)) + CommonSettings.micMode = TCommonSettings::InternalNoise; + else if(IsDlgCheckboxChecked(hDlg, IDC_USEPHYSICAL)) + CommonSettings.micMode = TCommonSettings::Physical; - cur = GetDlgItem(hDlg, IDC_MICSAMPLE); - GetWindowText(cur, MicSampleName, 256); - - WritePrivateProfileInt("MicSettings", "MicMode", (int)CommonSettings.micMode, IniName); - WritePrivateProfileString("MicSettings", "MicSampleFile", MicSampleName, IniName); - - if (CommonSettings.micMode == TCommonSettings::Sample) - { - if (!LoadSample(MicSampleName)) - { - MessageBox(hDlg, "Unable to read the sample", "DeSmuME", (MB_OK | MB_ICONEXCLAMATION)); - } - } - } + cur = GetDlgItem(hDlg, IDC_MICSAMPLE); + GetWindowText(cur, MicSampleName, 256); + + WritePrivateProfileInt("MicSettings", "MicMode", (int)CommonSettings.micMode, IniName); + WritePrivateProfileString("MicSettings", "MicSampleFile", MicSampleName, IniName); + RefreshMicSettings(); } case IDCANCEL: { diff --git a/desmume/src/windows/mic.cpp b/desmume/src/windows/mic.cpp index 623febea4..3b358cf79 100644 --- a/desmume/src/windows/mic.cpp +++ b/desmume/src/windows/mic.cpp @@ -153,7 +153,11 @@ static bool formatChunk(EMUFILE* inf) bool LoadSample(const char *name) { + SampleLoaded = 0; + if(!name) return true; + EMUFILE_FILE inf(name,"rb"); + if(inf.fail()) return false; //wav reading code adapted from AUDIERE (LGPL) @@ -193,8 +197,23 @@ bool LoadSample(const char *name) return true; } -BOOL Mic_Init() { +BOOL Mic_DeInit_Physical() +{ + if(!Mic_Inited) + return TRUE; + INFO("win32 microphone DEinit OK\n"); + + Mic_Inited = FALSE; + + waveInReset(waveIn); + waveInClose(waveIn); + + return TRUE; +} + +BOOL Mic_Init_Physical() +{ if(Mic_Inited) return TRUE; @@ -220,8 +239,6 @@ BOOL Mic_Init() { wfx.nAvgBytesPerSec = 16000; wfx.wBitsPerSample = 8; - int x = sizeof(DWORD_PTR); - hr = waveInOpen(&waveIn, WAVE_MAPPER, &wfx, (DWORD_PTR)waveInProc, 0, CALLBACK_FUNCTION); MIC_CHECKERR(hr) @@ -239,14 +256,26 @@ BOOL Mic_Init() { MIC_CHECKERR(hr) Mic_Inited = TRUE; + INFO("win32 microphone init OK\n"); + + return TRUE; +} + +BOOL Mic_Init() { + + micReadSamplePos = 0; + return TRUE; } void Mic_Reset() { + micReadSamplePos = 0; + if(!Mic_Inited) return; + //reset physical memset(Mic_TempBuf, 0x80, MIC_BUFSIZE); memset(Mic_Buffer[0], 0x80, MIC_BUFSIZE); memset(Mic_Buffer[1], 0x80, MIC_BUFSIZE); @@ -254,19 +283,10 @@ void Mic_Reset() Mic_WriteBuf = 0; Mic_PlayBuf = 1; - - micReadSamplePos = 0; } void Mic_DeInit() { - if(!Mic_Inited) - return; - - Mic_Inited = FALSE; - - waveInReset(waveIn); - waveInClose(waveIn); } static const u8 random[32] = @@ -279,34 +299,10 @@ static const u8 random[32] = u8 Mic_ReadSample() { - - if(!Mic_Inited) - return 0; - u8 ret; u8 tmp; - if(NDS_getFinalUserInput().mic.micButtonPressed) { - if(SampleLoaded) { - //use a sample - //TODO: what if a movie is active? - // for now I'm going to hope that if anybody records a movie with a sample loaded, - // either they know what they're doing and plan to distribute the sample, - // or they're playing a game where it doesn't even matter or they never press the mic button. - tmp = samplebuffer[micReadSamplePos >> 1]; - micReadSamplePos++; - if(micReadSamplePos == samplebuffersize*2) - micReadSamplePos=0; - } else { - //use the "random" values - if(CommonSettings.micMode == TCommonSettings::InternalNoise) - tmp = random[micReadSamplePos >> 1]; - else tmp = rand(); - micReadSamplePos++; - if(micReadSamplePos == ARRAY_SIZE(random)*2) - micReadSamplePos=0; - } - } - else { + if(CommonSettings.micMode == TCommonSettings::Physical) + { if(movieMode == MOVIEMODE_INACTIVE) { //normal mic behavior @@ -317,9 +313,41 @@ u8 Mic_ReadSample() //since we're not recording Mic_Buffer to the movie, use silence tmp = 0x80; } + } + else + { + if(NDS_getFinalUserInput().mic.micButtonPressed) + { + if(SampleLoaded) + { + //use a sample + //TODO: what if a movie is active? + // for now I'm going to hope that if anybody records a movie with a sample loaded, + // either they know what they're doing and plan to distribute the sample, + // or they're playing a game where it doesn't even matter or they never press the mic button. + tmp = samplebuffer[micReadSamplePos >> 1]; + micReadSamplePos++; + if(micReadSamplePos == samplebuffersize*2) + micReadSamplePos=0; + } + else + { + //use the "random" values + if(CommonSettings.micMode == TCommonSettings::InternalNoise) + tmp = random[micReadSamplePos >> 1]; + else tmp = rand(); + micReadSamplePos++; + if(micReadSamplePos == ARRAY_SIZE(random)*2) + micReadSamplePos=0; + } + } + else + { + tmp = 0x80; - //reset mic button buffer pos if not pressed - micReadSamplePos=0; + //reset mic button buffer pos if not pressed + micReadSamplePos=0; + } } if(Mic_BufPos & 0x1) diff --git a/desmume/src/windows/resource.h b/desmume/src/windows/resource.h index 5005e7cbc..783ea6bf7 100644 --- a/desmume/src/windows/resource.h +++ b/desmume/src/windows/resource.h @@ -353,6 +353,7 @@ #define IDC_SYNCHMETHOD_P 1018 #define IDC_BGMAP_PAL 1019 #define IDC_VISIBLE 1019 +#define IDC_USEPHYSICAL 1019 #define IDC_BGMAP_SIZE 1020 #define IDC_BGMAP_SCROLL 1021 #define IDC_BGMAP_MOSAIC 1025 @@ -807,7 +808,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 105 #define _APS_NEXT_COMMAND_VALUE 40008 -#define _APS_NEXT_CONTROL_VALUE 1018 +#define _APS_NEXT_CONTROL_VALUE 1020 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/desmume/src/windows/resources.rc b/desmume/src/windows/resources.rc index 8a3f9d083..b6e5f947e 100644 Binary files a/desmume/src/windows/resources.rc and b/desmume/src/windows/resources.rc differ