win32: fiddle with the mic input, moving it towards more reliability

This commit is contained in:
zeromus 2009-05-21 05:44:55 +00:00
parent 250bcd5b18
commit 57dbe9128d
1 changed files with 38 additions and 35 deletions

View File

@ -23,16 +23,16 @@ int SampleLoaded=0;
#define MIC_BUFSIZE 4096 #define MIC_BUFSIZE 4096
BOOL Mic_Inited = FALSE; static BOOL Mic_Inited = FALSE;
u8 Mic_TempBuf[MIC_BUFSIZE]; static u8 Mic_TempBuf[MIC_BUFSIZE];
u8 Mic_Buffer[2][MIC_BUFSIZE]; static u8 Mic_Buffer[2][MIC_BUFSIZE];
u16 Mic_BufPos; static u16 Mic_BufPos;
u8 Mic_WriteBuf; static u8 Mic_WriteBuf;
u8 Mic_PlayBuf; static u8 Mic_PlayBuf;
HWAVEIN waveIn; static HWAVEIN waveIn;
WAVEHDR waveHdr; static WAVEHDR waveHdr;
static int CALLBACK waveInProc(HWAVEIN wavein, UINT msg, DWORD instance, DWORD param1, DWORD param2) 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; return 0;
} }
char* samplebuffer; static char* samplebuffer;
int samplebuffersize; static int samplebuffersize;
FILE* fp; static FILE* fp;
char* LoadSample(const char *name) char* LoadSample(const char *name)
{ {
@ -148,11 +148,11 @@ void Mic_DeInit()
waveInClose(waveIn); 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x28, 0x00, 0x00, 0x00,
0x00, 0x00, 0x20, 0xE1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE9}; 0x00, 0x00, 0x20, 0xE1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE9};
int x=0; static int x=0;
u8 Mic_ReadSample() u8 Mic_ReadSample()
{ {
@ -161,22 +161,26 @@ u8 Mic_ReadSample()
return 0; return 0;
u8 ret; u8 ret;
u8 tmp;
if(MicButtonPressed) if(MicButtonPressed) {
if(SampleLoaded) { //use a sample if(SampleLoaded) {
//use a sample
tmp = samplebuffer[x >> 1];
x++; x++;
if(x > samplebuffersize) if(x == samplebuffersize*2)
x=0; x=0;
ret=samplebuffer[x]; } else {
} //use the "random" values
else { //use the "random" values tmp = random[x >> 1];
//tmp = rand()&0xFF;
x++; x++;
if(x > ARRAY_SIZE(random)) if(x == ARRAY_SIZE(random)*2)
x=0; x=0;
ret = random[x];
} }
else { //normal mic behavior } else {
u8 tmp = (u8)Mic_Buffer[Mic_PlayBuf][Mic_BufPos >> 1]; //normal mic behavior
tmp = (u8)Mic_Buffer[Mic_PlayBuf][Mic_BufPos >> 1];
}
if(Mic_BufPos & 0x1) if(Mic_BufPos & 0x1)
{ {
@ -186,7 +190,8 @@ u8 Mic_ReadSample()
{ {
ret = ((tmp & 0xFE) >> 1); ret = ((tmp & 0xFE) >> 1);
} }
}
MicDisplay = tmp;
Mic_BufPos++; Mic_BufPos++;
if(Mic_BufPos >= (MIC_BUFSIZE << 1)) if(Mic_BufPos >= (MIC_BUFSIZE << 1))
@ -195,7 +200,5 @@ u8 Mic_ReadSample()
Mic_PlayBuf ^= 1; Mic_PlayBuf ^= 1;
} }
MicDisplay = ret;
return ret; return ret;
} }