X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=linux%2Fsndout_oss.c;h=0df17b272a7a91b797049871c473a0774459c02b;hb=20b143089cc395dbcd51cac516a9e36f4ab6f5ac;hp=f9cc6c23da30dd32f6de77350bc86b857c13d07b;hpb=f679add71bb8f7e6480cd5ab62e8b489454739a4;p=libpicofe.git diff --git a/linux/sndout_oss.c b/linux/sndout_oss.c index f9cc6c2..0df17b2 100644 --- a/linux/sndout_oss.c +++ b/linux/sndout_oss.c @@ -1,3 +1,14 @@ +/* + * (C) Gražvydas "notaz" Ignotas, 2009-2010 + * + * This work is licensed under the terms of any of these licenses + * (at your option): + * - GNU GPL, version 2 or later. + * - GNU LGPL, version 2.1 or later. + * - MAME license. + * See the COPYING file in the top-level directory. + */ + /* sound output via OSS */ #include #include @@ -98,6 +109,42 @@ int sndout_oss_write(const void *buff, int len) return write(sounddev, buff, len); } +#include "../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;