1/**************************************************************************/
2/* audio_effect_delay.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_DELAY_H
32#define AUDIO_EFFECT_DELAY_H
33
34#include "servers/audio/audio_effect.h"
35
36class AudioEffectDelay;
37
38class AudioEffectDelayInstance : public AudioEffectInstance {
39 GDCLASS(AudioEffectDelayInstance, AudioEffectInstance);
40
41 friend class AudioEffectDelay;
42 Ref<AudioEffectDelay> base;
43
44 Vector<AudioFrame> ring_buffer;
45
46 unsigned int ring_buffer_pos;
47 unsigned int ring_buffer_mask;
48
49 /* feedback buffer */
50 Vector<AudioFrame> feedback_buffer;
51
52 unsigned int feedback_buffer_pos;
53
54 AudioFrame h;
55 void _process_chunk(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count);
56
57public:
58 virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) override;
59};
60
61class AudioEffectDelay : public AudioEffect {
62 GDCLASS(AudioEffectDelay, AudioEffect);
63
64 friend class AudioEffectDelayInstance;
65 enum {
66 MAX_DELAY_MS = 3000,
67 MAX_TAPS = 2
68 };
69
70 float dry = 1.0f;
71
72 bool tap_1_active = true;
73 float tap_1_delay_ms = 250.0f;
74 float tap_1_level = -6.0f;
75 float tap_1_pan = 0.2f;
76
77 bool tap_2_active = true;
78 float tap_2_delay_ms = 500.0f;
79 float tap_2_level = -12.0f;
80 float tap_2_pan = -0.4f;
81
82 bool feedback_active = false;
83 float feedback_delay_ms = 340.0f;
84 float feedback_level = -6.0f;
85 float feedback_lowpass = 16000.0f;
86
87protected:
88 static void _bind_methods();
89
90public:
91 void set_dry(float p_dry);
92 float get_dry();
93
94 void set_tap1_active(bool p_active);
95 bool is_tap1_active() const;
96
97 void set_tap1_delay_ms(float p_delay_ms);
98 float get_tap1_delay_ms() const;
99
100 void set_tap1_level_db(float p_level_db);
101 float get_tap1_level_db() const;
102
103 void set_tap1_pan(float p_pan);
104 float get_tap1_pan() const;
105
106 void set_tap2_active(bool p_active);
107 bool is_tap2_active() const;
108
109 void set_tap2_delay_ms(float p_delay_ms);
110 float get_tap2_delay_ms() const;
111
112 void set_tap2_level_db(float p_level_db);
113 float get_tap2_level_db() const;
114
115 void set_tap2_pan(float p_pan);
116 float get_tap2_pan() const;
117
118 void set_feedback_active(bool p_active);
119 bool is_feedback_active() const;
120
121 void set_feedback_delay_ms(float p_delay_ms);
122 float get_feedback_delay_ms() const;
123
124 void set_feedback_level_db(float p_level_db);
125 float get_feedback_level_db() const;
126
127 void set_feedback_lowpass(float p_lowpass);
128 float get_feedback_lowpass() const;
129
130 Ref<AudioEffectInstance> instantiate() override;
131
132 AudioEffectDelay() {}
133};
134
135#endif // AUDIO_EFFECT_DELAY_H
136