AnalogTapeModel

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

HysteresisProcessor.h (2860B)


      1 #ifndef HYSTERESISPROCESSOR_H_INCLUDED
      2 #define HYSTERESISPROCESSOR_H_INCLUDED
      3 
      4 #include "../BypassProcessor.h"
      5 #include "DCBlocker.h"
      6 #include "HysteresisProcessing.h"
      7 
      8 /* Hysteresis Processor for tape. */
      9 class HysteresisProcessor
     10 {
     11 public:
     12     HysteresisProcessor (AudioProcessorValueTreeState& vts);
     13 
     14     /* Reset fade buffers, filters, and processors. Prepare oversampling */
     15     void prepareToPlay (double sampleRate, int samplesPerBlock, int numChannels);
     16 
     17     /* Reset oversampling */
     18     void releaseResources();
     19 
     20     /* Proceess a buffer. */
     21     void processBlock (AudioBuffer<float>& buffer);
     22 
     23     static void createParameterLayout (chowdsp::Parameters& params);
     24 
     25     float getLatencySamples() const noexcept;
     26     auto& getOSManager() { return osManager; }
     27 
     28 private:
     29     void setSolver (int newSolver);
     30     void setDrive (float newDrive);
     31     void setSaturation (float newSat);
     32     void setWidth (float newWidth);
     33     void setOversampling();
     34     double calcMakeup();
     35     void calcBiasFreq();
     36 
     37     template <SolverType solverType, typename T>
     38     void process (chowdsp::AudioBlock<T>& block);
     39     template <SolverType solverType, typename T>
     40     void processSmooth (chowdsp::AudioBlock<T>& block);
     41     template <typename T>
     42     void processV1 (chowdsp::AudioBlock<T>& block);
     43     template <typename T>
     44     void processSmoothV1 (chowdsp::AudioBlock<T>& block);
     45     void applyDCBlockers (AudioBuffer<float>& buffer);
     46 
     47     chowdsp::FloatParameter* driveParam = nullptr;
     48     chowdsp::FloatParameter* satParam = nullptr;
     49     chowdsp::FloatParameter* widthParam = nullptr;
     50     std::atomic<float>* modeParam = nullptr;
     51     std::atomic<float>* onOffParam = nullptr;
     52 
     53     std::vector<SmoothedValue<double, ValueSmoothingTypes::Linear>> drive;
     54     std::vector<SmoothedValue<double, ValueSmoothingTypes::Linear>> width;
     55     std::vector<SmoothedValue<double, ValueSmoothingTypes::Linear>> sat;
     56     SmoothedValue<double, ValueSmoothingTypes::Multiplicative> makeup;
     57 
     58     double fs = 44100.0f;
     59     chowdsp::VariableOversampling<double> osManager; // needs oversampling to avoid aliasing
     60     std::vector<HysteresisProcessing> hProcs;
     61     SolverType solver = SolverType::RK4;
     62     std::vector<DCBlocker> dcBlocker;
     63 
     64     static constexpr double dcFreq = 35.0;
     65 
     66     double biasGain = 10.0;
     67     double biasFreq = 48000.0;
     68     std::vector<double> biasAngle;
     69     bool wasV1 = false, useV1 = false;
     70     float clipLevel = 20.0f;
     71 
     72     AudioBuffer<double> doubleBuffer;
     73     BypassProcessor bypass;
     74 
     75 #if HYSTERESIS_USE_SIMD
     76     using Vec2 = xsimd::batch<double>;
     77     chowdsp::AudioBlock<Vec2> interleavedBlock;
     78     chowdsp::AudioBlock<double> zeroBlock;
     79 
     80     HeapBlock<char> interleavedBlockData, zeroData;
     81     std::vector<const double*> channelPointers;
     82 #endif
     83 
     84     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HysteresisProcessor)
     85 };
     86 
     87 #endif //HYSTERESISPROCESSOR_H_INCLUDED