aboutsummaryrefslogtreecommitdiffstats
path: root/tests/config.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-02 13:28:23 +0100
committersalmonik <salmonik@tuta.io>2026-11-02 13:28:23 +0100
commit6e62ee4057b8ea3144f2f4df85e5d56c37c8fd72 (patch)
tree5cc559e2eaad47f632294914a9d57133e863b1b8 /tests/config.rs
parentconfig: parse the config once and reuse it until the file changes (diff)
downloadrsplayer-6e62ee4057b8ea3144f2f4df85e5d56c37c8fd72.tar.gz
rsplayer-6e62ee4057b8ea3144f2f4df85e5d56c37c8fd72.zip
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.
Diffstat (limited to 'tests/config.rs')
-rw-r--r--tests/config.rs42
1 files changed, 42 insertions, 0 deletions
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() {
21 volume: None, 21 volume: None,
22 shuffle: None, 22 shuffle: None,
23 display_format: Some(String::from("$ARTIST - $TRACK")), 23 display_format: Some(String::from("$ARTIST - $TRACK")),
24 sample_rate: None,
24 }; 25 };
25 assert_eq!(config.get("scan_interval").unwrap(), "3600"); 26 assert_eq!(config.get("scan_interval").unwrap(), "3600");
26} 27}
@@ -38,6 +39,7 @@ fn test_config_get_not_set() {
38 volume: None, 39 volume: None,
39 shuffle: None, 40 shuffle: None,
40 display_format: None, 41 display_format: None,
42 sample_rate: None,
41 }; 43 };
42 assert_eq!(config.get("scan_interval").unwrap(), "not set"); 44 assert_eq!(config.get("scan_interval").unwrap(), "not set");
43} 45}
@@ -55,6 +57,7 @@ fn test_config_get_volume() {
55 volume: Some(75), 57 volume: Some(75),
56 shuffle: None, 58 shuffle: None,
57 display_format: None, 59 display_format: None,
60 sample_rate: None,
58 }; 61 };
59 assert_eq!(config.get("volume").unwrap(), "75"); 62 assert_eq!(config.get("volume").unwrap(), "75");
60} 63}
@@ -135,6 +138,7 @@ fn test_config_unset_volume() {
135 volume: Some(50), 138 volume: Some(50),
136 shuffle: None, 139 shuffle: None,
137 display_format: None, 140 display_format: None,
141 sample_rate: None,
138 }; 142 };
139 config.unset("volume").unwrap(); 143 config.unset("volume").unwrap();
140 assert_eq!(config.volume, None); 144 assert_eq!(config.volume, None);
@@ -146,3 +150,41 @@ fn test_config_unset_unknown_key() {
146 let result = config.unset("unknown_key"); 150 let result = config.unset("unknown_key");
147 assert!(result.is_err()); 151 assert!(result.is_err());
148} 152}
153
154#[test]
155fn test_config_sample_rate_defaults_to_auto() {
156 let config = Config {
157 config_path: PathBuf::from("/test/config.toml"),
158 music_paths: vec![],
159 scan_interval: None,
160 lastfm_api_key: None,
161 lastfm_api_secret: None,
162 lastfm_session_key: None,
163 listenbrainz_token: None,
164 volume: None,
165 shuffle: None,
166 display_format: None,
167 sample_rate: None,
168 };
169 assert_eq!(config.get("sample_rate").unwrap(), "auto");
170 assert_eq!(config.sample_rate_hz(), None);
171}
172
173#[test]
174fn test_config_set_sample_rate() {
175 let mut config = Config::default();
176 config.set("sample_rate", "48000").unwrap();
177 assert_eq!(config.get("sample_rate").unwrap(), "48000");
178 assert_eq!(config.sample_rate_hz(), Some(48_000));
179
180 config.set("sample_rate", "auto").unwrap();
181 assert_eq!(config.sample_rate_hz(), None);
182}
183
184#[test]
185fn test_config_rejects_bad_sample_rate() {
186 let mut config = Config::default();
187 assert!(config.set("sample_rate", "fast").is_err());
188 assert!(config.set("sample_rate", "100").is_err());
189 assert!(config.set("sample_rate", "999999").is_err());
190}