MCPcopy Create free account
hub / github.com/audacity/audacity / process

Method process

libraries/lib-builtin-effects/PaulstretchBase.cpp:395–475  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

393}
394
395void PaulStretch::process(float* smps, size_t nsmps)
396{
397 // add NEW samples to the pool
398 if ((smps != NULL) && (nsmps != 0))
399 {
400 if (nsmps > poolsize)
401 {
402 nsmps = poolsize;
403 }
404 int nleft = poolsize - nsmps;
405
406 // move left the samples from the pool to make room for NEW samples
407 for (int i = 0; i < nleft; i++)
408 in_pool[i] = in_pool[i + nsmps];
409
410 // add NEW samples to the pool
411 for (size_t i = 0; i < nsmps; i++)
412 in_pool[i + nleft] = smps[i];
413 }
414
415 // get the samples from the pool
416 for (size_t i = 0; i < poolsize; i++)
417 fft_smps[i] = in_pool[i];
418 WindowFunc(eWinFuncHann, poolsize, fft_smps.get());
419
420 RealFFT(poolsize, fft_smps.get(), fft_c.get(), fft_s.get());
421
422 for (size_t i = 0; i < poolsize / 2; i++)
423 fft_freq[i] = sqrt(fft_c[i] * fft_c[i] + fft_s[i] * fft_s[i]);
424 process_spectrum(fft_freq.get());
425
426 // put randomize phases to frequencies and do a IFFT
427 float inv_2p15_2pi = 1.0 / 16384.0 * (float)M_PI;
428 for (size_t i = 1; i < poolsize / 2; i++)
429 {
430 unsigned int random = (rand()) & 0x7fff;
431 float phase = random * inv_2p15_2pi;
432 float s = fft_freq[i] * sin(phase);
433 float c = fft_freq[i] * cos(phase);
434
435 fft_c[i] = fft_c[poolsize - i] = c;
436
437 fft_s[i] = s;
438 fft_s[poolsize - i] = -s;
439 }
440 fft_c[0] = fft_s[0] = 0.0;
441 fft_c[poolsize / 2] = fft_s[poolsize / 2] = 0.0;
442
443 FFT(poolsize, true, fft_c.get(), fft_s.get(), fft_smps.get(), fft_tmp.get());
444
445 float max = 0.0, max2 = 0.0;
446 for (size_t i = 0; i < poolsize; i++)
447 {
448 max = std::max(max, fabsf(fft_tmp[i]));
449 max2 = std::max(max2, fabsf(fft_smps[i]));
450 }
451
452 // make the output buffer

Callers 2

ProcessOneMethod · 0.45
ProcessMethod · 0.45

Calls 6

WindowFuncFunction · 0.85
RealFFTFunction · 0.85
maxFunction · 0.85
sqrtFunction · 0.50
FFTFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected