Skip to content

File f32_to_i16u32_core.h

FileList > f32_to_i16u32 > f32_to_i16u32_core.h

Go to the source code of this file

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

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

Classes

Type Name
struct f32_to_i16u32_state_t
F32ToI16U32 state.

Public Functions

Type Name
f32_to_i16u32_state_t * f32_to_i16u32_create (float scale)
Create a f32_to_i16u32 instance.
void f32_to_i16u32_destroy (f32_to_i16u32_state_t * state)
Destroy a f32_to_i16u32 instance and release all memory.
void f32_to_i16u32_get_state (const f32_to_i16u32_state_t * state, void * blob)
void f32_to_i16u32_reset (f32_to_i16u32_state_t * state)
Reset f32_to_i16u32 to its post-create state.
int f32_to_i16u32_set_state (f32_to_i16u32_state_t * state, const void * blob)
size_t f32_to_i16u32_state_bytes (const f32_to_i16u32_state_t * state)
JM_FORCEINLINE JM_HOT uint32_t f32_to_i16u32_step (f32_to_i16u32_state_t * state, float x)
Process one input sample.
void f32_to_i16u32_steps (f32_to_i16u32_state_t * state, const float * input, uint32_t * output, size_t n)
Process a block of float samples to Q15-in-uint32.

Macros

Type Name
define F32_TO_I16U32_STATE_MAGIC [**DP\_FOURCC**](dp__state_8h.md#define-dp_fourcc) ('F','U','3','2')
define F32_TO_I16U32_STATE_VERSION 1u

Detailed Description

Converts a float to a saturated int16, then zero-extends the 16-bit two's complement bit pattern into the lower 16 bits of a uint32 (upper 16 bits are always zero). This is the wire format expected by the CIC filter's integer input path, which exploits the upper bits as headroom for the bit-growth that naturally occurs through an integrator cascade.

input +1.0 → int16 32767 → uint32 0x00007FFF input -1.0 → int16 -32768 → uint32 0x00008000

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 F32ToI16U32
>>> import numpy as np
>>> obj = F32ToI16U32(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 f32_to_i16u32_create

Create a f32_to_i16u32 instance.

f32_to_i16u32_state_t * f32_to_i16u32_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 a uint32.

Returns:

Heap-allocated state, or NULL on allocation failure.

Note:

Caller must call f32_to_i16u32_destroy() when done.


function f32_to_i16u32_destroy

Destroy a f32_to_i16u32 instance and release all memory.

void f32_to_i16u32_destroy (
    f32_to_i16u32_state_t * state
) 

Parameters:

  • state May be NULL.

function f32_to_i16u32_get_state

void f32_to_i16u32_get_state (
    const f32_to_i16u32_state_t * state,
    void * blob
) 

function f32_to_i16u32_reset

Reset f32_to_i16u32 to its post-create state.

void f32_to_i16u32_reset (
    f32_to_i16u32_state_t * state
) 

Clears the sticky clipped flag. The scale is preserved.

Parameters:

  • state Must be non-NULL.

function f32_to_i16u32_set_state

int f32_to_i16u32_set_state (
    f32_to_i16u32_state_t * state,
    const void * blob
) 

function f32_to_i16u32_state_bytes

size_t f32_to_i16u32_state_bytes (
    const f32_to_i16u32_state_t * state
) 

function f32_to_i16u32_step

Process one input sample.

JM_FORCEINLINE  JM_HOT uint32_t f32_to_i16u32_step (
    f32_to_i16u32_state_t * state,
    float x
) 

Computes round(x * scale), saturates to [-32768, 32767], then zero-extends the int16 bit pattern into the lower 16 bits of a uint32. The clipped flag is set if saturation occurred.

Parameters:

  • state Must be non-NULL.
  • x Normalised float input sample.

Returns:

Q15 value packed into the lower 16 bits of a uint32.


function f32_to_i16u32_steps

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

void f32_to_i16u32_steps (
    f32_to_i16u32_state_t * state,
    const float * input,
    uint32_t * output,
    size_t n
) 

Applies step() to every element. The clipped flag is updated cumulatively across the block. Accepts an optional pre-allocated output array; allocates a fresh one when output is NULL.

Parameters:

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

Macro Definition Documentation

define F32_TO_I16U32_STATE_MAGIC

#define F32_TO_I16U32_STATE_MAGIC `DP_FOURCC ('F','U','3','2')`

define F32_TO_I16U32_STATE_VERSION

#define F32_TO_I16U32_STATE_VERSION `1u`


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