X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=linux%2Fsndout_oss.c;h=52496888f476132a21e32d346329432d57cfeca3;hb=d747e9d65ed765c7662f448703165c02776de930;hp=f74e706d57c817bb0f94ab0d416d8b21516c59cc;hpb=5f7b515538c52c9a4e137f35fe07011e4388a517;p=libpicofe.git diff --git a/linux/sndout_oss.c b/linux/sndout_oss.c index f74e706..5249688 100644 --- a/linux/sndout_oss.c +++ b/linux/sndout_oss.c @@ -25,33 +25,39 @@ int sndout_oss_init(void) return 0; } +void sndout_oss_stop(void) +{ + if (sounddev < 0) + return; + + ioctl(sounddev, SOUND_PCM_SYNC, 0); + close(sounddev); + sounddev = -1; +} + int sndout_oss_start(int rate, int frame_samples, int stereo) { static int s_oldrate = 0, s_old_fsamples = 0, s_oldstereo = 0; int frag, bsize, bits, ret; - // if no settings change, we don't need to do anything, - // since audio is never stopped - if (rate == s_oldrate && s_old_fsamples == frame_samples && s_oldstereo == stereo) + // GP2X: if no settings change, we don't need to do anything, + // since audio is never stopped there + if (sounddev >= 0 && rate == s_oldrate && s_old_fsamples == frame_samples && s_oldstereo == stereo) return 0; - if (sounddev >= 0) { - ioctl(sounddev, SOUND_PCM_SYNC, 0); - close(sounddev); - } - - sounddev = open("/dev/dsp", O_WRONLY|O_ASYNC); + sndout_oss_stop(); + sounddev = open("/dev/dsp", O_WRONLY); if (sounddev == -1) { perror("open(\"/dev/dsp\")"); - sounddev = open("/dev/dsp1", O_WRONLY|O_ASYNC); + sounddev = open("/dev/dsp1", O_WRONLY); if (sounddev == -1) { perror("open(\"/dev/dsp1\")"); return -1; } } - // calculate buffer size. We one to fit 1 frame worth of sound data. + // calculate buffer size. We want to fit 1 frame worth of sound data. // Also ignore mono because both GP2X and Wiz mixes mono to stereo anyway. bsize = frame_samples << 2; @@ -72,8 +78,10 @@ int sndout_oss_start(int rate, int frame_samples, int stereo) if (ret < 0) perror("failed to set audio format"); +#ifdef __GP2X__ // not sure if this is still needed (avoiding driver bugs?) usleep(192*1024); +#endif printf("sndout_oss_start: %d/%dbit/%s, %d buffers of %i bytes\n", rate, bits, stereo ? "stereo" : "mono", frag >> 16, 1 << (frag & 0xffff));