00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MARSYAS_PEAKVIEW_H
00020 #define MARSYAS_PEAKVIEW_H
00021
00022 #include "realvec.h"
00023 #include <vector>
00024 #include "DLLDefines.h"
00025
00026 namespace Marsyas
00027 {
00034 class marsyas_EXPORT peakView
00035 {
00036 public:
00037 enum pkParameter{
00038 pkFrequency,
00039 pkAmplitude,
00040 pkPhase,
00041 pkDeltaFrequency,
00042 pkDeltaAmplitude,
00043 pkFrame,
00044 pkGroup,
00045 pkVolume,
00046 pkPan,
00047 pkBinLow,
00048 pkBin,
00049 pkBinHigh,
00050 pkTrack,
00051 nbPkParameters
00052 };
00053
00054 private:
00055 realvec& vec_;
00056
00057 mrs_real fs_;
00058 mrs_natural frameSize_;
00059
00060 mrs_natural frameMaxNumPeaks_;
00061 mrs_natural numFrames_;
00062
00063 public:
00064
00065 peakView(realvec& vec);
00066 ~peakView();
00067
00068 void fromTable(const realvec& vecTable);
00069 void toTable(realvec& vecTable);
00070
00071 mrs_real getFs() const {return fs_;};
00072 mrs_natural getFrameSize() const {return frameSize_;};
00073
00074 mrs_natural getNumFrames() const {return numFrames_;};
00075 mrs_natural getNumGroups();
00076
00077 mrs_natural getFrameMaxNumPeaks() const {return frameMaxNumPeaks_;};
00078 mrs_natural getFrameNumPeaks(const mrs_natural frame=0, const mrs_natural group=-1) const;
00079 mrs_natural getTotalNumPeaks(const mrs_natural group=-1) const;
00080
00081 void getPeaksParam(std::vector<realvec>& result, const pkParameter param, mrs_natural startFrame = 0, mrs_natural endFrame = 0) const;
00082
00083 mrs_real& operator()(const mrs_natural peakIndex, const pkParameter param, const mrs_natural frame=0, const mrs_natural group=-1);
00084 mrs_real operator()(const mrs_natural peakIndex, const pkParameter param, const mrs_natural frame=0, const mrs_natural group=-1) const;
00085
00086 static std::string getParamName(mrs_natural paramIdx);
00087
00088 bool peakWrite(std::string filename, mrs_real fs=0, mrs_natural frameSize=0);
00089 bool peakRead(std::string filename);
00090
00091 void removePeak (const mrs_natural peakIndex, const mrs_natural frame);
00092 };
00093
00094 inline
00095 mrs_real& peakView::operator()(const mrs_natural peakIndex, const pkParameter param, const mrs_natural frame, const mrs_natural group)
00096 {
00097
00098
00099 if(group == -1)
00100 return vec_(peakIndex + param * frameMaxNumPeaks_, frame);
00101 else
00102 {
00103
00104
00105 mrs_natural gp = 0;
00106 for(mrs_natural p = 0; p < this->getFrameNumPeaks(frame); ++p)
00107 {
00108 if(vec_(p + pkGroup * frameMaxNumPeaks_, frame) == group)
00109 {
00110 if(peakIndex == gp)
00111 return vec_(p + param * frameMaxNumPeaks_, frame);
00112 gp++;
00113 }
00114 }
00115
00116
00117 MRSERR("peakView::operator() - peakIndex " << peakIndex << " not found in passed group " << group);
00118 return vec_(peakIndex + param * frameMaxNumPeaks_, frame);
00119 }
00120 }
00121
00122 inline
00123 mrs_real peakView::operator()(const mrs_natural peakIndex, const pkParameter param, const mrs_natural frame, const mrs_natural group) const
00124 {
00125
00126
00127 if(group == -1)
00128 return vec_(peakIndex + param * frameMaxNumPeaks_, frame);
00129 else
00130 {
00131
00132
00133 mrs_natural gp = 0;
00134 for(mrs_natural p = 0; p < this->getFrameNumPeaks(frame); ++p)
00135 {
00136 if(vec_(p + pkGroup * frameMaxNumPeaks_, frame) == group)
00137 {
00138 if(peakIndex == gp)
00139 return vec_(p + param * frameMaxNumPeaks_, frame);
00140 gp++;
00141 }
00142 }
00143
00144
00145 MRSERR("peakView::operator() - peakIndex " << peakIndex << " not found in passed group " << group);
00146 return -1.0;
00147 }
00148 }
00149
00150 }
00151
00152 #endif
00153