2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* audio_effect_phaser.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
|
|
|
/*************************************************************************/
|
2021-01-01 20:13:46 +01:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 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-23 22:36:29 +01:00
|
|
|
#include "audio_effect_phaser.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/math/math_funcs.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "servers/audio_server.h"
|
2017-01-23 22:36:29 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void AudioEffectPhaserInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {
|
2017-01-23 22:36:29 +01:00
|
|
|
float sampling_rate = AudioServer::get_singleton()->get_mix_rate();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float dmin = base->range_min / (sampling_rate / 2.0);
|
|
|
|
float dmax = base->range_max / (sampling_rate / 2.0);
|
2017-01-23 22:36:29 +01:00
|
|
|
|
2020-04-03 11:50:40 +02:00
|
|
|
float increment = Math_TAU * (base->rate / sampling_rate);
|
2017-01-23 22:36:29 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_frame_count; i++) {
|
2017-01-23 22:36:29 +01:00
|
|
|
phase += increment;
|
|
|
|
|
2020-04-03 11:50:40 +02:00
|
|
|
while (phase >= Math_TAU) {
|
|
|
|
phase -= Math_TAU;
|
2017-01-23 22:36:29 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float d = dmin + (dmax - dmin) * ((sin(phase) + 1.f) / 2.f);
|
2017-01-23 22:36:29 +01:00
|
|
|
|
|
|
|
//update filter coeffs
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < 6; j++) {
|
|
|
|
allpass[0][j].delay(d);
|
|
|
|
allpass[1][j].delay(d);
|
2017-01-23 22:36:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//calculate output
|
2017-03-05 16:44:50 +01:00
|
|
|
float y = allpass[0][0].update(
|
|
|
|
allpass[0][1].update(
|
|
|
|
allpass[0][2].update(
|
|
|
|
allpass[0][3].update(
|
|
|
|
allpass[0][4].update(
|
|
|
|
allpass[0][5].update(p_src_frames[i].l + h.l * base->feedback))))));
|
|
|
|
h.l = y;
|
2017-01-23 22:36:29 +01:00
|
|
|
|
|
|
|
p_dst_frames[i].l = p_src_frames[i].l + y * base->depth;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
y = allpass[1][0].update(
|
|
|
|
allpass[1][1].update(
|
|
|
|
allpass[1][2].update(
|
|
|
|
allpass[1][3].update(
|
|
|
|
allpass[1][4].update(
|
|
|
|
allpass[1][5].update(p_src_frames[i].r + h.r * base->feedback))))));
|
|
|
|
h.r = y;
|
2017-01-23 22:36:29 +01:00
|
|
|
|
|
|
|
p_dst_frames[i].r = p_src_frames[i].r + y * base->depth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<AudioEffectInstance> AudioEffectPhaser::instance() {
|
|
|
|
Ref<AudioEffectPhaserInstance> ins;
|
|
|
|
ins.instance();
|
2017-03-05 16:44:50 +01:00
|
|
|
ins->base = Ref<AudioEffectPhaser>(this);
|
|
|
|
ins->phase = 0;
|
|
|
|
ins->h = AudioFrame(0, 0);
|
2017-01-23 22:36:29 +01:00
|
|
|
|
|
|
|
return ins;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioEffectPhaser::set_range_min_hz(float p_hz) {
|
2017-03-05 16:44:50 +01:00
|
|
|
range_min = p_hz;
|
2017-01-23 22:36:29 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float AudioEffectPhaser::get_range_min_hz() const {
|
2017-01-23 22:36:29 +01:00
|
|
|
return range_min;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void AudioEffectPhaser::set_range_max_hz(float p_hz) {
|
|
|
|
range_max = p_hz;
|
2017-01-23 22:36:29 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float AudioEffectPhaser::get_range_max_hz() const {
|
2017-01-23 22:36:29 +01:00
|
|
|
return range_max;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void AudioEffectPhaser::set_rate_hz(float p_hz) {
|
|
|
|
rate = p_hz;
|
2017-01-23 22:36:29 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float AudioEffectPhaser::get_rate_hz() const {
|
2017-01-23 22:36:29 +01:00
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void AudioEffectPhaser::set_feedback(float p_fbk) {
|
|
|
|
feedback = p_fbk;
|
2017-01-23 22:36:29 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float AudioEffectPhaser::get_feedback() const {
|
2017-01-23 22:36:29 +01:00
|
|
|
return feedback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioEffectPhaser::set_depth(float p_depth) {
|
2017-03-05 16:44:50 +01:00
|
|
|
depth = p_depth;
|
2017-01-23 22:36:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
float AudioEffectPhaser::get_depth() const {
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioEffectPhaser::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_range_min_hz", "hz"), &AudioEffectPhaser::set_range_min_hz);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_range_min_hz"), &AudioEffectPhaser::get_range_min_hz);
|
2017-01-23 22:36:29 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_range_max_hz", "hz"), &AudioEffectPhaser::set_range_max_hz);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_range_max_hz"), &AudioEffectPhaser::get_range_max_hz);
|
2017-01-23 22:36:29 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_rate_hz", "hz"), &AudioEffectPhaser::set_rate_hz);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_rate_hz"), &AudioEffectPhaser::get_rate_hz);
|
2017-01-23 22:36:29 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_feedback", "fbk"), &AudioEffectPhaser::set_feedback);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_feedback"), &AudioEffectPhaser::get_feedback);
|
2017-01-23 22:36:29 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_depth", "depth"), &AudioEffectPhaser::set_depth);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_depth"), &AudioEffectPhaser::get_depth);
|
2017-01-23 22:36:29 +01:00
|
|
|
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "range_min_hz", PROPERTY_HINT_RANGE, "10,10000"), "set_range_min_hz", "get_range_min_hz");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "range_max_hz", PROPERTY_HINT_RANGE, "10,10000"), "set_range_max_hz", "get_range_max_hz");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rate_hz", PROPERTY_HINT_RANGE, "0.01,20"), "set_rate_hz", "get_rate_hz");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "feedback", PROPERTY_HINT_RANGE, "0.1,0.9,0.1"), "set_feedback", "get_feedback");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth", PROPERTY_HINT_RANGE, "0.1,4,0.1"), "set_depth", "get_depth");
|
2017-01-23 22:36:29 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
AudioEffectPhaser::AudioEffectPhaser() {
|
|
|
|
range_min = 440;
|
|
|
|
range_max = 1600;
|
|
|
|
rate = 0.5;
|
|
|
|
feedback = 0.7;
|
|
|
|
depth = 1;
|
2017-01-23 22:36:29 +01:00
|
|
|
}
|