File resamp_core.h¶
FileList > inc > resamp > resamp_core.h
Go to the source code of this file
Continuously-variable polyphase resampler for CF32 IQ. More...
#include "clib_common.h"#include "dp_state.h"
Classes¶
| Type | Name |
|---|---|
| struct | resamp_state_t |
Public Functions¶
| Type | Name |
|---|---|
| resamp_state_t * | resamp_create (double rate) |
| resamp_state_t * | resamp_create_custom (size_t num_phases, size_t num_taps, const float * bank, double rate) |
| void | resamp_destroy (resamp_state_t * state) |
| size_t | resamp_execute (resamp_state_t * state, const float _Complex * in, size_t num_in, float _Complex * out, size_t max_out) Resample a block of CF32 samples (fixed rate). |
| size_t | resamp_execute_ctrl (resamp_state_t * state, const float _Complex * in, const float _Complex * ctrl, size_t num_in, float _Complex * out, size_t max_out) Resample with per-sample additive rate deviation. |
| size_t | resamp_get_num_phases (const resamp_state_t * state) |
| size_t | resamp_get_num_taps (const resamp_state_t * state) |
| double | resamp_get_rate (const resamp_state_t * state) |
| void | resamp_get_state (const resamp_state_t * state, void * blob) Serialize state's mutable state intoblob . |
| void | resamp_reset (resamp_state_t * state) |
| void | resamp_set_rate (resamp_state_t * state, double rate) |
| int | resamp_set_state (resamp_state_t * state, const void * blob) Restore mutable state from blob (same rate). |
| size_t | resamp_state_bytes (const resamp_state_t * state) Bytes resamp_get_state() writes for state (envelope + payload). |
Macros¶
| Type | Name |
|---|---|
| define | RESAMP_STATE_MAGIC [**DP\_FOURCC**](dp__state_8h.md#define-dp_fourcc) ('R', 'S', 'M', 'P') |
| define | RESAMP_STATE_VERSION 1u |
Detailed Description¶
Two execute paths:
resamp_execute — dual-mode: * Interpolation (rate >= 1): output-driven, one NCO tick per output sample, overflow pushes the next input into the delay line. * Decimation (rate < 1): input-driven transposed-form polyphase. Each input is multiplied by the current polyphase arm and accumulated into N integrate-and-dump registers; on NCO overflow the I&D dump through a transposed tapped delay line to produce one output. Bank coefficients are pre-scaled by rate so the passband gain is unity.
resamp_execute_ctrl — unified input-driven with a double-precision accumulator that handles all rates and per-sample deviations. Each input advances the accumulator by (rate + ctrl(i)); every time the accumulator crosses 1.0 an output is emitted.
Phase accumulator (execute): upper log2(num_phases) bits of the 32-bit NCO word index the polyphase bank — nearest-neighbor, no interpolation between branches.
Default constructor builds a 4096-phase × 19-tap Kaiser bank (60 dB rejection, 0.4/0.6 pass/stop) at first call. Use resamp_create_custom() to supply your own bank.
Lifecycle:
resamp_state_t *r = resamp_create(0.5);
float _Complex out[64];
size_t n = resamp_execute(r, in, 128, out, 64);
resamp_destroy(r);
Public Functions Documentation¶
function resamp_create¶
Built-in 4096×19 Kaiser bank (60 dB, 0.4/0.6 pass/stop).
function resamp_create_custom¶
resamp_state_t * resamp_create_custom (
size_t num_phases,
size_t num_taps,
const float * bank,
double rate
)
User-supplied bank, shape num_phases × num_taps, row-major. num_phases must be a power of two.
function resamp_destroy¶
Free all resources. NULL is a no-op.
function resamp_execute¶
Resample a block of CF32 samples (fixed rate).
size_t resamp_execute (
resamp_state_t * state,
const float _Complex * in,
size_t num_in,
float _Complex * out,
size_t max_out
)
Parameters:
stateMust be non-NULL.inInput samples.num_inNumber of input samples.outOutput buffer.max_outCapacity of out in samples.
Returns:
Number of output samples written.
function resamp_execute_ctrl¶
Resample with per-sample additive rate deviation.
size_t resamp_execute_ctrl (
resamp_state_t * state,
const float _Complex * in,
const float _Complex * ctrl,
size_t num_in,
float _Complex * out,
size_t max_out
)
rate_i = base_rate + crealf(ctrl(i)). ctrl is treated as real-valued; only the real part of each element is used.
Output buffer: allocate ceil(num_in × (rate + max_ctrl)) samples.
Parameters:
stateMust be non-NULL.inInput CF32 samples (length num_in).ctrlRate deviations, parallel to in (float _Complex, real part only, length num_in).num_inNumber of input samples (= length of ctrl).outOutput buffer.max_outCapacity of out in samples.
Returns:
Number of output samples written.
function resamp_get_num_phases¶
function resamp_get_num_taps¶
function resamp_get_rate¶
function resamp_get_state¶
Serialize state's mutable state intoblob .
function resamp_reset¶
Zero phase accumulator, ctrl accumulator, and delay line. Rate and bank are preserved.
function resamp_set_rate¶
Update rate and recompute phase_inc. Accumulator phase and delay line are preserved. Switching between interp and decim modes requires a new create() + destroy() pair.
function resamp_set_state¶
Restore mutable state from blob (same rate).
Returns:
DP_OK, or DP_ERR_INVALID if the blob's envelope rejects.
function resamp_state_bytes¶
Bytes resamp_get_state() writes forstate (envelope + payload).
Macro Definition Documentation¶
define RESAMP_STATE_MAGIC¶
define RESAMP_STATE_VERSION¶
The documentation for this class was generated from the following file native/inc/resamp/resamp_core.h