File i16u64_to_f32_core.h¶
FileList > i16u64_to_f32 > i16u64_to_f32_core.h
Go to the source code of this file
Q15-in-uint64 to float converter. More...
#include "clib_common.h"#include "jm_perf.h"
Classes¶
| Type | Name |
|---|---|
| struct | i16u64_to_f32_state_t I16U64ToF32 state. |
Public Functions¶
| Type | Name |
|---|---|
| i16u64_to_f32_state_t * | i16u64_to_f32_create (float scale) Create a i16u64_to_f32 instance. |
| void | i16u64_to_f32_destroy (i16u64_to_f32_state_t * state) Destroy a i16u64_to_f32 instance and release all memory. |
| void | i16u64_to_f32_reset (i16u64_to_f32_state_t * state) No-op reset, provided only for lifecycle symmetry. |
| JM_FORCEINLINE JM_HOT float | i16u64_to_f32_step (const i16u64_to_f32_state_t * state, uint64_t x) Unpack a Q15 code from a uint64's low 16 bits to a normalised float. |
| void | i16u64_to_f32_steps (i16u64_to_f32_state_t * state, const uint64_t * input, float * output, size_t n) Process a block of Q15-in-uint64 samples to float32. |
Detailed Description¶
Extracts the lower 16 bits of a uint64, 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 F32ToI16U64: a value written by that converter can be recovered here with the same scale.
uint64 0x0000000000008000 → int16 -32768 → float -1.0 uint64 0x0000000000007FFF → int16 32767 → float ~+1.0 uint64 0x0000000000000000 → int16 0 → float 0.0
All 48 upper bits are masked off; values carrying NCO phase-accumulator headroom in those bits are handled transparently.
Lifecycle: create -> (step / steps / reset)* -> destroy
>>> from doppler.cvt import I16U64ToF32
>>> import numpy as np
>>> obj = I16U64ToF32(scale=32768.0)
>>> float(obj.step(0x8000))
-1.0
>>> float(obj.step(0x0000))
0.0
>>> x = np.array([0, 0x8000, 0x7FFF], dtype=np.uint64)
>>> [round(v, 6) for v in obj.steps(x).tolist()]
[0.0, -1.0, 0.999969]
Public Functions Documentation¶
function i16u64_to_f32_create¶
Create a i16u64_to_f32 instance.
Pre-computes iscale = 1.0f / scale so the hot step path is a single multiply after the lower-16-bit extraction.
Parameters:
scaleDenominator scale; 1/scale is applied after sign-extension (default: 32768.0f). Use 32768.0 to match F32ToI16U64 at its default scale.
Returns:
Heap-allocated state, or NULL on allocation failure.
Note:
Caller must call i16u64_to_f32_destroy() when done.
function i16u64_to_f32_destroy¶
Destroy a i16u64_to_f32 instance and release all memory.
Parameters:
stateMay be NULL.
function i16u64_to_f32_reset¶
No-op reset, provided only for lifecycle symmetry.
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:
stateMust be non-NULL.
>>> from doppler.cvt import I16U64ToF32
>>> c = I16U64ToF32()
>>> c.reset() # stateless converter -> reset is a no-op
>>> round(c.step(16384), 4)
0.5
function i16u64_to_f32_step¶
Unpack a Q15 code from a uint64's low 16 bits to a normalised float.
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 48 bits (which may carry NCO phase-accumulator headroom) are ignored. Exact inverse of F32ToI16U64 at the same scale.
Parameters:
stateMust be non-NULL.xuint64 carrying a Q15 code in its low 16 bits.
Returns:
Normalised float recovered from the low-16 Q15 code.
>>> from doppler.cvt import I16U64ToF32
>>> c = I16U64ToF32(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 i16u64_to_f32_steps¶
Process a block of Q15-in-uint64 samples to float32.
void i16u64_to_f32_steps (
i16u64_to_f32_state_t * state,
const uint64_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:
stateMust be non-NULL.inputInput uint64 array (Q15 packed in lower 16 bits); must contain at leastnelements.outputOutput float32 array; must contain at leastnelements.nNumber of samples to process.
>>> from doppler.cvt import I16U64ToF32
>>> import numpy as np
>>> I16U64ToF32().steps(np.array([0, 16384], dtype=np.uint64)).tolist()
[0.0, 0.5]
The documentation for this class was generated from the following file native/inc/i16u64_to_f32/i16u64_to_f32_core.h