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 420 of file Paulstretch.cpp.

421 : samplerate { samplerate_ }
422 , rap { std::max(1.0f, rap_) }
423 , in_bufsize { in_bufsize_ }
424 , out_bufsize { std::max(size_t{ 8 }, in_bufsize) }
425 , out_buf { out_bufsize }
426 , old_out_smp_buf { out_bufsize * 2, true }
427 , poolsize { in_bufsize_ * 2 }
428 , in_pool { poolsize, true }
429 , remained_samples { 0.0 }
430 , fft_smps { poolsize, true }
431 , fft_c { poolsize, true }
432 , fft_s { poolsize, true }
433 , fft_freq { poolsize, true }
434 , fft_tmp { poolsize }
435{
436}
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 438 of file Paulstretch.cpp.

439{
440}

Member Function Documentation

◆ get_nsamples()

size_t PaulStretch::get_nsamples ( )

Definition at line 519 of file Paulstretch.cpp.

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

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 538 of file Paulstretch.cpp.

539{
540 return poolsize;
541}

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 442 of file Paulstretch.cpp.

443{
444 //add NEW samples to the pool
445 if ((smps != NULL) && (nsmps != 0)) {
446 if (nsmps > poolsize) {
447 nsmps = poolsize;
448 }
449 int nleft = poolsize - nsmps;
450
451 //move left the samples from the pool to make room for NEW samples
452 for (int i = 0; i < nleft; i++)
453 in_pool[i] = in_pool[i + nsmps];
454
455 //add NEW samples to the pool
456 for (size_t i = 0; i < nsmps; i++)
457 in_pool[i + nleft] = smps[i];
458 }
459
460 //get the samples from the pool
461 for (size_t i = 0; i < poolsize; i++)
462 fft_smps[i] = in_pool[i];
464
465 RealFFT(poolsize, fft_smps.get(), fft_c.get(), fft_s.get());
466
467 for (size_t i = 0; i < poolsize / 2; i++)
468 fft_freq[i] = sqrt(fft_c[i] * fft_c[i] + fft_s[i] * fft_s[i]);
470
471
472 //put randomize phases to frequencies and do a IFFT
473 float inv_2p15_2pi = 1.0 / 16384.0 * (float)M_PI;
474 for (size_t i = 1; i < poolsize / 2; i++) {
475 unsigned int random = (rand()) & 0x7fff;
476 float phase = random * inv_2p15_2pi;
477 float s = fft_freq[i] * sin(phase);
478 float c = fft_freq[i] * cos(phase);
479
480 fft_c[i] = fft_c[poolsize - i] = c;
481
482 fft_s[i] = s; fft_s[poolsize - i] = -s;
483 }
484 fft_c[0] = fft_s[0] = 0.0;
485 fft_c[poolsize / 2] = fft_s[poolsize / 2] = 0.0;
486
487 FFT(poolsize, true, fft_c.get(), fft_s.get(), fft_smps.get(), fft_tmp.get());
488
489 float max = 0.0, max2 = 0.0;
490 for (size_t i = 0; i < poolsize; i++) {
491 max = std::max(max, fabsf(fft_tmp[i]));
492 max2 = std::max(max2, fabsf(fft_smps[i]));
493 }
494
495
496 //make the output buffer
497 float tmp = 1.0 / (float) out_bufsize * M_PI;
498 float hinv_sqrt2 = 0.853553390593f;//(1.0+1.0/sqrt(2))*0.5;
499
500 float ampfactor = 1.0;
501 if (rap < 1.0)
502 ampfactor = rap * 0.707;
503 else
504 ampfactor = (out_bufsize / (float)poolsize) * 4.0;
505
506 for (size_t i = 0; i < out_bufsize; i++) {
507 float a = (0.5 + 0.5 * cos(i * tmp));
508 float out = fft_smps[i + out_bufsize] * (1.0 - a) + old_out_smp_buf[i] * a;
509 out_buf[i] =
510 out * (hinv_sqrt2 - (1.0 - hinv_sqrt2) * cos(i * 2.0 * tmp)) *
511 ampfactor;
512 }
513
514 //copy the current output buffer to old buffer
515 for (size_t i = 0; i < out_bufsize * 2; i++)
517}
#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: