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

Adapter class which allows the AudioDecoder API on a StreamingDecoder. More...

#include <StreamingDecoder.h>

Inheritance diagram for DecoderAdapter:
AudioDecoder AudioWriter AudioInfoSource AudioInfoSupport

Public Member Functions

 DecoderAdapter (StreamingDecoder &dec, int bufferSize)
 Constructor.
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 
bool begin () override
 Starts the processing.
 
virtual bool begin (AudioInfo info) override
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
void end () override
 Stops the processing.
 
PrintgetOutput ()
 
StreamingDecodergetStreamingDecoder ()
 Gets the wrapped StreamingDecoder.
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual bool isResultPCM ()
 Returns true to indicate that the decoding result is PCM data.
 
 operator bool () override
 Checks if the adapter is active.
 
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
void resize (int size)
 Resizes the internal buffer.
 
void setAudioInfo (AudioInfo from) override
 for most decoders this is not needed
 
virtual bool setCodecConfig (const uint8_t *data, size_t len)
 Some decoders need e.g. a magic cookie to provide the relevant info for decoding.
 
void setInput (Stream &in)
 Sets the input stream for the wrapped decoder.
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
virtual void setOutput (AudioOutput &out_stream)
 Defines where the decoded result is written to.
 
virtual void setOutput (AudioStream &out_stream)
 Defines where the decoded result is written to.
 
void setOutput (Print &out) override
 Defines the output Stream.
 
size_t write (const uint8_t *data, size_t len) override
 Writes encoded audio data to be decoded.
 

Public Attributes

int id
 custom id to be used by application
 

Protected Member Functions

void notifyAudioChange (AudioInfo info)
 
void setupLazy ()
 Performs lazy initialization of the ring buffer.
 
void writeBlocking (Print *out, uint8_t *data, size_t len)
 

Protected Attributes

bool active = false
 Whether the adapter is active.
 
int buffer_size
 Size of the ring buffer.
 
AudioInfo info
 
bool is_notify_active = true
 
bool is_setup = false
 Whether lazy setup has been performed.
 
Vector< AudioInfoSupport * > notify_vector
 
StreamingDecoderp_dec = nullptr
 Wrapped StreamingDecoder instance.
 
Printp_print = nullptr
 
QueueStream< uint8_t > queue {rbuffer}
 Stream interface to the ring buffer.
 
RingBuffer< uint8_t > rbuffer {0}
 Ring buffer for data storage.
 

Detailed Description

Adapter class which allows the AudioDecoder API on a StreamingDecoder.

This adapter provides the reverse functionality of StreamingDecoderAdapter: it allows you to use a StreamingDecoder with the write-based AudioDecoder API. It uses a ring buffer and queue to convert write() calls into a stream that the StreamingDecoder can read from.

Note
This is useful when you have a StreamingDecoder but need to integrate it into code that expects the AudioDecoder write-based interface.
Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ DecoderAdapter()

DecoderAdapter ( StreamingDecoder dec,
int  bufferSize 
)
inline

Constructor.

Parameters
decThe StreamingDecoder to wrap
bufferSizeSize of the internal ring buffer for data transfer

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

AudioInfo audioInfo ( )
inlineoverridevirtualinherited

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ begin() [1/2]

bool begin ( )
inlineoverridevirtual

Starts the processing.

Initializes the wrapped StreamingDecoder and marks this adapter as active.

Returns
true if the StreamingDecoder was started successfully

Reimplemented from AudioDecoder.

◆ begin() [2/2]

virtual bool begin ( AudioInfo  info)
inlineoverridevirtualinherited

Reimplemented from AudioWriter.

◆ end()

void end ( )
inlineoverridevirtual

Stops the processing.

Marks this adapter as inactive. The wrapped StreamingDecoder is not explicitly stopped to allow continued use.

Reimplemented from AudioDecoder.

◆ getStreamingDecoder()

StreamingDecoder * getStreamingDecoder ( )
inline

Gets the wrapped StreamingDecoder.

Provides direct access to the underlying StreamingDecoder for advanced use cases.

Returns
Pointer to the wrapped StreamingDecoder

◆ isResultPCM()

virtual bool isResultPCM ( )
inlinevirtualinherited

Returns true to indicate that the decoding result is PCM data.

Reimplemented in CopyDecoder, DecoderNetworkFormat, GGWaveDecoder, and ContainerM4A.

◆ operator bool()

operator bool ( )
inlineoverridevirtual

Checks if the adapter is active.

Returns
true if the adapter is active, false otherwise

Implements AudioWriter.

◆ resize()

void resize ( int  size)
inline

Resizes the internal buffer.

Changes the size of the ring buffer used for data transfer. The buffer is only allocated when first needed (lazy setup).

Parameters
sizeNew buffer size in bytes

◆ setAudioInfo()

void setAudioInfo ( AudioInfo  from)
inlineoverridevirtualinherited

for most decoders this is not needed

Implements AudioWriter.

Reimplemented in GGWaveDecoder, DecoderALAC, CodecChain, DSFDecoder, DecoderL8, OpusAudioDecoder, CodecNOP, and G7xxDecoder.

◆ setCodecConfig()

virtual bool setCodecConfig ( const uint8_t *  data,
size_t  len 
)
inlinevirtualinherited

Some decoders need e.g. a magic cookie to provide the relevant info for decoding.

Reimplemented in DecoderALAC, and MultiDecoder.

◆ setInput()

void setInput ( Stream in)
inline

Sets the input stream for the wrapped decoder.

Parameters
inThe input stream containing encoded audio data

◆ setOutput() [1/3]

virtual void setOutput ( AudioOutput out_stream)
inlinevirtualinherited

Defines where the decoded result is written to.

Reimplemented in ADTSDecoder, CodecChain, MTSDecoder, MTSDecoderTSDemux, and MetaDataFilterDecoder.

◆ setOutput() [2/3]

virtual void setOutput ( AudioStream out_stream)
inlinevirtualinherited

Defines where the decoded result is written to.

Reimplemented in ADTSDecoder, CodecChain, MTSDecoder, MTSDecoderTSDemux, and MetaDataFilterDecoder.

◆ setOutput() [3/3]

void setOutput ( Print out)
inlineoverridevirtual

Defines the output Stream.

Sets the output stream for the wrapped StreamingDecoder.

Parameters
outThe output stream for decoded audio data

Reimplemented from AudioDecoder.

◆ setupLazy()

void setupLazy ( )
inlineprotected

Performs lazy initialization of the ring buffer.

The ring buffer is only allocated when first needed to save memory.

◆ write()

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

Writes encoded audio data to be decoded.

The data is written to an internal queue, which is then processed by calling copy() on the wrapped StreamingDecoder.

Parameters
dataBuffer containing encoded audio data
lenNumber of bytes to write
Returns
Number of bytes actually written

Implements AudioWriter.


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