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

Converts any AudioDecoder to a StreamingDecoder. More...

#include <StreamingDecoder.h>

Inheritance diagram for StreamingDecoderAdapter:
StreamingDecoder AudioInfoSource AudioInfoSupport

Public Member Functions

 StreamingDecoderAdapter (AudioDecoder &decoder, const char *mimeStr, int copySize=DEFAULT_BUFFER_SIZE)
 Constructor.
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
AudioInfo audioInfo () override
 Provides the audio information.
 
virtual AudioInfo audioInfoOut ()
 
bool begin () override
 Starts the processing.
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
virtual bool copy () override
 Process a single read operation - to be called in the loop.
 
bool copyAll ()
 Process all available data.
 
void end () override
 Releases the reserved memory.
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
const char * mime () override
 Provides the MIME type.
 
virtual operator bool () override
 Checks if the class is active.
 
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
void resize (int bufferSize)
 Adjust the buffer size.
 
void setInput (Stream &inStream)
 Stream Interface: Decode directly by taking data from the stream.
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
virtual void setOutput (AudioOutput &out_stream)
 Defines the output streams and register to be notified.
 
virtual void setOutput (AudioStream &out_stream)
 Defines the output streams and register to be notified.
 
void setOutput (Print &out_stream) override
 Defines the output Stream.
 

Protected Member Functions

void notifyAudioChange (AudioInfo info)
 
size_t readBytes (uint8_t *data, size_t len) override
 Reads bytes from the input stream.
 
void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
 

Protected Attributes

Vector< uint8_t > buffer {0}
 Internal buffer for data transfer.
 
AudioInfo info
 
bool is_notify_active = true
 
const char * mime_str = nullptr
 MIME type string.
 
Vector< AudioInfoSupport * > notify_vector
 
AudioDecoderp_decoder = nullptr
 Wrapped AudioDecoder instance.
 
Streamp_input = nullptr
 Input stream for encoded audio data.
 
Printp_print = nullptr
 Output stream for decoded PCM data.
 

Detailed Description

Converts any AudioDecoder to a StreamingDecoder.

This adapter class allows you to use any existing AudioDecoder with the StreamingDecoder interface. It handles the conversion between the write-based AudioDecoder API and the stream-based StreamingDecoder API by using an internal buffer.

Note
The adapter reads data from the input stream into a buffer, then feeds that data to the wrapped AudioDecoder using its write() method.
Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ StreamingDecoderAdapter()

StreamingDecoderAdapter ( AudioDecoder decoder,
const char *  mimeStr,
int  copySize = DEFAULT_BUFFER_SIZE 
)
inline

Constructor.

Parameters
decoderThe AudioDecoder to wrap
mimeStrThe MIME type string for this decoder
copySizeBuffer size for data transfer (default: DEFAULT_BUFFER_SIZE)

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

AudioInfo audioInfo ( )
inlineoverridevirtual

Provides the audio information.

Delegates to the wrapped decoder's audioInfo() method.

Returns
AudioInfo from the wrapped decoder

Implements StreamingDecoder.

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ begin()

bool begin ( )
inlineoverridevirtual

Starts the processing.

Initializes the wrapped decoder.

Returns
true if initialization was successful, false otherwise

Implements StreamingDecoder.

◆ copy()

virtual bool copy ( )
inlineoverridevirtual

Process a single read operation - to be called in the loop.

Reads data from the input stream into the internal buffer, then feeds it to the wrapped AudioDecoder for processing.

Returns
true if data was processed successfully, false otherwise

Implements StreamingDecoder.

◆ copyAll()

bool copyAll ( )
inlineinherited

Process all available data.

Convenience method that calls copy() repeatedly until all available data has been processed.

Returns
true if any data was processed, false if no data was available

◆ end()

void end ( )
inlineoverridevirtual

Releases the reserved memory.

Calls end() on the wrapped decoder to clean up resources.

Implements StreamingDecoder.

◆ mime()

const char * mime ( )
inlineoverridevirtual

Provides the MIME type.

Returns the MIME type that was defined in the constructor.

Returns
MIME type string

Implements StreamingDecoder.

◆ operator bool()

virtual operator bool ( )
inlineoverridevirtual

Checks if the class is active.

Returns
true if the wrapped decoder is active, false otherwise

Implements StreamingDecoder.

◆ readBytes()

size_t readBytes ( uint8_t *  data,
size_t  len 
)
inlineoverrideprotectedvirtual

Reads bytes from the input stream.

Parameters
dataBuffer to store the read data
lenMaximum number of bytes to read
Returns
Number of bytes actually read

Implements StreamingDecoder.

◆ resize()

void resize ( int  bufferSize)
inline

Adjust the buffer size.

Changes the internal buffer size. The existing content of the buffer is lost!

Parameters
bufferSizeNew buffer size in bytes

◆ setAudioInfo()

void setAudioInfo ( AudioInfo  info)
inlineoverrideprotectedvirtualinherited

Defines the input AudioInfo.

Implements AudioInfoSupport.

◆ setInput()

void setInput ( Stream inStream)
inlineinherited

Stream Interface: Decode directly by taking data from the stream.

This is more efficient than feeding the decoder with write: just call copy() in the loop to process data from the input stream.

Parameters
inStreamThe input stream containing encoded audio data

◆ setOutput() [1/3]

virtual void setOutput ( AudioOutput out_stream)
inlinevirtualinherited

Defines the output streams and register to be notified.

Sets the output stream and registers for audio info change notifications.

Parameters
out_streamThe AudioOutput to write decoded audio data to

Reimplemented in MultiStreamingDecoder.

◆ setOutput() [2/3]

virtual void setOutput ( AudioStream out_stream)
inlinevirtualinherited

Defines the output streams and register to be notified.

Sets the output stream and registers for audio info change notifications.

Parameters
out_streamThe AudioStream to write decoded audio data to

Reimplemented in MultiStreamingDecoder.

◆ setOutput() [3/3]

void setOutput ( Print out_stream)
inlineoverridevirtual

Defines the output Stream.

Sets the output stream for the wrapped decoder.

Parameters
out_streamThe output stream for decoded audio data

Reimplemented from StreamingDecoder.


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