arduino-audio-tools
|
DSF (DSD Stream File) format decoder. More...
#include <CodecDSF.h>
Public Member Functions | |
DSFDecoder (DSFMetadata metaData) | |
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 () |
Initialize the decoder. | |
virtual bool | begin (AudioInfo info) override |
virtual void | clearNotifyAudioChange () |
Deletes all change notify subscriptions. | |
void | end () override |
const DSFMetadata | getMetadata () |
Get DSF file metadata. | |
Print * | getOutput () |
bool | isHeaderAvailable () |
Check if decoder is ready. | |
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 () | |
virtual bool | removeNotifyAudioChange (AudioInfoSupport &bi) |
Removes a target in order not to be notified about audio changes. | |
void | setAudioInfo (AudioInfo from) override |
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 | setMetaData (DSFMetadata metaData) |
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. | |
virtual void | setOutput (Print &out_stream) override |
Defines where the decoded result is written to. | |
size_t | write (const uint8_t *data, size_t len) |
Main entry point for processing incoming DSF data. | |
Public Attributes | |
int | id |
custom id to be used by application | |
Protected Member Functions | |
size_t | bufferDSDData (const uint8_t *data, size_t len, size_t startPos) |
Buffer incoming DSD data into ring buffer. | |
float | clip (float value) |
Clips audio values to valid range. | |
void | convertDSDToPCM () |
Convert buffered DSD data to PCM samples and output them. | |
int | findTag (const char *tag, const uint8_t *data, size_t len) |
Find a specific tag within binary data. | |
int | getOutputBufferSize () |
The buffer size is defined in the metadata: it must be at least 1 frame. | |
bool | hasEnoughData () |
Check if sufficient DSD data is available for conversion. | |
void | notifyAudioChange (AudioInfo info) |
bool | parseData (const uint8_t *data, size_t len) |
Parse DSF data chunk to extract audio data information. | |
bool | parseFMT (const uint8_t *data, size_t len) |
Parse DSF format chunk to extract audio parameters. | |
size_t | processDSDData (const uint8_t *data, size_t len, size_t startPos) |
Process DSD audio data: buffer it and convert to PCM when possible. | |
size_t | processHeader (const uint8_t *data, size_t len, size_t startPos) |
Process header data until header is complete or data is exhausted. | |
void | setupDecimationStep () |
Calculate optimal decimation step for DSD to PCM conversion. | |
void | setupTargetPCMRate () |
Set up low-pass filters for all channels. | |
void | writeBlocking (Print *out, uint8_t *data, size_t len) |
void | writePCMSample (float filteredValue) |
Convert filtered DSD value to PCM sample in the buffer. | |
Protected Attributes | |
Vector< float > | channelAccum |
Vector< LowPassFilter< float > > | channelFilters |
Anti-aliasing filters for each channel. | |
Vector< float > | channelIntegrator |
uint64_t | dataSize |
Size of audio data section in bytes. | |
uint32_t | decimationStep |
Decimation factor for DSD to PCM conversion. | |
RingBuffer< uint8_t > | dsdBuffer {0} |
Ring buffer for DSD data. | |
size_t | filePos |
Current position in DSF file. | |
bool | headerParsed = false |
Flag indicating if header parsing is complete. | |
size_t | headerSize |
Current size of accumulated header data. | |
AudioInfo | info |
bool | is_notify_active = true |
bool | isActive = false |
Flag indicating if decoder is active and ready. | |
float | max_value = 0.0f |
DSFMetadata | meta |
Extracted DSF file metadata. | |
Vector< AudioInfoSupport * > | notify_vector |
Print * | p_print = nullptr |
SingleBuffer< uint8_t > | pcmBuffer {0} |
DSF (DSD Stream File) format decoder.
Decodes DSF files containing Direct Stream Digital (DSD) audio data and converts it to PCM format. DSF is a file format that stores DSD audio streams, commonly used for high-resolution audio. This decoder:
The decoder uses BiQuad low-pass filters for high-quality anti-aliasing during the DSD to PCM conversion process, replacing traditional FIR filter implementations for better performance and modularity.
|
inlinevirtualinherited |
Adds target to be notified about audio changes.
Reimplemented in CodecNOP, EncodedAudioOutput, EncodedAudioStream, AACDecoderFDK, DecoderBasic, MP3DecoderHelix, MP3DecoderMAD, OggContainerDecoder, Pipeline, and Pipeline::ModifyingStreamAdapter.
|
inlineoverridevirtual |
provides the actual input AudioInfo
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 >.
|
inlinevirtual |
Initialize the decoder.
Sets up the decoder state, initializes buffers, and configures the low-pass filters with default parameters. The filters are initialized with a cutoff frequency of 40% of the Nyquist frequency to provide effective anti-aliasing.
Reimplemented from AudioDecoder.
|
inlineoverridevirtualinherited |
Reimplemented from AudioWriter.
|
inlineprotected |
Buffer incoming DSD data into ring buffer.
data | Input data buffer |
len | Length of input data |
startPos | Starting position in input buffer |
Copies DSD data bytes into the internal ring buffer until either all data is consumed or the buffer becomes full.
|
inlineprotected |
Clips audio values to valid range.
value | Input audio value |
Ensures that filtered audio values stay within the valid range to prevent clipping artifacts in the final PCM output.
|
inlineprotected |
Convert buffered DSD data to PCM samples and output them.
Performs the core DSD to PCM conversion process using integrator-based approach:
The conversion uses BiQuad low-pass filters for anti-aliasing, providing better audio quality than simple decimation.
DSF format uses byte interleaving: each byte contains 8 DSD samples for one channel, and channels are interleaved at the byte level (not bit level).
|
inlineoverridevirtual |
Reimplemented from AudioDecoder.
|
inlineprotected |
Find a specific tag within binary data.
tag | The tag string to search for (e.g., "fmt ", "data") |
data | The binary data buffer to search in |
len | The length of the data buffer |
Searches for DSF chunk identifiers within the file data. Used to locate format and data sections within the DSF file structure.
|
inline |
Get DSF file metadata.
Returns metadata extracted from the DSF file header, including DSD sample rate, data size, estimated PCM frames, and calculated duration.
|
inlineprotected |
Check if sufficient DSD data is available for conversion.
Determines if the DSD buffer contains enough data to perform one decimation step of DSD to PCM conversion. For DSF format with byte interleaving, we need enough bytes for all channels over the decimation period.
|
inline |
Check if decoder is ready.
Indicates whether the decoder has successfully parsed the DSF file header and is ready to process audio data.
|
inlinevirtualinherited |
Returns true to indicate that the decoding result is PCM data.
Reimplemented in CopyDecoder, DecoderNetworkFormat, GGWaveDecoder, and ContainerM4A.
|
inlinevirtual |
Implements AudioWriter.
|
inlineprotected |
Parse DSF data chunk to extract audio data information.
data | Pointer to the data chunk |
len | Length of available data |
Extracts audio data size information and calculates estimated playback duration and total PCM frames that will be produced after DSD to PCM conversion is complete.
|
inlineprotected |
Parse DSF format chunk to extract audio parameters.
data | Pointer to the fmt chunk data |
len | Length of available data |
Extracts essential audio format information from the DSF format chunk, including channel count, DSD sample rate, and validates the parameters are within acceptable ranges for processing.
|
inlineprotected |
Process DSD audio data: buffer it and convert to PCM when possible.
data | Input data buffer containing DSD audio data |
len | Length of input data |
startPos | Starting position in input buffer |
Buffers incoming DSD data and triggers PCM conversion when sufficient data is available for processing.
|
inlineprotected |
Process header data until header is complete or data is exhausted.
data | Input data buffer |
len | Length of input data |
startPos | Starting position in input buffer |
Accumulates header bytes and attempts to parse the DSF file header. When a complete and valid header is found, sets headerParsed flag and updates decimation parameters.
|
inlineoverridevirtual |
Can be used to set up alternative sample rate (default is 44100 Hz) and bits
Reimplemented from AudioDecoder.
|
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.
|
inlineoverridevirtualinherited |
Defines where the decoded result is written to.
Implements AudioWriter.
Reimplemented in DecoderBase64, MP3DecoderMAD, DecoderAdapter, CodecNOP, ADPCMDecoderXQ, APTXDecoder, Codec2Decoder, CopyDecoder, G722Decoder, GSMDecoder, ILBCDecoder, LC3Decoder, DecoderNetworkFormat, SBCDecoder, WavIMADecoder, GGWaveDecoder, AACDecoderFDK, AACDecoderHelix, ADPCMDecoder, ADTSDecoder, DecoderBasic, CodecChain, DecoderFloat, G7xxDecoder, DecoderL16, MTSDecoder, OpusAudioDecoder, MTSDecoderTSDemux, WAVDecoder, AVIDecoder, ContainerM4A, MultiDecoder, MetaDataFilterDecoder, MP3DecoderMini, BinaryContainerDecoder, OSCContainerDecoder, MP3DecoderHelix, and OggContainerDecoder.
|
inlineprotected |
Calculate optimal decimation step for DSD to PCM conversion.
Calculates the decimation factor as the ratio of DSD sample rate to target PCM sample rate. Clamps the value between 64 and 512 to ensure reasonable processing efficiency and audio quality while maintaining good anti-aliasing performance.
|
inlineprotected |
Set up low-pass filters for all channels.
Initializes anti-aliasing filters for each audio channel with appropriate cutoff frequency (40% of Nyquist frequency) for the current sample rate. This ensures proper anti-aliasing performance during DSD to PCM conversion.
|
inlinevirtual |
Main entry point for processing incoming DSF data.
data | Incoming DSF file data bytes |
len | Number of bytes in data buffer |
Processes incoming DSF file data in two phases:
The method is designed for streaming operation and always reports full consumption of input data for compatibility with streaming frameworks.
Implements AudioWriter.
|
inlineprotected |
Convert filtered DSD value to PCM sample in the buffer.
filteredValue | The filtered DSD value (range -1.0 to 1.0) |
channel | Channel index (0 for left/mono, 1 for right) |
|
protected |
Accumulator for each channel during DSD to PCM conversion
|
protected |
Integrator state for each channel (for better DSD conversion)
|
protected |
Buffer for PCM output samples - supports multi-channel up to 32-bit