summaryrefslogtreecommitdiffstats
path: root/libao2
diff options
context:
space:
mode:
authoratmosfear <atmosfear@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-06-03 10:48:36 +0000
committeratmosfear <atmosfear@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-06-03 10:48:36 +0000
commit6464ede7732581d78788cf2f019d4067b1c50f2f (patch)
tree8c211ac040ac8485ecc5c91d8223443f5b340cf1 /libao2
parent40fdf0b1c1211427908290c88780881b2fa7a9d9 (diff)
downloadmpv-6464ede7732581d78788cf2f019d4067b1c50f2f.tar.bz2
mpv-6464ede7732581d78788cf2f019d4067b1c50f2f.tar.xz
Added support for sdl audio out (buggy pre-alpha).
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@967 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libao2')
-rw-r--r--libao2/Makefile5
-rw-r--r--libao2/ao_sdl.c165
-rw-r--r--libao2/audio_out.c6
3 files changed, 174 insertions, 2 deletions
diff --git a/libao2/Makefile b/libao2/Makefile
index c726ab42de..9d64132ce3 100644
--- a/libao2/Makefile
+++ b/libao2/Makefile
@@ -1,9 +1,10 @@
-include ../config.mak
+include config.mak
LIBNAME = libao.a
-SRCS=audio_out.c ao_oss.c ao_null.c
+# TODO: moveout ao_sdl.c so it's only used when SDL is detected
+SRCS=audio_out.c ao_oss.c ao_null.c $(OPTIONAL_SRCS)
OBJS=$(SRCS:.c=.o)
CFLAGS = $(OPTFLAGS) -I. -I..
diff --git a/libao2/ao_sdl.c b/libao2/ao_sdl.c
new file mode 100644
index 0000000000..be95075451
--- /dev/null
+++ b/libao2/ao_sdl.c
@@ -0,0 +1,165 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "audio_out.h"
+#include "audio_out_internal.h"
+
+static ao_info_t info =
+{
+ "SDLlib audio output",
+ "sdl",
+ "Felix Buenemann <atmosfear@users.sourceforge.net>",
+ ""
+};
+
+LIBAO_EXTERN(sdl)
+
+// there are some globals:
+// ao_samplerate
+// ao_channels
+// ao_format
+// ao_bps
+// ao_outburst
+// ao_buffersize
+
+int audiolen = 0;
+int audioplayed = 0;
+int audiobuffer = 0;
+
+#ifdef __FreeBSD__
+#include <SDL11/SDL.h>
+#else
+#include <SDL/SDL.h>
+#endif
+
+/*
+
+typedef struct{
+ int freq;
+ Uint16 format;
+ Uint8 channels;
+ Uint8 silence;
+ Uint16 samples;
+ Uint32 size;
+ void (*callback)(void *userdata, Uint8 *stream, int len);
+ void *userdata;
+} SDL_AudioSpec;
+
+*/
+
+//static struct sdl_priv_s {
+
+ /* SDL Audio Specifications */
+ SDL_AudioSpec aspec;
+
+//} sdl_priv;
+
+// to set/get/query special features/parameters
+static int control(int cmd,int arg){
+ return -1;
+}
+
+// Callback function
+void mixaudio(void *datastream, Uint8 *stream, int len) {
+ //printf("SDL: mixaudio called!\n");
+ //printf("SDL pts: %u %u\n", aspec.userdata, stream);
+ if(audiolen == 0) return;
+ len = (len > audiolen ? audiolen : len);
+ SDL_MixAudio(stream, aspec.userdata, len, SDL_MIX_MAXVOLUME);
+ audiobuffer -= len;
+ audioplayed = len;
+}
+
+// open & setup audio device
+// return: 1=success 0=fail
+static int init(int rate,int channels,int format,int flags){
+
+ printf("SDL: Audio Out - This driver is early alpha, do not use!\n");
+ printf("SDL: rate: %iHz channels %i format %i Bit flags %i\n", rate, channels, format, flags);
+// ao_outburst=4096;
+
+ /* The desired audio frequency in samples-per-second. */
+ aspec.freq = rate;
+
+ /* The desired audio format (see SDL_AudioSpec) */
+ aspec.format = (format == 16) ? AUDIO_S16 : AUDIO_S8;
+
+ /* Number of channels (mono/stereo) */
+ aspec.channels = channels;
+
+ /* The desired size of the audio buffer in samples. This number should be a power of two, and may be adjusted by the audio driver to a value more suitable for the hardware. Good values seem to range between 512 and 8192 inclusive, depending on the application and CPU speed. Smaller values yield faster response time, but can lead to underflow if the application is doing heavy processing and cannot fill the audio buffer in time. A stereo sample consists of both right and left channels in LR ordering. Note that the number of samples is directly related to time by the following formula: ms = (samples*1000)/freq */
+ aspec.samples = 4096;
+
+ /* This should be set to a function that will be called when the audio device is ready for more data. It is passed a pointer to the audio buffer, and the length in bytes of the audio buffer. This function usually runs in a separate thread, and so you should protect data structures that it accesses by calling SDL_LockAudio and SDL_UnlockAudio in your code. The callback prototype is:
+void callback(void *userdata, Uint8 *stream, int len); userdata is the pointer stored in userdata field of the SDL_AudioSpec. stream is a pointer to the audio buffer you want to fill with information and len is the length of the audio buffer in bytes. */
+ aspec.callback = mixaudio;
+
+ /* This pointer is passed as the first parameter to the callback function. */
+ aspec.userdata = NULL;
+
+ /* Open the audio device and start playing sound! */
+ if(SDL_OpenAudio(&aspec, NULL) < 0) {
+ printf("SDL: Unable to open audio: %s\n", SDL_GetError());
+ return(0);
+ }
+
+ /* unsilence audio, if callback is ready */
+ SDL_PauseAudio(0);
+
+
+
+
+ return 1;
+}
+
+// close audio device
+static void uninit(){
+ /* Wait for sound to complete */
+ while ( audiolen > 0 ) {
+ SDL_Delay(100); /* Sleep 1/10 second */
+ }
+ SDL_CloseAudio();
+}
+
+// stop playing and empty buffers (for seeking/pause)
+static void reset(){
+
+}
+
+// return: how many bytes can be played without blocking
+static int get_space(){
+
+ return aspec.samples;
+}
+
+// plays 'len' bytes of 'data'
+// it should round it down to outburst*n
+// return: number of bytes played
+static int play(void* data,int len,int flags){
+
+ //printf("SDL: play called!\n");
+
+ audiolen = len;
+ audiobuffer = len;
+
+ SDL_LockAudio();
+ // copy audio stream into mixaudio stream here
+ aspec.userdata = data;
+ //printf("SDL pt: %u %u\n", data, aspec.userdata);
+
+ SDL_UnlockAudio();
+
+ return audioplayed;
+}
+
+// return: how many unplayed bytes are in the buffer
+static int get_delay(){
+ //printf("SDL: get_delay called (%i)!\n", audiobuffer);
+ return audiobuffer;
+}
+
+
+
+
+
+
diff --git a/libao2/audio_out.c b/libao2/audio_out.c
index 0e54a62672..a5671102d1 100644
--- a/libao2/audio_out.c
+++ b/libao2/audio_out.c
@@ -19,11 +19,17 @@ extern ao_functions_t audio_out_oss;
//extern ao_functions_t audio_out_alsa;
//extern ao_functions_t audio_out_esd;
extern ao_functions_t audio_out_null;
+#ifdef HAVE_SDL
+extern ao_functions_t audio_out_sdl;
+#endif
ao_functions_t* audio_out_drivers[] =
{
&audio_out_oss,
&audio_out_null,
+#ifdef HAVE_SDL
+ &audio_out_sdl,
+#endif
NULL
};