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

Vorbis Streaming Decoder using https://github.com/pschatzmann/arduino-libvorbis-tremor. More...

#include <CodecVorbis.h>

Inheritance diagram for VorbisDecoder:
StreamingDecoder AudioDecoder AudioInfoSource AudioInfoSupport AudioWriter AudioInfoSource AudioInfoSupport

Public Member Functions

 VorbisDecoder (size_t buffer_size=256, int header_packets=3)
 Constructor for VorbisDecoder.
 
 ~VorbisDecoder ()
 Destroy the VorbisDecoder object.
 
 ~VorbisDecoder ()
 Destructor for VorbisDecoder.
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
AudioInfo audioInfo () override
 Provides the last available MP3FrameInfo.
 
AudioInfo audioInfo () override
 Returns audio stream info (sample rate, channels, bits per sample)
 
virtual AudioInfo audioInfoOut ()
 
bool begin () override
 Starts the processing.
 
bool begin () override
 Resets decoder state and prepares for new Vorbis stream.
 
virtual bool begin (AudioInfo info) override
 
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.
 
void end () override
 Cleans up all Vorbis decoder structures.
 
PrintgetOutput ()
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual bool isResultPCM ()
 Returns true to indicate that the decoding result is PCM data.
 
const char * mime () override
 Provides "audio/ogg".
 
virtual operator bool () override
 checks if the class is active
 
 operator bool () override
 Returns true if decoder is active.
 
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
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 setDelayOnNoData (size_t delay)
 Defines the delay when there is no data.
 
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)
 
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 (AudioOutput &out_stream)
 Defines the output streams and register to be notified.
 
virtual void setOutput (AudioStream &out_stream)
 Defines where the decoded result is written to.
 
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.
 
virtual void setOutput (Print &out_stream) override
 Defines where the decoded result is written to.
 
void setReadSize (size_t size)
 Defines the default read size.
 
void setWaitForData (size_t wait)
 Defines the delay to wait if there is not enough data to open the decoder.
 
size_t write (const uint8_t *data, size_t len) override
 Feeds a Vorbis packet (header or audio) to the decoder.
 

Public Attributes

int id
 custom id to be used by application
 

Protected Member Functions

void convertFloatToInt16PCM (float **pcm, int samples, int channels)
 Converts float PCM to interleaved int16 PCM and stores in pcmout_buffer.
 
AudioInfo currentInfo ()
 
size_t decodeAudioPacket (ogg_packet &packet)
 Decodes an audio packet and writes PCM to output.
 
const char * getOpenError (int error)
 
bool initDecoder ()
 Initializes the Vorbis decoder after header parsing.
 
void notifyAudioChange (AudioInfo info)
 
void notifyAudioChange (AudioInfo info)
 
bool ovOpen ()
 
bool parseHeaderPacket (ogg_packet &packet, int header_packets)
 Parses a Vorbis header packet.
 
virtual size_t readBytes (uint8_t *data, size_t len) override
 Reads bytes from the input stream.
 
const char * readError (long error)
 
void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
 
void writeBlocking (Print *out, uint8_t *data, size_t len)
 

Static Protected Member Functions

static size_t read_func (void *ptr, size_t size, size_t nmemb, void *datasource)
 
static int seek_func (void *datasource, ogg_int64_t offset, int whence)
 
static long tell_func (void *datasource)
 

Protected Attributes

bool active = false
 Decoder active state.
 
int bitstream = 0
 
ov_callbacks callbacks
 
AudioInfo cfg
 
bool decoder_initialized = false
 
size_t delay_on_no_data_ms = 100
 
size_t delay_wait_for_data_ms = 500
 
OggVorbis_File file
 
int header_packets = 0
 
AudioInfo info
 
AudioInfo info
 
bool is_first = true
 
bool is_notify_active = true
 
bool is_notify_active = true
 
bool is_ov_open = false
 
size_t max_read_size = 1024
 
Vector< AudioInfoSupport * > notify_vector
 
Vector< AudioInfoSupport * > notify_vector
 
int num_header_packets = 3
 Number of Vorbis header packets.
 
Streamp_input = nullptr
 Input stream for encoded audio data.
 
Printp_print = nullptr
 Output stream for PCM audio.
 
Vector< uint8_t > pcm {0}
 
size_t pcm_buffer_size = 256
 PCM output buffer size.
 
Vector< int16_t > pcmout_buffer
 Buffer for interleaved PCM output.
 
vorbis_block vb {}
 Block structure for synthesis.
 
vorbis_comment vc {}
 Vorbis comment metadata.
 
vorbis_dsp_state vd {}
 Decoder state for synthesis.
 
vorbis_info vi {}
 Vorbis stream info (channels, sample rate, etc.)
 

Detailed Description

Vorbis Streaming Decoder using https://github.com/pschatzmann/arduino-libvorbis-tremor.

Vorbis Audio Decoder using low-level libvorbis API.

Author
Phil Schatzmann

This decoder expects Ogg Vorbis packets to be provided via the write() method. It parses the Vorbis headers, initializes the decoder, and outputs PCM audio.

Usage:

  1. Call begin() to reset the decoder.
  2. Feed the first three Vorbis header packets via write().
  3. Feed subsequent audio packets via write().
  4. Use setOutput() to set the PCM output destination.
  5. Call audioInfo() to retrieve stream parameters after header parsing.
Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ VorbisDecoder()

VorbisDecoder ( size_t  buffer_size = 256,
int  header_packets = 3 
)
inline

Constructor for VorbisDecoder.

Parameters
buffer_sizeSize of the PCM output buffer (default: 256)
header_packetsNumber of Vorbis header packets (default: 3)

Initializes the decoder and allocates the PCM output buffer.

◆ ~VorbisDecoder()

~VorbisDecoder ( )
inline

Destructor for VorbisDecoder.

Cleans up all decoder resources.

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo() [1/2]

AudioInfo audioInfo ( )
inlineoverridevirtual

Provides the last available MP3FrameInfo.

Implements StreamingDecoder.

◆ audioInfo() [2/2]

AudioInfo audioInfo ( )
inlineoverridevirtual

Returns audio stream info (sample rate, channels, bits per sample)

Returns
AudioInfo struct with stream parameters

Implements StreamingDecoder.

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ begin() [1/3]

bool begin ( )
inlineoverridevirtual

Starts the processing.

Implements StreamingDecoder.

◆ begin() [2/3]

bool begin ( )
inlineoverridevirtual

Resets decoder state and prepares for new Vorbis stream.

This method clears all decoder state, resizes the PCM output buffer, and initializes Vorbis structures. Call this before feeding header packets.

Returns
true if successful

Implements StreamingDecoder.

◆ begin() [3/3]

virtual bool begin ( AudioInfo  info)
inlineoverridevirtualinherited

Reimplemented from AudioWriter.

◆ convertFloatToInt16PCM()

void convertFloatToInt16PCM ( float **  pcm,
int  samples,
int  channels 
)
inlineprotected

Converts float PCM to interleaved int16 PCM and stores in pcmout_buffer.

Parameters
pcmPointer to float PCM array [channels][samples]
samplesNumber of samples
channelsNumber of channels

◆ copy()

virtual bool copy ( )
inlineoverridevirtual

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

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

◆ decodeAudioPacket()

size_t decodeAudioPacket ( ogg_packet &  packet)
inlineprotected

Decodes an audio packet and writes PCM to output.

Parameters
packetOgg Vorbis audio packet
Returns
Number of PCM bytes written

◆ end() [1/2]

void end ( )
inlineoverridevirtual

Releases the reserved memory.

Implements StreamingDecoder.

◆ end() [2/2]

void end ( )
inlineoverridevirtual

Cleans up all Vorbis decoder structures.

Implements StreamingDecoder.

◆ initDecoder()

bool initDecoder ( )
inlineprotected

Initializes the Vorbis decoder after header parsing.

Returns
true if successful

◆ isResultPCM()

virtual bool isResultPCM ( )
inlinevirtualinherited

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

Reimplemented in CopyDecoder, DecoderNetworkFormat, GGWaveDecoder, and ContainerM4A.

◆ mime()

const char * mime ( )
inlineoverridevirtual

Provides "audio/ogg".

Implements StreamingDecoder.

◆ operator bool() [1/2]

virtual operator bool ( )
inlineoverridevirtual

checks if the class is active

Implements StreamingDecoder.

◆ operator bool() [2/2]

operator bool ( )
inlineoverridevirtual

Returns true if decoder is active.

Implements StreamingDecoder.

◆ parseHeaderPacket()

bool parseHeaderPacket ( ogg_packet &  packet,
int  header_packets 
)
inlineprotected

Parses a Vorbis header packet.

Parameters
packetOgg Vorbis header packet
header_packetsIndex of header packet (0, 1, 2)
Returns
true if successful

◆ readBytes()

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

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

Implements StreamingDecoder.

◆ setAudioInfo() [1/2]

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.

◆ setAudioInfo() [2/2]

void setAudioInfo ( AudioInfo  info)
inlineoverrideprotectedvirtualinherited

Defines the input AudioInfo.

Implements AudioInfoSupport.

◆ 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 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/6]

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

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

virtual void setOutput ( AudioStream out_stream)
inlinevirtualinherited

Defines where the decoded result is written to.

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

◆ setOutput() [4/6]

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() [5/6]

virtual void setOutput ( Print out_stream)
inlinevirtualinherited

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.

◆ setOutput() [6/6]

virtual void setOutput ( Print out_stream)
inlineoverridevirtualinherited

◆ write()

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

Feeds a Vorbis packet (header or audio) to the decoder.

The first three packets must be Vorbis headers. Subsequent packets are audio. PCM output is written to the Print stream set via setOutput().

Parameters
dataPointer to packet data
lenLength of packet data
Returns
Number of PCM bytes written to output

Implements AudioWriter.


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