00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "PeakerOnset.h"
00020
00021 using namespace std;
00022 using namespace Marsyas;
00023
00024 PeakerOnset::PeakerOnset(mrs_string name):MarSystem("PeakerOnset", name)
00025 {
00026 addControls();
00027
00028 prevValue_ = 0.0;
00029 t_ = 0;
00030 }
00031
00032 PeakerOnset::PeakerOnset(const PeakerOnset& a) : MarSystem(a)
00033 {
00034 ctrl_lookAheadSamples_ = getctrl("mrs_natural/lookAheadSamples");
00035 ctrl_threshold_ = getctrl("mrs_real/threshold");
00036 ctrl_onsetDetected_ = getctrl("mrs_bool/onsetDetected");
00037 ctrl_confidence_ = getctrl("mrs_real/confidence");
00038
00039 prevValue_ = a.prevValue_;
00040 t_ = a.t_;
00041 }
00042
00043 PeakerOnset::~PeakerOnset()
00044 {
00045 }
00046
00047 MarSystem*
00048 PeakerOnset::clone() const
00049 {
00050 return new PeakerOnset(*this);
00051 }
00052
00053 void
00054 PeakerOnset::addControls()
00055 {
00056 addctrl("mrs_natural/lookAheadSamples", 0, ctrl_lookAheadSamples_);
00057 addctrl("mrs_real/threshold", 0.0, ctrl_threshold_);
00058 addctrl("mrs_bool/onsetDetected", false, ctrl_onsetDetected_);
00059 addctrl("mrs_real/confidence", 0.0, ctrl_confidence_);
00060 }
00061
00062 void
00063 PeakerOnset::myUpdate(MarControlPtr sender)
00064 {
00065 MRSDIAG("PeakerOnset.cpp - PeakerOnset:myUpdate");
00066
00067 ctrl_onSamples_->setValue(1, NOUPDATE);
00068 if(inObservations_ > 1)
00069 {
00070 MRSWARN("PeakerOnset::myUpdate() - inObservations is bigget than 1. This MarSystem only takes the first observation into consideration...");
00071 }
00072 ctrl_onObservations_->setValue(1, NOUPDATE);
00073 ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE);
00074 ctrl_onObsNames_->setValue("onset_confidence");
00075
00076 if(inSamples_ < 1 + 2 * ctrl_lookAheadSamples_->to<mrs_natural>())
00077 {
00078 cout << "inSamples_ = " << inSamples_ << endl;
00079 cout << "lookAhead = " << ctrl_lookAheadSamples_->to<mrs_natural>() << endl;
00080 MRSWARN("PeakerOnset::myUpdate() - inSamples is too small for specified onsetWinSize: onset detection not possible to be performed!");
00081 ctrl_lookAheadSamples_->setValue(0, NOUPDATE);
00082 }
00083 }
00084
00085 void
00086 PeakerOnset::myProcess(realvec& in, realvec& out)
00087 {
00088 mrs_natural o,t;
00089 (void) o;
00090 ctrl_onsetDetected_->setValue(false);
00091 ctrl_confidence_->setValue(0.0);
00092 out.setval(0.0);
00093
00094 mrs_natural w = ctrl_lookAheadSamples_->to<mrs_natural>();
00095
00096 if(w == 0)
00097 return;
00098
00099
00100 mrs_natural checkPoint = inSamples_-1-w;
00101 mrs_real checkPointValue = in(checkPoint);
00102 mrs_bool isOnset = true;
00103
00104
00105 mrs_natural interval = mrs_natural(2.0/3.0*w);
00106
00107 for(t=checkPoint-interval; t <= checkPoint+interval; t++)
00108 {
00109 if(checkPointValue < in(t))
00110 {
00111 isOnset = false;
00112 MRSDIAG("PeakerOnset::myProcess() - Failed 1st condition!");
00113 break;
00114 }
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 mrs_natural mul = 3;
00157 mrs_real m = 0.0;
00158 for(t=checkPoint-(mul*w); t < inSamples_; t++)
00159 m += in(t);
00160 m /= (w*4+1);
00161
00162
00163
00164
00165 if(checkPointValue <= (m * ctrl_threshold_->to<mrs_real>()) || m < 10e-20)
00166 {
00167 isOnset = false;
00168 MRSDIAG("PeakerOnset::myProcess() - Failed 2nd condition!");
00169 }
00170
00171
00172
00173
00174 if(isOnset)
00175 {
00176 ctrl_onsetDetected_->setValue(true);
00177 ctrl_confidence_->setValue(1.0);
00178 out.setval(1.0);
00179 MRSDIAG("PeakerOnset::myProcess() - Onset Detected!");
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 }