00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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 "common_header.h"
00032 #include "AbsSoundFileSource.h"
00033
00034 #ifdef MARSYAS_MAD
00035 extern "C" {
00036 #include "mad.h"
00037 }
00038 #endif
00039
00040 namespace Marsyas
00041 {
00054 class MP3FileSource: public AbsSoundFileSource
00055 {
00056 private:
00057 MarControlPtr ctrl_pos_;
00058 void addControls();
00059 void myUpdate(MarControlPtr sender);
00060 mrs_natural getLinear16(realvec& slice);
00061
00062 #ifdef MARSYAS_MAD
00063
00064 inline signed int scale(mad_fixed_t sample);
00065 void madStructInitialize();
00066 void madStructFinish();
00067 #endif
00068
00069 void fillStream( long offset = 0 );
00070 void closeFile();
00071
00072 void PrintFrameInfo(struct mad_header *Header);
00073
00074
00075 #ifdef MARSYAS_MAD
00076 struct mad_stream stream;
00077 struct mad_frame frame;
00078 struct mad_synth synth;
00079 #endif
00080
00081 mrs_natural fileSize_;
00082 mrs_natural frameSamples_;
00083 mrs_natural totalFrames_;
00084 mrs_natural frameCount_;
00085 unsigned char* ptr_;
00086 int fd;
00087 FILE* fp;
00088 struct stat myStat;
00089
00090
00091 int bufferSize_;
00092 mrs_natural currentPos_;
00093 realvec reservoir_;
00094 mrs_natural reservoirSize_;
00095 mrs_natural preservoirSize_;
00096 mrs_natural pnChannels;
00097
00098 mrs_natural ri_;
00099 long offset;
00100
00101 mrs_natural advance_;
00102 mrs_natural cindex_;
00103
00104 mrs_real duration_;
00105 mrs_natural csize_;
00106 mrs_natural size_;
00107 mrs_natural samplesOut_;
00108 std::string filename_;
00109 mrs_string debug_filename;
00110
00111 mrs_real repetitions_;
00112
00113 public:
00114
00115 MP3FileSource(std::string name);
00116 MP3FileSource(const MP3FileSource& a);
00117 ~MP3FileSource();
00118 MarSystem* clone() const;
00119
00120 void myProcess(realvec& in, realvec& out);
00121 void getHeader(std::string filename);
00122
00123
00124 };
00125
00126 }
00127
00128 #endif