=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/aucat/dsp.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- src/usr.bin/aucat/dsp.c 2016/05/26 06:17:31 1.4 +++ src/usr.bin/aucat/dsp.c 2016/05/27 15:38:27 1.5 @@ -1,4 +1,4 @@ -/* $OpenBSD: dsp.c,v 1.4 2016/05/26 06:17:31 ratchov Exp $ */ +/* $OpenBSD: dsp.c,v 1.5 2016/05/27 15:38:27 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -268,10 +268,38 @@ } /* - * resample the given number of frames + * return the number of output frames resamp_do() would produce with + * the given number of input frames */ +int +resamp_ocnt(struct resamp *p, int icnt) +{ + return ((long long)p->oblksz * icnt + p->diff) / p->iblksz; +} + +/* + * return the number of input frames resamp_do() needs in order to + * produce the given number of output frames + */ +int +resamp_icnt(struct resamp *p, int ocnt) +{ + return ((long long)p->iblksz * ocnt - p->diff + + p->oblksz - 1) / p->oblksz; +} + +/* + * Resample the given number of frames. The number of output frames + * must match the coresponding number the input frames. Either + * use: + * + * icnt * orate = ocnt * irate + * + * or use resamp_icnt() or resamp_ocnt() to calculate the proper + * numbers. + */ void -resamp_do(struct resamp *p, adata_t *in, adata_t *out, int *icnt, int *ocnt) +resamp_do(struct resamp *p, adata_t *in, adata_t *out, int icnt, int ocnt) { unsigned int nch; adata_t *idata; @@ -298,8 +326,8 @@ ctxbuf = p->ctx; ctx_start = p->ctx_start; nch = p->nch; - ifr = *icnt; - ofr = *ocnt; + ifr = icnt; + ofr = ocnt; /* * Start conversion. @@ -308,10 +336,10 @@ if (log_level >= 4) { log_puts("resamp: copying "); log_puti(ifr); - log_puts(" frames, diff = "); - log_putu(diff); - log_puts(", max = "); + log_puts(" -> "); log_putu(ofr); + log_puts(" frames, diff = "); + log_puti(diff); log_puts("\n"); } #endif @@ -361,8 +389,20 @@ } p->diff = diff; p->ctx_start = ctx_start; - *icnt -= ifr; - *ocnt -= ofr; +#ifdef DEBUG + if (ifr != 0) { + log_puts("resamp_do: "); + log_puti(ifr); + log_puts(": too many input frames\n"); + panic(); + } + if (ofr != 0) { + log_puts("resamp_do: "); + log_puti(ofr); + log_puts(": too many output frames\n"); + panic(); + } +#endif } /*