LMMS
Loading...
Searching...
No Matches
lmms::AudioResampler Class Reference

A utility class for resampling interleaved audio buffers using various resampling algorithms. More...

#include <AudioResampler.h>

Classes

struct  Result
 Result of a resampling operation. More...
struct  StateDeleter

Public Types

enum class  Mode {
  ZOH , Linear , SincFastest , SincMedium ,
  SincBest
}
 Defines the resampling method to use. More...

Public Member Functions

 AudioResampler (Mode mode, ch_cnt_t channels=2)
 Constructs an AudioResampler instance.
auto process (InterleavedBufferView< const float > input, InterleavedBufferView< float > output) -> Result
 Process a block of interleaved audio input from input and resample it into output.
void reset ()
 Resets the internal resampler state. Useful when working with unreleated pieces of audio.
void setRatio (double ratio)
 Sets the resampling ratio to ratio.
void setRatio (sample_rate_t input, sample_rate_t output)
 Sets the resampling ratio to output / input.
auto ratio () const -> double
auto channels () const -> ch_cnt_t
auto mode () const -> Mode

Private Attributes

std::unique_ptr< void, StateDeleterm_state
Mode m_mode
ch_cnt_t m_channels = 0
double m_ratio = 1.0
int m_error = 0

Detailed Description

A utility class for resampling interleaved audio buffers using various resampling algorithms.

This class provides support for zero-order hold, linear, and several levels of sinc-based resampling.

Member Enumeration Documentation

◆ Mode

enum class lmms::AudioResampler::Mode
strong

Defines the resampling method to use.

Enumerator
ZOH 

Zero Order Hold (nearest-neighbor) interpolation.

Linear 

Linear interpolation.

SincFastest 

Fastest sinc-based resampling.

SincMedium 

Medium quality sinc-based resampling.

SincBest 

Highest quality sinc-based resampling.

Constructor & Destructor Documentation

◆ AudioResampler()

lmms::AudioResampler::AudioResampler ( Mode mode,
ch_cnt_t channels = 2 )

Constructs an AudioResampler instance.

Parameters
modeThe resampling mode to use.
channelsNumber of audio channels. Defaults to 2 (stereo).

Member Function Documentation

◆ channels()

auto lmms::AudioResampler::channels ( ) const -> ch_cnt_t
inline
Returns
the number of channels expected by the resampler.

◆ mode()

auto lmms::AudioResampler::mode ( ) const -> Mode
inline
Returns
the interpolation mode used by this resampler.

◆ process()

auto lmms::AudioResampler::process ( InterleavedBufferView< const float > input,
InterleavedBufferView< float > output ) -> Result
nodiscard

Process a block of interleaved audio input from input and resample it into output.

Parameters
inputThe interleaved audio input.
outputThe interleaved audio output.
Exceptions
`std::invalid_argument`if a channel mismatch has been detected.
`std::runtime_error`if the resampling process has failed.
Remarks
This utility class does not cache the input and output buffers, making it stateless. In other words, input is directly resampled into the output.
Returns
the result of the resampling process. See Result for more details.

◆ ratio()

auto lmms::AudioResampler::ratio ( ) const -> double
inline
Returns
the resampling ratio.

◆ reset()

void lmms::AudioResampler::reset ( )

Resets the internal resampler state. Useful when working with unreleated pieces of audio.

◆ setRatio() [1/2]

void lmms::AudioResampler::setRatio ( double ratio)
inline

Sets the resampling ratio to ratio.

Parameters
ratioOutput sample rate divided by input sample rate.

◆ setRatio() [2/2]

void lmms::AudioResampler::setRatio ( sample_rate_t input,
sample_rate_t output )
inline

Sets the resampling ratio to output / input.

Parameters
inputInput sample rate.
outputOutput sample rate.

Member Data Documentation

◆ m_channels

ch_cnt_t lmms::AudioResampler::m_channels = 0
private

◆ m_error

int lmms::AudioResampler::m_error = 0
private

◆ m_mode

Mode lmms::AudioResampler::m_mode
private

◆ m_ratio

double lmms::AudioResampler::m_ratio = 1.0
private

◆ m_state

std::unique_ptr<void, StateDeleter> lmms::AudioResampler::m_state
private

The documentation for this class was generated from the following files: