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) Reset i16u64_to_f32 to its post-create state. |
| JM_FORCEINLINE JM_HOT float | i16u64_to_f32_step (const i16u64_to_f32_state_t * state, uint64_t x) Process one input sample. |
| 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¶
Reset i16u64_to_f32 to its post-create state.
No mutable state exists beyond the immutable iscale; reset is a no-op provided for lifecycle symmetry.
Parameters:
stateMust be non-NULL.
function i16u64_to_f32_step¶
Process one input sample.
Masks the lower 16 bits, sign-extends to int16, then multiplies by iscale. Upper 48 bits are ignored.
Parameters:
stateMust be non-NULL.xuint64 carrying a Q15 sample in its lower 16 bits.
Returns:
Scaled float32 output.
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