fix: use u64 to prevent overflowing (I can't believe I was stupid enough to think u32 could fit it) and add logging in case I was mistaken

This commit is contained in:
2026-06-01 23:18:55 -04:00
parent 65611d676d
commit 4fa25305b5

View File

@@ -294,8 +294,8 @@ pub async fn handle(state: State, interaction: Interaction) {
let channels = state.audio_channels.into();
let sample_rate = state.audio_sample_rate.into();
let total_samples = (duration.whole_seconds() as u32 * sample_rate)
+ (duration.subsec_microseconds() as u32 * sample_rate / 1_000_000);
let total_samples = (duration.whole_seconds() as u64 * sample_rate)
+ (duration.subsec_microseconds() as u64 * sample_rate / 1_000_000);
let mut composite = vec![0; total_samples as usize];
@@ -342,19 +342,24 @@ pub async fn handle(state: State, interaction: Interaction) {
let progress_by_time = after_start / duration;
let origin = (after_start.whole_seconds() as u32 * sample_rate)
+ (after_start.subsec_microseconds() as u32 * sample_rate / 1_000_000);
let origin = (after_start.whole_seconds() as u64 * sample_rate)
+ (after_start.subsec_microseconds() as u64 * sample_rate / 1_000_000);
let origin = origin as usize;
let progress_by_sample = (origin as f64) / (total_samples as f64);
let samples_length = samples.len();
let extent = origin + samples_length;
tracing::debug!(
progress_by_time,
progress_by_sample,
?after_start,
?duration,
origin,
total_samples
total_samples,
samples_length,
extent
);
for (i, sample) in samples.into_iter().enumerate() {
@@ -372,6 +377,8 @@ pub async fn handle(state: State, interaction: Interaction) {
?second,
?microsecond,
origin,
samples_length,
extent,
i,
total_samples,
"out of range"