Skip to content

File i8_to_f32_core.h

FileList > doppler > i8_to_f32 > i8_to_f32_core.h

Go to the source code of this file

int8-to-float converter with configurable inverse scale. More...

  • #include "doppler/clib_common.h"
  • #include "doppler/jm_perf.h"

Classes

Type Name
struct dp_i8_to_f32_state_t
I8ToF32 state.

Public Functions

Type Name
dp_i8_to_f32_state_t * dp_i8_to_f32_create (float scale)
Create a i8_to_f32 instance.
void dp_i8_to_f32_destroy (dp_i8_to_f32_state_t * state)
Destroy a i8_to_f32 instance and release all memory.
void dp_i8_to_f32_reset (dp_i8_to_f32_state_t * state)
No-op reset, provided only for lifecycle symmetry.
JM_FORCEINLINE JM_HOT float dp_i8_to_f32_step (const dp_i8_to_f32_state_t * state, int8_t x)
Convert one signed int8 sample to a normalised float via 1/scale .
void dp_i8_to_f32_steps (dp_i8_to_f32_state_t * state, const int8_t * input, float * output, size_t n)
Process a block of int8 samples to float32.

Detailed Description

Multiplies each signed int8 sample by 1/scale and returns a float32. The default scale of 128.0 maps the full int8 range [-128, 127] to [-1.0, ~+1.0), which is the natural inverse of an 8-bit ADC path. This converter is used in the 8-bit IQ sample pipeline for SIGNED 8-bit I/Q streams (cs8, e.g. HackRF) where samples arrive as int8 and must be converted to normalised complex floats. An RTL-SDR streams UNSIGNED offset-binary bytes (cu8) instead; read as int8 they are wrong by a sign flip above code 127, so use U8ToF32 for those. The inverse scale is pre-computed at construction time.

Lifecycle: create -> [step / steps / reset]* -> destroy

>>> from doppler.cvt import I8ToF32
>>> import numpy as np
>>> obj = I8ToF32(scale=128.0)
>>> float(obj.step(-128))
-1.0
>>> float(obj.step(0))
0.0
>>> x = np.array([-128, 0, 127], dtype=np.int8)
>>> [round(v, 7) for v in obj.steps(x).tolist()]
[-1.0, 0.0, 0.9921875]

Public Functions Documentation

function dp_i8_to_f32_create

Create a i8_to_f32 instance.

dp_i8_to_f32_state_t * dp_i8_to_f32_create (
    float scale
) 

Pre-computes iscale = 1.0f / scale.

Parameters:

  • scale Denominator scale; 1/scale is applied to each sample (default: 128.0f). Use 128.0 to recover normalised floats from a signed 8-bit stream.

Returns:

Heap-allocated state, or NULL on allocation failure.

Note:

Caller must call dp_i8_to_f32_destroy() when done.


function dp_i8_to_f32_destroy

Destroy a i8_to_f32 instance and release all memory.

void dp_i8_to_f32_destroy (
    dp_i8_to_f32_state_t * state
) 

Parameters:

  • state May be NULL.

function dp_i8_to_f32_reset

No-op reset, provided only for lifecycle symmetry.

void dp_i8_to_f32_reset (
    dp_i8_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 I8ToF32
>>> c = I8ToF32()
>>> c.reset()           # stateless converter -> reset is a no-op
>>> round(c.step(-128), 4)
-1.0

function dp_i8_to_f32_step

Convert one signed int8 sample to a normalised float via 1/scale .

JM_FORCEINLINE  JM_HOT float dp_i8_to_f32_step (
    const dp_i8_to_f32_state_t * state,
    int8_t x
) 

Returns `(float)x \* iscale, a single multiply on the hot path. At the default scale of 128 the full int8 range recovers[-1.0, ~+1.0)— the front end of a signed 8-bit IQ path (e.g. a HackRFcs8` stream) into normalised floats.

Parameters:

  • state Must be non-NULL.
  • x Signed int8 code in [-128, 127].

Returns:

Normalised float, x / scale.

>>> from doppler.cvt import I8ToF32
>>> c = I8ToF32(scale=128.0)   # signed 8-bit -> normalised float
>>> round(c.step(64), 4)        # 64 / 128
0.5
>>> round(c.step(-128), 4)      # full-negative code -> -1.0
-1.0

function dp_i8_to_f32_steps

Process a block of int8 samples to float32.

void dp_i8_to_f32_steps (
    dp_i8_to_f32_state_t * state,
    const int8_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:

  • state Must be non-NULL.
  • input Input int8 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 I8ToF32
>>> import numpy as np
>>> I8ToF32().steps(np.array([0, 64, -128], dtype=np.int8)).tolist()
[0.0, 0.5, -1.0]


The documentation for this class was generated from the following file native/inc/doppler/i8_to_f32/i8_to_f32_core.h