AnalogTapeModel

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

WowProcess.h (1562B)


      1 #ifndef WOWPROCESS_H_INCLUDED
      2 #define WOWPROCESS_H_INCLUDED
      3 
      4 #include "OHProcess.h"
      5 #include <JuceHeader.h>
      6 
      7 class WowProcess
      8 {
      9 public:
     10     WowProcess() = default;
     11     ~WowProcess();
     12 
     13     void prepare (double sampleRate, int samplesPerBlock, int numChannels);
     14     void prepareBlock (float curDepth, float wowFreq, float wowVar, float wowDrift, int numSamples, int numChannels);
     15     void plotBuffer (foleys::MagicPlotSource* plot);
     16 
     17     inline bool shouldTurnOff() const noexcept { return depthSlew[0].getTargetValue() == depthSlewMin; }
     18     inline void updatePhase (size_t ch) noexcept { phase[ch] += angleDelta; }
     19 
     20     inline std::pair<float, float> getLFO (int n, size_t ch) noexcept
     21     {
     22         updatePhase (ch);
     23         auto curDepth = depthSlew[ch].getNextValue() * amp;
     24         wowPtrs[ch][n] = curDepth * (std::cos (phase[ch]) + ohProc.process (n, ch));
     25         return std::make_pair (wowPtrs[ch][n], curDepth);
     26     }
     27 
     28     inline void boundPhase (size_t ch) noexcept
     29     {
     30         while (phase[ch] >= MathConstants<float>::twoPi)
     31             phase[ch] -= MathConstants<float>::twoPi;
     32     }
     33 
     34 private:
     35     float angleDelta = 0.0f;
     36     float amp = 0.0f;
     37     std::vector<float> phase;
     38     std::vector<SmoothedValue<float, ValueSmoothingTypes::Multiplicative>> depthSlew;
     39 
     40     AudioBuffer<float> wowBuffer;
     41     float** wowPtrs = nullptr;
     42     float fs = 44100.0f;
     43 
     44     OHProcess ohProc;
     45     Random driftRand;
     46 
     47     static constexpr float depthSlewMin = 0.001f;
     48 
     49     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WowProcess)
     50 };
     51 
     52 #endif // WOWPROCESS_H_INCLUDED