CLAM-Development  1.4.0
SpectralSynthesisConfig.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #include "CLAM_Math.hxx"
24 
25 namespace CLAM
26 {
27 
28 void SpectralSynthesisConfig::DefaultInit()
29 {
30  AddAll();
31  UpdateData();
32  DefaultValues();
33 }
34 
35 void SpectralSynthesisConfig::DefaultValues()
36 {
38  SetprZeroPadding(0);
39  SetSamplingRate(44100);
40 
42  SetAnalWindowSize(1025);
44  GetAnalWindowGenerator().SetInvert(true);
45 
48 
50  GetSynthWindowGenerator().SetType(EWindowType::eTriangular);
51  GetSynthWindowGenerator().SetNormalize(EWindowNormalize::eNone);
52  GetSynthWindowGenerator().SetSize(GetHopSize()*2+1);
53 
54  SetResidual(false);
55 
56 
57 }
58 
59 void SpectralSynthesisConfig::Sync()
60 {
61  int aws = GetprAnalWindowSize();
62  int hs = GetprHopSize();
63 
64  SetSamplingRate(GetprSamplingRate());
65 
66  SetAnalWindowSize(aws);
67  SetAnalWindowType(GetprAnalWindowType());
68 
69  SetHopSize(hs);
70 
71  GetSynthWindowGenerator().SetSize(GetHopSize()*2+1);
72 }
73 
74 
76 {
77  CLAM_ASSERT(w%2==1,"Window size must be odd");
78  SetprAnalWindowSize(w);
79  GetAnalWindowGenerator().SetSize(w);
80  TData audioSize=TData(PowerOfTwo((w-1)*int(pow(TData(2.0),TData(GetZeroPadding())))));
81  GetIFFT().SetAudioSize(int(audioSize));
82  GetCircularShift().SetAmount(TData(w/2));
83 }
84 
86 {
87  return GetAnalWindowGenerator().GetSize();
88 }
89 
91 {
92  GetAnalWindowGenerator().SetType(t);
93  SetprAnalWindowType(t);
94 }
95 
97 {
98  return GetAnalWindowGenerator().GetType();
99 }
100 
101 
103 {
104  CLAM_ASSERT(w%2==1,"Window size must be odd");
105  GetSynthWindowGenerator().SetSize(w);
106 }
107 
109 {
110  return GetSynthWindowGenerator().GetSize();
111 }
112 
114 {
115  SetprZeroPadding(z);
116  TData audioSize=TData(PowerOfTwo((GetAnalWindowSize()-1)*int(pow(TData(2),TData(GetZeroPadding())))));
117  GetIFFT().SetAudioSize(int(audioSize));
118 }
119 
121 {
122  return GetprZeroPadding();
123 }
124 
126 {
127  GetSynthWindowGenerator().SetSize(2*h+1);
128  SetprHopSize(h);
129 }
130 
132 {
133  return (GetSynthWindowGenerator().GetSize()-1)>>1;
134 }
135 
137 {
138  SetprSamplingRate(int(sr));
139 
142 }
143 
145 {
146  return TData(GetprSamplingRate());
147 }
148 
149 
150 TInt32 SpectralSynthesisConfig::PowerOfTwo(TInt32 size)
151 {
152  int tmp = size;
153  int outputSize = 1;
154  while (tmp)
155  {
156  outputSize=outputSize << 1;
157  tmp=tmp >> 1;
158  }
159  if(outputSize == size << 1)
160  outputSize = outputSize >> 1;
161  return outputSize;
162 }
163 
164 } // namespace CLAM
165