TinyModem
Header-only software audio modem library
Loading...
Searching...
No Matches
tinymodem::SampleRateConverter Class Reference

Converts the sample rate of a signal with a windowed sinc low pass filter (by default the cut off is at 45% of the lower sample rate). More...

#include <DSPUtils.h>

Public Member Functions

void begin (float in_rate, float out_rate, float cutoff=0.45f)
void reset ()
void setRateFactor (double factor)
template<class F>
void write (float x, F out)
 Adds an input sample and calls out(float) for each output sample.
template<class F>
void writeComplex (float re, float im, F out)

Protected Member Functions

float kernel (float u)
 kernel at the distance u (in samples of the lower rate)

Protected Attributes

float table [TABLE+2]
audio_tools::Vector< float > history
audio_tools::Vector< float > history_q
double ratio = 1
double base_ratio = 1
float cutoff = 0.45f
bool bypass = true
float half_width = HALF_WIDTH
float kernel_scale = 1
int64_t count = 0
double next = 0

Static Protected Attributes

static constexpr int HALF_WIDTH = 8
static constexpr int TABLE = 512

Detailed Description

Converts the sample rate of a signal with a windowed sinc low pass filter (by default the cut off is at 45% of the lower sample rate).

Member Function Documentation

◆ begin()

void tinymodem::SampleRateConverter::begin ( float in_rate,
float out_rate,
float cutoff = 0.45f )
inline

Defines the input and output sample rate and the cut off relative to the lower sample rate

◆ kernel()

float tinymodem::SampleRateConverter::kernel ( float u)
inlineprotected

kernel at the distance u (in samples of the lower rate)

◆ reset()

void tinymodem::SampleRateConverter::reset ( )
inline

◆ setRateFactor()

void tinymodem::SampleRateConverter::setRateFactor ( double factor)
inline

Changes the output rate by the indicated factor (e.g. 1.001), e.g. to follow a different clock of the sender

◆ write()

template<class F>
void tinymodem::SampleRateConverter::write ( float x,
F out )
inline

Adds an input sample and calls out(float) for each output sample.

◆ writeComplex()

template<class F>
void tinymodem::SampleRateConverter::writeComplex ( float re,
float im,
F out )
inline

Adds a complex input sample (both parts use the same timing) and calls out(float re, float im) for each output sample

Member Data Documentation

◆ base_ratio

double tinymodem::SampleRateConverter::base_ratio = 1
protected

◆ bypass

bool tinymodem::SampleRateConverter::bypass = true
protected

◆ count

int64_t tinymodem::SampleRateConverter::count = 0
protected

◆ cutoff

float tinymodem::SampleRateConverter::cutoff = 0.45f
protected

◆ HALF_WIDTH

int tinymodem::SampleRateConverter::HALF_WIDTH = 8
staticconstexprprotected

◆ half_width

float tinymodem::SampleRateConverter::half_width = HALF_WIDTH
protected

◆ history

audio_tools::Vector<float> tinymodem::SampleRateConverter::history
protected

◆ history_q

audio_tools::Vector<float> tinymodem::SampleRateConverter::history_q
protected

◆ kernel_scale

float tinymodem::SampleRateConverter::kernel_scale = 1
protected

◆ next

double tinymodem::SampleRateConverter::next = 0
protected

◆ ratio

double tinymodem::SampleRateConverter::ratio = 1
protected

◆ TABLE

int tinymodem::SampleRateConverter::TABLE = 512
staticconstexprprotected

◆ table

float tinymodem::SampleRateConverter::table[TABLE+2]
protected

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