arduino-audio-tools
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 (const uint8_t *buffer, int buffer_size, bool isActive=true, MemoryType memoryType=FLASH_RAM)
 Constructor for data from Progmem, active is set to true automatically by default.
 
 MemoryStream (int buffer_size, MemoryType memoryType)
 Constructor for alloction in RAM.
 
 MemoryStream (MemoryStream &&source)
 Move Constructor.
 
 MemoryStream (MemoryStream &source)
 Copy Constructor.
 
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
 
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_t * data ()
 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)
 Resizes the available memory. Returns false for PROGMEM or when allocation failed.
 
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)
 Automatically rewinds to the beginning when reaching the end. For wav files we move to pos 44 to ignore the header!
 
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)
 
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_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
 
int read_pos = 0
 
void(* rewind )() = nullptr
 
int rewind_pos = 0
 
RingBuffer< uint8_t > tmp_in {0}
 
RingBuffer< uint8_t > tmp_out {0}
 
int write_pos = 0
 

Detailed Description

A simple Stream implementation which is backed by allocated memory.

Author
Phil Schatzmann

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