From 6e62ee4057b8ea3144f2f4df85e5d56c37c8fd72 Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 2 Nov 2026 13:28:23 +0100 Subject: audio: open the output at the track's rate instead of pw-alsa's 44100 cpal asks the ALSA "default" PCM for its default config and pipewire-alsa answers 44.1 kHz no matter what the graph runs at, so 48 kHz material was resampled down to 44.1 in our linear resampler and then back up to 48 by PipeWire. The stream now opens at the track's own rate (when the device supports it), which keeps our resampler out of the path and leaves the conversion to PipeWire's polyphase one. The new `sample_rate` setting forces a fixed rate instead ("auto" by default), for anyone who would rather match the graph exactly. --- tests/config.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests/config.rs') diff --git a/tests/config.rs b/tests/config.rs index 7b9d179..6a44a17 100644 --- a/tests/config.rs +++ b/tests/config.rs @@ -21,6 +21,7 @@ fn test_config_get_scan_interval() { volume: None, shuffle: None, display_format: Some(String::from("$ARTIST - $TRACK")), + sample_rate: None, }; assert_eq!(config.get("scan_interval").unwrap(), "3600"); } @@ -38,6 +39,7 @@ fn test_config_get_not_set() { volume: None, shuffle: None, display_format: None, + sample_rate: None, }; assert_eq!(config.get("scan_interval").unwrap(), "not set"); } @@ -55,6 +57,7 @@ fn test_config_get_volume() { volume: Some(75), shuffle: None, display_format: None, + sample_rate: None, }; assert_eq!(config.get("volume").unwrap(), "75"); } @@ -135,6 +138,7 @@ fn test_config_unset_volume() { volume: Some(50), shuffle: None, display_format: None, + sample_rate: None, }; config.unset("volume").unwrap(); assert_eq!(config.volume, None); @@ -146,3 +150,41 @@ fn test_config_unset_unknown_key() { let result = config.unset("unknown_key"); assert!(result.is_err()); } + +#[test] +fn test_config_sample_rate_defaults_to_auto() { + let config = Config { + config_path: PathBuf::from("/test/config.toml"), + music_paths: vec![], + scan_interval: None, + lastfm_api_key: None, + lastfm_api_secret: None, + lastfm_session_key: None, + listenbrainz_token: None, + volume: None, + shuffle: None, + display_format: None, + sample_rate: None, + }; + assert_eq!(config.get("sample_rate").unwrap(), "auto"); + assert_eq!(config.sample_rate_hz(), None); +} + +#[test] +fn test_config_set_sample_rate() { + let mut config = Config::default(); + config.set("sample_rate", "48000").unwrap(); + assert_eq!(config.get("sample_rate").unwrap(), "48000"); + assert_eq!(config.sample_rate_hz(), Some(48_000)); + + config.set("sample_rate", "auto").unwrap(); + assert_eq!(config.sample_rate_hz(), None); +} + +#[test] +fn test_config_rejects_bad_sample_rate() { + let mut config = Config::default(); + assert!(config.set("sample_rate", "fast").is_err()); + assert!(config.set("sample_rate", "100").is_err()); + assert!(config.set("sample_rate", "999999").is_err()); +} -- cgit v1.2.3