diff --git a/desmume/src/mic.h b/desmume/src/mic.h index aede8df46..06c3c9a12 100644 --- a/desmume/src/mic.h +++ b/desmume/src/mic.h @@ -1,6 +1,13 @@ #ifndef MIC_H #define MIC_H +#ifdef WIN32 +extern int MicButtonPressed; +static char MicSampleName[256]; +char* LoadSample(const char *name); +extern int MicDisplay; +#endif + BOOL Mic_Init(); void Mic_Reset(); void Mic_DeInit(); diff --git a/desmume/src/windows/hotkey.cpp b/desmume/src/windows/hotkey.cpp index aca369e36..3b11fc4a3 100644 --- a/desmume/src/windows/hotkey.cpp +++ b/desmume/src/windows/hotkey.cpp @@ -26,6 +26,7 @@ #include "inputdx.h" #include "render3d.h" #include "throttle.h" +#include "../mic.h" SCustomKeys CustomKeys; @@ -146,6 +147,9 @@ void HK_StateQuickLoadSlot(int) HK_StateLoadSlot(lastSaveState); } +void HK_MicrophoneKeyDown(int) {MicButtonPressed =1;} +void HK_MicrophoneKeyUp(int) {MicButtonPressed =0;} + void HK_AutoHoldClearKeyDown(int) { for (int i=0; i < 10; i++) { @@ -356,6 +360,13 @@ void InitCustomKeys (SCustomKeys *keys) keys->PrintScreen.page = HOTKEY_PAGE_MAIN; keys->PrintScreen.key = VK_PAUSE; + keys->Microphone.handleKeyDown = HK_MicrophoneKeyDown; + keys->Microphone.handleKeyUp = HK_MicrophoneKeyUp; + keys->Microphone.code = "Microphone"; + keys->Microphone.name = L"Microphone"; + keys->Microphone.page = HOTKEY_PAGE_MAIN; + keys->Microphone.key = NULL; + keys->QuickSave.handleKeyDown = HK_StateQuickSaveSlot; keys->QuickSave.code = "QuickSave"; keys->QuickSave.name = L"Quick Save"; diff --git a/desmume/src/windows/hotkey.h b/desmume/src/windows/hotkey.h index b75c5dc53..0b09668bf 100644 --- a/desmume/src/windows/hotkey.h +++ b/desmume/src/windows/hotkey.h @@ -63,7 +63,7 @@ struct SCustomKeys SCustomKey Slot[10]; SCustomKey QuickSave, QuickLoad; - SCustomKey Pause, FrameAdvance, FastForward, FastForwardToggle, IncreaseSpeed, DecreaseSpeed; + SCustomKey Pause, FrameAdvance, FastForward, FastForwardToggle, IncreaseSpeed, DecreaseSpeed, Microphone; SCustomKey TurboRight, TurboLeft, TurboDown, TurboUp, TurboSelect, TurboStart, TurboB, TurboA, TurboY, TurboX; diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 99a7ae4cf..52fc970a8 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -70,6 +70,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "gbaslot_config.h" #include "cheatsWin.h" +#include "../mic.h" #include "../common.h" #include "main.h" #include "hotkey.h" @@ -220,7 +221,9 @@ bool frameCounterDisplay = false; bool FpsDisplay = false; bool ShowInputDisplay = false; bool ShowLagFrameCounter = false; +bool ShowMicrophone = false; bool HudEditorMode = false; +bool UseMicSample = false; unsigned short windowSize = 0; struct HudCoordinates{ @@ -239,6 +242,7 @@ struct HudStruct { HudCoordinates FrameCounter; HudCoordinates InputDisplay; HudCoordinates LagFrameCounter; + HudCoordinates Microphone; HudCoordinates Dummy; HudCoordinates &hud(int i) { return ((HudCoordinates*)this)[i]; } @@ -328,6 +332,11 @@ void ResetHud(HudStruct *hudstruct) { hudstruct->LagFrameCounter.y=65; hudstruct->LagFrameCounter.xsize=30; hudstruct->LagFrameCounter.ysize=10; + + hudstruct->Microphone.x=0; + hudstruct->Microphone.y=85; + hudstruct->Microphone.xsize=20; + hudstruct->Microphone.ysize=10; SetHudDummy(&hudstruct->Dummy); } @@ -361,6 +370,7 @@ struct NDS_fw_config_data win_fw_config; LRESULT CALLBACK GFX3DSettingsDlgProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp); LRESULT CALLBACK SoundSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK EmulationSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +LRESULT CALLBACK MicrophoneSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK WifiSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); struct configured_features { @@ -1120,6 +1130,7 @@ DWORD WINAPI run() if (frameCounterDisplay) osd->addFixed(Hud.FrameCounter.x, Hud.FrameCounter.y, "%d",frameCounter); if (ShowInputDisplay) osd->addFixed(Hud.InputDisplay.x, Hud.InputDisplay.y, "%s",InputDisplayString.c_str()); if (ShowLagFrameCounter) osd->addFixed(Hud.LagFrameCounter.x, Hud.LagFrameCounter.y, "%d",TotalLagFrames); + if (ShowMicrophone) osd->addFixed(Hud.Microphone.x, Hud.Microphone.y, "%d",MicDisplay); DisplayMessage(); CheckMessages(); } @@ -1217,6 +1228,7 @@ int MenuInit() MainWindow->checkMenu(ID_VIEW_DISPLAYFPS, FpsDisplay ? MF_CHECKED : MF_UNCHECKED); MainWindow->checkMenu(ID_VIEW_DISPLAYINPUT, ShowInputDisplay ? MF_CHECKED : MF_UNCHECKED); MainWindow->checkMenu(ID_VIEW_DISPLAYLAG, ShowLagFrameCounter ? MF_CHECKED : MF_UNCHECKED); + MainWindow->checkMenu(ID_VIEW_DISPLAYMICROPHONE, ShowMicrophone ? MF_CHECKED : MF_UNCHECKED); MainWindow->checkMenu(IDC_WINDOW1X, MF_BYCOMMAND | ((windowSize==1)?MF_CHECKED:MF_UNCHECKED)); MainWindow->checkMenu(IDC_WINDOW1_5X, MF_BYCOMMAND | ((windowSize==65535)?MF_CHECKED:MF_UNCHECKED)); @@ -1443,6 +1455,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, frameCounterDisplay = GetPrivateProfileInt("Display","FrameCounter", 0, IniName); ShowInputDisplay = GetPrivateProfileInt("Display","Display Input", 0, IniName); ShowLagFrameCounter = GetPrivateProfileInt("Display","Display Lag Counter", 0, IniName); + ShowMicrophone = GetPrivateProfileInt("Display","Display Microphone", 0, IniName); ScreenGap = GetPrivateProfileInt("Display", "ScreenGap", 0, IniName); FrameLimit = GetPrivateProfileInt("FrameLimit", "FrameLimit", 1, IniName); //sprintf(text, "%s", DESMUME_NAME_AND_VERSION); @@ -2228,7 +2241,8 @@ enum CONFIGSCREEN CONFIGSCREEN_FIRMWARE, CONFIGSCREEN_WIFI, CONFIGSCREEN_SOUND, - CONFIGSCREEN_EMULATION + CONFIGSCREEN_EMULATION, + CONFIGSCREEN_MICROPHONE }; void RunConfig(CONFIGSCREEN which) @@ -2258,6 +2272,9 @@ void RunConfig(CONFIGSCREEN which) case CONFIGSCREEN_EMULATION: DialogBox(hAppInst, MAKEINTRESOURCE(IDD_EMULATIONSETTINGS), hwnd, (DLGPROC)EmulationSettingsDlgProc); break; + case CONFIGSCREEN_MICROPHONE: + DialogBox(hAppInst, MAKEINTRESOURCE(IDD_MICROPHONE), hwnd, (DLGPROC)MicrophoneSettingsDlgProc); + break; case CONFIGSCREEN_WIFI: #ifdef EXPERIMENTAL_WIFI if(wifiMac.netEnabled) @@ -2698,6 +2715,9 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM case IDM_EMULATIONSETTINGS: RunConfig(CONFIGSCREEN_EMULATION); return 0; + case IDM_MICROPHONESETTINGS: + RunConfig(CONFIGSCREEN_MICROPHONE); + return 0; case IDM_GAME_INFO: { @@ -2901,6 +2921,13 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM osd->clear(); return 0; + case ID_VIEW_DISPLAYMICROPHONE: + ShowMicrophone ^= 1; + MainWindow->checkMenu(ID_VIEW_DISPLAYMICROPHONE, ShowMicrophone ? MF_CHECKED : MF_UNCHECKED); + WritePrivateProfileInt("Display", "Display Microphone", ShowMicrophone, IniName); + osd->clear(); + return 0; + #define clearsaver() \ MainWindow->checkMenu(IDC_SAVETYPE1, MF_BYCOMMAND | MF_UNCHECKED); \ MainWindow->checkMenu(IDC_SAVETYPE2, MF_BYCOMMAND | MF_UNCHECKED); \ @@ -3406,6 +3433,104 @@ LRESULT CALLBACK EmulationSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, L return FALSE; } +LRESULT CALLBACK MicrophoneSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch(uMsg) + { + case WM_INITDIALOG: + { + HWND cur; + + UseMicSample = GetPrivateProfileInt("Use Mic Sample", "UseMicSample", FALSE, IniName); + CheckDlgButton(hDlg, IDC_USEMICSAMPLE, ((UseMicSample == true) ? BST_CHECKED : BST_UNCHECKED)); + GetPrivateProfileString("Use Mic Sample", "MicSampleFile", "micsample.raw", MicSampleName, MAX_PATH, IniName); + SetDlgItemText(hDlg, IDC_MICSAMPLE, MicSampleName); + + if(UseMicSample == false) + { + cur = GetDlgItem(hDlg, IDC_MICSAMPLE); + EnableWindow(cur, FALSE); + cur = GetDlgItem(hDlg, IDC_MICSAMPLEBROWSE); + EnableWindow(cur, FALSE); + } + } + return TRUE; + + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case IDOK: + { + int val = 0; + + if((!romloaded) || (val == IDYES)) + { + HWND cur; + + UseMicSample = IsDlgButtonChecked(hDlg, IDC_USEMICSAMPLE); + cur = GetDlgItem(hDlg, IDC_MICSAMPLE); + GetWindowText(cur, MicSampleName, 256); + + WritePrivateProfileInt("Use Mic Sample", "UseMicSample", ((UseMicSample == true) ? 1 : 0), IniName); + WritePrivateProfileString("Use Mic Sample", "MicSampleFile", MicSampleName, IniName); + LoadSample(MicSampleName); + } + } + case IDCANCEL: + { + EndDialog(hDlg, TRUE); + } + return TRUE; + + case IDC_USEMICSAMPLE: + { + HWND cur; + BOOL enable = IsDlgButtonChecked(hDlg, IDC_USEMICSAMPLE); + + cur = GetDlgItem(hDlg, IDC_MICSAMPLE); + EnableWindow(cur, enable); + cur = GetDlgItem(hDlg, IDC_MICSAMPLEBROWSE); + EnableWindow(cur, enable); + } + return TRUE; + + case IDC_MICSAMPLEBROWSE: + { + char fileName[256] = ""; + OPENFILENAME ofn; + + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = hDlg; + ofn.lpstrFilter = "Any file(*.*)\0*.*\0\0"; + ofn.nFilterIndex = 1; + ofn.lpstrFile = fileName; + ofn.nMaxFile = 256; + ofn.lpstrDefExt = "bin"; + ofn.Flags = OFN_NOCHANGEDIR; + + if(GetOpenFileName(&ofn)) + { + HWND cur; + + switch(LOWORD(wParam)) + { + case IDC_MICSAMPLEBROWSE: cur = GetDlgItem(hDlg, IDC_MICSAMPLE); break; + } + + SetWindowText(cur, fileName); + } + } + return TRUE; + } + } + return TRUE; + } + + return FALSE; +} + LRESULT CALLBACK WifiSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { #ifdef EXPERIMENTAL_WIFI diff --git a/desmume/src/windows/mic.cpp b/desmume/src/windows/mic.cpp index c4dc479e5..1c3be3a62 100644 --- a/desmume/src/windows/mic.cpp +++ b/desmume/src/windows/mic.cpp @@ -12,6 +12,12 @@ #include "../types.h" #include "../debug.h" #include "../mic.h" +#include +#include + +int MicDisplay; +int MicButtonPressed=0; +int SampleLoaded=0; #define MIC_CHECKERR(hr) if(hr != MMSYSERR_NOERROR) return FALSE; @@ -51,8 +57,27 @@ static int CALLBACK waveInProc(HWAVEIN wavein, UINT msg, DWORD instance, DWORD p return 0; } -BOOL Mic_Init() +char* samplebuffer; +int samplebuffersize; +FILE* fp; + +char* LoadSample(const char *name) { + + std::ifstream fl(name); + fl.seekg( 0, std::ios::end ); + size_t len = fl.tellg(); + samplebuffersize=len; + char *ret = new char[len]; + fl.seekg(0, std::ios::beg); + fl.read(ret, len); + samplebuffer=ret; + SampleLoaded=1; + return ret; +} + +BOOL Mic_Init() { + if(Mic_Inited) return TRUE; @@ -123,21 +148,44 @@ void Mic_DeInit() waveInClose(waveIn); } +int random[32] = {0xB1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE9, 0x70, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x28, 0x00, 0x00, 0x00, +0x00, 0x00, 0x20, 0xE1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE9}; + +int x=0; + u8 Mic_ReadSample() { + if(!Mic_Inited) return 0; - u8 tmp = Mic_Buffer[Mic_PlayBuf][Mic_BufPos >> 1]; u8 ret; - if(Mic_BufPos & 0x1) - { - ret = ((tmp & 0x1) << 7); - } - else - { - ret = ((tmp & 0xFE) >> 1); + if(MicButtonPressed) + if(SampleLoaded) { //use a sample + x++; + if(x > samplebuffersize) + x=0; + ret=samplebuffer[x]; + } + else { //use the "random" values + x++; + if(x > ARRAYSIZE(random)) + x=0; + ret = random[x]; + } + else { //normal mic behavior + u8 tmp = (u8)Mic_Buffer[Mic_BufPos >> 1]; + + if(Mic_BufPos & 0x1) + { + ret = ((tmp & 0x1) << 7); + } + else + { + ret = ((tmp & 0xFE) >> 1); + } } Mic_BufPos++; @@ -147,5 +195,7 @@ u8 Mic_ReadSample() Mic_PlayBuf ^= 1; } + MicDisplay = ret; + return ret; -} +} \ No newline at end of file diff --git a/desmume/src/windows/resource.h b/desmume/src/windows/resource.h index 208b1d861..23f4ff68a 100644 --- a/desmume/src/windows/resource.h +++ b/desmume/src/windows/resource.h @@ -404,6 +404,11 @@ #define IDC_GI_ARM7SIZE 4486 #define IDC_GI_FNTOFS 4487 #define IDC_GI_FNTSIZE 4488 +#define IDD_MICROPHONE 5000 +#define IDM_MICROPHONESETTINGS 5001 +#define IDC_MICSAMPLEBROWSE 5003 +#define IDC_MICSAMPLE 5004 +#define IDC_USEMICSAMPLE 5005 #define IDM_SCREENSEP_NONE 40000 #define IDM_SCREENSEP_BORDER 40001 #define IDM_SCREENSEP_NDSGAP 40002 @@ -416,7 +421,8 @@ #define ID_VIEW_DISPLAYFPS 40010 #define ID_VIEW_DISPLAYINPUT 40011 #define ID_VIEW_DISPLAYLAG 40012 -#define ID_VIEW_HUDEDITOR 40013 +#define ID_VIEW_HUDEDITOR 40013 +#define ID_VIEW_DISPLAYMICROPHONE 40014 #define IDM_FILE_RECORDAVI 40015 #define IDM_FILE_STOPAVI 40016 #define ACCEL_CTRL_O 40032 diff --git a/desmume/src/windows/resources.rc b/desmume/src/windows/resources.rc index b01438cb0..9af62d302 100644 --- a/desmume/src/windows/resources.rc +++ b/desmume/src/windows/resources.rc @@ -115,6 +115,7 @@ MENU_PRINCIPAL MENU MENUITEM "Display Fps", ID_VIEW_DISPLAYFPS MENUITEM "Display Input", ID_VIEW_DISPLAYINPUT MENUITEM "Display Lag Counter", ID_VIEW_DISPLAYLAG + MENUITEM "Display Microphone", ID_VIEW_DISPLAYMICROPHONE MENUITEM "HUD Editing Mode", ID_VIEW_HUDEDITOR } POPUP "&Konfigure" @@ -135,6 +136,7 @@ MENU_PRINCIPAL MENU MENUITEM "Wifi settings", IDM_WIFISETTINGS, GRAYED MENUITEM "Firmware Indstillinger", IDM_FIRMSETTINGS MENUITEM "Emulation settings", IDM_EMULATIONSETTINGS + MENUITEM "Microphone Settings", IDM_MICROPHONESETTINGS POPUP "&Frame Skip" { MENUITEM "Limit framerate", IDC_FRAMELIMIT @@ -285,6 +287,7 @@ MENU_PRINCIPAL MENU MENUITEM "Display FPS", ID_VIEW_DISPLAYFPS MENUITEM "Display Input", ID_VIEW_DISPLAYINPUT MENUITEM "Display Lag Counter", ID_VIEW_DISPLAYLAG + MENUITEM "Display Microphone", ID_VIEW_DISPLAYMICROPHONE MENUITEM "HUD Editing Mode", ID_VIEW_HUDEDITOR } POPUP "&Config" @@ -306,6 +309,7 @@ MENU_PRINCIPAL MENU MENUITEM "Wifi settings", IDM_WIFISETTINGS, GRAYED MENUITEM "Firmware Settings", IDM_FIRMSETTINGS MENUITEM "Emulation Settings", IDM_EMULATIONSETTINGS + MENUITEM "Microphone Settings", IDM_MICROPHONESETTINGS POPUP "&Frame Skip" { MENUITEM "Limit framerate", IDC_FRAMELIMIT @@ -454,6 +458,7 @@ MENU_PRINCIPAL MENU MENUITEM "Framerate", ID_VIEW_DISPLAYFPS MENUITEM "Display Input", ID_VIEW_DISPLAYINPUT MENUITEM "Display Lag Counter", ID_VIEW_DISPLAYLAG + MENUITEM "Display Microphone", ID_VIEW_DISPLAYMICROPHONE MENUITEM "HUD Editing Mode", ID_VIEW_HUDEDITOR } POPUP "&Config" @@ -474,6 +479,7 @@ MENU_PRINCIPAL MENU MENUITEM "Config. wifi", IDM_WIFISETTINGS, GRAYED MENUITEM "Config. du firmware", IDM_FIRMSETTINGS MENUITEM "Config. d'émulation", IDM_EMULATIONSETTINGS + MENUITEM "Microphone Settings", IDM_MICROPHONESETTINGS POPUP "&Frame Skip" { MENUITEM "Limit framerate", IDC_FRAMELIMIT @@ -2230,7 +2236,20 @@ FONT 8, "MS Sans Serif", 0, 0, 1 LTEXT "frames", IDC_STATIC, 406, 5, 16, 8, SS_LEFT } - +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +IDD_MICROPHONE DIALOG 0, 0, 241, 111 +STYLE DS_SHELLFONT | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_SYSMENU +CAPTION "Microphone Simulation Settings" +FONT 8, "MS Sans Serif" +{ + DEFPUSHBUTTON "OK", IDOK, 130, 91, 50, 14, BS_DEFPUSHBUTTON + PUSHBUTTON "Cancel", IDCANCEL, 185, 91, 50, 14, BS_PUSHBUTTON + GROUPBOX "Microphone Sample", IDC_STATIC, 5, 6, 230, 75 + AUTOCHECKBOX "Use Microphone Sample", IDC_USEMICSAMPLE, 15, 21, 110, 10, BS_AUTOCHECKBOX + LTEXT "Sample:", IDC_STATIC, 15, 36, 110, 8, SS_LEFT + EDITTEXT IDC_MICSAMPLE, 15, 46, 190, 14, ES_AUTOHSCROLL + PUSHBUTTON "...", IDC_MICSAMPLEBROWSE, 205, 46, 20, 14, BS_PUSHBUTTON +} LANGUAGE LANG_DANISH, SUBLANG_DANISH_DENMARK IDD_OAM DIALOGEX 0, 0, 300, 200