From 347fdb3ba86b0318deac7082be8cb0933e8203cf Mon Sep 17 00:00:00 2001 From: Jacob Meuser Date: Sun, 9 May 2010 18:24:25 +0000 Subject: if the sample rate the hardware will use is different than the requested sample rate, scale the block/buffer sizes so the block/ buffer sizes the hardware will use are the same amount of *time* as the requested block/buffer sizes. ok ratchov@ --- lib/libsndio/sun.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/libsndio/sun.c b/lib/libsndio/sun.c index 6cf86db6a7d..d6c275dafdd 100644 --- a/lib/libsndio/sun.c +++ b/lib/libsndio/sun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sun.c,v 1.35 2010/04/29 21:09:50 ratchov Exp $ */ +/* $OpenBSD: sun.c,v 1.36 2010/05/09 18:24:24 jakemsr Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov * @@ -527,7 +527,7 @@ sun_setpar(struct sio_hdl *sh, struct sio_par *par) struct audio_info aui; unsigned i, infr, ibpf, onfr, obpf; unsigned bufsz, round; - unsigned rate, prec, enc; + unsigned rate, req_rate, prec, enc; /* * try to set parameters until the device accepts @@ -599,6 +599,19 @@ sun_setpar(struct sio_hdl *sh, struct sio_par *par) } } + /* + * If the rate that the hardware is using is different than + * the requested rate, scale buffer sizes so they will be the + * same time duration as what was requested. This just gets + * the rates to use for scaling, that actual scaling is done + * later. + */ + rate = (hdl->sio.mode & SIO_REC) ? aui.record.sample_rate : + aui.play.sample_rate; + req_rate = rate; + if (par->rate && par->rate != ~0U) + req_rate = par->rate; + /* * if block size and buffer size are not both set then * set the blocksize to half the buffer size @@ -606,11 +619,14 @@ sun_setpar(struct sio_hdl *sh, struct sio_par *par) bufsz = par->appbufsz; round = par->round; if (bufsz != ~0U) { + bufsz = bufsz * rate / req_rate; if (round == ~0U) round = (bufsz + 1) / 2; + else + round = round * rate / req_rate; } else if (round != ~0U) { - if (bufsz == ~0U) - bufsz = round * 2; + round = round * rate / req_rate; + bufsz = round * 2; } else return 1; -- cgit v1.2.3