From d88fa6fa9b696648caaed34b15ea6c5fa2852024 Mon Sep 17 00:00:00 2001 From: vvsvvsvvs Date: Fri, 10 Feb 2023 21:51:24 +0300 Subject: [PATCH 1/3] Update rresamp.proto.c to make input X array of any length It is a test-only proposal. The basic idea: we can feed any number of samples to the rresampler. Do not forget to make Y array of the corresponding length (enough to fit the output resampled data). Note: no changes to header files made (but required). --- src/filter/src/rresamp.proto.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/filter/src/rresamp.proto.c b/src/filter/src/rresamp.proto.c index 63a28bf61..1c4771dbe 100644 --- a/src/filter/src/rresamp.proto.c +++ b/src/filter/src/rresamp.proto.c @@ -35,6 +35,7 @@ struct RRESAMP(_s) { unsigned int Q; // decimation factor (primitive) unsigned int m; // filter semi-length, h_len = 2*m + 1 unsigned int block_len; // number of blocks to run in execute() + unsigned int index; // filterbank index FIRPFB() pfb; // filterbank object (interpolator), Q filters in bank }; @@ -70,6 +71,7 @@ RRESAMP() RRESAMP(_create)(unsigned int _interp, q->Q = _decim; q->m = _m; q->block_len = 1; + q->index = 0; // create poly-phase filter bank q->pfb = FIRPFB(_create)(q->P, _h, 2*q->P*q->m); @@ -323,6 +325,37 @@ void RRESAMP(_execute_block)(RRESAMP() _q, } } +// Execute rational-rate resampler on an arbitrary length block of input samples and +// store the resulting samples in the output array. +// _q : resamp object +// _x : input sample array, [size: _n] +// _n : input data size, samples +// _y : output sample array [size: ceil(_n x P/Q)] +unsigned int RRESAMP(_execute_nonblock)(RRESAMP() _q, + TI * _x, + unsigned int _n, + TO * _y) +{ + unsigned int i, n=0; + unsigned int index = _q->index; // relax compiler with non-volatile + + for (i=0; i<_n; i++) { + // push input + FIRPFB(_push)(_q->pfb, _x[i]); + + // continue to produce output + while (index < _q->P) { + FIRPFB(_execute)(_q->pfb, index, &_y[n++]); + index += _q->Q; + } + + // decrement filter-bank index by output rate + index -= _q->P; + } + _q->index = index; + return n; +} + // internal void RRESAMP(_execute_primitive)(RRESAMP() _q, TI * _x, From b2989a419e6e5abfc54f80307c6016bc04895926 Mon Sep 17 00:00:00 2001 From: vvsvvsvvs Date: Fri, 10 Feb 2023 22:01:07 +0300 Subject: [PATCH 2/3] Update liquid.h rresampler update with the new function. --- include/liquid.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/liquid.h b/include/liquid.h index 454ca0ac6..03e04e871 100644 --- a/include/liquid.h +++ b/include/liquid.h @@ -4470,6 +4470,16 @@ void RRESAMP(_execute_block)(RRESAMP() _q, \ TI * _x, \ unsigned int _n, \ TO * _y); \ + \ +/* Execute on an arbitrary length block of input samples */ \ +/* _q : resamp object */ \ +/* _x : input sample array, [size: decim*n x 1] */ \ +/* _n : block size */ \ +/* _y : output sample array, [size: interp*n x 1] */ \ +void RRESAMP(_execute_nonblock)(RRESAMP() _q, \ + TI * _x, \ + unsigned int _n, \ + TO * _y); LIQUID_RRESAMP_DEFINE_API(LIQUID_RRESAMP_MANGLE_RRRF, float, From 4ff1e9bb8f6b5f143c6fbe1d189b0daf987b676a Mon Sep 17 00:00:00 2001 From: vvsvvsvvs Date: Fri, 10 Feb 2023 22:11:18 +0300 Subject: [PATCH 3/3] Update liquid.h New function for rresampler. --- include/liquid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/liquid.h b/include/liquid.h index 03e04e871..19fcda059 100644 --- a/include/liquid.h +++ b/include/liquid.h @@ -4476,7 +4476,7 @@ void RRESAMP(_execute_block)(RRESAMP() _q, \ /* _x : input sample array, [size: decim*n x 1] */ \ /* _n : block size */ \ /* _y : output sample array, [size: interp*n x 1] */ \ -void RRESAMP(_execute_nonblock)(RRESAMP() _q, \ +unsigned int RRESAMP(_execute_nonblock)(RRESAMP() _q, \ TI * _x, \ unsigned int _n, \ TO * _y);