Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2010 George Tzanetakis <gtzan@cs.cmu.edu> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #ifndef MARSYAS_MP3SOURCE_H 00020 #define MARSYAS_MP3SOURCE_H 00021 00022 #include <cstdio> 00023 00024 #ifndef WIN32 00025 #include <sys/stat.h> 00026 #include <sys/types.h> 00027 #include <sys/mman.h> 00028 #include <fcntl.h> 00029 #endif 00030 00031 #include <marsyas/common_header.h> 00032 #include "AbsSoundFileSource.h" 00033 00034 extern "C" { 00035 #include "mad.h" 00036 } 00037 00038 namespace Marsyas 00039 { 00052 class MP3FileSource: public AbsSoundFileSource 00053 { 00054 private: 00055 MarControlPtr ctrl_pos_; 00056 void addControls(); 00057 void myUpdate(MarControlPtr sender); 00058 mrs_natural getLinear16(realvec& slice); 00059 00060 // MAD stuff 00061 inline signed int scale(mad_fixed_t sample); 00062 void madStructInitialize(); 00063 void madStructFinish(); 00064 00065 void fillStream( long offset = 0 ); 00066 void closeFile(); 00067 00068 void PrintFrameInfo(struct mad_header *Header); 00069 00070 // MAD stuff 00071 struct mad_stream stream; 00072 struct mad_frame frame; 00073 struct mad_synth synth; 00074 00075 mrs_natural fileSize_; 00076 mrs_natural frameSamples_; 00077 mrs_natural totalFrames_; 00078 mrs_natural frameCount_; 00079 unsigned char* ptr_; 00080 int fd; 00081 FILE* fp; 00082 struct stat myStat; 00083 00084 // variables for buffer balancing 00085 int bufferSize_; 00086 mrs_natural currentPos_; 00087 realvec reservoir_; 00088 mrs_natural reservoirSize_; 00089 mrs_natural preservoirSize_; 00090 mrs_natural pnChannels; 00091 00092 mrs_natural ri_; 00093 long offset; 00094 00095 mrs_natural advance_; 00096 mrs_natural cindex_; 00097 00098 mrs_real duration_; 00099 mrs_natural csize_; 00100 mrs_natural size_; 00101 mrs_natural samplesOut_; 00102 std::string filename_; 00103 mrs_string debug_filename; 00104 00105 mrs_real repetitions_; 00106 00107 public: 00108 00109 MP3FileSource(std::string name); 00110 MP3FileSource(const MP3FileSource& a); 00111 ~MP3FileSource(); 00112 MarSystem* clone() const; 00113 00114 void myProcess(realvec& in, realvec& out); 00115 void getHeader(std::string filename); 00116 00117 00118 }; 00119 00120 }//namespace Marsyas 00121 00122 #endif