Skip to content

File i16u32_to_f32_core.h

FileList > i16u32_to_f32 > i16u32_to_f32_core.h

Go to the source code of this file

Q15-in-uint32 to float converter. More...

  • #include "clib_common.h"
  • #include "jm_perf.h"

Classes

Type Name
struct i16u32_to_f32_state_t
I16U32ToF32 state.

Public Functions

Type Name
i16u32_to_f32_state_t * i16u32_to_f32_create (float scale)
Create a i16u32_to_f32 instance.
void i16u32_to_f32_destroy (i16u32_to_f32_state_t * state)
Destroy a i16u32_to_f32 instance and release all memory.
void i16u32_to_f32_reset (i16u32_to_f32_state_t * state)
Reset i16u32_to_f32 to its post-create state.
JM_FORCEINLINE JM_HOT float i16u32_to_f32_step (const i16u32_to_f32_state_t * state, uint32_t x)
Process one input sample.
void i16u32_to_f32_steps (i16u32_to_f32_state_t * state, const uint32_t * input, float * output, size_t n)
Process a block of Q15-in-uint32 samples to float32.

Detailed Description

Extracts the lower 16 bits of a uint32, re-interprets them as a signed int16 (two's complement), then multiplies by 1/scale to produce a normalised float. This is the exact inverse of F32ToI16U32: a value written by that converter can be recovered here with the same scale.

uint32 0x00008000 → int16 -32768 → float -1.0 uint32 0x00007FFF → int16 32767 → float ~+1.0 uint32 0x00000000 → int16 0 → float 0.0

Upper 16 bits of the uint32 are masked off and ignored, so values carrying CIC bit-growth headroom in those bits are handled correctly.

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

>>> from doppler.cvt import I16U32ToF32
>>> import numpy as np
>>> obj = I16U32ToF32(scale=32768.0)
>>> float(obj.step(0x8000))
-1.0
>>> float(obj.step(0x0000))
0.0
>>> x = np.array([0x8000, 0x0000, 0x7FFF], dtype=np.uint32)
>>> [round(v, 6) for v in obj.steps(x).tolist()]
[-1.0, 0.0, 0.999969]

Public Functions Documentation

function i16u32_to_f32_create

Create a i16u32_to_f32 instance.

i16u32_to_f32_state_t * i16u32_to_f32_create (
    float scale
) 

Pre-computes iscale = 1.0f / scale so the hot step path is a single multiply after the lower-16-bit extraction.

Parameters:

  • scale Denominator scale; 1/scale is applied after sign-extension (default: 32768.0f). Use 32768.0 to match F32ToI16U32 at its default scale.

Returns:

Heap-allocated state, or NULL on allocation failure.

Note:

Caller must call i16u32_to_f32_destroy() when done.


function i16u32_to_f32_destroy

Destroy a i16u32_to_f32 instance and release all memory.

void i16u32_to_f32_destroy (
    i16u32_to_f32_state_t * state
) 

Parameters:

  • state May be NULL.

function i16u32_to_f32_reset

Reset i16u32_to_f32 to its post-create state.

void i16u32_to_f32_reset (
    i16u32_to_f32_state_t * state
) 

No mutable state exists beyond the immutable iscale; reset is a no-op provided for lifecycle symmetry.

Parameters:

  • state Must be non-NULL.

function i16u32_to_f32_step

Process one input sample.

JM_FORCEINLINE  JM_HOT float i16u32_to_f32_step (
    const i16u32_to_f32_state_t * state,
    uint32_t x
) 

Masks the lower 16 bits, sign-extends to int16, then multiplies by iscale. Upper 16 bits are ignored.

Parameters:

  • state Must be non-NULL.
  • x uint32 carrying a Q15 sample in its lower 16 bits.

Returns:

Scaled float32 output.


function i16u32_to_f32_steps

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

void i16u32_to_f32_steps (
    i16u32_to_f32_state_t * state,
    const uint32_t * input,
    float * output,
    size_t n
) 

Applies step() to every element. Accepts an optional pre-allocated output array; allocates a fresh one when output is NULL.

Parameters:

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


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