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

We generate the samples from an array which is provided in the constructor. More...

#include <CodecOpusOgg.h>

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

Public Member Functions

 GeneratorFromArray ()=default
 GeneratorFromArray ()=default
template<size_t arrayLen>
 GeneratorFromArray (T(&array)[arrayLen], int repeat=0, bool setInactiveAtEnd=false, size_t startIndex=0)
 Construct a new Generator from an array.
template<size_t arrayLen>
 GeneratorFromArray (T(&array)[arrayLen], int repeat=0, bool setInactiveAtEnd=false, size_t startIndex=0)
 Construct a new Generator from an array.
virtual AudioInfo audioInfo ()
 Provides the AudioInfo.
bool begin () override
 Starts the generation of samples.
bool begin () override
 Starts the generation of samples.
bool begin (AudioInfo info) override
 Starts the generation of samples with the provided AudioInfo.
bool begin (AudioInfo info) override
 Starts the generation of samples with the provided AudioInfo.
bool begin (AudioInfo info, float frequency)
 Starts the generation of samples with the provided AudioInfo and frequency.
bool begin (AudioInfo info, float frequency)
 Starts the generation of samples with the provided AudioInfo and frequency.
virtual AudioInfo defaultConfig ()
 Provides the default configuration.
void end () override
void end () override
virtual bool isActive ()
 Checks if the begin method has been called - after end() isActive is false.
bool isRunning ()
bool isRunning ()
virtual size_t readBytes (uint8_t *data, size_t len)
 Provides the data as byte array with the requested number of channels.
T readSample () override
 Provides a single sample.
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 setArray (T *array, size_t size)
void setArray (T *array, size_t size)
template<int arrayLen>
void setArray (T(&array)[arrayLen])
template<int arrayLen>
void setArray (T(&array)[arrayLen])
virtual void setAudioInfo (AudioInfo info)
 Defines/updates the AudioInfo.
void setFrequency (float frequency) override
 Defines the output frequency based on sample rate and table size.
void setFrequency (float frequency) override
 Defines the output frequency based on sample rate and table size.
void setIncrement (int inc)
void setIncrement (int inc)
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)
int setupSine (int sampleRate, float reqFrequency, float amplitude=1.0)
int setupSine (int sampleRate, float reqFrequency, float amplitude=1.0)

Protected Member Functions

int16_t applyRamp (int16_t sample)
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
uint32_t downMs
uint8_t downPercent
uint32_t downSamples
float factor
float frequency = 0.0f
bool inactive_at_end = false
float index_increment = 1.0f
AudioInfo info
bool is_running = false
int max_repeat = 0
bool owns_data = false
uint32_t playMs
uint32_t playSamples
float rampDownDec
float rampUpInc
int repeat_counter = 0
RingBuffer< uint8_t > ring_buffer
float sound_index = 0.0f
Vector< T > table
uint32_t upMs
uint8_t upPercent
uint32_t upSamples

Detailed Description

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

We generate the samples from an array which is provided in the constructor.

Author
Phil Schatzmann
Template Parameters
T

Constructor & Destructor Documentation

◆ GeneratorFromArray() [1/4]

template<class T = int16_t>
GeneratorFromArray ( )
default

◆ GeneratorFromArray() [2/4]

template<class T = int16_t>
template<size_t arrayLen>
GeneratorFromArray ( T(&) array[arrayLen],
int repeat = 0,
bool setInactiveAtEnd = false,
size_t startIndex = 0 )
inline

Construct a new Generator from an array.

Template Parameters
arrayarray of audio data of the the type defined as class template parameter
Parameters
repeatnumber of repetions the array should be played, set to 0 for endless repeat. (default 0)
setInactiveAtEnddefines if the generator is set inactive when the array has played fully. Default is false.
startIndexdefines if the phase. Default is 0.

◆ GeneratorFromArray() [3/4]

template<class T = int16_t>
GeneratorFromArray ( )
default

◆ GeneratorFromArray() [4/4]

template<class T = int16_t>
template<size_t arrayLen>
GeneratorFromArray ( T(&) array[arrayLen],
int repeat = 0,
bool setInactiveAtEnd = false,
size_t startIndex = 0 )
inline

Construct a new Generator from an array.

Template Parameters
arrayarray of audio data of the the type defined as class template parameter
Parameters
repeatnumber of repetions the array should be played, set to 0 for endless repeat. (default 0)
setInactiveAtEnddefines if the generator is set inactive when the array has played fully. Default is false.
startIndexdefines if the phase. Default is 0.

Member Function Documentation

◆ applyRamp()

int16_t applyRamp ( int16_t sample)
inlineprotectedinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlinevirtualinherited

Provides the AudioInfo.

◆ begin() [1/6]

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

Starts the generation of samples.

◆ begin() [2/6]

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

Starts the generation of samples.

◆ begin() [3/6]

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

Starts the generation of samples with the provided AudioInfo.

Reimplemented from SoundGenerator< int16_t >.

◆ begin() [4/6]

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

Starts the generation of samples with the provided AudioInfo.

Reimplemented from SoundGenerator< int16_t >.

◆ begin() [5/6]

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

Starts the generation of samples with the provided AudioInfo and frequency.

◆ begin() [6/6]

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

Starts the generation of samples with the provided AudioInfo and frequency.

◆ defaultConfig()

◆ end() [1/2]

template<class T = int16_t>
void end ( )
inlineoverridevirtual

Reimplemented from SoundGenerator< int16_t >.

◆ end() [2/2]

template<class T = int16_t>
void end ( )
inlineoverridevirtual

Reimplemented from SoundGenerator< int16_t >.

◆ isActive()

virtual bool isActive ( )
inlinevirtualinherited

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

◆ isRunning() [1/2]

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

◆ isRunning() [2/2]

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

◆ 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 ( )
inlineoverridevirtual

Provides a single sample.

Implements SoundGenerator< int16_t >.

◆ readSample() [2/2]

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

◆ setArray() [1/4]

template<class T = int16_t>
void setArray ( T * array,
size_t size )
inline

◆ setArray() [2/4]

template<class T = int16_t>
void setArray ( T * array,
size_t size )
inline

◆ setArray() [3/4]

template<class T = int16_t>
template<int arrayLen>
void setArray ( T(&) array[arrayLen])
inline

◆ setArray() [4/4]

template<class T = int16_t>
template<int arrayLen>
void setArray ( T(&) array[arrayLen])
inline

◆ setAudioInfo()

◆ setFrequency() [1/2]

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

Defines the output frequency based on sample rate and table size.

Reimplemented from SoundGenerator< int16_t >.

◆ setFrequency() [2/2]

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

Defines the output frequency based on sample rate and table size.

Reimplemented from SoundGenerator< int16_t >.

◆ setIncrement() [1/2]

template<class T = int16_t>
void setIncrement ( int inc)
inline

◆ setIncrement() [2/2]

template<class T = int16_t>
void setIncrement ( int inc)
inline

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

◆ setupSine() [1/2]

template<class T = int16_t>
int setupSine ( int sampleRate,
float reqFrequency,
float amplitude = 1.0 )
inline

◆ setupSine() [2/2]

template<class T = int16_t>
int setupSine ( int sampleRate,
float reqFrequency,
float amplitude = 1.0 )
inline

Member Data Documentation

◆ active

bool active
protectedinherited

◆ activeWarningIssued

bool activeWarningIssued
protectedinherited

◆ currentSample

uint32_t currentSample
protectedinherited

◆ downMs

uint32_t downMs
protectedinherited

◆ downPercent

uint8_t downPercent
protectedinherited

◆ downSamples

uint32_t downSamples
protectedinherited

◆ factor

float factor
protectedinherited

◆ frequency

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

◆ inactive_at_end

template<class T = int16_t>
bool inactive_at_end = false
protected

◆ index_increment

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

◆ info

AudioInfo info
protectedinherited

◆ is_running

template<class T = int16_t>
bool is_running = false
protected

◆ max_repeat

template<class T = int16_t>
int max_repeat = 0
protected

◆ owns_data

template<class T = int16_t>
bool owns_data = false
protected

◆ playMs

uint32_t playMs
protectedinherited

◆ playSamples

uint32_t playSamples
protectedinherited

◆ rampDownDec

float rampDownDec
protectedinherited

◆ rampUpInc

float rampUpInc
protectedinherited

◆ repeat_counter

template<class T = int16_t>
int repeat_counter = 0
protected

◆ ring_buffer

RingBuffer< uint8_t > ring_buffer
protectedinherited

◆ sound_index

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

◆ table

template<class T = int16_t>
Vector< T > table
protected

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