70 lines
1.4 KiB
Text
70 lines
1.4 KiB
Text
$NetBSD: patch-aa,v 1.1.1.1 2004/07/26 17:05:05 dillo Exp $
|
|
|
|
--- sys/sdl/sdl.c.orig 2001-09-17 18:40:14.000000000 +0200
|
|
+++ sys/sdl/sdl.c
|
|
@@ -441,6 +441,8 @@ static int sound = 1;
|
|
static int samplerate = 44100;
|
|
static int stereo = 1;
|
|
static volatile int audio_done;
|
|
+static SDL_sem *pcm_rsem, *pcm_wsem;
|
|
+static int atexit_done = 0;
|
|
|
|
rcvar_t pcm_exports[] =
|
|
{
|
|
@@ -453,8 +455,16 @@ rcvar_t pcm_exports[] =
|
|
|
|
static void audio_callback(void *blah, byte *stream, int len)
|
|
{
|
|
+ SDL_SemWait(pcm_rsem);
|
|
memcpy(stream, pcm.buf, len);
|
|
- audio_done = 1;
|
|
+ SDL_SemPost(pcm_wsem);
|
|
+}
|
|
+
|
|
+
|
|
+static void audio_atexit(void)
|
|
+{
|
|
+ if (pcm_wsem)
|
|
+ SDL_SemPost(pcm_rsem);
|
|
}
|
|
|
|
|
|
@@ -466,6 +476,13 @@ void pcm_init()
|
|
if (!sound) return;
|
|
|
|
SDL_InitSubSystem(SDL_INIT_AUDIO);
|
|
+ /* XXX: check for NULL */
|
|
+ pcm_rsem = SDL_CreateSemaphore(0);
|
|
+ pcm_wsem = SDL_CreateSemaphore(0);
|
|
+ if (!atexit_done) {
|
|
+ atexit(audio_atexit);
|
|
+ atexit_done = 1;
|
|
+ }
|
|
as.freq = samplerate;
|
|
as.format = AUDIO_U8;
|
|
as.channels = 1 + stereo;
|
|
@@ -491,16 +508,20 @@ int pcm_submit()
|
|
{
|
|
if (!pcm.buf) return 0;
|
|
if (pcm.pos < pcm.len) return 1;
|
|
- while (!audio_done)
|
|
- SDL_Delay(4);
|
|
- audio_done = 0;
|
|
+ SDL_SemPost(pcm_rsem);
|
|
+ SDL_SemWait(pcm_wsem);
|
|
pcm.pos = 0;
|
|
return 1;
|
|
}
|
|
|
|
void pcm_close()
|
|
{
|
|
- if (sound) SDL_CloseAudio();
|
|
+ if (sound) {
|
|
+ SDL_CloseAudio();
|
|
+ SDL_DestroySemaphore(pcm_rsem);
|
|
+ SDL_DestroySemaphore(pcm_wsem);
|
|
+ pcm_rsem = pcm_wsem = 0;
|
|
+ }
|
|
}
|
|
|
|
|