From 4fa25305b572727c7f3d0adca7e511c962e77770 Mon Sep 17 00:00:00 2001 From: Jacob Date: Mon, 1 Jun 2026 23:18:55 -0400 Subject: [PATCH] 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 --- src/command/render.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/command/render.rs b/src/command/render.rs index 6e9a144..0b87fe2 100644 --- a/src/command/render.rs +++ b/src/command/render.rs @@ -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"