DSF2FLAC
|
00001 /* 00002 * dsf2flac - http://code.google.com/p/dsf2flac/ 00003 * 00004 * A file conversion tool for translating dsf dsd audio files into 00005 * flac pcm audio files. 00006 * 00007 * Copyright (c) 2013 by respective authors. 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 * 00023 * 00024 * Acknowledgements 00025 * 00026 * Many thanks to the following authors and projects whose work has greatly 00027 * helped the development of this tool. 00028 * 00029 * 00030 * Sebastian Gesemann - dsd2pcm (http://code.google.com/p/dsd2pcm/) 00031 * SACD Ripper (http://code.google.com/p/sacd-ripper/) 00032 * Maxim V.Anisiutkin - foo_input_sacd (http://sourceforge.net/projects/sacddecoder/files/) 00033 * Vladislav Goncharov - foo_input_sacd_hq (http://vladgsound.wordpress.com) 00034 * Jesus R - www.sonore.us 00035 * 00036 */ 00037 00049 #define calc_type dsf2flac_float64 // you can change the type used to do the filtering... but there is barely any change in calc speed between float and double 00050 00051 #ifndef DSDDECIMATOR_H 00052 #define DSDDECIMATOR_H 00053 00054 #include <dsd_sample_reader.h> 00055 00056 class dsdDecimator 00057 { 00058 public: 00059 dsdDecimator(DsdSampleReader *reader, dsf2flac_uint32 outputSampleRate); 00060 virtual ~dsdDecimator(); 00061 // Method to get the output samples 00062 template <typename sampleType> void getSamples(sampleType *buffer, dsf2flac_uint32 bufferLen, dsf2flac_float64 scale, dsf2flac_float64 tpdfDitherPeakAmplitude = 0); 00063 dsf2flac_uint32 getOutputSampleRate(); 00064 dsf2flac_int64 getLength(); // return total length in samples of decimated data 00065 dsf2flac_float64 getPosition(); 00066 dsf2flac_float64 getFirstValidSample(); 00067 dsf2flac_float64 getLastValidSample(); 00068 dsf2flac_float64 getPositionInSeconds() { return getPosition()/outputSampleRate; }; 00069 dsf2flac_float64 getPositionAsPercent() { return getPosition()/getLength()*100; }; 00070 dsf2flac_uint32 getNumChannels() { return reader->getNumChannels(); }; 00071 bool isValid(); // return false if the decimator is invalid 00072 std::string getErrorMsg(); // returns a human readable error message 00073 void step() { reader->step(); }; // handy wrappers. 00074 dsf2flac_uint32 getDecimationRatio() {return ratio;}; 00075 private: 00076 DsdSampleReader *reader; 00077 dsf2flac_uint32 outputSampleRate; 00078 dsf2flac_uint32 nLookupTable; 00079 dsf2flac_uint32 tzero; // filter t=0 position 00080 calc_type** lookupTable; 00081 dsf2flac_uint32 ratio; // inFs/outFs 00082 dsf2flac_uint32 nStep; 00083 bool valid; 00084 std::string errorMsg; 00085 // private methods 00086 void initLookupTable(const dsf2flac_int32 nCoefs,const dsf2flac_float64* coefs,const dsf2flac_int32 tzero); 00087 template <typename sampleType> void getSamplesInternal(sampleType *buffer, dsf2flac_uint32 bufferLen, dsf2flac_float64 scale, dsf2flac_float64 tpdfDitherPeakAmplitude, bool roundToInt); 00088 00089 }; 00090 00091 #endif // DSDDECIMATOR_H