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

The Arduino Stream supports operations on single characters. This is usually not the best way to push audio information, but we will support it anyway - by using a buffer. On reads: if the buffer is empty it gets refilled. More...

#include <AudioStreams.h>

Inheritance diagram for BufferedStream:
ModifyingStream AudioStream BaseStream AudioInfoSupport AudioInfoSource Stream Print AudioOutputWithCallback TimerCallbackAudioStream

Public Member Functions

 BufferedStream (Print &out, size_t buffer_size=1024)
 
 BufferedStream (size_t buffer_size)
 
 BufferedStream (size_t buffer_size, Print &out)
 
 BufferedStream (size_t buffer_size, Stream &io)
 
 BufferedStream (Stream &io, size_t buffer_size=1024)
 
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
 Returns the available bytes.
 
virtual int availableForWrite () override
 
virtual bool begin ()
 
void clear ()
 Clears all the data in the buffer.
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
virtual void end ()
 
void flush () override
 empties the buffer
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual operator bool ()
 
int peek () override
 peeks a byte - to be avoided
 
size_t peekBytes (uint8_t *data, size_t len)
 Provides data w/o consuming.
 
int read () override
 reads a byte - to be avoided
 
size_t readBytes (uint8_t *data, size_t len) override
 Use this method !!
 
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 resize (int size)
 Resize the buffer.
 
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
 
void setMinUnbufferedReadSize (size_t size)
 Defines the minimum direct unbuffered read size to the original source (default is 1024)
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
void setOutput (Print &out) override
 Defines/Changes the output target.
 
void setStream (Print &out)
 
void setStream (Stream &io) override
 Defines/Changes the input & output.
 
void setWriteBufferSize (int size)
 
size_t write (const uint8_t *data, size_t len) override
 Use this method: write an array.
 
size_t write (uint8_t c) override
 writes a byte to the buffer
 
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)
 
virtual size_t readExt (uint8_t *data, size_t len)
 
void refill ()
 refills the buffer with data from the source
 
void refill (size_t len)
 refill only if not enough data
 
void refillReadBuffer ()
 
virtual size_t writeExt (const uint8_t *data, size_t len)
 

Protected Attributes

int _timeout = 10
 
SingleBuffer< uint8_t > buffer {0}
 
AudioInfo info
 
bool is_notify_active = true
 
size_t minReadBufferSize = 1024
 
Vector< AudioInfoSupport * > notify_vector
 
Streamp_in = nullptr
 
Printp_out = nullptr
 
RingBuffer< uint8_t > tmp_in {0}
 
RingBuffer< uint8_t > tmp_out {0}
 
int write_buffer_size = MAX_SINGLE_CHARS
 

Detailed Description

The Arduino Stream supports operations on single characters. This is usually not the best way to push audio information, but we will support it anyway - by using a buffer. On reads: if the buffer is empty it gets refilled.

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlineoverridevirtualinherited

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ available()

int available ( )
inlineoverridevirtual

Returns the available bytes.

Reimplemented from BaseStream.

◆ availableForWrite()

virtual int availableForWrite ( )
inlineoverridevirtualinherited

◆ begin()

virtual bool begin ( )
inlinevirtualinherited

◆ end()

virtual void end ( )
inlinevirtualinherited

◆ flush()

void flush ( )
inlineoverridevirtual

empties the buffer

Reimplemented from BaseStream.

◆ operator bool()

virtual operator bool ( )
inlinevirtualinherited

◆ readBytes()

size_t readBytes ( uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

Use this method !!

Reimplemented from AudioStream.

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfo  info)
inlineoverridevirtualinherited

◆ setOutput()

void setOutput ( Print out)
inlineoverridevirtual

Defines/Changes the output target.

Implements ModifyingStream.

◆ setStream()

void setStream ( Stream in)
inlineoverridevirtual

Defines/Changes the input & output.

Implements ModifyingStream.

◆ write() [1/2]

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

Use this method: write an array.

Reimplemented from AudioStream.

◆ write() [2/2]

size_t write ( uint8_t  c)
inlineoverridevirtual

writes a byte to the buffer

Reimplemented from BaseStream.


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