DSF2FLAC
|
The DsdDecimator reads DSD samples from a DsdSampleReader and converts them to PCM samples. More...
#include <dsd_decimator.h>
Public Member Functions | |
DsdDecimator (DsdSampleReader *reader, dsf2flac_uint32 outputSampleRate) | |
Class constructor. | |
virtual | ~DsdDecimator () |
Class destructor, frees internal buffers and lookup table. | |
bool | isValid () |
Return false if the reader is invalid (format/file error for example). | |
std::string | getErrorMsg () |
Returns a message explaining why the reader is invalid. | |
dsf2flac_uint32 | getOutputSampleRate () |
Return the output sample rate in Hz. | |
dsf2flac_uint32 | getDecimationRatio () |
Return the decimation ratio: DSD sample rate / PCM sample rate. | |
dsf2flac_int64 | getLength () |
Return the data length in PCM samples. | |
dsf2flac_uint32 | getNumChannels () |
Return the number of channels if audio data. | |
dsf2flac_float64 | getPosition () |
Return the current position in PCM samples. | |
dsf2flac_float64 | getPositionInSeconds () |
Return the current position in seconds. | |
dsf2flac_float64 | getPositionAsPercent () |
Return the current position as a percent of the total data length. | |
dsf2flac_float64 | getFirstValidSample () |
Return the position of the first PCM sample that is completely defined. | |
dsf2flac_float64 | getLastValidSample () |
Return the position of the last PCM sample that is completely defined. | |
void | step () |
Steps the decimator forward by 8 DSD samples. | |
template<typename sampleType > | |
void | getSamples (sampleType *buffer, dsf2flac_uint32 bufferLen, dsf2flac_float64 scale, dsf2flac_float64 tpdfDitherPeakAmplitude=0) |
Read PCM output samples in format sampleType into a buffer of length bufferLen. | |
Private Member Functions | |
void | initLookupTable (const dsf2flac_int32 nCoefs, const dsf2flac_float64 *coefs, const dsf2flac_int32 tzero) |
Initializes the filter lookup table. | |
template<typename sampleType > | |
void | getSamplesInternal (sampleType *buffer, dsf2flac_uint32 bufferLen, dsf2flac_float64 scale, dsf2flac_float64 tpdfDitherPeakAmplitude, bool roundToInt) |
Does the actual calculation for the getSamples method. Using the lookup tables FIR calculation is a pretty simple summing operation. |
The DsdDecimator reads DSD samples from a DsdSampleReader and converts them to PCM samples.
The DsdDecimator only supports output sample rates which are multiples of 44.1kHz.
DsdDecimator::DsdDecimator | ( | DsdSampleReader * | reader, |
dsf2flac_uint32 | outputSampleRate | ||
) |
Class constructor.
DsdSampleReader must be a valid reader. outputSampleRate sets the sampling frequency for the output PCM samples, must be a multiple of 44100. Note that not all output sample rates are supported by default. Most can be easily added by putting an appropriate filter into the filters.cpp file.
DsdDecimator::~DsdDecimator | ( | ) | [virtual] |
Class destructor, frees internal buffers and lookup table.
dsf2flac_uint32 DsdDecimator::getDecimationRatio | ( | ) | [inline] |
Return the decimation ratio: DSD sample rate / PCM sample rate.
std::string DsdDecimator::getErrorMsg | ( | ) |
Returns a message explaining why the reader is invalid.
dsf2flac_float64 DsdDecimator::getFirstValidSample | ( | ) |
Return the position of the first PCM sample that is completely defined.
dsf2flac_float64 DsdDecimator::getLastValidSample | ( | ) |
Return the position of the last PCM sample that is completely defined.
dsf2flac_int64 DsdDecimator::getLength | ( | ) |
Return the data length in PCM samples.
dsf2flac_uint32 DsdDecimator::getNumChannels | ( | ) | [inline] |
Return the number of channels if audio data.
dsf2flac_uint32 DsdDecimator::getOutputSampleRate | ( | ) |
Return the output sample rate in Hz.
dsf2flac_float64 DsdDecimator::getPosition | ( | ) |
Return the current position in PCM samples.
dsf2flac_float64 DsdDecimator::getPositionAsPercent | ( | ) | [inline] |
Return the current position as a percent of the total data length.
dsf2flac_float64 DsdDecimator::getPositionInSeconds | ( | ) | [inline] |
Return the current position in seconds.
void DsdDecimator::getSamples | ( | sampleType * | buffer, |
dsf2flac_uint32 | bufferLen, | ||
dsf2flac_float64 | scale, | ||
dsf2flac_float64 | tpdfDitherPeakAmplitude = 0 |
||
) |
Read PCM output samples in format sampleType into a buffer of length bufferLen.
bufferLen must be a multiple of getNumChannels(). Channels are interleaved into the buffer.
You also need to provide a scaling factor. This is particularly important for int sample types. The raw DSD data has peak amplitude +-1.
If you wish to add TPDF dither to the data before quantization then please also provide the peak amplitude.
These sample types are supported:
short int, int, long int, float, double
Others should be very simple to add (just take a look at the templates in the source code).
void DsdDecimator::getSamplesInternal | ( | sampleType * | buffer, |
dsf2flac_uint32 | bufferLen, | ||
dsf2flac_float64 | scale, | ||
dsf2flac_float64 | tpdfDitherPeakAmplitude, | ||
bool | roundToInt | ||
) | [private] |
Does the actual calculation for the getSamples method. Using the lookup tables FIR calculation is a pretty simple summing operation.
void DsdDecimator::initLookupTable | ( | const dsf2flac_int32 | nCoefs, |
const dsf2flac_float64 * | coefs, | ||
const dsf2flac_int32 | tzero | ||
) | [private] |
Initializes the filter lookup table.
bool DsdDecimator::isValid | ( | ) |
Return false if the reader is invalid (format/file error for example).
void DsdDecimator::step | ( | ) | [inline] |
Steps the decimator forward by 8 DSD samples.