Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2007 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #include "../common_source.h" 00020 #include "StereoSpectrumSources.h" 00021 #include "Peaker.h" 00022 00023 using namespace std; 00024 using namespace Marsyas; 00025 00026 StereoSpectrumSources::StereoSpectrumSources(mrs_string name):MarSystem("StereoSpectrumSources", name) 00027 { 00028 panPeaker_ = new Peaker("panPeaker"); 00029 } 00030 00031 StereoSpectrumSources::StereoSpectrumSources(const StereoSpectrumSources& a):MarSystem(a) 00032 { 00033 panPeaker_ = new Peaker("panPeaker"); 00034 } 00035 00036 StereoSpectrumSources::~StereoSpectrumSources() 00037 { 00038 delete panPeaker_; 00039 } 00040 00041 MarSystem* 00042 StereoSpectrumSources::clone() const 00043 { 00044 return new StereoSpectrumSources(*this); 00045 } 00046 00047 void 00048 StereoSpectrumSources::myUpdate(MarControlPtr sender) 00049 { 00050 (void) sender; //suppress warning of unused parameter(s) 00051 MRSDIAG("StereoSpectrumSources.cpp - StereoSpectrumSources:myUpdate"); 00052 00053 ctrl_onSamples_->setValue(ctrl_inSamples_, NOUPDATE); 00054 ctrl_onObservations_->setValue(1, NOUPDATE); 00055 ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE); 00056 ctrl_onObsNames_->setValue("StereoSpectrumSources,", NOUPDATE); 00057 00058 panPeaker_->updControl("mrs_natural/inSamples", inObservations_-1); 00059 panPeaker_->updControl("mrs_natural/inObservations", 1); 00060 panPeaker_->updControl("mrs_natural/peakStart", 0); 00061 panPeaker_->updControl("mrs_natural/peakEnd", inObservations_-2); 00062 panPeaker_->updControl("mrs_real/peakStrength", 1.0); 00063 } 00064 00065 void 00066 StereoSpectrumSources::myProcess(realvec& in, realvec& out) 00067 { 00068 mrs_natural t,o; 00069 for (t = 0; t < inSamples_; t++) 00070 { 00071 //start by sorting in non-descending order the panning values 00072 //of all spectrum bins of the current frame 00073 in.getCol(t, orderedPans_); 00074 orderedPans_.sort(); 00075 00076 //MATLAB_PUT(orderedPans_, "orderedPans"); 00077 //MATLAB_EVAL("plot(orderedPans)"); 00078 00079 //calculate derivative, i.e changes of panning 00080 panChanges_.create(inObservations_-1); 00081 for(o=0; o<inObservations_-1; ++o) 00082 panChanges_(o) = orderedPans_(o+1)-orderedPans_(o); 00083 00084 //MATLAB_PUT(panChanges_, "panChanges"); 00085 //MATLAB_EVAL("plot(panChanges)"); 00086 00087 //look for peaks in pan changes, i.e. a good estimate of 00088 //the number of stereo sources in the signal 00089 panPeaks_.create(inObservations_-1); 00090 panPeaker_->process(panChanges_, panPeaks_); 00091 00092 //MATLAB_PUT(panPeaks_, "panPeaks"); 00093 //MATLAB_EVAL("plot(panPeaks)"); 00094 00095 out(0, t) = 0.0; 00096 for(o=0; o < inObservations_-1; ++o) 00097 out(0,t) += (panPeaks_(o) != 0.0);//peaks are the non-zero values in panPeaks_ 00098 00099 //cout << out(0,t) << endl; 00100 00101 // other option for calculating this (pseudo-code): 00102 // if abs(running-average - current_value) > 0.3 * running_average 00103 } 00104 }