X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Flinux%2Fsndout_oss.c;h=2313d3fb8b2c14cdfa659b2c93a78aad187b8473;hb=a4edca53b489370b0814a74579acbcc183578355;hp=f9cc6c23da30dd32f6de77350bc86b857c13d07b;hpb=d40231e29a3e492b19612d7b6e9c7b9c2f9885a9;p=picodrive.git diff --git a/platform/linux/sndout_oss.c b/platform/linux/sndout_oss.c index f9cc6c2..2313d3f 100644 --- a/platform/linux/sndout_oss.c +++ b/platform/linux/sndout_oss.c @@ -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;