|
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. Since WAV files can use different ADPCM (or other) encodings, you can register more than one decoder with addDecoder(): the decoder matching the format tag found in the WAV header is selected automatically when a file is parsed. More...
#include <CodecWAV.h>
Classes | |
| struct | DecoderEntry |
| Associates a WAV format tag with the decoder responsible for it. More... | |
Public Member Functions | |
| WAVDecoder ()=default | |
| Construct a new WAVDecoder object for PCM data. | |
| WAVDecoder (AudioDecoderExt &dec, AudioFormat fmt=AudioFormat::UNKNOWN) | |
| Construct a new WAVDecoder object for ADPCM data. If fmt is not provided, it is derived from dec.wavFormat() (see setDecoder()). | |
| void | addDecoder (AudioDecoderExt &dec, AudioFormat fmt=AudioFormat::UNKNOWN) |
| 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. | |
| WAVHeader & | getHeader () |
| Access to the internal header parser and info. | |
| 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 | setConvertALawMuLaw (bool enable) |
| void | setConvertFloatToInt16 (bool enable) |
| void | setDecoder (AudioDecoderExt &dec, AudioFormat fmt=AudioFormat::UNKNOWN) |
| 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 | endCurrentDecoder () |
| AudioDecoderExt * | findDecoder (AudioFormat format) |
| Finds the decoder registered for the given format tag, if any. | |
| void | logSupportedFormats () |
| 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. | |
| size_t | write_out_alaw (const uint8_t *in_ptr, size_t in_size) |
| Expand G.711 A-law 8-bit samples to 16-bit linear PCM and write out. | |
| size_t | write_out_float_to_int16 (const uint8_t *in_ptr, size_t in_size) |
| size_t | write_out_mulaw (const uint8_t *in_ptr, size_t in_size) |
| Expand G.711 mu-law 8-bit samples to 16-bit linear PCM and write out. | |
| void | writeBlocking (Print *out, uint8_t *data, size_t len) |
Static Protected Member Functions | |
| static int16_t | alaw2linear (uint8_t a_val) |
| Converts a G.711 A-law encoded byte to a 16-bit linear PCM sample. | |
| static bool | isNativelySupported (AudioFormat format) |
| Formats that are handled internally without an external decoder. | |
| static int16_t | ulaw2linear (uint8_t u_val) |
| Converts a G.711 mu-law encoded byte to a 16-bit linear PCM sample. | |
Protected Attributes | |
| bool | active = false |
| const size_t | batch_size = 256 |
| SingleBuffer< int32_t > | buffer24 {0} |
| SingleBuffer< int16_t > | buffer_float16 {0} |
| SingleBuffer< uint8_t > | byte_buffer {0} |
| bool | convert24 = true |
| bool | convert8to16 = true |
| bool | convertALawMuLaw = true |
| bool | convertFloatToInt16 = true |
| EncodedAudioOutput | dec_out |
| Vector< DecoderEntry > | decoders |
| decoders registered via setDecoder()/addDecoder(), keyed by format tag | |
| 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. Since WAV files can use different ADPCM (or other) encodings, you can register more than one decoder with addDecoder(): the decoder matching the format tag found in the WAV header is selected automatically when a file is parsed.
Besides plain PCM, the following formats are natively supported without the need to provide an external decoder:
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.
|
default |
Construct a new WAVDecoder object for PCM data.
|
inline |
Construct a new WAVDecoder object for ADPCM data. If fmt is not provided, it is derived from dec.wavFormat() (see setDecoder()).
|
inline |
Registers an additional decoder for a specific WAV format tag, on top of any decoder(s) already defined. The decoder used to decode the stream is selected automatically based on the format tag found in the WAV header, so a single WAVDecoder instance can transparently handle files using any of the registered formats (e.g. multiple ADPCM variants). If a decoder is already registered for the same format tag, it is replaced. See setDecoder() for details on the optional fmt parameter.
|
inlinevirtualinherited |
Adds target to be notified about audio changes.
Reimplemented in CodecNOP, EncodedAudioOutput, EncodedAudioStream, AACDecoderFDK, DecoderBasic, CodecChain, MP3DecoderHelix, MP3DecoderMAD, OggContainerDecoder, RTSPClient< TcpClient, UdpSocket >, Pipeline, and Pipeline::ModifyingStreamAdapter.
|
inlinestaticprotected |
Converts a G.711 A-law encoded byte to a 16-bit linear PCM sample.
|
inlineoverridevirtual |
Exposed AudioInfo (may reflect conversion flags)
Reimplemented from AudioDecoder.
|
inline |
Extended WAV specific info (original header values)
|
inlinevirtualinherited |
provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
Reimplemented in MP3EncoderShine, PureDataStream, PWMAudioOutput< PWMDriverT >, ChannelFormatConverterStreamT< T >, ChannelFormatConverterStream, NumberFormatConverterStreamT< TFrom, TTo >, NumberFormatConverterStream, FormatConverterStream, Pipeline, ResampleStream, ResampleStreamT< TInterpolator >, and SupportedRatesStream.
|
inlineoverridevirtual |
Prepare decoder for a new WAV stream.
Reimplemented from AudioDecoder.
|
inlineoverridevirtualinherited |
Reimplemented from AudioWriter.
Reimplemented in DecoderBasic, and OggContainerDecoder.
|
inlinevirtualinherited |
Deletes all change notify subscriptions.
Reimplemented in RTSPClient< TcpClient, UdpSocket >.
|
inlineprotected |
Decodes the header data: Returns the start pos of the data.
|
inlineoverridevirtual |
Finish decoding and release temporary buffers.
Reimplemented from AudioDecoder.
|
inlineprotected |
Ends the decoder currently selected for the stream just finished (if any), so it doesn't retain state (e.g. sample_rate/channels) across unrelated streams the next time this format is matched
|
inlineprotected |
Finds the decoder registered for the given format tag, if any.
|
inline |
Access to the internal header parser and info.
|
inlineinherited |
|
inlinestaticprotected |
Formats that are handled internally without an external decoder.
|
inlineinherited |
Checks if the automatic AudioInfo update is active.
|
inlinevirtualinherited |
Returns true to indicate that the decoding result is PCM data.
Reimplemented in CopyDecoder, DecoderNetworkFormat, and ContainerM4A.
|
inlineprotected |
Logs (at error level) the WAV format tags this instance can currently decode: the natively handled ones, plus any registered via setDecoder()/addDecoder()
|
inlinevirtual |
Provides MIME type "audio/wav".
Implements AudioDecoder.
|
inlineprotectedinherited |
|
inlineoverridevirtual |
Check if the decoder is active.
Implements AudioWriter.
|
inlineprotected |
|
inlinevirtualinherited |
Removes a target in order not to be notified about audio changes.
Reimplemented in RTSPClient< TcpClient, UdpSocket >.
|
inlineoverridevirtualinherited |
for most decoders this is not needed
Implements AudioWriter.
Reimplemented in DecoderALAC, CodecChain, DSFDecoder, DecoderL8, OpusAudioDecoder, OpusMultiStreamAudioDecoder, CodecNOP, G729Decoder, and G7xxDecoder.
|
inlinevirtualinherited |
Some decoders need e.g. a magic cookie to provide the relevant info for decoding.
Reimplemented in DecoderALAC, and MultiDecoder.
|
inline |
Convert 24 bit (3 byte) to 32 bit (4 byte) PCM data (default: enabled)
|
inline |
Convert 8 bit to 16 bit PCM data (default: enabled)
|
inline |
Expand ALAW/MULAW 8-bit logarithmic samples to 16-bit linear PCM (default: enabled). If disabled, the raw encoded bytes are passed through unchanged.
|
inline |
Convert 32-bit IEEE_FLOAT samples to 16-bit linear PCM (default: enabled). Samples are clamped to [-1.0, 1.0] before scaling to the int16 range. If disabled, the raw 32-bit float bytes are passed through unchanged.
|
inline |
Defines an optional decoder if the format is not PCM. This replaces any previously registered decoders. To support WAV files that may use different ADPCM (or other) formats, register multiple decoders with addDecoder() instead.
fmt is the WAV format tag (see AudioFormat) that dec decodes. It can be omitted if dec can identify its own format via AudioDecoderExt::wavFormat() - e.g. ADPCMDecoder does this for the codec ids that correspond to a well defined WAV format tag (currently MS ADPCM, IMA/DVI ADPCM and Yamaha ADPCM). For codecs that don't map to a single WAV format tag, fmt must be provided explicitly.
|
inlineinherited |
Deactivate/Reactivate automatic AudioInfo updates: (default is active)
|
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.
|
inlineprotected |
|
inlinestaticprotected |
Converts a G.711 mu-law encoded byte to a 16-bit linear PCM sample.
|
inlineoverridevirtual |
Write incoming WAV data (header + PCM) into output.
Implements AudioWriter.
|
inlineprotectedvirtual |
|
inlineprotected |
convert 3 byte int24 to 4 byte int32
|
inlineprotected |
Convert 8-bit PCM to 16-bit PCM and write out.
|
inlineprotected |
Expand G.711 A-law 8-bit samples to 16-bit linear PCM and write out.
|
inlineprotected |
Convert 32-bit IEEE_FLOAT samples to 16-bit linear PCM and write out. Samples are clamped to [-1.0, 1.0] before scaling to the int16 range.
|
inlineprotected |
Expand G.711 mu-law 8-bit samples to 16-bit linear PCM and write out.
|
inlineprotectedinherited |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
decoders registered via setDecoder()/addDecoder(), keyed by format tag
|
protected |
|
inherited |
custom id to be used by application
|
protectedinherited |
|
protectedinherited |
|
protected |
|
protected |
|
protectedinherited |
|
protected |
decoder matching the format of the WAV file currently being processed (selected in decodeHeader() from the registered decoders)
|
protectedinherited |