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

A simple WAVDecoder: We parse the header data on the first record to determine the format. If no AudioDecoderExt is specified we just write the PCM data to the output that is defined by calling setOutput(). You can define a ADPCM decoder to decode WAV files that contain ADPCM data. More...

#include <CodecWAV.h>

Inheritance diagram for WAVDecoder:
AudioDecoder AudioWriter AudioInfoSource AudioInfoSupport

Public Member Functions

 WAVDecoder ()=default
 Construct a new WAVDecoder object for PCM data.
 
 WAVDecoder (AudioDecoderExt &dec, AudioFormat fmt)
 Construct a new WAVDecoder object for ADPCM data.
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
AudioInfo audioInfo () override
 Exposed AudioInfo (may reflect conversion flags)
 
WAVAudioInfoaudioInfoEx ()
 Extended WAV specific info (original header values)
 
virtual AudioInfo audioInfoOut ()
 
bool begin () override
 Prepare decoder for a new WAV stream.
 
virtual bool begin (AudioInfo info) override
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
void end () override
 Finish decoding and release temporary buffers.
 
PrintgetOutput ()
 
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 charmime ()
 Provides MIME type "audio/wav".
 
virtual operator bool () override
 Check if the 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 setConvert24Bit (bool enable)
 Convert 24 bit (3 byte) to 32 bit (4 byte) PCM data (default: enabled)
 
void setConvert8Bit (bool enable)
 Convert 8 bit to 16 bit PCM data (default: enabled)
 
void setDecoder (AudioDecoderExt &dec, AudioFormat fmt)
 Defines an optional decoder if the format is not PCM.
 
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_stream) override
 Defines the output Stream.
 
virtual size_t write (const uint8_t *data, size_t len) override
 Write incoming WAV data (header + PCM) into output.
 

Public Attributes

int id
 custom id to be used by application
 

Protected Member Functions

int decodeHeader (uint8_t *in_ptr, size_t in_size)
 Decodes the header data: Returns the start pos of the data.
 
void notifyAudioChange (AudioInfo info)
 
Printout ()
 
void setupEncodedAudio ()
 
virtual size_t write_out (const uint8_t *in_ptr, size_t in_size)
 
size_t write_out_24 (const uint8_t *in_ptr, size_t in_size)
 convert 3 byte int24 to 4 byte int32
 
size_t write_out_8to16 (const uint8_t *in_ptr, size_t in_size)
 Convert 8-bit PCM to 16-bit PCM and write out.
 
void writeBlocking (Print *out, uint8_t *data, size_t len)
 

Protected Attributes

bool active = false
 
const size_t batch_size = 256
 
SingleBuffer< int32_tbuffer24 {0}
 
SingleBuffer< uint8_tbyte_buffer {0}
 
bool convert24 = true
 
bool convert8to16 = true
 
EncodedAudioOutput dec_out
 
AudioFormat decoder_format = AudioFormat::PCM
 
WAVHeader header
 
AudioInfo info
 
bool is_notify_active = true
 
bool isFirst = true
 
bool isValid = true
 
Vector< AudioInfoSupport * > notify_vector
 
AudioDecoderExtp_decoder = nullptr
 
Printp_print = nullptr
 

Detailed Description

A simple WAVDecoder: We parse the header data on the first record to determine the format. If no AudioDecoderExt is specified we just write the PCM data to the output that is defined by calling setOutput(). You can define a ADPCM decoder to decode WAV files that contain ADPCM data.

Optionally, if the input WAV file contains 8-bit PCM data, you can enable automatic conversion to 16-bit PCM output by calling setConvert8to16(true). This will convert unsigned 8-bit samples to signed 16-bit samples before writing to the output stream, and the reported bits_per_sample in audioInfo() will be 16 when conversion is active. The same is valid for the 24 bit conversion which converts 24 bit (3 byte) to 32 bit (4 byte).

Please note that you need to call begin() everytime you process a new file to let the decoder know that we start with a new header.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ WAVDecoder() [1/2]

WAVDecoder ( )
default

Construct a new WAVDecoder object for PCM data.

◆ WAVDecoder() [2/2]

WAVDecoder ( AudioDecoderExt dec,
AudioFormat  fmt 
)
inline

Construct a new WAVDecoder object for ADPCM data.

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

AudioInfo audioInfo ( )
inlineoverridevirtual

Exposed AudioInfo (may reflect conversion flags)

Reimplemented from AudioDecoder.

◆ audioInfoEx()

WAVAudioInfo & audioInfoEx ( )
inline

Extended WAV specific info (original header values)

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ begin() [1/2]

bool begin ( )
inlineoverridevirtual

Prepare decoder for a new WAV stream.

Reimplemented from AudioDecoder.

◆ begin() [2/2]

virtual bool begin ( AudioInfo  info)
inlineoverridevirtualinherited

Reimplemented from AudioWriter.

Reimplemented in DecoderBasic, and OggContainerDecoder.

◆ clearNotifyAudioChange()

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ decodeHeader()

int decodeHeader ( uint8_t in_ptr,
size_t  in_size 
)
inlineprotected

Decodes the header data: Returns the start pos of the data.

◆ end()

void end ( )
inlineoverridevirtual

Finish decoding and release temporary buffers.

Reimplemented from AudioDecoder.

◆ getOutput()

Print * getOutput ( )
inlineinherited

◆ isNotifyActive()

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ isResultPCM()

virtual bool isResultPCM ( )
inlinevirtualinherited

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

Reimplemented in CopyDecoder, DecoderNetworkFormat, and ContainerM4A.

◆ mime()

const char * mime ( )
inline

Provides MIME type "audio/wav".

◆ notifyAudioChange()

void notifyAudioChange ( AudioInfo  info)
inlineprotectedinherited

◆ operator bool()

virtual operator bool ( )
inlineoverridevirtual

Check if the decoder is active.

Implements AudioWriter.

◆ out()

Print & out ( )
inlineprotected

◆ removeNotifyAudioChange()

virtual bool removeNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

Removes a target in order not to be notified about audio changes.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ setAudioInfo()

void setAudioInfo ( AudioInfo  from)
inlineoverridevirtualinherited

for most decoders this is not needed

Implements AudioWriter.

Reimplemented in DecoderALAC, CodecChain, DSFDecoder, DecoderL8, OpusAudioDecoder, CodecNOP, G729Decoder, 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.

◆ setConvert24Bit()

void setConvert24Bit ( bool  enable)
inline

Convert 24 bit (3 byte) to 32 bit (4 byte) PCM data (default: enabled)

◆ setConvert8Bit()

void setConvert8Bit ( bool  enable)
inline

Convert 8 bit to 16 bit PCM data (default: enabled)

◆ setDecoder()

void setDecoder ( AudioDecoderExt dec,
AudioFormat  fmt 
)
inline

Defines an optional decoder if the format is not PCM.

◆ setNotifyActive()

void setNotifyActive ( bool  flag)
inlineinherited

Deactivate/Reactivate automatic AudioInfo updates: (default is active)

◆ 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_stream)
inlineoverridevirtual

Defines the output Stream.

Reimplemented from AudioDecoder.

◆ setupEncodedAudio()

void setupEncodedAudio ( )
inlineprotected

◆ write()

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

Write incoming WAV data (header + PCM) into output.

Implements AudioWriter.

◆ write_out()

virtual size_t write_out ( const uint8_t in_ptr,
size_t  in_size 
)
inlineprotectedvirtual

◆ write_out_24()

size_t write_out_24 ( const uint8_t in_ptr,
size_t  in_size 
)
inlineprotected

convert 3 byte int24 to 4 byte int32

◆ write_out_8to16()

size_t write_out_8to16 ( const uint8_t in_ptr,
size_t  in_size 
)
inlineprotected

Convert 8-bit PCM to 16-bit PCM and write out.

◆ writeBlocking()

void writeBlocking ( Print out,
uint8_t data,
size_t  len 
)
inlineprotectedinherited

Member Data Documentation

◆ active

bool active = false
protected

◆ batch_size

const size_t batch_size = 256
protected

◆ buffer24

SingleBuffer<int32_t> buffer24 {0}
protected

◆ byte_buffer

SingleBuffer<uint8_t> byte_buffer {0}
protected

◆ convert24

bool convert24 = true
protected

◆ convert8to16

bool convert8to16 = true
protected

◆ dec_out

EncodedAudioOutput dec_out
protected

◆ decoder_format

AudioFormat decoder_format = AudioFormat::PCM
protected

◆ header

WAVHeader header
protected

◆ id

int id
inherited

custom id to be used by application

◆ info

AudioInfo info
protectedinherited

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ isFirst

bool isFirst = true
protected

◆ isValid

bool isValid = true
protected

◆ notify_vector

Vector<AudioInfoSupport*> notify_vector
protectedinherited

◆ p_decoder

AudioDecoderExt* p_decoder = nullptr
protected

◆ p_print

Print* p_print = nullptr
protectedinherited

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