From 32d122935914526db3267903027e9077b0f4594b Mon Sep 17 00:00:00 2001 From: rofl0r Date: Thu, 2 Oct 2014 22:00:39 +0000 Subject: [PATCH] split sdl-audio backend into separate TU that way it can be used with other video backends, e.g. fbgnuboy. --- Makefile.in | 2 +- sys/sdl/sdl-audio.c | 92 +++++++++++++++++++++++++++++++++++++++++++++ sys/sdl/sdl.c | 75 ------------------------------------ 3 files changed, 93 insertions(+), 76 deletions(-) create mode 100644 sys/sdl/sdl-audio.c diff --git a/Makefile.in b/Makefile.in index 58e49a3..194f495 100644 --- a/Makefile.in +++ b/Makefile.in @@ -26,7 +26,7 @@ FB_LIBS = SVGA_OBJS = sys/svga/svgalib.o sys/pc/keymap.o @JOY@ @SOUND@ SVGA_LIBS = -L/usr/local/lib -lvga -SDL_OBJS = sys/sdl/sdl.o sys/sdl/keymap.o +SDL_OBJS = sys/sdl/sdl.o sys/sdl/sdl-audio.o sys/sdl/keymap.o SDL_LIBS = @SDL_LIBS@ SDL_CFLAGS = @SDL_CFLAGS@ diff --git a/sys/sdl/sdl-audio.c b/sys/sdl/sdl-audio.c new file mode 100644 index 0000000..b54e54b --- /dev/null +++ b/sys/sdl/sdl-audio.c @@ -0,0 +1,92 @@ +/* + * sdl-audio.c + * sdl audio interface + * + * (C) 2001 Laguna + * + * Licensed under the GPLv2, or later. + */ + +#include +#include + +#include + +#include "rc.h" +#include "pcm.h" + + +struct pcm pcm; + + +static int sound = 1; +static int samplerate = 44100; +static int stereo = 1; +static volatile int audio_done; + +rcvar_t pcm_exports[] = +{ + RCV_BOOL("sound", &sound), + RCV_INT("stereo", &stereo), + RCV_INT("samplerate", &samplerate), + RCV_END +}; + + +static void audio_callback(void *blah, byte *stream, int len) +{ + memcpy(stream, pcm.buf, len); + audio_done = 1; +} + + +void pcm_init() +{ + int i; + SDL_AudioSpec as; + + if (!sound) return; + + SDL_InitSubSystem(SDL_INIT_AUDIO); + as.freq = samplerate; + as.format = AUDIO_U8; + as.channels = 1 + stereo; + as.samples = samplerate / 60; + for (i = 1; i < as.samples; i<<=1); + as.samples = i; + as.callback = audio_callback; + as.userdata = 0; + if (SDL_OpenAudio(&as, 0) == -1) + return; + + pcm.hz = as.freq; + pcm.stereo = as.channels - 1; + pcm.len = as.size; + pcm.buf = malloc(pcm.len); + pcm.pos = 0; + memset(pcm.buf, 0, pcm.len); + + SDL_PauseAudio(0); +} + +int pcm_submit() +{ + if (!pcm.buf) return 0; + if (pcm.pos < pcm.len) return 1; + while (!audio_done) + SDL_Delay(4); + audio_done = 0; + pcm.pos = 0; + return 1; +} + +void pcm_close() +{ + if (sound) SDL_CloseAudio(); +} + + + + + + diff --git a/sys/sdl/sdl.c b/sys/sdl/sdl.c index 2350ebd..714a85d 100644 --- a/sys/sdl/sdl.c +++ b/sys/sdl/sdl.c @@ -4,7 +4,6 @@ * * (C) 2001 Damian Gryski * Joystick code contributed by David Lau - * Sound code added by Laguna * * Licensed under the GPLv2, or later. */ @@ -431,80 +430,6 @@ void vid_end() -#include "pcm.h" - - -struct pcm pcm; - - -static int sound = 1; -static int samplerate = 44100; -static int stereo = 1; -static volatile int audio_done; - -rcvar_t pcm_exports[] = -{ - RCV_BOOL("sound", &sound), - RCV_INT("stereo", &stereo), - RCV_INT("samplerate", &samplerate), - RCV_END -}; - - -static void audio_callback(void *blah, byte *stream, int len) -{ - memcpy(stream, pcm.buf, len); - audio_done = 1; -} - - -void pcm_init() -{ - int i; - SDL_AudioSpec as; - - if (!sound) return; - - SDL_InitSubSystem(SDL_INIT_AUDIO); - as.freq = samplerate; - as.format = AUDIO_U8; - as.channels = 1 + stereo; - as.samples = samplerate / 60; - for (i = 1; i < as.samples; i<<=1); - as.samples = i; - as.callback = audio_callback; - as.userdata = 0; - if (SDL_OpenAudio(&as, 0) == -1) - return; - - pcm.hz = as.freq; - pcm.stereo = as.channels - 1; - pcm.len = as.size; - pcm.buf = malloc(pcm.len); - pcm.pos = 0; - memset(pcm.buf, 0, pcm.len); - - SDL_PauseAudio(0); -} - -int pcm_submit() -{ - if (!pcm.buf) return 0; - if (pcm.pos < pcm.len) return 1; - while (!audio_done) - SDL_Delay(4); - audio_done = 0; - pcm.pos = 0; - return 1; -} - -void pcm_close() -{ - if (sound) SDL_CloseAudio(); -} - - -