Skip to content

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)
No-op reset, provided only for lifecycle symmetry.
JM_FORCEINLINE JM_HOT float uq15_to_f32_step (const uq15_to_f32_state_t * state, uint16_t x)
Decode one offset-binary UQ15 uint16 code to a normalised float.
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:

x̂ = ((int32_t)u - 32768) * (1 / 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.

uq15_to_f32_state_t * uq15_to_f32_create (
    float scale
) 

Pre-computes iscale = 1.0f / scale so the hot step path is a single subtract and multiply.

Parameters:

  • scale Denominator 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.

void uq15_to_f32_destroy (
    uq15_to_f32_state_t * state
) 

Parameters:

  • state May be NULL.

function uq15_to_f32_reset

No-op reset, provided only for lifecycle symmetry.

void uq15_to_f32_reset (
    uq15_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 UQ15ToF32
>>> c = UQ15ToF32()
>>> c.reset()           # stateless converter -> reset is a no-op
>>> round(c.step(32768), 4)
0.0

function uq15_to_f32_step

Decode one offset-binary UQ15 uint16 code to a normalised float.

JM_FORCEINLINE  JM_HOT float uq15_to_f32_step (
    const uq15_to_f32_state_t * state,
    uint16_t x
) 

Computes `((int32\_t)x - 32768) \* iscale — removes the 32768 offset-binary bias and applies1/scale. The int32\_t cast prevents signed overflow whenx` is 0 (which yields -32768 after bias removal). Exact inverse of F32ToUQ15 at the same scale.

Parameters:

  • state Must be non-NULL.
  • x UQ15 offset-binary uint16 code: 0 -> -1.0, 32768 -> 0.0, 65535 -> +32767/32768.

Returns:

Normalised float in [-1.0, ~+1.0).

>>> from doppler.cvt import UQ15ToF32
>>> c = UQ15ToF32(scale=32768.0)
>>> round(c.step(32768), 4)   # midscale code -> 0.0
0.0
>>> round(c.step(0), 4)       # zero code -> -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:

  • state Must be non-NULL.
  • input Input uint16 offset-binary array; 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 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