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

Generates a Sound with the help of sin() function. If performance is of concern, I suggest to use theSineFromTable, the FastSineGenerator or the FastIntSineGenerator. More...

#include <CodecOpusOgg.h>

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

Public Member Functions

 FloatSineGenerator (float amplitude=NumberConverter::maxValueT< T >(), float phase=0.0f)
 FloatSineGenerator (float amplitude=NumberConverter::maxValueT< T >(), float phase=0.0f)
virtual AudioInfo audioInfo ()
 Provides the AudioInfo.
bool begin () override
bool begin () override
bool begin (AudioInfo info) override
 Starts the processing with the provided AudioInfo.
bool begin (AudioInfo info) override
 Starts the processing with the provided AudioInfo.
bool begin (AudioInfo info, float frequency)
bool begin (AudioInfo info, float frequency)
bool begin (int channels, int sample_rate, float frequency)
bool begin (int channels, int sample_rate, float frequency)
virtual AudioInfo defaultConfig () override
 Provides the default configuration.
virtual AudioInfo defaultConfig () override
 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.
virtual T readSample () override
 Provides a single sample.
virtual T readSample () override
 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 amp)
void setAmplitude (float amp)
virtual void setAudioInfo (AudioInfo info) override
 Defines/updates the AudioInfo.
virtual void setAudioInfo (AudioInfo info) override
 Defines/updates the AudioInfo.
void setFrequency (float frequency) override
 Defines the frequency - after the processing has been started.
void setFrequency (float frequency) override
 Defines the frequency - after the processing has been started.
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)
void logStatus ()
void logStatus ()
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 ()

Protected Attributes

bool active
bool activeWarningIssued
uint32_t currentSample
const float double_Pi = 2.0f * 3.14159265359f
uint32_t downMs
uint8_t downPercent
uint32_t downSamples
float factor
AudioInfo info
float m_amplitude = 1.0f
float m_cycles = 0.0f
float m_deltaTime = 0.0f
volatile float m_frequency = 0.0f
float m_phase = 0.0f
uint32_t playMs
uint32_t playSamples
float rampDownDec
float rampUpInc
RingBuffer< uint8_t > ring_buffer
uint32_t upMs
uint8_t upPercent
uint32_t upSamples

Detailed Description

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

Generates a Sound with the help of sin() function. If performance is of concern, I suggest to use theSineFromTable, the FastSineGenerator or the FastIntSineGenerator.

Note
Prefer SineGenerator instead of using this class directly: it automatically picks this (float) or FastIntSineGenerator, whichever is optimal for the target platform (see PREFER_FIXEDPOINT).
Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ FloatSineGenerator() [1/2]

template<class T = int16_t>
FloatSineGenerator ( float amplitude = NumberConverter::maxValueT<T>(),
float phase = 0.0f )
inline

◆ FloatSineGenerator() [2/2]

template<class T = int16_t>
FloatSineGenerator ( float amplitude = NumberConverter::maxValueT<T>(),
float phase = 0.0f )
inline

Member Function Documentation

◆ applyRamp()

int16_t applyRamp ( int16_t sample)
inlineprotectedinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlinevirtualinherited

Provides the AudioInfo.

◆ begin() [1/8]

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

◆ begin() [2/8]

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

◆ begin() [3/8]

template<class T = int16_t>
bool begin ( AudioInfo info)
inlineoverridevirtual

Starts the processing with the provided AudioInfo.

Reimplemented from SoundGenerator< int16_t >.

◆ begin() [4/8]

template<class T = int16_t>
bool begin ( AudioInfo info)
inlineoverridevirtual

Starts the processing with the provided AudioInfo.

Reimplemented from SoundGenerator< int16_t >.

◆ begin() [5/8]

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

◆ begin() [6/8]

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

◆ begin() [7/8]

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

◆ begin() [8/8]

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

◆ defaultConfig() [1/2]

template<class T = int16_t>
virtual AudioInfo defaultConfig ( )
inlineoverridevirtual

Provides the default configuration.

Reimplemented from SoundGenerator< int16_t >.

◆ defaultConfig() [2/2]

template<class T = int16_t>
virtual AudioInfo defaultConfig ( )
inlineoverridevirtual

Provides the default configuration.

Reimplemented from SoundGenerator< int16_t >.

◆ end()

◆ isActive()

virtual bool isActive ( )
inlinevirtualinherited

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

◆ logStatus() [1/2]

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

◆ logStatus() [2/2]

template<class T = int16_t>
void logStatus ( )
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>
virtual T readSample ( )
inlineoverridevirtual

Provides a single sample.

Implements SoundGenerator< int16_t >.

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

◆ readSample() [2/2]

template<class T = int16_t>
virtual T readSample ( )
inlineoverridevirtual

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 amp)
inline

◆ setAmplitude() [2/2]

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

◆ setAudioInfo() [1/2]

template<class T = int16_t>
virtual void setAudioInfo ( AudioInfo info)
inlineoverridevirtual

Defines/updates the AudioInfo.

Reimplemented from SoundGenerator< int16_t >.

◆ setAudioInfo() [2/2]

template<class T = int16_t>
virtual void setAudioInfo ( AudioInfo info)
inlineoverridevirtual

Defines/updates the AudioInfo.

Reimplemented from SoundGenerator< int16_t >.

◆ setFrequency() [1/2]

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

Defines the frequency - after the processing has been started.

Reimplemented from SoundGenerator< int16_t >.

◆ setFrequency() [2/2]

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

Defines the frequency - after the processing has been started.

Reimplemented from SoundGenerator< int16_t >.

◆ 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.

Member Data Documentation

◆ active

bool active
protectedinherited

◆ activeWarningIssued

bool activeWarningIssued
protectedinherited

◆ currentSample

uint32_t currentSample
protectedinherited

◆ double_Pi

template<class T = int16_t>
const float double_Pi = 2.0f * 3.14159265359f
protected

◆ downMs

uint32_t downMs
protectedinherited

◆ downPercent

uint8_t downPercent
protectedinherited

◆ downSamples

uint32_t downSamples
protectedinherited

◆ factor

float factor
protectedinherited

◆ info

AudioInfo info
protectedinherited

◆ m_amplitude

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

◆ m_cycles

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

◆ m_deltaTime

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

◆ m_frequency

template<class T = int16_t>
volatile float m_frequency = 0.0f
protected

◆ m_phase

template<class T = int16_t>
float m_phase = 0.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

◆ upMs

uint32_t upMs
protectedinherited

◆ upPercent

uint8_t upPercent
protectedinherited

◆ upSamples

uint32_t upSamples
protectedinherited

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