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