From: notaz Date: Sun, 23 Jun 2013 19:26:56 +0000 (+0300) Subject: support multiple sound drivers X-Git-Tag: v1.85~92 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df92fbd1f2d16f83b66a9941f7312fdfea2602ca;p=picodrive.git support multiple sound drivers --- diff --git a/Makefile b/Makefile index 4cd832f2..32d4b59f 100644 --- 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 diff --git a/platform/common/emu.c b/platform/common/emu.c index 76765a4d..e0c50aff 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -16,6 +16,7 @@ #include "../libpicofe/posix.h" #include "../libpicofe/input.h" #include "../libpicofe/fonts.h" +#include "../libpicofe/sndout.h" #include "../libpicofe/lprintf.h" #include "../libpicofe/plat.h" #include "emu.h" @@ -45,6 +46,8 @@ int pico_pen_x = 320/2, pico_pen_y = 240/2; int pico_inp_mode = 0; int engineState = PGS_Menu; +static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; + /* tmp buff to reduce stack usage for plats with small stack */ static char static_buff[512]; const char *rom_fname_reload; @@ -1418,6 +1421,8 @@ void emu_init(void) PicoMessage = plat_status_msg_busy_next; PicoMCDopenTray = emu_tray_open; PicoMCDcloseTray = emu_tray_close; + + sndout_init(); } void emu_finish(void) @@ -1440,6 +1445,42 @@ void emu_finish(void) pprof_finish(); PicoExit(); + sndout_exit(); +} + +static void snd_write_nonblocking(int len) +{ + sndout_write_nb(PsndOut, len); +} + +void emu_sound_start(void) +{ + PsndOut = NULL; + + if (currentConfig.EmuOpt & EOPT_EN_SOUND) + { + int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0; + + PsndRerate(Pico.m.frame_count ? 1 : 0); + + printf("starting audio: %i len: %i stereo: %i, pal: %i\n", + PsndRate, PsndLen, is_stereo, Pico.m.pal); + sndout_start(PsndRate, is_stereo); + PicoWriteSound = snd_write_nonblocking; + plat_update_volume(0, 0); + memset(sndBuffer, 0, sizeof(sndBuffer)); + PsndOut = sndBuffer; + } +} + +void emu_sound_stop(void) +{ + sndout_stop(); +} + +void emu_sound_wait(void) +{ + sndout_wait(); } static void skip_frame(int do_audio) @@ -1477,6 +1518,7 @@ void emu_loop(void) plat_video_loop_prepare(); pemu_loop_prep(); + pemu_sound_start(); /* number of ticks per frame */ if (Pico.m.pal) { @@ -1641,6 +1683,7 @@ void emu_loop(void) } pemu_loop_end(); + emu_sound_stop(); // pemu_loop_end() might want to do 1 frame for bg image, // so free CD buffer here diff --git a/platform/common/emu.h b/platform/common/emu.h index faa4868e..d63a1f0b 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -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); diff --git a/platform/common/menu_pico.c b/platform/common/menu_pico.c index 62b6b803..b6a8b044 100644 --- a/platform/common/menu_pico.c +++ b/platform/common/menu_pico.c @@ -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) diff --git a/platform/gp2x/plat.c b/platform/gp2x/plat.c index 321a4b67..88154535 100644 --- a/platform/gp2x/plat.c +++ b/platform/gp2x/plat.c @@ -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(); } diff --git a/platform/libpicofe b/platform/libpicofe index 20b14308..26d3ca0d 160000 --- a/platform/libpicofe +++ b/platform/libpicofe @@ -1 +1 @@ -Subproject commit 20b143089cc395dbcd51cac516a9e36f4ab6f5ac +Subproject commit 26d3ca0d29e87a14943d29fcafc93da753df60cd diff --git a/platform/linux/emu.c b/platform/linux/emu.c index 591db8a0..25bb05c5 100644 --- a/platform/linux/emu.c +++ b/platform/linux/emu.c @@ -11,7 +11,6 @@ #include "../libpicofe/menu.h" #include "../libpicofe/plat.h" -#include "../libpicofe/linux/sndout_oss.h" #include "../common/emu.h" #include "../common/arm_utils.h" #include "version.h" @@ -19,7 +18,6 @@ #include -static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL }; const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL }; enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT }; @@ -209,43 +207,9 @@ void pemu_forced_frame(int no_scale, int do_emu) g_menubg_src_ptr = g_screen_ptr; } -static void oss_write_nonblocking(int len) -{ - // sndout_oss_can_write() is not reliable, only use with no_frmlimit - if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len)) - return; - - sndout_oss_write_nb(PsndOut, len); -} - void pemu_sound_start(void) { - PsndOut = NULL; - - if (currentConfig.EmuOpt & EOPT_EN_SOUND) - { - int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0; - - PsndRerate(Pico.m.frame_count ? 1 : 0); - - printf("starting audio: %i len: %i stereo: %i, pal: %i\n", - PsndRate, PsndLen, is_stereo, Pico.m.pal); - sndout_oss_start(PsndRate, is_stereo, 1); - sndout_oss_setvol(currentConfig.volume, currentConfig.volume); - PicoWriteSound = oss_write_nonblocking; - plat_update_volume(0, 0); - memset(sndBuffer, 0, sizeof(sndBuffer)); - PsndOut = sndBuffer; - } -} - -void pemu_sound_stop(void) -{ -} - -void pemu_sound_wait(void) -{ - // don't need to do anything, writes will block by themselves + emu_sound_start(); } void plat_debug_cat(char *str) @@ -262,14 +226,10 @@ void pemu_loop_prep(void) { apply_renderer(); osd_text = osd_text16; - - pemu_sound_start(); } void pemu_loop_end(void) { - pemu_sound_stop(); - /* do one more frame for menu bg */ pemu_forced_frame(0, 1); } diff --git a/platform/linux/io.c b/platform/linux/io.c index 5a766966..1b912c98 100644 --- a/platform/linux/io.c +++ b/platform/linux/io.c @@ -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 */