7 * Licensed under the GPLv2, or later.
23 static int samplerate
= 44100;
24 static int stereo
= 1;
25 static volatile int audio_done
;
27 rcvar_t pcm_exports
[] =
29 RCV_BOOL("sound", &sound
, "enable sound"),
30 RCV_INT("stereo", &stereo
, "enable stereo"),
31 RCV_INT("samplerate", &samplerate
, "samplerate, recommended: 32768"),
36 static void audio_callback(void *blah
, byte
*stream
, int len
)
38 memcpy(stream
, pcm
.buf
, len
);
46 SDL_AudioSpec as
= {0}, ob
;
50 SDL_InitSubSystem(SDL_INIT_AUDIO
);
53 as
.channels
= 1 + stereo
;
54 as
.samples
= samplerate
/ 60;
55 for (i
= 1; i
< as
.samples
; i
<<=1);
57 as
.callback
= audio_callback
;
59 if (SDL_OpenAudio(&as
, &ob
) == -1) {
65 pcm
.stereo
= ob
.channels
- 1;
67 pcm
.buf
= malloc(pcm
.len
);
69 memset(pcm
.buf
, 0, pcm
.len
);
76 if (!pcm
.buf
) return 0;
77 if (pcm
.pos
< pcm
.len
) return 1;
87 if (sound
) SDL_CloseAudio();