arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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 BaseStream AudioInfoSupport AudioInfoSource Stream Print

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 AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
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 end ()
 
virtual 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 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 bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
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 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)
 
void setStream (AudioOutput &out)
 
void setStream (AudioStream &stream)
 
void setStream (Stream &stream) override
 Defines/Changes the input & output.
 
void setWriteBufferSize (int size)
 
size_t size ()
 
size_t write (const uint8_t *data, size_t len) override
 Plays only data for the indiated start and end time.
 
virtual size_t write (uint8_t ch) override
 
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="")
 
void notifyAudioChange (AudioInfo info)
 
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
 
AudioInfoSupportp_info = nullptr
 
Printp_print = nullptr
 
Streamp_stream = nullptr
 
uint32_t start_bytes = 0
 
uint32_t start_ms = 0
 
RingBuffer< uint8_ttmp_in {0}
 
RingBuffer< uint8_ttmp_out {0}
 
int write_buffer_size = MAX_SINGLE_CHARS
 

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

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlineoverridevirtualinherited

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

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

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ consumeBytes()

void consumeBytes ( uint32_t  len)
inlineprotected

◆ end()

virtual void end ( )
inlinevirtualinherited

◆ flush()

virtual void flush ( )
inlineoverridevirtualinherited

◆ isActive()

bool isActive ( )
inline

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

◆ isNotifyActive()

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

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

◆ notifyAudioChange()

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

virtual size_t readSilence ( uint8_t buffer,
size_t  length 
)
inlinevirtualinherited

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

◆ refillReadBuffer()

void refillReadBuffer ( )
inlineprotectedinherited

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

◆ removeNotifyAudioChange()

virtual bool removeNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

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

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ setAudioInfo()

void setAudioInfo ( AudioInfo  info)
inlineoverridevirtual

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

Reimplemented from AudioStream.

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

void setNotifyActive ( bool  flag)
inlineinherited

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

◆ setOutput() [1/2]

void setOutput ( AudioOutput out)
inline

◆ setOutput() [2/2]

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/3]

void setStream ( AudioOutput out)
inline

◆ setStream() [2/3]

void setStream ( AudioStream stream)
inline

◆ setStream() [3/3]

void setStream ( Stream in)
inlineoverridevirtual

Defines/Changes the input & output.

Implements ModifyingStream.

◆ setWriteBufferSize()

void setWriteBufferSize ( int  size)
inlineinherited

◆ size()

size_t size ( )
inline

◆ write() [1/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.

◆ write() [2/2]

virtual size_t write ( uint8_t  ch)
inlineoverridevirtualinherited

◆ writeSilence()

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_print

Print* p_print = nullptr
protected

◆ p_stream

Stream* p_stream = 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 = MAX_SINGLE_CHARS
protectedinherited

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