- implemented pc speaker beep in the lowlevel sound module for win32
- improved square wave generator code
This commit is contained in:
parent
8e7f582bc3
commit
f4134d5d29
@ -83,26 +83,36 @@ Bit8u *beep_buffer;
|
||||
int beep_bytes, beep_bufsize;
|
||||
bx_bool beep_active = 0;
|
||||
|
||||
#ifdef WIN32
|
||||
DWORD WINAPI beep_thread(LPVOID indata)
|
||||
#else
|
||||
void beep_thread(void *indata)
|
||||
#endif
|
||||
{
|
||||
Bit8u level;
|
||||
int i;
|
||||
int i, j;
|
||||
|
||||
beep_active = 1;
|
||||
bx_sound_lowlevel_c *soundmod = (bx_sound_lowlevel_c*)indata;
|
||||
level = 0x40;
|
||||
i = 0;
|
||||
do {
|
||||
beep_buffer[i] = level;
|
||||
if ((++i % beep_bytes) == 0) level ^= 0x40;
|
||||
} while (i < beep_bufsize);
|
||||
while (beep_bytes > 0) {
|
||||
j = 0;
|
||||
do {
|
||||
beep_buffer[j++] = level;
|
||||
if ((++i % beep_bytes) == 0) level ^= 0x40;
|
||||
} while (j < beep_bufsize);
|
||||
soundmod->sendwavepacket(beep_bufsize, beep_buffer);
|
||||
#ifdef WIN32
|
||||
Sleep(100);
|
||||
#endif
|
||||
}
|
||||
soundmod->stopwaveplayback();
|
||||
free(beep_buffer);
|
||||
beep_active = 0;
|
||||
#ifndef WIN32
|
||||
#ifdef WIN32
|
||||
return 0;
|
||||
#else
|
||||
pthread_exit(NULL);
|
||||
#endif
|
||||
}
|
||||
@ -111,18 +121,19 @@ bx_bool bx_soundmod_ctl_c::beep_on(float frequency)
|
||||
{
|
||||
if (soundmod != NULL) {
|
||||
BX_DEBUG(("Beep ON (frequency=%.2f)",frequency));
|
||||
#ifndef WIN32
|
||||
if (!beep_active) {
|
||||
soundmod->startwaveplayback(44100, 8, 0, 0);
|
||||
beep_bytes = (int)(44100.0 / frequency / 2);
|
||||
beep_bufsize = (4410 / beep_bytes / 2) * beep_bytes * 2;
|
||||
beep_bufsize = 4410;
|
||||
beep_buffer = (Bit8u*)malloc(beep_bufsize);
|
||||
#ifdef WIN32
|
||||
DWORD threadID;
|
||||
CreateThread(NULL, 0, beep_thread, soundmod, 0, &threadID);
|
||||
#else
|
||||
pthread_create(&thread, NULL, (void *(*)(void *))&beep_thread, soundmod);
|
||||
#endif
|
||||
}
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -133,13 +144,13 @@ bx_bool bx_soundmod_ctl_c::beep_off()
|
||||
BX_DEBUG(("Beep OFF"));
|
||||
if (beep_active) {
|
||||
beep_bytes = 0;
|
||||
#ifndef WIN32
|
||||
#ifdef WIN32
|
||||
while (beep_active) Sleep(1);
|
||||
#else
|
||||
pthread_join(thread, NULL);
|
||||
#endif
|
||||
}
|
||||
#ifndef WIN32
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user