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

A simple Stream implementation which is backed by allocated memory. More...

#include <AudioStreams.h>

Inheritance diagram for MemoryStream:
AudioStream BaseStream AudioInfoSupport AudioInfoSource Stream Print

Public Member Functions

 MemoryStream ()=default
 
 MemoryStream (const uint8_t *buffer, int buffer_size, bool isActive=true, MemoryType memoryType=FLASH_RAM)
 
 MemoryStream (int buffer_size, MemoryType memoryType)
 Constructor for alloction in RAM.
 
 MemoryStream (MemoryStream &&source)
 Move Constructor.
 
 MemoryStream (MemoryStream &source)
 Copy Constructor.
 
 ~MemoryStream ()
 
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 () override
 resets the read pointer
 
bool begin (AudioInfo info)
 Define some audio info and start the processing.
 
virtual void clear (bool reset=false)
 clears the audio data: sets all values to 0
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
virtual uint8_tdata ()
 Provides access to the data array.
 
virtual void end () override
 
virtual void flush () override
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
 operator bool () override
 Returns true if there is still some more data.
 
MemoryStreamoperator= (MemoryStream &other)
 copy assignement operator
 
virtual int peek () override
 
virtual int read () override
 
virtual 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 bool resize (size_t size)
 
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
 
virtual void setAvailable (size_t len)
 update the write_pos (e.g. when we used data() to update the array)
 
virtual void setLoop (bool loop)
 
virtual void setLoop (bool loop, int rewindPos)
 Automatically rewinds to the indicated position when reaching the end.
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
void setRewindCallback (void(*cb)())
 Callback which is executed when we rewind (in loop mode) to the beginning.
 
void setValue (const uint8_t *buffer, int buffer_size, MemoryType memoryType=FLASH_RAM)
 Update the values (buffer and size)
 
void setWriteBufferSize (int size)
 
virtual size_t write (const uint8_t *data, size_t len) override
 
virtual size_t write (uint8_t byte) override
 
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
 

Protected Member Functions

void copy (MemoryStream &source)
 
bool memoryCanChange ()
 
virtual int not_supported (int out, const char *msg="")
 
void notifyAudioChange (AudioInfo info)
 
void refillReadBuffer ()
 

Protected Attributes

int _timeout = 10
 
uint8_tbuffer = nullptr
 
int buffer_size = 0
 
AudioInfo info
 
bool is_active = false
 
bool is_loop = false
 
bool is_notify_active = true
 
MemoryType memory_type = RAM
 
Vector< AudioInfoSupport * > notify_vector
 
bool owns_memory = true
 
int read_pos = 0
 
void(* rewind )() = nullptr
 
int rewind_pos = 0
 
RingBuffer< uint8_ttmp_in {0}
 
RingBuffer< uint8_ttmp_out {0}
 
int write_buffer_size = MAX_SINGLE_CHARS
 
int write_pos = 0
 

Detailed Description

A simple Stream implementation which is backed by allocated memory.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ MemoryStream() [1/5]

MemoryStream ( )
default

◆ MemoryStream() [2/5]

MemoryStream ( int  buffer_size,
MemoryType  memoryType 
)
inline

Constructor for alloction in RAM.

◆ MemoryStream() [3/5]

MemoryStream ( const uint8_t buffer,
int  buffer_size,
bool  isActive = true,
MemoryType  memoryType = FLASH_RAM 
)
inline

Constructor for data from Progmem, active is set to true automatically by default.

◆ MemoryStream() [4/5]

MemoryStream ( MemoryStream source)
inline

Copy Constructor.

◆ MemoryStream() [5/5]

MemoryStream ( MemoryStream &&  source)
inline

Move Constructor.

◆ ~MemoryStream()

~MemoryStream ( )
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 ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ availableForWrite()

virtual int availableForWrite ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ begin() [1/2]

bool begin ( )
inlineoverridevirtual

resets the read pointer

Reimplemented from BaseStream.

◆ begin() [2/2]

bool begin ( AudioInfo  info)
inline

Define some audio info and start the processing.

◆ clear()

virtual void clear ( bool  reset = false)
inlinevirtual

clears the audio data: sets all values to 0

◆ clearNotifyAudioChange()

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ copy()

void copy ( MemoryStream source)
inlineprotected

◆ data()

virtual uint8_t * data ( )
inlinevirtual

Provides access to the data array.

◆ end()

virtual void end ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ flush()

virtual void flush ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ isNotifyActive()

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ memoryCanChange()

bool memoryCanChange ( )
inlineprotected

◆ not_supported()

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

◆ notifyAudioChange()

void notifyAudioChange ( AudioInfo  info)
inlineprotectedinherited

◆ operator bool()

operator bool ( )
inlineoverridevirtual

Returns true if there is still some more data.

Reimplemented from AudioStream.

◆ operator=()

MemoryStream & operator= ( MemoryStream other)
inline

copy assignement operator

◆ peek()

virtual int peek ( )
inlineoverridevirtual

◆ read()

virtual int read ( )
inlineoverridevirtual

◆ readBytes()

virtual 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

◆ removeNotifyAudioChange()

virtual bool removeNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

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

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ resize()

virtual bool resize ( size_t  size)
inlinevirtual

Resizes the available memory. Returns false for PROGMEM or when allocation failed

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfo  info)
inlineoverridevirtualinherited

◆ setAvailable()

virtual void setAvailable ( size_t  len)
inlinevirtual

update the write_pos (e.g. when we used data() to update the array)

◆ setLoop() [1/2]

virtual void setLoop ( bool  loop)
inlinevirtual

Automatically rewinds to the beginning when reaching the end. For wav files we move to pos 44 to ignore the header!

◆ setLoop() [2/2]

virtual void setLoop ( bool  loop,
int  rewindPos 
)
inlinevirtual

Automatically rewinds to the indicated position when reaching the end.

◆ setNotifyActive()

void setNotifyActive ( bool  flag)
inlineinherited

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

◆ setRewindCallback()

void setRewindCallback ( void(*)()  cb)
inline

Callback which is executed when we rewind (in loop mode) to the beginning.

◆ setValue()

void setValue ( const uint8_t buffer,
int  buffer_size,
MemoryType  memoryType = FLASH_RAM 
)
inline

Update the values (buffer and size)

◆ setWriteBufferSize()

void setWriteBufferSize ( int  size)
inlineinherited

◆ write() [1/2]

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

Reimplemented from AudioStream.

◆ write() [2/2]

virtual size_t write ( uint8_t  byte)
inlineoverridevirtual

Reimplemented from BaseStream.

◆ writeSilence()

virtual void writeSilence ( size_t  len)
inlinevirtualinherited

Writes len bytes of silence (=0).

Member Data Documentation

◆ _timeout

int _timeout = 10
protectedinherited

◆ buffer

uint8_t* buffer = nullptr
protected

◆ buffer_size

int buffer_size = 0
protected

◆ info

AudioInfo info
protectedinherited

◆ is_active

bool is_active = false
protected

◆ is_loop

bool is_loop = false
protected

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ memory_type

MemoryType memory_type = RAM
protected

◆ notify_vector

Vector<AudioInfoSupport*> notify_vector
protectedinherited

◆ owns_memory

bool owns_memory = true
protected

◆ read_pos

int read_pos = 0
protected

◆ rewind

void(* rewind) () = nullptr
protected

◆ rewind_pos

int rewind_pos = 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

◆ write_pos

int write_pos = 0
protected

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