Debian Codegraph @

servers/audio/effects/audio_effect_chorus.h

raw symbols SCIP
1 /**************************************************************************/
2 /* audio_effect_chorus.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 "servers/audio/audio_effect.h"
34
35 class AudioEffectChorus;
36
37 class AudioEffectChorusInstance : public AudioEffectInstance {
38 GDCLASS(AudioEffectChorusInstance, AudioEffectInstance);
39 friend class AudioEffectChorus;
40 Ref<AudioEffectChorus> base;
41
42 Vector<AudioFrame> audio_buffer;
43 unsigned int buffer_pos;
44 unsigned int buffer_mask;
45
46 AudioFrame filter_h[4];
47 uint64_t cycles[4];
48
49 void _process_chunk(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
55 class AudioEffectChorus : public AudioEffect {
56 GDCLASS(AudioEffectChorus, AudioEffect);
57
58 friend class AudioEffectChorusInstance;
59
60 public:
61 static constexpr int32_t MAX_DELAY_MS = 50;
62 static constexpr int32_t MAX_DEPTH_MS = 20;
63 static constexpr int32_t MAX_WIDTH_MS = 50;
64 static constexpr int32_t MAX_VOICES = 4;
65 static constexpr int32_t CYCLES_FRAC = 16;
66 static constexpr int32_t CYCLES_MASK = (1 << CYCLES_FRAC) - 1;
67 static constexpr int32_t MAX_CHANNELS = 4;
68 static constexpr int32_t MS_CUTOFF_MAX = 16000;
69
70 private:
71 struct Voice {
72 float delay;
73 float rate;
74 float depth;
75 float level;
76 float cutoff;
77 float pan;
78
79 Voice() {
80 delay = 12.0;
81 rate = 1;
82 depth = 0;
83 level = 0;
84 cutoff = MS_CUTOFF_MAX;
85 pan = 0;
86 }
87
88 } voice[MAX_VOICES];
89
90 int voice_count;
91
92 float wet;
93 float dry;
94
95 protected:
96 void _validate_property(PropertyInfo &p_property) const;
97
98 static void _bind_methods();
99
100 public:
101 void set_voice_count(int p_voices);
102 int get_voice_count() const;
103
104 void set_voice_delay_ms(int p_voice, float p_delay_ms);
105 float get_voice_delay_ms(int p_voice) const;
106
107 void set_voice_rate_hz(int p_voice, float p_rate_hz);
108 float get_voice_rate_hz(int p_voice) const;
109
110 void set_voice_depth_ms(int p_voice, float p_depth_ms);
111 float get_voice_depth_ms(int p_voice) const;
112
113 void set_voice_level_db(int p_voice, float p_level_db);
114 float get_voice_level_db(int p_voice) const;
115
116 void set_voice_cutoff_hz(int p_voice, float p_cutoff_hz);
117 float get_voice_cutoff_hz(int p_voice) const;
118
119 void set_voice_pan(int p_voice, float p_pan);
120 float get_voice_pan(int p_voice) const;
121
122 void set_wet(float amount);
123 float get_wet() const;
124
125 void set_dry(float amount);
126 float get_dry() const;
127
128 Ref<AudioEffectInstance> instantiate() override;
129
130 AudioEffectChorus();
131 };