forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBbcb4dc5Tahinli21 days ago1034 commits

flac_write.rs35 lines, 1.1 KiBHistoryRawDownload
1//! Writes interleaved PCM as a `.flac` file through `ec-flac`, the family's own
2//! encoder (fixed 4096-sample blocks, LPC, Rice partitions, stereo
3//! decorrelation, and an MD5 in `STREAMINFO` that any decoder can check).
4//!
5//! The export path only ever asks for 16 bits; the bit depth is a parameter so
6//! the parity tests can write 24-bit streams through the same function.
7
8use std::path::Path;
9
10use ec_flac::EncoderConfig;
11
12/// Encode `samples` (interleaved by channel, each already within
13/// `bits_per_sample`) and write the stream to `out`.
14///
15/// `EncoderConfig::default()` is the level the family ships. Edith has no
16/// FLAC compression setting, so there is nothing to map: the export always
17/// asks for that default.
18pub fn write(
19 out: &Path,
20 samples: &[i32],
21 channels: usize,
22 bits_per_sample: u32,
23 sample_rate: u32,
24) -> crate::Result<()> {
25 let bytes = ec_flac::encode(
26 &EncoderConfig::default(),
27 samples,
28 channels,
29 bits_per_sample,
30 sample_rate,
31 )
32 .map_err(|e| format!("flac encode: {e}"))?;
33 std::fs::write(out, bytes)?;
34 Ok(())
35}