File uq15_to_f32_core.h¶
FileList > inc > uq15_to_f32 > uq15_to_f32_core.h
Go to the source code of this file
UQ15 (offset-binary uint16) to float converter. More...
#include "clib_common.h"#include "jm_perf.h"
Classes¶
| Type | Name |
|---|---|
| struct | uq15_to_f32_state_t UQ15ToF32 state. |
Public Functions¶
| Type | Name |
|---|---|
| uq15_to_f32_state_t * | uq15_to_f32_create (float scale) Create a uq15_to_f32 instance. |
| void | uq15_to_f32_destroy (uq15_to_f32_state_t * state) Destroy a uq15_to_f32 instance and release all memory. |
| void | uq15_to_f32_reset (uq15_to_f32_state_t * state) Reset uq15_to_f32 to its post-create state. |
| JM_FORCEINLINE JM_HOT float | uq15_to_f32_step (const uq15_to_f32_state_t * state, uint16_t x) Process one input sample. |
| void | uq15_to_f32_steps (uq15_to_f32_state_t * state, const uint16_t * input, float * output, size_t n) Process a block of UQ15 samples to float32. |
Detailed Description¶
Decodes an offset-binary uint16 (UQ15) sample back to a normalised float by removing the +32768 bias and dividing by scale:
This is the exact inverse of F32ToUQ15 with the same scale. The bias removal uses int32_t arithmetic to avoid signed overflow for the u=0 (full-negative) case. The inverse scale is pre-computed at construction time so the step path is a single subtract and multiply.
Lifecycle: create -> (step / steps / reset)* -> destroy
>>> from doppler.cvt import UQ15ToF32
>>> import numpy as np
>>> obj = UQ15ToF32(scale=32768.0)
>>> float(obj.step(32768))
0.0
>>> float(obj.step(0))
-1.0
>>> x = np.array([0, 32768, 65535], dtype=np.uint16)
>>> [round(v, 6) for v in obj.steps(x).tolist()]
[-1.0, 0.0, 0.999969]
Public Functions Documentation¶
function uq15_to_f32_create¶
Create a uq15_to_f32 instance.
Pre-computes iscale = 1.0f / scale so the hot step path is a single subtract and multiply.
Parameters:
scaleDenominator applied after offset-binary bias removal (default: 32768.0f). Use 32768.0 to recover normalised[-1, +1]floats from UQ15 data written by F32ToUQ15. Must be > 0; returns NULL otherwise.
Returns:
Heap-allocated state, or NULL on invalid args or allocation failure.
Note:
Caller must call uq15_to_f32_destroy() when done.
function uq15_to_f32_destroy¶
Destroy a uq15_to_f32 instance and release all memory.
Parameters:
stateMay be NULL.
function uq15_to_f32_reset¶
Reset uq15_to_f32 to its post-create state.
No mutable state exists beyond the immutable iscale; reset is a no-op provided for lifecycle symmetry with other converters.
Parameters:
stateMust be non-NULL.
function uq15_to_f32_step¶
Process one input sample.
Computes `((int32\_t)x - 32768) \* iscale. The int32\_t cast prevents signed overflow whenx` is 0 (which yields -32768 after bias removal).
Parameters:
stateMust be non-NULL.xUQ15 offset-binary uint16 sample: 0x0000 → -1.0f, 0x8000 → 0.0f, 0xFFFF → +32767/32768.
Returns:
Decoded float sample in [-1.0, ~+1.0).
function uq15_to_f32_steps¶
Process a block of UQ15 samples to float32.
void uq15_to_f32_steps (
uq15_to_f32_state_t * state,
const uint16_t * input,
float * output,
size_t n
)
Applies step() to every element. State is not mutated (no clipped flag). Accepts an optional pre-allocated output array; allocates a fresh one when output is NULL.
Parameters:
stateMust be non-NULL.inputInput uint16 offset-binary array; must contain at leastnelements.outputOutput float32 array; must contain at leastnelements.nNumber of samples to process.
>>> from doppler.cvt import UQ15ToF32
>>> import numpy as np
>>> UQ15ToF32().steps(np.array([0, 32768], dtype=np.uint16)).tolist()
[-1.0, 0.0]
The documentation for this class was generated from the following file native/inc/uq15_to_f32/uq15_to_f32_core.h