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 "CLAM_Math.hxx" 00023 #include "SpectralSynthesisConfig.hxx" 00024 00025 namespace CLAM 00026 { 00027 00028 void SpectralSynthesisConfig::DefaultInit() 00029 { 00030 AddAll(); 00031 UpdateData(); 00032 DefaultValues(); 00033 } 00034 00035 void SpectralSynthesisConfig::DefaultValues() 00036 { 00038 SetprZeroPadding(0); 00039 SetSamplingRate(44100); 00040 00042 SetAnalWindowSize(1025); 00043 SetAnalWindowType(EWindowType::eBlackmanHarris92); 00044 GetAnalWindowGenerator().SetInvert(true); 00045 00047 SetHopSize((GetAnalWindowSize()-1)/2); 00048 00050 GetSynthWindowGenerator().SetType(EWindowType::eTriangular); 00051 GetSynthWindowGenerator().SetNormalize(EWindowNormalize::eNone); 00052 GetSynthWindowGenerator().SetSize(GetHopSize()*2+1); 00053 00054 SetResidual(false); 00055 00056 00057 } 00058 00059 void SpectralSynthesisConfig::Sync() 00060 { 00061 int aws = GetprAnalWindowSize(); 00062 int hs = GetprHopSize(); 00063 00064 SetSamplingRate(GetprSamplingRate()); 00065 00066 SetAnalWindowSize(aws); 00067 SetAnalWindowType(GetprAnalWindowType()); 00068 00069 SetHopSize(hs); 00070 00071 GetSynthWindowGenerator().SetSize(GetHopSize()*2+1); 00072 } 00073 00074 00075 void SpectralSynthesisConfig::SetAnalWindowSize(TSize w) 00076 { 00077 CLAM_ASSERT(w%2==1,"Window size must be odd"); 00078 SetprAnalWindowSize(w); 00079 GetAnalWindowGenerator().SetSize(w); 00080 TData audioSize=TData(PowerOfTwo((w-1)*int(pow(TData(2.0),TData(GetZeroPadding()))))); 00081 GetIFFT().SetAudioSize(int(audioSize)); 00082 GetCircularShift().SetAmount(TData(w/2)); 00083 } 00084 00085 TSize SpectralSynthesisConfig::GetAnalWindowSize() const 00086 { 00087 return GetAnalWindowGenerator().GetSize(); 00088 } 00089 00090 void SpectralSynthesisConfig::SetAnalWindowType(const EWindowType& t) 00091 { 00092 GetAnalWindowGenerator().SetType(t); 00093 SetprAnalWindowType(t); 00094 } 00095 00096 const EWindowType& SpectralSynthesisConfig::GetAnalWindowType() const 00097 { 00098 return GetAnalWindowGenerator().GetType(); 00099 } 00100 00101 00102 void SpectralSynthesisConfig::SetSynthWindowSize(TSize w) 00103 { 00104 CLAM_ASSERT(w%2==1,"Window size must be odd"); 00105 GetSynthWindowGenerator().SetSize(w); 00106 } 00107 00108 TSize SpectralSynthesisConfig::GetSynthWindowSize() const 00109 { 00110 return GetSynthWindowGenerator().GetSize(); 00111 } 00112 00113 void SpectralSynthesisConfig::SetZeroPadding(int z) 00114 { 00115 SetprZeroPadding(z); 00116 TData audioSize=TData(PowerOfTwo((GetAnalWindowSize()-1)*int(pow(TData(2),TData(GetZeroPadding()))))); 00117 GetIFFT().SetAudioSize(int(audioSize)); 00118 } 00119 00120 int SpectralSynthesisConfig::GetZeroPadding() const 00121 { 00122 return GetprZeroPadding(); 00123 } 00124 00125 void SpectralSynthesisConfig::SetHopSize(TSize h) 00126 { 00127 GetSynthWindowGenerator().SetSize(2*h+1); 00128 SetprHopSize(h); 00129 } 00130 00131 TSize SpectralSynthesisConfig::GetHopSize() const 00132 { 00133 return (GetSynthWindowGenerator().GetSize()-1)>>1; 00134 } 00135 00136 void SpectralSynthesisConfig::SetSamplingRate(TData sr) 00137 { 00138 SetprSamplingRate(int(sr)); 00139 00141 SetAnalWindowSize(GetAnalWindowSize()); 00142 } 00143 00144 TData SpectralSynthesisConfig::GetSamplingRate() const 00145 { 00146 return TData(GetprSamplingRate()); 00147 } 00148 00149 00150 TInt32 SpectralSynthesisConfig::PowerOfTwo(TInt32 size) 00151 { 00152 int tmp = size; 00153 int outputSize = 1; 00154 while (tmp) 00155 { 00156 outputSize=outputSize << 1; 00157 tmp=tmp >> 1; 00158 } 00159 if(outputSize == size << 1) 00160 outputSize = outputSize >> 1; 00161 return outputSize; 00162 } 00163 00164 } // namespace CLAM 00165