v0.6.5 — Two-tone audible alarms
Both standard/technical and critical alarm sounds now consist of two distinct successive pitches. Critical alarms retain their priority and faster repeat interval; standard alarms retain their slower cadence. The Admin test button plays the standard two-tone alert. A single QRS beep is reserved for a later release and is not generated yet. No visual alarm or simulation logic changed.
This commit is contained in:
parent
00dc22b1aa
commit
196ed03a3d
8 changed files with 267 additions and 46 deletions
|
|
@ -84,14 +84,21 @@ pub fn level(p: &Parameters, sim: &Simulator) -> AlarmLevel {
|
|||
result
|
||||
}
|
||||
|
||||
/// Very short, original synthesized sine beeps; mono PCM16 WAV.
|
||||
/// Both alarm priorities sound as two successive, different pitches.
|
||||
/// A future QRS beep will be a separate, single-tone signal.
|
||||
/// Zero-frequency segments are short silences between the notes.
|
||||
fn tone_segments(critical: bool) -> &'static [(f64, f64)] {
|
||||
if critical {
|
||||
&[(880.0, 0.16), (0.0, 0.08), (1160.0, 0.16)]
|
||||
} else {
|
||||
&[(700.0, 0.14), (0.0, 0.06), (950.0, 0.14)]
|
||||
}
|
||||
}
|
||||
|
||||
/// Very short, original synthesized two-tone alerts; mono PCM16 WAV.
|
||||
fn wav(critical: bool) -> Vec<u8> {
|
||||
const SAMPLE_RATE: u32 = 44_100;
|
||||
let segments: &[(f64, f64)] = if critical {
|
||||
&[(880.0, 0.16), (0.0, 0.09), (880.0, 0.16)]
|
||||
} else {
|
||||
&[(700.0, 0.18)]
|
||||
};
|
||||
let segments = tone_segments(critical);
|
||||
let samples: usize = segments.iter()
|
||||
.map(|(_, seconds)| (seconds * f64::from(SAMPLE_RATE)).round() as usize)
|
||||
.sum();
|
||||
|
|
@ -267,8 +274,9 @@ impl AlarmAudio {
|
|||
}
|
||||
|
||||
/// Called from a 100-ms GLib timer, not the 250-Hz waveform simulator.
|
||||
/// Critical rhythms: double tone every 1.5 s; other alarms: single tone
|
||||
/// every 2.5 s. Stop promptly when muted or all alarm states clear.
|
||||
/// Critical rhythms: higher-pitched two-tone alert every 1.5 s;
|
||||
/// other alarms: lower-pitched two-tone alert every 2.5 s.
|
||||
/// Stop promptly when muted or all alarm states clear.
|
||||
pub fn update(&mut self, level: AlarmLevel, enabled: bool) {
|
||||
self.reap();
|
||||
if !enabled || level == AlarmLevel::None {
|
||||
|
|
@ -322,6 +330,21 @@ mod tests {
|
|||
assert!(wav(true).len() > wav(false).len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn both_alarm_priorities_have_two_distinct_audible_pitches() {
|
||||
for critical in [false, true] {
|
||||
let segments = tone_segments(critical);
|
||||
let notes: Vec<f64> = segments.iter()
|
||||
.filter_map(|(hz, _seconds)| (*hz > 0.0).then_some(*hz))
|
||||
.collect();
|
||||
assert_eq!(notes.len(), 2, "each alarm pattern must contain two notes");
|
||||
assert_ne!(notes[0], notes[1], "a two-tone alert needs distinct pitches");
|
||||
assert!(segments.iter().any(|(hz, _)| *hz == 0.0), "notes must be separated");
|
||||
assert!(segments.iter().all(|(_, seconds)| *seconds > 0.0));
|
||||
}
|
||||
assert_ne!(wav(false), wav(true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normal_signals_are_silent_and_numeric_limit_alarms_beep() {
|
||||
let mut p = Parameters::default();
|
||||
|
|
|
|||
Loading…
Reference in a new issue