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

A Streaming Decoder where we provide both the input and output as streams. More...

#include <StreamingDecoder.h>

Inheritance diagram for StreamingDecoder:
AudioInfoSource AudioInfoSupport FLACDecoder MultiStreamingDecoder StreamingDecoderAdapter VorbisDecoder

Public Member Functions

virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
virtual AudioInfo audioInfo ()=0
 Provides the audio information for the current stream.
 
virtual AudioInfo audioInfoOut ()
 
virtual bool begin ()=0
 Starts the processing.
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
virtual bool copy ()=0
 Process a single read operation - to be called in the loop.
 
bool copyAll ()
 Process all available data.
 
virtual void end ()=0
 Releases the reserved memory.
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual const char * mime ()=0
 Provides the MIME type of the audio format handled by this decoder.
 
virtual operator bool ()=0
 Checks if the class is active.
 
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
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.
 
virtual void setOutput (Print &out_stream)
 Defines the output Stream.
 

Protected Member Functions

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

Protected Attributes

AudioInfo info
 
bool is_notify_active = true
 
Vector< AudioInfoSupport * > notify_vector
 
Streamp_input = nullptr
 Input stream for encoded audio data.
 
Printp_print = nullptr
 Output stream for decoded PCM data.
 

Detailed Description

A Streaming Decoder where we provide both the input and output as streams.

This is the base class for all streaming decoders that process audio data by reading from an input stream and writing decoded PCM data to an output stream. Unlike AudioDecoder which uses a write-based interface, StreamingDecoder uses a pull-based approach where you call copy() to process data.

Note
This is more efficient than the write-based AudioDecoder interface for streaming scenarios where you have direct access to input and output streams.
Author
Phil Schatzmann

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
pure virtual

Provides the audio information for the current stream.

Returns audio format information such as sample rate, channels, and bits per sample that was determined from the decoded audio stream.

Returns
AudioInfo structure containing format information

Implements AudioInfoSupport.

Implemented in FLACDecoder, VorbisDecoder, StreamingDecoderAdapter, and MultiStreamingDecoder.

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ begin()

virtual bool begin ( )
pure virtual

Starts the processing.

Initializes the decoder and prepares it for processing audio data. Must be called before any copy() operations.

Returns
true if initialization was successful, false otherwise

Implemented in FLACDecoder, VorbisDecoder, StreamingDecoderAdapter, and MultiStreamingDecoder.

◆ copy()

virtual bool copy ( )
pure virtual

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

Reads a chunk of data from the input stream, decodes it, and writes the decoded PCM data to the output stream.

Returns
true if data was processed successfully, false if no more data is available or an error occurred

Implemented in FLACDecoder, VorbisDecoder, StreamingDecoderAdapter, and MultiStreamingDecoder.

◆ copyAll()

bool copyAll ( )
inline

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()

virtual void end ( )
pure virtual

Releases the reserved memory.

Cleans up any resources allocated by the decoder and stops processing.

Implemented in FLACDecoder, VorbisDecoder, StreamingDecoderAdapter, and MultiStreamingDecoder.

◆ mime()

virtual const char * mime ( )
pure virtual

Provides the MIME type of the audio format handled by this decoder.

Returns
C-string containing the MIME type (e.g., "audio/mpeg", "audio/flac")

Implemented in FLACDecoder, VorbisDecoder, StreamingDecoderAdapter, and MultiStreamingDecoder.

◆ operator bool()

virtual operator bool ( )
pure virtual

Checks if the class is active.

Returns
true if the decoder is ready and active, false otherwise

Implemented in FLACDecoder, VorbisDecoder, StreamingDecoderAdapter, and MultiStreamingDecoder.

◆ readBytes()

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

Reads bytes from the input stream.

Derived classes must implement this to read data from their input source.

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

Implemented in FLACDecoder, VorbisDecoder, StreamingDecoderAdapter, and MultiStreamingDecoder.

◆ setAudioInfo()

void setAudioInfo ( AudioInfo  info)
inlineoverrideprotectedvirtual

Defines the input AudioInfo.

Implements AudioInfoSupport.

◆ setInput()

void setInput ( Stream inStream)
inline

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)
inlinevirtual

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)
inlinevirtual

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]

virtual void setOutput ( Print out_stream)
inlinevirtual

Defines the output Stream.

Sets where the decoded PCM audio data will be written to.

Parameters
out_streamThe Print stream to write decoded audio data to

Reimplemented in StreamingDecoderAdapter, and MultiStreamingDecoder.


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