Skip to content

Commit

Permalink
Clamp samples before encoding flac
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Bushchik <[email protected]>
  • Loading branch information
ivabus committed Sep 1, 2024
1 parent 60791dc commit 80cef97
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 80cef97

Please sign in to comment.