SpectralAnalysisConfig.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 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 "SpectralAnalysisConfig.hxx"
00023 #include "CLAM_Math.hxx"
00024 
00025 #include <iostream>
00026 
00027 namespace CLAM
00028 {
00029 
00030 void SpectralAnalysisConfig::DefaultInit()
00031 {
00032   
00033   AddAll();
00034   UpdateData();
00035   DefaultValues();      
00036 }
00037 
00038 void SpectralAnalysisConfig::DefaultValues()
00039 {
00040 
00041         SetprSamplingRate(44100);
00043         SetprZeroPadding(0);
00044 
00045         SetprHopSize(0);//for preventing reading uninitialized memory
00046 
00048         SetWindowSize(1025);
00049         SetWindowType(EWindowType::eBlackmanHarris92);
00050         
00052         SetHopSize((GetWindowSize()-1)/2);
00053 
00054         GetCircularShift().SetAmount(-(GetWindowSize()-1)/2);
00055 
00056 }
00057 
00058 
00059 void SpectralAnalysisConfig::SetWindowSize(TSize w)
00060 {
00061         CLAM_ASSERT(w%2==1,"Window size must be odd");
00062         SetprWindowSize(w);
00063         GetWindowGenerator().SetSize(w);
00064         SetprFFTSize(nextPowerOfTwo( int( (w-1)*CLAM_pow(TData(2),TData(GetZeroPadding())) ) ) );
00065         GetCircularShift().SetAmount(-((w-1)/TData(2))); 
00066         GetFFT().SetAudioSize(GetprFFTSize());
00067         if(w<2*GetHopSize()+1)
00068                 SetHopSize((w-1)/2);
00069 
00070 }
00071 
00072 TSize SpectralAnalysisConfig::GetWindowSize() const
00073 {
00074         return GetWindowGenerator().GetSize();
00075 }
00076 
00078 void SpectralAnalysisConfig::SetWindowType(const EWindowType& t)
00079 {
00080         SetprWindowType(t);
00081         GetWindowGenerator().SetType(t);
00082 }
00083 
00084 const EWindowType& SpectralAnalysisConfig::GetWindowType() const
00085 {
00086         return GetWindowGenerator().GetType();
00087 }
00088 
00090 void SpectralAnalysisConfig::SetZeroPadding(int z)
00091 {
00092         SetprZeroPadding(z);
00093         SetprFFTSize(nextPowerOfTwo( int( (GetWindowSize()-1) * CLAM_pow(TData(2),TData(GetZeroPadding())) ) ) );
00094         GetFFT().SetAudioSize(GetprFFTSize());
00095 }
00096 
00097 int SpectralAnalysisConfig::GetZeroPadding() const
00098 {
00099         return GetprZeroPadding();
00100 }
00101 
00102 
00103 
00104 void SpectralAnalysisConfig::SetHopSize(TSize h)
00105 {
00106         SetprHopSize(h);
00107 }
00108 
00109 TSize SpectralAnalysisConfig::GetHopSize() const
00110 {
00111         return GetprHopSize();
00112 }
00113 
00115 void SpectralAnalysisConfig::SetSamplingRate(TData sr)
00116 {
00117         SetprSamplingRate(int(sr));
00119         SetWindowSize(GetWindowSize());
00120 }
00121 
00122 TData SpectralAnalysisConfig::GetSamplingRate() const
00123 {
00124         return GetprSamplingRate();
00125 }
00126 
00127 
00128 void  SpectralAnalysisConfig::Sync()
00129 {
00130   
00131         int zp = GetprZeroPadding();
00132         int ws = GetprWindowSize();
00133         SetSamplingRate(GetprSamplingRate());
00134 
00135         SetZeroPadding(zp);
00136 
00137         SetWindowSize(ws);
00138         SetWindowType(GetprWindowType());  
00139 
00140         SetHopSize(GetprHopSize());
00141 }
00142 
00143 } // namespace CLAM
00144 
Generated by  doxygen 1.6.3