Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::dsp::types Namespace Reference

Conversion at the DMA boundary. More...

Detailed Description

Conversion at the DMA boundary.

Typedefs

using S24RjI32 = int32_t
 One sample in the codec's DMA word format, s24_rj_i32
 

Functions

void deinterleave_to_float (const S24RjI32 *interleaved, float *left, float *right, uint16_t frames)
 Deinterleave stereo codec words into float L/R buffers.
 
void interleave_from_float (const float *left, const float *right, S24RjI32 *interleaved, uint16_t frames)
 Interleave float L/R buffers into stereo codec words.
 

Variables

constexpr float SAMPLE_SCALE_F = 8388607.0f
 
constexpr float SAMPLE_SCALE_INV_F = 1.0f / 8388607.0f
 

Typedef Documentation

◆ S24RjI32

using sbl::dsp::types::S24RjI32 = typedef int32_t

One sample in the codec's DMA word format, s24_rj_i32

24-bit two's complement, right-aligned in 32 bits. The SAI leaves the upper byte zero; deinterleave_to_float() sign-extends from bit 23, so a sign-extended word reads the same.

Definition at line 37 of file convert.hpp.

Function Documentation

◆ deinterleave_to_float()

void sbl::dsp::types::deinterleave_to_float ( const S24RjI32 *  interleaved,
float *  left,
float *  right,
uint16_t  frames 
)
inline

Deinterleave stereo codec words into float L/R buffers.

Parameters
interleaved[L0, R0, L1, R1, ...], two words per frame
[out]leftOutput, one float per frame; full scale is +/-1.0
[out]rightOutput, one float per frame; full scale is +/-1.0
framesFrame count
Context
Audio thread; real-time safe.

Definition at line 51 of file convert.hpp.

References SAMPLE_SCALE_INV_F.

◆ interleave_from_float()

void sbl::dsp::types::interleave_from_float ( const float *  left,
const float *  right,
S24RjI32 *  interleaved,
uint16_t  frames 
)
inline

Interleave float L/R buffers into stereo codec words.

Clamps each sample to [-1.0, 1.0] before conversion.

NaN guard: IEEE 754 NaN fails all comparisons, so the clamp would pass NaN through to static_cast<int32_t>(NaN * SCALE), which is undefined behavior. A NaN sample is replaced with 0 first.

Parameters
leftInput, one float per frame, nominally [-1.0, 1.0]
rightInput, one float per frame, nominally [-1.0, 1.0]
[out]interleavedOutput [L0, R0, L1, R1, ...], two words per frame
framesFrame count
Context
Audio thread; real-time safe.

Definition at line 93 of file convert.hpp.

References SAMPLE_SCALE_F, and SBL_NAN_DETECTED.

Variable Documentation

◆ SAMPLE_SCALE_F

constexpr float sbl::dsp::types::SAMPLE_SCALE_F = 8388607.0f
inlineconstexpr

24-bit full scale: +/-8,388,607

Definition at line 39 of file convert.hpp.

Referenced by interleave_from_float().

◆ SAMPLE_SCALE_INV_F

constexpr float sbl::dsp::types::SAMPLE_SCALE_INV_F = 1.0f / 8388607.0f
inlineconstexpr

1 / SAMPLE_SCALE_F

Definition at line 40 of file convert.hpp.

Referenced by deinterleave_to_float().