speech_prep/
monitoring.rs1use std::sync::atomic::{AtomicU64, Ordering};
4
5#[derive(Debug, Default)]
7pub struct AtomicCounter(AtomicU64);
8
9impl AtomicCounter {
10 pub fn new(initial: u64) -> Self {
11 Self(AtomicU64::new(initial))
12 }
13
14 pub fn increment(&self) -> u64 {
15 self.0.fetch_add(1, Ordering::Relaxed)
16 }
17
18 pub fn get(&self) -> u64 {
19 self.0.load(Ordering::Relaxed)
20 }
21
22 pub fn reset(&self) {
23 self.0.store(0, Ordering::Relaxed);
24 }
25
26 pub fn fetch_add(&self, val: u64) -> u64 {
27 self.0.fetch_add(val, Ordering::Relaxed)
28 }
29
30 pub fn fetch_sub(&self, val: u64) -> u64 {
31 self.0.fetch_sub(val, Ordering::Relaxed)
32 }
33}
34
35#[derive(Debug, Clone, Default)]
37pub struct VADStats {
38 pub frames_processed: u64,
39 pub speech_frames: u64,
40 pub silence_frames: u64,
41}
42
43impl VADStats {
44 pub fn new() -> Self {
45 Self::default()
46 }
47
48 pub fn speech_ratio(&self) -> f64 {
49 if self.frames_processed == 0 {
50 return 0.0;
51 }
52 self.speech_frames as f64 / self.frames_processed as f64
53 }
54}