DSF2FLAC
Public Member Functions | Private Member Functions | Private Attributes
dsdDecimator Class Reference

#include <dsd_decimator.h>

List of all members.

Public Member Functions

 dsdDecimator (dsdSampleReader *reader, dsf2flac_uint32 outputSampleRate)
virtual ~dsdDecimator ()
template<typename sampleType >
void getSamples (sampleType *buffer, dsf2flac_uint32 bufferLen, dsf2flac_float64 scale, dsf2flac_float64 tpdfDitherPeakAmplitude=0)
dsf2flac_uint32 getOutputSampleRate ()
dsf2flac_int64 getLength ()
dsf2flac_float64 getPosition ()
dsf2flac_float64 getFirstValidSample ()
dsf2flac_float64 getLastValidSample ()
dsf2flac_float64 getPositionInSeconds ()
dsf2flac_float64 getPositionAsPercent ()
dsf2flac_uint32 getNumChannels ()
bool isValid ()
std::string getErrorMsg ()
void step ()
dsf2flac_uint32 getDecimationRatio ()
template<>
void getSamples (short int *buffer, dsf2flac_uint32 bufferLen, dsf2flac_float64 scale, dsf2flac_float64 tpdfDitherPeakAmplitude)
template<>
void getSamples (int *buffer, dsf2flac_uint32 bufferLen, dsf2flac_float64 scale, dsf2flac_float64 tpdfDitherPeakAmplitude)
template<>
void getSamples (long int *buffer, dsf2flac_uint32 bufferLen, dsf2flac_float64 scale, dsf2flac_float64 tpdfDitherPeakAmplitude)
template<>
void getSamples (float *buffer, dsf2flac_uint32 bufferLen, dsf2flac_float64 scale, dsf2flac_float64 tpdfDitherPeakAmplitude)
template<>
void getSamples (double *buffer, dsf2flac_uint32 bufferLen, dsf2flac_float64 scale, dsf2flac_float64 tpdfDitherPeakAmplitude)

Private Member Functions

void initLookupTable (const dsf2flac_int32 nCoefs, const dsf2flac_float64 *coefs, const dsf2flac_int32 tzero)
template<typename sampleType >
void getSamplesInternal (sampleType *buffer, dsf2flac_uint32 bufferLen, dsf2flac_float64 scale, dsf2flac_float64 tpdfDitherPeakAmplitude, bool roundToInt)

Private Attributes

dsdSampleReaderreader
dsf2flac_uint32 outputSampleRate
dsf2flac_uint32 nLookupTable
dsf2flac_uint32 tzero
calc_type ** lookupTable
dsf2flac_uint32 ratio
dsf2flac_uint32 nStep
bool valid
std::string errorMsg

Constructor & Destructor Documentation

dsdDecimator::dsdDecimator(dsdSampleReader *r, dsf2flac_uint32 rate)

Constructor!

Pass in a dsdSampleReader and the desired output sample rate.

dsdDecimator::~dsdDecimator

Destructor! Free the lookuptable


Member Function Documentation

std::string dsdDecimator::getErrorMsg ( )

bool dsdDecimator::getErrorMsg()

Returns a message describing the last error which caused the reader to become invalid.

unsigned long long int dsdDecimator::dsdDecimator::getLength()

Return the data length in output samples

dsf2flac_uint32 dsdDecimator::getOutputSampleRate()

Return the output sample rate

unsigned long long int dsdDecimator::dsdDecimator::getPosition()

Return the current position in output samples

template<typename sampleType >
void dsdDecimator::getSamples ( sampleType *  buffer,
dsf2flac_uint32  bufferLen,
dsf2flac_float64  scale,
dsf2flac_float64  tpdfDitherPeakAmplitude = 0 
)
template<>
void dsdDecimator::getSamples ( short int *  buffer,
dsf2flac_uint32  bufferLen,
dsf2flac_float64  scale,
dsf2flac_float64  tpdfDitherPeakAmplitude 
)

template <typename sampletype>=""> void getSamples(sampleType *buffer, dsf2flac_uint32 bufferLen, dsf2flac_float64 scale, dsf2flac_float64 tpdfDitherPeakAmplitude);

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 dsf2flac_float64

Others should be very simple to add (just take a look at the templates below).

template<>
void dsdDecimator::getSamples ( int *  buffer,
dsf2flac_uint32  bufferLen,
dsf2flac_float64  scale,
dsf2flac_float64  tpdfDitherPeakAmplitude 
)
template<>
void dsdDecimator::getSamples ( long int *  buffer,
dsf2flac_uint32  bufferLen,
dsf2flac_float64  scale,
dsf2flac_float64  tpdfDitherPeakAmplitude 
)
template<>
void dsdDecimator::getSamples ( float *  buffer,
dsf2flac_uint32  bufferLen,
dsf2flac_float64  scale,
dsf2flac_float64  tpdfDitherPeakAmplitude 
)
template<>
void dsdDecimator::getSamples ( double *  buffer,
dsf2flac_uint32  bufferLen,
dsf2flac_float64  scale,
dsf2flac_float64  tpdfDitherPeakAmplitude 
)
template<typename sampleType >
void dsdDecimator::getSamplesInternal ( sampleType *  buffer,
dsf2flac_uint32  bufferLen,
dsf2flac_float64  scale,
dsf2flac_float64  tpdfDitherPeakAmplitude,
bool  roundToInt 
) [private]

template <typename sampletype>=""> void dsdDecimator::getSamplesInternal(sampleType *buffer, dsf2flac_uint32 bufferLen, dsf2flac_float64 scale, dsf2flac_float64 tpdfDitherPeakAmplitude, bool roundToInt)

private method. 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]

void dsdDecimator::initLookupTable(const dsf2flac_float64 nCoefs,const dsf2flac_float64* coefs)

private method. Initialises the lookup table used for very fast filtering.

bool dsdDecimator::isValid()

Return false if the reader is invalid (format/file error for example).

void dsdDecimator::step ( ) [inline]

Member Data Documentation

std::string dsdDecimator::errorMsg [private]
bool dsdDecimator::valid [private]

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines