diff options
author | 2010-05-09 18:24:24 +0000 | |
---|---|---|
committer | 2010-05-09 18:24:24 +0000 | |
commit | b2815c432593d7c81fcbda0c63d961a79e638f72 (patch) | |
tree | aa8355b0fc5b86ac3122bc1fea477fcd5e0e9a67 | |
parent | -Wstack-larger-than-N for hppa/hppa64. (diff) | |
download | wireguard-openbsd-b2815c432593d7c81fcbda0c63d961a79e638f72.tar.xz wireguard-openbsd-b2815c432593d7c81fcbda0c63d961a79e638f72.zip |
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@
-rw-r--r-- | lib/libsndio/sun.c | 24 |
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; |