arduino-audio-tools
Loading...
Searching...
No Matches
SineFromTable< T > Class Template Reference

A sine generator based on a table. The table is created using degrees where one full wave is 360 degrees. More...

#include <CodecOpusOgg.h>

Inheritance diagram for SineFromTable< T >:
SoundGenerator< int16_t > SoundGenerator< int16_t >

Public Member Functions

 SineFromTable (float amplitude=NumberConverter::maxValueT< T >())
 SineFromTable (float amplitude=NumberConverter::maxValueT< T >())
virtual AudioInfo audioInfo ()
 Provides the AudioInfo.
bool begin ()
bool begin ()
bool begin (AudioInfo info, float frequency)
bool begin (AudioInfo info, float frequency)
bool begin (int channels, int sample_rate, uint16_t frequency=0)
bool begin (int channels, int sample_rate, uint16_t frequency=0)
virtual bool begin (AudioInfo info)
 Starts the processing with the provided AudioInfo.
virtual AudioInfo defaultConfig ()
 Provides the default configuration.
virtual void end ()
virtual bool isActive ()
 Checks if the begin method has been called - after end() isActive is false.
virtual size_t readBytes (uint8_t *data, size_t len)
 Provides the data as byte array with the requested number of channels.
T readSample ()
 Provides a single sample.
T readSample ()
 Provides a single sample.
virtual size_t readSamples (int16_t *data, size_t len)
virtual void restart ()
 Restarts the generator, e.g. after a play time has been defined and reached.
void setAmplitude (float amplitude)
 Defines the new amplitude (volume).
void setAmplitude (float amplitude)
 Defines the new amplitude (volume).
virtual void setAudioInfo (AudioInfo info)
 Defines/updates the AudioInfo.
void setFrequency (float freq)
 Abstract method: not implemented! Just provides an error message...
void setFrequency (float freq)
 Abstract method: not implemented! Just provides an error message...
void setMaxAmplitudeStep (float step)
void setMaxAmplitudeStep (float step)
virtual void setPlayTime (uint32_t playMs, uint8_t upPercent=20, uint8_t downPercent=30)
 Defines the play time in ms and the ramp up and ramp down time in percent.
virtual void setRampTimes (uint32_t playMs, uint32_t upMs=5, uint32_t downMs=5)

Protected Member Functions

int16_t applyRamp (int16_t sample)
T interpolate (float angle)
T interpolate (float angle)
T map (T x, T in_min, T in_max, T out_min, T out_max)
T map (T x, T in_min, T in_max, T out_min, T out_max)
size_t readBytesFrames (uint8_t *buffer, size_t lengthBytes, int frames, int channels)
size_t readBytesFromBuffer (uint8_t *buffer, size_t lengthBytes, int frame_size, int channels)
void recalculatePlayTime ()
void updateAmplitudeInSteps ()
void updateAmplitudeInSteps ()

Protected Attributes

bool active
bool activeWarningIssued
float amplitude
float amplitude_to_be
float angle = 0.0f
float base_frequency = 1.0f
uint32_t currentSample
uint32_t downMs
uint8_t downPercent
uint32_t downSamples
float factor
AudioInfo info
bool is_first = true
float max_amplitude_step = 50.0f
uint32_t playMs
uint32_t playSamples
float rampDownDec
float rampUpInc
RingBuffer< uint8_t > ring_buffer
float step = 1.0f
float step_new = 1.0f
uint32_t upMs
uint8_t upPercent
uint32_t upSamples
const float values [181]

Detailed Description

template<class T = int16_t>
class audio_tools::audio_tools::SineFromTable< T >

A sine generator based on a table. The table is created using degrees where one full wave is 360 degrees.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ SineFromTable() [1/2]

template<class T = int16_t>
SineFromTable ( float amplitude = NumberConverter::maxValueT<T>())
inline

◆ SineFromTable() [2/2]

template<class T = int16_t>
SineFromTable ( float amplitude = NumberConverter::maxValueT<T>())
inline

Member Function Documentation

◆ applyRamp()

int16_t applyRamp ( int16_t sample)
inlineprotectedinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlinevirtualinherited

Provides the AudioInfo.

◆ begin() [1/7]

template<class T = int16_t>
bool begin ( )
inline

◆ begin() [2/7]

template<class T = int16_t>
bool begin ( )
inline

◆ begin() [3/7]

template<class T = int16_t>
bool begin ( AudioInfo info,
float frequency )
inline

◆ begin() [4/7]

template<class T = int16_t>
bool begin ( AudioInfo info,
float frequency )
inline

◆ begin() [5/7]

template<class T = int16_t>
bool begin ( int channels,
int sample_rate,
uint16_t frequency = 0 )
inline

◆ begin() [6/7]

template<class T = int16_t>
bool begin ( int channels,
int sample_rate,
uint16_t frequency = 0 )
inline

◆ begin() [7/7]

◆ defaultConfig()

◆ end()

◆ interpolate() [1/2]

template<class T = int16_t>
T interpolate ( float angle)
inlineprotected

◆ interpolate() [2/2]

template<class T = int16_t>
T interpolate ( float angle)
inlineprotected

◆ isActive()

virtual bool isActive ( )
inlinevirtualinherited

Checks if the begin method has been called - after end() isActive is false.

◆ map() [1/2]

template<class T = int16_t>
T map ( T x,
T in_min,
T in_max,
T out_min,
T out_max )
inlineprotected

◆ map() [2/2]

template<class T = int16_t>
T map ( T x,
T in_min,
T in_max,
T out_min,
T out_max )
inlineprotected

◆ readBytes()

virtual size_t readBytes ( uint8_t * data,
size_t len )
inlinevirtualinherited

Provides the data as byte array with the requested number of channels.

Reimplemented in GeneratorQueue< T >, GeneratorQueue< T >, and GeneratorQueue< T >.

◆ readBytesFrames()

size_t readBytesFrames ( uint8_t * buffer,
size_t lengthBytes,
int frames,
int channels )
inlineprotectedinherited

◆ readBytesFromBuffer()

size_t readBytesFromBuffer ( uint8_t * buffer,
size_t lengthBytes,
int frame_size,
int channels )
inlineprotectedinherited

◆ readSample() [1/2]

template<class T = int16_t>
T readSample ( )
inlinevirtual

Provides a single sample.

Implements SoundGenerator< int16_t >.

◆ readSample() [2/2]

template<class T = int16_t>
T readSample ( )
inlinevirtual

Provides a single sample.

Implements SoundGenerator< int16_t >.

◆ readSamples()

virtual size_t readSamples ( int16_t * data,
size_t len )
inlinevirtualinherited

Provides the data as T array (interleaved by channel) with the requested number of samples (values, not frames)

◆ recalculatePlayTime()

void recalculatePlayTime ( )
inlineprotectedinherited

◆ restart()

virtual void restart ( )
inlinevirtualinherited

Restarts the generator, e.g. after a play time has been defined and reached.

◆ setAmplitude() [1/2]

template<class T = int16_t>
void setAmplitude ( float amplitude)
inline

Defines the new amplitude (volume).

◆ setAmplitude() [2/2]

template<class T = int16_t>
void setAmplitude ( float amplitude)
inline

Defines the new amplitude (volume).

◆ setAudioInfo()

◆ setFrequency() [1/2]

template<class T = int16_t>
void setFrequency ( float frequency)
inlinevirtual

Abstract method: not implemented! Just provides an error message...

Reimplemented from SoundGenerator< int16_t >.

◆ setFrequency() [2/2]

template<class T = int16_t>
void setFrequency ( float frequency)
inlinevirtual

Abstract method: not implemented! Just provides an error message...

Reimplemented from SoundGenerator< int16_t >.

◆ setMaxAmplitudeStep() [1/2]

template<class T = int16_t>
void setMaxAmplitudeStep ( float step)
inline

To avoid pops we do not allow to big amplitude changes at once and spread them over time

◆ setMaxAmplitudeStep() [2/2]

template<class T = int16_t>
void setMaxAmplitudeStep ( float step)
inline

To avoid pops we do not allow to big amplitude changes at once and spread them over time

◆ setPlayTime()

virtual void setPlayTime ( uint32_t playMs,
uint8_t upPercent = 20,
uint8_t downPercent = 30 )
inlinevirtualinherited

Defines the play time in ms and the ramp up and ramp down time in percent.

Reimplemented in GeneratorQueue< T >, GeneratorQueue< T >, and GeneratorQueue< T >.

◆ setRampTimes()

virtual void setRampTimes ( uint32_t playMs,
uint32_t upMs = 5,
uint32_t downMs = 5 )
inlinevirtualinherited

Alternative to setPlayTime. It sets ramp-up and ramp-down times in ms instead of percentages. If playMs == 0, it will play indefinitely. restart();begin(); starts the ramp-up and sustain as normal, but it will sustain forever. end(true) triggers a ramp-down then inactive.

◆ updateAmplitudeInSteps() [1/2]

template<class T = int16_t>
void updateAmplitudeInSteps ( )
inlineprotected

◆ updateAmplitudeInSteps() [2/2]

template<class T = int16_t>
void updateAmplitudeInSteps ( )
inlineprotected

Member Data Documentation

◆ active

bool active
protectedinherited

◆ activeWarningIssued

bool activeWarningIssued
protectedinherited

◆ amplitude

template<class T = int16_t>
float amplitude
protected

◆ amplitude_to_be

template<class T = int16_t>
float amplitude_to_be
protected

◆ angle

template<class T = int16_t>
float angle = 0.0f
protected

◆ base_frequency

template<class T = int16_t>
float base_frequency = 1.0f
protected

◆ currentSample

uint32_t currentSample
protectedinherited

◆ downMs

uint32_t downMs
protectedinherited

◆ downPercent

uint8_t downPercent
protectedinherited

◆ downSamples

uint32_t downSamples
protectedinherited

◆ factor

float factor
protectedinherited

◆ info

AudioInfo info
protectedinherited

◆ is_first

template<class T = int16_t>
bool is_first = true
protected

◆ max_amplitude_step

template<class T = int16_t>
float max_amplitude_step = 50.0f
protected

◆ playMs

uint32_t playMs
protectedinherited

◆ playSamples

uint32_t playSamples
protectedinherited

◆ rampDownDec

float rampDownDec
protectedinherited

◆ rampUpInc

float rampUpInc
protectedinherited

◆ ring_buffer

RingBuffer< uint8_t > ring_buffer
protectedinherited

◆ step

template<class T = int16_t>
float step = 1.0f
protected

◆ step_new

template<class T = int16_t>
float step_new = 1.0f
protected

◆ upMs

uint32_t upMs
protectedinherited

◆ upPercent

uint8_t upPercent
protectedinherited

◆ upSamples

uint32_t upSamples
protectedinherited

◆ values

template<class T = int16_t>
const float values
protected

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