Clamp samples before encoding flac

Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
Ivan Bushchik 2024-09-01 14:42:14 +03:00
parent 60791dc292
commit 80cef97ca2
No known key found for this signature in database
GPG key ID: 2F16FBF3262E090C

View file

@ -32,13 +32,12 @@ pub fn encode(
#[cfg(feature = "flac")]
{
use flacenc::{component::BitRepr, error::Verify, source::MemSource};
let encoded = flacenc::encode_with_fixed_block_size(
&flacenc::config::Encoder::default().into_verified().unwrap(),
MemSource::from_samples(
&samples
.iter()
.map(|x| (*x as f64 * 32768.0 * 256.0) as i32)
.map(|x| (x.clamp(-1.0, 1.0) as f64 * 32768.0 * 256.0) as i32)
.collect::<Vec<i32>>(),
channels as usize,
24,