File i16_to_f32_core.h¶
FileList > i16_to_f32 > i16_to_f32_core.h
Go to the source code of this file
int16-to-float converter with configurable inverse scale. More...
#include "clib_common.h"#include "jm_perf.h"
Classes¶
| Type | Name |
|---|---|
| struct | i16_to_f32_state_t I16ToF32 state. |
Public Functions¶
| Type | Name |
|---|---|
| i16_to_f32_state_t * | i16_to_f32_create (float scale) Create a i16_to_f32 instance. |
| void | i16_to_f32_destroy (i16_to_f32_state_t * state) Destroy a i16_to_f32 instance and release all memory. |
| void | i16_to_f32_reset (i16_to_f32_state_t * state) Reset i16_to_f32 to its post-create state. |
| JM_FORCEINLINE JM_HOT float | i16_to_f32_step (const i16_to_f32_state_t * state, int16_t x) Process one input sample. |
| void | i16_to_f32_steps (i16_to_f32_state_t * state, const int16_t * input, float * output, size_t n) Process a block of int16 samples to float32. |
Detailed Description¶
Multiplies the signed int16 sample by 1/scale. The default scale of 32768.0 maps the full Q15 range [-32768, 32767] to [-1.0, ~+1.0), making it the exact inverse of F32ToI16 at its default scale. The inverse scale is pre-computed at construction time so each step is a single multiply with no division on the hot path.
Lifecycle: create -> (step / steps / reset)* -> destroy
>>> from doppler.cvt import I16ToF32
>>> import numpy as np
>>> obj = I16ToF32(scale=32768.0)
>>> float(obj.step(-32768))
-1.0
>>> float(obj.step(0))
0.0
>>> x = np.array([-32768, 0, 32767], dtype=np.int16)
>>> [round(v, 6) for v in obj.steps(x).tolist()]
[-1.0, 0.0, 0.999969]
Public Functions Documentation¶
function i16_to_f32_create¶
Create a i16_to_f32 instance.
Pre-computes iscale = 1.0f / scale so the hot step path is a single multiply. Any non-zero finite float is a valid scale value.
Parameters:
scaleDenominator scale; 1/scale is applied to each sample (default: 32768.0f). Use 32768.0 to recover normalised[-1, +1]floats from a Q15 int16 stream.
Returns:
Heap-allocated state, or NULL on allocation failure.
Note:
Caller must call i16_to_f32_destroy() when done.
function i16_to_f32_destroy¶
Destroy a i16_to_f32 instance and release all memory.
Parameters:
stateMay be NULL.
function i16_to_f32_reset¶
Reset i16_to_f32 to its post-create state.
This converter has no accumulating state beyond the immutable iscale field, so reset is a no-op in practice; it exists for lifecycle symmetry.
Parameters:
stateMust be non-NULL.
function i16_to_f32_step¶
Process one input sample.
Returns ``(float)x * iscale. No saturation or clipping possible — the int16 range maps cleanly to float32.
Parameters:
stateMust be non-NULL.xSigned int16 input sample.
Returns:
Scaled float output.
function i16_to_f32_steps¶
Process a block of int16 samples to float32.
void i16_to_f32_steps (
i16_to_f32_state_t * state,
const int16_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 int16 array; must contain at leastnelements.outputOutput float32 array; must contain at leastnelements.nNumber of samples to process.
>>> from doppler.cvt import I16ToF32
>>> import numpy as np
>>> I16ToF32().steps(np.array([0, 16384, -32768], dtype=np.int16)).tolist()
[0.0, 0.5, -1.0]
The documentation for this class was generated from the following file native/inc/i16_to_f32/i16_to_f32_core.h