Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
Classes | Functions
sbl::dsp::stereo Namespace Reference

Stereo panning utilities. More...

Classes

struct  PanGain
 Stereo pan gains (float) More...
 

Functions

PanGain constant_power (float position)
 Compute constant-power pan gains (-3 dB at center)
 
void pan_mix (const float *mono, float *left, float *right, PanGain gain, uint16_t frames)
 Apply pan gains to a mono buffer and accumulate into stereo buffers.
 

Detailed Description

Stereo panning utilities.

Function Documentation

◆ constant_power()

PanGain sbl::dsp::stereo::constant_power ( float  position)
inline

Compute constant-power pan gains (-3 dB at center)

Uses sqrt-based constant-power pan law: L = sqrt(1 - p), R = sqrt(p)

This ensures L^2 + R^2 = 1 for any position, maintaining constant power across the stereo field.

Parameters
positionPan position: 0.0 = hard left, 0.5 = center, 1.0 = hard right
Returns
PanGain with left and right gains [0.0, 1.0]
Note
Uses sqrtf internally. Intended for init-time precomputation, not per-sample use. On Cortex-M7 with FPU, cost is ~10 cycles.

Definition at line 53 of file stereo.hpp.

◆ pan_mix()

void sbl::dsp::stereo::pan_mix ( const float *  mono,
float *  left,
float *  right,
PanGain  gain,
uint16_t  frames 
)
inline

Apply pan gains to a mono buffer and accumulate into stereo buffers.

Multiplies each mono sample by the left and right gains, and ADDS the result to the left[] and right[] buffers. Caller must zero the stereo buffers before the first call when mixing multiple sources.

Parameters
monoInput mono buffer (read-only)
leftLeft output buffer (accumulated, += semantics)
rightRight output buffer (accumulated, += semantics)
gainPrecomputed pan gains from constant_power()
framesNumber of samples
Note
ISR-safe — bounded computation, no I/O

Definition at line 78 of file stereo.hpp.

References sbl::dsp::stereo::PanGain::left, and sbl::dsp::stereo::PanGain::right.

Referenced by sbl::widgets::source::SuperSawOsc::process_stereo().

Here is the caller graph for this function: