SpectralCombTriang.cxx

Go to the documentation of this file.
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 "SpectralCombTriang.hxx"
00023 #include "ProcessingFactory.hxx"
00024 
00025 namespace CLAM
00026 {
00027 
00028 namespace Hidden
00029 {
00030         static const char * metadata[] = {
00031                 "key", "SpectralCombTriang",
00032         //      "category", "Spectral Transformations",
00033         //      "description", "SpectralCombTriang",
00034                 0
00035         };
00036         static FactoryRegistrator<ProcessingFactory, SpectralCombTriang> reg = metadata;
00037 }
00038 
00039 
00040 bool SpectralCombTriang::Do(const Spectrum& in, Spectrum& out)
00041 {
00042         if (!mConfig.GetPreserveOuts())
00043         {
00044                 out = in; //TODO big cludge for streaming
00045         }
00046         DataArray& inMag = in.GetMagBuffer();
00047         DataArray& outMag = out.GetMagBuffer();
00048         
00049         int spectrumSize = in.GetSize();
00050         
00051         TData spectralResolution = spectrumSize/in.GetSpectralRange();
00052         int fundamental = Round(mFundamentalCtl.GetLastValue()* spectralResolution);
00053         
00054         int i;
00055         int n;
00056         n = 0;
00057         int bandlimit = fundamental;
00058         //control expected in dB
00059         TData overallGain = log2lin(mAmount.GetLastValue());
00060         for(i = 0; i<spectrumSize; i++)
00061         {
00062                 if(i > bandlimit)
00063                 {
00064                         n++;
00065                         bandlimit = fundamental * n;
00066                 }
00067                 outMag[i] = inMag[i]*GetGain(fundamental, i, n)*overallGain;
00068         }
00069         return true;
00070 }
00071 
00072 TData SpectralCombTriang::GetGain(int fundamental, int binPos, int bandNum)
00073 {
00074         //first we find whether the binPos is on a positive or negative slope part
00075         //auxiliary data
00076         TData period = fundamental;
00077         
00078         //compute mid point
00079         int midPoint = int (period * 0.5);
00080         
00081         bool ascending = false;
00082         if ((binPos - fundamental*bandNum)> midPoint || bandNum == 0) ascending = true;
00083         
00084                 
00085         //compute linear equation y = ax + b
00086         //first the 'a'
00087         TData a = 2/fundamental;
00088         if (!ascending) a = -a;
00089         //now the 'b'
00090         TData b = 1;
00091         if(ascending) b = 0;
00092         //now the x
00093         int x;
00094         if (bandNum==0) x = binPos;
00095         else if(ascending) x = binPos - int(fundamental*bandNum + midPoint);
00096         else x = binPos - int(fundamental * bandNum);
00097         
00098         //ready to compute the gain
00099         return a*x + b;
00100 }
00101 
00102 
00103 }
00104 
Generated by  doxygen 1.6.3