arduino-audio-tools
Loading...
Searching...
No Matches
TimedStream Class Reference

AudioStream class that can define a start and (an optional) stop time Usually it is used to wrap an Audio Sink (e.g. I2SStream), but wrapping an Audio Source is supported as well. Only wrap classes which represent PCM data! More...

#include <AudioIO.h>

Inheritance diagram for TimedStream:
ModifyingStream AudioStream AudioStream AudioInfoSource AudioInfoSupport BaseStream AudioInfoSource AudioInfoSupport BaseStream AudioInfoSource AudioInfoSupport BaseStream AudioInfoSource AudioInfoSupport BaseStream

Public Member Functions

 TimedStream ()=default
 TimedStream (AudioOutput &o, long startSeconds=0, long endSeconds=-1)
 TimedStream (AudioStream &io, long startSeconds=0, long endSeconds=-1)
 TimedStream (Print &o, long startSeconds=0, long endSeconds=-1)
 TimedStream (Stream &io, long startSeconds=0, long endSeconds=-1)
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
virtual AudioInfo audioInfoOut ()
virtual AudioInfo audioInfoOut ()
int available () override
 Provides the available bytes until the end time has reached.
int availableForWrite () override
bool begin () override
bool begin (AudioInfo info)
int bytesPerSecond ()
 Calculates the bytes per second from the AudioInfo.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
virtual void end ()
virtual void end ()
void flush () override
bool isActive ()
 Returns true if we are not past the end time;.
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
bool isPlaying ()
 Returns true if we are in a valid time range and are still playing sound.
 operator bool () override
size_t readBytes (uint8_t *data, size_t len) override
virtual size_t readSilence (uint8_t *buffer, size_t length)
 Source to generate silence: just sets the buffer to 0.
virtual size_t readSilence (uint8_t *buffer, size_t length)
 Source to generate silence: just sets the buffer to 0.
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
void setAudioInfo (AudioInfo info) override
 Updates the AudioInfo in the current object and in the source or target.
void setCompressionRatio (float ratio)
void setEndMs (uint32_t ms)
 Defines the (optional) end time in milliseconds.
void setEndSec (uint32_t endSeconds)
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active).
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active).
virtual void setOutput (AudioOutput &out)
 Defines/Changes the output target and registers for audio change notifications.
void setOutput (AudioOutput &out)
void setOutput (Print &out) override
 Defines/Changes the output target.
void setStartMs (uint32_t ms)
 Defines the start time in milliseconds.
void setStartSec (uint32_t startSeconds)
virtual void setStream (AudioStream &io)
 Defines/Changes the input & output and registers for audio change notifications.
void setStream (AudioOutput &out)
void setStream (AudioStream &stream)
void setStream (Stream &stream) override
 Defines/Changes the input & output.
void setWriteBufferSize (int size)
void setWriteBufferSize (int size)
size_t size ()
virtual size_t write (uint8_t ch) override
size_t write (const uint8_t *data, size_t len) override
 Plays only data for the indiated start and end time.
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).

Protected Member Functions

void calculateByteLimits ()
void consumeBytes (uint32_t len)
virtual int not_supported (int out, const char *msg="")
virtual int not_supported (int out, const char *msg="")
void notifyAudioChange (AudioInfo info)
void notifyAudioChange (AudioInfo info)
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().

Protected Attributes

int _timeout = 10
float compression_ratio = 1.0
uint32_t current_bytes = 0
uint32_t end_bytes = UINT32_MAX
uint32_t end_ms = UINT32_MAX
AudioInfo info
bool is_notify_active = true
Vector< AudioInfoSupport * > notify_vector
AudioInfoSupport * p_info = nullptr
Stream * p_io = nullptr
Print * p_out = nullptr
uint32_t start_bytes = 0
uint32_t start_ms = 0
RingBuffer< uint8_t > tmp_in {0}
RingBuffer< uint8_t > tmp_out {0}
int write_buffer_size = 8

Detailed Description

AudioStream class that can define a start and (an optional) stop time Usually it is used to wrap an Audio Sink (e.g. I2SStream), but wrapping an Audio Source is supported as well. Only wrap classes which represent PCM data!

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ TimedStream() [1/5]

TimedStream ( )
default

◆ TimedStream() [2/5]

TimedStream ( AudioStream & io,
long startSeconds = 0,
long endSeconds = -1 )
inline

◆ TimedStream() [3/5]

TimedStream ( AudioOutput & o,
long startSeconds = 0,
long endSeconds = -1 )
inline

◆ TimedStream() [4/5]

TimedStream ( Stream & io,
long startSeconds = 0,
long endSeconds = -1 )
inline

◆ TimedStream() [5/5]

TimedStream ( Print & o,
long startSeconds = 0,
long endSeconds = -1 )
inline

Member Function Documentation

◆ addNotifyAudioChange() [1/2]

virtual void addNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Adds target to be notified about audio changes.

Reimplemented in CodecNOP, CodecNOP, EncodedAudioOutput, and EncodedAudioStream.

◆ addNotifyAudioChange() [2/2]

virtual void addNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Adds target to be notified about audio changes.

Reimplemented in CodecNOP, CodecNOP, EncodedAudioOutput, and EncodedAudioStream.

◆ audioInfo() [1/2]

◆ audioInfo() [2/2]

◆ audioInfoOut() [1/2]

◆ audioInfoOut() [2/2]

◆ available()

int available ( )
inlineoverridevirtual

Provides the available bytes until the end time has reached.

Reimplemented from BaseStream.

◆ availableForWrite()

int availableForWrite ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ begin() [1/2]

bool begin ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ begin() [2/2]

bool begin ( AudioInfo info)
inline

◆ bytesPerSecond()

int bytesPerSecond ( )
inline

Calculates the bytes per second from the AudioInfo.

◆ calculateByteLimits()

void calculateByteLimits ( )
inlineprotected

◆ clearNotifyAudioChange() [1/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ clearNotifyAudioChange() [2/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ consumeBytes()

void consumeBytes ( uint32_t len)
inlineprotected

◆ end() [1/2]

virtual void end ( )
inlinevirtualinherited

Reimplemented in A2DPStream, AbstractURLStream, AdapterAudioOutputToAudioStream, AdaptiveResamplingStream, AnalogAudioStream, AdapterAudioOutputToAudioStream, AudioStreamWrapper, AudioStreamWrapper, CallbackStream, CallbackStream, CatStream, CatStream, DynamicMemoryStream, DynamicMemoryStream, EncodedAudioStream, FilteredStream< T, TF >, FilteredStream< T, TF >, FilteredStream< int16_t, int16_t >, GeneratedSoundStream< T >, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, InputMerge< T >, InputMerge< T >, InputMixer< T, SumT >, InputMixer< T, SumT >, MemoryStream, MemoryStream, QueueStream< T >, QueueStream< T >, QueueStream< uint8_t >, ReformatBaseStream, TimerCallbackAudioStream, TimerCallbackAudioStream, AudioBLEClient, AudioBLEClient, AudioBLEServer, AudioBLEServer, AudioBLEStream, AudioEffectStream, AudioEffectStreamT< T >, AudioFFTBase, AudioKitStream, AudioLoRa, AudioMP34DT05, AudioStreamWrapper, AutomaticGainControlStream, BufferedTaskStream, CallbackStream, CatStream, ChannelFormatConverterStream, DynamicMemoryStream, EncodedAudioStream, Equalizer3BandsPerChannelT< T >, Equalizer3BandsPerChannelT< float >, Equalizer3BandsT< T >, Equalizer3BandsT< float >, EqualizerNBands< SampleT, AccT, NUM_TAPS, NUM_BANDS >, ESPNowStream, FaustStream< DSP >, FileLoopT< FileType >, FileLoopT< File >, FilteredStream< T, TF >, FormatConverterStream, GeneratedSoundStream< T >, GoertzelStream, HLSStreamT< URLStream >, HLSStreamT< URLStreamESP32 >, HttpRequest, I2SCodecStream, I2SStream, ICYStreamT< T >, ICYStreamT< URLStream >, ICYStreamT< URLStreamESP32 >, InputMerge< T >, InputMixer< T, SumT >, MemoryStream, MiniAudioStream, MozziStream, NRF24Stream, NumberFormatConverterStream, Pipeline, Pipeline::ModifyingStreamAdapter, PortAudioStream, PureDataStream, QueueStream< T >, ReformatBaseStream, SPDIFOutput, SPIAudioSlave, StdioStream, SupportedRatesStream, TimerCallbackAudioStream, URLStream, URLStreamBufferedT< T >, URLStreamBufferedT< ICYStream >, URLStreamBufferedT< ICYStreamESP32 >, URLStreamBufferedT< URLStream >, URLStreamBufferedT< URLStreamESP32 >, URLStreamESP32, USBAudioDeviceBase, USBAudioHostBase, VolumeStream, VS1053Stream, and WM8960Stream.

◆ end() [2/2]

virtual void end ( )
inlinevirtualinherited

Reimplemented in A2DPStream, AbstractURLStream, AdapterAudioOutputToAudioStream, AdaptiveResamplingStream, AnalogAudioStream, AdapterAudioOutputToAudioStream, AudioStreamWrapper, AudioStreamWrapper, CallbackStream, CallbackStream, CatStream, CatStream, DynamicMemoryStream, DynamicMemoryStream, EncodedAudioStream, FilteredStream< T, TF >, FilteredStream< T, TF >, FilteredStream< int16_t, int16_t >, GeneratedSoundStream< T >, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, InputMerge< T >, InputMerge< T >, InputMixer< T, SumT >, InputMixer< T, SumT >, MemoryStream, MemoryStream, QueueStream< T >, QueueStream< T >, QueueStream< uint8_t >, ReformatBaseStream, TimerCallbackAudioStream, TimerCallbackAudioStream, AudioBLEClient, AudioBLEClient, AudioBLEServer, AudioBLEServer, AudioBLEStream, AudioEffectStream, AudioEffectStreamT< T >, AudioFFTBase, AudioKitStream, AudioLoRa, AudioMP34DT05, AudioStreamWrapper, AutomaticGainControlStream, BufferedTaskStream, CallbackStream, CatStream, ChannelFormatConverterStream, DynamicMemoryStream, EncodedAudioStream, Equalizer3BandsPerChannelT< T >, Equalizer3BandsPerChannelT< float >, Equalizer3BandsT< T >, Equalizer3BandsT< float >, EqualizerNBands< SampleT, AccT, NUM_TAPS, NUM_BANDS >, ESPNowStream, FaustStream< DSP >, FileLoopT< FileType >, FileLoopT< File >, FilteredStream< T, TF >, FormatConverterStream, GeneratedSoundStream< T >, GoertzelStream, HLSStreamT< URLStream >, HLSStreamT< URLStreamESP32 >, HttpRequest, I2SCodecStream, I2SStream, ICYStreamT< T >, ICYStreamT< URLStream >, ICYStreamT< URLStreamESP32 >, InputMerge< T >, InputMixer< T, SumT >, MemoryStream, MiniAudioStream, MozziStream, NRF24Stream, NumberFormatConverterStream, Pipeline, Pipeline::ModifyingStreamAdapter, PortAudioStream, PureDataStream, QueueStream< T >, ReformatBaseStream, SPDIFOutput, SPIAudioSlave, StdioStream, SupportedRatesStream, TimerCallbackAudioStream, URLStream, URLStreamBufferedT< T >, URLStreamBufferedT< ICYStream >, URLStreamBufferedT< ICYStreamESP32 >, URLStreamBufferedT< URLStream >, URLStreamBufferedT< URLStreamESP32 >, URLStreamESP32, USBAudioDeviceBase, USBAudioHostBase, VolumeStream, VS1053Stream, and WM8960Stream.

◆ flush()

void flush ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ isActive()

bool isActive ( )
inline

Returns true if we are not past the end time;.

◆ isNotifyActive() [1/2]

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ isNotifyActive() [2/2]

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ isPlaying()

bool isPlaying ( )
inline

Returns true if we are in a valid time range and are still playing sound.

◆ not_supported() [1/2]

virtual int not_supported ( int out,
const char * msg = "" )
inlineprotectedvirtualinherited

◆ not_supported() [2/2]

virtual int not_supported ( int out,
const char * msg = "" )
inlineprotectedvirtualinherited

◆ notifyAudioChange() [1/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ notifyAudioChange() [2/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ operator bool()

operator bool ( )
inlineoverridevirtual

Reimplemented from AudioStream.

◆ readBytes()

size_t readBytes ( uint8_t * data,
size_t len )
inlineoverridevirtual

Provides only data for the indicated start and end time. Only supported for data which does not contain any heder information: so PCM, mp3 should work!

Reimplemented from AudioStream.

◆ readSilence() [1/2]

virtual size_t readSilence ( uint8_t * buffer,
size_t length )
inlinevirtualinherited

Source to generate silence: just sets the buffer to 0.

◆ readSilence() [2/2]

virtual size_t readSilence ( uint8_t * buffer,
size_t length )
inlinevirtualinherited

Source to generate silence: just sets the buffer to 0.

◆ refillReadBuffer() [1/2]

void refillReadBuffer ( )
inlineprotectedinherited

Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().

◆ refillReadBuffer() [2/2]

void refillReadBuffer ( )
inlineprotectedinherited

Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().

◆ removeNotifyAudioChange() [1/2]

virtual bool removeNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Removes a target in order not to be notified about audio changes.

◆ removeNotifyAudioChange() [2/2]

virtual bool removeNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Removes a target in order not to be notified about audio changes.

◆ setAudioInfo() [1/2]

◆ setAudioInfo() [2/2]

void setAudioInfo ( AudioInfo info)
inlineoverride

Updates the AudioInfo in the current object and in the source or target.

◆ setCompressionRatio()

void setCompressionRatio ( float ratio)
inline

Experimental: if used on mp3 you can set the compression ratio e.g. to 11 which will be used to approximate the time

◆ setEndMs()

void setEndMs ( uint32_t ms)
inline

Defines the (optional) end time in milliseconds.

◆ setEndSec()

void setEndSec ( uint32_t endSeconds)
inline

Defines (an optional) the end time in seconds. After the end time no audio is played and available() will return 0

◆ setNotifyActive() [1/2]

void setNotifyActive ( bool flag)
inlineinherited

Deactivate/Reactivate automatic AudioInfo updates: (default is active).

◆ setNotifyActive() [2/2]

void setNotifyActive ( bool flag)
inlineinherited

Deactivate/Reactivate automatic AudioInfo updates: (default is active).

◆ setOutput() [1/3]

virtual void setOutput ( AudioOutput & out)
inlinevirtualinherited

Defines/Changes the output target and registers for audio change notifications.

Reimplemented in AudioInputMonitor, AudioInputMonitor, EncodedAudioStream, ReformatBaseStream, TimedStream, VolumeMeter, and VolumeMeter.

◆ setOutput() [2/3]

void setOutput ( AudioOutput & out)
inline

◆ setOutput() [3/3]

void setOutput ( Print & out)
inlineoverridevirtual

Defines/Changes the output target.

Implements ModifyingStream.

◆ setStartMs()

void setStartMs ( uint32_t ms)
inline

Defines the start time in milliseconds.

◆ setStartSec()

void setStartSec ( uint32_t startSeconds)
inline

Defines the start time in seconds. The audio before the start time will be skipped

◆ setStream() [1/4]

virtual void setStream ( AudioStream & io)
inlinevirtualinherited

Defines/Changes the input & output and registers for audio change notifications.

Reimplemented in AudioInputMonitor, AudioInputMonitor, EncodedAudioStream, ReformatBaseStream, TimedStream, VolumeMeter, and VolumeMeter.

◆ setStream() [2/4]

void setStream ( AudioOutput & out)
inline

◆ setStream() [3/4]

void setStream ( AudioStream & stream)
inline

◆ setStream() [4/4]

void setStream ( Stream & in)
inlineoverridevirtual

Defines/Changes the input & output.

Implements ModifyingStream.

◆ setWriteBufferSize() [1/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ setWriteBufferSize() [2/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ size()

size_t size ( )
inline

◆ write() [1/2]

◆ write() [2/2]

size_t write ( const uint8_t * data,
size_t len )
inlineoverridevirtual

Plays only data for the indiated start and end time.

Reimplemented from AudioStream.

◆ writeSilence() [1/2]

virtual void writeSilence ( size_t len)
inlinevirtualinherited

Writes len bytes of silence (=0).

◆ writeSilence() [2/2]

virtual void writeSilence ( size_t len)
inlinevirtualinherited

Writes len bytes of silence (=0).

Member Data Documentation

◆ _timeout

int _timeout = 10
protectedinherited

◆ compression_ratio

float compression_ratio = 1.0
protected

◆ current_bytes

uint32_t current_bytes = 0
protected

◆ end_bytes

uint32_t end_bytes = UINT32_MAX
protected

◆ end_ms

uint32_t end_ms = UINT32_MAX
protected

◆ info

AudioInfo info
protectedinherited

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ notify_vector

Vector< AudioInfoSupport * > notify_vector
protectedinherited

◆ p_info

AudioInfoSupport* p_info = nullptr
protected

◆ p_io

Stream* p_io = nullptr
protected

◆ p_out

Print* p_out = nullptr
protected

◆ start_bytes

uint32_t start_bytes = 0
protected

◆ start_ms

uint32_t start_ms = 0
protected

◆ tmp_in

RingBuffer< uint8_t > tmp_in {0}
protectedinherited

◆ tmp_out

RingBuffer< uint8_t > tmp_out {0}
protectedinherited

◆ write_buffer_size

int write_buffer_size = 8
protectedinherited

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