From 57dbe9128d0f8cbb4bd79154fb9cda3ab6fab386 Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 21 May 2009 05:44:55 +0000 Subject: [PATCH] win32: fiddle with the mic input, moving it towards more reliability --- desmume/src/windows/mic.cpp | 73 +++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/desmume/src/windows/mic.cpp b/desmume/src/windows/mic.cpp index c6a54d820..393f33101 100644 --- a/desmume/src/windows/mic.cpp +++ b/desmume/src/windows/mic.cpp @@ -23,16 +23,16 @@ int SampleLoaded=0; #define MIC_BUFSIZE 4096 -BOOL Mic_Inited = FALSE; +static BOOL Mic_Inited = FALSE; -u8 Mic_TempBuf[MIC_BUFSIZE]; -u8 Mic_Buffer[2][MIC_BUFSIZE]; -u16 Mic_BufPos; -u8 Mic_WriteBuf; -u8 Mic_PlayBuf; +static u8 Mic_TempBuf[MIC_BUFSIZE]; +static u8 Mic_Buffer[2][MIC_BUFSIZE]; +static u16 Mic_BufPos; +static u8 Mic_WriteBuf; +static u8 Mic_PlayBuf; -HWAVEIN waveIn; -WAVEHDR waveHdr; +static HWAVEIN waveIn; +static WAVEHDR waveHdr; static int CALLBACK waveInProc(HWAVEIN wavein, UINT msg, DWORD instance, DWORD param1, DWORD param2) { @@ -57,9 +57,9 @@ static int CALLBACK waveInProc(HWAVEIN wavein, UINT msg, DWORD instance, DWORD p return 0; } -char* samplebuffer; -int samplebuffersize; -FILE* fp; +static char* samplebuffer; +static int samplebuffersize; +static FILE* fp; char* LoadSample(const char *name) { @@ -148,11 +148,11 @@ void Mic_DeInit() waveInClose(waveIn); } -int random[32] = {0xB1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE9, 0x70, +static const 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; +static int x=0; u8 Mic_ReadSample() { @@ -161,33 +161,38 @@ u8 Mic_ReadSample() return 0; u8 ret; - - if(MicButtonPressed) - if(SampleLoaded) { //use a sample + u8 tmp; + if(MicButtonPressed) { + if(SampleLoaded) { + //use a sample + tmp = samplebuffer[x >> 1]; x++; - if(x > samplebuffersize) + if(x == samplebuffersize*2) x=0; - ret=samplebuffer[x]; - } - else { //use the "random" values + } else { + //use the "random" values + tmp = random[x >> 1]; + //tmp = rand()&0xFF; x++; - if(x > ARRAY_SIZE(random)) + if(x == ARRAY_SIZE(random)*2) x=0; - ret = random[x]; - } - else { //normal mic behavior - u8 tmp = (u8)Mic_Buffer[Mic_PlayBuf][Mic_BufPos >> 1]; - - if(Mic_BufPos & 0x1) - { - ret = ((tmp & 0x1) << 7); - } - else - { - ret = ((tmp & 0xFE) >> 1); } + } else { + //normal mic behavior + tmp = (u8)Mic_Buffer[Mic_PlayBuf][Mic_BufPos >> 1]; } + if(Mic_BufPos & 0x1) + { + ret = ((tmp & 0x1) << 7); + } + else + { + ret = ((tmp & 0xFE) >> 1); + } + + MicDisplay = tmp; + Mic_BufPos++; if(Mic_BufPos >= (MIC_BUFSIZE << 1)) { @@ -195,7 +200,5 @@ u8 Mic_ReadSample() Mic_PlayBuf ^= 1; } - MicDisplay = ret; - return ret; } \ No newline at end of file