Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2006 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 "PeakLabeler.h" 00021 #include <marsyas/peakView.h> 00022 00023 using std::ostringstream; 00024 using namespace Marsyas; 00025 00026 //#define MTLB_DBG_LOG 00027 00028 PeakLabeler::PeakLabeler(mrs_string name):MarSystem("PeakLabeler", name) 00029 { 00030 addControls(); 00031 } 00032 00033 PeakLabeler::PeakLabeler(const PeakLabeler& a) : MarSystem(a) 00034 { 00035 ctrl_peakLabels_ = getctrl("mrs_realvec/peakLabels"); 00036 } 00037 00038 PeakLabeler::~PeakLabeler() 00039 { 00040 } 00041 00042 MarSystem* 00043 PeakLabeler::clone() const 00044 { 00045 return new PeakLabeler(*this); 00046 } 00047 00048 void 00049 PeakLabeler::addControls() 00050 { 00051 addctrl("mrs_realvec/peakLabels", realvec(), ctrl_peakLabels_); 00052 } 00053 00054 void 00055 PeakLabeler::myUpdate(MarControlPtr sender) 00056 { 00057 //the out flow parameters are the same as the out flow ones 00058 MarSystem::myUpdate(sender); 00059 } 00060 00061 void 00062 PeakLabeler::myProcess(realvec& in, realvec& out) 00063 { 00064 out = in; 00065 00066 peakView outPeakView(out); 00067 00068 mrs_natural maxNumPeaks = outPeakView.getFrameMaxNumPeaks(); 00069 const realvec& peakLabels = ctrl_peakLabels_->to<mrs_realvec>(); //reading unlocked and linked control!!! --> should use MarControlAccessor [TODO][!] 00070 00071 if((mrs_natural)peakLabels.getSize() != outPeakView.getTotalNumPeaks()) 00072 { 00073 MRSERR("PeakLabeler::myProcess - peakLabels control and input peaks number mismatch! Labeling not performed!"); 00074 } 00075 else 00076 { 00077 //fill in the peak labeling using the info 00078 //from the peakLabels control (if any) 00079 labelIdx_ = 0; 00080 for(mrs_natural f=0; f < outPeakView.getNumFrames(); ++f) 00081 { 00082 for(mrs_natural p=0; p < outPeakView.getFrameNumPeaks(f); ++p) 00083 { 00084 // outPeakView(p, peakView::pkGroup, f) = peakLabels(labelIdx_); // assignment operator doesn't seem to work 00085 out(p + maxNumPeaks*peakView::pkGroup, f) = peakLabels(labelIdx_); 00086 labelIdx_++; 00087 } 00088 } 00089 } 00090 00091 #ifdef MARSYAS_MATLAB 00092 #ifdef MTLB_DBG_LOG 00093 MATLAB_PUT(out, "out"); 00094 MATLAB_PUT((mrs_natural)peakView::nbPkParameters, "numPeakParams"); 00095 MATLAB_EVAL("numPeaks = size(out,1)/numPeakParams;"); 00096 MATLAB_EVAL("numFrames = size(out,2);"); 00097 MATLAB_EVAL("groupIdx = 6;"); 00098 MATLAB_EVAL("dispRange = -1 + min([min(min(out(1+numPeaks*groupIdx:numPeaks*(groupIdx+1),1:numFrames))) -max(max(out(1+numPeaks*groupIdx:numPeaks*(groupIdx+1),1:numFrames)))]);"); 00099 MATLAB_EVAL("dispFreqRange = 100:20:3000;"); 00100 MATLAB_EVAL("spectrogram = zeros(length(dispFreqRange), size(out,2))+dispRange;"); 00101 MATLAB_EVAL("for (f=1:numFrames) for (i=1:numPeaks) [v,freqIdx] = min(abs(dispFreqRange - out(i,f))); spectrogram(freqIdx,f) = out(i+numPeaks*groupIdx,f); end; end;"); 00102 MATLAB_EVAL("figure(82),imagesc(1:10,dispFreqRange,spectrogram,[dispRange abs(dispRange)]),colorbar,xlabel('frames'),ylabel('frequency'),title('Clusters')"); 00103 #endif 00104 #endif 00105 }