Audio.h

Go to the documentation of this file.
00001 
00024 #ifndef _AUDIO_H
00025 #define _AUDIO_H
00026 
00027 #include "../Numerical.h"
00028 #include "PaWrapper.h"
00029 
00030 #ifndef _WIN32_WCE
00031 
00039 class FEATURE_EXPORT_CLASS AudioBandFeature : public NumericalContinuousFeature
00040 {
00041         friend class AudioFeatureProvider;
00042 
00043         protected:
00059                 AudioBandFeature(double* minval, double* maxval) : NumericalContinuousFeature(minval, maxval) {}
00060 
00075                 AudioBandFeature(double* minval, double* maxval, double val) : NumericalContinuousFeature(minval, maxval, val) {}
00076 
00077         public:
00078                 virtual const string getName() const { return "Audio.Band"; }
00079 
00080 #if _DEBUG_FEATURES
00081                 virtual string toString() const;
00082 #endif
00083 };
00084 #endif
00085 
00093 class FEATURE_EXPORT_CLASS AudioMeanFeature : public NumericalContinuousFeature
00094 {
00095         friend class AudioFeatureProvider;
00096 
00097         protected:
00113                 AudioMeanFeature(double* minval, double* maxval) : NumericalContinuousFeature(minval, maxval) {}
00114 
00129                 AudioMeanFeature(double* minval, double* maxval, double mean) : NumericalContinuousFeature(minval, maxval, mean) {}
00130 
00131         public:
00132                 virtual const string getName() const { return "Audio.Mean"; }
00133 
00134 #if _DEBUG_FEATURES
00135                 virtual string toString() const;
00136 #endif
00137 };
00138 
00147 class FEATURE_EXPORT_CLASS AudioPeakFeature : public NumericalDiscreteFeature 
00148 {
00149         friend class AudioFeatureProvider;
00150 
00151         protected:
00167                 AudioPeakFeature(long* minval, long* maxval) : NumericalDiscreteFeature(minval, maxval) {}
00168 
00183                 AudioPeakFeature(long* minval, long* maxval, unsigned peaks) : NumericalDiscreteFeature(minval, maxval, peaks) {}
00184 
00185         public:
00186                 virtual const string getName() const { return "Audio.Peaks"; }
00187 
00188 #if _DEBUG_FEATURES
00189                 virtual string toString() const;
00190 #endif
00191 };
00192 
00196 class FEATURE_EXPORT_CLASS AudioFeatureProvider : public FeatureProvider
00197 {
00198         private:
00202                 struct SampleData {
00204 
00206                         double *spectrum;
00207                         unsigned long spectrum_counter;
00208 
00209                         double average;
00210                         unsigned long average_counter;
00211 
00212                         double average2;
00213                         double average2_old;
00214                         unsigned long average2_counter;
00215 
00216                         double treshold;
00217                         unsigned long peaks;
00218                         bool peak;
00220 
00226                         SampleData(unsigned bands=0) {
00227                                 spectrum_counter = 0;
00228                                 if (bands != 0)
00229                                         spectrum = new double[bands];
00230                                 else
00231                                         spectrum = NULL;
00232                                 for (unsigned i = 0; i < bands; i++) {
00233                                         spectrum[i] = 0.0;
00234                                 }
00235 
00236                                 average_counter = 0;
00237                                 average = 0.0;
00238 
00239                                 average2_counter = 0;
00240                                 average2 = 0.0;
00241                                 average2_old = 0.0;
00242 
00243                                 treshold = 10000.0;             // init 10000.0
00244                                 peaks = 0;
00245                                 peak = true;
00246                         }
00247 
00249                         ~SampleData() {
00250                                 if (spectrum != NULL) {
00251                                         delete spectrum;
00252                                 }
00253                         }
00254                 };
00255 
00257                 stringvector features;
00259                 unsigned bands;
00260 
00262 
00264                 double audioBandFeature_minval;
00265                 double audioBandFeature_maxval;
00266                 double audioMeanFeature_minval;
00267                 double audioMeanFeature_maxval;
00268                 long audioPeaksFeature_minval;
00269                 long audioPeaksFeature_maxval;
00270 
00271                 PaDeviceID device;
00272                 PortAudioStream *stream;
00273                 SampleData current;
00274                 SampleData processed;
00276 
00278                 static int audioCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, PaTimestamp outTime, void *userData);
00279 
00280         public:
00281                 AudioFeatureProvider(providerparams &params);
00282                 virtual ~AudioFeatureProvider();
00283 
00284                 virtual Feature* getFeature(string name) const;
00285                 virtual Feature* getSample(string name) const;
00286                 virtual void nextSample(clock_t checkpoint);
00287 };
00288 
00289 #endif // _AUDIO_H

Generated on Mon Jun 5 10:20:42 2006 for Intelligence.kdevelop by  doxygen 1.4.6