Skip to content

File f32_to_i16u64_core.h

FileList > doppler > f32_to_i16u64 > f32_to_i16u64_core.h

Go to the source code of this file

Scale-and-saturate float to Q15-in-uint64 converter. More...

  • #include "doppler/clib_common.h"
  • #include "doppler/dp_state.h"
  • #include "doppler/jm_perf.h"
  • #include <math.h>

Classes

Type Name
struct dp_f32_to_i16u64_state_t
F32ToI16U64 state.

Public Functions

Type Name
dp_f32_to_i16u64_state_t * dp_f32_to_i16u64_create (float scale)
Create a f32_to_i16u64 instance.
void dp_f32_to_i16u64_destroy (dp_f32_to_i16u64_state_t * state)
Destroy a f32_to_i16u64 instance and release all memory.
void dp_f32_to_i16u64_get_state (const dp_f32_to_i16u64_state_t * state, void * blob)
Serialize the state (scale and sticky clip flag) into blob .
void dp_f32_to_i16u64_reset (dp_f32_to_i16u64_state_t * state)
Clear the sticky clip flag, starting a fresh saturation history.
int dp_f32_to_i16u64_set_state (dp_f32_to_i16u64_state_t * state, const void * blob)
Restore a state previously written by dp_f32_to_i16u64_get_state() .
size_t dp_f32_to_i16u64_state_bytes (const dp_f32_to_i16u64_state_t * state)
Size of the serialized state blob.
JM_FORCEINLINE JM_HOT uint64_t dp_f32_to_i16u64_step (dp_f32_to_i16u64_state_t * state, float x)
Scale one float sample to a saturated Q15 code packed in a uint64.
void dp_f32_to_i16u64_steps (dp_f32_to_i16u64_state_t * state, const float * input, uint64_t * output, size_t n)
Process a block of float samples to Q15-in-uint64.

Macros

Type Name
define F32_TO_I16U64_STATE_MAGIC [**DP\_FOURCC**](dp__state_8h.md#define-dp_fourcc) ('F','U','6','4')
State-blob magic for F32ToI16U64 (FourCC "FU64").
define F32_TO_I16U64_STATE_VERSION 1u
State-blob layout version for F32ToI16U64.

Detailed Description

Identical semantics to F32ToI16U32 but the zero-extended Q15 result occupies the lower 16 bits of a uint64, providing 48 bits of upper headroom. This is the input format for the NCO's uint64 phase accumulator pipeline, where the upper bits carry phase increment headroom across accumulations.

input +1.0 → int16 32767 → uint64 0x0000000000007FFF input -1.0 → int16 -32768 → uint64 0x0000000000008000

The default scale of 32768.0 maps [-1, +1] float to Q15 range. A sticky clipped flag is raised on saturation and cleared only by reset().

Lifecycle: create -> (step / steps / reset)* -> destroy

>>> from doppler.cvt import F32ToI16U64
>>> import numpy as np
>>> obj = F32ToI16U64(scale=32768.0)
>>> hex(obj.step(-1.0))
'0x8000'
>>> hex(obj.step(1.0))
'0x7fff'
>>> obj.step(0.0)
0
>>> x = np.array([-1.0, 0.0, 1.0], dtype=np.float32)
>>> obj.steps(x).tolist()
[32768, 0, 32767]

Public Functions Documentation

function dp_f32_to_i16u64_create

Create a f32_to_i16u64 instance.

dp_f32_to_i16u64_state_t * dp_f32_to_i16u64_create (
    float scale
) 

Stores scale and initialises the sticky clipped flag to 0.

Parameters:

  • scale Multiply factor applied before quantisation and saturation (default: 32768.0f). Use 32768.0 to convert normalised [-1, +1] samples to Q15 packed into the low 16 bits of a uint64. Must be positive and finite.

Returns:

Heap-allocated state, or NULL if scale is not positive and finite, or allocation fails.

Note:

Caller must call dp_f32_to_i16u64_destroy() when done.


function dp_f32_to_i16u64_destroy

Destroy a f32_to_i16u64 instance and release all memory.

void dp_f32_to_i16u64_destroy (
    dp_f32_to_i16u64_state_t * state
) 

Parameters:

  • state May be NULL.

function dp_f32_to_i16u64_get_state

Serialize the state (scale and sticky clip flag) into blob .

void dp_f32_to_i16u64_get_state (
    const dp_f32_to_i16u64_state_t * state,
    void * blob
) 

Parameters:


function dp_f32_to_i16u64_reset

Clear the sticky clip flag, starting a fresh saturation history.

void dp_f32_to_i16u64_reset (
    dp_f32_to_i16u64_state_t * state
) 

Zeroes clipped so a subsequent clipped query reflects only samples seen after this call; scale is preserved. Call it at a buffer or segment boundary so a saturation on one block does not leak into the next.

Parameters:

  • state Must be non-NULL.
>>> from doppler.cvt import F32ToI16U64
>>> c = F32ToI16U64()
>>> c.step(5.0)          # out of range -> saturates, latches clipped
32767
>>> c.reset()            # forget the clip history
>>> c.clipped
False

function dp_f32_to_i16u64_set_state

Restore a state previously written by dp_f32_to_i16u64_get_state() .

int dp_f32_to_i16u64_set_state (
    dp_f32_to_i16u64_state_t * state,
    const void * blob
) 

The envelope is validated first; on rejection state is left untouched. The blob carries scale too, so the restored instance takes the sender's scale.

Parameters:

Returns:

DP_OK, or DP_ERR_INVALID on a magic, version, endian or size mismatch.


function dp_f32_to_i16u64_state_bytes

Size of the serialized state blob.

size_t dp_f32_to_i16u64_state_bytes (
    const dp_f32_to_i16u64_state_t * state
) 

Parameters:

  • state Must be non-NULL (its contents do not affect the size).

Returns:

Bytes: the dp_state_hdr_t envelope plus the whole state struct.


function dp_f32_to_i16u64_step

Scale one float sample to a saturated Q15 code packed in a uint64.

JM_FORCEINLINE  JM_HOT uint64_t dp_f32_to_i16u64_step (
    dp_f32_to_i16u64_state_t * state,
    float x
) 

Computes round(x * scale), saturates to [-32768, 32767], then zero-extends the 16-bit two's-complement pattern into the lower 16 bits of a uint64 (upper 48 bits are always zero — headroom for the NCO phase accumulator). Latches the sticky clipped flag on saturation.

A NaN input counts as clipped: it latches clipped and returns the negative full-scale code, -32768 (0x8000).

Parameters:

  • state Must be non-NULL.
  • x Input sample, normally a normalised float in [-1, +1].

Returns:

Q15 code in the low 16 bits of a uint64; e.g. -32768 -> 0x8000.

>>> from doppler.cvt import F32ToI16U64
>>> c = F32ToI16U64(scale=32768.0)
>>> c.step(0.5)              # 0.5 -> Q15 16384, upper 48 bits zero
16384
>>> hex(c.step(-1.0))        # -32768 as an unsigned low-16 pattern
'0x8000'

function dp_f32_to_i16u64_steps

Process a block of float samples to Q15-in-uint64.

void dp_f32_to_i16u64_steps (
    dp_f32_to_i16u64_state_t * state,
    const float * input,
    uint64_t * output,
    size_t n
) 

Applies step() to every element. The clipped flag is updated cumulatively across the block. In C, output must be non-NULL; the Python binding allocates a fresh array when no out= is passed.

Parameters:

  • state Must be non-NULL.
  • input Input float32 array; must contain at least n elements.
  • output Output uint64 array; must contain at least n elements.
  • n Number of samples to process.
>>> from doppler.cvt import F32ToI16U64
>>> import numpy as np
>>> F32ToI16U64().steps(
...     np.array([0.0, 0.5], dtype=np.float32)).tolist()
[0, 16384]

Macro Definition Documentation

define F32_TO_I16U64_STATE_MAGIC

State-blob magic for F32ToI16U64 (FourCC "FU64").

#define F32_TO_I16U64_STATE_MAGIC `DP_FOURCC ('F','U','6','4')`


define F32_TO_I16U64_STATE_VERSION

State-blob layout version for F32ToI16U64.

#define F32_TO_I16U64_STATE_VERSION `1u`



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