Skip to content

Commit

Permalink
rename reverb to reflectivity to match docs
Browse files Browse the repository at this point in the history
  • Loading branch information
PhairZ committed Nov 14, 2024
1 parent ce0709e commit 642f65f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 18 deletions.
6 changes: 4 additions & 2 deletions doc/classes/AudioEffectReverb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
<link title="Third Person Shooter (TPS) Demo">https://godotengine.org/asset-library/asset/2710</link>
</tutorials>
<members>
<member name="damping" type="float" setter="set_damping" getter="get_damping" default="0.5">
Defines how reflective the imaginary room's walls are. Value can range from 0 to 1.
<member name="damping" type="float" setter="set_damping" getter="get_damping" default="0.5" deprecated="Use [member reflectivity] instead.">
</member>
<member name="dry" type="float" setter="set_dry" getter="get_dry" default="1.0">
Output percent of original sound. At 0, only modified sound is outputted. Value can range from 0 to 1.
Expand All @@ -26,6 +25,9 @@
<member name="predelay_msec" type="float" setter="set_predelay_msec" getter="get_predelay_msec" default="150.0">
Time between the original signal and the early reflections of the reverb signal, in milliseconds.
</member>
<member name="reflectivity" type="float" setter="set_reflectivity" getter="get_reflectivity" default="0.5">
Defines how reflective the imaginary room's walls are. Value can range from 0 to 1 with 1 being fully reflective and 0 being non-reflective.
</member>
<member name="room_size" type="float" setter="set_room_size" getter="get_room_size" default="0.8">
Dimensions of simulated room. Bigger means more echoes. Value can range from 0 to 1.
</member>
Expand Down
33 changes: 28 additions & 5 deletions servers/audio/effects/audio_effect_reverb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**************************************************************************/

#include "audio_effect_reverb.h"
// #include "audio_effect_reverb.compat.inc"
#include "servers/audio_server.h"
void AudioEffectReverbInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
for (int i = 0; i < 2; i++) {
Expand All @@ -38,7 +39,7 @@ void AudioEffectReverbInstance::process(const AudioFrame *p_src_frames, AudioFra
r.set_predelay_feedback(base->predelay_fb);
r.set_highpass(base->hpf);
r.set_room_size(base->room_size);
r.set_damp(base->damping);
r.set_reflection(base->reflectivity);
r.set_extra_spread(base->spread);
r.set_wet(base->wet);
r.set_dry(base->dry);
Expand Down Expand Up @@ -98,9 +99,16 @@ void AudioEffectReverb::set_room_size(float p_size) {
room_size = p_size;
}

void AudioEffectReverb::set_reflectivity(float p_reflectivity) {
reflectivity = p_reflectivity;
}

#ifndef DISABLE_DEPRECATED
void AudioEffectReverb::set_damping(float p_damping) {
damping = p_damping;
WARN_DEPRECATED_MSG("Use set_reflectivity instead.");
set_reflectivity(p_damping);
}
#endif

void AudioEffectReverb::set_spread(float p_spread) {
spread = p_spread;
Expand Down Expand Up @@ -130,9 +138,16 @@ float AudioEffectReverb::get_room_size() const {
return room_size;
}

float AudioEffectReverb::get_reflectivity() const {
return reflectivity;
}

#ifndef DISABLE_DEPRECATED
float AudioEffectReverb::get_damping() const {
return damping;
WARN_DEPRECATED_MSG("Use get_reflectivity instead.");
return get_reflectivity();
}
#endif

float AudioEffectReverb::get_spread() const {
return spread;
Expand Down Expand Up @@ -160,8 +175,13 @@ void AudioEffectReverb::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_room_size", "size"), &AudioEffectReverb::set_room_size);
ClassDB::bind_method(D_METHOD("get_room_size"), &AudioEffectReverb::get_room_size);

ClassDB::bind_method(D_METHOD("set_reflectivity", "amount"), &AudioEffectReverb::set_reflectivity);
ClassDB::bind_method(D_METHOD("get_reflectivity"), &AudioEffectReverb::get_reflectivity);

#ifndef DISABLE_DEPRECATED
ClassDB::bind_method(D_METHOD("set_damping", "amount"), &AudioEffectReverb::set_damping);
ClassDB::bind_method(D_METHOD("get_damping"), &AudioEffectReverb::get_damping);
#endif

ClassDB::bind_method(D_METHOD("set_spread", "amount"), &AudioEffectReverb::set_spread);
ClassDB::bind_method(D_METHOD("get_spread"), &AudioEffectReverb::get_spread);
Expand All @@ -180,7 +200,10 @@ void AudioEffectReverb::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "predelay_feedback", PROPERTY_HINT_RANGE, "0,0.98,0.01"), "set_predelay_feedback", "get_predelay_feedback");
ADD_GROUP("", "");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "room_size", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_room_size", "get_room_size");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "damping", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_damping", "get_damping");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "reflectivity", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_reflectivity", "get_reflectivity");
#ifndef DISABLE_DEPRECATED
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "damping", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_damping", "get_damping");
#endif
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "spread", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_spread", "get_spread");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "hipass", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_hpf", "get_hpf");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dry", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_dry", "get_dry");
Expand All @@ -192,7 +215,7 @@ AudioEffectReverb::AudioEffectReverb() {
predelay_fb = 0.4;
hpf = 0;
room_size = 0.8;
damping = 0.5;
reflectivity = 0.5;
spread = 1.0;
dry = 1.0;
wet = 0.5;
Expand Down
14 changes: 13 additions & 1 deletion servers/audio/effects/audio_effect_reverb.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,28 @@ class AudioEffectReverb : public AudioEffect {
float predelay_fb;
float hpf;
float room_size;
float damping;
float reflectivity;
float spread;
float dry;
float wet;

protected:
static void _bind_methods();
//
// #ifndef DISABLE_DEPRECATED
// float _get_damping_bind_compat_99222() const;
// void _set_damping_bind_compat_99222(float p_damping);
// static void _bind_compatibility_methods();
// #endif

public:
void set_predelay_msec(float p_msec);
void set_predelay_feedback(float p_feedback);
void set_room_size(float p_size);
void set_reflectivity(float p_reflectivity);
#ifndef DISABLE_DEPRECATED
void set_damping(float p_damping);
#endif
void set_spread(float p_spread);
void set_dry(float p_dry);
void set_wet(float p_wet);
Expand All @@ -83,7 +92,10 @@ class AudioEffectReverb : public AudioEffect {
float get_predelay_msec() const;
float get_predelay_feedback() const;
float get_room_size() const;
float get_reflectivity() const;
#ifndef DISABLE_DEPRECATED
float get_damping() const;
#endif
float get_spread() const;
float get_dry() const;
float get_wet() const;
Expand Down
22 changes: 15 additions & 7 deletions servers/audio/effects/reverb_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) {
}

float out = undenormalize(c.buffer[c.pos] * c.feedback);
out = out * (1.0 - c.damp) + c.damp_h * c.damp; //lowpass
c.damp_h = out;
out = out * (1.0 - c.reflection) + c.reflection_h * c.reflection; //lowpass
c.reflection_h = out;
c.buffer[c.pos] = input_buffer[j] + out;
p_dst[j] += out;
c.pos++;
Expand Down Expand Up @@ -181,11 +181,19 @@ void Reverb::set_room_size(float p_size) {
update_parameters();
}

void Reverb::set_damp(float p_damp) {
params.damp = p_damp;
void Reverb::set_reflection(float p_reflection) {
params.reflection = p_reflection;
update_parameters();
}

#ifndef DISABLE_DEPRECATED
void Reverb::set_damp(float p_damp) {
WARN_DEPRECATED_MSG("Use set_reflection instead.");
set_reflection(p_damp);
}

#endif

void Reverb::set_wet(float p_wet) {
params.wet = p_wet;
}
Expand Down Expand Up @@ -288,10 +296,10 @@ void Reverb::update_parameters() {
c.feedback = (room_offset + room_scale);
}

float auxdmp = params.damp / 2.0 + 0.5; //only half the range (0.5 .. 1.0 is enough)
float auxdmp = params.reflection / 2.0 + 0.5; //only half the range (0.5 .. 1.0 is enough)
auxdmp *= auxdmp;

c.damp = expf(-Math_TAU * auxdmp * 10000 / params.mix_rate); // 0 .. 10khz
c.reflection = expf(-Math_TAU * auxdmp * 10000 / params.mix_rate); // 0 .. 10khz
}
}

Expand Down Expand Up @@ -319,7 +327,7 @@ void Reverb::clear_buffers() {

Reverb::Reverb() {
params.room_size = 0.8;
params.damp = 0.5;
params.reflection = 0.5;
params.dry = 1.0;
params.wet = 0.0;
params.mix_rate = 44100;
Expand Down
9 changes: 6 additions & 3 deletions servers/audio/effects/reverb_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class Reverb {
int size = 0;
float *buffer = nullptr;
float feedback = 0;
float damp = 0; //lowpass
float damp_h = 0; //history
float reflection = 0; //lowpass
float reflection_h = 0; //history
int pos = 0;
int extra_spread_frames = 0;

Expand All @@ -85,7 +85,7 @@ class Reverb {

struct Parameters {
float room_size;
float damp;
float reflection;
float wet;
float dry;
float mix_rate;
Expand All @@ -102,7 +102,10 @@ class Reverb {

public:
void set_room_size(float p_size);
void set_reflection(float p_reflection);
#ifndef DISABLE_DEPRECATED
void set_damp(float p_damp);
#endif
void set_wet(float p_wet);
void set_dry(float p_dry);
void set_predelay(float p_predelay); // in ms
Expand Down

0 comments on commit 642f65f

Please sign in to comment.