clean up mic configuration and only enable mic when physical mic mode is selected

This commit is contained in:
zeromus 2009-11-04 03:51:01 +00:00
parent a9e0617180
commit 3411a9c9ca
6 changed files with 115 additions and 66 deletions

View File

@ -479,6 +479,7 @@ extern struct TCommonSettings {
InternalNoise = 0, InternalNoise = 0,
Sample = 1, Sample = 1,
Random = 2, Random = 2,
Physical = 3,
} micMode; } micMode;

View File

@ -176,7 +176,7 @@ MovieData::MovieData()
void MovieData::truncateAt(int frame) void MovieData::truncateAt(int frame)
{ {
if(records.size() > frame) if((int)records.size() > frame)
records.resize(frame); records.resize(frame);
} }
@ -868,7 +868,7 @@ bool mov_loadstate(EMUFILE* fp, int size)
currMovieData.rerecordCount = currRerecordCount; currMovieData.rerecordCount = currRerecordCount;
} }
if(currFrameCounter > currMovieData.records.size()) if(currFrameCounter > (int)currMovieData.records.size())
{ {
// if the frame counter is longer than our current movie, // if the frame counter is longer than our current movie,
// switch to "finished" mode. // switch to "finished" mode.

View File

@ -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 const int kGapNDS2 = 90; // more normal viewing angle
static BOOL OpenCore(const char* filename); static BOOL OpenCore(const char* filename);
BOOL Mic_DeInit_Physical();
BOOL Mic_Init_Physical();
//----Recent ROMs menu globals---------- //----Recent ROMs menu globals----------
vector<string> RecentRoms; //The list of recent ROM filenames vector<string> RecentRoms; //The list of recent ROM filenames
@ -2059,6 +2061,26 @@ std::string GetPrivateProfileStdString(LPCSTR lpAppName,LPCSTR lpKeyName,LPCSTR
return buf; 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; DWORD wmTimerRes;
int _main() int _main()
{ {
@ -2160,6 +2182,10 @@ int _main()
CommonSettings.hud.ShowGraphicalInputDisplay = GetPrivateProfileBool("Display","Display Graphical Input", false, IniName); CommonSettings.hud.ShowGraphicalInputDisplay = GetPrivateProfileBool("Display","Display Graphical Input", false, IniName);
CommonSettings.hud.ShowLagFrameCounter = GetPrivateProfileBool("Display","Display Lag Counter", false, IniName); CommonSettings.hud.ShowLagFrameCounter = GetPrivateProfileBool("Display","Display Lag Counter", false, IniName);
CommonSettings.hud.ShowMicrophone = GetPrivateProfileBool("Display","Display Microphone", 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); video.screengap = GetPrivateProfileInt("Display", "ScreenGap", 0, IniName);
SeparationBorderDrag = GetPrivateProfileBool("Display", "Window Split Border Drag", true, 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_USEMICSAMPLE, ((CommonSettings.micMode == TCommonSettings::Sample) ? BST_CHECKED : BST_UNCHECKED));
CheckDlgButton(hDlg, IDC_USEMICRAND, ((CommonSettings.micMode == TCommonSettings::Random) ? 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_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); GetPrivateProfileString("MicSettings", "MicSampleFile", "micsample.raw", MicSampleName, MAX_PATH, IniName);
SetDlgItemText(hDlg, IDC_MICSAMPLE, MicSampleName); SetDlgItemText(hDlg, IDC_MICSAMPLE, MicSampleName);
@ -5103,31 +5130,23 @@ LRESULT CALLBACK MicrophoneSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
{ {
int val = 0; int val = 0;
if((romloaded)) //|| (val == IDYES)) HWND cur;
{
HWND cur;
if(IsDlgCheckboxChecked(hDlg, IDC_USEMICSAMPLE)) if(IsDlgCheckboxChecked(hDlg, IDC_USEMICSAMPLE))
CommonSettings.micMode = TCommonSettings::Sample; CommonSettings.micMode = TCommonSettings::Sample;
else if(IsDlgCheckboxChecked(hDlg, IDC_USEMICRAND)) else if(IsDlgCheckboxChecked(hDlg, IDC_USEMICRAND))
CommonSettings.micMode = TCommonSettings::Random; CommonSettings.micMode = TCommonSettings::Random;
else if(IsDlgCheckboxChecked(hDlg, IDC_USENOISE)) else if(IsDlgCheckboxChecked(hDlg, IDC_USENOISE))
CommonSettings.micMode = TCommonSettings::InternalNoise; CommonSettings.micMode = TCommonSettings::InternalNoise;
else if(IsDlgCheckboxChecked(hDlg, IDC_USEPHYSICAL))
CommonSettings.micMode = TCommonSettings::Physical;
cur = GetDlgItem(hDlg, IDC_MICSAMPLE); cur = GetDlgItem(hDlg, IDC_MICSAMPLE);
GetWindowText(cur, MicSampleName, 256); GetWindowText(cur, MicSampleName, 256);
WritePrivateProfileInt("MicSettings", "MicMode", (int)CommonSettings.micMode, IniName); WritePrivateProfileInt("MicSettings", "MicMode", (int)CommonSettings.micMode, IniName);
WritePrivateProfileString("MicSettings", "MicSampleFile", MicSampleName, IniName); WritePrivateProfileString("MicSettings", "MicSampleFile", MicSampleName, IniName);
RefreshMicSettings();
if (CommonSettings.micMode == TCommonSettings::Sample)
{
if (!LoadSample(MicSampleName))
{
MessageBox(hDlg, "Unable to read the sample", "DeSmuME", (MB_OK | MB_ICONEXCLAMATION));
}
}
}
} }
case IDCANCEL: case IDCANCEL:
{ {

View File

@ -153,7 +153,11 @@ static bool formatChunk(EMUFILE* inf)
bool LoadSample(const char *name) bool LoadSample(const char *name)
{ {
SampleLoaded = 0;
if(!name) return true;
EMUFILE_FILE inf(name,"rb"); EMUFILE_FILE inf(name,"rb");
if(inf.fail()) return false;
//wav reading code adapted from AUDIERE (LGPL) //wav reading code adapted from AUDIERE (LGPL)
@ -193,8 +197,23 @@ bool LoadSample(const char *name)
return true; 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) if(Mic_Inited)
return TRUE; return TRUE;
@ -220,8 +239,6 @@ BOOL Mic_Init() {
wfx.nAvgBytesPerSec = 16000; wfx.nAvgBytesPerSec = 16000;
wfx.wBitsPerSample = 8; wfx.wBitsPerSample = 8;
int x = sizeof(DWORD_PTR);
hr = waveInOpen(&waveIn, WAVE_MAPPER, &wfx, (DWORD_PTR)waveInProc, 0, CALLBACK_FUNCTION); hr = waveInOpen(&waveIn, WAVE_MAPPER, &wfx, (DWORD_PTR)waveInProc, 0, CALLBACK_FUNCTION);
MIC_CHECKERR(hr) MIC_CHECKERR(hr)
@ -239,14 +256,26 @@ BOOL Mic_Init() {
MIC_CHECKERR(hr) MIC_CHECKERR(hr)
Mic_Inited = TRUE; Mic_Inited = TRUE;
INFO("win32 microphone init OK\n");
return TRUE;
}
BOOL Mic_Init() {
micReadSamplePos = 0;
return TRUE; return TRUE;
} }
void Mic_Reset() void Mic_Reset()
{ {
micReadSamplePos = 0;
if(!Mic_Inited) if(!Mic_Inited)
return; return;
//reset physical
memset(Mic_TempBuf, 0x80, MIC_BUFSIZE); memset(Mic_TempBuf, 0x80, MIC_BUFSIZE);
memset(Mic_Buffer[0], 0x80, MIC_BUFSIZE); memset(Mic_Buffer[0], 0x80, MIC_BUFSIZE);
memset(Mic_Buffer[1], 0x80, MIC_BUFSIZE); memset(Mic_Buffer[1], 0x80, MIC_BUFSIZE);
@ -254,19 +283,10 @@ void Mic_Reset()
Mic_WriteBuf = 0; Mic_WriteBuf = 0;
Mic_PlayBuf = 1; Mic_PlayBuf = 1;
micReadSamplePos = 0;
} }
void Mic_DeInit() void Mic_DeInit()
{ {
if(!Mic_Inited)
return;
Mic_Inited = FALSE;
waveInReset(waveIn);
waveInClose(waveIn);
} }
static const u8 random[32] = static const u8 random[32] =
@ -279,34 +299,10 @@ static const u8 random[32] =
u8 Mic_ReadSample() u8 Mic_ReadSample()
{ {
if(!Mic_Inited)
return 0;
u8 ret; u8 ret;
u8 tmp; u8 tmp;
if(NDS_getFinalUserInput().mic.micButtonPressed) { if(CommonSettings.micMode == TCommonSettings::Physical)
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(movieMode == MOVIEMODE_INACTIVE) if(movieMode == MOVIEMODE_INACTIVE)
{ {
//normal mic behavior //normal mic behavior
@ -317,9 +313,41 @@ u8 Mic_ReadSample()
//since we're not recording Mic_Buffer to the movie, use silence //since we're not recording Mic_Buffer to the movie, use silence
tmp = 0x80; 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 //reset mic button buffer pos if not pressed
micReadSamplePos=0; micReadSamplePos=0;
}
} }
if(Mic_BufPos & 0x1) if(Mic_BufPos & 0x1)

View File

@ -353,6 +353,7 @@
#define IDC_SYNCHMETHOD_P 1018 #define IDC_SYNCHMETHOD_P 1018
#define IDC_BGMAP_PAL 1019 #define IDC_BGMAP_PAL 1019
#define IDC_VISIBLE 1019 #define IDC_VISIBLE 1019
#define IDC_USEPHYSICAL 1019
#define IDC_BGMAP_SIZE 1020 #define IDC_BGMAP_SIZE 1020
#define IDC_BGMAP_SCROLL 1021 #define IDC_BGMAP_SCROLL 1021
#define IDC_BGMAP_MOSAIC 1025 #define IDC_BGMAP_MOSAIC 1025
@ -807,7 +808,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105 #define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40008 #define _APS_NEXT_COMMAND_VALUE 40008
#define _APS_NEXT_CONTROL_VALUE 1018 #define _APS_NEXT_CONTROL_VALUE 1020
#define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_SYMED_VALUE 101
#endif #endif
#endif #endif

Binary file not shown.