Fix bug in AudioData
This commit is contained in:
parent
7a78c6b9e6
commit
9311470b1c
@ -153,13 +153,15 @@ impl AudioData {
|
|||||||
let samples_needed = output_slice.len();
|
let samples_needed = output_slice.len();
|
||||||
|
|
||||||
while samples_written < samples_needed {
|
while samples_written < samples_needed {
|
||||||
let samples_remaining = samples_needed - samples_written;
|
|
||||||
let samples_until_loop = length - logical_position;
|
|
||||||
let samples_to_copy = samples_remaining.min(samples_until_loop);
|
|
||||||
|
|
||||||
// Map logical position to buffer position using sync offset
|
// Map logical position to buffer position using sync offset
|
||||||
let buffer_position = (logical_position + sync_offset) % length;
|
let buffer_position = (logical_position + sync_offset) % length;
|
||||||
|
|
||||||
|
let samples_remaining_in_output = samples_needed - samples_written;
|
||||||
|
// This is the crucial change: determine how many contiguous samples can be read from the current buffer_position
|
||||||
|
let readable_samples_from_here = length - buffer_position;
|
||||||
|
|
||||||
|
let samples_to_copy = samples_remaining_in_output.min(readable_samples_from_here);
|
||||||
|
|
||||||
// Copy from chunks to output slice
|
// Copy from chunks to output slice
|
||||||
chunks.copy_samples(
|
chunks.copy_samples(
|
||||||
&mut output_slice[samples_written..samples_written + samples_to_copy],
|
&mut output_slice[samples_written..samples_written + samples_to_copy],
|
||||||
@ -172,12 +174,7 @@ impl AudioData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
samples_written += samples_to_copy;
|
samples_written += samples_to_copy;
|
||||||
logical_position += samples_to_copy;
|
logical_position = (logical_position + samples_to_copy) % length;
|
||||||
|
|
||||||
// Handle looping
|
|
||||||
if logical_position >= length {
|
|
||||||
logical_position = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user