| 197 | } |
| 198 | |
| 199 | void BandProcessor::processDistortion(juce::dsp::AudioBlock<float>& blockToProcess, |
| 200 | const juce::AudioBuffer<float>& dryBuffer, // This is original-sized dry buffer |
| 201 | const BandProcessingParameters& params) |
| 202 | { |
| 203 | // Create a copy of the incoming block (which might be oversampled) |
| 204 | // to use as the correctly-sized "dry" signal for the shape mixer. |
| 205 | // This must be done BEFORE blockToProcess is modified. |
| 206 | auto dryBlockForShapeMixer = blockToProcess; |
| 207 | |
| 208 | // Now, push this correctly-sized dry block into the mixer. |
| 209 | shapeMixer.setWetMixProportion(params.shapeMixVal); |
| 210 | shapeMixer.pushDrySamples(dryBlockForShapeMixer); |
| 211 | |
| 212 | const int numSamples = (int) blockToProcess.getNumSamples(); |
| 213 | const int numChannels = (int) blockToProcess.getNumChannels(); |
| 214 | |
| 215 | // Note: mSampleMaxValue is still calculated from the original-sized dryBuffer, which is correct. |
| 216 | this->mSampleMaxValue = dryBuffer.getMagnitude(0, dryBuffer.getNumSamples()); |
| 217 | auto waveshaperFunction = DistortionLogic::getWaveshaperForMode(params.mode); |
| 218 | |
| 219 | // The providers are now correctly prepared with LFO signals (if any) |
| 220 | auto driveProvider = params.driveVal; |
| 221 | auto biasProvider = params.biasVal; |
| 222 | auto recProvider = params.recVal; |
| 223 | |
| 224 | if (! params.isShapeEnabled) |
| 225 | { |
| 226 | // Disable LFO modulation for Bias and Rectification |
| 227 | biasProvider.baseValue = 0.0f; |
| 228 | recProvider.baseValue = 0.0f; |
| 229 | biasProvider.lfoSignal = nullptr; |
| 230 | recProvider.lfoSignal = nullptr; |
| 231 | } |
| 232 | |
| 233 | DistortionLogic::State currentState; |
| 234 | currentState.mode = params.mode; |
| 235 | |
| 236 | if (isFirstBlock) |
| 237 | { |
| 238 | // On the first block, calculate the FINAL gain for the *first sample* |
| 239 | // to properly initialize the smoothers and prevent clicks. |
| 240 | |
| 241 | float initialFinalDriveGain; |
| 242 | |
| 243 | if (! params.isDriveEnabled) |
| 244 | { |
| 245 | // If bypassed at startup, initialize the smoother to a gain of 1.0. |
| 246 | initialFinalDriveGain = 1.0f; |
| 247 | } |
| 248 | else |
| 249 | { |
| 250 | // If not bypassed, perform the full calculation as before. |
| 251 | float initialDrive = driveProvider.get(0); // Get LFO-modulated value for sample 0 |
| 252 | if (params.isExtremeModeOn) |
| 253 | initialDrive = log2f(10.0f) * initialDrive; |
| 254 | const float initialDriveForCalc = initialDrive * 6.5f / 100.0f; |
| 255 | float initialPowerDrive = std::pow(2.0f, initialDriveForCalc); |
| 256 |
nothing calls this directly
no test coverage detected