forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB8dbd683Tahinli3 months ago856 commits

config.rs92 lines, 2.5 KiBHistoryRawDownload
1//! `flacenc::config`: the encoder configuration tree.
2//!
3//! The fields the replica reads (`block_size`) and the ones its `Default`
4//! walks are kept; the knobs that only steer the incumbent's own search
5//! (window functions, per-order caps) are not reproduced, because a value set
6//! there would silently do nothing.
7
8use crate::error::{Verify, VerifyError};
9
10/// Encoder configuration — `flacenc::config::Encoder`.
11#[derive(Clone, Debug, PartialEq, Eq)]
12#[non_exhaustive]
13pub struct Encoder {
14 /// Encoder block size.
15 pub block_size: usize,
16 /// Whether the encoder may use several threads.
17 pub multithread: bool,
18 /// Stereo coding switches.
19 pub stereo_coding: StereoCoding,
20 /// Per-channel coding switches.
21 pub subframe_coding: SubFrameCoding,
22}
23
24impl Default for Encoder {
25 fn default() -> Self {
26 Encoder {
27 block_size: 4096,
28 multithread: false,
29 stereo_coding: StereoCoding::default(),
30 subframe_coding: SubFrameCoding::default(),
31 }
32 }
33}
34
35impl Verify for Encoder {
36 fn verify(&self) -> Result<(), VerifyError> {
37 if !(16..=65535).contains(&self.block_size) {
38 return Err(VerifyError::new(
39 "block_size",
40 "must be in the range of 16..=65535.",
41 ));
42 }
43 Ok(())
44 }
45}
46
47/// Stereo coding switches — `flacenc::config::StereoCoding`.
48#[derive(Clone, Debug, PartialEq, Eq)]
49#[non_exhaustive]
50pub struct StereoCoding {
51 /// Allow left/side coding.
52 pub use_leftside: bool,
53 /// Allow right/side coding.
54 pub use_rightside: bool,
55 /// Allow mid/side coding.
56 pub use_midside: bool,
57}
58
59impl Default for StereoCoding {
60 fn default() -> Self {
61 StereoCoding {
62 use_leftside: true,
63 use_rightside: true,
64 use_midside: true,
65 }
66 }
67}
68
69/// Per-channel coding switches — `flacenc::config::SubFrameCoding`.
70///
71/// Verbatim coding is deliberately not switchable: it is the representation
72/// that always exists, so turning it off could leave a signal unencodable.
73#[derive(Clone, Debug, PartialEq, Eq)]
74#[non_exhaustive]
75pub struct SubFrameCoding {
76 /// Allow constant subframes.
77 pub use_constant: bool,
78 /// Allow fixed-predictor subframes.
79 pub use_fixed: bool,
80 /// Allow LPC subframes.
81 pub use_lpc: bool,
82}
83
84impl Default for SubFrameCoding {
85 fn default() -> Self {
86 SubFrameCoding {
87 use_constant: true,
88 use_fixed: true,
89 use_lpc: true,
90 }
91 }
92}