route the size and byte maths through saturating helpers

This commit is contained in:
2026-09-21 01:20:11 +03:00
parent 7c577eafd7
commit cd583ba02b
3 changed files with 46 additions and 21 deletions
+2 -2
View File
@@ -356,7 +356,7 @@ fn clear_temp_segments(app_dir: &Path, keep_previews: bool) {
fn adjust_audio_length(path: &Path, sample_rate: u32, channels: u16, target_secs: f64) -> Result<()> {
use std::io::Write;
let bytes_per_sec = f64::from(sample_rate) * f64::from(channels) * 4.0;
let target_bytes = (target_secs * bytes_per_sec).round() as u64;
let target_bytes = encode::round_u64(target_secs * bytes_per_sec);
let current_bytes = std::fs::metadata(path)?.len();
if current_bytes == target_bytes {
return Ok(());
@@ -387,7 +387,7 @@ fn adjust_audio_length(path: &Path, sample_rate: u32, channels: u16, target_secs
fn pad_audio_head(path: &Path, sample_rate: u32, channels: u16, head_secs: f64) -> Result<()> {
use std::io::Write;
let bytes_per_sec = f64::from(sample_rate) * f64::from(channels) * 4.0;
let pad_bytes = (head_secs * bytes_per_sec).round() as u64;
let pad_bytes = encode::round_u64(head_secs * bytes_per_sec);
if pad_bytes == 0 {
return Ok(());
}