Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New function for RRESAMP. #316

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/liquid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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] */ \
unsigned int RRESAMP(_execute_nonblock)(RRESAMP() _q, \
TI * _x, \
unsigned int _n, \
TO * _y);

LIQUID_RRESAMP_DEFINE_API(LIQUID_RRESAMP_MANGLE_RRRF,
float,
Expand Down
33 changes: 33 additions & 0 deletions src/filter/src/rresamp.proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down