Skip to content

File u8_to_f32_core.h

File List > doppler > u8_to_f32 > u8_to_f32_core.h

Go to the documentation of this file

#ifndef DP_U8_TO_F32_CORE_H
#define DP_U8_TO_F32_CORE_H

#include "doppler/clib_common.h"
#include "doppler/jm_perf.h"
#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
    U8_TO_F32_SHIFT    = 0, 
    U8_TO_F32_MIDPOINT = 1  
} u8_to_f32_mode_t;

typedef struct {
    int   mode;   /* u8_to_f32_mode_t, validated at create */
    float iscale; /* 1/127.5, pre-computed for the midpoint multiply */
} dp_u8_to_f32_state_t;

dp_u8_to_f32_state_t *dp_u8_to_f32_create(int mode);

void dp_u8_to_f32_destroy(dp_u8_to_f32_state_t *state);

void dp_u8_to_f32_reset(dp_u8_to_f32_state_t *state);

JM_FORCEINLINE float
u8_to_f32_shift(uint8_t x)
{
    return (float)((int32_t)x - 128) * 0x1p-7f;
}

JM_FORCEINLINE float
u8_to_f32_midpoint(const dp_u8_to_f32_state_t *state, uint8_t x)
{
    return ((float)x - 127.5f) * state->iscale;
}

JM_FORCEINLINE JM_HOT float
dp_u8_to_f32_step(const dp_u8_to_f32_state_t *state, uint8_t x)
{
    return state->mode == U8_TO_F32_MIDPOINT ? u8_to_f32_midpoint(state, x)
                                             : u8_to_f32_shift(x);
}

void dp_u8_to_f32_steps(
    dp_u8_to_f32_state_t *state,
    const uint8_t    *input,
    float          *output,
    size_t               n);





#ifdef __cplusplus
}
#endif

#endif /* U8_TO_F32_CORE_H */