Skip to content

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"

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_reset (resamp_state_t * state)
void resamp_set_rate (resamp_state_t * state, double rate)

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

resamp_state_t * resamp_create (
    double rate
) 

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

void resamp_destroy (
    resamp_state_t * state
) 

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:

  • state Must be non-NULL.
  • in Input samples.
  • num_in Number of input samples.
  • out Output buffer.
  • max_out Capacity 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:

  • state Must be non-NULL.
  • in Input CF32 samples (length num_in).
  • ctrl Rate deviations, parallel to in (float _Complex, real part only, length num_in).
  • num_in Number of input samples (= length of ctrl).
  • out Output buffer.
  • max_out Capacity of out in samples.

Returns:

Number of output samples written.


function resamp_get_num_phases

size_t resamp_get_num_phases (
    const resamp_state_t * state
) 

function resamp_get_num_taps

size_t resamp_get_num_taps (
    const resamp_state_t * state
) 

function resamp_get_rate

double resamp_get_rate (
    const resamp_state_t * state
) 

function resamp_reset

void resamp_reset (
    resamp_state_t * state
) 

Zero phase accumulator, ctrl accumulator, and delay line. Rate and bank are preserved.


function resamp_set_rate

void resamp_set_rate (
    resamp_state_t * state,
    double 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.



The documentation for this class was generated from the following file native/inc/resamp/resamp_core.h