On Wed, Apr 21, 2010 at 04:32:17PM +0200, Eric Faurot wrote:
> Hi,
>
> - update to 0.6
> - implement sndio backend and get rid of ossaudio
>
> comments? ok?
>
Great! Few comment inlined below:
> +
> +#define bPS 16
> +#define BPS 2
> +
> +ad_rec_t *
> +ad_open_dev(const char *dev, int32 rate)
> +{
> + struct sio_hdl *hdl;
> + struct sio_par param;
> +
> + hdl = sio_open(dev, SIO_REC, 1);
> + if (hdl == NULL) {
> + fprintf(stderr, "ad_open_dev: sio_open(%s) failed\n");
> + return NULL;
> + }
> +
> + sio_initpar(¶m);
> + param.bits = bPS;
> + param.bps = BPS;
> + param.sig = 1;
> + param.le = 1;
this forces little endian on any arch; not 100% sure, but
looking at the alsa backend, native endianness seems what
the program expects. Ex.
par.le = SIO_LE_NATIVE;
> + param.rchan = 1;
> + param.rate = rate;
> + if (sio_setpar(&hdl, ¶m)) {
sio_setpar() returns 1 on success, so it should be:
if (!sio_setpar...)
> + fprintf(stderr, "ad_open_dev: sio_setpar() failed\n");
> + sio_close(hdl);
> + return NULL;
> + }
> + if (sio_getpar(&hdl, ¶m)) {
if (!sio_getpar...)
> + fprintf(stderr, "ad_open_dev: sio_getpar() failed\n");
> + sio_close(hdl);
> + return NULL;
> + }
> + if (param.bits != bPS ||
> + param.bps != BPS ||
> + param.sig != 1 ||
> + param.le != 1 ||
SIO_LE_NATIVE
> + param.rchan != 1 ||
> + param.rate != rate) {
> + fprintf(stderr, "ad_open_dev: can't set specified params\n");
> + sio_close(hdl);
> + return NULL;
> + }
> +
> + return (ad_rec_t*)hdl;
> +}
> +
> +ad_rec_t *
> +ad_open_sps(int32 rate)
> +{
> + return ad_open_dev(NULL, rate);
> +}
> +
> +ad_rec_t *
> +ad_open(void)
> +{
> + return ad_open_sps(DEFAULT_SAMPLES_PER_SEC);
> +}
> +
> +int32
> +ad_start_rec(ad_rec_t *r)
> +{
> + struct sio_hdl *hdl = (struct sio_hdl*)r;
> +
> + if (sio_start(hdl))
> + return AD_ERR_GEN;
if (!sio_start(hdl))
> +
> + return (0);
> +}
> +
> +int32
> +ad_stop_rec(ad_rec_t *r)
> +{
> + struct sio_hdl *hdl = (struct sio_hdl*)r;
> +
> + if (sio_stop(hdl))
> + return AD_ERR_GEN;
if (!sio_stop())
> +
> + return (0);
> +}
> +
> +
> +int32
> +ad_read(ad_rec_t *r, int16 *buf, int32 max)
> +{
> + size_t n;
> + struct sio_hdl *hdl = (struct sio_hdl*)r;
> +
> + n = sio_read(hdl, buf, max * BPS);
sio_read() may return a partial read, which may cause
alignement error in the next read, to avoid this:
n = sio_read(..., max * BPS);
todo = n % BPS;
while (todo > 0) {
done = sio_read(..., todo);
if (done == 0)
break; /* error */
todo -= done;
}
return n / BPS;
> + return (n / 2);
> +}
> +
> +int32
> +ad_close(ad_rec_t *r)
> +{
> + struct sio_hdl *hdl = (struct sio_hdl*)r;
> +
> + sio_close(hdl);
> + return (0);
> +}
-- Alexandre