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

Method ProcessAudio

Source/DistortionEffect.cpp:66–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64}
65
66void DistortionEffect::ProcessAudio(double time, ChannelBuffer* buffer)
67{
68 PROFILER(DistortionEffect);
69
70 if (!mEnabled)
71 return;
72
73 float bufferSize = buffer->BufferSize();
74
75 for (int ch = 0; ch < buffer->NumActiveChannels(); ++ch)
76 {
77 if (mRemoveInputDC)
78 mDCRemover[ch].Filter(buffer->GetChannel(ch), bufferSize);
79
80 mPeakTracker[ch].Process(buffer->GetChannel(ch), bufferSize);
81
82 if (mType == kDirty)
83 {
84 for (int i = 0; i < bufferSize; ++i)
85 {
86 ComputeSliders(i);
87 buffer->GetChannel(ch)[i] = (ofClamp((buffer->GetChannel(ch)[i] + mFuzzAmount * mPeakTracker[ch].GetPeak()) * mPreamp * mGain, -1, 1)) / mGain;
88 }
89 }
90 else if (mType == kClean)
91 {
92 for (int i = 0; i < bufferSize; ++i)
93 {
94 ComputeSliders(i);
95 buffer->GetChannel(ch)[i] = tanh((buffer->GetChannel(ch)[i] + mFuzzAmount * mPeakTracker[ch].GetPeak()) * mPreamp * mGain) / mGain;
96 }
97 }
98 else if (mType == kWarm)
99 {
100 for (int i = 0; i < bufferSize; ++i)
101 {
102 ComputeSliders(i);
103 buffer->GetChannel(ch)[i] = sin((buffer->GetChannel(ch)[i] + mFuzzAmount * mPeakTracker[ch].GetPeak()) * mPreamp * mGain) / mGain;
104 }
105 }
106 else if (mType == kGrungy)
107 {
108 for (int i = 0; i < bufferSize; ++i)
109 {
110 ComputeSliders(i);
111 buffer->GetChannel(ch)[i] = asin(ofClamp((buffer->GetChannel(ch)[i] + mFuzzAmount * mPeakTracker[ch].GetPeak()) * mPreamp * mGain, -1, 1)) / mGain;
112 }
113 }
114 //soft and asymmetric from http://www.music.mcgill.ca/~gary/courses/projects/618_2009/NickDonaldson/#Distortion
115 else if (mType == kSoft)
116 {
117 for (int i = 0; i < bufferSize; ++i)
118 {
119 ComputeSliders(i);
120 float sample = (buffer->GetChannel(ch)[i] + mFuzzAmount * mPeakTracker[ch].GetPeak()) * mPreamp * mGain;
121 if (sample > 1)
122 sample = .66666f;
123 else if (sample < -1)

Callers

nothing calls this directly

Calls 7

ofClampFunction · 0.85
BufferSizeMethod · 0.80
NumActiveChannelsMethod · 0.80
GetChannelMethod · 0.80
GetPeakMethod · 0.80
FilterMethod · 0.60
ProcessMethod · 0.45

Tested by

no test coverage detected