00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "PitchDiff.h"
00020
00021 using std::ostringstream;
00022 using namespace Marsyas;
00023
00024 PitchDiff::PitchDiff(mrs_string name) : MarSystem("PitchDiff", name)
00025 {
00027 addControls();
00028 }
00029
00030 PitchDiff::PitchDiff(const PitchDiff& a) : MarSystem(a)
00031 {
00034 ctrl_expectedPitch_ = getctrl("mrs_real/expectedPitch");
00035 ctrl_ignoreOctaves_ = getctrl("mrs_bool/ignoreOctaves");
00036 ctrl_absoluteValue_ = getctrl("mrs_bool/absoluteValue");
00037 }
00038
00039
00040 PitchDiff::~PitchDiff()
00041 {
00042 }
00043
00044 MarSystem*
00045 PitchDiff::clone() const
00046 {
00047 return new PitchDiff(*this);
00048 }
00049
00050 void
00051 PitchDiff::addControls()
00052 {
00054 addctrl("mrs_real/expectedPitch", 440.0, ctrl_expectedPitch_);
00055 addctrl("mrs_bool/ignoreOctaves", false, ctrl_ignoreOctaves_);
00056 addctrl("mrs_bool/absoluteValue", false, ctrl_absoluteValue_);
00057 setctrlState("mrs_real/expectedPitch", true);
00058 }
00059
00060 void
00061 PitchDiff::myUpdate(MarControlPtr sender)
00062 {
00063 MRSDIAG("PitchDiff.cpp - PitchDiff:myUpdate");
00064
00066 MarSystem::myUpdate(sender);
00067
00068
00069 mrs_string inObsNames = ctrl_inObsNames_->to<mrs_string>();
00070 ctrl_onObsNames_->setValue(obsNamesAddPrefix(inObsNames, "PitchDiff_"),
00071 NOUPDATE);
00072
00073 expectedMidiPitch_ = hertz2pitch(ctrl_expectedPitch_->to<mrs_real>());
00074 }
00075
00076 void
00077 PitchDiff::myProcess(realvec& in, realvec& out)
00078 {
00080 for (o = 0; o < inObservations_; o++)
00081 {
00082
00083
00084
00085 mrs_real in_midi = hertz2pitch(in(o,0));
00086
00087 mrs_real diff = in_midi - expectedMidiPitch_;
00088 if (ctrl_ignoreOctaves_->isTrue()) {
00089 diff = fmod(diff, 12.0);
00090
00091
00092 if (diff > 6) {
00093 diff -= 12.0;
00094 }
00095 if (diff < -6) {
00096 diff += 12.0;
00097 }
00098 }
00099 if (ctrl_absoluteValue_->isTrue()) {
00100 diff = fabs(diff);
00101 }
00102 out(o, 0) = diff;
00103 }
00104 }