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

Method Process

Source/FFTtoAdditive.cpp:86–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86void FFTtoAdditive::Process(double time)
87{
88 PROFILER(FFTtoAdditive);
89
90 IAudioReceiver* target = GetTarget();
91
92 if (target == nullptr || !mEnabled)
93 return;
94
95 ComputeSliders(0);
96 SyncBuffers();
97
98 float inputPreampSq = mInputPreamp * mInputPreamp;
99 float volSq = mVolume * mVolume;
100
101 int bufferSize = GetBuffer()->BufferSize();
102
103 mRollingInputBuffer.WriteChunk(GetBuffer()->GetChannel(0), bufferSize, 0);
104
105 //copy rolling input buffer into working buffer and window it
106 mRollingInputBuffer.ReadChunk(mFFTData.mTimeDomain, fftWindowSize, 0, 0);
107 Mult(mFFTData.mTimeDomain, mWindower, fftWindowSize);
108 Mult(mFFTData.mTimeDomain, inputPreampSq, fftWindowSize);
109
110 mFFT.Forward(mFFTData.mTimeDomain,
111 mFFTData.mRealValues,
112 mFFTData.mImaginaryValues);
113
114 for (int i = 0; i < fftFreqDomainSize; ++i)
115 {
116 float real = mFFTData.mRealValues[i];
117 float imag = mFFTData.mImaginaryValues[i];
118
119 //cartesian to polar
120 float amp = 2. * sqrtf(real * real + imag * imag);
121 float phase = atan2(imag, real);
122
123 mFFTData.mRealValues[i] = amp / (fftWindowSize / 2);
124 mFFTData.mImaginaryValues[i] = phase;
125 }
126
127 float* out = target->GetBuffer()->GetChannel(0);
128 for (int i = 0; i < bufferSize; ++i)
129 {
130 float write = 0;
131 for (int j = 1; j < numPartials; ++j)
132 {
133 float phase = ((mFFTData.mImaginaryValues[j + 1] + i * mPhaseInc[j]) / FTWO_PI) * 512;
134 float sample = SinSample(phase) * mFFTData.mRealValues[j + 1] * volSq * .4f;
135 write += sample;
136 }
137
138 GetVizBuffer()->Write(write, 0);
139
140 out[i] += write;
141
142 time += gInvSampleRateMs;
143 }

Callers

nothing calls this directly

Calls 9

MultFunction · 0.85
BufferSizeMethod · 0.80
WriteChunkMethod · 0.80
GetChannelMethod · 0.80
ReadChunkMethod · 0.80
ForwardMethod · 0.80
GetBufferMethod · 0.80
WriteMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected