AnalogTapeModel

Physical modelling signal processing for analog tape recording
Log | Files | Refs | Submodules | README | LICENSE

DryWetProcessor.h (1413B)


      1 #ifndef DRYWETPROCESSOR_H_INCLUDED
      2 #define DRYWETPROCESSOR_H_INCLUDED
      3 
      4 #include "JuceHeader.h"
      5 
      6 /** Simple processor to mix dry and wet signals */
      7 class DryWetProcessor
      8 {
      9 public:
     10     DryWetProcessor() {}
     11 
     12     void setDryWet (float newDryWet) { dryWet = newDryWet; }
     13     float getDryWet() const noexcept { return dryWet; }
     14 
     15     void reset() { lastDryWet = dryWet; }
     16 
     17     /**
     18       Mix dry and wet buffer. Mixed buffer returned in place of wet buffer
     19     */
     20     void processBlock (AudioBuffer<float>& dryBuffer, AudioBuffer<float>& wetBuffer)
     21     {
     22         if (lastDryWet == dryWet)
     23         {
     24             wetBuffer.applyGain (dryWet);
     25             for (int ch = 0; ch < wetBuffer.getNumChannels(); ++ch)
     26                 wetBuffer.addFrom (ch, 0, dryBuffer.getReadPointer (ch), wetBuffer.getNumSamples(), (1.0f - dryWet));
     27         }
     28         else
     29         {
     30             for (int ch = 0; ch < wetBuffer.getNumChannels(); ++ch)
     31             {
     32                 wetBuffer.applyGainRamp (ch, 0, wetBuffer.getNumSamples(), lastDryWet, dryWet);
     33                 wetBuffer.addFromWithRamp (ch, 0, dryBuffer.getReadPointer (ch), wetBuffer.getNumSamples(), (1.0f - lastDryWet), (1.0f - dryWet));
     34             }
     35 
     36             lastDryWet = dryWet;
     37         }
     38     }
     39 
     40 private:
     41     float dryWet = 0.0f;
     42     float lastDryWet = 0.0f;
     43 
     44     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DryWetProcessor)
     45 };
     46 
     47 #endif //DRYWETPROCESSOR_H_INCLUDED