On Mon, Nov 10, 2008 at 12:38:54AM +0100, Christian Weisgerber wrote: > This is a first draft of a new port of mpg123 1.6.0, created from > scratch as a replacement for our cadaverous audio/mpg123 port. >
works here, on i386 with various devices. > I have added a simple sndio backend. The output module API isn't > documented, so this involves a bit of guesswork. There is a function > to query the capabilities of the audio system, which could be > interfaced with sio_getcap() to enable resampling in mpg123. sio_getcap() returns the ``hardware'' capabilities, this is mainly for apps that need direct access to hardware and therefore do not run with the aucat(1) backend. IMO mpg123 (as most apps) should call sio_setpar() as you do, and possibly check that it worked with sio_getpar(). > I haven't bothered with this for a simple audio player--does anybody > think it would be worth it? > i don't think it's worth. below is a small diff for fixed rate devices: by calling sio_getpar(), and returning the rate/channels the mpg123 conversion code will be triggered if aucat is not running. as we're at it, check that the returned format is correct so mpg321 can fail rather than playing with the wrong format (eg. on envy(4) devices). that reminds me that audio/libao port should check this too. -- Alexandre --- files/sndio.c.old Mon Nov 10 11:02:16 2008 +++ files/sndio.c Mon Nov 10 11:22:31 2008 @@ -50,11 +50,20 @@ static int open_sndio(audio_output_t *ao) return -1; } - if (!sio_setpar(hdl, &par) || !sio_start(hdl)) { + if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par) || + !sio_start(hdl)) { sio_close(hdl); return -1; } - + if ((par.bits != 8 && par.bits != 16) || par.le != SIO_LE_NATIVE) { + sio_close(hdl); + return -1; + } + ao->rate = par.rate; + ao->channels = par.pchan; + ao->format = (par.bits == 8) ? + (par.sig ? MPG123_ENC_SIGNED_8 : MPG123_ENC_UNSIGNED_8) : + (par.sig ? MPG123_ENC_SIGNED_16 : MPG123_ENC_UNSIGNED_16); ao->userptr = hdl; return 0; } @@ -68,8 +77,12 @@ static int get_formats_sndio(audio_output_t *ao) static int write_sndio(audio_output_t *ao, unsigned char *buf, int len) { struct sio_hdl *hdl = (struct sio_hdl *)ao->userptr; + int count; - return (int)sio_write(hdl, buf, len); + count = (int)sio_write(hdl, buf, len); + if (count == 0 && sio_eof(hdl)) + return -1; + return count; } static void flush_sndio(audio_output_t *ao)