222 float magn, phase, tmp, real, imag;
223 float freqPerBin, expct;
224 int ch, i, k, qpd, index, fftFrameSize2;
227 fftFrameSize2 = h->fftFrameSize/2;
228 freqPerBin = h->sampleRate/(float)h->fftFrameSize;
229 expct = 2.0f*
SAF_PI*(float)(h->stepSize)/(float)h->fftFrameSize;
232 if(h->pitchShiftFactor!=pitchShift){
233 h->pitchShiftFactor = pitchShift;
234 for(ch=0; ch<h->nCH; ch++){
235 memset(h->gOutputAccum[ch], 0, h->stepSize*
sizeof(
float));
236 memset(h->gLastPhase[ch], 0, (h->fftFrameSize/2+1)*
sizeof(
float));
237 memset(h->gSumPhase[ch], 0, (h->fftFrameSize/2+1)*
sizeof(
float));
242 for(ch=0; ch<h->nCH; ch++){
243 for (i = 0; i < frameSize; i++){
245 h->gInFIFO[ch][h->gRover[ch]] = indata[ch*frameSize+i];
246 outdata[ch*frameSize+i] = h->gOutFIFO[ch][h->gRover[ch]-(h->inFifoLatency)];
250 if (h->gRover[ch] >= h->fftFrameSize) {
251 h->gRover[ch] = h->inFifoLatency;
253#ifdef SMB_ENABLE_SAF_FFT
254 for (k = 0; k < h->fftFrameSize;k++)
255 h->gFFTworksp_td[ch][k] = cmplxf(h->gInFIFO[ch][k] * (
float)h->window[k], 0.0f);
259 for (k = 0; k < h->fftFrameSize;k++) {
260 h->gFFTworksp[ch][2*k] = h->gInFIFO[ch][k] * h->window[k];
261 h->gFFTworksp[ch][2*k+1] = 0.;
265 smbFft(h->gFFTworksp[ch], h->fftFrameSize, -1);
269 for (k = 0; k <= fftFrameSize2; k++) {
270#ifdef SMB_ENABLE_SAF_FFT
271 real = crealf(h->gFFTworksp_fd[ch][k]);
272 imag = cimagf(h->gFFTworksp_fd[ch][k]);
275 real = h->gFFTworksp[ch][2*k];
276 imag = h->gFFTworksp[ch][2*k+1];
279 magn = 2.0f*sqrtf(real*real + imag*imag);
280 phase = atan2f(imag,real);
283 tmp = phase - h->gLastPhase[ch][k];
284 h->gLastPhase[ch][k] = phase;
287 tmp -= (float)k*expct;
291 if (qpd >= 0) qpd += qpd&1;
296 tmp = (float)h->osamp*tmp/(2.0f*
SAF_PI);
299 tmp = (float)k*freqPerBin + tmp*freqPerBin;
302 h->gAnaMagn[ch][k] = magn;
303 h->gAnaFreq[ch][k] = tmp;
309 memset(h->gSynMagn[ch], 0, h->fftFrameSize*
sizeof(
float));
310 memset(h->gSynFreq[ch], 0, h->fftFrameSize*
sizeof(
float));
311 for (k = 0; k <= fftFrameSize2; k++) {
312 index = (int)((
float)k*(h->pitchShiftFactor));
313 if (index <= fftFrameSize2) {
314 h->gSynMagn[ch][index] += (h->gAnaMagn[ch][k]);
315 h->gSynFreq[ch][index] = h->gAnaFreq[ch][k] * (h->pitchShiftFactor);
321 for (k = 0; k <= fftFrameSize2; k++) {
323 magn = h->gSynMagn[ch][k];
324 tmp = h->gSynFreq[ch][k];
327 tmp -= (float)k*freqPerBin;
333 tmp = 2.0f*
SAF_PI*tmp/(h->osamp);
336 tmp += (float)k*expct;
339 h->gSumPhase[ch][k] += tmp;
340 phase = h->gSumPhase[ch][k];
342#ifdef SMB_ENABLE_SAF_FFT
343 h->gFFTworksp_fd[ch][k] = cmplxf(magn*cosf(phase), magn*sinf(phase));
346 h->gFFTworksp[ch][2*k] = magn*cos(phase);
347 h->gFFTworksp[ch][2*k+1] = magn*sin(phase);
351#ifdef SMB_ENABLE_SAF_FFT
352 for (k = fftFrameSize2+1; k < h->fftFrameSize; k++)
353 h->gFFTworksp_fd[ch][k] = cmplxf(0.0f, 0.0f);
357 for(k=0; k < h->fftFrameSize; k++)
358 h->gOutputAccum[ch][k] += 2.0f*(h->window[k])*crealf(h->gFFTworksp_td[ch][k])/((h->osamp));
361 for (k = h->fftFrameSize+2; k < 2*(h->fftFrameSize); k++)
362 h->gFFTworksp[ch][k] = 0.;
365 smbFft(h->gFFTworksp[ch], h->fftFrameSize, 1);
368 for(k=0; k < h->fftFrameSize; k++)
369 h->gOutputAccum[ch][k] += 2.*(h->window[k])*(h->gFFTworksp[ch][2*k])/(fftFrameSize2*(h->osamp));
371 for (k = 0; k < h->stepSize; k++)
372 h->gOutFIFO[ch][k] = h->gOutputAccum[ch][k];
375 memmove(h->gOutputAccum[ch], h->gOutputAccum[ch] + (h->stepSize), h->fftFrameSize*
sizeof(
float));
378 for (k = 0; k < h->inFifoLatency; k++)
379 h->gInFIFO[ch][k] = h->gInFIFO[ch][k+h->stepSize];