arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AudioTimeSourceStream Class Reference

AudioTimeSourceStream: A stream that provides time information based on the audio data actually processed - implements the TimeSource interface. millis() (inherited, unmodified) is plain wall time; playbackTime() is the audio-derived progress, which is what a consumer that must stay tied to genuine playback (e.g. PacedVideoOutput) should use instead - see playbackTime()'s own comment for why they can diverge. More...

#include <AudioIO.h>

Inheritance diagram for AudioTimeSourceStream:
AudioStream TimeSource BaseStream AudioInfoSupport AudioInfoSource Stream Print

Public Member Functions

 AudioTimeSourceStream ()=default
 
 AudioTimeSourceStream (AudioOutput &out)
 
 AudioTimeSourceStream (AudioStream &stream)
 
 AudioTimeSourceStream (Print &print)
 
 AudioTimeSourceStream (Stream &stream)
 
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 ()
 
virtual int available () override
 
virtual int availableForWrite () override
 
bool begin ()
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
virtual void end ()
 
virtual void flush () override
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual uint32_t millis ()
 
virtual operator bool ()
 
uint32_t playbackTime () 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.
 
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
void setOutput (AudioOutput &out)
 
void setOutput (Print &out)
 
void setStream (AudioStream &stream)
 
void setStream (Stream &stream)
 
void setTimeCallback (void(*cb)(uint32_t time_ms))
 Defines a callback function to be called whenever the time is updated.
 
void setTimeCallbackAfter (void(*cb)(uint32_t time_ms))
 Defines a callback function to be called whenever the time is updated.
 
void setWriteBufferSize (int size)
 
size_t write (const uint8_t *data, size_t len) override
 
virtual size_t write (uint8_t ch) override
 
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
 

Protected Member Functions

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()
 
void resetTime ()
 
void updateTime (size_t bytes)
 

Protected Attributes

int _timeout = 10
 
AudioInfo info
 
bool is_notify_active = true
 
Vector< AudioInfoSupport * > notify_vector
 
Printp_out = nullptr
 
Streamp_stream = nullptr
 
uint32_t playback_time_ms = 0
 
void(* time_callback_after )(uint32_t time_ms) = nullptr
 
void(* time_callback_before )(uint32_t time_ms) = nullptr
 
RingBuffer< uint8_t > tmp_in {0}
 
RingBuffer< uint8_t > tmp_out {0}
 
int write_buffer_size = MAX_SINGLE_CHARS
 

Detailed Description

AudioTimeSourceStream: A stream that provides time information based on the audio data actually processed - implements the TimeSource interface. millis() (inherited, unmodified) is plain wall time; playbackTime() is the audio-derived progress, which is what a consumer that must stay tied to genuine playback (e.g. PacedVideoOutput) should use instead - see playbackTime()'s own comment for why they can diverge.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ AudioTimeSourceStream() [1/5]

AudioTimeSourceStream ( )
default

◆ AudioTimeSourceStream() [2/5]

AudioTimeSourceStream ( AudioStream stream)
inline

◆ AudioTimeSourceStream() [3/5]

◆ AudioTimeSourceStream() [4/5]

AudioTimeSourceStream ( Print print)
inline

◆ AudioTimeSourceStream() [5/5]

AudioTimeSourceStream ( Stream stream)
inline

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlineoverridevirtualinherited

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ available()

virtual int available ( )
inlineoverridevirtualinherited

◆ availableForWrite()

virtual int availableForWrite ( )
inlineoverridevirtualinherited

◆ begin()

bool begin ( )
inlinevirtual

Optional: explicitly (re)starts playbackTime() at 0 - use this if you need an explicit restart point (e.g. looping/seeking). Not required otherwise: the first byte that actually flows through write()/readBytes() anchors it on its own (see updateTime()) - most callers just wire this in as a plain Print/AudioStream target (e.g. PacedVideoOutput::setAudioClock()'s usage pattern) and never call begin() on it directly.

Reimplemented from BaseStream.

◆ clearNotifyAudioChange()

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ end()

virtual void end ( )
inlinevirtualinherited

◆ flush()

virtual void flush ( )
inlineoverridevirtualinherited

◆ isNotifyActive()

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ millis()

virtual uint32_t millis ( )
inlinevirtualinherited

Wall-clock elapsed time (ms) - real time passing, regardless of whatever this TimeSource actually tracks. The default implementation just forwards to Arduino's own millis(); override only if this TimeSource needs a different wall-clock source - most subclasses should leave this alone and override playbackTime() instead.

◆ not_supported()

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

◆ notifyAudioChange()

void notifyAudioChange ( AudioInfo  info)
inlineprotectedinherited

◆ operator bool()

virtual operator bool ( )
inlinevirtualinherited

◆ playbackTime()

uint32_t playbackTime ( )
inlineoverridevirtual

Elapsed playback time (ms): the sum of audio duration (sample_rate/channels/bits_per_sample-derived) actually handed to write()/readBytes() so far - see TimeSource::playbackTime(). Purely a running total of processed bytes: never extrapolated by, or otherwise dependent on, wall-clock time (see millis(), inherited unmodified, for that) - so it stalls exactly when the caller stalls (e.g. busy elsewhere in a shared demux/decode loop) instead of continuing to advance. Returns 0 before the first byte has ever been processed (begin() is optional - see its own comment).

Reimplemented from TimeSource.

◆ readBytes()

size_t readBytes ( uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

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

◆ resetTime()

void resetTime ( )
inlineprotected

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfo  info)
inlineoverridevirtualinherited

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

◆ setStream() [1/2]

void setStream ( AudioStream stream)
inline

◆ setStream() [2/2]

void setStream ( Stream stream)
inline

◆ setTimeCallback()

void setTimeCallback ( void(*)(uint32_t time_ms)  cb)
inline

Defines a callback function to be called whenever the time is updated.

◆ setTimeCallbackAfter()

void setTimeCallbackAfter ( void(*)(uint32_t time_ms)  cb)
inline

Defines a callback function to be called whenever the time is updated.

◆ setWriteBufferSize()

void setWriteBufferSize ( int  size)
inlineinherited

◆ updateTime()

void updateTime ( size_t  bytes)
inlineprotected

◆ write() [1/2]

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

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

◆ info

AudioInfo info
protectedinherited

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ notify_vector

Vector<AudioInfoSupport*> notify_vector
protectedinherited

◆ p_out

Print* p_out = nullptr
protected

◆ p_stream

Stream* p_stream = nullptr
protected

◆ playback_time_ms

uint32_t playback_time_ms = 0
protected

◆ time_callback_after

void(* time_callback_after) (uint32_t time_ms) = nullptr
protected

◆ time_callback_before

void(* time_callback_before) (uint32_t time_ms) = nullptr
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: