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)
No-op reset, provided only for lifecycle symmetry.
JM_FORCEINLINE JM_HOT float i16u32_to_f32_step (const i16u32_to_f32_state_t * state, uint32_t x)
Unpack a Q15 code from a uint32's low 16 bits to a normalised float.
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

No-op reset, provided only for lifecycle symmetry.

void i16u32_to_f32_reset (
    i16u32_to_f32_state_t * state
) 

No mutable state exists beyond the immutable iscale, so there is nothing to clear; the method exists so every converter in the module presents the same create / step / reset / destroy lifecycle.

Parameters:

  • state Must be non-NULL.
>>> from doppler.cvt import I16U32ToF32
>>> c = I16U32ToF32()
>>> c.reset()           # stateless converter -> reset is a no-op
>>> round(c.step(16384), 4)
0.5

function i16u32_to_f32_step

Unpack a Q15 code from a uint32's low 16 bits to a normalised float.

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

Masks off the lower 16 bits, reinterprets them as a signed int16 (two's complement), then multiplies by iscale — a single multiply after the extraction. The upper 16 bits (which may carry CIC bit-growth headroom) are ignored. Exact inverse of F32ToI16U32 at the same scale.

Parameters:

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

Returns:

Normalised float recovered from the low-16 Q15 code.

>>> from doppler.cvt import I16U32ToF32
>>> c = I16U32ToF32(scale=32768.0)
>>> round(c.step(16384), 4)         # low-16 Q15 16384 -> 0.5
0.5
>>> round(c.step(0x8000), 4)     # 0x8000 read as -32768 -> -1.0
-1.0

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