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

Method Process

Source/KarplusStrongVoice.cpp:63–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61}
62
63bool KarplusStrongVoice::Process(double time, ChannelBuffer* out, int oversampling)
64{
65 PROFILER(KarplusStrongVoice);
66
67 if (IsDone(time))
68 return false;
69
70 int bufferSize = out->BufferSize();
71 int channels = out->NumActiveChannels();
72 double sampleIncrementMs = gInvSampleRateMs;
73 double sampleRate = gSampleRate;
74 ChannelBuffer* destBuffer = out;
75
76 if (oversampling != 1)
77 {
78 gMidiVoiceWorkChannelBuffer.SetNumActiveChannels(channels);
79 destBuffer = &gMidiVoiceWorkChannelBuffer;
80 gMidiVoiceWorkChannelBuffer.Clear();
81 bufferSize *= oversampling;
82 sampleIncrementMs /= oversampling;
83 sampleRate *= oversampling;
84 }
85
86 float freq;
87 float filterRate;
88 float filterLerp;
89 float pitch;
90 float oscPhaseInc;
91
92 if (mVoiceParams->mLiteCPUMode)
93 DoParameterUpdate(0, oversampling, pitch, freq, filterRate, filterLerp, oscPhaseInc);
94
95 for (int pos = 0; pos < bufferSize; ++pos)
96 {
97 if (!mVoiceParams->mLiteCPUMode)
98 DoParameterUpdate(pos / oversampling, oversampling, pitch, freq, filterRate, filterLerp, oscPhaseInc);
99
100 if (mVoiceParams->mSourceType == kSourceTypeSaw)
101 mOsc.SetType(kOsc_Saw);
102 else
103 mOsc.SetType(kOsc_Sin);
104 mOscPhase += oscPhaseInc;
105 float sample = 0;
106 float oscSample = mOsc.Audio(time, mOscPhase);
107 float noiseSample = RandomSample();
108 float pitchBlend = ofClamp((pitch - 40) / 60.0f, 0, 1);
109 pitchBlend *= pitchBlend;
110 if (mVoiceParams->mSourceType == kSourceTypeSin || mVoiceParams->mSourceType == kSourceTypeSaw)
111 sample = oscSample;
112 else if (mVoiceParams->mSourceType == kSourceTypeNoise)
113 sample = noiseSample;
114 else if (mVoiceParams->mSourceType == kSourceTypeMix)
115 sample = noiseSample * pitchBlend + oscSample * (1 - pitchBlend);
116 else if (mVoiceParams->mSourceType == kSourceTypeInput || mVoiceParams->mSourceType == kSourceTypeInputNoEnvelope)
117 sample = mKarplusStrongModule->GetBuffer()->GetChannel(0)[pos / oversampling];
118
119 if (mVoiceParams->mSourceType != kSourceTypeInputNoEnvelope)
120 sample *= mEnv.Value(time) + mVoiceParams->mExcitation;

Callers

nothing calls this directly

Calls 15

RandomSampleFunction · 0.85
ofClampFunction · 0.85
AssertIfDenormalFunction · 0.85
ofLerpFunction · 0.85
GetLeftPanGainFunction · 0.85
GetRightPanGainFunction · 0.85
AddFunction · 0.85
BufferSizeMethod · 0.80
NumActiveChannelsMethod · 0.80
SetNumActiveChannelsMethod · 0.80
AudioMethod · 0.80
GetChannelMethod · 0.80

Tested by

no test coverage detected