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

An Adapter Class which lets you use any Stream as a Generator. More...

#include <CodecOpusOgg.h>

Inheritance diagram for GeneratorFromStream< T >:
SoundGenerator< int16_t > VolumeSupport SoundGenerator< int16_t > VolumeSupport

Public Member Functions

 GeneratorFromStream ()
 GeneratorFromStream ()
 GeneratorFromStream (Stream &input, int channels=1, float volume=1.0)
 Constructs a new Generator from a Stream object that can be used e.g. as input for AudioEffectss.
 GeneratorFromStream (Stream &input, int channels=1, float volume=1.0)
 Constructs a new Generator from a Stream object that can be used e.g. as input for AudioEffectss.
virtual AudioInfo audioInfo ()
 Provides the AudioInfo.
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 from the stream.
T readSample ()
 Provides a single sample from the stream.
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.
virtual void setAudioInfo (AudioInfo info)
 Defines/updates the AudioInfo.
void setChannels (int channels)
void setChannels (int channels)
virtual void setFrequency (float frequency)
 Abstract method: not implemented! Just provides an error message...
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)
void setStream (Stream &input)
 (Re-)Assigns a stream to the Adapter class
void setStream (Stream &input)
 (Re-)Assigns a stream to the Adapter class
virtual bool setVolume (float volume)
 define the actual volume in the range of 0.0f to 1.0f
virtual bool setVolume (float volume)
 define the actual volume in the range of 0.0f to 1.0f
virtual float volume ()
 provides the actual volume in the range of 0.0f to 1.0f
virtual float volume ()
 provides the actual volume in the range of 0.0f to 1.0f

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
int channels = 1
uint32_t currentSample
uint32_t downMs
uint8_t downPercent
uint32_t downSamples
float factor
AudioInfo info
float maxValue
Stream * p_stream = nullptr
uint32_t playMs
uint32_t playSamples
float rampDownDec
float rampUpInc
RingBuffer< uint8_t > ring_buffer
uint32_t upMs
uint8_t upPercent
uint32_t upSamples
float volume_value = 1.0f

Detailed Description

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

An Adapter Class which lets you use any Stream as a Generator.

Author
Phil Schatzmann
Template Parameters
T

Constructor & Destructor Documentation

◆ GeneratorFromStream() [1/4]

template<class T = int16_t>
GeneratorFromStream ( )
inline

◆ GeneratorFromStream() [2/4]

template<class T = int16_t>
GeneratorFromStream ( Stream & input,
int channels = 1,
float volume = 1.0 )
inline

Constructs a new Generator from a Stream object that can be used e.g. as input for AudioEffectss.

Parameters
inputStream
channelsnumber of channels of the Stream
volumefactor my which the sample value is multiplied - default 1.0; Use it e.g. to reduce the volume (e.g. with 0.5)

◆ GeneratorFromStream() [3/4]

template<class T = int16_t>
GeneratorFromStream ( )
inline

◆ GeneratorFromStream() [4/4]

template<class T = int16_t>
GeneratorFromStream ( Stream & input,
int channels = 1,
float volume = 1.0 )
inline

Constructs a new Generator from a Stream object that can be used e.g. as input for AudioEffectss.

Parameters
inputStream
channelsnumber of channels of the Stream
volumefactor my which the sample value is multiplied - default 1.0; Use it e.g. to reduce the volume (e.g. with 0.5)

Member Function Documentation

◆ applyRamp()

int16_t applyRamp ( int16_t sample)
inlineprotectedinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlinevirtualinherited

Provides the AudioInfo.

◆ begin()

◆ defaultConfig()

◆ end()

◆ isActive()

virtual bool isActive ( )
inlinevirtualinherited

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

◆ 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 from the stream.

Implements SoundGenerator< int16_t >.

◆ readSample() [2/2]

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

Provides a single sample from the stream.

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.

◆ setAudioInfo()

◆ setChannels() [1/2]

template<class T = int16_t>
void setChannels ( int channels)
inline

◆ setChannels() [2/2]

template<class T = int16_t>
void setChannels ( int channels)
inline

◆ setFrequency()

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

◆ setStream() [1/2]

template<class T = int16_t>
void setStream ( Stream & input)
inline

(Re-)Assigns a stream to the Adapter class

◆ setStream() [2/2]

template<class T = int16_t>
void setStream ( Stream & input)
inline

(Re-)Assigns a stream to the Adapter class

◆ setVolume() [1/2]

virtual bool setVolume ( float volume)
inlinevirtualinherited

define the actual volume in the range of 0.0f to 1.0f

Reimplemented in A2DPStream, AudioPlayer, Boost, I2SCodecStream, Maximilian, USBAudioStreamBase, VolumeStream, and VS1053Stream.

◆ setVolume() [2/2]

virtual bool setVolume ( float volume)
inlinevirtualinherited

define the actual volume in the range of 0.0f to 1.0f

Reimplemented in A2DPStream, AudioPlayer, Boost, I2SCodecStream, Maximilian, USBAudioStreamBase, VolumeStream, and VS1053Stream.

◆ volume() [1/2]

virtual float volume ( )
inlinevirtualinherited

provides the actual volume in the range of 0.0f to 1.0f

Reimplemented in AudioPlayer, I2SCodecStream, USBAudioStreamBase, VolumeStream, and VS1053Stream.

◆ volume() [2/2]

virtual float volume ( )
inlinevirtualinherited

provides the actual volume in the range of 0.0f to 1.0f

Reimplemented in AudioPlayer, I2SCodecStream, USBAudioStreamBase, VolumeStream, and VS1053Stream.

Member Data Documentation

◆ active

bool active
protectedinherited

◆ activeWarningIssued

bool activeWarningIssued
protectedinherited

◆ channels

template<class T = int16_t>
int channels = 1
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

◆ maxValue

template<class T = int16_t>
float maxValue
protected

◆ p_stream

template<class T = int16_t>
Stream * p_stream = nullptr
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

◆ volume_value

float volume_value = 1.0f
protectedinherited

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