CLAM-Development  1.4.0
LoopingSDIFFileReader.hxx
Go to the documentation of this file.
1 #ifndef _LoopingSDIFFileReader_
2 #define _LoopingSDIFFileReader_
3 
5 #include "SDIFInConfig.hxx"
6 #include "Frame.hxx"
7 #include "SpectralPeakArray.hxx"
8 #include "Spectrum.hxx"
9 #include "SimpleLoopMetadata.hxx"
10 
11 #define DEFAULT_NUMBER_OF_CROSSFADE_FRAMES 100
12 
13 namespace CLAM
14 {
15 
24 {
25 public:
30  LoopingSDIFFileReader(const SDIFInConfig& argSDIFInConfig);
31 
33 
39  bool Configure(const SDIFInConfig& c);
40 
44  virtual Frame* ReadFrame();
45 
49  bool isLooping();
50 
54  void AddLoop(SimpleLoopMetadata& aSimpleLoop);
55 
60  void SetListOfLoops(std::vector<SimpleLoopMetadata>& theLoopList);
61 
65  void ClearLoops();
66 
70  std::vector<SimpleLoopMetadata>& GetListOfLoops();
71 
76  void Reset();
77 
78 private:
82  void CrossfadeSpectralPeakArrays(SpectralPeakArray& sourceSpectralPeaks1,
83  SpectralPeakArray& sourceSpectralPeaks2,
84  SpectralPeakArray& targetSpectralPeaks,
85  float crossfadeFactor);
86 
90  void CrossfadeResidualSpectrum(Spectrum& sourceSpectrum1,
91  Spectrum& sourceSpectrum2,
92  Spectrum& targetSpectrum,
93  float crossfadeFactor);
94 
100  int ChooseLoopRandomly(int frameBufferPosition, int indexOfCurrentLoop);
101 
102  // every time ReadFrame() is called, the frame is copied to this singleton
103  // object which is returned rather than the frame from the BufferedSDIFReader
104  Frame* outgoingFrame;
105  // number of frames that should be crossfaded before looping
106  int numberOfCrossfadeFrames;
107  // a list of loop points for this sample
108  std::vector<SimpleLoopMetadata> listOfLoops;
109  // the index of the loop that we are currently using
110  int indexOfCurrentLoop;
111 };
112 
113 } // end namespace CLAM
114 
115 #endif