1use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
6
7use crate::ring::SpscRing;
8
9pub struct ShareInput {
10 ring: SpscRing,
11 rate: AtomicU32,
12 channels: AtomicU32,
13 pub active: AtomicBool,
14}
15
16impl Default for ShareInput {
17 fn default() -> Self {
18 Self::new()
19 }
20}
21
22impl ShareInput {
23 pub fn new() -> Self {
24 Self {
25 ring: SpscRing::new(192_000),
27 rate: AtomicU32::new(48_000),
28 channels: AtomicU32::new(2),
29 active: AtomicBool::new(false),
30 }
31 }
32
33 pub fn push(&self, rate: u32, channels: u8, samples: &[f32]) {
34 self.rate.store(rate, Ordering::Relaxed);
35 self.channels.store(channels as u32, Ordering::Relaxed);
36 self.ring.push(samples);
37 }
38
39 pub fn ring(&self) -> &SpscRing {
40 &self.ring
41 }
42
43 pub fn rate(&self) -> u32 {
44 self.rate.load(Ordering::Relaxed)
45 }
46
47 pub fn channels(&self) -> u32 {
48 self.channels.load(Ordering::Relaxed)
49 }
50}