00001 #ifndef _LoopingSDIFFileReader_ 00002 #define _LoopingSDIFFileReader_ 00003 00004 #include "BufferedSDIFFileReader.hxx" 00005 #include "SDIFInConfig.hxx" 00006 #include "Frame.hxx" 00007 #include "SpectralPeakArray.hxx" 00008 #include "Spectrum.hxx" 00009 #include "SimpleLoopMetadata.hxx" 00010 00011 #define DEFAULT_NUMBER_OF_CROSSFADE_FRAMES 100 00012 00013 namespace CLAM 00014 { 00015 00023 class LoopingSDIFFileReader : public BufferedSDIFFileReader 00024 { 00025 public: 00030 LoopingSDIFFileReader(const SDIFInConfig& argSDIFInConfig); 00031 00032 ~LoopingSDIFFileReader(); 00033 00039 bool Configure(const SDIFInConfig& c); 00040 00044 virtual Frame* ReadFrame(); 00045 00049 bool isLooping(); 00050 00054 void AddLoop(SimpleLoopMetadata& aSimpleLoop); 00055 00060 void SetListOfLoops(std::vector<SimpleLoopMetadata>& theLoopList); 00061 00065 void ClearLoops(); 00066 00070 std::vector<SimpleLoopMetadata>& GetListOfLoops(); 00071 00076 void Reset(); 00077 00078 private: 00082 void CrossfadeSpectralPeakArrays(SpectralPeakArray& sourceSpectralPeaks1, 00083 SpectralPeakArray& sourceSpectralPeaks2, 00084 SpectralPeakArray& targetSpectralPeaks, 00085 float crossfadeFactor); 00086 00090 void CrossfadeResidualSpectrum(Spectrum& sourceSpectrum1, 00091 Spectrum& sourceSpectrum2, 00092 Spectrum& targetSpectrum, 00093 float crossfadeFactor); 00094 00100 int ChooseLoopRandomly(int frameBufferPosition, int indexOfCurrentLoop); 00101 00102 // every time ReadFrame() is called, the frame is copied to this singleton 00103 // object which is returned rather than the frame from the BufferedSDIFReader 00104 Frame* outgoingFrame; 00105 // number of frames that should be crossfaded before looping 00106 int numberOfCrossfadeFrames; 00107 // a list of loop points for this sample 00108 std::vector<SimpleLoopMetadata> listOfLoops; 00109 // the index of the loop that we are currently using 00110 int indexOfCurrentLoop; 00111 }; 00112 00113 } // end namespace CLAM 00114 00115 #endif