From 36df64979fefe7d07f216c5609555782e79fad19 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Thu, 22 Sep 2011 16:22:46 +0200 Subject: [PATCH] rearanged downsampling to reduce code size --- ddc.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/ddc.c b/ddc.c index 732267f..59448c0 100644 --- a/ddc.c +++ b/ddc.c @@ -14,27 +14,25 @@ You should have received a copy of the CC0 Public Domain Dedication along with t void do_ddc(ddc_t *ddc, float *input, float complex *output) { - int in = 0; - ddc->s[ddc->last] = input[in++]; - ddc->last = (ddc->last + 1) < ddc->samples ? ddc->last + 1 : 0; - ddc->skip += ddc->L; // this works only for L <= M - for (int k = 0; k < ddc->L; k++) { - float complex sum = 0.0; - for (int i = ddc->offset, j = ddc->last; i < ddc->taps; i += ddc->L) { - sum += ddc->b[i] * ddc->s[j]; - j += j ? - 1 : ddc->samples - 1; - } - - ddc->offset = (ddc->offset + ddc->M) % ddc->L; - + for (int k = 0, last = ddc->last, in = 0; k < ddc->L; k++) { while (ddc->skip < ddc->M) { ddc->s[ddc->last] = input[in++]; + last = ddc->last; ddc->last = (ddc->last + 1) < ddc->samples ? ddc->last + 1 : 0; ddc->skip += ddc->L; } ddc->skip %= ddc->M; + + float complex sum = 0.0; + for (int i = ddc->offset; i < ddc->taps; i += ddc->L) { + sum += ddc->b[i] * ddc->s[last]; + last += last ? - 1 : ddc->samples - 1; + } + + ddc->offset = (ddc->offset + ddc->M) % ddc->L; + output[k] = ddc->osc * sum; ddc->osc *= ddc->d; // ddc->osc /= cabsf(ddc->osc); // not really needed @@ -51,7 +49,7 @@ ddc_t *alloc_ddc(float freq, float bw, float step, int taps, int L, int M, float ddc->s = malloc(sizeof(float) * ddc->samples); ddc->osc = I; ddc->d = cexpf(-I * 2.0 * M_PI * freq * ostep); - ddc->offset = 0; + ddc->offset = (M - 1) % L; ddc->last = 0; ddc->skip = 0; ddc->L = L;