constants.rs (1485B)
1 //! Audio processing constants 2 3 pub const SAMPLE_RATE: u32 = 22050; 4 5 // BPM 6 pub const BPM_WINDOW_SIZE: usize = 1024; 7 pub const BPM_HOP_SIZE: usize = 128; 8 pub const BPM_OFFSET: f32 = -1.15; 9 pub const BPM_MIN: f32 = 80.0; 10 pub const BPM_MAX: f32 = 160.0; 11 12 // Key 13 pub const KEY_WINDOW_SIZE: usize = 8192; 14 pub const KEY_HOP_SIZE: usize = 2205; 15 pub const TUNING_PRECISION: f64 = 0.01; 16 pub const CHROMA_BINS: usize = 12; 17 18 // Supported audio file extensions 19 use std::collections::HashSet; 20 use std::sync::LazyLock; 21 22 pub static SUPPORTED_EXTENSIONS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| { 23 HashSet::from([ 24 "aac", "ape", "aif", "aiff", "flac", "mp3", "mp4", "m4a", "mpc", "opus", "ogg", "spx", 25 "wav", "wv", 26 ]) 27 }); 28 29 #[cfg(test)] 30 mod tests { 31 use super::*; 32 33 #[test] 34 fn supported_extensions_are_lowercase_and_present() { 35 // The matcher lowercases input, so the set itself must stay lowercase. 36 for ext in SUPPORTED_EXTENSIONS.iter() { 37 assert_eq!(*ext, ext.to_lowercase(), "{ext} is not lowercase"); 38 } 39 assert!(SUPPORTED_EXTENSIONS.contains("mp3")); 40 assert!(SUPPORTED_EXTENSIONS.contains("flac")); 41 assert!(!SUPPORTED_EXTENSIONS.contains("txt")); 42 } 43 44 #[test] 45 fn bpm_bounds_are_sane() { 46 assert!(BPM_MIN > 0.0); 47 assert!(BPM_MAX > BPM_MIN); 48 assert!(BPM_HOP_SIZE > 0); 49 assert!(BPM_WINDOW_SIZE >= BPM_HOP_SIZE); 50 assert_eq!(CHROMA_BINS, 12); 51 } 52 }