Copiste  0.1
 All Classes Functions Variables Enumerations Friends Pages
soundanalyser.h
1 /*
2  * This file is part of Copiste.
3  *
4  * Copiste is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Copiste is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Copiste. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 #ifndef INCLUDED_SOUNDANALYSERH
20 #define INCLUDED_SOUNDANALYSERH
21 
23 class SoundAnalyser;
24 
25 // Libraries
26 #include <vector>
27 #include <utility>
28 #include <string>
29 
30 // Stream handling
31 #include "core/streamplayer.h"
32 #include "features/extractor.h"
33 
34 // Features
35 #include "features/spectrum.h"
36 #include "features/zcr.h"
37 #include "features/hzcrr.h"
38 #include "features/ste.h"
39 #include "features/lster.h"
40 
41 // Storage
42 #include "algo/corpus.h"
43 
44 // Filters
45 #include "filters/average.h"
46 #include "filters/flux.h"
47 #include "filters/range.h"
48 #include "filters/highlowratio.h"
49 #include "filters/centroid.h"
50 #include "filters/memory.h"
51 #include "filters/compare.h"
52 #include "filters/mel.h"
53 #include "filters/distance.h"
54 
55 using namespace std;
56 
57 
88 class SoundAnalyser : protected StreamPlayer
89 {
90  public:
92  SoundAnalyser(bool live = false);
94  ~SoundAnalyser();
95 
97 
99  void resetExtractors();
101  void cleanExtractors();
103  void registerExtractor(string name, FeatureExtractor* extr, bool used = true, bool drawLines = true);
105  FeatureExtractor* getExtractor(string name);
106 
108 
110  bool setupPipeline(string filename);
112  void setNormalization(float min, float max);
114  bool compute(string url);
116  void waitComputed();
117 
119 
121  unsigned int nbFeatures() { return mExtr.size(); }
123  unsigned int nbElems(unsigned int n);
125  unsigned int nbSamples() { return mFeatures.size(); }
127  unsigned int dimension() { return mDimension; }
129  unsigned int realDimension() { return mRealDimension; }
130 
131  // Features management : data
132 
134  double** features(unsigned int n);
136  void clearFeatures();
138  void cleanOldFeatures(unsigned int newestCount);
139 
141 
143  bool isUsed(unsigned int index);
145  bool isDrawnWithLines(unsigned int index);
147  string name(unsigned int n);
149  int getFeatureByName(string name);
150 
152 
154  void useBuffer();
156  void sequenceEnds();
158  virtual void useFeatures() { ; }
159 
161 
163  unsigned int samplingFrequency() { return mFrequency; }
164 
165  private:
166  vector<pair<string, FeatureExtractor* > > mExtr; // TODO : it could be an hashtable
167  vector<bool> mUsed;
168  vector<bool> mDrawLines;
169  vector<double**> mFeatures;
170 
171  int mDimension;
172  int mRealDimension;
173  int mUsedExtractors;
174 
175  bool mNormalize;
176  float mOverlapping;
177  float mMinFeature;
178  float mMaxFeature;
179 
180  boost::mutex mSwitchLock;
181  bool mComputed;
182  libvlc_time_t mLastUpdateTime;
183 };
184 
185 #endif