aboutsummaryrefslogtreecommitdiffstats
path: root/src/recording/mod.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-04 01:12:58 +0100
committersalmonik <salmonik@tuta.io>2026-11-04 01:12:58 +0100
commit91d51e9f7382ea01d69b2e21452d4de56fefec8d (patch)
tree87113f53f9b30631fc9697ba4ab939cb2b7fa386 /src/recording/mod.rs
parentcron/triggers: keep pre-scoping rows manageable (diff)
downloadsenator-sperma-91d51e9f7382ea01d69b2e21452d4de56fefec8d.tar.gz
senator-sperma-91d51e9f7382ea01d69b2e21452d4de56fefec8d.zip
recording: reject a zero-length window
Diffstat (limited to 'src/recording/mod.rs')
-rw-r--r--src/recording/mod.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/recording/mod.rs b/src/recording/mod.rs
index 4cd2891..e03df32 100644
--- a/src/recording/mod.rs
+++ b/src/recording/mod.rs
@@ -57,6 +57,9 @@ struct Inner {
57impl Recorder { 57impl Recorder {
58 pub fn new(sample_rate: u32, window_seconds: u64) -> Self { 58 pub fn new(sample_rate: u32, window_seconds: u64) -> Self {
59 let samples_per_frame = (sample_rate as usize) / TICKS_PER_SEC; 59 let samples_per_frame = (sample_rate as usize) / TICKS_PER_SEC;
60 // Defensive: callers validate config, but a zero-length ring would
61 // panic on `% len` in `mix_tick`.
62 let window_seconds = window_seconds.max(1);
60 let window_samples = (sample_rate as usize) * (window_seconds as usize); 63 let window_samples = (sample_rate as usize) * (window_seconds as usize);
61 // `head` advances by `samples_per_frame` and wraps mod `window_samples`, 64 // `head` advances by `samples_per_frame` and wraps mod `window_samples`,
62 // so the window length must be a whole number of frames. 65 // so the window length must be a whole number of frames.
@@ -342,6 +345,14 @@ mod tests {
342 } 345 }
343 346
344 #[test] 347 #[test]
348 fn zero_window_is_clamped_and_does_not_panic() {
349 let rec = Recorder::new(48_000, 0);
350 let spf = rec.samples_per_frame;
351 rec.mix_tick(&[vec![1i16; spf]]);
352 assert!(!rec.flush().is_empty());
353 }
354
355 #[test]
345 fn single_speaker_values_survive() { 356 fn single_speaker_values_survive() {
346 let rec = Recorder::new(48_000, 1); 357 let rec = Recorder::new(48_000, 1);
347 let spf = rec.samples_per_frame; 358 let spf = rec.samples_per_frame;