split sdl-audio backend into separate TU

that way it can be used with other video backends, e.g. fbgnuboy.
This commit is contained in:
rofl0r 2014-10-02 22:00:39 +00:00
parent 6b3a4d932c
commit 32d1229359
3 changed files with 93 additions and 76 deletions

View File

@ -26,7 +26,7 @@ FB_LIBS =
SVGA_OBJS = sys/svga/svgalib.o sys/pc/keymap.o @JOY@ @SOUND@ SVGA_OBJS = sys/svga/svgalib.o sys/pc/keymap.o @JOY@ @SOUND@
SVGA_LIBS = -L/usr/local/lib -lvga 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_LIBS = @SDL_LIBS@
SDL_CFLAGS = @SDL_CFLAGS@ SDL_CFLAGS = @SDL_CFLAGS@

92
sys/sdl/sdl-audio.c Normal file
View File

@ -0,0 +1,92 @@
/*
* sdl-audio.c
* sdl audio interface
*
* (C) 2001 Laguna
*
* Licensed under the GPLv2, or later.
*/
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#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();
}

View File

@ -4,7 +4,6 @@
* *
* (C) 2001 Damian Gryski <dgryski@uwaterloo.ca> * (C) 2001 Damian Gryski <dgryski@uwaterloo.ca>
* Joystick code contributed by David Lau * Joystick code contributed by David Lau
* Sound code added by Laguna
* *
* Licensed under the GPLv2, or later. * 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();
}