make OSS detect blocking, adjust audio API

git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@898 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2010-09-18 16:40:13 +00:00
parent b6eccda317
commit a33164fffe
8 changed files with 81 additions and 90 deletions

View file

@ -210,47 +210,27 @@ void plat_update_volume(int has_changed, int is_up)
void pemu_forced_frame(int no_scale, int do_emu)
{
int po_old = PicoOpt;
memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);
PicoOpt &= ~POPT_ALT_RENDERER;
PicoOpt |= POPT_ACC_SPRITES;
if (!no_scale)
PicoOpt |= POPT_EN_SOFTSCALE;
PicoDrawSetOutFormat(PDF_RGB555, 1);
PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
PicoDraw32xSetFrameMode(0, 0);
PicoDrawSetCallbacks(NULL, NULL);
Pico.m.dirtyPal = 1;
if (do_emu)
PicoFrame();
else
PicoFrameDrawOnly();
emu_cmn_forced_frame(no_scale, do_emu);
g_menubg_src_ptr = g_screen_ptr;
PicoOpt = po_old;
}
static void updateSound(int len)
static void oss_write_nonblocking(int len)
{
len <<= 1;
if (PicoOpt & POPT_EN_STEREO)
len <<= 1;
// sndout_oss_can_write() is not reliable, only use with no_frmlimit
if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len))
return;
/* avoid writing audio when lagging behind to prevent audio lag */
if (PicoSkipFrame != 2)
sndout_oss_write(PsndOut, len);
sndout_oss_write_nb(PsndOut, len);
}
void pemu_sound_start(void)
{
int target_fps = Pico.m.pal ? 50 : 60;
PsndOut = NULL;
if (currentConfig.EmuOpt & EOPT_EN_SOUND)
@ -263,7 +243,7 @@ void pemu_sound_start(void)
PsndRate, PsndLen, is_stereo, Pico.m.pal);
sndout_oss_start(PsndRate, is_stereo, 1);
sndout_oss_setvol(currentConfig.volume, currentConfig.volume);
PicoWriteSound = updateSound;
PicoWriteSound = oss_write_nonblocking;
plat_update_volume(0, 0);
memset(sndBuffer, 0, sizeof(sndBuffer));
PsndOut = sndBuffer;

View file

@ -98,6 +98,42 @@ int sndout_oss_write(const void *buff, int len)
return write(sounddev, buff, len);
}
#include "../common/plat.h"
/* not really non-blocking, just detects if blocking occurs
* and starts skipping writes in case it does. */
int sndout_oss_write_nb(const void *buff, int len)
{
static int lag_counter, skip_counter;
unsigned int t;
int ret;
if (lag_counter > 2) {
// skip writes if audio starts blocking
lag_counter = 0;
skip_counter = FRAG_COUNT;
}
if (skip_counter > 0) {
skip_counter--;
return len;
}
t = plat_get_ticks_ms();
ret = sndout_oss_write(buff, len);
t = plat_get_ticks_ms() - t;
if (t > 1) {
// this shouldn't really happen, most likely audio is out of sync
lag_counter++;
if (lag_counter > 2)
printf("audio lag %u\n", t);
}
else
lag_counter = 0;
return ret;
}
int sndout_oss_can_write(int bytes)
{
audio_buf_info bi;

View file

@ -2,6 +2,7 @@ int sndout_oss_init(void);
int sndout_oss_start(int rate, int stereo, int frames_in_frag);
void sndout_oss_stop(void);
int sndout_oss_write(const void *buff, int len);
int sndout_oss_write_nb(const void *buff, int len);
int sndout_oss_can_write(int bytes);
void sndout_oss_sync(void);
void sndout_oss_setvol(int l, int r);