diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-05-14 23:09:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-14 23:09:03 +0200 |
commit | 00949f0c5fcc6a4f8382a4a97d5591fd9ec380f8 (patch) | |
tree | 2b1c31f45add24085b64425ce440f577424c16a1 /servers/audio/effects | |
parent | 5046f666a1181675b39f156c38346525dc1c444e (diff) | |
parent | 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (diff) |
Merge pull request #38738 from akien-mga/cause-we-never-go-out-of-style
Style: Remove new line at block start, enforce line between functions, enforce braces in if and loop blocks
Diffstat (limited to 'servers/audio/effects')
24 files changed, 160 insertions, 305 deletions
diff --git a/servers/audio/effects/audio_effect_amplify.cpp b/servers/audio/effects/audio_effect_amplify.cpp index 8ad2ecc5ce..74fdcbc67a 100644 --- a/servers/audio/effects/audio_effect_amplify.cpp +++ b/servers/audio/effects/audio_effect_amplify.cpp @@ -31,7 +31,6 @@ #include "audio_effect_amplify.h" void AudioEffectAmplifyInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - //multiply volume interpolating to avoid clicks if this changes float volume_db = base->volume_db; float vol = Math::db2linear(mix_volume_db); @@ -58,12 +57,10 @@ void AudioEffectAmplify::set_volume_db(float p_volume) { } float AudioEffectAmplify::get_volume_db() const { - return volume_db; } void AudioEffectAmplify::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_volume_db", "volume"), &AudioEffectAmplify::set_volume_db); ClassDB::bind_method(D_METHOD("get_volume_db"), &AudioEffectAmplify::get_volume_db); diff --git a/servers/audio/effects/audio_effect_chorus.cpp b/servers/audio/effects/audio_effect_chorus.cpp index 34c03dca8d..2b530475f0 100644 --- a/servers/audio/effects/audio_effect_chorus.cpp +++ b/servers/audio/effects/audio_effect_chorus.cpp @@ -33,11 +33,9 @@ #include "servers/audio_server.h" void AudioEffectChorusInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - int todo = p_frame_count; while (todo) { - int to_mix = MIN(todo, 256); //can't mix too much _process_chunk(p_src_frames, p_dst_frames, to_mix); @@ -50,7 +48,6 @@ void AudioEffectChorusInstance::process(const AudioFrame *p_src_frames, AudioFra } void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - //fill ringbuffer for (int i = 0; i < p_frame_count; i++) { audio_buffer.write[(buffer_pos + i) & buffer_mask] = p_src_frames[i]; @@ -61,7 +58,6 @@ void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, A /* process voices */ for (int vc = 0; vc < base->voice_count; vc++) { - AudioEffectChorus::Voice &v = base->voice[vc]; double time_to_mix = (float)p_frame_count / mix_rate; @@ -85,8 +81,9 @@ void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, A } //low pass filter - if (v.cutoff == 0) + if (v.cutoff == 0) { continue; + } float auxlp = expf(-2.0 * Math_PI * v.cutoff / mix_rate); float c1 = 1.0 - auxlp; float c2 = auxlp; @@ -103,7 +100,6 @@ void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, A vol_modifier.r *= CLAMP(1.0 + v.pan, 0, 1); for (int i = 0; i < p_frame_count; i++) { - /** COMPUTE WAVEFORM **/ float phase = (float)(local_cycles & AudioEffectChorus::CYCLES_MASK) / (float)(1 << AudioEffectChorus::CYCLES_FRAC); @@ -146,7 +142,6 @@ void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, A } Ref<AudioEffectInstance> AudioEffectChorus::instance() { - Ref<AudioEffectChorusInstance> ins; ins.instance(); ins->base = Ref<AudioEffectChorus>(this); @@ -182,24 +177,21 @@ Ref<AudioEffectInstance> AudioEffectChorus::instance() { } void AudioEffectChorus::set_voice_count(int p_voices) { - ERR_FAIL_COND(p_voices < 1 || p_voices > MAX_VOICES); voice_count = p_voices; } int AudioEffectChorus::get_voice_count() const { - return voice_count; } void AudioEffectChorus::set_voice_delay_ms(int p_voice, float p_delay_ms) { - ERR_FAIL_INDEX(p_voice, MAX_VOICES); voice[p_voice].delay = p_delay_ms; } -float AudioEffectChorus::get_voice_delay_ms(int p_voice) const { +float AudioEffectChorus::get_voice_delay_ms(int p_voice) const { ERR_FAIL_INDEX_V(p_voice, MAX_VOICES, 0); return voice[p_voice].delay; } @@ -209,85 +201,78 @@ void AudioEffectChorus::set_voice_rate_hz(int p_voice, float p_rate_hz) { voice[p_voice].rate = p_rate_hz; } -float AudioEffectChorus::get_voice_rate_hz(int p_voice) const { +float AudioEffectChorus::get_voice_rate_hz(int p_voice) const { ERR_FAIL_INDEX_V(p_voice, MAX_VOICES, 0); return voice[p_voice].rate; } void AudioEffectChorus::set_voice_depth_ms(int p_voice, float p_depth_ms) { - ERR_FAIL_INDEX(p_voice, MAX_VOICES); voice[p_voice].depth = p_depth_ms; } -float AudioEffectChorus::get_voice_depth_ms(int p_voice) const { +float AudioEffectChorus::get_voice_depth_ms(int p_voice) const { ERR_FAIL_INDEX_V(p_voice, MAX_VOICES, 0); return voice[p_voice].depth; } void AudioEffectChorus::set_voice_level_db(int p_voice, float p_level_db) { - ERR_FAIL_INDEX(p_voice, MAX_VOICES); voice[p_voice].level = p_level_db; } -float AudioEffectChorus::get_voice_level_db(int p_voice) const { +float AudioEffectChorus::get_voice_level_db(int p_voice) const { ERR_FAIL_INDEX_V(p_voice, MAX_VOICES, 0); return voice[p_voice].level; } void AudioEffectChorus::set_voice_cutoff_hz(int p_voice, float p_cutoff_hz) { - ERR_FAIL_INDEX(p_voice, MAX_VOICES); voice[p_voice].cutoff = p_cutoff_hz; } -float AudioEffectChorus::get_voice_cutoff_hz(int p_voice) const { +float AudioEffectChorus::get_voice_cutoff_hz(int p_voice) const { ERR_FAIL_INDEX_V(p_voice, MAX_VOICES, 0); return voice[p_voice].cutoff; } void AudioEffectChorus::set_voice_pan(int p_voice, float p_pan) { - ERR_FAIL_INDEX(p_voice, MAX_VOICES); voice[p_voice].pan = p_pan; } -float AudioEffectChorus::get_voice_pan(int p_voice) const { +float AudioEffectChorus::get_voice_pan(int p_voice) const { ERR_FAIL_INDEX_V(p_voice, MAX_VOICES, 0); return voice[p_voice].pan; } void AudioEffectChorus::set_wet(float amount) { - wet = amount; } -float AudioEffectChorus::get_wet() const { +float AudioEffectChorus::get_wet() const { return wet; } void AudioEffectChorus::set_dry(float amount) { - dry = amount; } -float AudioEffectChorus::get_dry() const { +float AudioEffectChorus::get_dry() const { return dry; } void AudioEffectChorus::_validate_property(PropertyInfo &property) const { - if (property.name.begins_with("voice/")) { int voice_idx = property.name.get_slice("/", 1).to_int(); if (voice_idx > voice_count) { @@ -297,7 +282,6 @@ void AudioEffectChorus::_validate_property(PropertyInfo &property) const { } void AudioEffectChorus::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_voice_count", "voices"), &AudioEffectChorus::set_voice_count); ClassDB::bind_method(D_METHOD("get_voice_count"), &AudioEffectChorus::get_voice_count); diff --git a/servers/audio/effects/audio_effect_chorus.h b/servers/audio/effects/audio_effect_chorus.h index ab5053b919..4d15c518d6 100644 --- a/servers/audio/effects/audio_effect_chorus.h +++ b/servers/audio/effects/audio_effect_chorus.h @@ -73,7 +73,6 @@ public: private: struct Voice { - float delay; float rate; float depth; @@ -82,7 +81,6 @@ private: float pan; Voice() { - delay = 12.0; rate = 1; depth = 0; diff --git a/servers/audio/effects/audio_effect_compressor.cpp b/servers/audio/effects/audio_effect_compressor.cpp index 8d54bd8e36..4b0b4dabea 100644 --- a/servers/audio/effects/audio_effect_compressor.cpp +++ b/servers/audio/effects/audio_effect_compressor.cpp @@ -32,7 +32,6 @@ #include "servers/audio_server.h" void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - float threshold = Math::db2linear(base->threshold); float sample_rate = AudioServer::get_singleton()->get_mix_rate(); @@ -51,7 +50,6 @@ void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames, Audi const AudioFrame *src = p_src_frames; if (base->sidechain != StringName() && current_channel != -1) { - int bus = AudioServer::get_singleton()->thread_find_bus_index(base->sidechain); if (bus >= 0) { src = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus, current_channel); @@ -59,7 +57,6 @@ void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames, Audi } for (int i = 0; i < p_frame_count; i++) { - AudioFrame s = src[i]; //convert to positive s.l = Math::abs(s.l); @@ -69,11 +66,13 @@ void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames, Audi float overdb = 2.08136898f * Math::linear2db(peak / threshold); - if (overdb < 0.0) //we only care about what goes over to compress + if (overdb < 0.0) { //we only care about what goes over to compress overdb = 0.0; + } - if (overdb - rundb > 5) // diffeence is too large + if (overdb - rundb > 5) { // diffeence is too large averatio = 4; + } if (overdb > rundb) { rundb = overdb + atcoef * (rundb - overdb); @@ -104,8 +103,9 @@ void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames, Audi gr_meter = grv; } else { gr_meter *= gr_meter_decay; - if (gr_meter > 1) + if (gr_meter > 1) { gr_meter = 1; + } } p_dst_frames[i] = p_src_frames[i] * grv * makeup * mix + p_src_frames[i] * (1.0 - mix); @@ -127,76 +127,65 @@ Ref<AudioEffectInstance> AudioEffectCompressor::instance() { } void AudioEffectCompressor::set_threshold(float p_threshold) { - threshold = p_threshold; } float AudioEffectCompressor::get_threshold() const { - return threshold; } void AudioEffectCompressor::set_ratio(float p_ratio) { - ratio = p_ratio; } -float AudioEffectCompressor::get_ratio() const { +float AudioEffectCompressor::get_ratio() const { return ratio; } void AudioEffectCompressor::set_gain(float p_gain) { - gain = p_gain; } -float AudioEffectCompressor::get_gain() const { +float AudioEffectCompressor::get_gain() const { return gain; } void AudioEffectCompressor::set_attack_us(float p_attack_us) { - attack_us = p_attack_us; } -float AudioEffectCompressor::get_attack_us() const { +float AudioEffectCompressor::get_attack_us() const { return attack_us; } void AudioEffectCompressor::set_release_ms(float p_release_ms) { - release_ms = p_release_ms; } -float AudioEffectCompressor::get_release_ms() const { +float AudioEffectCompressor::get_release_ms() const { return release_ms; } void AudioEffectCompressor::set_mix(float p_mix) { - mix = p_mix; } -float AudioEffectCompressor::get_mix() const { +float AudioEffectCompressor::get_mix() const { return mix; } void AudioEffectCompressor::set_sidechain(const StringName &p_sidechain) { - AudioServer::get_singleton()->lock(); sidechain = p_sidechain; AudioServer::get_singleton()->unlock(); } StringName AudioEffectCompressor::get_sidechain() const { - return sidechain; } void AudioEffectCompressor::_validate_property(PropertyInfo &property) const { - if (property.name == "sidechain") { - String buses = ""; for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { buses += ","; @@ -208,7 +197,6 @@ void AudioEffectCompressor::_validate_property(PropertyInfo &property) const { } void AudioEffectCompressor::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_threshold", "threshold"), &AudioEffectCompressor::set_threshold); ClassDB::bind_method(D_METHOD("get_threshold"), &AudioEffectCompressor::get_threshold); diff --git a/servers/audio/effects/audio_effect_delay.cpp b/servers/audio/effects/audio_effect_delay.cpp index fa57a94977..d6ab14be89 100644 --- a/servers/audio/effects/audio_effect_delay.cpp +++ b/servers/audio/effects/audio_effect_delay.cpp @@ -33,11 +33,9 @@ #include "servers/audio_server.h" void AudioEffectDelayInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - int todo = p_frame_count; while (todo) { - int to_mix = MIN(todo, 256); //can't mix too much _process_chunk(p_src_frames, p_dst_frames, to_mix); @@ -50,7 +48,6 @@ void AudioEffectDelayInstance::process(const AudioFrame *p_src_frames, AudioFram } void AudioEffectDelayInstance::_process_chunk(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - float main_level_f = base->dry; float mix_rate = AudioServer::get_singleton()->get_mix_rate(); @@ -87,7 +84,6 @@ void AudioEffectDelayInstance::_process_chunk(const AudioFrame *p_src_frames, Au AudioFrame *fb_buf = feedback_buffer.ptrw(); for (int i = 0; i < p_frame_count; i++) { - rb_buf[ring_buffer_pos & ring_buffer_mask] = src[i]; AudioFrame main_val = src[i] * main_level_f; @@ -109,8 +105,9 @@ void AudioEffectDelayInstance::_process_chunk(const AudioFrame *p_src_frames, Au ring_buffer_pos++; - if ((++feedback_buffer_pos) >= feedback_delay_frames) + if ((++feedback_buffer_pos) >= feedback_delay_frames) { feedback_buffer_pos = 0; + } } } @@ -147,125 +144,110 @@ Ref<AudioEffectInstance> AudioEffectDelay::instance() { } void AudioEffectDelay::set_dry(float p_dry) { - dry = p_dry; } float AudioEffectDelay::get_dry() { - return dry; } void AudioEffectDelay::set_tap1_active(bool p_active) { - tap_1_active = p_active; } -bool AudioEffectDelay::is_tap1_active() const { +bool AudioEffectDelay::is_tap1_active() const { return tap_1_active; } void AudioEffectDelay::set_tap1_delay_ms(float p_delay_ms) { - tap_1_delay_ms = p_delay_ms; } -float AudioEffectDelay::get_tap1_delay_ms() const { +float AudioEffectDelay::get_tap1_delay_ms() const { return tap_1_delay_ms; } void AudioEffectDelay::set_tap1_level_db(float p_level_db) { - tap_1_level = p_level_db; } -float AudioEffectDelay::get_tap1_level_db() const { +float AudioEffectDelay::get_tap1_level_db() const { return tap_1_level; } void AudioEffectDelay::set_tap1_pan(float p_pan) { - tap_1_pan = p_pan; } -float AudioEffectDelay::get_tap1_pan() const { +float AudioEffectDelay::get_tap1_pan() const { return tap_1_pan; } void AudioEffectDelay::set_tap2_active(bool p_active) { - tap_2_active = p_active; } -bool AudioEffectDelay::is_tap2_active() const { +bool AudioEffectDelay::is_tap2_active() const { return tap_2_active; } void AudioEffectDelay::set_tap2_delay_ms(float p_delay_ms) { - tap_2_delay_ms = p_delay_ms; } -float AudioEffectDelay::get_tap2_delay_ms() const { +float AudioEffectDelay::get_tap2_delay_ms() const { return tap_2_delay_ms; } void AudioEffectDelay::set_tap2_level_db(float p_level_db) { - tap_2_level = p_level_db; } -float AudioEffectDelay::get_tap2_level_db() const { +float AudioEffectDelay::get_tap2_level_db() const { return tap_2_level; } void AudioEffectDelay::set_tap2_pan(float p_pan) { - tap_2_pan = p_pan; } -float AudioEffectDelay::get_tap2_pan() const { +float AudioEffectDelay::get_tap2_pan() const { return tap_2_pan; } void AudioEffectDelay::set_feedback_active(bool p_active) { - feedback_active = p_active; } -bool AudioEffectDelay::is_feedback_active() const { +bool AudioEffectDelay::is_feedback_active() const { return feedback_active; } void AudioEffectDelay::set_feedback_delay_ms(float p_delay_ms) { - feedback_delay_ms = p_delay_ms; } -float AudioEffectDelay::get_feedback_delay_ms() const { +float AudioEffectDelay::get_feedback_delay_ms() const { return feedback_delay_ms; } void AudioEffectDelay::set_feedback_level_db(float p_level_db) { - feedback_level = p_level_db; } -float AudioEffectDelay::get_feedback_level_db() const { +float AudioEffectDelay::get_feedback_level_db() const { return feedback_level; } void AudioEffectDelay::set_feedback_lowpass(float p_lowpass) { - feedback_lowpass = p_lowpass; } -float AudioEffectDelay::get_feedback_lowpass() const { +float AudioEffectDelay::get_feedback_lowpass() const { return feedback_lowpass; } void AudioEffectDelay::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_dry", "amount"), &AudioEffectDelay::set_dry); ClassDB::bind_method(D_METHOD("get_dry"), &AudioEffectDelay::get_dry); diff --git a/servers/audio/effects/audio_effect_distortion.cpp b/servers/audio/effects/audio_effect_distortion.cpp index bc4fc7ecd6..dc5c2cc16f 100644 --- a/servers/audio/effects/audio_effect_distortion.cpp +++ b/servers/audio/effects/audio_effect_distortion.cpp @@ -33,7 +33,6 @@ #include "servers/audio_server.h" void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - const float *src = (const float *)p_src_frames; float *dst = (float *)p_dst_frames; @@ -51,7 +50,6 @@ void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, Audi float lofi_mult = powf(2.0, 2.0 + (1.0 - drive_f) * 14); //goes from 16 to 2 bits for (int i = 0; i < p_frame_count * 2; i++) { - float out = undenormalise(src[i] * lpf_ic + lpf_c * h[i & 1]); h[i & 1] = out; float a = out; @@ -59,28 +57,24 @@ void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, Audi a *= pregain_f; switch (base->mode) { - case AudioEffectDistortion::MODE_CLIP: { - a = powf(a, 1.0001 - drive_f); - if (a > 1.0) + if (a > 1.0) { a = 1.0; - else if (a < (-1.0)) + } else if (a < (-1.0)) { a = -1.0; + } } break; case AudioEffectDistortion::MODE_ATAN: { - a = atanf(a * atan_mult) * atan_div; } break; case AudioEffectDistortion::MODE_LOFI: { - a = floorf(a * lofi_mult + 0.5) / lofi_mult; } break; case AudioEffectDistortion::MODE_OVERDRIVE: { - const double x = a * 0.686306; const double z = 1 + exp(sqrt(fabs(x)) * -0.75); a = (expf(x) - expf(-x * z)) / (expf(x) + expf(-x)); @@ -109,53 +103,46 @@ Ref<AudioEffectInstance> AudioEffectDistortion::instance() { } void AudioEffectDistortion::set_mode(Mode p_mode) { - mode = p_mode; } AudioEffectDistortion::Mode AudioEffectDistortion::get_mode() const { - return mode; } void AudioEffectDistortion::set_pre_gain(float p_pre_gain) { - pre_gain = p_pre_gain; } -float AudioEffectDistortion::get_pre_gain() const { +float AudioEffectDistortion::get_pre_gain() const { return pre_gain; } void AudioEffectDistortion::set_keep_hf_hz(float p_keep_hf_hz) { - keep_hf_hz = p_keep_hf_hz; } -float AudioEffectDistortion::get_keep_hf_hz() const { +float AudioEffectDistortion::get_keep_hf_hz() const { return keep_hf_hz; } void AudioEffectDistortion::set_drive(float p_drive) { - drive = p_drive; } -float AudioEffectDistortion::get_drive() const { +float AudioEffectDistortion::get_drive() const { return drive; } void AudioEffectDistortion::set_post_gain(float p_post_gain) { - post_gain = p_post_gain; } -float AudioEffectDistortion::get_post_gain() const { +float AudioEffectDistortion::get_post_gain() const { return post_gain; } void AudioEffectDistortion::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mode", "mode"), &AudioEffectDistortion::set_mode); ClassDB::bind_method(D_METHOD("get_mode"), &AudioEffectDistortion::get_mode); diff --git a/servers/audio/effects/audio_effect_eq.cpp b/servers/audio/effects/audio_effect_eq.cpp index b315fdc3bb..ed4e7122b5 100644 --- a/servers/audio/effects/audio_effect_eq.cpp +++ b/servers/audio/effects/audio_effect_eq.cpp @@ -32,7 +32,6 @@ #include "servers/audio_server.h" void AudioEffectEQInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - int band_count = bands[0].size(); EQ::BandProcess *proc_l = bands[0].ptrw(); EQ::BandProcess *proc_r = bands[1].ptrw(); @@ -42,12 +41,10 @@ void AudioEffectEQInstance::process(const AudioFrame *p_src_frames, AudioFrame * } for (int i = 0; i < p_frame_count; i++) { - AudioFrame src = p_src_frames[i]; AudioFrame dst = AudioFrame(0, 0); for (int j = 0; j < band_count; j++) { - float l = src.l; float r = src.r; @@ -87,12 +84,12 @@ float AudioEffectEQ::get_band_gain_db(int p_band) const { return gain[p_band]; } + int AudioEffectEQ::get_band_count() const { return gain.size(); } bool AudioEffectEQ::_set(const StringName &p_name, const Variant &p_value) { - const Map<StringName, int>::Element *E = prop_band_map.find(p_name); if (E) { set_band_gain_db(E->get(), p_value); @@ -103,7 +100,6 @@ bool AudioEffectEQ::_set(const StringName &p_name, const Variant &p_value) { } bool AudioEffectEQ::_get(const StringName &p_name, Variant &r_ret) const { - const Map<StringName, int>::Element *E = prop_band_map.find(p_name); if (E) { r_ret = get_band_gain_db(E->get()); @@ -114,22 +110,18 @@ bool AudioEffectEQ::_get(const StringName &p_name, Variant &r_ret) const { } void AudioEffectEQ::_get_property_list(List<PropertyInfo> *p_list) const { - for (int i = 0; i < band_names.size(); i++) { - p_list->push_back(PropertyInfo(Variant::FLOAT, band_names[i], PROPERTY_HINT_RANGE, "-60,24,0.1")); } } void AudioEffectEQ::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_band_gain_db", "band_idx", "volume_db"), &AudioEffectEQ::set_band_gain_db); ClassDB::bind_method(D_METHOD("get_band_gain_db", "band_idx"), &AudioEffectEQ::get_band_gain_db); ClassDB::bind_method(D_METHOD("get_band_count"), &AudioEffectEQ::get_band_count); } AudioEffectEQ::AudioEffectEQ(EQ::Preset p_preset) { - eq.set_mix_rate(AudioServer::get_singleton()->get_mix_rate()); eq.set_preset_band_mode(p_preset); gain.resize(eq.get_band_count()); diff --git a/servers/audio/effects/audio_effect_filter.cpp b/servers/audio/effects/audio_effect_filter.cpp index 18047bc99e..a5135ee1a6 100644 --- a/servers/audio/effects/audio_effect_filter.cpp +++ b/servers/audio/effects/audio_effect_filter.cpp @@ -33,16 +33,18 @@ template <int S> void AudioEffectFilterInstance::_process_filter(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - for (int i = 0; i < p_frame_count; i++) { float f = p_src_frames[i].l; filter_process[0][0].process_one(f); - if (S > 1) + if (S > 1) { filter_process[0][1].process_one(f); - if (S > 2) + } + if (S > 2) { filter_process[0][2].process_one(f); - if (S > 3) + } + if (S > 3) { filter_process[0][3].process_one(f); + } p_dst_frames[i].l = f; } @@ -50,19 +52,21 @@ void AudioEffectFilterInstance::_process_filter(const AudioFrame *p_src_frames, for (int i = 0; i < p_frame_count; i++) { float f = p_src_frames[i].r; filter_process[1][0].process_one(f); - if (S > 1) + if (S > 1) { filter_process[1][1].process_one(f); - if (S > 2) + } + if (S > 2) { filter_process[1][2].process_one(f); - if (S > 3) + } + if (S > 3) { filter_process[1][3].process_one(f); + } p_dst_frames[i].r = f; } } void AudioEffectFilterInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - filter.set_cutoff(base->cutoff); filter.set_gain(base->gain); filter.set_resonance(base->resonance); @@ -89,7 +93,6 @@ void AudioEffectFilterInstance::process(const AudioFrame *p_src_frames, AudioFra } AudioEffectFilterInstance::AudioEffectFilterInstance() { - for (int i = 0; i < 2; i++) { for (int j = 0; j < 4; j++) { filter_process[i][j].set_filter(&filter); @@ -106,30 +109,26 @@ Ref<AudioEffectInstance> AudioEffectFilter::instance() { } void AudioEffectFilter::set_cutoff(float p_freq) { - cutoff = p_freq; } float AudioEffectFilter::get_cutoff() const { - return cutoff; } void AudioEffectFilter::set_resonance(float p_amount) { - resonance = p_amount; } -float AudioEffectFilter::get_resonance() const { +float AudioEffectFilter::get_resonance() const { return resonance; } void AudioEffectFilter::set_gain(float p_amount) { - gain = p_amount; } -float AudioEffectFilter::get_gain() const { +float AudioEffectFilter::get_gain() const { return gain; } @@ -138,12 +137,10 @@ void AudioEffectFilter::set_db(FilterDB p_db) { } AudioEffectFilter::FilterDB AudioEffectFilter::get_db() const { - return db; } void AudioEffectFilter::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_cutoff", "freq"), &AudioEffectFilter::set_cutoff); ClassDB::bind_method(D_METHOD("get_cutoff"), &AudioEffectFilter::get_cutoff); @@ -168,7 +165,6 @@ void AudioEffectFilter::_bind_methods() { } AudioEffectFilter::AudioEffectFilter(AudioFilterSW::Mode p_mode) { - mode = p_mode; cutoff = 2000; resonance = 0.5; diff --git a/servers/audio/effects/audio_effect_filter.h b/servers/audio/effects/audio_effect_filter.h index c439c5a5b5..b11a4e3623 100644 --- a/servers/audio/effects/audio_effect_filter.h +++ b/servers/audio/effects/audio_effect_filter.h @@ -99,8 +99,9 @@ class AudioEffectLowPassFilter : public AudioEffectFilter { GDCLASS(AudioEffectLowPassFilter, AudioEffectFilter); void _validate_property(PropertyInfo &property) const { - if (property.name == "gain") + if (property.name == "gain") { property.usage = 0; + } } public: @@ -111,8 +112,9 @@ public: class AudioEffectHighPassFilter : public AudioEffectFilter { GDCLASS(AudioEffectHighPassFilter, AudioEffectFilter); void _validate_property(PropertyInfo &property) const { - if (property.name == "gain") + if (property.name == "gain") { property.usage = 0; + } } public: @@ -123,8 +125,9 @@ public: class AudioEffectBandPassFilter : public AudioEffectFilter { GDCLASS(AudioEffectBandPassFilter, AudioEffectFilter); void _validate_property(PropertyInfo &property) const { - if (property.name == "gain") + if (property.name == "gain") { property.usage = 0; + } } public: diff --git a/servers/audio/effects/audio_effect_limiter.cpp b/servers/audio/effects/audio_effect_limiter.cpp index 40a4243168..27f1aaf71f 100644 --- a/servers/audio/effects/audio_effect_limiter.cpp +++ b/servers/audio/effects/audio_effect_limiter.cpp @@ -31,7 +31,6 @@ #include "audio_effect_limiter.h" void AudioEffectLimiterInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - float threshdb = base->threshold; float ceiling = Math::db2linear(base->ceiling); float ceildb = base->ceiling; @@ -42,7 +41,6 @@ void AudioEffectLimiterInstance::process(const AudioFrame *p_src_frames, AudioFr float scmult = Math::abs((ceildb - sc) / (peakdb - sc)); for (int i = 0; i < p_frame_count; i++) { - float spl0 = p_src_frames[i].l; float spl1 = p_src_frames[i].r; spl0 = spl0 * makeup; @@ -78,44 +76,38 @@ Ref<AudioEffectInstance> AudioEffectLimiter::instance() { } void AudioEffectLimiter::set_threshold_db(float p_threshold) { - threshold = p_threshold; } float AudioEffectLimiter::get_threshold_db() const { - return threshold; } void AudioEffectLimiter::set_ceiling_db(float p_ceiling) { - ceiling = p_ceiling; } -float AudioEffectLimiter::get_ceiling_db() const { +float AudioEffectLimiter::get_ceiling_db() const { return ceiling; } void AudioEffectLimiter::set_soft_clip_db(float p_soft_clip) { - soft_clip = p_soft_clip; } -float AudioEffectLimiter::get_soft_clip_db() const { +float AudioEffectLimiter::get_soft_clip_db() const { return soft_clip; } void AudioEffectLimiter::set_soft_clip_ratio(float p_soft_clip) { - soft_clip_ratio = p_soft_clip; } -float AudioEffectLimiter::get_soft_clip_ratio() const { +float AudioEffectLimiter::get_soft_clip_ratio() const { return soft_clip_ratio; } void AudioEffectLimiter::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_ceiling_db", "ceiling"), &AudioEffectLimiter::set_ceiling_db); ClassDB::bind_method(D_METHOD("get_ceiling_db"), &AudioEffectLimiter::get_ceiling_db); diff --git a/servers/audio/effects/audio_effect_panner.cpp b/servers/audio/effects/audio_effect_panner.cpp index 10724175e5..32b7921d1f 100644 --- a/servers/audio/effects/audio_effect_panner.cpp +++ b/servers/audio/effects/audio_effect_panner.cpp @@ -31,12 +31,10 @@ #include "audio_effect_panner.h" void AudioEffectPannerInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - float lvol = CLAMP(1.0 - base->pan, 0, 1); float rvol = CLAMP(1.0 + base->pan, 0, 1); for (int i = 0; i < p_frame_count; i++) { - p_dst_frames[i].l = p_src_frames[i].l * lvol + p_src_frames[i].r * (1.0 - rvol); p_dst_frames[i].r = p_src_frames[i].r * rvol + p_src_frames[i].l * (1.0 - lvol); } @@ -54,12 +52,10 @@ void AudioEffectPanner::set_pan(float p_cpanume) { } float AudioEffectPanner::get_pan() const { - return pan; } void AudioEffectPanner::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_pan", "cpanume"), &AudioEffectPanner::set_pan); ClassDB::bind_method(D_METHOD("get_pan"), &AudioEffectPanner::get_pan); diff --git a/servers/audio/effects/audio_effect_phaser.cpp b/servers/audio/effects/audio_effect_phaser.cpp index 3709b69d45..ffeaa7d25e 100644 --- a/servers/audio/effects/audio_effect_phaser.cpp +++ b/servers/audio/effects/audio_effect_phaser.cpp @@ -33,7 +33,6 @@ #include "servers/audio_server.h" void AudioEffectPhaserInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - float sampling_rate = AudioServer::get_singleton()->get_mix_rate(); float dmin = base->range_min / (sampling_rate / 2.0); @@ -42,7 +41,6 @@ void AudioEffectPhaserInstance::process(const AudioFrame *p_src_frames, AudioFra float increment = 2.f * Math_PI * (base->rate / sampling_rate); for (int i = 0; i < p_frame_count; i++) { - phase += increment; while (phase >= Math_PI * 2.f) { @@ -91,54 +89,46 @@ Ref<AudioEffectInstance> AudioEffectPhaser::instance() { } void AudioEffectPhaser::set_range_min_hz(float p_hz) { - range_min = p_hz; } float AudioEffectPhaser::get_range_min_hz() const { - return range_min; } void AudioEffectPhaser::set_range_max_hz(float p_hz) { - range_max = p_hz; } -float AudioEffectPhaser::get_range_max_hz() const { +float AudioEffectPhaser::get_range_max_hz() const { return range_max; } void AudioEffectPhaser::set_rate_hz(float p_hz) { - rate = p_hz; } -float AudioEffectPhaser::get_rate_hz() const { +float AudioEffectPhaser::get_rate_hz() const { return rate; } void AudioEffectPhaser::set_feedback(float p_fbk) { - feedback = p_fbk; } -float AudioEffectPhaser::get_feedback() const { +float AudioEffectPhaser::get_feedback() const { return feedback; } void AudioEffectPhaser::set_depth(float p_depth) { - depth = p_depth; } float AudioEffectPhaser::get_depth() const { - return depth; } void AudioEffectPhaser::_bind_methods() { - 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); diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp index a74ac3c007..fb6b56d984 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.cpp +++ b/servers/audio/effects/audio_effect_pitch_shift.cpp @@ -94,7 +94,9 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff freqPerBin = sampleRate/(double)fftFrameSize; expct = 2.*Math_PI*(double)stepSize/(double)fftFrameSize; inFifoLatency = fftFrameSize-stepSize; - if (gRover == 0) gRover = inFifoLatency; + if (gRover == 0) { gRover = inFifoLatency; + +} /* initialize our static arrays */ @@ -142,8 +144,10 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff /* map delta phase into +/- Pi interval */ qpd = tmp/Math_PI; - if (qpd >= 0) qpd += qpd&1; - else qpd -= qpd&1; + if (qpd >= 0) { qpd += qpd&1; + } else { qpd -= qpd&1; + +} tmp -= Math_PI*(double)qpd; /* get deviation from bin frequency from the +/- Pi interval */ @@ -200,7 +204,9 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff } /* zero negative frequencies */ - for (k = fftFrameSize+2; k < 2*fftFrameSize; k++) gFFTworksp[k] = 0.; + for (k = fftFrameSize+2; k < 2*fftFrameSize; k++) { gFFTworksp[k] = 0.; + +} /* do inverse transform */ smbFft(gFFTworksp, fftFrameSize, 1); @@ -210,13 +216,17 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff window = -.5*cos(2.*Math_PI*(double)k/(double)fftFrameSize)+.5; gOutputAccum[k] += 2.*window*gFFTworksp[2*k]/(fftFrameSize2*osamp); } - for (k = 0; k < stepSize; k++) gOutFIFO[k] = gOutputAccum[k]; + for (k = 0; k < stepSize; k++) { gOutFIFO[k] = gOutputAccum[k]; + +} /* shift accumulator */ memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameSize*sizeof(float)); /* move input FIFO */ - for (k = 0; k < inFifoLatency; k++) gInFIFO[k] = gInFIFO[k+stepSize]; + for (k = 0; k < inFifoLatency; k++) { gInFIFO[k] = gInFIFO[k+stepSize]; + +} } } @@ -225,6 +235,7 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff } + void SMBPitchShift::smbFft(float *fftBuffer, long fftFrameSize, long sign) /* FFT routine, (C)1996 S.M.Bernsee. Sign = -1 is FFT, 1 is iFFT (inverse) @@ -244,7 +255,9 @@ void SMBPitchShift::smbFft(float *fftBuffer, long fftFrameSize, long sign) for (i = 2; i < 2*fftFrameSize-2; i += 2) { for (bitm = 2, j = 0; bitm < 2*fftFrameSize; bitm <<= 1) { - if (i & bitm) j++; + if (i & bitm) { j++; + +} j <<= 1; } if (i < j) { @@ -280,11 +293,11 @@ void SMBPitchShift::smbFft(float *fftBuffer, long fftFrameSize, long sign) } } + /* Godot code again */ /* clang-format on */ void AudioEffectPitchShiftInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - float sample_rate = AudioServer::get_singleton()->get_mix_rate(); float *in_l = (float *)p_src_frames; @@ -313,7 +326,6 @@ void AudioEffectPitchShift::set_pitch_scale(float p_pitch_scale) { } float AudioEffectPitchShift::get_pitch_scale() const { - return pitch_scale; } @@ -323,7 +335,6 @@ void AudioEffectPitchShift::set_oversampling(int p_oversampling) { } int AudioEffectPitchShift::get_oversampling() const { - return oversampling; } @@ -337,7 +348,6 @@ AudioEffectPitchShift::FFT_Size AudioEffectPitchShift::get_fft_size() const { } void AudioEffectPitchShift::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_pitch_scale", "rate"), &AudioEffectPitchShift::set_pitch_scale); ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioEffectPitchShift::get_pitch_scale); diff --git a/servers/audio/effects/audio_effect_pitch_shift.h b/servers/audio/effects/audio_effect_pitch_shift.h index c6528bafa9..48f8e5dc39 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.h +++ b/servers/audio/effects/audio_effect_pitch_shift.h @@ -34,7 +34,6 @@ #include "servers/audio/audio_effect.h" class SMBPitchShift { - enum { MAX_FRAME_LENGTH = 8192 }; diff --git a/servers/audio/effects/audio_effect_record.cpp b/servers/audio/effects/audio_effect_record.cpp index f2784679b5..79388b2dc7 100644 --- a/servers/audio/effects/audio_effect_record.cpp +++ b/servers/audio/effects/audio_effect_record.cpp @@ -101,7 +101,6 @@ void AudioEffectRecordInstance::_io_store_buffer() { } void AudioEffectRecordInstance::_thread_callback(void *_instance) { - AudioEffectRecordInstance *aeri = reinterpret_cast<AudioEffectRecordInstance *>(_instance); aeri->_io_thread_process(); @@ -124,7 +123,6 @@ void AudioEffectRecordInstance::init() { } void AudioEffectRecordInstance::finish() { - #ifdef NO_THREADS AudioServer::get_singleton()->remove_update_callback(&AudioEffectRecordInstance::_update, this); #else @@ -135,7 +133,6 @@ void AudioEffectRecordInstance::finish() { } AudioEffectRecordInstance::~AudioEffectRecordInstance() { - finish(); } diff --git a/servers/audio/effects/audio_effect_reverb.cpp b/servers/audio/effects/audio_effect_reverb.cpp index 6dccb2945b..f6465abfaf 100644 --- a/servers/audio/effects/audio_effect_reverb.cpp +++ b/servers/audio/effects/audio_effect_reverb.cpp @@ -31,7 +31,6 @@ #include "audio_effect_reverb.h" #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++) { Reverb &r = reverb[i]; @@ -49,7 +48,6 @@ void AudioEffectReverbInstance::process(const AudioFrame *p_src_frames, AudioFra int offset = 0; while (todo) { - int to_mix = MIN(todo, Reverb::INPUT_BUFFER_MAX_SIZE); for (int j = 0; j < to_mix; j++) { @@ -75,7 +73,6 @@ void AudioEffectReverbInstance::process(const AudioFrame *p_src_frames, AudioFra } AudioEffectReverbInstance::AudioEffectReverbInstance() { - reverb[0].set_mix_rate(AudioServer::get_singleton()->get_mix_rate()); reverb[0].set_extra_spread_base(0); reverb[1].set_mix_rate(AudioServer::get_singleton()->get_mix_rate()); @@ -90,75 +87,70 @@ Ref<AudioEffectInstance> AudioEffectReverb::instance() { } void AudioEffectReverb::set_predelay_msec(float p_msec) { - predelay = p_msec; } void AudioEffectReverb::set_predelay_feedback(float p_feedback) { - predelay_fb = CLAMP(p_feedback, 0, 0.98); } -void AudioEffectReverb::set_room_size(float p_size) { +void AudioEffectReverb::set_room_size(float p_size) { room_size = p_size; } -void AudioEffectReverb::set_damping(float p_damping) { +void AudioEffectReverb::set_damping(float p_damping) { damping = p_damping; } -void AudioEffectReverb::set_spread(float p_spread) { +void AudioEffectReverb::set_spread(float p_spread) { spread = p_spread; } void AudioEffectReverb::set_dry(float p_dry) { - dry = p_dry; } -void AudioEffectReverb::set_wet(float p_wet) { +void AudioEffectReverb::set_wet(float p_wet) { wet = p_wet; } -void AudioEffectReverb::set_hpf(float p_hpf) { +void AudioEffectReverb::set_hpf(float p_hpf) { hpf = p_hpf; } float AudioEffectReverb::get_predelay_msec() const { - return predelay; } -float AudioEffectReverb::get_predelay_feedback() const { +float AudioEffectReverb::get_predelay_feedback() const { return predelay_fb; } -float AudioEffectReverb::get_room_size() const { +float AudioEffectReverb::get_room_size() const { return room_size; } -float AudioEffectReverb::get_damping() const { +float AudioEffectReverb::get_damping() const { return damping; } -float AudioEffectReverb::get_spread() const { +float AudioEffectReverb::get_spread() const { return spread; } -float AudioEffectReverb::get_dry() const { +float AudioEffectReverb::get_dry() const { return dry; } -float AudioEffectReverb::get_wet() const { +float AudioEffectReverb::get_wet() const { return wet; } -float AudioEffectReverb::get_hpf() const { +float AudioEffectReverb::get_hpf() const { return hpf; } void AudioEffectReverb::_bind_methods() { - 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); diff --git a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp index 680ef567fd..e744dbf9b0 100644 --- a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp +++ b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp @@ -50,8 +50,9 @@ static void smbFft(float *fftBuffer, long fftFrameSize, long sign) for (i = 2; i < 2 * fftFrameSize - 2; i += 2) { for (bitm = 2, j = 0; bitm < 2 * fftFrameSize; bitm <<= 1) { - if (i & bitm) + if (i & bitm) { j++; + } j <<= 1; } if (i < j) { @@ -96,8 +97,8 @@ static void smbFft(float *fftBuffer, long fftFrameSize, long sign) } } } -void AudioEffectSpectrumAnalyzerInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { +void AudioEffectSpectrumAnalyzerInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { uint64_t time = OS::get_singleton()->get_ticks_usec(); //copy everything over first, since this only really does capture @@ -149,14 +150,12 @@ void AudioEffectSpectrumAnalyzerInstance::process(const AudioFrame *p_src_frames } void AudioEffectSpectrumAnalyzerInstance::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_magnitude_for_frequency_range", "from_hz", "to_hz", "mode"), &AudioEffectSpectrumAnalyzerInstance::get_magnitude_for_frequency_range, DEFVAL(MAGNITUDE_MAX)); BIND_ENUM_CONSTANT(MAGNITUDE_AVERAGE); BIND_ENUM_CONSTANT(MAGNITUDE_MAX); } Vector2 AudioEffectSpectrumAnalyzerInstance::get_magnitude_for_frequency_range(float p_begin, float p_end, MagnitudeMode p_mode) const { - if (last_fft_time == 0) { return Vector2(); } @@ -197,7 +196,6 @@ Vector2 AudioEffectSpectrumAnalyzerInstance::get_magnitude_for_frequency_range(f return avg; } else { - Vector2 max; for (int i = begin_pos; i <= end_pos; i++) { @@ -210,7 +208,6 @@ Vector2 AudioEffectSpectrumAnalyzerInstance::get_magnitude_for_frequency_range(f } Ref<AudioEffectInstance> AudioEffectSpectrumAnalyzer::instance() { - Ref<AudioEffectSpectrumAnalyzerInstance> ins; ins.instance(); ins->base = Ref<AudioEffectSpectrumAnalyzer>(this); @@ -237,7 +234,6 @@ void AudioEffectSpectrumAnalyzer::set_buffer_length(float p_seconds) { } float AudioEffectSpectrumAnalyzer::get_buffer_length() const { - return buffer_length; } @@ -259,7 +255,6 @@ AudioEffectSpectrumAnalyzer::FFT_Size AudioEffectSpectrumAnalyzer::get_fft_size( } void AudioEffectSpectrumAnalyzer::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_buffer_length", "seconds"), &AudioEffectSpectrumAnalyzer::set_buffer_length); ClassDB::bind_method(D_METHOD("get_buffer_length"), &AudioEffectSpectrumAnalyzer::get_buffer_length); diff --git a/servers/audio/effects/audio_effect_stereo_enhance.cpp b/servers/audio/effects/audio_effect_stereo_enhance.cpp index a10aca02b2..4f9bee83e4 100644 --- a/servers/audio/effects/audio_effect_stereo_enhance.cpp +++ b/servers/audio/effects/audio_effect_stereo_enhance.cpp @@ -31,14 +31,12 @@ #include "audio_effect_stereo_enhance.h" #include "servers/audio_server.h" void AudioEffectStereoEnhanceInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - float intensity = base->pan_pullout; bool surround_mode = base->surround > 0; float surround_amount = base->surround; unsigned int delay_frames = (base->time_pullout / 1000.0) * AudioServer::get_singleton()->get_mix_rate(); for (int i = 0; i < p_frame_count; i++) { - float l = p_src_frames[i].l; float r = p_src_frames[i].r; @@ -48,7 +46,6 @@ void AudioEffectStereoEnhanceInstance::process(const AudioFrame *p_src_frames, A r = (center + (r - center) * intensity); if (surround_mode) { - float val = (l + r) / 2.0; delay_ringbuff[ringbuff_pos & ringbuff_mask] = val; @@ -58,7 +55,6 @@ void AudioEffectStereoEnhanceInstance::process(const AudioFrame *p_src_frames, A l += out; r += -out; } else { - float val = r; delay_ringbuff[ringbuff_pos & ringbuff_mask] = val; @@ -75,7 +71,6 @@ void AudioEffectStereoEnhanceInstance::process(const AudioFrame *p_src_frames, A } AudioEffectStereoEnhanceInstance::~AudioEffectStereoEnhanceInstance() { - memdelete_arr(delay_ringbuff); } @@ -108,35 +103,30 @@ Ref<AudioEffectInstance> AudioEffectStereoEnhance::instance() { } void AudioEffectStereoEnhance::set_pan_pullout(float p_amount) { - pan_pullout = p_amount; } float AudioEffectStereoEnhance::get_pan_pullout() const { - return pan_pullout; } void AudioEffectStereoEnhance::set_time_pullout(float p_amount) { - time_pullout = p_amount; } -float AudioEffectStereoEnhance::get_time_pullout() const { +float AudioEffectStereoEnhance::get_time_pullout() const { return time_pullout; } void AudioEffectStereoEnhance::set_surround(float p_amount) { - surround = p_amount; } -float AudioEffectStereoEnhance::get_surround() const { +float AudioEffectStereoEnhance::get_surround() const { return surround; } void AudioEffectStereoEnhance::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_pan_pullout", "amount"), &AudioEffectStereoEnhance::set_pan_pullout); ClassDB::bind_method(D_METHOD("get_pan_pullout"), &AudioEffectStereoEnhance::get_pan_pullout); diff --git a/servers/audio/effects/audio_stream_generator.cpp b/servers/audio/effects/audio_stream_generator.cpp index d272a2cdf7..aba04550db 100644 --- a/servers/audio/effects/audio_stream_generator.cpp +++ b/servers/audio/effects/audio_stream_generator.cpp @@ -35,21 +35,18 @@ void AudioStreamGenerator::set_mix_rate(float p_mix_rate) { } float AudioStreamGenerator::get_mix_rate() const { - return mix_rate; } void AudioStreamGenerator::set_buffer_length(float p_seconds) { - buffer_len = p_seconds; } -float AudioStreamGenerator::get_buffer_length() const { +float AudioStreamGenerator::get_buffer_length() const { return buffer_len; } Ref<AudioStreamPlayback> AudioStreamGenerator::instance_playback() { - Ref<AudioStreamGeneratorPlayback> playback; playback.instance(); playback->generator = this; @@ -58,8 +55,8 @@ Ref<AudioStreamPlayback> AudioStreamGenerator::instance_playback() { playback->buffer.clear(); return playback; } -String AudioStreamGenerator::get_stream_name() const { +String AudioStreamGenerator::get_stream_name() const { return "UserFeed"; } @@ -99,8 +96,8 @@ bool AudioStreamGeneratorPlayback::push_frame(const Vector2 &p_frame) { bool AudioStreamGeneratorPlayback::can_push_buffer(int p_frames) const { return buffer.space_left() >= p_frames; } -bool AudioStreamGeneratorPlayback::push_buffer(const PackedVector2Array &p_frames) { +bool AudioStreamGeneratorPlayback::push_buffer(const PackedVector2Array &p_frames) { int to_write = p_frames.size(); if (buffer.space_left() < to_write) { return false; @@ -115,7 +112,6 @@ bool AudioStreamGeneratorPlayback::push_buffer(const PackedVector2Array &p_frame AudioFrame buf[2048]; int ofs = 0; while (to_write) { - int w = MIN(to_write, 2048); for (int i = 0; i < w; i++) { buf[i] = r[i + ofs]; @@ -143,7 +139,6 @@ void AudioStreamGeneratorPlayback::clear_buffer() { } void AudioStreamGeneratorPlayback::_mix_internal(AudioFrame *p_buffer, int p_frames) { - int read_amount = buffer.data_left(); if (p_frames < read_amount) { read_amount = p_frames; @@ -162,12 +157,12 @@ void AudioStreamGeneratorPlayback::_mix_internal(AudioFrame *p_buffer, int p_fra mixed += p_frames / generator->get_mix_rate(); } + float AudioStreamGeneratorPlayback::get_stream_sampling_rate() { return generator->get_mix_rate(); } void AudioStreamGeneratorPlayback::start(float p_from_pos) { - if (mixed == 0.0) { _begin_resample(); } @@ -179,8 +174,8 @@ void AudioStreamGeneratorPlayback::start(float p_from_pos) { void AudioStreamGeneratorPlayback::stop() { active = false; } -bool AudioStreamGeneratorPlayback::is_playing() const { +bool AudioStreamGeneratorPlayback::is_playing() const { return active; //always playing, can't be stopped } @@ -191,6 +186,7 @@ int AudioStreamGeneratorPlayback::get_loop_count() const { float AudioStreamGeneratorPlayback::get_playback_position() const { return mixed; } + void AudioStreamGeneratorPlayback::seek(float p_time) { //no seek possible } diff --git a/servers/audio/effects/audio_stream_generator.h b/servers/audio/effects/audio_stream_generator.h index aee3459e17..763d913684 100644 --- a/servers/audio/effects/audio_stream_generator.h +++ b/servers/audio/effects/audio_stream_generator.h @@ -58,7 +58,6 @@ public: }; class AudioStreamGeneratorPlayback : public AudioStreamPlaybackResampled { - GDCLASS(AudioStreamGeneratorPlayback, AudioStreamPlaybackResampled); friend class AudioStreamGenerator; RingBuffer<AudioFrame> buffer; diff --git a/servers/audio/effects/eq.cpp b/servers/audio/effects/eq.cpp index b90e8a2726..08a6cf55fa 100644 --- a/servers/audio/effects/eq.cpp +++ b/servers/audio/effects/eq.cpp @@ -42,48 +42,45 @@ static int solve_quadratic(double a, double b, double c, double *r1, double *r2) //solves quadractic and returns number of roots double base = 2 * a; - if (base == 0.0f) + if (base == 0.0f) { return 0; + } double squared = b * b - 4 * a * c; - if (squared < 0.0) + if (squared < 0.0) { return 0; + } squared = sqrt(squared); *r1 = (-b + squared) / base; *r2 = (-b - squared) / base; - if (*r1 == *r2) + if (*r1 == *r2) { return 1; - else + } else { return 2; + } } EQ::BandProcess::BandProcess() { - c1 = c2 = c3 = history.a1 = history.a2 = history.a3 = 0; history.b1 = history.b2 = history.b3 = 0; } void EQ::recalculate_band_coefficients() { - #define BAND_LOG(m_f) (log((m_f)) / log(2.)) for (int i = 0; i < band.size(); i++) { - double octave_size; double frq = band[i].freq; if (i == 0) { - octave_size = BAND_LOG(band[1].freq) - BAND_LOG(frq); } else if (i == (band.size() - 1)) { - octave_size = BAND_LOG(frq) - BAND_LOG(band[i - 1].freq); } else { - double next = BAND_LOG(band[i + 1].freq) - BAND_LOG(frq); double prev = BAND_LOG(frq) - BAND_LOG(band[i - 1].freq); octave_size = (next + prev) / 2.0; @@ -118,7 +115,6 @@ void EQ::recalculate_band_coefficients() { } void EQ::set_preset_band_mode(Preset p_preset) { - band.clear(); #define PUSH_BANDS(m_bands) \ @@ -130,16 +126,13 @@ void EQ::set_preset_band_mode(Preset p_preset) { } switch (p_preset) { - case PRESET_6_BANDS: { - static const double bands[] = { 32, 100, 320, 1e3, 3200, 10e3 }; PUSH_BANDS(6); } break; case PRESET_8_BANDS: { - static const double bands[] = { 32, 72, 192, 512, 1200, 3000, 7500, 16e3 }; PUSH_BANDS(8); @@ -153,14 +146,12 @@ void EQ::set_preset_band_mode(Preset p_preset) { } break; case PRESET_21_BANDS: { - static const double bands[] = { 22, 32, 44, 63, 90, 125, 175, 250, 350, 500, 700, 1e3, 1400, 2e3, 2800, 4e3, 5600, 8e3, 11e3, 16e3, 22e3 }; PUSH_BANDS(21); } break; case PRESET_31_BANDS: { - static const double bands[] = { 20, 25, 31.5, 40, 50, 63, 80, 100, 125, 160, 200, 250, 315, 400, 500, 630, 800, 1e3, 1250, 1600, 2e3, 2500, 3150, 4e3, 5e3, 6300, 8e3, 10e3, 12500, 16e3, 20e3 }; PUSH_BANDS(31); } break; @@ -170,19 +161,17 @@ void EQ::set_preset_band_mode(Preset p_preset) { } int EQ::get_band_count() const { - return band.size(); } -float EQ::get_band_frequency(int p_band) { +float EQ::get_band_frequency(int p_band) { ERR_FAIL_INDEX_V(p_band, band.size(), 0); return band[p_band].freq; } -void EQ::set_bands(const Vector<float> &p_bands) { +void EQ::set_bands(const Vector<float> &p_bands) { band.resize(p_bands.size()); for (int i = 0; i < p_bands.size(); i++) { - band.write[i].freq = p_bands[i]; } @@ -190,13 +179,11 @@ void EQ::set_bands(const Vector<float> &p_bands) { } void EQ::set_mix_rate(float p_mix_rate) { - mix_rate = p_mix_rate; recalculate_band_coefficients(); } EQ::BandProcess EQ::get_band_processor(int p_band) const { - EQ::BandProcess band_proc; ERR_FAIL_INDEX_V(p_band, band.size(), band_proc); diff --git a/servers/audio/effects/eq.h b/servers/audio/effects/eq.h index 6c002effbf..391a7aa24b 100644 --- a/servers/audio/effects/eq.h +++ b/servers/audio/effects/eq.h @@ -52,7 +52,6 @@ public: }; class BandProcess { - friend class EQ; float c1, c2, c3; struct History { @@ -69,7 +68,6 @@ public: private: struct Band { - float freq; float c1, c2, c3; }; @@ -96,7 +94,6 @@ public: /* Inline Function */ inline void EQ::BandProcess::process_one(float &p_data) { - history.a1 = p_data; history.b1 = c1 * (history.a1 - history.a3) + c3 * history.b2 - c2 * history.b3; diff --git a/servers/audio/effects/reverb.cpp b/servers/audio/effects/reverb.cpp index 02565f4516..7c35d88ced 100644 --- a/servers/audio/effects/reverb.cpp +++ b/servers/audio/effects/reverb.cpp @@ -57,24 +57,27 @@ const float Reverb::allpass_tunings[MAX_ALLPASS] = { }; void Reverb::process(float *p_src, float *p_dst, int p_frames) { - - if (p_frames > INPUT_BUFFER_MAX_SIZE) + if (p_frames > INPUT_BUFFER_MAX_SIZE) { p_frames = INPUT_BUFFER_MAX_SIZE; + } int predelay_frames = lrint((params.predelay / 1000.0) * params.mix_rate); - if (predelay_frames < 10) + if (predelay_frames < 10) { predelay_frames = 10; - if (predelay_frames >= echo_buffer_size) + } + if (predelay_frames >= echo_buffer_size) { predelay_frames = echo_buffer_size - 1; + } for (int i = 0; i < p_frames; i++) { - - if (echo_buffer_pos >= echo_buffer_size) + if (echo_buffer_pos >= echo_buffer_size) { echo_buffer_pos = 0; + } int read_pos = echo_buffer_pos - predelay_frames; - while (read_pos < 0) + while (read_pos < 0) { read_pos += echo_buffer_size; + } float in = undenormalise(echo_buffer[read_pos] * params.predelay_fb + p_src[i]); @@ -94,7 +97,6 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { float hp_b1 = hpaux; for (int i = 0; i < p_frames; i++) { - float in = input_buffer[i]; input_buffer[i] = in * hp_a1 + hpf_h1 * hp_a2 + hpf_h2 * hp_b1; hpf_h2 = input_buffer[i]; @@ -103,14 +105,13 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { } for (int i = 0; i < MAX_COMBS; i++) { - Comb &c = comb[i]; int size_limit = c.size - lrintf((float)c.extra_spread_frames * (1.0 - params.extra_spread)); for (int j = 0; j < p_frames; j++) { - - if (c.pos >= size_limit) //reset this now just in case + if (c.pos >= size_limit) { //reset this now just in case c.pos = 0; + } float out = undenormalise(c.buffer[c.pos] * c.feedback); out = out * (1.0 - c.damp) + c.damp_h * c.damp; //lowpass @@ -157,14 +158,13 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { */ for (int i = 0; i < MAX_ALLPASS; i++) { - AllPass &a = allpass[i]; int size_limit = a.size - lrintf((float)a.extra_spread_frames * (1.0 - params.extra_spread)); for (int j = 0; j < p_frames; j++) { - - if (a.pos >= size_limit) + if (a.pos >= size_limit) { a.pos = 0; + } float aux = a.buffer[a.pos]; a.buffer[a.pos] = undenormalise(allpass_feedback * aux + p_dst[j]); @@ -176,108 +176,102 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { static const float wet_scale = 0.6; for (int i = 0; i < p_frames; i++) { - p_dst[i] = p_dst[i] * params.wet * wet_scale + p_src[i] * params.dry; } } void Reverb::set_room_size(float p_size) { - params.room_size = p_size; update_parameters(); } -void Reverb::set_damp(float p_damp) { +void Reverb::set_damp(float p_damp) { params.damp = p_damp; update_parameters(); } -void Reverb::set_wet(float p_wet) { +void Reverb::set_wet(float p_wet) { params.wet = p_wet; } void Reverb::set_dry(float p_dry) { - params.dry = p_dry; } void Reverb::set_predelay(float p_predelay) { - params.predelay = p_predelay; } -void Reverb::set_predelay_feedback(float p_predelay_fb) { +void Reverb::set_predelay_feedback(float p_predelay_fb) { params.predelay_fb = p_predelay_fb; } void Reverb::set_highpass(float p_frq) { - - if (p_frq > 1) + if (p_frq > 1) { p_frq = 1; - if (p_frq < 0) + } + if (p_frq < 0) { p_frq = 0; + } params.hpf = p_frq; } void Reverb::set_extra_spread(float p_spread) { - params.extra_spread = p_spread; } void Reverb::set_mix_rate(float p_mix_rate) { - params.mix_rate = p_mix_rate; configure_buffers(); } void Reverb::set_extra_spread_base(float p_sec) { - params.extra_spread_base = p_sec; configure_buffers(); } void Reverb::configure_buffers() { - clear_buffers(); //clear if necessary for (int i = 0; i < MAX_COMBS; i++) { - Comb &c = comb[i]; c.extra_spread_frames = lrint(params.extra_spread_base * params.mix_rate); int len = lrint(comb_tunings[i] * params.mix_rate) + c.extra_spread_frames; - if (len < 5) + if (len < 5) { len = 5; //may this happen? + } c.buffer = memnew_arr(float, len); c.pos = 0; - for (int j = 0; j < len; j++) + for (int j = 0; j < len; j++) { c.buffer[j] = 0; + } c.size = len; } for (int i = 0; i < MAX_ALLPASS; i++) { - AllPass &a = allpass[i]; a.extra_spread_frames = lrint(params.extra_spread_base * params.mix_rate); int len = lrint(allpass_tunings[i] * params.mix_rate) + a.extra_spread_frames; - if (len < 5) + if (len < 5) { len = 5; //may this happen? + } a.buffer = memnew_arr(float, len); a.pos = 0; - for (int j = 0; j < len; j++) + for (int j = 0; j < len; j++) { a.buffer[j] = 0; + } a.size = len; } echo_buffer_size = (int)(((float)MAX_ECHO_MS / 1000.0) * params.mix_rate + 1.0); echo_buffer = memnew_arr(float, echo_buffer_size); for (int i = 0; i < echo_buffer_size; i++) { - echo_buffer[i] = 0; } @@ -285,19 +279,18 @@ void Reverb::configure_buffers() { } void Reverb::update_parameters() { - //more freeverb derived constants static const float room_scale = 0.28f; static const float room_offset = 0.7f; for (int i = 0; i < MAX_COMBS; i++) { - Comb &c = comb[i]; c.feedback = room_offset + params.room_size * room_scale; - if (c.feedback < room_offset) + if (c.feedback < room_offset) { c.feedback = room_offset; - else if (c.feedback > (room_offset + room_scale)) + } else if (c.feedback > (room_offset + room_scale)) { c.feedback = (room_offset + room_scale); + } float auxdmp = params.damp / 2.0 + 0.5; //only half the range (0.5 .. 1.0 is enough) auxdmp *= auxdmp; @@ -307,29 +300,28 @@ void Reverb::update_parameters() { } void Reverb::clear_buffers() { - - if (echo_buffer) + if (echo_buffer) { memdelete_arr(echo_buffer); + } for (int i = 0; i < MAX_COMBS; i++) { - - if (comb[i].buffer) + if (comb[i].buffer) { memdelete_arr(comb[i].buffer); + } comb[i].buffer = nullptr; } for (int i = 0; i < MAX_ALLPASS; i++) { - - if (allpass[i].buffer) + if (allpass[i].buffer) { memdelete_arr(allpass[i].buffer); + } allpass[i].buffer = nullptr; } } Reverb::Reverb() { - params.room_size = 0.8; params.damp = 0.5; params.dry = 1.0; @@ -348,7 +340,6 @@ Reverb::Reverb() { } Reverb::~Reverb() { - memdelete_arr(input_buffer); clear_buffers(); } diff --git a/servers/audio/effects/reverb.h b/servers/audio/effects/reverb.h index ed8c824148..614de0c534 100644 --- a/servers/audio/effects/reverb.h +++ b/servers/audio/effects/reverb.h @@ -57,7 +57,6 @@ private: static const float allpass_tunings[MAX_ALLPASS]; struct Comb { - int size = 0; float *buffer = nullptr; float feedback = 0; @@ -70,7 +69,6 @@ private: }; struct AllPass { - int size = 0; float *buffer = nullptr; int pos = 0; @@ -88,7 +86,6 @@ private: float hpf_h1, hpf_h2 = 0; struct Parameters { - float room_size; float damp; float wet; |