arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
audio_tools::Resample< T > Class Template Reference

A simple implementation which changes the sample rate by the indicated integer factor. To downlample we calculate the avarage of n (=factor) samples. To upsample we interpolate the missing samples. If the indicated factor is positive we upsample if it is negative we downsample. More...

#include <Resample.h>

Inheritance diagram for audio_tools::Resample< T >:
audio_tools::AudioStreamX audio_tools::AudioStream audio_tools::Stream audio_tools::AudioBaseInfoDependent audio_tools::AudioBaseInfoSource audio_tools::Print

Public Member Functions

 Resample ()=default
 Construct a new Resample object call setOut and begin to setup the required parameters.
 
int available () override
 Determines the available bytes from the final source stream. More...
 
int availableForWrite () override
 
bool begin (int channels, int factor, ResampleScenario scenario)
 
bool begin (Print &out, int channels, int factor, ResampleScenario scenario)
 Construct a new Converter Resample object. More...
 
bool begin (Stream &in, int channels, int factor, ResampleScenario scenario)
 Construct a new Resample object. More...
 
size_t lastBytesWritten ()
 
size_t readBytes (uint8_t *src, size_t length) override
 Reads the up/downsampled bytes. More...
 
size_t resampleFactor ()
 
void setIn (Stream &in)
 
void setOut (Print &out)
 
size_t write (const uint8_t *src, size_t byte_count) override
 Writes the data up or downsampled to the final destination. More...
 
- Public Member Functions inherited from audio_tools::AudioStreamX
 AudioStreamX (AudioStreamX const &)=delete
 
virtual int available () override
 
AudioStreamXoperator= (AudioStreamX const &)=delete
 
virtual int peek () override
 
virtual int read () override
 
virtual size_t readBytes (uint8_t *buffer, size_t length) override
 
virtual size_t write (const uint8_t *buffer, size_t size) override
 
virtual size_t write (uint8_t) override
 
- Public Member Functions inherited from audio_tools::AudioStream
 AudioStream (AudioStream const &)=delete
 
virtual AudioBaseInfo audioInfo () override
 
virtual int availableForWrite () override
 
virtual bool begin ()
 
virtual void end ()
 
virtual void flush () override
 
 operator bool ()
 
AudioStreamoperator= (AudioStream const &)=delete
 
virtual size_t readBytes (char *buffer, size_t length)
 
virtual size_t readBytes (uint8_t *buffer, size_t length) STREAM_WRITE_OVERRIDE=0
 
virtual void setAudioInfo (AudioBaseInfo info) override
 
virtual void setNotifyAudioChange (AudioBaseInfoDependent &bi) override
 
virtual StreamtoStreamPointer ()
 
virtual size_t write (const uint8_t *buffer, size_t size) override=0
 
- Public Member Functions inherited from audio_tools::Stream
virtual int available ()
 
virtual int peek ()
 
virtual int read ()
 
virtual size_t readBytes (uint8_t *buffer, size_t len)
 
virtual void setTimeout (size_t t)
 
- Public Member Functions inherited from audio_tools::Print
virtual int availableForWrite ()
 
virtual void flush ()
 
virtual int print (char c, PrintCharFmt spec)
 
virtual int print (const char *msg)
 
virtual int print (int number)
 
virtual int println (const char *msg="")
 
virtual size_t write (const char *buffer, size_t size)
 
virtual size_t write (const char *str)
 
virtual size_t write (const uint8_t *buffer, size_t size)
 
virtual size_t write (uint8_t ch)
 
- Public Member Functions inherited from audio_tools::AudioBaseInfoDependent
virtual AudioBaseInfo audioInfo ()=0
 
virtual void setAudioInfo (AudioBaseInfo info)=0
 
virtual bool validate (AudioBaseInfo &info)
 
virtual void setNotifyAudioChange (AudioBaseInfoDependent &bi)=0
 

Protected Member Functions

void allocateBuffer (int len)
 
size_t downsample (T *from, T *to, int sample_count, int channels, int factor)
 
size_t downsampleSkip (T *from, T *to, int sample_count, int channels, int skip_every_nth)
 
T * p_data (int frame_pos, int channel, T *start)
 
size_t upsample (T *from, T *to, int sample_count, int channels, int factor)
 Increases the samples by the indicated factor: We interpolate the missing samples.
 
size_t upsampleMultiply (T *from, T *to, int sample_count, int channels, int factor)
 Increases the samples by the indicated factor: We repeat the input samples.
 
- Protected Member Functions inherited from audio_tools::AudioStream
virtual int not_supported (int out)
 

Protected Attributes

T * buffer =nullptr
 
int buffer_size = 0
 
size_t bytes = 0
 
int channels = 2
 
int downsample_skip_counter = 0
 
int downsample_start_offset = 0
 
int factor = 1
 
bool is_active = false
 
T * last_end =nullptr
 
Streamp_in =nullptr
 
Printp_out =nullptr
 
ResampleScenario scenario
 
- Protected Attributes inherited from audio_tools::AudioStream
AudioBaseInfo info
 
AudioBaseInfoDependentp_notify =nullptr
 

Detailed Description

template<typename T>
class audio_tools::Resample< T >

A simple implementation which changes the sample rate by the indicated integer factor. To downlample we calculate the avarage of n (=factor) samples. To upsample we interpolate the missing samples. If the indicated factor is positive we upsample if it is negative we downsample.

Author
Phil Schatzmann
Template Parameters
Tdata type of audio data

Member Function Documentation

◆ available()

template<typename T >
int audio_tools::Resample< T >::available ( )
inlineoverridevirtual

Determines the available bytes from the final source stream.

Reimplemented from audio_tools::AudioStreamX.

◆ availableForWrite()

template<typename T >
int audio_tools::Resample< T >::availableForWrite ( )
inlineoverridevirtual

Reimplemented from audio_tools::AudioStream.

◆ begin() [1/2]

template<typename T >
bool audio_tools::Resample< T >::begin ( Print out,
int  channels,
int  factor,
ResampleScenario  scenario 
)
inline

Construct a new Converter Resample object.

Parameters
channelsnumber of channels (default 2)
factoruse a negative value to downsample

◆ begin() [2/2]

template<typename T >
bool audio_tools::Resample< T >::begin ( Stream in,
int  channels,
int  factor,
ResampleScenario  scenario 
)
inline

Construct a new Resample object.

Parameters
in
channels
factor

◆ readBytes()

template<typename T >
size_t audio_tools::Resample< T >::readBytes ( uint8_t *  src,
size_t  length 
)
inlineoverridevirtual

Reads the up/downsampled bytes.

Reimplemented from audio_tools::AudioStreamX.

◆ write()

template<typename T >
size_t audio_tools::Resample< T >::write ( const uint8_t *  src,
size_t  byte_count 
)
inlineoverridevirtual

Writes the data up or downsampled to the final destination.

Reimplemented from audio_tools::AudioStreamX.


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