MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / Process

Method Process

Source/PitchShifter.cpp:66–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64#if MY_PITCHSHIFTER
65
66void PitchShifter::Process(float* buffer, int bufferSize)
67{
68 PROFILER(PitchShifter);
69
70 const int osamp = mOversampling;
71 const int stepSize = mFFTBins / osamp;
72 const double expct = 2. * M_PI * (double)stepSize / (double)mFFTBins;
73 const double freqPerBin = gSampleRate / (double)mFFTBins;
74
75 mLatency = mFFTBins - stepSize;
76
77 mRollingInputBuffer.WriteChunk(buffer, bufferSize, 0);
78
79 //copy rolling input buffer into working buffer and window it
80 mRollingInputBuffer.ReadChunk(mFFTData.mTimeDomain, mFFTBins, latency);
81 Mult(mFFTData.mTimeDomain, mWindower, mFFTBins);
82
83 mFFT.Forward(mFFTData.mTimeDomain,
84 mFFTData.mRealValues,
85 mFFTData.mImaginaryValues);
86
87 const int fftFrameSize2 = mFFTBins / 2;
88
89 // this is the analysis step
90 for (int k = 0; k <= fftFrameSize2; k++)
91 {
92 // de-interlace FFT buffer
93 float real = mFFTData.mRealValues[k];
94 float imag = mFFTData.mImaginaryValues[k];
95
96 // compute magnitude and phase
97 double mag = 2. * sqrt(real * real + imag * imag);
98 double phase = atan2(imag, real);
99
100 // compute phase difference
101 double diff = phase - mLastPhase[k];
102 mLastPhase[k] = phase;
103
104 // subtract expected phase difference
105 diff -= (double)k * expct;
106
107 // map delta phase into +/- Pi interval
108 long qpd = diff / M_PI;
109 if (qpd >= 0)
110 qpd += qpd & 1;
111 else
112 qpd -= qpd & 1;
113 diff -= M_PI * (double)qpd;
114
115 // get deviation from bin frequency from the +/- Pi interval
116 double deviation = osamp * diff / (2. * M_PI);
117
118 // compute the k-th partials' true frequency
119 double freq = (double)k * freqPerBin + deviation * freqPerBin;
120
121 // store magnitude and true frequency in analysis arrays
122 mAnalysisMag[k] = mag;
123 mAnalysisFreq[k] = freq;

Callers

nothing calls this directly

Calls 9

MultFunction · 0.85
smbFftFunction · 0.85
WriteChunkMethod · 0.80
ReadChunkMethod · 0.80
ForwardMethod · 0.80
InverseMethod · 0.80
AccumMethod · 0.80
WriteMethod · 0.45
GetSampleMethod · 0.45

Tested by

no test coverage detected