Debian Codegraph @

servers/audio/effects/eq_filter.h

raw symbols SCIP
1 /**************************************************************************/
2 /* eq_filter.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/templates/vector.h"
34
35 class EQ {
36 public:
37 enum Preset {
38 PRESET_6_BANDS,
39 PRESET_8_BANDS,
40 PRESET_10_BANDS,
41 PRESET_21_BANDS,
42 PRESET_31_BANDS
43 };
44
45 class BandProcess {
46 friend class EQ;
47 float c1, c2, c3;
48 struct History {
49 float a1, a2, a3;
50 float b1, b2, b3;
51
52 } history;
53
54 public:
55 inline void process_one(float &p_data);
56
57 BandProcess();
58 };
59
60 private:
61 struct Band {
62 float freq;
63 float c1, c2, c3;
64 };
65
66 Vector<Band> band;
67
68 float mix_rate;
69
70 void recalculate_band_coefficients();
71
72 public:
73 void set_mix_rate(float p_mix_rate);
74
75 int get_band_count() const;
76 void set_preset_band_mode(Preset p_preset);
77 void set_bands(const Vector<float> &p_bands);
78 BandProcess get_band_processor(int p_band) const;
79 float get_band_frequency(int p_band);
80
81 EQ();
82 ~EQ();
83 };
84
85 /* Inline Function */
86
87 inline void EQ::BandProcess::process_one(float &p_data) {
88 history.a1 = p_data;
89
90 history.b1 = c1 * (history.a1 - history.a3) + c3 * history.b2 - c2 * history.b3;
91
92 p_data = history.b1;
93
94 history.a3 = history.a2;
95 history.a2 = history.a1;
96 history.b3 = history.b2;
97 history.b2 = history.b1;
98 }