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 00038 /* 00039 * dsf_file_reader.h 00040 * 00041 * Header file for the class dsfFileReader. 00042 * 00043 * This class extends dsdSampleReader providing acces to dsd samples and other info 00044 * from dsf files. 00045 * 00046 * Some of the rarer features of dsf are not well tested due to a lack of files: 00047 * dsd64 00048 * 8bit dsd 00049 * 00050 */ 00051 00052 #ifndef DSFFILEREADER_H 00053 #define DSFFILEREADER_H 00054 00055 #include "dsd_sample_reader.h" // Base class: dsdSampleReader 00056 #include "fstream_plus.h" 00057 00058 class dsfFileReader : public DsdSampleReader 00059 { 00060 public: 00061 // constructor and destructor 00062 dsfFileReader(char* filePath); 00063 virtual ~dsfFileReader(); 00064 public: 00065 // methods overriding dsdSampleReader 00066 bool step(); 00067 void rewind(); 00068 dsf2flac_int64 getLength() {return sampleCount;}; 00069 dsf2flac_uint32 getNumChannels() {return chanNum;}; 00070 dsf2flac_uint32 getSamplingFreq() {return samplingFreq;}; 00071 bool msbIsPlayedFirst() { return true;} 00072 bool samplesAvailable() { return !file.eof() && DsdSampleReader::samplesAvailable(); }; // false when no more samples left 00073 ID3_Tag getID3Tag(dsf2flac_uint32 trackNum) {return metadata;} 00074 public: 00075 // other public methods 00076 void dispFileInfo(); 00077 private: 00078 // private variables 00079 char* filePath; 00080 fstreamPlus file; 00081 // below store file info 00082 dsf2flac_uint64 fileSz; 00083 dsf2flac_uint64 metaChunkPointer; 00084 dsf2flac_uint64 sampleDataPointer; 00085 dsf2flac_uint64 dataChunkSz; 00086 dsf2flac_uint32 formatVer; 00087 dsf2flac_uint32 formatID; 00088 dsf2flac_uint32 chanType; 00089 dsf2flac_uint32 chanNum; 00090 dsf2flac_uint32 samplingFreq; 00091 dsf2flac_uint64 sampleCount; //per channel 00092 dsf2flac_uint32 blockSzPerChan; 00093 ID3_Tag metadata; 00094 // vars to hold the data and mark position 00095 dsf2flac_uint8** blockBuffer; // used to store blocks of raw data from the file 00096 dsf2flac_int64 blockCounter; // stores the index to the current blockBuffer 00097 dsf2flac_int64 blockMarker; // stores the current position in the blockBuffer 00098 // private methods 00099 void allocateBlockBuffer(); 00100 bool readHeaders(); 00101 void readMetadata(); 00102 bool readNextBlock(); 00103 static bool checkIdent(dsf2flac_int8* a, dsf2flac_int8* b); // MUST be used with the char[4]s or you'll get segfaults! 00104 }; 00105 00106 #endif // DSFFILEREADER_H