DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
dspark::MidSide< T > Struct Template Reference

Static utility for Mid/Side stereo encoding and decoding. More...

#include <MidSide.h>

Static Public Member Functions

static constexpr void encodeSample (T &left_mid, T &right_side) noexcept
 Encodes a single sample frame from Left/Right to Mid/Side in-place.
 
static constexpr void decodeSample (T &mid_left, T &side_right) noexcept
 Decodes a single sample frame from Mid/Side to Left/Right in-place.
 
static void encode (AudioBufferView< T > buffer) noexcept
 Encodes an entire stereo buffer from Left/Right to Mid/Side.
 
static void decode (AudioBufferView< T > buffer) noexcept
 Decodes an entire stereo buffer from Mid/Side back to Left/Right.
 

Detailed Description

template<typename T>
struct dspark::MidSide< T >

Static utility for Mid/Side stereo encoding and decoding.

Buffers with fewer than two channels are left untouched (release-safe no-op); channels beyond the first two are ignored.

Template Parameters
TSample type (float or double).

Definition at line 56 of file MidSide.h.

Member Function Documentation

◆ decode()

template<typename T >
static void dspark::MidSide< T >::decode ( AudioBufferView< T >  buffer)
inlinestaticnoexcept

Decodes an entire stereo buffer from Mid/Side back to Left/Right.

L = M + S R = M - S

Precondition
The two channels must not alias each other (they never do in a view over a real stereo buffer; the loop is restrict-qualified).
Parameters
bufferStereo buffer (2 channels, containing M/S). Modified in-place. Fewer than 2 channels: no-op.

Definition at line 136 of file MidSide.h.

◆ decodeSample()

template<typename T >
static constexpr void dspark::MidSide< T >::decodeSample ( T &  mid_left,
T &  side_right 
)
inlinestaticconstexprnoexcept

Decodes a single sample frame from Mid/Side to Left/Right in-place.

Bit-identical to decode() applied to the same frame.

Parameters
mid_leftReference to the mid sample (becomes left).
side_rightReference to the side sample (becomes right).

Definition at line 84 of file MidSide.h.

◆ encode()

template<typename T >
static void dspark::MidSide< T >::encode ( AudioBufferView< T >  buffer)
inlinestaticnoexcept

Encodes an entire stereo buffer from Left/Right to Mid/Side.

M = (L + R) * 0.5 S = (L - R) * 0.5

The 0.5 scaling preserves peak amplitude (unity round-trip gain) and avoids clipping when summing highly correlated signals.

Precondition
The two channels must not alias each other (they never do in a view over a real stereo buffer; the loop is restrict-qualified).
Parameters
bufferStereo buffer (2 channels). Modified in-place. Fewer than 2 channels: no-op.

Definition at line 106 of file MidSide.h.

◆ encodeSample()

template<typename T >
static constexpr void dspark::MidSide< T >::encodeSample ( T &  left_mid,
T &  right_side 
)
inlinestaticconstexprnoexcept

Encodes a single sample frame from Left/Right to Mid/Side in-place.

Useful for interleaving M/S processing inside a custom DSP loop to maintain L1/L2 cache locality and avoid multi-pass buffer traversals. Bit-identical to encode() applied to the same frame.

Parameters
left_midReference to the left sample (becomes mid).
right_sideReference to the right sample (becomes side).

Definition at line 68 of file MidSide.h.


The documentation for this struct was generated from the following file: