1 | /**************************************************************************/ |
2 | /* audio_effect_eq.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_EQ_H |
32 | #define AUDIO_EFFECT_EQ_H |
33 | |
34 | #include "servers/audio/audio_effect.h" |
35 | #include "servers/audio/effects/eq_filter.h" |
36 | |
37 | class AudioEffectEQ; |
38 | |
39 | class AudioEffectEQInstance : public AudioEffectInstance { |
40 | GDCLASS(AudioEffectEQInstance, AudioEffectInstance); |
41 | friend class AudioEffectEQ; |
42 | Ref<AudioEffectEQ> base; |
43 | |
44 | Vector<EQ::BandProcess> bands[2]; |
45 | Vector<float> gains; |
46 | |
47 | public: |
48 | virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) override; |
49 | }; |
50 | |
51 | class AudioEffectEQ : public AudioEffect { |
52 | GDCLASS(AudioEffectEQ, AudioEffect); |
53 | |
54 | friend class AudioEffectEQInstance; |
55 | |
56 | EQ eq; |
57 | Vector<float> gain; |
58 | HashMap<StringName, int> prop_band_map; |
59 | Vector<String> band_names; |
60 | |
61 | protected: |
62 | bool _set(const StringName &p_name, const Variant &p_value); |
63 | bool _get(const StringName &p_name, Variant &r_ret) const; |
64 | void _get_property_list(List<PropertyInfo> *p_list) const; |
65 | |
66 | static void _bind_methods(); |
67 | |
68 | public: |
69 | Ref<AudioEffectInstance> instantiate() override; |
70 | void set_band_gain_db(int p_band, float p_volume); |
71 | float get_band_gain_db(int p_band) const; |
72 | int get_band_count() const; |
73 | |
74 | AudioEffectEQ(EQ::Preset p_preset = EQ::PRESET_6_BANDS); |
75 | }; |
76 | |
77 | class AudioEffectEQ6 : public AudioEffectEQ { |
78 | GDCLASS(AudioEffectEQ6, AudioEffectEQ); |
79 | |
80 | public: |
81 | AudioEffectEQ6() : |
82 | AudioEffectEQ(EQ::PRESET_6_BANDS) {} |
83 | }; |
84 | |
85 | class AudioEffectEQ10 : public AudioEffectEQ { |
86 | GDCLASS(AudioEffectEQ10, AudioEffectEQ); |
87 | |
88 | public: |
89 | AudioEffectEQ10() : |
90 | AudioEffectEQ(EQ::PRESET_10_BANDS) {} |
91 | }; |
92 | |
93 | class AudioEffectEQ21 : public AudioEffectEQ { |
94 | GDCLASS(AudioEffectEQ21, AudioEffectEQ); |
95 | |
96 | public: |
97 | AudioEffectEQ21() : |
98 | AudioEffectEQ(EQ::PRESET_21_BANDS) {} |
99 | }; |
100 | |
101 | #endif // AUDIO_EFFECT_EQ_H |
102 | |