chenlh
2026-03-10 0f65a1a9267b8a7ab4678ef20b07532e4c8377ca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 
#pragma once
 
namespace ReverbHallRoom
{
    class Biquad
    {
    public:
        enum class FilterType
        {
            LowPass6db = 0,
            HighPass6db,
            LowPass,
            HighPass,
            BandPass,
            Notch,
            Peak,
            LowShelf,
            HighShelf
        };
 
    private:
        float fs;
        float fsInv;
        float gainDB;
        float q;
        float a0, a1, a2, b0, b1, b2;
        float x1, x2, y, y1, y2;
        float gain;
 
    public:
        FilterType Type;
        float Output;
        float Frequency;
 
        Biquad();
        Biquad(FilterType filterType, float fs);
        ~Biquad();
 
        float GetSamplerate();
        void SetSamplerate(float fs);
        float GetGainDb();
        void SetGainDb(float value);
        float GetGain();
        void SetGain(float value);
        float GetQ();
        void SetQ(float value);
 
        void Update();
 
        double GetResponse(float freq) const;
 
        float inline Process(float x)
        {
            y = b0 * x + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;
            x2 = x1;
            y2 = y1;
            x1 = x;
            y1 = y;
 
            Output = y;
            return Output;
        }
 
        void inline Process(float* input, float* output, int len)
        {
            for (int i = 0; i < len; i++)
            {
                float x = input[i];
                y = ((b0 * x) + (b1 * x1) + (b2 * x2)) - (a1 * y1) - (a2 * y2);
                x2 = x1;
                y2 = y1;
                x1 = x;
                y1 = y;
 
                output[i] = y;
            }
 
            Output = y;
        }
 
        void ClearBuffers();
    };
}