|
CLAM-Development
1.3
|
00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 00022 #include "Complex.hxx" 00023 #include "SpecTypeFlags.hxx" 00024 #include "SpectralPeakArrayAdder.hxx" 00025 #include "BPF.hxx" 00026 #include "Point.hxx" 00027 #include "Spectrum.hxx" 00028 00029 namespace CLAM { 00030 00031 SpectralPeakArrayAdder::SpectralPeakArrayAdder(const Config &c) 00032 : mIn1("Input 1",this), 00033 mIn2("Input 2",this), 00034 mOut("Output",this) 00035 { 00036 Configure(c); 00037 } 00038 00039 00040 // Unsupervised Do() function. 00041 bool SpectralPeakArrayAdder::Do(const SpectralPeakArray& in1, const SpectralPeakArray& in2, SpectralPeakArray& out) 00042 { 00043 CLAM_DEBUG_ASSERT(IsRunning(), 00044 "SpectralPeakArrayAdder::Do(): Not in execution mode"); 00045 00046 CLAM_ASSERT((&out)!=(&in1) && (&out)!=(&in1), "SpectralPeakAdder cannot process inplace"); 00047 00048 //we initialize output peak array making sure index array is present 00049 out.AddIndexArray(); 00050 out.UpdateData(); 00051 out.SetnPeaks(0); 00052 00053 int nPeaks1=in1.GetnPeaks(); 00054 int nPeaks2=in2.GetnPeaks(); 00055 00056 if(nPeaks1==0) 00057 { 00058 out=in2; 00059 return true; 00060 } 00061 if(nPeaks2==0) 00062 { 00063 out=in1; 00064 return true; 00065 } 00066 00067 IndexArray& in1Index = in1.GetIndexArray(); 00068 /*we first multiply indices in second input by 1000 in order 00069 to avoid aliasing between indices. Note though that if this 00070 process is applied recursively indices may end up getting out 00071 of bounds*/ 00072 IndexArray& in2Index = in2.GetIndexArray(); 00073 int i; 00074 for (i=0; i<nPeaks2;i++) in2Index[i]*=1000; 00075 00076 int nSelected1, nSelected2; 00077 nSelected1 = nSelected2 = 0; 00081 do 00082 { 00083 /* TODO?: if peaks have exactly the same frequency we could think 00084 * on adding the magnitudes and adding a single peak. The problem 00085 * would then be that indices would get mixed up. Appart from that, 00086 * the synthesis process will work by adding their energy */ 00087 if(in1.GetFreq(nSelected1)<in2.GetFreq(nSelected2)) 00088 { 00089 out.AddSpectralPeak(in1.GetSpectralPeak(nSelected1), true, in1Index[nSelected1]); 00090 //std::cout<<"peak index"<<in1Index[nSelected1]<<std::endl; 00091 nSelected1++; 00092 } 00093 else 00094 { 00095 out.AddSpectralPeak(in2.GetSpectralPeak(nSelected2), true, in2Index[nSelected2]); 00096 nSelected2++; 00097 } 00098 00099 }while(nPeaks1-nSelected1 >0 && nPeaks2-nSelected2>0); 00100 00101 return true; 00102 } 00103 00104 }; 00105
1.7.6.1