| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
}; |