support multiple sound drivers

This commit is contained in:
notaz 2013-06-23 22:26:56 +03:00
parent 636d5f257c
commit df92fbd1f2
8 changed files with 55 additions and 58 deletions

View file

@ -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

View 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);

View 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)