diff options
Diffstat (limited to 'servers/audio')
-rw-r--r-- | servers/audio/audio_effect.cpp | 8 | ||||
-rw-r--r-- | servers/audio/audio_rb_resampler.cpp | 8 | ||||
-rw-r--r-- | servers/audio/audio_stream.cpp | 84 | ||||
-rw-r--r-- | servers/audio/audio_stream.h | 32 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_delay.cpp | 2 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_distortion.cpp | 6 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_eq.cpp | 6 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_filter.cpp | 12 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_record.cpp | 8 | ||||
-rw-r--r-- | servers/audio/effects/audio_stream_generator.cpp | 10 | ||||
-rw-r--r-- | servers/audio/effects/audio_stream_generator.h | 8 | ||||
-rw-r--r-- | servers/audio/effects/reverb_filter.cpp | 8 |
12 files changed, 82 insertions, 110 deletions
diff --git a/servers/audio/audio_effect.cpp b/servers/audio/audio_effect.cpp index f38d0adfb2..ef0e3197e1 100644 --- a/servers/audio/audio_effect.cpp +++ b/servers/audio/audio_effect.cpp @@ -36,11 +36,9 @@ void AudioEffectInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_ } } bool AudioEffectInstance::process_silence() const { - bool ret; - if (GDVIRTUAL_CALL(_process_silence, ret)) { - return ret; - } - return false; + bool ret = false; + GDVIRTUAL_CALL(_process_silence, ret); + return ret; } void AudioEffectInstance::_bind_methods() { diff --git a/servers/audio/audio_rb_resampler.cpp b/servers/audio/audio_rb_resampler.cpp index 0cfba17563..adb0dc32ea 100644 --- a/servers/audio/audio_rb_resampler.cpp +++ b/servers/audio/audio_rb_resampler.cpp @@ -57,14 +57,14 @@ uint32_t AudioRBResampler::_resample(AudioFrame *p_dest, int p_todo, int32_t p_i uint32_t pos_next = (pos + 1) & rb_mask; // since this is a template with a known compile time value (C), conditionals go away when compiling. - if (C == 1) { + if constexpr (C == 1) { float v0 = rb[pos]; float v0n = rb[pos_next]; v0 += (v0n - v0) * frac; p_dest[i] = AudioFrame(v0, v0); } - if (C == 2) { + if constexpr (C == 2) { float v0 = rb[(pos << 1) + 0]; float v1 = rb[(pos << 1) + 1]; float v0n = rb[(pos_next << 1) + 0]; @@ -76,7 +76,7 @@ uint32_t AudioRBResampler::_resample(AudioFrame *p_dest, int p_todo, int32_t p_i } // This will probably never be used, but added anyway - if (C == 4) { + if constexpr (C == 4) { float v0 = rb[(pos << 2) + 0]; float v1 = rb[(pos << 2) + 1]; float v0n = rb[(pos_next << 2) + 0]; @@ -86,7 +86,7 @@ uint32_t AudioRBResampler::_resample(AudioFrame *p_dest, int p_todo, int32_t p_i p_dest[i] = AudioFrame(v0, v1); } - if (C == 6) { + if constexpr (C == 6) { float v0 = rb[(pos * 6) + 0]; float v1 = rb[(pos * 6) + 1]; float v0n = rb[(pos_next * 6) + 0]; diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp index 4252131161..33d4c816f2 100644 --- a/servers/audio/audio_stream.cpp +++ b/servers/audio/audio_stream.cpp @@ -33,7 +33,7 @@ #include "core/config/project_settings.h" #include "core/os/os.h" -void AudioStreamPlayback::start(float p_from_pos) { +void AudioStreamPlayback::start(double p_from_pos) { if (GDVIRTUAL_CALL(_start, p_from_pos)) { return; } @@ -54,24 +54,20 @@ bool AudioStreamPlayback::is_playing() const { } int AudioStreamPlayback::get_loop_count() const { - int ret; - if (GDVIRTUAL_CALL(_get_loop_count, ret)) { - return ret; - } - return 0; + int ret = 0; + GDVIRTUAL_CALL(_get_loop_count, ret); + return ret; } -float AudioStreamPlayback::get_playback_position() const { - float ret; +double AudioStreamPlayback::get_playback_position() const { + double ret; if (GDVIRTUAL_CALL(_get_playback_position, ret)) { return ret; } ERR_FAIL_V_MSG(0, "AudioStreamPlayback::get_playback_position unimplemented!"); } -void AudioStreamPlayback::seek(float p_time) { - if (GDVIRTUAL_CALL(_seek, p_time)) { - return; - } +void AudioStreamPlayback::seek(double p_time) { + GDVIRTUAL_CALL(_seek, p_time); } int AudioStreamPlayback::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) { @@ -201,58 +197,44 @@ Ref<AudioStreamPlayback> AudioStream::instantiate_playback() { } String AudioStream::get_stream_name() const { String ret; - if (GDVIRTUAL_CALL(_get_stream_name, ret)) { - return ret; - } - return String(); + GDVIRTUAL_CALL(_get_stream_name, ret); + return ret; } -float AudioStream::get_length() const { - float ret; - if (GDVIRTUAL_CALL(_get_length, ret)) { - return ret; - } - return 0; +double AudioStream::get_length() const { + double ret = 0; + GDVIRTUAL_CALL(_get_length, ret); + return ret; } bool AudioStream::is_monophonic() const { - bool ret; - if (GDVIRTUAL_CALL(_is_monophonic, ret)) { - return ret; - } - return true; + bool ret = true; + GDVIRTUAL_CALL(_is_monophonic, ret); + return ret; } double AudioStream::get_bpm() const { double ret = 0; - if (GDVIRTUAL_CALL(_get_bpm, ret)) { - return ret; - } - return 0; + GDVIRTUAL_CALL(_get_bpm, ret); + return ret; } bool AudioStream::has_loop() const { bool ret = 0; - if (GDVIRTUAL_CALL(_has_loop, ret)) { - return ret; - } - return 0; + GDVIRTUAL_CALL(_has_loop, ret); + return ret; } int AudioStream::get_bar_beats() const { int ret = 0; - if (GDVIRTUAL_CALL(_get_bar_beats, ret)) { - return ret; - } - return 0; + GDVIRTUAL_CALL(_get_bar_beats, ret); + return ret; } int AudioStream::get_beat_count() const { int ret = 0; - if (GDVIRTUAL_CALL(_get_beat_count, ret)) { - return ret; - } - return 0; + GDVIRTUAL_CALL(_get_beat_count, ret); + return ret; } void AudioStream::tag_used(float p_offset) { @@ -309,7 +291,7 @@ String AudioStreamMicrophone::get_stream_name() const { return "Microphone"; } -float AudioStreamMicrophone::get_length() const { +double AudioStreamMicrophone::get_length() const { return 0; } @@ -382,7 +364,7 @@ float AudioStreamPlaybackMicrophone::get_stream_sampling_rate() { return AudioDriver::get_singleton()->get_mix_rate(); } -void AudioStreamPlaybackMicrophone::start(float p_from_pos) { +void AudioStreamPlaybackMicrophone::start(double p_from_pos) { if (active) { return; } @@ -415,11 +397,11 @@ int AudioStreamPlaybackMicrophone::get_loop_count() const { return 0; } -float AudioStreamPlaybackMicrophone::get_playback_position() const { +double AudioStreamPlaybackMicrophone::get_playback_position() const { return 0; } -void AudioStreamPlaybackMicrophone::seek(float p_time) { +void AudioStreamPlaybackMicrophone::seek(double p_time) { // Can't seek a microphone input } @@ -664,7 +646,7 @@ String AudioStreamRandomizer::get_stream_name() const { return "Randomizer"; } -float AudioStreamRandomizer::get_length() const { +double AudioStreamRandomizer::get_length() const { return 0; } @@ -769,7 +751,7 @@ void AudioStreamRandomizer::_bind_methods() { AudioStreamRandomizer::AudioStreamRandomizer() {} -void AudioStreamPlaybackRandomizer::start(float p_from_pos) { +void AudioStreamPlaybackRandomizer::start(double p_from_pos) { playing = playback; { float range_from = 1.0 / randomizer->random_pitch_scale; @@ -812,7 +794,7 @@ int AudioStreamPlaybackRandomizer::get_loop_count() const { return 0; } -float AudioStreamPlaybackRandomizer::get_playback_position() const { +double AudioStreamPlaybackRandomizer::get_playback_position() const { if (playing.is_valid()) { return playing->get_playback_position(); } @@ -820,7 +802,7 @@ float AudioStreamPlaybackRandomizer::get_playback_position() const { return 0; } -void AudioStreamPlaybackRandomizer::seek(float p_time) { +void AudioStreamPlaybackRandomizer::seek(double p_time) { if (playing.is_valid()) { playing->seek(p_time); } diff --git a/servers/audio/audio_stream.h b/servers/audio/audio_stream.h index 7c4577977d..c41475010c 100644 --- a/servers/audio/audio_stream.h +++ b/servers/audio/audio_stream.h @@ -47,23 +47,23 @@ class AudioStreamPlayback : public RefCounted { protected: static void _bind_methods(); - GDVIRTUAL1(_start, float) + GDVIRTUAL1(_start, double) GDVIRTUAL0(_stop) GDVIRTUAL0RC(bool, _is_playing) GDVIRTUAL0RC(int, _get_loop_count) - GDVIRTUAL0RC(float, _get_playback_position) - GDVIRTUAL1(_seek, float) + GDVIRTUAL0RC(double, _get_playback_position) + GDVIRTUAL1(_seek, double) GDVIRTUAL3R(int, _mix, GDNativePtr<AudioFrame>, float, int) GDVIRTUAL0(_tag_used_streams) public: - virtual void start(float p_from_pos = 0.0); + virtual void start(double p_from_pos = 0.0); virtual void stop(); virtual bool is_playing() const; virtual int get_loop_count() const; //times it looped - virtual float get_playback_position() const; - virtual void seek(float p_time); + virtual double get_playback_position() const; + virtual void seek(double p_time); virtual void tag_used_streams(); @@ -119,7 +119,7 @@ protected: GDVIRTUAL0RC(Ref<AudioStreamPlayback>, _instantiate_playback) GDVIRTUAL0RC(String, _get_stream_name) - GDVIRTUAL0RC(float, _get_length) + GDVIRTUAL0RC(double, _get_length) GDVIRTUAL0RC(bool, _is_monophonic) GDVIRTUAL0RC(double, _get_bpm) GDVIRTUAL0RC(bool, _has_loop) @@ -135,7 +135,7 @@ public: virtual int get_bar_beats() const; virtual int get_beat_count() const; - virtual float get_length() const; + virtual double get_length() const; virtual bool is_monophonic() const; void tag_used(float p_offset); @@ -161,7 +161,7 @@ public: virtual Ref<AudioStreamPlayback> instantiate_playback() override; virtual String get_stream_name() const override; - virtual float get_length() const override; //if supported, otherwise return 0 + virtual double get_length() const override; //if supported, otherwise return 0 virtual bool is_monophonic() const override; @@ -180,18 +180,18 @@ class AudioStreamPlaybackMicrophone : public AudioStreamPlaybackResampled { protected: virtual int _mix_internal(AudioFrame *p_buffer, int p_frames) override; virtual float get_stream_sampling_rate() override; - virtual float get_playback_position() const override; + virtual double get_playback_position() const override; public: virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override; - virtual void start(float p_from_pos = 0.0) override; + virtual void start(double p_from_pos = 0.0) override; virtual void stop() override; virtual bool is_playing() const override; virtual int get_loop_count() const override; //times it looped - virtual void seek(float p_time) override; + virtual void seek(double p_time) override; virtual void tag_used_streams() override; @@ -265,7 +265,7 @@ public: virtual Ref<AudioStreamPlayback> instantiate_playback() override; virtual String get_stream_name() const override; - virtual float get_length() const override; //if supported, otherwise return 0 + virtual double get_length() const override; //if supported, otherwise return 0 virtual bool is_monophonic() const override; AudioStreamRandomizer(); @@ -283,14 +283,14 @@ class AudioStreamPlaybackRandomizer : public AudioStreamPlayback { float volume_scale; public: - virtual void start(float p_from_pos = 0.0) override; + virtual void start(double p_from_pos = 0.0) override; virtual void stop() override; virtual bool is_playing() const override; virtual int get_loop_count() const override; //times it looped - virtual float get_playback_position() const override; - virtual void seek(float p_time) override; + virtual double get_playback_position() const override; + virtual void seek(double p_time) override; virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override; diff --git a/servers/audio/effects/audio_effect_delay.cpp b/servers/audio/effects/audio_effect_delay.cpp index f71ff05b23..69c62e3a13 100644 --- a/servers/audio/effects/audio_effect_delay.cpp +++ b/servers/audio/effects/audio_effect_delay.cpp @@ -94,7 +94,7 @@ void AudioEffectDelayInstance::_process_chunk(const AudioFrame *p_src_frames, Au //apply lowpass and feedback gain AudioFrame fb_in = out * feedback_level_f * lpf_ic + h * lpf_c; - fb_in.undenormalise(); //avoid denormals + fb_in.undenormalize(); //avoid denormals h = fb_in; fb_buf[feedback_buffer_pos] = fb_in; diff --git a/servers/audio/effects/audio_effect_distortion.cpp b/servers/audio/effects/audio_effect_distortion.cpp index 5987ed7bb2..25ca0cfdfe 100644 --- a/servers/audio/effects/audio_effect_distortion.cpp +++ b/servers/audio/effects/audio_effect_distortion.cpp @@ -50,7 +50,7 @@ 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]); + float out = undenormalize(src[i] * lpf_ic + lpf_c * h[i & 1]); h[i & 1] = out; float a = out; float ha = src[i] - out; //high freqs @@ -160,10 +160,10 @@ void AudioEffectDistortion::_bind_methods() { ClassDB::bind_method(D_METHOD("get_post_gain"), &AudioEffectDistortion::get_post_gain); ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Clip,ATan,LoFi,Overdrive,Wave Shape"), "set_mode", "get_mode"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pre_gain", PROPERTY_HINT_RANGE, "-60,60,0.01"), "set_pre_gain", "get_pre_gain"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pre_gain", PROPERTY_HINT_RANGE, "-60,60,0.01,suffix:dB"), "set_pre_gain", "get_pre_gain"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "keep_hf_hz", PROPERTY_HINT_RANGE, "1,20500,1,suffix:Hz"), "set_keep_hf_hz", "get_keep_hf_hz"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "drive", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drive", "get_drive"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "post_gain", PROPERTY_HINT_RANGE, "-80,24,0.01"), "set_post_gain", "get_post_gain"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "post_gain", PROPERTY_HINT_RANGE, "-80,24,0.01,suffix:dB"), "set_post_gain", "get_post_gain"); BIND_ENUM_CONSTANT(MODE_CLIP); BIND_ENUM_CONSTANT(MODE_ATAN); diff --git a/servers/audio/effects/audio_effect_eq.cpp b/servers/audio/effects/audio_effect_eq.cpp index 14ece8d93e..8a71ef0be7 100644 --- a/servers/audio/effects/audio_effect_eq.cpp +++ b/servers/audio/effects/audio_effect_eq.cpp @@ -128,8 +128,8 @@ AudioEffectEQ::AudioEffectEQ(EQ::Preset p_preset) { gain.resize(eq.get_band_count()); for (int i = 0; i < gain.size(); i++) { gain.write[i] = 0.0; - String name = "band_db/" + itos(eq.get_band_frequency(i)) + "_hz"; - prop_band_map[name] = i; - band_names.push_back(name); + String band_name = "band_db/" + itos(eq.get_band_frequency(i)) + "_hz"; + prop_band_map[band_name] = i; + band_names.push_back(band_name); } } diff --git a/servers/audio/effects/audio_effect_filter.cpp b/servers/audio/effects/audio_effect_filter.cpp index a9409076cd..68f8e334df 100644 --- a/servers/audio/effects/audio_effect_filter.cpp +++ b/servers/audio/effects/audio_effect_filter.cpp @@ -36,13 +36,13 @@ void AudioEffectFilterInstance::_process_filter(const AudioFrame *p_src_frames, 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 constexpr (S > 1) { filter_process[0][1].process_one(f); } - if (S > 2) { + if constexpr (S > 2) { filter_process[0][2].process_one(f); } - if (S > 3) { + if constexpr (S > 3) { filter_process[0][3].process_one(f); } @@ -52,13 +52,13 @@ 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 constexpr (S > 1) { filter_process[1][1].process_one(f); } - if (S > 2) { + if constexpr (S > 2) { filter_process[1][2].process_one(f); } - if (S > 3) { + if constexpr (S > 3) { filter_process[1][3].process_one(f); } diff --git a/servers/audio/effects/audio_effect_record.cpp b/servers/audio/effects/audio_effect_record.cpp index fff6dbc32a..b2e57c9a01 100644 --- a/servers/audio/effects/audio_effect_record.cpp +++ b/servers/audio/effects/audio_effect_record.cpp @@ -116,19 +116,11 @@ void AudioEffectRecordInstance::init() { recording_data.clear(); //Clear data completely and reset length is_recording = true; -#ifdef NO_THREADS - AudioServer::get_singleton()->add_update_callback(&AudioEffectRecordInstance::_update, this); -#else io_thread.start(_thread_callback, this); -#endif } void AudioEffectRecordInstance::finish() { -#ifdef NO_THREADS - AudioServer::get_singleton()->remove_update_callback(&AudioEffectRecordInstance::_update, this); -#else io_thread.wait_to_finish(); -#endif } AudioEffectRecordInstance::~AudioEffectRecordInstance() { diff --git a/servers/audio/effects/audio_stream_generator.cpp b/servers/audio/effects/audio_stream_generator.cpp index 6365dacc80..547b60a317 100644 --- a/servers/audio/effects/audio_stream_generator.cpp +++ b/servers/audio/effects/audio_stream_generator.cpp @@ -60,7 +60,7 @@ String AudioStreamGenerator::get_stream_name() const { return "UserFeed"; } -float AudioStreamGenerator::get_length() const { +double AudioStreamGenerator::get_length() const { return 0; } @@ -108,7 +108,7 @@ bool AudioStreamGeneratorPlayback::push_buffer(const PackedVector2Array &p_frame } const Vector2 *r = p_frames.ptr(); - if (sizeof(real_t) == 4) { + if constexpr (sizeof(real_t) == 4) { //write directly buffer.write((const AudioFrame *)r, to_write); } else { @@ -167,7 +167,7 @@ float AudioStreamGeneratorPlayback::get_stream_sampling_rate() { return generator->get_mix_rate(); } -void AudioStreamGeneratorPlayback::start(float p_from_pos) { +void AudioStreamGeneratorPlayback::start(double p_from_pos) { if (mixed == 0.0) { begin_resample(); } @@ -188,11 +188,11 @@ int AudioStreamGeneratorPlayback::get_loop_count() const { return 0; } -float AudioStreamGeneratorPlayback::get_playback_position() const { +double AudioStreamGeneratorPlayback::get_playback_position() const { return mixed; } -void AudioStreamGeneratorPlayback::seek(float p_time) { +void AudioStreamGeneratorPlayback::seek(double p_time) { //no seek possible } diff --git a/servers/audio/effects/audio_stream_generator.h b/servers/audio/effects/audio_stream_generator.h index a0bed0fda5..21cb3954d3 100644 --- a/servers/audio/effects/audio_stream_generator.h +++ b/servers/audio/effects/audio_stream_generator.h @@ -53,7 +53,7 @@ public: virtual Ref<AudioStreamPlayback> instantiate_playback() override; virtual String get_stream_name() const override; - virtual float get_length() const override; + virtual double get_length() const override; virtual bool is_monophonic() const override; AudioStreamGenerator(); }; @@ -74,14 +74,14 @@ protected: static void _bind_methods(); public: - virtual void start(float p_from_pos = 0.0) override; + virtual void start(double p_from_pos = 0.0) override; virtual void stop() override; virtual bool is_playing() const override; virtual int get_loop_count() const override; //times it looped - virtual float get_playback_position() const override; - virtual void seek(float p_time) override; + virtual double get_playback_position() const override; + virtual void seek(double p_time) override; bool push_frame(const Vector2 &p_frame); bool can_push_buffer(int p_frames) const; diff --git a/servers/audio/effects/reverb_filter.cpp b/servers/audio/effects/reverb_filter.cpp index 0363706714..2b60b73b7e 100644 --- a/servers/audio/effects/reverb_filter.cpp +++ b/servers/audio/effects/reverb_filter.cpp @@ -77,7 +77,7 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { read_pos += echo_buffer_size; } - float in = undenormalise(echo_buffer[read_pos] * params.predelay_fb + p_src[i]); + float in = undenormalize(echo_buffer[read_pos] * params.predelay_fb + p_src[i]); echo_buffer[echo_buffer_pos] = in; @@ -111,7 +111,7 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { c.pos = 0; } - float out = undenormalise(c.buffer[c.pos] * c.feedback); + 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; c.buffer[c.pos] = input_buffer[j] + out; @@ -138,7 +138,7 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { ap=&allpass[m_ap]; \ if (ap->pos>=ap_size_limit[m_ap]) \ ap->pos=0; \ - aux=undenormalise(ap->buffer[ap->pos]); \ + aux=undenormalize(ap->buffer[ap->pos]); \ in=sample; \ sample=-in+aux; \ ap->pos++; @@ -163,7 +163,7 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { } float aux = a.buffer[a.pos]; - a.buffer[a.pos] = undenormalise(allpass_feedback * aux + p_dst[j]); + a.buffer[a.pos] = undenormalize(allpass_feedback * aux + p_dst[j]); p_dst[j] = aux - allpass_feedback * a.buffer[a.pos]; a.pos++; } |