Audacity 3.2.0
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
PaulStretch Class Reference

Class that helps EffectPaulStretch. It does the FFTs and inner loop of the effect. More...

Collaboration diagram for PaulStretch:
[legend]

Public Member Functions

 PaulStretch (float rap_, size_t in_bufsize_, float samplerate_)
 
virtual ~PaulStretch ()
 
void process (float *smps, size_t nsmps)
 
size_t get_nsamples ()
 
size_t get_nsamples_for_fill ()
 

Public Attributes

const size_t out_bufsize
 
const Floats out_buf
 
const size_t poolsize
 

Private Member Functions

void process_spectrum (float *WXUNUSED(freq))
 

Private Attributes

const float samplerate
 
const float rap
 
const size_t in_bufsize
 
const Floats old_out_smp_buf
 
const Floats in_pool
 
double remained_samples
 
const Floats fft_smps
 
const Floats fft_c
 
const Floats fft_s
 
const Floats fft_freq
 
const Floats fft_tmp
 

Detailed Description

Class that helps EffectPaulStretch. It does the FFTs and inner loop of the effect.

Definition at line 47 of file Paulstretch.cpp.

Constructor & Destructor Documentation

◆ PaulStretch()

PaulStretch::PaulStretch ( float  rap_,
size_t  in_bufsize_,
float  samplerate_ 
)

Definition at line 421 of file Paulstretch.cpp.

422 : samplerate { samplerate_ }
423 , rap { std::max(1.0f, rap_) }
424 , in_bufsize { in_bufsize_ }
425 , out_bufsize { std::max(size_t{ 8 }, in_bufsize) }
426 , out_buf { out_bufsize }
427 , old_out_smp_buf { out_bufsize * 2, true }
428 , poolsize { in_bufsize_ * 2 }
429 , in_pool { poolsize, true }
430 , remained_samples { 0.0 }
431 , fft_smps { poolsize, true }
432 , fft_c { poolsize, true }
433 , fft_s { poolsize, true }
434 , fft_freq { poolsize, true }
435 , fft_tmp { poolsize }
436{
437}
const float rap
Definition: Paulstretch.cpp:63
const Floats in_pool
Definition: Paulstretch.cpp:77
double remained_samples
Definition: Paulstretch.cpp:79
const size_t out_bufsize
Definition: Paulstretch.cpp:67
const Floats old_out_smp_buf
Definition: Paulstretch.cpp:71
const Floats fft_tmp
Definition: Paulstretch.cpp:81
const float samplerate
Definition: Paulstretch.cpp:60
const Floats fft_freq
Definition: Paulstretch.cpp:81
const Floats fft_smps
Definition: Paulstretch.cpp:81
const size_t in_bufsize
Definition: Paulstretch.cpp:64
const size_t poolsize
Definition: Paulstretch.cpp:74
const Floats out_buf
Definition: Paulstretch.cpp:68
const Floats fft_s
Definition: Paulstretch.cpp:81
const Floats fft_c
Definition: Paulstretch.cpp:81

◆ ~PaulStretch()

PaulStretch::~PaulStretch ( )
virtual

Definition at line 439 of file Paulstretch.cpp.

440{
441}

Member Function Documentation

◆ get_nsamples()

size_t PaulStretch::get_nsamples ( )

Definition at line 520 of file Paulstretch.cpp.

521{
522 double r = out_bufsize / rap;
523 auto ri = (size_t)floor(r);
524 double rf = r - floor(r);
525
526 remained_samples += rf;
527 if (remained_samples >= 1.0){
528 ri += (size_t)floor(remained_samples);
530 }
531
532 if (ri > poolsize) {
533 ri = poolsize;
534 }
535
536 return ri;
537}

References out_bufsize, poolsize, rap, and remained_samples.

Referenced by EffectPaulstretch::ProcessOne().

Here is the caller graph for this function:

◆ get_nsamples_for_fill()

size_t PaulStretch::get_nsamples_for_fill ( )

Definition at line 539 of file Paulstretch.cpp.

540{
541 return poolsize;
542}

References poolsize.

Referenced by EffectPaulstretch::ProcessOne().

Here is the caller graph for this function:

◆ process()

void PaulStretch::process ( float *  smps,
size_t  nsmps 
)

Definition at line 443 of file Paulstretch.cpp.

444{
445 //add NEW samples to the pool
446 if ((smps != NULL) && (nsmps != 0)) {
447 if (nsmps > poolsize) {
448 nsmps = poolsize;
449 }
450 int nleft = poolsize - nsmps;
451
452 //move left the samples from the pool to make room for NEW samples
453 for (int i = 0; i < nleft; i++)
454 in_pool[i] = in_pool[i + nsmps];
455
456 //add NEW samples to the pool
457 for (size_t i = 0; i < nsmps; i++)
458 in_pool[i + nleft] = smps[i];
459 }
460
461 //get the samples from the pool
462 for (size_t i = 0; i < poolsize; i++)
463 fft_smps[i] = in_pool[i];
465
466 RealFFT(poolsize, fft_smps.get(), fft_c.get(), fft_s.get());
467
468 for (size_t i = 0; i < poolsize / 2; i++)
469 fft_freq[i] = sqrt(fft_c[i] * fft_c[i] + fft_s[i] * fft_s[i]);
471
472
473 //put randomize phases to frequencies and do a IFFT
474 float inv_2p15_2pi = 1.0 / 16384.0 * (float)M_PI;
475 for (size_t i = 1; i < poolsize / 2; i++) {
476 unsigned int random = (rand()) & 0x7fff;
477 float phase = random * inv_2p15_2pi;
478 float s = fft_freq[i] * sin(phase);
479 float c = fft_freq[i] * cos(phase);
480
481 fft_c[i] = fft_c[poolsize - i] = c;
482
483 fft_s[i] = s; fft_s[poolsize - i] = -s;
484 }
485 fft_c[0] = fft_s[0] = 0.0;
486 fft_c[poolsize / 2] = fft_s[poolsize / 2] = 0.0;
487
488 FFT(poolsize, true, fft_c.get(), fft_s.get(), fft_smps.get(), fft_tmp.get());
489
490 float max = 0.0, max2 = 0.0;
491 for (size_t i = 0; i < poolsize; i++) {
492 max = std::max(max, fabsf(fft_tmp[i]));
493 max2 = std::max(max2, fabsf(fft_smps[i]));
494 }
495
496
497 //make the output buffer
498 float tmp = 1.0 / (float) out_bufsize * M_PI;
499 float hinv_sqrt2 = 0.853553390593f;//(1.0+1.0/sqrt(2))*0.5;
500
501 float ampfactor = 1.0;
502 if (rap < 1.0)
503 ampfactor = rap * 0.707;
504 else
505 ampfactor = (out_bufsize / (float)poolsize) * 4.0;
506
507 for (size_t i = 0; i < out_bufsize; i++) {
508 float a = (0.5 + 0.5 * cos(i * tmp));
509 float out = fft_smps[i + out_bufsize] * (1.0 - a) + old_out_smp_buf[i] * a;
510 out_buf[i] =
511 out * (hinv_sqrt2 - (1.0 - hinv_sqrt2) * cos(i * 2.0 * tmp)) *
512 ampfactor;
513 }
514
515 //copy the current output buffer to old buffer
516 for (size_t i = 0; i < out_bufsize * 2; i++)
518}
#define M_PI
Definition: Distortion.cpp:30
void WindowFunc(int whichFunction, size_t NumSamples, float *in)
Definition: FFT.cpp:513
void RealFFT(size_t NumSamples, const float *RealIn, float *RealOut, float *ImagOut)
Definition: FFT.cpp:228
void FFT(size_t NumSamples, bool InverseTransform, const float *RealIn, const float *ImagIn, float *RealOut, float *ImagOut)
Definition: FFT.cpp:129
@ eWinFuncHann
Definition: FFT.h:114
void process_spectrum(float *WXUNUSED(freq))
Definition: Paulstretch.cpp:60
__finl float_x4 __vecc sqrt(const float_x4 &a)

References eWinFuncHann, FFT(), fft_c, fft_freq, fft_s, fft_smps, fft_tmp, in_pool, M_PI, old_out_smp_buf, out_buf, out_bufsize, poolsize, process_spectrum(), rap, RealFFT(), staffpad::audio::simd::sqrt(), and WindowFunc().

Referenced by EffectPaulstretch::ProcessOne().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_spectrum()

void PaulStretch::process_spectrum ( float *  WXUNUSEDfreq)
inlineprivate

Definition at line 60 of file Paulstretch.cpp.

60{};

Referenced by process().

Here is the caller graph for this function:

Member Data Documentation

◆ fft_c

const Floats PaulStretch::fft_c
private

Definition at line 81 of file Paulstretch.cpp.

Referenced by process().

◆ fft_freq

const Floats PaulStretch::fft_freq
private

Definition at line 81 of file Paulstretch.cpp.

Referenced by process().

◆ fft_s

const Floats PaulStretch::fft_s
private

Definition at line 81 of file Paulstretch.cpp.

Referenced by process().

◆ fft_smps

const Floats PaulStretch::fft_smps
private

Definition at line 81 of file Paulstretch.cpp.

Referenced by process().

◆ fft_tmp

const Floats PaulStretch::fft_tmp
private

Definition at line 81 of file Paulstretch.cpp.

Referenced by process().

◆ in_bufsize

const size_t PaulStretch::in_bufsize
private

Definition at line 64 of file Paulstretch.cpp.

◆ in_pool

const Floats PaulStretch::in_pool
private

Definition at line 77 of file Paulstretch.cpp.

Referenced by process().

◆ old_out_smp_buf

const Floats PaulStretch::old_out_smp_buf
private

Definition at line 71 of file Paulstretch.cpp.

Referenced by process().

◆ out_buf

const Floats PaulStretch::out_buf

Definition at line 68 of file Paulstretch.cpp.

Referenced by process(), and EffectPaulstretch::ProcessOne().

◆ out_bufsize

const size_t PaulStretch::out_bufsize

Definition at line 67 of file Paulstretch.cpp.

Referenced by get_nsamples(), process(), and EffectPaulstretch::ProcessOne().

◆ poolsize

const size_t PaulStretch::poolsize

◆ rap

const float PaulStretch::rap
private

Definition at line 63 of file Paulstretch.cpp.

Referenced by get_nsamples(), and process().

◆ remained_samples

double PaulStretch::remained_samples
private

Definition at line 79 of file Paulstretch.cpp.

Referenced by get_nsamples().

◆ samplerate

const float PaulStretch::samplerate
private

Definition at line 62 of file Paulstretch.cpp.


The documentation for this class was generated from the following file: