1 | /**************************************************************************/ |
2 | /* reverb_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 | #ifndef REVERB_FILTER_H |
32 | #define REVERB_FILTER_H |
33 | |
34 | #include "core/math/audio_frame.h" |
35 | #include "core/os/memory.h" |
36 | #include "core/typedefs.h" |
37 | |
38 | class Reverb { |
39 | public: |
40 | enum { |
41 | INPUT_BUFFER_MAX_SIZE = 1024, |
42 | |
43 | }; |
44 | |
45 | private: |
46 | enum { |
47 | MAX_COMBS = 8, |
48 | MAX_ALLPASS = 4, |
49 | MAX_ECHO_MS = 500 |
50 | |
51 | }; |
52 | |
53 | static const float comb_tunings[MAX_COMBS]; |
54 | static const float allpass_tunings[MAX_ALLPASS]; |
55 | |
56 | struct Comb { |
57 | int size = 0; |
58 | float *buffer = nullptr; |
59 | float feedback = 0; |
60 | float damp = 0; //lowpass |
61 | float damp_h = 0; //history |
62 | int pos = 0; |
63 | int = 0; |
64 | |
65 | Comb() {} |
66 | }; |
67 | |
68 | struct AllPass { |
69 | int size = 0; |
70 | float *buffer = nullptr; |
71 | int pos = 0; |
72 | int = 0; |
73 | AllPass() {} |
74 | }; |
75 | |
76 | Comb comb[MAX_COMBS]; |
77 | AllPass allpass[MAX_ALLPASS]; |
78 | float *input_buffer = nullptr; |
79 | float *echo_buffer = nullptr; |
80 | int echo_buffer_size = 0; |
81 | int echo_buffer_pos = 0; |
82 | |
83 | float hpf_h1 = 0.0f; |
84 | float hpf_h2 = 0.0f; |
85 | |
86 | struct Parameters { |
87 | float room_size; |
88 | float damp; |
89 | float wet; |
90 | float dry; |
91 | float mix_rate; |
92 | float ; |
93 | float ; |
94 | float predelay; |
95 | float predelay_fb; |
96 | float hpf; |
97 | } params; |
98 | |
99 | void configure_buffers(); |
100 | void update_parameters(); |
101 | void clear_buffers(); |
102 | |
103 | public: |
104 | void set_room_size(float p_size); |
105 | void set_damp(float p_damp); |
106 | void set_wet(float p_wet); |
107 | void set_dry(float p_dry); |
108 | void set_predelay(float p_predelay); // in ms |
109 | void set_predelay_feedback(float p_predelay_fb); // in ms |
110 | void set_highpass(float p_frq); |
111 | void set_mix_rate(float p_mix_rate); |
112 | void (float p_spread); |
113 | void (float p_sec); |
114 | |
115 | void process(float *p_src, float *p_dst, int p_frames); |
116 | |
117 | Reverb(); |
118 | |
119 | ~Reverb(); |
120 | }; |
121 | |
122 | #endif // REVERB_FILTER_H |
123 | |