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

Method Process

Source/SignalGenerator.cpp:136–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136void SignalGenerator::Process(double time)
137{
138 PROFILER(SignalGenerator);
139
140 IAudioReceiver* target = GetTarget();
141
142 if (!mEnabled || target == nullptr)
143 return;
144
145 int bufferSize = target->GetBuffer()->BufferSize();
146 float* out = target->GetBuffer()->GetChannel(0);
147 assert(bufferSize == gBufferSize);
148
149 Clear(mWriteBuffer, gBufferSize);
150 for (int pos = 0; pos < bufferSize; ++pos)
151 {
152 ComputeSliders(pos);
153
154 if (mResetPhaseAtMs > 0 && time > mResetPhaseAtMs)
155 {
156 mPhase = mPhaseOffset;
157 mResetPhaseAtMs = -9999;
158 }
159
160 float volSq = mVol * mVol;
161
162 if (mFreqMode == kFreqMode_Root)
163 mFreq = TheScale->PitchToFreq(TheScale->ScaleRoot() + 24);
164 else if (mFreqMode == kFreqMode_Ramp)
165 mFreq = mFreqRamp.Value(time);
166 else if (mFreqMode == kFreqMode_Slider)
167 mFreq = ofLerp(mFreqSliderStart, mFreqSliderEnd, mFreqSliderAmount);
168
169 float mult = mMult;
170 if (mult < 0)
171 mult = -1.0f / mult;
172 float outputFreq = mFreq * exp2(mDetune) * mult;
173 float phaseInc = GetPhaseInc(outputFreq);
174
175 float syncPhaseInc = 0;
176 if (mSyncMode == Oscillator::SyncMode::Frequency)
177 syncPhaseInc = GetPhaseInc(mSyncFreq);
178 else if (mSyncMode == Oscillator::SyncMode::Ratio)
179 syncPhaseInc = GetPhaseInc(outputFreq * mSyncRatio);
180
181 mPhase += phaseInc;
182 if (mPhase == INFINITY)
183 {
184 ofLog() << "Infinite phase.";
185 }
186 else
187 {
188 while (mPhase > FTWO_PI * 2)
189 {
190 mPhase -= FTWO_PI * 2;
191 mSyncPhase = 0;
192 }
193 }

Callers

nothing calls this directly

Calls 13

ClearFunction · 0.85
ofLerpFunction · 0.85
GetPhaseIncFunction · 0.85
ofLogClass · 0.85
AddFunction · 0.85
BufferSizeMethod · 0.80
GetBufferMethod · 0.80
GetChannelMethod · 0.80
PitchToFreqMethod · 0.80
AudioMethod · 0.80
WriteChunkMethod · 0.80
ScaleRootMethod · 0.45

Tested by

no test coverage detected