1 | /**************************************************************************/ |
2 | /* audio_effect_compressor.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_COMPRESSOR_H |
32 | #define AUDIO_EFFECT_COMPRESSOR_H |
33 | |
34 | #include "servers/audio/audio_effect.h" |
35 | |
36 | class AudioEffectCompressor; |
37 | |
38 | class AudioEffectCompressorInstance : public AudioEffectInstance { |
39 | GDCLASS(AudioEffectCompressorInstance, AudioEffectInstance); |
40 | friend class AudioEffectCompressor; |
41 | Ref<AudioEffectCompressor> base; |
42 | |
43 | float rundb, averatio, runratio, runmax, maxover, gr_meter; |
44 | int current_channel; |
45 | |
46 | public: |
47 | void set_current_channel(int p_channel) { current_channel = p_channel; } |
48 | virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) override; |
49 | }; |
50 | |
51 | class AudioEffectCompressor : public AudioEffect { |
52 | GDCLASS(AudioEffectCompressor, AudioEffect); |
53 | |
54 | friend class AudioEffectCompressorInstance; |
55 | float threshold; |
56 | float ratio; |
57 | float gain; |
58 | float attack_us; |
59 | float release_ms; |
60 | float mix; |
61 | StringName sidechain; |
62 | |
63 | protected: |
64 | void _validate_property(PropertyInfo &p_property) const; |
65 | static void _bind_methods(); |
66 | |
67 | public: |
68 | Ref<AudioEffectInstance> instantiate() override; |
69 | |
70 | void set_threshold(float p_threshold); |
71 | float get_threshold() const; |
72 | |
73 | void set_ratio(float p_ratio); |
74 | float get_ratio() const; |
75 | |
76 | void set_gain(float p_gain); |
77 | float get_gain() const; |
78 | |
79 | void set_attack_us(float p_attack_us); |
80 | float get_attack_us() const; |
81 | |
82 | void set_release_ms(float p_release_ms); |
83 | float get_release_ms() const; |
84 | |
85 | void set_mix(float p_mix); |
86 | float get_mix() const; |
87 | |
88 | void set_sidechain(const StringName &p_sidechain); |
89 | StringName get_sidechain() const; |
90 | |
91 | AudioEffectCompressor(); |
92 | }; |
93 | |
94 | #endif // AUDIO_EFFECT_COMPRESSOR_H |
95 | |