00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "common.h"
00020 #include "PeakLabeler.h"
00021 #include "peakView.h"
00022
00023 using std::ostringstream;
00024 using namespace Marsyas;
00025
00026
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
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>();
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
00078
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
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 }