allow multiple sound drivers to be compiled
authornotaz <notasas@gmail.com>
Mon, 30 Jul 2012 18:29:29 +0000 (21:29 +0300)
committernotaz <notasas@gmail.com>
Mon, 30 Jul 2012 22:31:34 +0000 (01:31 +0300)
13 files changed:
Makefile
configure
frontend/libretro.c
plugins/dfsound/alsa.c
plugins/dfsound/dsoundoss.h [deleted file]
plugins/dfsound/nullsnd.c
plugins/dfsound/oss.c
plugins/dfsound/out.c [new file with mode: 0644]
plugins/dfsound/out.h [new file with mode: 0644]
plugins/dfsound/pulseaudio.c
plugins/dfsound/sdl.c
plugins/dfsound/spu.c
plugins/dfsound/stdafx.h

index 5720bab..8b7d83c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
 # default stuff goes here, so that config can override
 TARGET = pcsx
 CFLAGS += -Wall -ggdb -Ifrontend -ffast-math
-LDLIBS += -lpthread -ldl -lpng -lz -lm
+LDLIBS += -lpthread -lm
 ifndef DEBUG
 CFLAGS += -O2 -DNDEBUG
 endif
@@ -26,6 +26,7 @@ endif
 -include Makefile.local
 
 CC_LINK = $(CC)
+LDLIBS += $(MAIN_LDLIBS)
 
 # core
 OBJS += libpcsxcore/cdriso.o libpcsxcore/cdrom.o libpcsxcore/cheat.o libpcsxcore/debug.o \
@@ -64,26 +65,32 @@ endif
 
 # spu
 OBJS += plugins/dfsound/dma.o plugins/dfsound/freeze.o \
-       plugins/dfsound/registers.o plugins/dfsound/spu.o
+       plugins/dfsound/registers.o plugins/dfsound/spu.o \
+       plugins/dfsound/out.o plugins/dfsound/nullsnd.o
 plugins/dfsound/spu.o: plugins/dfsound/adsr.c plugins/dfsound/reverb.c \
        plugins/dfsound/xa.c
 ifeq "$(ARCH)" "arm"
 OBJS += plugins/dfsound/arm_utils.o
 endif
-ifeq "$(SOUND_DRIVER)" "oss"
-plugins/dfsound/%.o: CFLAGS += -DUSEOSS
+ifneq ($(findstring oss,$(SOUND_DRIVERS)),)
+plugins/dfsound/out.o: CFLAGS += -DHAVE_OSS
 OBJS += plugins/dfsound/oss.o
 endif
-ifeq "$(SOUND_DRIVER)" "alsa"
-plugins/dfsound/%.o: CFLAGS += -DUSEALSA
+ifneq ($(findstring alsa,$(SOUND_DRIVERS)),)
+plugins/dfsound/out.o: CFLAGS += -DHAVE_ALSA
 OBJS += plugins/dfsound/alsa.o
 LDLIBS += -lasound
 endif
-ifeq "$(SOUND_DRIVER)" "sdl"
+ifneq ($(findstring sdl,$(SOUND_DRIVERS)),)
+plugins/dfsound/out.o: CFLAGS += -DHAVE_SDL
 OBJS += plugins/dfsound/sdl.o
 endif
-ifeq "$(SOUND_DRIVER)" "none"
-OBJS += plugins/dfsound/nullsnd.o
+ifneq ($(findstring pulseaudio,$(SOUND_DRIVERS)),)
+plugins/dfsound/out.o: CFLAGS += -DHAVE_PULSE
+OBJS += plugins/dfsound/pulseaudio.o
+endif
+ifneq ($(findstring libretro,$(SOUND_DRIVERS)),)
+plugins/dfsound/out.o: CFLAGS += -DHAVE_LIBRETRO
 endif
 
 # builtin gpu
index babf444..f5e3b6f 100755 (executable)
--- a/configure
+++ b/configure
@@ -4,12 +4,20 @@ set -e
 
 TMPC="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.c"
 TMPO="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.o"
-trap "rm -f $TMPC $TMPO" EXIT INT QUIT TERM
+TMPB="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}"
+trap "rm -f $TMPC $TMPO $TMPB" EXIT INT QUIT TERM
 rm -f config.log
 
 compile_object()
 {
-  c="$CC $CFLAGS -c $TMPC -o $TMPO $1"
+  c="$CC $CFLAGS -c $TMPC -o $TMPO $@"
+  echo $c >> config.log
+  $c >> config.log 2>&1
+}
+
+compile_binary()
+{
+  c="$CC $CFLAGS $TMPC -o $TMPB $LDFLAGS $MAIN_LDLIBS $@"
   echo $c >> config.log
   $c >> config.log 2>&1
 }
@@ -28,8 +36,8 @@ platform_list="generic pandora maemo caanoo libretro"
 platform="generic"
 builtin_gpu_list="peops unai neon"
 builtin_gpu=""
-sound_driver_list="oss alsa sdl libretro none"
-sound_driver="alsa"
+sound_driver_list="oss alsa sdl pulseaudio libretro"
+sound_drivers=""
 plugins="plugins/spunull/spunull.so \
 plugins/dfxvideo/gpu_peops.so plugins/gpu_unai/gpu_unai.so"
 ram_fixed="no"
@@ -48,8 +56,15 @@ CC="${CC-${CROSS_COMPILE}gcc}"
 CXX="${CXX-${CROSS_COMPILE}g++}"
 AS="${AS-${CROSS_COMPILE}as}"
 AR="${AS-${CROSS_COMPILE}ar}"
+MAIN_LDLIBS="$LDLIBS -ldl -lpng -lz"
 config_mak="config.mak"
 
+fail()
+{
+  echo "$@"
+  exit 1
+}
+
 # call during arg parsing, so that cmd line can override platform defaults
 set_platform()
 {
@@ -58,7 +73,7 @@ set_platform()
   generic)
     ;;
   pandora)
-    sound_driver="oss"
+    sound_drivers="oss alsa"
     ram_fixed="yes"
     drc_cache_base="yes"
     optimize_cortexa8="yes"
@@ -71,17 +86,16 @@ set_platform()
     have_arm_neon="yes"
     ;;
   caanoo)
-    sound_driver="oss"
+    sound_drivers="oss"
     ram_fixed="yes"
     drc_cache_base="yes"
     optimize_arm926ej="yes"
     ;;
   libretro)
-    sound_driver="libretro"
+    sound_drivers="libretro"
     ;;
   *)
-    echo "unsupported platform: $platform"
-    exit 1
+    fail "unsupported platform: $platform"
     ;;
   esac
 }
@@ -95,7 +109,7 @@ for opt do
   ;;
   --gpu=*) builtin_gpu="$optarg"
   ;;
-  --sound-driver=*) sound_driver="$optarg"
+  --sound-drivers=*) sound_drivers="$optarg"
   ;;
   --enable-neon) have_arm_neon="yes"
   ;;
@@ -115,7 +129,7 @@ if [ "$show_help" = "yes" ]; then
   echo "                           available: $platform_list"
   echo "  --gpu=NAME               builtin gpu plugin [guessed]"
   echo "                           available: $builtin_gpu_list"
-  echo "  --sound-driver=NAME      sound output driver [$sound_driver]"
+  echo "  --sound-drivers=LIST     sound output drivers [guessed]"
   echo "                           available: $sound_driver_list"
   echo "  --enable-neon"
   echo "  --disable-neon           enable/disable ARM NEON optimizations [guessed]"
@@ -126,25 +140,20 @@ if [ "$show_help" = "yes" ]; then
   exit 1
 fi
 
+# validate selections
 if [ "x$builtin_gpu" != "x" ]; then
-  case "$builtin_gpu" in
-  peops|unai|neon)
-    ;;
-  *)
-    echo "unsupported builtin gpu plugin: $builtin_gpu"
-    exit 1
-    ;;
-  esac
+  if ! echo $builtin_gpu_list | grep -q "\<$builtin_gpu\>"; then
+    fail "unsupported builtin gpu plugin: $builtin_gpu"
+  fi
 fi
 
-case "$sound_driver" in
-oss|alsa|sdl|libretro|none)
-  ;;
-*)
-  echo "unsupported sound driver: $sound_driver"
-  exit 1
-  ;;
-esac
+if [ "x$sound_drivers" != "x" ]; then
+  for d in $sound_drivers; do
+    if ! echo $sound_driver_list | grep -q "\<$d\>"; then
+      fail "unsupported sound driver: $sound_driver"
+    fi
+  done
+fi
 
 if [ -z "$ARCH" ]; then
   ARCH=`$CC -v 2>&1 | grep -i 'target:' | awk '{print $2}' \
@@ -241,13 +250,13 @@ generic)
   generic_cflags=`sdl-config --cflags`
   generic_ldlibs=`sdl-config --libs`
   CFLAGS="$CFLAGS $generic_cflags"
-  LDFLAGS="$LDFLAGS $generic_ldlibs"
+  MAIN_LDLIBS="$MAIN_LDLIBS $generic_ldlibs"
   ;;
 maemo)
   maemo_cflags=`pkg-config --cflags hildon-1`
   maemo_ldlibs=`pkg-config --libs hildon-1`
   CFLAGS="$CFLAGS -DMAEMO -DMAEMO_CHANGES $maemo_cflags"
-  LDFLAGS="$LDFLAGS $maemo_ldlibs"
+  MAIN_LDLIBS="$MAIN_LDLIBS $maemo_ldlibs"
   ;;
 libretro)
   CFLAGS="$CFLAGS -fPIC"
@@ -255,6 +264,86 @@ libretro)
   ;;
 esac
 
+# header/library presence tests
+check_zlib()
+{
+  cat > $TMPC <<EOF
+  #include <zlib.h>
+  void main() { uncompress(0, 0, 0, 0); }
+EOF
+  compile_binary
+}
+
+check_bzlib()
+{
+  cat > $TMPC <<EOF
+  #include <bzlib.h>
+  void main() { BZ2_bzBuffToBuffDecompress(0, 0, 0, 0, 0, 0); }
+EOF
+  compile_object
+}
+
+check_libpng()
+{
+  cat > $TMPC <<EOF
+  #include <png.h>
+  void main() { png_init_io(0, 0); }
+EOF
+  compile_binary
+}
+
+check_oss()
+{
+  cat > $TMPC <<EOF
+  #include <sys/soundcard.h>
+  #include <sys/ioctl.h>
+  void main() { int a=0; ioctl(0, SNDCTL_DSP_SETFMT, &a); }
+EOF
+  compile_binary
+}
+
+check_alsa()
+{
+  cat > $TMPC <<EOF
+  #include <alsa/asoundlib.h>
+  void main() { snd_pcm_open(0, 0, 0, 0); }
+EOF
+  compile_binary "$@"
+}
+
+check_sdl()
+{
+  cat > $TMPC <<EOF
+  #include <SDL.h>
+  void main() { SDL_OpenAudio(0, 0); }
+EOF
+  compile_binary "$@"
+}
+
+check_zlib || fail "please install libz-dev"
+check_bzlib || fail "please install libbz2-dev"
+check_libpng || fail "please install libpng-dev"
+
+# find what audio support we can compile
+if [ "x$sound_drivers" = "x" ]; then
+  if check_oss; then sound_drivers="$sound_drivers oss"; fi
+  if check_alsa -lasound; then sound_drivers="$sound_drivers alsa"; fi
+  if check_sdl; then sound_drivers="$sound_drivers sdl"; fi
+fi
+
+if echo $sound_drivers | grep -q "\<oss\>"; then
+  check_oss || fail "oss support missing"
+fi
+if echo $sound_drivers | grep -q "\<alsa\>"; then
+  MAIN_LDLIBS="$MAIN_LDLIBS -lasound"
+  check_alsa || fail "please install libasound2-dev"
+fi
+if echo $sound_drivers | grep -q "\<sdl\>"; then
+  echo $MAIN_LDLIBS | grep -qi SDL || CFLAGS="$CFLAGS `sdl-config --cflags`"
+  echo $MAIN_LDLIBS | grep -qi SDL || MAIN_LDLIBS="$MAIN_LDLIBS `sdl-config --libs`"
+  check_sdl || fail "please install libsdl1.2-dev"
+fi
+
 # check for tslib (only headers needed)
 if [ "x$have_tslib" = "x" ]; then
   cat > $TMPC <<EOF
@@ -299,10 +388,11 @@ test "x$have_arm_neon" != "x" || have_arm_neon="no"
 echo "architecture        $ARCH"
 echo "platform            $platform"
 echo "built-in GPU        $builtin_gpu"
-echo "sound driver        $sound_driver"
+echo "sound drivers       $sound_drivers"
 echo "plugins             $plugins_short"
 echo "C compiler          $CC"
 echo "C compiler flags    $CFLAGS"
+echo "libraries           $MAIN_LDLIBS"
 echo "linker flags        $LDFLAGS"
 echo "enable dynarec      $enable_dynarec"
 echo "ARMv7 optimizations $have_armv7"
@@ -320,7 +410,7 @@ echo "AS = $AS" >> $config_mak
 echo "CFLAGS += $CFLAGS" >> $config_mak
 echo "ASFLAGS += $ASFLAGS" >> $config_mak
 echo "LDFLAGS += $LDFLAGS" >> $config_mak
-echo "LDLIBS += $LDLIBS" >> $config_mak
+echo "MAIN_LDLIBS += $MAIN_LDLIBS" >> $config_mak
 echo "PLUGIN_CFLAGS += $PLUGIN_CFLAGS" >> $config_mak
 echo >> $config_mak
 
@@ -330,7 +420,7 @@ fi
 echo "ARCH = $ARCH" >> $config_mak
 echo "PLATFORM = $platform" >> $config_mak
 echo "BUILTIN_GPU = $builtin_gpu" >> $config_mak
-echo "SOUND_DRIVER = $sound_driver" >> $config_mak
+echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
 if [ "$ARCH" = "arm" ]; then
   echo "PLUGINS = $plugins" >> $config_mak
 else
index 29276bd..a0b9f46 100644 (file)
@@ -12,6 +12,7 @@
 #include "../libpcsxcore/misc.h"
 #include "../libpcsxcore/psxcounters.h"
 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
+#include "../plugins/dfsound/out.h"
 #include "main.h"
 #include "plugin.h"
 #include "plugin_lib.h"
@@ -100,15 +101,16 @@ void pl_update_gun(int *xn, int *xres, int *y, int *in)
 }
 
 /* sound calls */
-void SetupSound(void)
+static int snd_init(void)
 {
+       return 0;
 }
 
-void RemoveSound(void)
+static void snd_finish(void)
 {
 }
 
-unsigned long SoundGetBytesBuffered(void)
+static int snd_busy(void)
 {
        if (samples_to_send > samples_sent)
                return 0; /* give more samples */
@@ -116,12 +118,21 @@ unsigned long SoundGetBytesBuffered(void)
                return 1;
 }
 
-void SoundFeedStreamData(void *buf, long bytes)
+static void snd_feed(void *buf, int bytes)
 {
        audio_batch_cb(buf, bytes / 4);
        samples_sent += bytes / 4;
 }
 
+void out_register_libretro(struct out_driver *drv)
+{
+       drv->name = "libretro";
+       drv->init = snd_init;
+       drv->finish = snd_finish;
+       drv->busy = snd_busy;
+       drv->feed = snd_feed;
+}
+
 /* libretro */
 void retro_set_environment(retro_environment_t cb) { environ_cb = cb; }
 void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
index c67943a..58900cc 100644 (file)
  *                                                                         *
  ***************************************************************************/
 
-#include "stdafx.h"
-
-#define _IN_OSS
-
-#include "externals.h"
-
+#include <stdio.h>
 #define ALSA_PCM_NEW_HW_PARAMS_API
 #define ALSA_PCM_NEW_SW_PARAMS_API
 #include <alsa/asoundlib.h>
+#include "out.h"
 
 static snd_pcm_t *handle = NULL;
 static snd_pcm_uframes_t buffer_size;
 
 // SETUP SOUND
-void SetupSound(void)
+static int alsa_init(void)
 {
  snd_pcm_hw_params_t *hwparams;
  snd_pcm_status_t *status;
@@ -49,13 +45,13 @@ void SetupSound(void)
                       SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)) < 0)
   {
    printf("Audio open error: %s\n", snd_strerror(err));
-   return;
+   return -1;
   }
 
  if((err = snd_pcm_nonblock(handle, 0))<0)
   {
    printf("Can't set blocking moded: %s\n", snd_strerror(err));
-   return;
+   return -1;
   }
 
  snd_pcm_hw_params_alloca(&hwparams);
@@ -63,63 +59,64 @@ void SetupSound(void)
  if((err=snd_pcm_hw_params_any(handle, hwparams))<0)
   {
    printf("Broken configuration for this PCM: %s\n", snd_strerror(err));
-   return;
+   return -1;
   }
 
  if((err=snd_pcm_hw_params_set_access(handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED))<0)
   {
    printf("Access type not available: %s\n", snd_strerror(err));
-   return;
+   return -1;
   }
 
  if((err=snd_pcm_hw_params_set_format(handle, hwparams, format))<0)
   {
    printf("Sample format not available: %s\n", snd_strerror(err));
-   return;
+   return -1;
   }
 
  if((err=snd_pcm_hw_params_set_channels(handle, hwparams, pchannels))<0)
   {
    printf("Channels count not available: %s\n", snd_strerror(err));
-   return;
+   return -1;
   }
 
  if((err=snd_pcm_hw_params_set_rate_near(handle, hwparams, &pspeed, 0))<0)
   {
    printf("Rate not available: %s\n", snd_strerror(err));
-   return;
+   return -1;
   }
 
  if((err=snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, 0))<0)
   {
    printf("Buffer time error: %s\n", snd_strerror(err));
-   return;
+   return -1;
   }
 
  if((err=snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, 0))<0)
   {
    printf("Period time error: %s\n", snd_strerror(err));
-   return;
+   return -1;
   }
 
  if((err=snd_pcm_hw_params(handle, hwparams))<0)
   {
    printf("Unable to install hw params: %s\n", snd_strerror(err));
-   return;
+   return -1;
   }
 
  snd_pcm_status_alloca(&status);
  if((err=snd_pcm_status(handle, status))<0)
   {
    printf("Unable to get status: %s\n", snd_strerror(err));
-   return;
+   return -1;
   }
 
  buffer_size = snd_pcm_status_get_avail(status);
+ return 0;
 }
 
 // REMOVE SOUND
-void RemoveSound(void)
+static void alsa_finish(void)
 {
  if(handle != NULL)
   {
@@ -130,9 +127,9 @@ void RemoveSound(void)
 }
 
 // GET BYTES BUFFERED
-unsigned long SoundGetBytesBuffered(void)
+static int alsa_busy(void)
 {
unsigned long l;
int l;
 
  if (handle == NULL)                                 // failed to open?
   return 1;
@@ -146,7 +143,7 @@ unsigned long SoundGetBytesBuffered(void)
 }
 
 // FEED SOUND DATA
-void SoundFeedStreamData(unsigned char* pSound,long lBytes)
+static void alsa_feed(void *pSound, int lBytes)
 {
  if (handle == NULL) return;
 
@@ -154,3 +151,12 @@ void SoundFeedStreamData(unsigned char* pSound,long lBytes)
   snd_pcm_prepare(handle);
  snd_pcm_writei(handle,pSound, lBytes / 4);
 }
+
+void out_register_alsa(struct out_driver *drv)
+{
+       drv->name = "alsa";
+       drv->init = alsa_init;
+       drv->finish = alsa_finish;
+       drv->busy = alsa_busy;
+       drv->feed = alsa_feed;
+}
diff --git a/plugins/dfsound/dsoundoss.h b/plugins/dfsound/dsoundoss.h
deleted file mode 100644 (file)
index 543b297..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/***************************************************************************
-                         dsoundoss.h  -  description
-                             -------------------
-    begin                : Wed May 15 2002
-    copyright            : (C) 2002 by Pete Bernert
-    email                : BlackDove@addcom.de
- ***************************************************************************/
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version. See also the license.txt file for *
- *   additional informations.                                              *
- *                                                                         *
- ***************************************************************************/
-
-void SetupSound(void);
-void RemoveSound(void);
-unsigned long SoundGetBytesBuffered(void);
-void SoundFeedStreamData(unsigned char* pSound,long lBytes);
index bf07909..d8714df 100644 (file)
@@ -1,24 +1,32 @@
-#include "stdafx.h"
-#define _IN_OSS
-#include "externals.h"
+#include "out.h"
 
 // SETUP SOUND
-void SetupSound(void)
+static int none_init(void)
 {
+  return 0;
 }
 
 // REMOVE SOUND
-void RemoveSound(void)
+static void none_finish(void)
 {
 }
 
 // GET BYTES BUFFERED
-unsigned long SoundGetBytesBuffered(void)
+static int none_busy(void)
 {
-  return 0;
+  return 1;
 }
 
 // FEED SOUND DATA
-void SoundFeedStreamData(unsigned char* pSound,long lBytes)
+static void none_feed(void *buf, int bytes)
+{
+}
+
+void out_register_none(struct out_driver *drv)
 {
+       drv->name = "none";
+       drv->init = none_init;
+       drv->finish = none_finish;
+       drv->busy = none_busy;
+       drv->feed = none_feed;
 }
index 04d7446..709cb37 100644 (file)
  *                                                                         *
  ***************************************************************************/
 
-#include "stdafx.h"
-
-#define _IN_OSS
-
-#include "externals.h"
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <sys/soundcard.h>
+#include "out.h"
 
 ////////////////////////////////////////////////////////////////////////
 // oss globals
@@ -37,7 +40,7 @@ extern int errno;
 // SETUP SOUND
 ////////////////////////////////////////////////////////////////////////
 
-void SetupSound(void)
+static int oss_init(void)
 {
  int pspeed=44100;
  int pstereo;
@@ -52,14 +55,14 @@ void SetupSound(void)
 
  if((oss_audio_fd=open("/dev/dsp",O_WRONLY,0))==-1)
   {
-   printf("Sound device not available!\n");
-   return;
+   printf("OSS device not available\n");
+   return -1;
   }
 
  if(ioctl(oss_audio_fd,SNDCTL_DSP_RESET,0)==-1)
   {
    printf("Sound reset failed\n");
-   return;
+   return -1;
   }
 
  // we use 64 fragments with 1024 bytes each
@@ -71,7 +74,7 @@ void SetupSound(void)
  if(ioctl(oss_audio_fd,SNDCTL_DSP_SETFRAGMENT,&myfrag)==-1)
   {
    printf("Sound set fragment failed!\n");
-   return;        
+   return -1;
   }
 
  format = AFMT_S16_NE;
@@ -79,39 +82,41 @@ void SetupSound(void)
  if(ioctl(oss_audio_fd,SNDCTL_DSP_SETFMT,&format) == -1)
   {
    printf("Sound format not supported!\n");
-   return;
+   return -1;
   }
 
  if(format!=AFMT_S16_NE)
   {
    printf("Sound format not supported!\n");
-   return;
+   return -1;
   }
 
  if(ioctl(oss_audio_fd,SNDCTL_DSP_STEREO,&oss_stereo)==-1 || !oss_stereo)
   {
    printf("Stereo mode not supported!\n");
-   return;
+   return -1;
   }
 
  if(ioctl(oss_audio_fd,SNDCTL_DSP_SPEED,&oss_speed)==-1)
   {
    printf("Sound frequency not supported\n");
-   return;
+   return -1;
   }
 
  if(oss_speed!=pspeed)
   {
    printf("Sound frequency not supported\n");
-   return;
+   return -1;
   }
+
+ return 0;
 }
 
 ////////////////////////////////////////////////////////////////////////
 // REMOVE SOUND
 ////////////////////////////////////////////////////////////////////////
 
-void RemoveSound(void)
+static void oss_finish(void)
 {
  if(oss_audio_fd != -1 )
   {
@@ -121,10 +126,10 @@ void RemoveSound(void)
 }
 
 ////////////////////////////////////////////////////////////////////////
-// GET BYTES BUFFERED
+// GET BUFFERED STATUS
 ////////////////////////////////////////////////////////////////////////
 
-unsigned long SoundGetBytesBuffered(void)
+static int oss_busy(void)
 {
  audio_buf_info info;
  unsigned long l;
@@ -146,8 +151,17 @@ unsigned long SoundGetBytesBuffered(void)
 // FEED SOUND DATA
 ////////////////////////////////////////////////////////////////////////
 
-void SoundFeedStreamData(unsigned char* pSound,long lBytes)
+static void oss_feed(void *buf, int bytes)
 {
  if(oss_audio_fd == -1) return;
- write(oss_audio_fd,pSound,lBytes);
+ write(oss_audio_fd, buf, bytes);
+}
+
+void out_register_oss(struct out_driver *drv)
+{
+       drv->name = "oss";
+       drv->init = oss_init;
+       drv->finish = oss_finish;
+       drv->busy = oss_busy;
+       drv->feed = oss_feed;
 }
diff --git a/plugins/dfsound/out.c b/plugins/dfsound/out.c
new file mode 100644 (file)
index 0000000..150d718
--- /dev/null
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "out.h"
+
+#define MAX_OUT_DRIVERS 5
+
+static struct out_driver out_drivers[MAX_OUT_DRIVERS];
+struct out_driver *out_current;
+static int driver_count;
+
+#define REGISTER_DRIVER(d) { \
+       extern void out_register_##d(struct out_driver *drv); \
+       out_register_##d(&out_drivers[driver_count++]); \
+}
+
+void SetupSound(void)
+{
+       int i;
+
+       if (driver_count == 0) {
+#ifdef HAVE_OSS
+               REGISTER_DRIVER(oss);
+#endif
+#ifdef HAVE_ALSA
+               REGISTER_DRIVER(alsa);
+#endif
+#ifdef HAVE_SDL
+               REGISTER_DRIVER(sdl);
+#endif
+#ifdef HAVE_PULSE
+               REGISTER_DRIVER(pulse);
+#endif
+#ifdef HAVE_LIBRETRO
+               REGISTER_DRIVER(libretro);
+#endif
+               REGISTER_DRIVER(none);
+       }
+
+       for (i = 0; i < driver_count; i++)
+               if (out_drivers[i].init() == 0)
+                       break;
+
+       if (i < 0 || i >= driver_count) {
+               printf("the impossible happened\n");
+               abort();
+       }
+
+       out_current = &out_drivers[i];
+       printf("selected sound output driver: %s\n", out_current->name);
+}
+
diff --git a/plugins/dfsound/out.h b/plugins/dfsound/out.h
new file mode 100644 (file)
index 0000000..4607099
--- /dev/null
@@ -0,0 +1,12 @@
+
+struct out_driver {
+       const char *name;
+       int (*init)(void);
+       void (*finish)(void);
+       int (*busy)(void);
+       void (*feed)(void *data, int bytes);
+};
+
+extern struct out_driver *out_current;
+
+void SetupSound(void);
index 1dadd88..057c2c4 100644 (file)
@@ -19,8 +19,6 @@ comment              : Much of this was taken from simple.c, in the pulseaudio
 
 #include "stdafx.h"
 
-#ifdef USEPULSEAUDIO
-
 #define _IN_OSS
 
 #include "externals.h"
@@ -136,7 +134,7 @@ static void stream_request_cb (pa_stream *stream, size_t length, void *userdata)
 // SETUP SOUND
 ////////////////////////////////////////////////////////////////////////
 
-void SetupSound (void)
+static void pulse_init(void)
 {
      int error_number;
 
@@ -145,7 +143,7 @@ void SetupSound (void)
      if (device.mainloop == NULL)
      {
          fprintf (stderr, "Could not acquire PulseAudio main loop\n");
-         return;
+         return -1;
      }
 
      // Acquire context ////////////////////////////////////////////////////////
@@ -156,7 +154,7 @@ void SetupSound (void)
      if (device.context == NULL)
      {
          fprintf (stderr, "Could not acquire PulseAudio device context\n");
-         return;
+         return -1;
      }
 
      // Connect to PulseAudio server ///////////////////////////////////////////
@@ -164,7 +162,7 @@ void SetupSound (void)
      {
          error_number = pa_context_errno (device.context);
          fprintf (stderr, "Could not connect to PulseAudio server: %s\n", pa_strerror(error_number));
-         return;
+         return -1;
      }
 
      // Run mainloop until sever context is ready //////////////////////////////
@@ -172,7 +170,7 @@ void SetupSound (void)
      if (pa_threaded_mainloop_start (device.mainloop) < 0)
      {
          fprintf (stderr, "Could not start mainloop\n");
-         return;
+         return -1;
      }
 
      pa_context_state_t context_state;
@@ -184,7 +182,7 @@ void SetupSound (void)
          {
               error_number = pa_context_errno (device.context);
               fprintf (stderr, "Context state is not good: %s\n", pa_strerror (error_number));
-              return;
+              return -1;
          }
          else if (context_state == PA_CONTEXT_READY)
               break;
@@ -216,7 +214,7 @@ void SetupSound (void)
      {
          error_number = pa_context_errno (device.context);
          fprintf (stderr, "Could not acquire new PulseAudio stream: %s\n", pa_strerror (error_number));
-         return;
+         return -1;
      }
 
      // Set callbacks for server events ////////////////////////////////////////
@@ -231,7 +229,7 @@ void SetupSound (void)
      {
          pa_context_errno (device.context);
          fprintf (stderr, "Could not connect for playback: %s\n", pa_strerror (error_number));
-         return;
+         return -1;
      }
 
      // Run mainloop until stream is ready /////////////////////////////////////
@@ -248,7 +246,7 @@ void SetupSound (void)
          {
               error_number = pa_context_errno (device.context);
               fprintf (stderr, "Stream state is not good: %s\n", pa_strerror (error_number));
-              return;
+              return -1;
          }
          else
               fprintf (stderr, "PulseAudio stream state is %d\n", stream_state);
@@ -258,13 +256,13 @@ void SetupSound (void)
      pa_threaded_mainloop_unlock (device.mainloop);
 
      fprintf  (stderr, "PulseAudio should be connected\n");
-     return;
+     return 0;
 }
 
 ////////////////////////////////////////////////////////////////////////
 // REMOVE SOUND
 ////////////////////////////////////////////////////////////////////////
-void RemoveSound (void)
+static void pulse_finish(void)
 {
      if (device.mainloop != NULL)
          pa_threaded_mainloop_stop (device.mainloop);
@@ -295,7 +293,7 @@ void RemoveSound (void)
 // GET BYTES BUFFERED
 ////////////////////////////////////////////////////////////////////////
 
-unsigned long SoundGetBytesBuffered (void)
+static int pulse_busy(void)
 {
      int free_space;
      int error_code;
@@ -329,7 +327,7 @@ unsigned long SoundGetBytesBuffered (void)
 // FEED SOUND DATA
 ////////////////////////////////////////////////////////////////////////
 
-void SoundFeedStreamData (unsigned char *pSound, long lBytes)
+static void pulse_feed(void *pSound, int lBytes)
 {
      int error_code;
      int size;
@@ -348,4 +346,12 @@ void SoundFeedStreamData (unsigned char *pSound, long lBytes)
          }
      }
 }
-#endif
+
+void out_register_pulse(struct out_driver *drv)
+{
+       drv->name = "pulseaudio";
+       drv->init = pulse_init;
+       drv->finish = pulse_finish;
+       drv->busy = pulse_busy;
+       drv->feed = pulse_feed;
+}
index f7dc298..ce92b6e 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA
  */
 
-#include "stdafx.h"
-
-#include "externals.h"
+#include <stdlib.h>
 #include <SDL.h>
+#include "out.h"
 
 #define BUFFER_SIZE            22050
 
@@ -61,10 +60,10 @@ static void DestroySDL() {
        }
 }
 
-void SetupSound(void) {
+static int sdl_init(void) {
        SDL_AudioSpec                           spec;
 
-       if (pSndBuffer != NULL) return;
+       if (pSndBuffer != NULL) return -1;
 
        InitSDL();
 
@@ -76,7 +75,7 @@ void SetupSound(void) {
 
        if (SDL_OpenAudio(&spec, NULL) < 0) {
                DestroySDL();
-               return;
+               return -1;
        }
 
        iBufSize = BUFFER_SIZE;
@@ -84,16 +83,17 @@ void SetupSound(void) {
        pSndBuffer = (short *)malloc(iBufSize * sizeof(short));
        if (pSndBuffer == NULL) {
                SDL_CloseAudio();
-               return;
+               return -1;
        }
 
        iReadPos = 0;
        iWritePos = 0;
 
        SDL_PauseAudio(0);
+       return 0;
 }
 
-void RemoveSound(void) {
+static void sdl_finish(void) {
        if (pSndBuffer == NULL) return;
 
        SDL_CloseAudio();
@@ -103,7 +103,7 @@ void RemoveSound(void) {
        pSndBuffer = NULL;
 }
 
-unsigned long SoundGetBytesBuffered(void) {
+static int sdl_busy(void) {
        int size;
 
        if (pSndBuffer == NULL) return 1;
@@ -116,7 +116,7 @@ unsigned long SoundGetBytesBuffered(void) {
        return 0;
 }
 
-void SoundFeedStreamData(unsigned char *pSound, long lBytes) {
+static void sdl_feed(void *pSound, int lBytes) {
        short *p = (short *)pSound;
 
        if (pSndBuffer == NULL) return;
@@ -132,3 +132,12 @@ void SoundFeedStreamData(unsigned char *pSound, long lBytes) {
                lBytes -= sizeof(short);
        }
 }
+
+void out_register_sdl(struct out_driver *drv)
+{
+       drv->name = "sdl";
+       drv->init = sdl_init;
+       drv->finish = sdl_finish;
+       drv->busy = sdl_busy;
+       drv->feed = sdl_feed;
+}
index bbbe1e3..45a7886 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "externals.h"
 #include "registers.h"
-#include "dsoundoss.h"
+#include "out.h"
 
 #ifdef ENABLE_NLS
 #include <libintl.h>
@@ -697,7 +697,7 @@ static int do_samples(int forced_updates)
    // until enuff free place is available/a new channel gets
    // started
 
-   if(!forced_updates && SoundGetBytesBuffered())      // still enuff data in sound buffer?
+   if(!forced_updates && out_current->busy())          // still enuff data in sound buffer?
     {
      return 0;
     }
@@ -872,7 +872,7 @@ static int do_samples(int forced_updates)
   // wanna have around 1/60 sec (16.666 ms) updates
   if (iCycle++ > 16/FRAG_MSECS)
    {
-    SoundFeedStreamData((unsigned char *)pSpuBuffer,
+    out_current->feed(pSpuBuffer,
                         ((unsigned char *)pS) - ((unsigned char *)pSpuBuffer));
     pS = (short *)pSpuBuffer;
     iCycle = 0;
@@ -1056,7 +1056,7 @@ long CALLBACK SPUclose(void)
 
  bSPUIsOpen = 0;                                       // no more open
 
RemoveSound();                                        // no more sound handling
out_current->finish();                                // no more sound handling
 
  return 0;
 }
index 45b366b..d40344f 100644 (file)
@@ -23,9 +23,6 @@
 #include <sys/ioctl.h>
 #include <unistd.h>
 #include <fcntl.h>
-#ifdef USEOSS
-#include <sys/soundcard.h>
-#endif
 #include <unistd.h>
 #include <pthread.h>
 #define RRand(range) (random()%range)