support multiple sound drivers
authornotaz <notasas@gmail.com>
Sun, 23 Jun 2013 19:26:56 +0000 (22:26 +0300)
committernotaz <notasas@gmail.com>
Wed, 26 Jun 2013 00:07:08 +0000 (03:07 +0300)
Makefile
platform/common/emu.c
platform/common/emu.h
platform/common/menu_pico.c
platform/gp2x/plat.c
platform/libpicofe
platform/linux/emu.c
platform/linux/io.c

index 4cd832f..32d4b59 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,7 @@ CFLAGS += -Iplatform/linux/
 LDLIBS += -lm -lpng
 
 # tmp
-CFLAGS += `sdl-config --cflags`
+CFLAGS += `sdl-config --cflags` -DHAVE_SDL
 LDLIBS += `sdl-config --libs`
 
 all: PicoDrive
@@ -45,7 +45,8 @@ OBJS += platform/common/main.o platform/common/emu.o platform/common/menu_pico.o
 OBJS += platform/libpicofe/input.o platform/libpicofe/readpng.o \
        platform/libpicofe/fonts.o platform/libpicofe/linux/in_evdev.o \
        platform/libpicofe/linux/plat.o platform/libpicofe/linux/sndout_oss.o \
-       platform/libpicofe/plat_sdl.o platform/libpicofe/in_sdl.o
+       platform/libpicofe/plat_sdl.o platform/libpicofe/in_sdl.o \
+       platform/libpicofe/sndout.o platform/libpicofe/sndout_sdl.o
 
 OBJS += platform/libpicofe/plat_dummy.o
 
index 76765a4..e0c50af 100644 (file)
@@ -16,6 +16,7 @@
 #include "../libpicofe/posix.h"\r
 #include "../libpicofe/input.h"\r
 #include "../libpicofe/fonts.h"\r
+#include "../libpicofe/sndout.h"\r
 #include "../libpicofe/lprintf.h"\r
 #include "../libpicofe/plat.h"\r
 #include "emu.h"\r
@@ -45,6 +46,8 @@ int pico_pen_x = 320/2, pico_pen_y = 240/2;
 int pico_inp_mode = 0;\r
 int engineState = PGS_Menu;\r
 \r
+static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
+\r
 /* tmp buff to reduce stack usage for plats with small stack */\r
 static char static_buff[512];\r
 const char *rom_fname_reload;\r
@@ -1418,6 +1421,8 @@ void emu_init(void)
        PicoMessage = plat_status_msg_busy_next;\r
        PicoMCDopenTray = emu_tray_open;\r
        PicoMCDcloseTray = emu_tray_close;\r
+\r
+       sndout_init();\r
 }\r
 \r
 void emu_finish(void)\r
@@ -1440,6 +1445,42 @@ void emu_finish(void)
        pprof_finish();\r
 \r
        PicoExit();\r
+       sndout_exit();\r
+}\r
+\r
+static void snd_write_nonblocking(int len)\r
+{\r
+       sndout_write_nb(PsndOut, len);\r
+}\r
+\r
+void emu_sound_start(void)\r
+{\r
+       PsndOut = NULL;\r
+\r
+       if (currentConfig.EmuOpt & EOPT_EN_SOUND)\r
+       {\r
+               int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0;\r
+\r
+               PsndRerate(Pico.m.frame_count ? 1 : 0);\r
+\r
+               printf("starting audio: %i len: %i stereo: %i, pal: %i\n",\r
+                       PsndRate, PsndLen, is_stereo, Pico.m.pal);\r
+               sndout_start(PsndRate, is_stereo);\r
+               PicoWriteSound = snd_write_nonblocking;\r
+               plat_update_volume(0, 0);\r
+               memset(sndBuffer, 0, sizeof(sndBuffer));\r
+               PsndOut = sndBuffer;\r
+       }\r
+}\r
+\r
+void emu_sound_stop(void)\r
+{\r
+       sndout_stop();\r
+}\r
+\r
+void emu_sound_wait(void)\r
+{\r
+       sndout_wait();\r
 }\r
 \r
 static void skip_frame(int do_audio)\r
@@ -1477,6 +1518,7 @@ void emu_loop(void)
 \r
        plat_video_loop_prepare();\r
        pemu_loop_prep();\r
+       pemu_sound_start();\r
 \r
        /* number of ticks per frame */\r
        if (Pico.m.pal) {\r
@@ -1641,6 +1683,7 @@ void emu_loop(void)
        }\r
 \r
        pemu_loop_end();\r
+       emu_sound_stop();\r
 \r
        // pemu_loop_end() might want to do 1 frame for bg image,\r
        // so free CD buffer here\r
index faa4868..d63a1f0 100644 (file)
@@ -149,6 +149,11 @@ void  emu_get_game_name(char *str150);
 void  emu_set_fastforward(int set_on);
 void  emu_status_msg(const char *format, ...);
 
+/* default sound code */
+void  emu_sound_start(void);
+void  emu_sound_stop(void);
+void  emu_sound_wait(void);
+
 /* used by some (but not all) platforms */
 void  emu_cmn_forced_frame(int no_scale, int do_emu);
 
@@ -164,8 +169,6 @@ void pemu_forced_frame(int no_scale, int do_emu); // ..to g_menubg_src_ptr
 void pemu_finalize_frame(const char *fps, const char *notice_msg);
 
 void pemu_sound_start(void);
-void pemu_sound_stop(void);
-void pemu_sound_wait(void);
 
 void plat_early_init(void);
 void plat_init(void);
index 62b6b80..b6a8b04 100644 (file)
@@ -726,10 +726,10 @@ static void mplayer_loop(void)
                PDebugZ80Frame();
                if (in_menu_wait_any(NULL, 0) & PBTN_MA3)
                        break;
-               pemu_sound_wait();
+               emu_sound_wait();
        }
 
-       pemu_sound_stop();
+       emu_sound_stop();
 }
 
 static void draw_text_debug(const char *str, int skip, int from)
index 321a4b6..8815453 100644 (file)
@@ -198,9 +198,6 @@ void plat_init(void)
        // use buffer2 for menubg to save mem (using only buffers 0, 1 in menu)
        g_menubg_ptr = gp2x_screens[2];
 
-       // snd
-       sndout_oss_init();
-
        if (gp2x_dev_id == GP2X_DEV_CAANOO)
                in_set_config(in_name_to_id("evdev:pollux-analog"), IN_CFG_KEY_NAMES,
                                caanoo_keys, sizeof(caanoo_keys));
@@ -227,7 +224,5 @@ void plat_finish(void)
                dummy_finish();
                break;
        }
-
-       sndout_oss_exit();
 }
 
index 20b1430..26d3ca0 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 20b143089cc395dbcd51cac516a9e36f4ab6f5ac
+Subproject commit 26d3ca0d29e87a14943d29fcafc93da753df60cd
index 591db8a..25bb05c 100644 (file)
@@ -11,7 +11,6 @@
 \r
 #include "../libpicofe/menu.h"\r
 #include "../libpicofe/plat.h"\r
-#include "../libpicofe/linux/sndout_oss.h"\r
 #include "../common/emu.h"\r
 #include "../common/arm_utils.h"\r
 #include "version.h"\r
@@ -19,7 +18,6 @@
 #include <pico/pico_int.h>\r
 \r
 \r
-static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
 const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL };\r
 const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL };\r
 enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT };\r
@@ -209,43 +207,9 @@ void pemu_forced_frame(int no_scale, int do_emu)
        g_menubg_src_ptr = g_screen_ptr;\r
 }\r
 \r
-static void oss_write_nonblocking(int len)\r
-{\r
-       // sndout_oss_can_write() is not reliable, only use with no_frmlimit\r
-       if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len))\r
-               return;\r
-\r
-       sndout_oss_write_nb(PsndOut, len);\r
-}\r
-\r
 void pemu_sound_start(void)\r
 {\r
-       PsndOut = NULL;\r
-\r
-       if (currentConfig.EmuOpt & EOPT_EN_SOUND)\r
-       {\r
-               int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0;\r
-\r
-               PsndRerate(Pico.m.frame_count ? 1 : 0);\r
-\r
-               printf("starting audio: %i len: %i stereo: %i, pal: %i\n",\r
-                       PsndRate, PsndLen, is_stereo, Pico.m.pal);\r
-               sndout_oss_start(PsndRate, is_stereo, 1);\r
-               sndout_oss_setvol(currentConfig.volume, currentConfig.volume);\r
-               PicoWriteSound = oss_write_nonblocking;\r
-               plat_update_volume(0, 0);\r
-               memset(sndBuffer, 0, sizeof(sndBuffer));\r
-               PsndOut = sndBuffer;\r
-       }\r
-}\r
-\r
-void pemu_sound_stop(void)\r
-{\r
-}\r
-\r
-void pemu_sound_wait(void)\r
-{\r
-       // don't need to do anything, writes will block by themselves\r
+       emu_sound_start();\r
 }\r
 \r
 void plat_debug_cat(char *str)\r
@@ -262,14 +226,10 @@ void pemu_loop_prep(void)
 {\r
        apply_renderer();\r
        osd_text = osd_text16;\r
-\r
-       pemu_sound_start();\r
 }\r
 \r
 void pemu_loop_end(void)\r
 {\r
-       pemu_sound_stop();\r
-\r
        /* do one more frame for menu bg */\r
        pemu_forced_frame(0, 1);\r
 }\r
index 5a76696..1b912c9 100644 (file)
@@ -11,7 +11,6 @@
 
 #include "../libpicofe/menu.h"
 #include "../libpicofe/input.h"
-#include "../libpicofe/linux/sndout_oss.h"
 #include "../common/emu.h"
 #include "../common/input_pico.h"
 #include "version.h"
@@ -342,9 +341,6 @@ void plat_init(void)
        memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2);
        xlib_init();
 #endif
-
-       // snd
-       sndout_oss_init();
 }
 
 void plat_finish(void)
@@ -354,7 +350,6 @@ void plat_finish(void)
 #else
        free(g_screen_ptr);
 #endif
-       sndout_oss_exit();
 }
 
 /* misc */