Line data Source code
1 : #pragma once
2 :
3 : // Tempo-independent ring-buffer delay line with feedback and wet/dry control.
4 : // The circular buffer reads d samples behind the write head and writes
5 : // x[n] + feedback*y_delay[n]; output is y[n]=(1-mix)*x[n]+mix*y_delay[n], with
6 : // a one-pole tone filter shaping repeated echoes.
7 :
8 : #include "audio/effects/effect.h"
9 : #include "audio/dsp/biquad.h"
10 :
11 : namespace Amplitron {
12 :
13 : class Delay : public Effect {
14 : public:
15 : Delay();
16 : void process(float* buffer, int num_samples) override;
17 : void set_sample_rate(int sample_rate) override;
18 : void set_transport_state(float bpm) override;
19 : void reset() override;
20 326 : const char* name() const override { return "Delay"; }
21 3 : const char* type_id() const override { return "Delay"; }
22 235 : std::vector<EffectParam>& params() override { return params_; }
23 :
24 : private:
25 : std::vector<EffectParam> params_;
26 : std::vector<float> delay_buffer_;
27 : int write_pos_ = 0;
28 : int max_delay_samples_ = 0;
29 : OnePole tone_lp_;
30 :
31 : // One-pole smoothed parameter states
32 : float smoothed_time_ms_ = 350.0f;
33 : float smoothed_feedback_ = 0.4f;
34 : float smoothed_tone_ = 0.7f;
35 : float smoothed_level_ = 0.5f;
36 :
37 : //shortcut if bpm hasn't changed
38 : float last_bpm_ = 0.0f;
39 : };
40 :
41 : } // namespace Amplitron
|