arduino-audio-tools
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 (AudioOutput &o, long startSeconds=0, long endSeconds=-1)
 
 TimedStream (AudioStream &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 ()
 provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
 
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 ()
 
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)
 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)
 Defines/Changes the input & output.
 
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 ()
 

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_t > tmp_in {0}
 
RingBuffer< uint8_t > tmp_out {0}
 

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

Member Function Documentation

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

◆ 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

◆ 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

◆ setStartSec()

void setStartSec ( uint32_t  startSeconds)
inline

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


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