summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2016-05-27 16:18:59 +0000
committerratchov <ratchov@openbsd.org>2016-05-27 16:18:59 +0000
commitf2e307d4351505bc11d0a0beacbc5261b1605ef2 (patch)
tree8c105e667c91e6de358c865556d0856c069e539a
parentFlush rec buffer if there's less than one block space left and refill (diff)
downloadwireguard-openbsd-f2e307d4351505bc11d0a0beacbc5261b1605ef2.tar.xz
wireguard-openbsd-f2e307d4351505bc11d0a0beacbc5261b1605ef2.zip
When resampling, use the exact resampling factor instead of the ratio
between input and output block sizes. This was inherited from sndiod, but is not required for files because they are continuous streams of samples and do not need to be split in blocks of equal duration. This change makes playback/recording rate match exactly the requested sample rate.
-rw-r--r--usr.bin/aucat/aucat.c4
-rw-r--r--usr.bin/aucat/dsp.c32
2 files changed, 32 insertions, 4 deletions
diff --git a/usr.bin/aucat/aucat.c b/usr.bin/aucat/aucat.c
index 6e025813f7b..3b1a3638a4b 100644
--- a/usr.bin/aucat/aucat.c
+++ b/usr.bin/aucat/aucat.c
@@ -310,7 +310,7 @@ slot_init(struct slot *s)
xmalloc(s->round * slot_nch * sizeof(adata_t));
}
if (s->afile.rate != dev_rate) {
- resamp_init(&s->resamp, s->round, dev_round,
+ resamp_init(&s->resamp, s->afile.rate, dev_rate,
slot_nch);
s->resampbuf =
xmalloc(dev_round * slot_nch * sizeof(adata_t));
@@ -329,7 +329,7 @@ slot_init(struct slot *s)
s->cmin, s->cmax,
s->cmin, s->cmax);
if (s->afile.rate != dev_rate) {
- resamp_init(&s->resamp, dev_round, s->round,
+ resamp_init(&s->resamp, dev_rate, s->afile.rate,
slot_nch);
s->resampbuf =
xmalloc(dev_round * slot_nch * sizeof(adata_t));
diff --git a/usr.bin/aucat/dsp.c b/usr.bin/aucat/dsp.c
index d1934f8b2cd..1a8b5eb2cdd 100644
--- a/usr.bin/aucat/dsp.c
+++ b/usr.bin/aucat/dsp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dsp.c,v 1.5 2016/05/27 15:38:27 ratchov Exp $ */
+/* $OpenBSD: dsp.c,v 1.6 2016/05/27 16:18:59 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -405,6 +405,19 @@ resamp_do(struct resamp *p, adata_t *in, adata_t *out, int icnt, int ocnt)
#endif
}
+static unsigned int
+uint_gcd(unsigned int a, unsigned int b)
+{
+ unsigned int r;
+
+ while (b > 0) {
+ r = a % b;
+ a = b;
+ b = r;
+ }
+ return a;
+}
+
/*
* initialize resampler with ibufsz/obufsz factor and "nch" channels
*/
@@ -412,7 +425,22 @@ void
resamp_init(struct resamp *p, unsigned int iblksz,
unsigned int oblksz, int nch)
{
- unsigned int i;
+ unsigned int i, g;
+
+ /*
+ * reduice iblksz/oblksz fraction
+ */
+ g = uint_gcd(iblksz, oblksz);
+ iblksz /= g;
+ oblksz /= g;
+
+ /*
+ * ensure weired rates dont cause integer overflows
+ */
+ while (iblksz > ADATA_UNIT || oblksz > ADATA_UNIT) {
+ iblksz >>= 1;
+ oblksz >>= 1;
+ }
p->iblksz = iblksz;
p->oblksz = oblksz;