X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=linux%2Fsndout_oss.c;h=6d4eded4241e94cbb0ff36ef799532cef656857d;hb=HEAD;hp=2313d3fb8b2c14cdfa659b2c93a78aad187b8473;hpb=a33164fffe6463cd0aa698fac2bcc1fc213af18e;p=libpicofe.git diff --git a/linux/sndout_oss.c b/linux/sndout_oss.c index 2313d3f..6d4eded 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 @@ -9,6 +20,9 @@ #include "sndout_oss.h" +int sndout_oss_frag_frames = 1; +int sndout_oss_can_restart = 1; + static int sounddev = -1, mixerdev = -1; static int can_write_safe; @@ -28,15 +42,22 @@ int sndout_oss_init(void) void sndout_oss_stop(void) { + /* restarting audio on GP2X causes trouble, + * not restarting on Caanoo causes trouble */ + if (!sndout_oss_can_restart) + return; + if (sounddev < 0) return; - ioctl(sounddev, SOUND_PCM_SYNC, 0); + // sync causes trouble on Caanoo.. + //ioctl(sounddev, SNDCTL_DSP_SYNC, 0); + close(sounddev); sounddev = -1; } -int sndout_oss_start(int rate, int stereo, int frames_in_frag) +int sndout_oss_start(int rate, int stereo) { static int s_oldrate = 0, s_oldstereo = 0; int frag, bsize, bits, ret; @@ -58,10 +79,11 @@ int sndout_oss_start(int rate, int stereo, int frames_in_frag) } } - // try to fit frames_in_frag frames worth of data in fragment + // try to fit sndout_oss_frag_frames (video) frames + // worth of sound data in OSS fragment // ignore mono because it's unlikely to be used and // both GP2X and Wiz mixes mono to stereo anyway. - bsize = (frames_in_frag * rate / 50) * 4; + bsize = (sndout_oss_frag_frames * rate / 50) * 4; for (frag = 0; bsize; bsize >>= 1, frag++) ; @@ -98,7 +120,7 @@ int sndout_oss_write(const void *buff, int len) return write(sounddev, buff, len); } -#include "../common/plat.h" +#include "../plat.h" /* not really non-blocking, just detects if blocking occurs * and starts skipping writes in case it does. */ @@ -153,9 +175,10 @@ int sndout_oss_can_write(int bytes) return bi.bytes - bi.fragsize >= bytes ? 1 : 0; } -void sndout_oss_sync(void) +void sndout_oss_wait(void) { - ioctl(sounddev, SOUND_PCM_SYNC, 0); + // FIXME? + ioctl(sounddev, SNDCTL_DSP_SYNC, 0); } void sndout_oss_setvol(int l, int r) @@ -169,7 +192,10 @@ void sndout_oss_setvol(int l, int r) void sndout_oss_exit(void) { - if (sounddev >= 0) close(sounddev); sounddev = -1; - if (mixerdev >= 0) close(mixerdev); mixerdev = -1; + if (sounddev >= 0) + close(sounddev); + if (mixerdev >= 0) + close(mixerdev); + sounddev = mixerdev = -1; }