diff options
Diffstat (limited to 'servers/audio')
-rw-r--r-- | servers/audio/audio_stream.cpp | 27 | ||||
-rw-r--r-- | servers/audio/audio_stream.h | 11 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_reverb.cpp | 4 |
3 files changed, 26 insertions, 16 deletions
diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp index 369dfac042..0ad30987e7 100644 --- a/servers/audio/audio_stream.cpp +++ b/servers/audio/audio_stream.cpp @@ -46,9 +46,9 @@ void AudioStreamPlaybackResampled::_begin_resample() { void AudioStreamPlaybackResampled::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) { - float target_rate = AudioServer::get_singleton()->get_mix_rate() * p_rate_scale; + float target_rate = AudioServer::get_singleton()->get_mix_rate(); - uint64_t mix_increment = uint64_t((get_stream_sampling_rate() / double(target_rate)) * double(FP_LEN)); + uint64_t mix_increment = uint64_t(((get_stream_sampling_rate() * p_rate_scale) / double(target_rate)) * double(FP_LEN)); for (int i = 0; i < p_frames; i++) { @@ -91,6 +91,13 @@ void AudioStreamPlaybackResampled::mix(AudioFrame *p_buffer, float p_rate_scale, } //////////////////////////////// +void AudioStream::_bind_methods() { + + ClassDB::bind_method(D_METHOD("get_length"), &AudioStream::get_length); +} + +//////////////////////////////// + void AudioStreamRandomPitch::set_audio_stream(const Ref<AudioStream> &p_audio_stream) { audio_stream = p_audio_stream; @@ -136,6 +143,14 @@ String AudioStreamRandomPitch::get_stream_name() const { return "RandomPitch"; } +float AudioStreamRandomPitch::get_length() const { + if (audio_stream.is_valid()) { + return audio_stream->get_length(); + } + + return 0; +} + void AudioStreamRandomPitch::_bind_methods() { ClassDB::bind_method(D_METHOD("set_audio_stream", "stream"), &AudioStreamRandomPitch::set_audio_stream); @@ -209,14 +224,6 @@ void AudioStreamPlaybackRandomPitch::mix(AudioFrame *p_buffer, float p_rate_scal } } -float AudioStreamPlaybackRandomPitch::get_length() const { - if (playing.is_valid()) { - return playing->get_length(); - } - - return 0; -} - AudioStreamPlaybackRandomPitch::~AudioStreamPlaybackRandomPitch() { random_pitch->playbacks.erase(this); } diff --git a/servers/audio/audio_stream.h b/servers/audio/audio_stream.h index a6fb88364f..fda4fc2ccc 100644 --- a/servers/audio/audio_stream.h +++ b/servers/audio/audio_stream.h @@ -50,8 +50,6 @@ public: virtual void seek(float p_time) = 0; virtual void mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) = 0; - - virtual float get_length() const = 0; //if supported, otherwise return 0 }; class AudioStreamPlaybackResampled : public AudioStreamPlayback { @@ -85,9 +83,14 @@ class AudioStream : public Resource { GDCLASS(AudioStream, Resource) OBJ_SAVE_TYPE(AudioStream) //children are all saved as AudioStream, so they can be exchanged +protected: + static void _bind_methods(); + public: virtual Ref<AudioStreamPlayback> instance_playback() = 0; virtual String get_stream_name() const = 0; + + virtual float get_length() const = 0; //if supported, otherwise return 0 }; class AudioStreamPlaybackRandomPitch; @@ -114,6 +117,8 @@ public: virtual Ref<AudioStreamPlayback> instance_playback(); virtual String get_stream_name() const; + virtual float get_length() const; //if supported, otherwise return 0 + AudioStreamRandomPitch(); }; @@ -139,8 +144,6 @@ public: virtual void mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames); - virtual float get_length() const; //if supported, otherwise return 0 - ~AudioStreamPlaybackRandomPitch(); }; diff --git a/servers/audio/effects/audio_effect_reverb.cpp b/servers/audio/effects/audio_effect_reverb.cpp index 204b11746c..162c0a1445 100644 --- a/servers/audio/effects/audio_effect_reverb.cpp +++ b/servers/audio/effects/audio_effect_reverb.cpp @@ -96,7 +96,7 @@ void AudioEffectReverb::set_predelay_msec(float p_msec) { void AudioEffectReverb::set_predelay_feedback(float p_feedback) { - predelay_fb = p_feedback; + predelay_fb = CLAMP(p_feedback, 0, 0.98); } void AudioEffectReverb::set_room_size(float p_size) { @@ -185,7 +185,7 @@ void AudioEffectReverb::_bind_methods() { ADD_GROUP("Predelay", "predelay_"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "predelay_msec", PROPERTY_HINT_RANGE, "20,500,1"), "set_predelay_msec", "get_predelay_msec"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "predelay_feedback", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_predelay_feedback", "get_predelay_feedback"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "predelay_feedback", PROPERTY_HINT_RANGE, "0,0.98,0.01"), "set_predelay_feedback", "get_predelay_feedback"); 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"); |