2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* audio_effect_reverb.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
2018-01-01 14:40:08 +01:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2017-03-05 15:47:28 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2017-01-21 23:00:25 +01:00
|
|
|
#include "audio_effect_reverb.h"
|
|
|
|
#include "servers/audio_server.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
void AudioEffectReverbInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
Reverb &r = reverb[i];
|
|
|
|
|
|
|
|
r.set_predelay(base->predelay);
|
|
|
|
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_extra_spread(base->spread);
|
|
|
|
r.set_wet(base->wet);
|
|
|
|
r.set_dry(base->dry);
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int todo = p_frame_count;
|
2017-03-05 16:44:50 +01:00
|
|
|
int offset = 0;
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (todo) {
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int to_mix = MIN(todo, Reverb::INPUT_BUFFER_MAX_SIZE);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < to_mix; j++) {
|
|
|
|
tmp_src[j] = p_src_frames[offset + j].l;
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
reverb[0].process(tmp_src, tmp_dst, to_mix);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < to_mix; j++) {
|
|
|
|
p_dst_frames[offset + j].l = tmp_dst[j];
|
|
|
|
tmp_src[j] = p_src_frames[offset + j].r;
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
reverb[1].process(tmp_src, tmp_dst, to_mix);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < to_mix; j++) {
|
|
|
|
p_dst_frames[offset + j].r = tmp_dst[j];
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
offset += to_mix;
|
|
|
|
todo -= to_mix;
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioEffectReverbInstance::AudioEffectReverbInstance() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
reverb[0].set_mix_rate(AudioServer::get_singleton()->get_mix_rate());
|
2017-01-21 23:00:25 +01:00
|
|
|
reverb[0].set_extra_spread_base(0);
|
2017-03-05 16:44:50 +01:00
|
|
|
reverb[1].set_mix_rate(AudioServer::get_singleton()->get_mix_rate());
|
2017-01-21 23:00:25 +01:00
|
|
|
reverb[1].set_extra_spread_base(0.000521); //for stereo effect
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<AudioEffectInstance> AudioEffectReverb::instance() {
|
|
|
|
Ref<AudioEffectReverbInstance> ins;
|
|
|
|
ins.instance();
|
2017-03-05 16:44:50 +01:00
|
|
|
ins->base = Ref<AudioEffectReverb>(this);
|
2017-01-21 23:00:25 +01:00
|
|
|
return ins;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioEffectReverb::set_predelay_msec(float p_msec) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
predelay = p_msec;
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void AudioEffectReverb::set_predelay_feedback(float p_feedback) {
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2018-01-30 17:42:37 +01:00
|
|
|
predelay_fb = CLAMP(p_feedback, 0, 0.98);
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
void AudioEffectReverb::set_room_size(float p_size) {
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
room_size = p_size;
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
void AudioEffectReverb::set_damping(float p_damping) {
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
damping = p_damping;
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
void AudioEffectReverb::set_spread(float p_spread) {
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
spread = p_spread;
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void AudioEffectReverb::set_dry(float p_dry) {
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
dry = p_dry;
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
void AudioEffectReverb::set_wet(float p_wet) {
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
wet = p_wet;
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
|
|
|
void AudioEffectReverb::set_hpf(float p_hpf) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
hpf = p_hpf;
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
float AudioEffectReverb::get_predelay_msec() const {
|
|
|
|
|
|
|
|
return predelay;
|
|
|
|
}
|
|
|
|
float AudioEffectReverb::get_predelay_feedback() const {
|
|
|
|
|
|
|
|
return predelay_fb;
|
|
|
|
}
|
|
|
|
float AudioEffectReverb::get_room_size() const {
|
|
|
|
|
|
|
|
return room_size;
|
|
|
|
}
|
|
|
|
float AudioEffectReverb::get_damping() const {
|
|
|
|
|
|
|
|
return damping;
|
|
|
|
}
|
|
|
|
float AudioEffectReverb::get_spread() const {
|
|
|
|
|
|
|
|
return spread;
|
|
|
|
}
|
|
|
|
float AudioEffectReverb::get_dry() const {
|
|
|
|
|
|
|
|
return dry;
|
|
|
|
}
|
|
|
|
float AudioEffectReverb::get_wet() const {
|
|
|
|
|
|
|
|
return wet;
|
|
|
|
}
|
|
|
|
float AudioEffectReverb::get_hpf() const {
|
|
|
|
|
|
|
|
return hpf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioEffectReverb::_bind_methods() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_predelay_msec", "msec"), &AudioEffectReverb::set_predelay_msec);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_predelay_msec"), &AudioEffectReverb::get_predelay_msec);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_predelay_feedback", "feedback"), &AudioEffectReverb::set_predelay_feedback);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_predelay_feedback"), &AudioEffectReverb::get_predelay_feedback);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
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);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_damping", "amount"), &AudioEffectReverb::set_damping);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_damping"), &AudioEffectReverb::get_damping);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_spread", "amount"), &AudioEffectReverb::set_spread);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_spread"), &AudioEffectReverb::get_spread);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_dry", "amount"), &AudioEffectReverb::set_dry);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_dry"), &AudioEffectReverb::get_dry);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_wet", "amount"), &AudioEffectReverb::set_wet);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_wet"), &AudioEffectReverb::get_wet);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_hpf", "amount"), &AudioEffectReverb::set_hpf);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_hpf"), &AudioEffectReverb::get_hpf);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_GROUP("Predelay", "predelay_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "predelay_msec", PROPERTY_HINT_RANGE, "20,500,1"), "set_predelay_msec", "get_predelay_msec");
|
2018-01-30 17:42:37 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "predelay_feedback", PROPERTY_HINT_RANGE, "0,0.98,0.01"), "set_predelay_feedback", "get_predelay_feedback");
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_GROUP("", "");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "room_size", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_room_size", "get_room_size");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "damping", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_damping", "get_damping");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "spread", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_spread", "get_spread");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "hipass", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_hpf", "get_hpf");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "dry", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_dry", "get_dry");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "wet", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_wet", "get_wet");
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioEffectReverb::AudioEffectReverb() {
|
2017-03-05 16:44:50 +01:00
|
|
|
predelay = 150;
|
|
|
|
predelay_fb = 0.4;
|
|
|
|
hpf = 0;
|
|
|
|
room_size = 0.8;
|
|
|
|
damping = 0.5;
|
|
|
|
spread = 1.0;
|
|
|
|
dry = 1.0;
|
|
|
|
wet = 0.5;
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|