00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "PeakFeatureSelect.h"
00020 #include "peakView.h"
00021
00022 using std::ostringstream;
00023 using namespace Marsyas;
00024
00025 PeakFeatureSelect::PeakFeatureSelect(mrs_string name):MarSystem("PeakFeatureSelect", name)
00026 {
00027 addControls();
00028 }
00029
00030 PeakFeatureSelect::PeakFeatureSelect(const PeakFeatureSelect& a) : MarSystem(a)
00031 {
00032 ctrl_selectedFeatures_ = getctrl("mrs_natural/selectedFeatures");
00033 ctrl_totalNumPeaks_ = getctrl("mrs_natural/totalNumPeaks");
00034 ctrl_frameMaxNumPeaks_ = getctrl("mrs_natural/frameMaxNumPeaks");
00035
00036 selectedFeatures_ = 0;
00037 frameMaxNumPeaks_ = 0;
00038 numFeats_ = 0;
00039 }
00040
00041 PeakFeatureSelect::~PeakFeatureSelect()
00042 {
00043 }
00044
00045 MarSystem*
00046 PeakFeatureSelect::clone() const
00047 {
00048 return new PeakFeatureSelect(*this);
00049 }
00050
00051 void
00052 PeakFeatureSelect::addControls()
00053 {
00054 addctrl("mrs_natural/selectedFeatures", 0, ctrl_selectedFeatures_);
00055 ctrl_selectedFeatures_->setState(true);
00056
00057 addctrl("mrs_natural/totalNumPeaks", 0, ctrl_totalNumPeaks_);
00058 ctrl_totalNumPeaks_->setState(true);
00059
00060 addctrl("mrs_natural/frameMaxNumPeaks", 0, ctrl_frameMaxNumPeaks_);
00061 ctrl_frameMaxNumPeaks_->setState(true);
00062
00063 selectedFeatures_ = 0;
00064 frameMaxNumPeaks_ = 0;
00065
00066 numFeats_ = 0;
00067 }
00068
00069 void
00070 PeakFeatureSelect::myUpdate(MarControlPtr sender)
00071 {
00072 (void) sender;
00073 if(ctrl_selectedFeatures_->to<mrs_natural>() != selectedFeatures_ ||
00074 ctrl_frameMaxNumPeaks_->to<mrs_natural>() != frameMaxNumPeaks_)
00075 {
00076 selectedFeatures_ = ctrl_selectedFeatures_->to<mrs_natural>();
00077 frameMaxNumPeaks_ = ctrl_frameMaxNumPeaks_->to<mrs_natural>();
00078
00079
00080 numFeats_ = 0;
00081 ostringstream oss;
00082 if(selectedFeatures_ & PeakFeatureSelect::pkFrequency)
00083 {
00084 numFeats_++;
00085 oss << "pkFrequency,";
00086 }
00087 if(selectedFeatures_ & PeakFeatureSelect::pkAmplitude)
00088 {
00089 numFeats_++;
00090 oss << "pkAmplitude,";
00091 }
00092 if(selectedFeatures_ & PeakFeatureSelect::pkDeltaFrequency)
00093 {
00094 numFeats_++;
00095 oss << "pkDeltaFrequency,";
00096 }
00097 if(selectedFeatures_ & PeakFeatureSelect::pkDeltaAmplitude)
00098 {
00099 numFeats_++;
00100 oss << "pkDeltaAmplitude,";
00101 }
00102 if(selectedFeatures_ & PeakFeatureSelect::pkFrame)
00103 {
00104 numFeats_++;
00105 oss << "pkFrame,";
00106 }
00107 if(selectedFeatures_ & PeakFeatureSelect::pkPan)
00108 {
00109 numFeats_++;
00110 oss << "pkPan,";
00111 }
00112
00113 if(selectedFeatures_ & (PeakFeatureSelect::pkSetFrequencies |
00114 PeakFeatureSelect::pkSetAmplitudes |
00115 PeakFeatureSelect::pkSetFrames))
00116 {
00117 numFeats_++;
00118 oss << "frameNumPeaks,";
00119 }
00120 if(selectedFeatures_ & PeakFeatureSelect::pkSetFrequencies)
00121 {
00122 for(mrs_natural i = 0; i < frameMaxNumPeaks_; ++i)
00123 oss << "pk_"<< i << "_Frequency,";
00124 numFeats_ += frameMaxNumPeaks_;
00125 }
00126 if(selectedFeatures_ & PeakFeatureSelect::pkSetAmplitudes)
00127 {
00128 for(mrs_natural i = 0; i < frameMaxNumPeaks_; ++i)
00129 oss << "pk_"<< i << "_Amplitude,";
00130 numFeats_ += frameMaxNumPeaks_;
00131 }
00132 if(selectedFeatures_ & PeakFeatureSelect::pkSetFrames)
00133 {
00134 for(mrs_natural i = 0; i < frameMaxNumPeaks_; ++i)
00135 oss << "pk_"<< i << "_Frame,";
00136 numFeats_ += frameMaxNumPeaks_;
00137 }
00138 if(numFeats_ == 0)
00139 oss << ",";
00140
00141 ctrl_onObsNames_->setValue(oss.str(), NOUPDATE);
00142 }
00143
00144 ctrl_onSamples_->setValue(ctrl_totalNumPeaks_->to<mrs_natural>(), NOUPDATE);
00145 ctrl_onObservations_->setValue(numFeats_, NOUPDATE);
00146 ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE);
00147 }
00148
00149 void
00150 PeakFeatureSelect::myProcess(realvec& in, realvec& out)
00151 {
00152 peakView inPeakView(in);
00153
00154
00155
00156
00157
00158
00159
00160
00161 if(ctrl_totalNumPeaks_->to<mrs_natural>() > 0 && ctrl_selectedFeatures_->to<mrs_natural>() != 0)
00162 {
00164
00166 mrs_natural peak_index = 0;
00167 for(mrs_natural f=0; f < inPeakView.getNumFrames(); ++f)
00168 {
00169 mrs_natural frameNumPeaks = inPeakView.getFrameNumPeaks(f);
00170 for(mrs_natural p=0; p<frameNumPeaks; ++p)
00171 {
00172 mrs_natural feat_index = 0;
00173
00174 if(selectedFeatures_ & PeakFeatureSelect::pkFrequency)
00175 {
00176 out(feat_index, peak_index) = inPeakView(p, peakView::pkFrequency, f);
00177 if(selectedFeatures_ & PeakFeatureSelect::barkPkFreq)
00178 {
00179 out(feat_index, peak_index) = hertz2bark(out(feat_index, peak_index));
00180 }
00181 feat_index++;
00182 }
00183 if(selectedFeatures_ & PeakFeatureSelect::pkAmplitude)
00184 {
00185 out(feat_index, peak_index) = inPeakView(p, peakView::pkAmplitude, f);
00186 if(selectedFeatures_ & PeakFeatureSelect::dBPkAmp)
00187 {
00188 out(feat_index, peak_index) = amplitude2dB(out(feat_index, peak_index));
00189 }
00190 feat_index++;
00191 }
00192 if(selectedFeatures_ & PeakFeatureSelect::pkDeltaFrequency)
00193 {
00194 out(feat_index, peak_index) = inPeakView(p, peakView::pkDeltaFrequency, f);
00195 if(selectedFeatures_ & PeakFeatureSelect::barkPkFreq)
00196 {
00197 out(feat_index, peak_index) = hertz2bark(out(feat_index, peak_index));
00198 }
00199 feat_index++;
00200 }
00201 if(selectedFeatures_ & PeakFeatureSelect::pkDeltaAmplitude)
00202 {
00203 out(feat_index, peak_index) = inPeakView(p, peakView::pkDeltaAmplitude , f);
00204 if(selectedFeatures_ & PeakFeatureSelect::dBPkAmp)
00205 {
00206 out(feat_index, peak_index) = amplitude2dB(out(feat_index, peak_index));
00207 }
00208 feat_index++;
00209 }
00210 if(selectedFeatures_ & PeakFeatureSelect::pkFrame)
00211 {
00212 out(feat_index, peak_index) = inPeakView(p, peakView::pkFrame, f);
00213 feat_index++;
00214 }
00215 if(selectedFeatures_ & PeakFeatureSelect::pkPan)
00216 {
00217 out(feat_index, peak_index) = inPeakView(p, peakView::pkPan, f);
00218 feat_index++;
00219 }
00220
00221 if(selectedFeatures_ & (PeakFeatureSelect::pkSetFrequencies |
00222 PeakFeatureSelect::pkSetAmplitudes |
00223 PeakFeatureSelect::pkSetFrames))
00224 {
00225 out(feat_index, peak_index) = frameNumPeaks;
00226 feat_index++;
00227 }
00228 if(selectedFeatures_ & PeakFeatureSelect::pkSetFrequencies)
00229 {
00230
00231 for(mrs_natural i=0; i < frameNumPeaks; ++i)
00232 {
00233 out(feat_index, peak_index) = inPeakView(i, peakView::pkFrequency, f);
00234 feat_index++;
00235 }
00236 }
00237 if(selectedFeatures_ & PeakFeatureSelect::pkSetAmplitudes)
00238 {
00239
00240 for(mrs_natural i=0; i < frameNumPeaks; ++i)
00241 {
00242 out(feat_index, peak_index) = inPeakView(i, peakView::pkAmplitude, f);
00243 feat_index++;
00244 }
00245 }
00246 if(selectedFeatures_ & PeakFeatureSelect::pkSetFrames)
00247 {
00248
00249 for(mrs_natural i=0; i < frameNumPeaks; ++i)
00250 {
00251 out(feat_index, peak_index) = inPeakView(i, peakView::pkFrame, f);
00252 feat_index++;
00253 }
00254 }
00255
00256 peak_index++;
00257 }
00258 }
00259 }
00260 }