summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-09-12 09:25:31 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-09-12 09:25:31 +0200
commitb998cb13355f4cf985e895ff9a2ee695b0fb4845 (patch)
treefe5f446e85aa9a1c14a0b666d7a29b21cbecf4ed
parentcee14dbff2073ae5e0047c1b68c78dcbe4bb0181 (diff)
parent147accdf74762ee8da012422f879db61b2ed8ebb (diff)
downloadredot-engine-b998cb13355f4cf985e895ff9a2ee695b0fb4845.tar.gz
Merge pull request #96768 from DeeJayLSP/wav-end
WAV: Fix one frame overflow at the end
-rw-r--r--editor/import/resource_importer_wav.cpp4
-rw-r--r--scene/resources/audio_stream_wav.cpp2
2 files changed, 3 insertions, 3 deletions
diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp
index 77b3629b07..7a6f39906c 100644
--- a/editor/import/resource_importer_wav.cpp
+++ b/editor/import/resource_importer_wav.cpp
@@ -429,10 +429,10 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
loop_end = p_options["edit/loop_end"];
// Wrap around to max frames, so `-1` can be used to select the end, etc.
if (loop_begin < 0) {
- loop_begin = CLAMP(loop_begin + frames + 1, 0, frames);
+ loop_begin = CLAMP(loop_begin + frames, 0, frames - 1);
}
if (loop_end < 0) {
- loop_end = CLAMP(loop_end + frames + 1, 0, frames);
+ loop_end = CLAMP(loop_end + frames, 0, frames - 1);
}
}
diff --git a/scene/resources/audio_stream_wav.cpp b/scene/resources/audio_stream_wav.cpp
index de67a93bd1..f9787dde2e 100644
--- a/scene/resources/audio_stream_wav.cpp
+++ b/scene/resources/audio_stream_wav.cpp
@@ -297,7 +297,7 @@ int AudioStreamPlaybackWAV::mix(AudioFrame *p_buffer, float p_rate_scale, int p_
int64_t loop_end_fp = ((int64_t)base->loop_end << MIX_FRAC_BITS);
int64_t length_fp = ((int64_t)len << MIX_FRAC_BITS);
int64_t begin_limit = (base->loop_mode != AudioStreamWAV::LOOP_DISABLED) ? loop_begin_fp : 0;
- int64_t end_limit = (base->loop_mode != AudioStreamWAV::LOOP_DISABLED) ? loop_end_fp : length_fp;
+ int64_t end_limit = (base->loop_mode != AudioStreamWAV::LOOP_DISABLED) ? loop_end_fp : length_fp - MIX_FRAC_LEN;
bool is_stereo = base->stereo;
int32_t todo = p_frames;