summaryrefslogtreecommitdiff
path: root/lib/libsndio
diff options
context:
space:
mode:
authorJacob Meuser <jakemsr@cvs.openbsd.org>2010-05-09 18:24:25 +0000
committerJacob Meuser <jakemsr@cvs.openbsd.org>2010-05-09 18:24:25 +0000
commit347fdb3ba86b0318deac7082be8cb0933e8203cf (patch)
tree1630f7520789590b7bb0fccfbe9c5d9cb0dd48ad /lib/libsndio
parentf2ae3e657e198cdead18d513351b87cfe60f80a1 (diff)
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@
Diffstat (limited to 'lib/libsndio')
-rw-r--r--lib/libsndio/sun.c24
1 files changed, 20 insertions, 4 deletions
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 <alex@caoua.org>
*
@@ -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
@@ -600,17 +600,33 @@ 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
*/
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;