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 #ifndef DSDSAMPLEREADER_H 00050 #define DSDSAMPLEREADER_H 00051 00052 #include "stdio.h" 00053 #include "dsf2flac_types.h" 00054 #include <boost/circular_buffer.hpp> 00055 #include "id3/tag.h" 00056 00057 static const dsf2flac_uint32 defaultBufferLength = 5000; 00058 00059 class DsdSampleReader 00060 { 00061 public: 00062 // constructor and destructor 00063 DsdSampleReader(); 00064 virtual ~DsdSampleReader(); 00065 // CHILD CLASSES SHOULD OVERRIDE THESE! 00066 virtual bool step() {return false;}; // move buffer forward by 1byte (8bits) of sample data. 00067 virtual void rewind() {}; // resets the dsd reader to the start of the dsd data. Implementors should call clearBuffer. 00068 virtual dsf2flac_int64 getLength() {return 1;}; // length of file in dsd samples 00069 virtual dsf2flac_uint32 getNumChannels() {return 2;}; // number of channels in the file 00070 virtual dsf2flac_uint32 getSamplingFreq() {return 2822400;}; // the sampling freq of the dsd data 00071 ID3_Tag getID3Tag() {return getID3Tag(1);}; 00072 virtual ID3_Tag getID3Tag(dsf2flac_uint32 trackNum) {return NULL;}; 00073 virtual bool msbIsPlayedFirst() {return true;} // the data is stored in 8-bit chars, returns true if the left most bit (msb) is the youngest (i.e. msb should be played first and lsb last). 00074 virtual dsf2flac_uint8 getIdleSample() { return 0x69; }; // returns the idle tone used by this reader. 00075 virtual bool samplesAvailable() { return getPosition()<getLength(); }; // false when no more samples left 00076 virtual dsf2flac_uint32 getNumTracks() {return 1;}; // the number of audio tracks in the dsd data 00077 virtual dsf2flac_uint64 getTrackStart(dsf2flac_uint32 trackNum) { return 0; } // return the start position in dsd samples of the nth track 00078 virtual dsf2flac_uint64 getTrackEnd(dsf2flac_uint32 trackNum) { return getLength(); } // return the end position in dsd samples of the nth track 00079 // positioning. 00080 // public methods 00081 boost::circular_buffer<dsf2flac_uint8>* getBuffer(); // return a circular buffer which is updated with the dsd samples stored as 8bit chars (1 per channel) by default filled with getIdleSample(). 00082 bool setBufferLength(dsf2flac_uint32 bufferLength); // set the length of the circular buffers in 8bit chars WARNING: causes the file to be rewound! 00083 dsf2flac_uint32 getBufferLength(); // return the length of the circular buffers (8bit chars). 00084 dsf2flac_int64 getPosition() {return posMarker*samplesPerChar;}; // current position in the file in dsd samples 00085 dsf2flac_int64 getPosition(dsf2flac_int64 bufferPos) { return getPosition() - bufferPos; }; // get the position in dsd samples in relation to a certain position in the buffer. 00086 dsf2flac_float64 getPositionInSeconds(); // current position in the file in seconds 00087 dsf2flac_float64 getPositionAsPercent(); 00088 dsf2flac_float64 getLengthInSeconds(); // length of file in seconds 00089 bool isValid(); // returns false if the reader is invalid 00090 std::string getErrorMsg(); 00091 // static method to help out with latin1 charset 00092 static char* latin1_to_utf8(char* latin1); 00093 protected: 00094 // protected properties 00095 boost::circular_buffer<dsf2flac_uint8>* circularBuffers; 00096 // position marker 00097 dsf2flac_int64 posMarker; // implementors need to increment this on step() 00098 dsf2flac_uint32 samplesPerChar; // should be set by implementors 00099 // to hold feedback on errors 00100 bool valid; 00101 std::string errorMsg; 00102 protected: 00103 // protected methods 00104 void allocateBuffer(); //implementors need to call this once they know the number of channels! 00105 void clearBuffer(); // fill entire buffer with idleSample 00106 void resizeBuffer(); // resize buffer, fill with idleSample, call rewind 00107 private: 00108 // private properties 00109 dsf2flac_uint32 bufferLength; 00110 bool isBufferAllocated; 00111 }; 00112 #endif // DSDSAMPLEREADER_H