1 | /**************************************************************************/ |
2 | /* audio_effect_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 AUDIO_EFFECT_FILTER_H |
32 | #define AUDIO_EFFECT_FILTER_H |
33 | |
34 | #include "servers/audio/audio_effect.h" |
35 | #include "servers/audio/audio_filter_sw.h" |
36 | |
37 | class AudioEffectFilter; |
38 | |
39 | class AudioEffectFilterInstance : public AudioEffectInstance { |
40 | GDCLASS(AudioEffectFilterInstance, AudioEffectInstance); |
41 | friend class AudioEffectFilter; |
42 | |
43 | Ref<AudioEffectFilter> base; |
44 | |
45 | AudioFilterSW filter; |
46 | AudioFilterSW::Processor filter_process[2][4]; |
47 | |
48 | template <int S> |
49 | void _process_filter(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count); |
50 | |
51 | public: |
52 | virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) override; |
53 | |
54 | AudioEffectFilterInstance(); |
55 | }; |
56 | |
57 | class AudioEffectFilter : public AudioEffect { |
58 | GDCLASS(AudioEffectFilter, AudioEffect); |
59 | |
60 | public: |
61 | enum FilterDB { |
62 | FILTER_6DB, |
63 | FILTER_12DB, |
64 | FILTER_18DB, |
65 | FILTER_24DB, |
66 | }; |
67 | friend class AudioEffectFilterInstance; |
68 | |
69 | AudioFilterSW::Mode mode; |
70 | float cutoff; |
71 | float resonance; |
72 | float gain; |
73 | FilterDB db; |
74 | |
75 | protected: |
76 | static void _bind_methods(); |
77 | |
78 | public: |
79 | void set_cutoff(float p_freq); |
80 | float get_cutoff() const; |
81 | |
82 | void set_resonance(float p_amount); |
83 | float get_resonance() const; |
84 | |
85 | void set_gain(float p_amount); |
86 | float get_gain() const; |
87 | |
88 | void set_db(FilterDB p_db); |
89 | FilterDB get_db() const; |
90 | |
91 | Ref<AudioEffectInstance> instantiate() override; |
92 | |
93 | AudioEffectFilter(AudioFilterSW::Mode p_mode = AudioFilterSW::LOWPASS); |
94 | }; |
95 | |
96 | VARIANT_ENUM_CAST(AudioEffectFilter::FilterDB) |
97 | |
98 | class AudioEffectLowPassFilter : public AudioEffectFilter { |
99 | GDCLASS(AudioEffectLowPassFilter, AudioEffectFilter); |
100 | |
101 | void _validate_property(PropertyInfo &p_property) const { |
102 | if (p_property.name == "gain" ) { |
103 | p_property.usage = PROPERTY_USAGE_NONE; |
104 | } |
105 | } |
106 | |
107 | public: |
108 | AudioEffectLowPassFilter() : |
109 | AudioEffectFilter(AudioFilterSW::LOWPASS) {} |
110 | }; |
111 | |
112 | class AudioEffectHighPassFilter : public AudioEffectFilter { |
113 | GDCLASS(AudioEffectHighPassFilter, AudioEffectFilter); |
114 | void _validate_property(PropertyInfo &p_property) const { |
115 | if (p_property.name == "gain" ) { |
116 | p_property.usage = PROPERTY_USAGE_NONE; |
117 | } |
118 | } |
119 | |
120 | public: |
121 | AudioEffectHighPassFilter() : |
122 | AudioEffectFilter(AudioFilterSW::HIGHPASS) {} |
123 | }; |
124 | |
125 | class AudioEffectBandPassFilter : public AudioEffectFilter { |
126 | GDCLASS(AudioEffectBandPassFilter, AudioEffectFilter); |
127 | void _validate_property(PropertyInfo &p_property) const { |
128 | if (p_property.name == "gain" ) { |
129 | p_property.usage = PROPERTY_USAGE_NONE; |
130 | } |
131 | } |
132 | |
133 | public: |
134 | AudioEffectBandPassFilter() : |
135 | AudioEffectFilter(AudioFilterSW::BANDPASS) {} |
136 | }; |
137 | |
138 | class AudioEffectNotchFilter : public AudioEffectFilter { |
139 | GDCLASS(AudioEffectNotchFilter, AudioEffectFilter); |
140 | |
141 | public: |
142 | AudioEffectNotchFilter() : |
143 | AudioEffectFilter(AudioFilterSW::NOTCH) {} |
144 | }; |
145 | |
146 | class AudioEffectBandLimitFilter : public AudioEffectFilter { |
147 | GDCLASS(AudioEffectBandLimitFilter, AudioEffectFilter); |
148 | |
149 | public: |
150 | AudioEffectBandLimitFilter() : |
151 | AudioEffectFilter(AudioFilterSW::BANDLIMIT) {} |
152 | }; |
153 | |
154 | class AudioEffectLowShelfFilter : public AudioEffectFilter { |
155 | GDCLASS(AudioEffectLowShelfFilter, AudioEffectFilter); |
156 | |
157 | public: |
158 | AudioEffectLowShelfFilter() : |
159 | AudioEffectFilter(AudioFilterSW::LOWSHELF) {} |
160 | }; |
161 | |
162 | class AudioEffectHighShelfFilter : public AudioEffectFilter { |
163 | GDCLASS(AudioEffectHighShelfFilter, AudioEffectFilter); |
164 | |
165 | public: |
166 | AudioEffectHighShelfFilter() : |
167 | AudioEffectFilter(AudioFilterSW::HIGHSHELF) {} |
168 | }; |
169 | |
170 | #endif // AUDIO_EFFECT_FILTER_H |
171 | |