Skip to content

File resamp_core.h

FileList > doppler > resamp > resamp_core.h

Go to the source code of this file

Continuously-variable polyphase resampler for CF32 IQ. More...

  • #include "doppler/clib_common.h"
  • #include "doppler/dp_state.h"

Classes

Type Name
struct resamp_state_t
Polyphase resampler state.

Public Functions

Type Name
size_t dp_resamp_consumed (const resamp_state_t * state)
Inputs the last block call took: dp_resamp_execute() ,dp_resamp_execute_ctrl() ordp_resamp_execute_ctrl_pos() .
resamp_state_t * dp_resamp_create (double rate)
Create a resampler with the built-in 4096x19 Kaiser bank (60 dB, 0.4/0.6 pass/stop).
resamp_state_t * dp_resamp_create_custom (size_t num_phases, size_t num_taps, const float * bank, double rate)
Create a resampler over a user-supplied polyphase bank.
double dp_resamp_dc_gain (const resamp_state_t * state)
The resampler's response to a constant input, from its own bank.
void dp_resamp_destroy (resamp_state_t * state)
Free the state, its bank and its delay lines.
size_t dp_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 dp_resamp_execute_ctrl (resamp_state_t * state, const float _Complex * in, const double * ctrl, size_t num_in, float _Complex * out, size_t max_out)
Resample with per-sample additive rate deviation.
size_t dp_resamp_execute_ctrl_pair (resamp_state_t * state, const float _Complex * in, const double * ctrl, size_t num_in, float _Complex * out, float _Complex * dout, uint32_t * arm, size_t max_out)
The block form of dp_resamp_execute_ctrl_push_pair() : a loop over it, asdp_resamp_execute_ctrl() is a loop over the push form, so the two give the same outputs, pairs and arms.
size_t dp_resamp_execute_ctrl_pos (resamp_state_t * state, const float _Complex * in, const double * ctrl, size_t num_in, float _Complex * out, double * pos, size_t max_out)
dp_resamp_execute_ctrl() , also reporting where each output sits on the input timeline.
size_t dp_resamp_execute_ctrl_push (resamp_state_t * state, float _Complex x, double ctrl, float _Complex * out, size_t max_out)
Push one input at an instantaneous rate deviation; emit any outputs.
size_t dp_resamp_execute_ctrl_push_pair (resamp_state_t * state, float _Complex x, double ctrl, float _Complex * out, float _Complex * dout, uint32_t * arm, size_t max_out)
dp_resamp_execute_ctrl_push() , also returning each output's second-bank value and the arm both were read at.
size_t dp_resamp_execute_ctrl_push_pos (resamp_state_t * state, float _Complex x, double ctrl, float _Complex * out, double * pos, size_t max_out)
dp_resamp_execute_ctrl_push() , also returning where each output sits on the input timeline.
double dp_resamp_get_ctrl_acc (const resamp_state_t * state)
The control accumulator's fractional phase, in [0, 1).
double dp_resamp_get_ctrl_lead (const resamp_state_t * state)
Where the next steered output sits, in input intervals past the newest input the delay line holds.
double dp_resamp_get_delay (const resamp_state_t * state)
Group delay of the interpolating structure, in INPUT samples.
double dp_resamp_get_execute_delay (const resamp_state_t * state)
Group delay of dp_resamp_execute() , in INPUT samples, on the path its rate runs.
size_t dp_resamp_get_num_phases (const resamp_state_t * state)
Polyphase arms in the bank.
size_t dp_resamp_get_num_taps (const resamp_state_t * state)
Taps per polyphase arm.
double dp_resamp_get_rate (const resamp_state_t * state)
Base output/input rate ratio.
void dp_resamp_get_state (const resamp_state_t * state, void * blob)
Serialize state's mutable state intoblob .
int dp_resamp_has_dbank (const resamp_state_t * state)
Whether a second bank is attached ( dp_resamp_set_dbank() ).
size_t dp_resamp_interp_fill (resamp_state_t * state, const float _Complex * in, float _Complex * out, size_t max_out)
Emit exactly max_out interpolated outputs, pulling inputs on overflow.
size_t dp_resamp_interp_inputs_needed (const resamp_state_t * state, size_t max_out)
Input samples an interpolating fill of max_out outputs consumes.
int dp_resamp_rate_ok (double rate)
The rate domain: finite and > 0.
void dp_resamp_reset (resamp_state_t * state)
Zero the phase accumulators, the ctrl debt/ahead counters and every delay line. Rate and bank are preserved.
int dp_resamp_set_dbank (resamp_state_t * state, const float * dbank)
Attach a second bank, read beside the first at the same arm.
int dp_resamp_set_rate (resamp_state_t * state, double rate)
Update rate and recompute phase_inc.
int dp_resamp_set_state (resamp_state_t * state, const void * blob)
Restore mutable state from blob (same rate).
size_t dp_resamp_state_bytes (const resamp_state_t * state)
Bytes dp_resamp_get_state() writes forstate (envelope + payload).

Macros

Type Name
define RESAMP_CTRL_RATE_MIN 1e-6
Floor on the composite rate rate + ctrl in the ctrl paths.
define RESAMP_MAX_PHASES ((uint64\_t)1 << 32)
Most polyphase arms a bank may have: 2^32. The arm is the top log2(num_phases) bits of the 32-bit phase word, selected by a right shift of 32 - log2(num_phases), which is defined only while that count is >= 0; a 32-bit word cannot name more arms anyway. A uint64_t, since 2^32 does not fit a 32-bit size_t. dp_resamp_create_custom() refuses a larger count, and so does every create that builds a bank for it.
define RESAMP_STATE_MAGIC [**DP\_FOURCC**](dp__state_8h.md#define-dp_fourcc) ('R', 'S', 'M', 'P')
State-blob magic for the resampler (FourCC "RSMP").
define RESAMP_STATE_VERSION 2u
State-blob layout version (v2: uint32 ctrl phase + debt).

Detailed Description

Two execute paths:

dp_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.

dp_resamp_execute_ctrl — unified, and it rides the INTERPOLATOR at every rate: emit at every tick, and load an input when the accumulator fails to advance (u(k) <= u(k-1)). The steered rate rate + ctrl(i) sets the step; whole input intervals per output are owed as ctrl_debt and the fractional remainder selects the arm.

This paragraph used to describe the other structure — "each input advances the accumulator by (rate + ctrl(i)); every time the accumulator crosses 1.0 an output is emitted" — which is the DECIMATOR's recurrence, exact only at rate 1 where the two coincide. Running it here cost 55-60 dB of tone purity at every other rate. The description is kept accurate rather than deleted because it is the mental model under which someone writes a private (uint32_t) (frac * 2^32 + 0.5) and believes it correct; one did, and it stalled the interpolator for composite rates just above unity.

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 create. Use dp_resamp_create_custom() to supply your own bank.

Lifecycle:

resamp_state_t *r = dp_resamp_create(0.5);
float _Complex out[64];
size_t n = dp_resamp_execute(r, in, 128, out, 64);
dp_resamp_destroy(r);

Public Functions Documentation

function dp_resamp_consumed

Inputs the last block call took: dp_resamp_execute() ,dp_resamp_execute_ctrl() ordp_resamp_execute_ctrl_pos() .

size_t dp_resamp_consumed (
    const resamp_state_t * state
) 

Every block form stops offering input once out is full, so this is its num_in unless the output filled first; the caller resumes at in + consumed and the output continues exactly as one whole call gives it (doppler#2643). 0 after create and reset.

Parameters:

  • state Must be non-NULL.

Returns:

Input samples taken by the last block call.


function dp_resamp_create

Create a resampler with the built-in 4096x19 Kaiser bank (60 dB, 0.4/0.6 pass/stop).

resamp_state_t * dp_resamp_create (
    double rate
) 

Parameters:

  • rate Output/input rate ratio; > 1 interpolates, < 1 decimates. Must satisfy dp_resamp_rate_ok().

Returns:

Heap-allocated state, or NULL if rate is outside dp_resamp_rate_ok() or allocation fails. Free with dp_resamp_destroy().


function dp_resamp_create_custom

Create a resampler over a user-supplied polyphase bank.

resamp_state_t * dp_resamp_create_custom (
    size_t num_phases,
    size_t num_taps,
    const float * bank,
    double rate
) 

Parameters:

  • num_phases Arms in the bank; a power of two (1 included), at most 2^32. The arm is the top log2(num_phases) bits of the 32-bit phase word, so any other count would address arms past the end of the bank, and a word that wide cannot name more than 2^32; both are refused, before the bank is copied.
  • num_taps Taps per arm.
  • bank num_phases x num_taps floats, row-major (one row per arm); copied, so the caller keeps ownership.
  • rate Output/input rate ratio; must satisfy dp_resamp_rate_ok().

Returns:

Heap-allocated state, or NULL if num_phases is 0, not a power of two or above 2^32, num_taps is 0, bank is NULL, rate is outside dp_resamp_rate_ok(), or allocation fails.


function dp_resamp_dc_gain

The resampler's response to a constant input, from its own bank.

double dp_resamp_dc_gain (
    const resamp_state_t * state
) 

Every arm of a polyphase bank is the same filter at a different fractional delay, so they share one DC gain and arm 0 answers for all of them: the sum of its taps. Computed, not measured — a caller (or a gate) can ask what gain this stage contributes without running a signal through it.

The decimating path pre-scales by rate and integrates over the whole bank between outputs, which cancels: rate inputs' worth of taps per output, so the tap sum is the answer on both paths.

ARM 0's gain, which is the realised gain only where arm 0 is the arm being used — at rate 1, where the fraction is zero and one arm is selected forever. A non-unity rate visits every arm, so what a caller measures is the arm AVERAGE: 1.000586 computed against 1.000293 at rate 0.5 and 2, and 1.000249 at 0.25 and 4. The 3.4e-4 spread is the bank's arm-to-arm ripple and of no practical consequence, but this returns the computed number, not the one a measurement will find. Pinned by test_resamp_core.c §13, which checks both.

Parameters:

  • state State. Must be non-NULL.

Returns:

The DC gain. 1.0 for the default Kaiser bank; a matched pulse bank is a matched filter, not a flat one, so its DC gain is the pulse's own sum(h)/sum(h^2) and is not expected to be 1.

resamp_state_t *r = dp_resamp_create (0.5);
printf ("%.3f\n", dp_resamp_dc_gain (r));   // 1.000
dp_resamp_destroy (r);

function dp_resamp_destroy

Free the state, its bank and its delay lines.

void dp_resamp_destroy (
    resamp_state_t * state
) 

Parameters:

  • state May be NULL (no-op).

function dp_resamp_execute

Resample a block of CF32 samples (fixed rate).

size_t dp_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. A full out stops the call with input unread, never dropped: dp_resamp_consumed() says where to resume.

Returns:

Number of output samples written.


function dp_resamp_execute_ctrl

Resample with per-sample additive rate deviation.

size_t dp_resamp_execute_ctrl (
    resamp_state_t * state,
    const float _Complex * in,
    const double * ctrl,
    size_t num_in,
    float _Complex * out,
    size_t max_out
) 

rate_i = base_rate + ctrl[i]. The control is real-valued and double-precision, matching dp_resamp_execute_ctrl_push()'s scalar ctrl and the double the base rate itself is configured in.

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 (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 dp_resamp_execute_ctrl_pair

The block form of dp_resamp_execute_ctrl_push_pair() : a loop over it, asdp_resamp_execute_ctrl() is a loop over the push form, so the two give the same outputs, pairs and arms.

size_t dp_resamp_execute_ctrl_pair (
    resamp_state_t * state,
    const float _Complex * in,
    const double * ctrl,
    size_t num_in,
    float _Complex * out,
    float _Complex * dout,
    uint32_t * arm,
    size_t max_out
) 

Parameters:

  • state Must be non-NULL.
  • in Input samples (length num_in).
  • ctrl Rate deviations, parallel to in.
  • num_in Number of inputs.
  • out Output samples.
  • dout Second-bank values, parallel to out. Must be non-NULL.
  • arm Arm indices, parallel to out. Must be non-NULL.
  • max_out Capacity of out, dout and arm. A full out stops the call with input unread: dp_resamp_consumed() says where to resume.

Returns:

Number of outputs written.


function dp_resamp_execute_ctrl_pos

dp_resamp_execute_ctrl() , also reporting where each output sits on the input timeline.

size_t dp_resamp_execute_ctrl_pos (
    resamp_state_t * state,
    const float _Complex * in,
    const double * ctrl,
    size_t num_in,
    float _Complex * out,
    double * pos,
    size_t max_out
) 

Identical outputs, bit for bit: this IS dp_resamp_execute_ctrl() (same accumulator, same push loop), with one extra read per emitted output. pos[j] is output j's position on the input timeline, in input samples, measured from in[0]: the newest input sample under the taps plus the fraction of an interval past it, exactly the quantity the accumulator already holds. It is NEGATIVE for an output emitted before in[0] was loaded, which is a tick that falls ahead of a call's first sample possible at the head of EVERY call, not only the first of a fresh stream (where it is -1). Add the count of inputs consumed by earlier calls and it is the stream-absolute position. The group delay (dp_resamp_get_delay()) is not in it: it is where the interpolation is centred, not where the content came from.

What it is for: the excess delay a time-dilating channel has accumulated at output k is (P + pos[j] - k + 1) / fs, where P is the number of inputs consumed by earlier calls and k the absolute output index. That is the dilation itself, read off the resampler rather than integrated a second time beside it, so a carrier phase derived from it cannot disagree with the dilation and cannot depend on how the stream was chunked pos is relative to in[0] only so that its magnitude stays small.

Parameters:

  • state Must be non-NULL.
  • in Input CF32 samples (length num_in).
  • ctrl Rate deviations, parallel to in (length num_in).
  • num_in Number of input samples (= length of ctrl).
  • out Output buffer.
  • pos Output positions, parallel to out (capacity max_out). Must be non-NULL.
  • max_out Capacity of out and pos in samples.

Returns:

Number of output samples written.

See also: dp_resamp_execute_ctrl


function dp_resamp_execute_ctrl_push

Push one input at an instantaneous rate deviation; emit any outputs.

size_t dp_resamp_execute_ctrl_push (
    resamp_state_t * state,
    float _Complex x,
    double ctrl,
    float _Complex * out,
    size_t max_out
) 

The single-input streaming form of dp_resamp_execute_ctrl(): OFFERS x to the delay line, advances the accumulator by rate + ctrl, and emits every output whose period completes (0 for a decimator between strobes, 1 typically, or several for an interpolator) at the polyphase arm the fractional remainder selects.

The scalar and block forms are INDISTINGUISHABLE. Feeding a stream one sample at a time through here yields the same outputs, in the same number, at the same ticks, as one dp_resamp_execute_ctrl() over the same (in, ctrl[]) never "one sample of delay apart". Each value agrees to a few float ULPs rather than to the bit: the library builds with -ffast-math, and a compiler may sum the polyphase dot product in a different order at each call site (GCC 15 on aarch64 does). A caller chooses between them for control flow — the block form when ctrl[] is known in advance, this one when each correction depends on the outputs already emitted — never for a difference in what comes out.

That is what "offers" buys, and why x is NOT pushed on entry: nothing enters an interpolator's delay line without a load REQUEST — a tick emits, the accumulator fails to advance, and only then is an input consumed. x is held until a tick asks. Pushing on entry is an unrequested load, and it is precisely what broke the invariant, costing exactly one sample of group delay against the block form. Fixed, and gated: eq_ctrl_push in test_resamp_core.c asserts bit-exact equality across decimating, unity-neighbourhood and interpolating rates, at zero and at both signs of steer.

ctrl_ahead covers the one case the API cannot decline — max_out ending the call before any tick could ask for the offered sample. Feeding a stream of (x, ctrl) through this one input at a time reproduces dp_resamp_execute_ctrl() on the same (in, ctrl[]) bit-for-bit — but, unlike the block form's precomputed ctrl[], ctrl here can depend on the outputs already emitted. That closes the loop: a timing-recovery or rate-tracking loop reads each emitted output, computes its correction, and feeds it back as the next call's ctrl to steer the strobe. This is the per-output feedback a matched-filter timing loop (track.RateSync) needs and the block execute_ctrl cannot provide.

Parameters:

  • state Must be non-NULL.
  • x One input sample.
  • ctrl Rate deviation added to the base rate for this input (real-valued; the effective rate is rate + ctrl).
  • out Output buffer for any emitted samples.
  • max_out Capacity of out (emission stops at this bound).

Returns:

Number of outputs emitted into out (0, 1, or more).


function dp_resamp_execute_ctrl_push_pair

dp_resamp_execute_ctrl_push() , also returning each output's second-bank value and the arm both were read at.

size_t dp_resamp_execute_ctrl_push_pair (
    resamp_state_t * state,
    float _Complex x,
    double ctrl,
    float _Complex * out,
    float _Complex * dout,
    uint32_t * arm,
    size_t max_out
) 

out is bit for bit what dp_resamp_execute_ctrl_push() returns from the same state and input: the same accumulator, the same loads, the same arm, the same dot product. Beside each out[j], dout[j] is the second bank's arm at the same index over the same delay line, and arm[j] that index: the arm the phase word selected, in [0, num_phases). With no second bank attached, dout[j] is 0.

Parameters:

  • state Must be non-NULL.
  • x One input sample.
  • ctrl As dp_resamp_execute_ctrl_push().
  • out Output samples.
  • dout Second-bank values, parallel to out; may be NULL.
  • arm Arm indices, parallel to out; may be NULL.
  • max_out Capacity of out, dout and arm.

Returns:

Number of outputs emitted.


function dp_resamp_execute_ctrl_push_pos

dp_resamp_execute_ctrl_push() , also returning where each output sits on the input timeline.

size_t dp_resamp_execute_ctrl_push_pos (
    resamp_state_t * state,
    float _Complex x,
    double ctrl,
    float _Complex * out,
    double * pos,
    size_t max_out
) 

out is bit for bit what dp_resamp_execute_ctrl_push() returns from the same state and input: the same accumulator and the same loads. Beside each out[j], pos[j] is its position in input samples relative to x, the sample this call offers: the newest sample under the taps when the tick fired, plus the accumulator's fraction of an interval past it. An output is formed before the offered sample loads, so the newest sample under the taps is the previous call's: pos[j] is the accumulator's fraction less one, in [-1, 0), whenever no interval is still owed. It is dp_resamp_execute_ctrl_pos()'s pos for a call of one input, and the group delay is not in it, as there.

What it is for: a timing loop's strobe placed on its input clock (doppler#3177). A caller who counts the samples it has offered adds that count to pos[j].

Parameters:

  • state Must be non-NULL.
  • x One input sample.
  • ctrl As dp_resamp_execute_ctrl_push().
  • out Output samples.
  • pos Output positions, parallel to out. Must be non-NULL.
  • max_out Capacity of out and pos.

Returns:

Number of outputs emitted.


function dp_resamp_get_ctrl_acc

The control accumulator's fractional phase, in [0, 1).

double dp_resamp_get_ctrl_acc (
    const resamp_state_t * state
) 

This is the timing NCO's state, and observing it is the only way to see what a closed timing loop is actually doing to the sampling instant. mu IS the fractional delay applied to the stream, and floor(mu * num_phases) is the polyphase arm the next output will read — the accumulator advances after the emit, so on return it already describes the output still to come. That holds at EVERY rate, because the control port rides the interpolating structure at every rate (see dp_resamp_execute_ctrl); it is not a peculiarity of a decimating stage.

A steady mu means the loop has settled on a sampling phase. A mu that slews and wraps means a residual RATE error the loop has not absorbed, and one cycle of wrap is one INPUT interval of slip — an output period only at rate 1, where the two coincide.

Reports the CONTROL accumulator, so it stays 0.0 for a caller driving this object through dp_resamp_execute(): the free-running phase is a separate accumulator with no accessor.

Pinned by test_resamp_core.c §10 (the arm, read off the output at four rates), §11 (the wrap's unit, against the counting law) and §12.

Parameters:

  • state Must be non-NULL.

Returns:

mu, from 0 up to (not including) 1: a fraction of one input interval; 0 after create/reset.


function dp_resamp_get_ctrl_lead

Where the next steered output sits, in input intervals past the newest input the delay line holds.

double dp_resamp_get_ctrl_lead (
    const resamp_state_t * state
) 

dp_resamp_get_ctrl_acc() is the fraction; this adds the whole inputs the accumulator still has to be given before that output is formed, less any it was handed early. With n inputs taken since create or reset, the next output of the control forms reads the input timeline at n - 1 + lead, which is what a caller needs to place an output after the rate has been steered: the count of outputs no longer says. The interval to that output was fixed when the output before it was emitted, so a control passed now moves the one after.

Pinned by test_ratesync_core.c (test_seed): unsteered, on four plans, n - 1 + lead is the output count over the rate at every input.

Parameters:

  • state Must be non-NULL.

Returns:

The lead, in input intervals; 0 after create/reset.


function dp_resamp_get_delay

Group delay of the interpolating structure, in INPUT samples.

double dp_resamp_get_delay (
    const resamp_state_t * state
) 

The prototype is a symmetric (linear-phase) Kaiser lowpass, so its delay is its centre: floor((num_phases * num_taps) | 1) / 2 prototype taps, i.e. that over num_phases input samples 9.5 for the built-in bank plus ONE input sample of pipeline: an output is formed from the delay line as it stands, and only then is the next input loaded, so the newest sample under the taps is the one before the sample being offered. 10.5 for the built-in bank.

It is the delay of the ctrl and push forms at EVERY rate (they ride the interpolating structure, which is what lets a timing loop steer through unity), and of dp_resamp_execute() at rate >= 1; test_resamp_core.c §3 measures it by phase differencing on each. dp_resamp_execute() below unity runs the decimator instead, whose delay is dp_resamp_get_execute_delay()'s.

What it is for: output k carries the input at index k * (1/rate) + (the accumulated ctrl) - delay. A caller comparing the output timeline with the input's a code loop fed through doppler_channel, a test asserting where a chip lands subtracts this, and a loop started at the input's phase without it is this far from the peak (doppler-dsp/doppler#1189: 5 chips at 2 samples per chip, onto a Gold sidelobe). Closed-form from the bank's geometry, so it is exact for the built-in bank; a dp_resamp_create_custom() bank is assumed symmetric about the same centre.

Parameters:

  • state Must be non-NULL.

Returns:

The delay in input samples (>= 1).


function dp_resamp_get_execute_delay

Group delay of dp_resamp_execute() , in INPUT samples, on the path its rate runs.

double dp_resamp_get_execute_delay (
    const resamp_state_t * state
) 

At rate >= 1 it is the interpolating structure's, dp_resamp_get_delay(). Below unity dp_resamp_execute() runs the decimator, the transposed form, which runs at the OUTPUT rate and emits each interval's output as the interval closes, one output period ahead of the prototype's centre: (centre - 1) output samples, 8.5 / rate input samples for the built-in bank. test_resamp_core.c §3b measures it at 0.91, 0.80, 0.67 and 0.50 and holds it to this value.

What it is for: output k of dp_resamp_execute() carries the input at index k / rate - dp_resamp_get_execute_delay() from a fresh stream; a caller mapping a position found on the output timeline back to the input (a search run on resampled samples handing off to a loop on the original ones) subtracts this.

Parameters:

  • state Must be non-NULL.

Returns:

The delay in input samples.


function dp_resamp_get_num_phases

Polyphase arms in the bank.

size_t dp_resamp_get_num_phases (
    const resamp_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

num_phases (4096 for the built-in bank).


function dp_resamp_get_num_taps

Taps per polyphase arm.

size_t dp_resamp_get_num_taps (
    const resamp_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

num_taps (19 for the built-in bank).


function dp_resamp_get_rate

Base output/input rate ratio.

double dp_resamp_get_rate (
    const resamp_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

The create() rate, or the last dp_resamp_set_rate() value.


function dp_resamp_get_state

Serialize state's mutable state intoblob .

void dp_resamp_get_state (
    const resamp_state_t * state,
    void * blob
) 

Parameters:


function dp_resamp_has_dbank

Whether a second bank is attached ( dp_resamp_set_dbank() ).

int dp_resamp_has_dbank (
    const resamp_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

1 if attached, else 0.


function dp_resamp_interp_fill

Emit exactly max_out interpolated outputs, pulling inputs on overflow.

size_t dp_resamp_interp_fill (
    resamp_state_t * state,
    const float _Complex * in,
    float _Complex * out,
    size_t max_out
) 

The output-count-driven twin of the interpolation branch of dp_resamp_execute(): it emits one output per phase tick and pushes the next input on each NCO overflow, but — unlike dp_resamp_execute(), whose loop halts as soon as the input is exhausted even with output capacity left — it always writes max_out outputs. The caller must therefore supply at least dp_resamp_interp_inputs_needed(state, max_out) inputs in in; supplying exactly that many (the common case) consumes them all. This is what lets a streaming producer (e.g. a pulse-shaping synth) feed symbols on demand and get a bit-exact match between a single call for max_out outputs and max_out single-output calls (the resampler is block-boundary invariant).

Parameters:

  • state Must be non-NULL, upsampling.
  • in Inputs to push on overflow (>= inputs_needed available).
  • out Output buffer, capacity >= max_out.
  • max_out Number of outputs to emit.

Returns:

Inputs consumed (== dp_resamp_interp_inputs_needed(state, max_out)).


function dp_resamp_interp_inputs_needed

Input samples an interpolating fill of max_out outputs consumes.

size_t dp_resamp_interp_inputs_needed (
    const resamp_state_t * state,
    size_t max_out
) 

The exact number of delay-line pushes producing max_out outputs from the current phase: ((uint64_t)phase + max_out * phase_inc) >> 32.

Exact at EVERY rate, not only at an integer interpolation factor, and a caller may rely on it: generate precisely this many inputs, hand them to dp_resamp_interp_fill(), and there is no over- or under-production. The guarantee is structural rather than numeric — this closed form and the fill loop advance the same accumulator by the same phase_inc, so they cannot disagree whatever the rate, and mid-stream phase is carried in the formula. Measured across 1800 mid-stream calls at nine rates with randomised max_out, worst deviation zero (test_resamp_core.c §20).

(This paragraph used to scope the promise to "an integer interpolation factor". That is where phase_inc divides evenly and therefore represents the rate exactly — a real property, but a different one: the prediction matches the fill because both USE phase_inc, not because it is exact.)

Meaningful only for an upsampling resampler (rate >= 1) — the prediction still matches what dp_resamp_interp_fill() consumes below unity, but that entry point interpolates, so a decimating caller wants dp_resamp_execute().

Parameters:

  • state Must be non-NULL, upsampling.
  • max_out Number of outputs the following dp_resamp_interp_fill() call will request.

Returns:

Inputs that call will consume.


function dp_resamp_rate_ok

The rate domain: finite and > 0.

int dp_resamp_rate_ok (
    double rate
) 

The one predicate. dp_resamp_create() and dp_resamp_create_custom() return NULL outside it and dp_resamp_set_rate() refuses such a value; the RateConverter cascade checks its own rate with it too. A NaN fails the comparison, so it is outside; 0 would emit zeros and a negative rate a negated copy, which is why neither is accepted.

Parameters:

  • rate Output/input rate ratio.

Returns:

1 inside the domain, 0 outside it.


function dp_resamp_reset

Zero the phase accumulators, the ctrl debt/ahead counters and every delay line. Rate and bank are preserved.

void dp_resamp_reset (
    resamp_state_t * state
) 

Parameters:

  • state Must be non-NULL.

function dp_resamp_set_dbank

Attach a second bank, read beside the first at the same arm.

int dp_resamp_set_dbank (
    resamp_state_t * state,
    const float * dbank
) 

The derivative-bank timing detector (docs/design/ratesync-timing.md, §2 and §9.1) reads two dot products over one delay line at one timing hypothesis: the arm bank[p] and its derivative dbank[p]. One phase word selects p for both, so the pair cannot read two hypotheses. The second bank has the first's shape by definition, num_phases x num_taps row-major, so the shape is not an argument.

Config, like the first bank: copied here, owned, freed by dp_resamp_destroy(), and never packed into a blob, so a blob taken with a second bank resumes on a resampler without one and returns the same outputs.

Parameters:

  • state Must be non-NULL.
  • dbank num_phases x num_taps floats, copied; NULL detaches the second bank.

Returns:

0, or -1 on an allocation failure (the old second bank, if any, is kept).


function dp_resamp_set_rate

Update rate and recompute phase_inc.

int dp_resamp_set_rate (
    resamp_state_t * state,
    double rate
) 

On the same side of 1 (both interpolating, or both decimating) the accumulator phase and every delay line are preserved, so the stream continues at the new rate. A change that CROSSES 1 hands dp_resamp_execute() to the other path, whose running state the old path never advanced; the call therefore resets the state as dp_resamp_reset() does, and the output from there on is exactly what a fresh dp_resamp_create() at the new rate would emit. A rate outside dp_resamp_rate_ok() is refused and nothing changes.

Parameters:

  • state Must be non-NULL.
  • rate New output/input rate ratio.

Returns:

DP_OK, or DP_ERR_INVALID if rate is outside dp_resamp_rate_ok() (the state is then unchanged).


function dp_resamp_set_state

Restore mutable state from blob (same rate).

int dp_resamp_set_state (
    resamp_state_t * state,
    const void * blob
) 

Parameters:

Returns:

DP_OK, or DP_ERR_INVALID if the blob's envelope rejects or its delay-line head lies outside the line; state is then unchanged.


function dp_resamp_state_bytes

Bytes dp_resamp_get_state() writes forstate (envelope + payload).

size_t dp_resamp_state_bytes (
    const resamp_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

Blob size in bytes; depends on num_taps (via delay_cap).


Macro Definition Documentation

define RESAMP_CTRL_RATE_MIN

Floor on the composite rate rate + ctrl in the ctrl paths.

#define RESAMP_CTRL_RATE_MIN `1e-6`


define RESAMP_MAX_PHASES

Most polyphase arms a bank may have: 2^32. The arm is the top log2(num_phases) bits of the 32-bit phase word, selected by a right shift of 32 - log2(num_phases), which is defined only while that count is >= 0; a 32-bit word cannot name more arms anyway. A uint64_t, since 2^32 does not fit a 32-bit size_t. dp_resamp_create_custom() refuses a larger count, and so does every create that builds a bank for it.

#define RESAMP_MAX_PHASES `((uint64_t)1 << 32)`


define RESAMP_STATE_MAGIC

State-blob magic for the resampler (FourCC "RSMP").

#define RESAMP_STATE_MAGIC `DP_FOURCC ('R', 'S', 'M', 'P')`


define RESAMP_STATE_VERSION

State-blob layout version (v2: uint32 ctrl phase + debt).

#define RESAMP_STATE_VERSION `2u`



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