28 #define CLASS "SpectralEnvelopeExtract"
71 mMagBPF.
SetIntpType(mConfig.GetInterpolationType());
105 output.SetScale(input.GetScale());
109 if (nPeaks<4)
return false;
111 CheckOutputType(output);
113 DataArray& magBuffer=input.GetMagBuffer();
114 DataArray& phaseBuffer=input.GetPhaseBuffer();
115 DataArray& freqBuffer=input.GetFreqBuffer();
117 Array<Point>& magPointArray=output.GetMagBPF().GetPointArray();
118 Array<Point>& phasePointArray=output.GetPhaseBPF().GetPointArray();
121 magPointArray.
Resize(mConfig.GetMaxPeaks());
122 magPointArray.
SetSize(mConfig.GetMaxPeaks());
123 phasePointArray.
Resize(mConfig.GetMaxPeaks());
124 phasePointArray.
SetSize(mConfig.GetMaxPeaks());
127 for(
int i=0;i<nPeaks;i++)
129 magPointArray[i+1].SetX(freqBuffer[i]);
130 magPointArray[i+1].SetY(magBuffer[i]);
132 phasePointArray[i+1].SetX(freqBuffer[i]);
133 phasePointArray[i+1].SetY(phaseBuffer[i]);
142 magPointArray[0].SetX(0);
143 magPointArray[0].SetY(magBuffer[0]-3);
144 phasePointArray[0].SetX(0);
145 phasePointArray[0].SetY(0);
150 TData lastFreq=freqBuffer[nPeaks-2];
151 TData freqGap=lastFreq-freqBuffer[nPeaks-3];
152 TData currentFreq=lastFreq+freqGap;
153 TData currentMag=magBuffer[nPeaks-2];
155 while(currentMag>-200)
157 currentMag-=(currentFreq/lastFreq-1)*12;
159 magPointArray[nPeaks].SetY(currentMag);
160 magPointArray[nPeaks].SetX(currentFreq);
161 phasePointArray[nPeaks].SetY(0);
162 phasePointArray[nPeaks].SetX(currentFreq);
164 currentFreq+=freqGap;
166 if(nPeaks==mConfig.GetMaxPeaks())
break;
170 magPointArray.
Resize(nPeaks);
172 phasePointArray.
Resize(nPeaks);
173 phasePointArray.
SetSize(nPeaks);
180 magPointArray[0].SetX(0);
181 magPointArray[0].SetY(magBuffer[0]*0.5);
182 phasePointArray[0].SetX(0);
183 phasePointArray[0].SetY(0);
188 TData lastFreq=freqBuffer[nPeaks-2];
189 TData freqGap=lastFreq-freqBuffer[nPeaks-3];
190 TData currentFreq=lastFreq+freqGap;
191 TData currentMag=magBuffer[nPeaks-2];
194 while(currentMag<0.0000000001)
196 currentMag*=
CLAM_pow(0.06,(
double)(currentFreq/lastFreq-1.0));
198 magPointArray[nPeaks].SetY(currentMag);
199 magPointArray[nPeaks].SetX(currentFreq);
200 phasePointArray[nPeaks].SetY(0);
201 phasePointArray[nPeaks].SetX(currentFreq);
203 currentFreq+=freqGap;
205 if(nPeaks==mConfig.GetMaxPeaks())
break;
209 magPointArray.
Resize(nPeaks);
211 phasePointArray.
Resize(nPeaks);
212 phasePointArray.
SetSize(nPeaks);
217 output.GetMagBPF().UpdateSplineTable();
222 bool SpectralEnvelopeExtract::CheckOutputType(
Spectrum& out)
231 out.SetMagBPF(mMagBPF);
232 out.SetPhaseBPF(mPhaseBPF);