arduino-audio-tools
Loading...
Searching...
No Matches
MemoryStream Class Reference

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

#include <CodecOpusOgg.h>

Inheritance diagram for MemoryStream:
AudioStream AudioStream AudioInfoSource AudioInfoSupport BaseStream AudioInfoSource AudioInfoSupport BaseStream AudioInfoSource AudioInfoSupport BaseStream AudioInfoSource AudioInfoSupport BaseStream

Public Member Functions

 MemoryStream ()=default
 MemoryStream ()=default
 MemoryStream (const uint8_t *buffer, int buffer_size, bool isActive=true, MemoryType memoryType=FLASH_RAM)
 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 (int buffer_size, MemoryType memoryType)
 Constructor for alloction in RAM.
 MemoryStream (MemoryStream &&source)
 Move Constructor.
 MemoryStream (MemoryStream &&source)
 Move Constructor.
 MemoryStream (MemoryStream &source)
 Copy Constructor.
 MemoryStream (MemoryStream &source)
 Copy Constructor.
 ~MemoryStream ()
 ~MemoryStream ()
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
virtual AudioInfo audioInfoOut ()
virtual AudioInfo audioInfoOut ()
virtual int available () override
virtual int available () override
virtual int availableForWrite () override
virtual int availableForWrite () override
bool begin () override
 resets the read pointer and write pointer if the memory is changeable
bool begin () override
 resets the read pointer and write pointer if the memory is changeable
bool begin (AudioInfo info)
 Define some audio info and start the processing.
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 clear (bool reset=false)
 clears the audio data: sets all values to 0
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
virtual uint8_t * data ()
 Provides access to the data array.
virtual uint8_t * data ()
 Provides access to the data array.
virtual void end () override
virtual void end () override
virtual void flush () override
virtual void flush () override
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 operator bool () override
 Returns true if there is still some more data.
 operator bool () override
 Returns true if there is still some more data.
MemoryStream & operator= (MemoryStream &other)
 copy assignement operator
MemoryStream & operator= (MemoryStream &other)
 copy assignement operator
virtual int peek () override
virtual int peek () override
virtual int read () override
virtual int read () override
virtual size_t readBytes (uint8_t *data, size_t len) 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 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 removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
virtual bool resize (size_t size)
virtual bool resize (size_t size)
void rewind ()
 Resets the read pointer.
void rewind ()
 Resets the read pointer.
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
virtual bool setAvailable (size_t len)
 update the write_pos (e.g. when we used data() to update the array)
virtual bool 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)
virtual void setLoop (bool loop, int rewindPos)
 Automatically rewinds to the indicated position when reaching the end.
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 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 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 setValue (const uint8_t *buffer, int buffer_size, MemoryType memoryType=FLASH_RAM)
 Update the values (buffer and size).
void setWriteBufferSize (int size)
void setWriteBufferSize (int size)
virtual size_t write (const uint8_t *data, size_t len) override
virtual size_t write (const uint8_t *data, size_t len) override
virtual size_t write (uint8_t byte) override
virtual size_t write (uint8_t byte) override
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).

Protected Member Functions

void copy (MemoryStream &source)
void copy (MemoryStream &source)
bool memoryCanChange ()
bool memoryCanChange ()
virtual int not_supported (int out, const char *msg="")
virtual int not_supported (int out, const char *msg="")
void notifyAudioChange (AudioInfo info)
void notifyAudioChange (AudioInfo info)
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().

Protected Attributes

int _timeout = 10
uint8_t * buffer = 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_cb )() = nullptr
int rewind_pos = 0
RingBuffer< uint8_t > tmp_in {0}
RingBuffer< uint8_t > tmp_out {0}
int write_buffer_size = 8
int write_pos = 0

Detailed Description

A simple Stream implementation which is backed by allocated memory.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ MemoryStream() [1/10]

MemoryStream ( )
default

◆ MemoryStream() [2/10]

MemoryStream ( int buffer_size,
MemoryType memoryType )
inline

Constructor for alloction in RAM.

◆ MemoryStream() [3/10]

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

MemoryStream ( MemoryStream & source)
inline

Copy Constructor.

◆ MemoryStream() [5/10]

MemoryStream ( MemoryStream && source)
inline

Move Constructor.

◆ ~MemoryStream() [1/2]

~MemoryStream ( )
inline

◆ MemoryStream() [6/10]

MemoryStream ( )
default

◆ MemoryStream() [7/10]

MemoryStream ( int buffer_size,
MemoryType memoryType )
inline

Constructor for alloction in RAM.

◆ MemoryStream() [8/10]

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() [9/10]

MemoryStream ( MemoryStream & source)
inline

Copy Constructor.

◆ MemoryStream() [10/10]

MemoryStream ( MemoryStream && source)
inline

Move Constructor.

◆ ~MemoryStream() [2/2]

~MemoryStream ( )
inline

Member Function Documentation

◆ addNotifyAudioChange() [1/2]

virtual void addNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Adds target to be notified about audio changes.

Reimplemented in CodecNOP, CodecNOP, EncodedAudioOutput, and EncodedAudioStream.

◆ addNotifyAudioChange() [2/2]

virtual void addNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Adds target to be notified about audio changes.

Reimplemented in CodecNOP, CodecNOP, EncodedAudioOutput, and EncodedAudioStream.

◆ audioInfo() [1/2]

◆ audioInfo() [2/2]

◆ audioInfoOut() [1/2]

◆ audioInfoOut() [2/2]

◆ available() [1/2]

virtual int available ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ available() [2/2]

virtual int available ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ availableForWrite() [1/2]

virtual int availableForWrite ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ availableForWrite() [2/2]

virtual int availableForWrite ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ begin() [1/4]

bool begin ( )
inlineoverridevirtual

resets the read pointer and write pointer if the memory is changeable

Reimplemented from BaseStream.

◆ begin() [2/4]

bool begin ( )
inlineoverridevirtual

resets the read pointer and write pointer if the memory is changeable

Reimplemented from BaseStream.

◆ begin() [3/4]

bool begin ( AudioInfo info)
inline

Define some audio info and start the processing.

◆ begin() [4/4]

bool begin ( AudioInfo info)
inline

Define some audio info and start the processing.

◆ clear() [1/2]

virtual void clear ( bool reset = false)
inlinevirtual

clears the audio data: sets all values to 0

◆ clear() [2/2]

virtual void clear ( bool reset = false)
inlinevirtual

clears the audio data: sets all values to 0

◆ clearNotifyAudioChange() [1/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ clearNotifyAudioChange() [2/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ copy() [1/2]

void copy ( MemoryStream & source)
inlineprotected

◆ copy() [2/2]

void copy ( MemoryStream & source)
inlineprotected

◆ data() [1/2]

virtual uint8_t * data ( )
inlinevirtual

Provides access to the data array.

◆ data() [2/2]

virtual uint8_t * data ( )
inlinevirtual

Provides access to the data array.

◆ end() [1/2]

virtual void end ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ end() [2/2]

virtual void end ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ flush() [1/2]

virtual void flush ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ flush() [2/2]

virtual void flush ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ isNotifyActive() [1/2]

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ isNotifyActive() [2/2]

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ memoryCanChange() [1/2]

bool memoryCanChange ( )
inlineprotected

◆ memoryCanChange() [2/2]

bool memoryCanChange ( )
inlineprotected

◆ not_supported() [1/2]

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

◆ not_supported() [2/2]

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

◆ notifyAudioChange() [1/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ notifyAudioChange() [2/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ operator bool() [1/2]

operator bool ( )
inlineoverridevirtual

Returns true if there is still some more data.

Reimplemented from AudioStream.

◆ operator bool() [2/2]

operator bool ( )
inlineoverridevirtual

Returns true if there is still some more data.

Reimplemented from AudioStream.

◆ operator=() [1/2]

MemoryStream & operator= ( MemoryStream & other)
inline

copy assignement operator

◆ operator=() [2/2]

MemoryStream & operator= ( MemoryStream & other)
inline

copy assignement operator

◆ peek() [1/2]

virtual int peek ( )
inlineoverridevirtual

◆ peek() [2/2]

virtual int peek ( )
inlineoverridevirtual

◆ read() [1/2]

virtual int read ( )
inlineoverridevirtual

◆ read() [2/2]

virtual int read ( )
inlineoverridevirtual

◆ readBytes() [1/2]

virtual size_t readBytes ( uint8_t * data,
size_t len )
inlineoverridevirtual

Reimplemented from AudioStream.

◆ readBytes() [2/2]

virtual size_t readBytes ( uint8_t * data,
size_t len )
inlineoverridevirtual

Reimplemented from AudioStream.

◆ readSilence() [1/2]

virtual size_t readSilence ( uint8_t * buffer,
size_t length )
inlinevirtualinherited

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

◆ readSilence() [2/2]

virtual size_t readSilence ( uint8_t * buffer,
size_t length )
inlinevirtualinherited

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

◆ refillReadBuffer() [1/2]

void refillReadBuffer ( )
inlineprotectedinherited

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

◆ refillReadBuffer() [2/2]

void refillReadBuffer ( )
inlineprotectedinherited

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

◆ removeNotifyAudioChange() [1/2]

virtual bool removeNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

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

◆ removeNotifyAudioChange() [2/2]

virtual bool removeNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

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

◆ resize() [1/2]

virtual bool resize ( size_t size)
inlinevirtual

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

◆ resize() [2/2]

virtual bool resize ( size_t size)
inlinevirtual

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

◆ rewind() [1/2]

void rewind ( )
inline

Resets the read pointer.

◆ rewind() [2/2]

void rewind ( )
inline

Resets the read pointer.

◆ setAudioInfo() [1/2]

◆ setAudioInfo() [2/2]

◆ setAvailable() [1/2]

virtual bool setAvailable ( size_t len)
inlinevirtual

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

◆ setAvailable() [2/2]

virtual bool setAvailable ( size_t len)
inlinevirtual

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

◆ setLoop() [1/4]

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

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() [3/4]

virtual void setLoop ( bool loop,
int rewindPos )
inlinevirtual

Automatically rewinds to the indicated position when reaching the end.

◆ setLoop() [4/4]

virtual void setLoop ( bool loop,
int rewindPos )
inlinevirtual

Automatically rewinds to the indicated position when reaching the end.

◆ setNotifyActive() [1/2]

void setNotifyActive ( bool flag)
inlineinherited

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

◆ setNotifyActive() [2/2]

void setNotifyActive ( bool flag)
inlineinherited

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

◆ setRewindCallback() [1/2]

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

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

◆ setRewindCallback() [2/2]

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

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

◆ setValue() [1/2]

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

Update the values (buffer and size).

◆ setValue() [2/2]

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

Update the values (buffer and size).

◆ setWriteBufferSize() [1/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ setWriteBufferSize() [2/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ write() [1/4]

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

Reimplemented from AudioStream.

◆ write() [2/4]

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

Reimplemented from AudioStream.

◆ write() [3/4]

virtual size_t write ( uint8_t byte)
inlineoverridevirtual

Reimplemented from BaseStream.

◆ write() [4/4]

virtual size_t write ( uint8_t byte)
inlineoverridevirtual

Reimplemented from BaseStream.

◆ writeSilence() [1/2]

virtual void writeSilence ( size_t len)
inlinevirtualinherited

Writes len bytes of silence (=0).

◆ writeSilence() [2/2]

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_cb

void(* rewind_cb)() = 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 = 8
protectedinherited

◆ write_pos

int write_pos = 0
protected

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