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

Method Process

Source/FeedbackModule.cpp:66–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64}
65
66void FeedbackModule::Process(double time)
67{
68 PROFILER(FeedbackModule);
69
70
71 ComputeSliders(0);
72 SyncBuffers();
73
74 int bufferSize = GetBuffer()->BufferSize();
75 IAudioReceiver* target = GetTarget();
76
77 if (target)
78 {
79 for (int ch = 0; ch < GetBuffer()->NumActiveChannels(); ++ch)
80 {
81 Add(target->GetBuffer()->GetChannel(ch), GetBuffer()->GetChannel(ch), bufferSize);
82 GetVizBuffer()->WriteChunk(GetBuffer()->GetChannel(ch), bufferSize, ch);
83 }
84 }
85
86 if (mFeedbackTarget && mEnabled)
87 {
88 mFeedbackTarget->GetBuffer()->SetNumActiveChannels(GetBuffer()->NumActiveChannels());
89 mFeedbackVizBuffer.SetNumChannels(GetBuffer()->NumActiveChannels());
90 mDelay.ProcessAudio(time, GetBuffer());
91
92 const double kReleaseMs = 50;
93 const double kReleaseCoeff = exp(-1000.0 / (kReleaseMs * gSampleRate));
94 for (int ch = 0; ch < GetBuffer()->NumActiveChannels(); ++ch)
95 {
96 float* channel = GetBuffer()->GetChannel(ch);
97 for (int i = 0; i < bufferSize; ++i)
98 {
99 //ofLog() << "input: " << channel[i];
100 if (abs(channel[i]) * mGainScale[ch] > mSignalLimit)
101 {
102 mGainScale[ch] = mSignalLimit / abs(channel[i]); //limit immediately
103 //ofLog() << "limiting, new scale " << mGainScale[ch];
104 }
105 else
106 {
107 mGainScale[ch] = MIN(1 - kReleaseCoeff * (mGainScale[ch] - 1), //blend towards 1
108 mSignalLimit / abs(channel[i])); //but don't make the scale less than it would have to be to limit the output
109 //ofLog() << "releasing, new scale " << mGainScale[ch];
110 }
111
112 channel[i] *= mGainScale[ch];
113 //ofLog() << "output: " << channel[i];
114 //assert(abs(channel[i]) <= mSignalLimit);
115 }
116
117 if (mDelay.IsEnabled())
118 {
119 Add(mFeedbackTarget->GetBuffer()->GetChannel(ch), GetBuffer()->GetChannel(ch), bufferSize);
120 mFeedbackVizBuffer.WriteChunk(GetBuffer()->GetChannel(ch), bufferSize, ch);
121 }
122 else
123 {

Callers

nothing calls this directly

Calls 11

AddFunction · 0.85
BufferSizeMethod · 0.80
NumActiveChannelsMethod · 0.80
GetChannelMethod · 0.80
GetBufferMethod · 0.80
WriteChunkMethod · 0.80
SetNumActiveChannelsMethod · 0.80
SetNumChannelsMethod · 0.80
ProcessAudioMethod · 0.45
IsEnabledMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected