arduino-audio-tools
|
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>
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) | |
WAVAudioInfo & | audioInfoEx () |
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. | |
Print * | getOutput () |
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 () |
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) |
Print & | out () |
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_t > | buffer24 {0} |
SingleBuffer< uint8_t > | byte_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 |
AudioDecoderExt * | p_decoder = nullptr |
Print * | p_print = nullptr |
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.
|
inlinevirtualinherited |
Adds target to be notified about audio changes.
Reimplemented in CodecNOP, EncodedAudioOutput, EncodedAudioStream, AACDecoderFDK, DecoderBasic, CodecChain, MP3DecoderHelix, MP3DecoderMAD, OggContainerDecoder, Pipeline, and Pipeline::ModifyingStreamAdapter.
|
inlineoverridevirtual |
Exposed AudioInfo (may reflect conversion flags)
Reimplemented from AudioDecoder.
|
inlinevirtualinherited |
provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
Reimplemented in PureDataStream, PWMAudioOutput, ChannelFormatConverterStreamT< T >, ChannelFormatConverterStream, NumberFormatConverterStreamT< TFrom, TTo >, NumberFormatConverterStream, FormatConverterStream, Pipeline, ResampleStream, and ResampleStreamT< TInterpolator >.
|
inlineoverridevirtual |
Prepare decoder for a new WAV stream.
Reimplemented from AudioDecoder.
|
inlineoverridevirtualinherited |
Reimplemented from AudioWriter.
|
inlineoverridevirtual |
Finish decoding and release temporary buffers.
Reimplemented from AudioDecoder.
|
inlinevirtualinherited |
Returns true to indicate that the decoding result is PCM data.
Reimplemented in CopyDecoder, DecoderNetworkFormat, GGWaveDecoder, and ContainerM4A.
|
inlineoverridevirtual |
Check if the decoder is active.
Implements AudioWriter.
|
inlineoverridevirtualinherited |
for most decoders this is not needed
Implements AudioWriter.
Reimplemented in GGWaveDecoder, DecoderALAC, CodecChain, DSFDecoder, DecoderL8, OpusAudioDecoder, CodecNOP, and G7xxDecoder.
|
inlinevirtualinherited |
Some decoders need e.g. a magic cookie to provide the relevant info for decoding.
Reimplemented in DecoderALAC, and MultiDecoder.
|
inlinevirtualinherited |
Defines where the decoded result is written to.
Reimplemented in ADTSDecoder, CodecChain, MTSDecoder, MTSDecoderTSDemux, and MetaDataFilterDecoder.
|
inlinevirtualinherited |
Defines where the decoded result is written to.
Reimplemented in ADTSDecoder, CodecChain, MTSDecoder, MTSDecoderTSDemux, and MetaDataFilterDecoder.
|
inlineoverridevirtual |
Defines the output Stream.
Reimplemented from AudioDecoder.
|
inlineoverridevirtual |
Write incoming WAV data (header + PCM) into output.
Implements AudioWriter.