DegradeNoise.h (1058B)
1 #ifndef DEGRADENOISE_H_INCLUDED 2 #define DEGRADENOISE_H_INCLUDED 3 4 #include "JuceHeader.h" 5 6 /** Noise for tape degrade effect */ 7 class DegradeNoise 8 { 9 public: 10 DegradeNoise() = default; 11 DegradeNoise (DegradeNoise&&) noexcept = default; 12 13 void setGain (float newGain) { curGain = newGain; } 14 15 void prepare() 16 { 17 prevGain = curGain; 18 } 19 20 void processBlock (float* buffer, int numSamples) 21 { 22 if (curGain == prevGain) 23 { 24 for (int n = 0; n < numSamples; ++n) 25 buffer[n] += (random.nextFloat() - 0.5f) * curGain; 26 } 27 else 28 { 29 for (int n = 0; n < numSamples; ++n) 30 buffer[n] += (random.nextFloat() - 0.5f) * ((curGain * (float) n / (float) numSamples) + (prevGain * (1.0f - (float) n / (float) numSamples))); 31 32 prevGain = curGain; 33 } 34 } 35 36 private: 37 float curGain = 0.0f; 38 float prevGain = curGain; 39 40 Random random; 41 42 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DegradeNoise) 43 }; 44 45 #endif // DEGRADENOISE_H_INCLUDED