1use crate::{frame::Frame, Mixer, Writer};
2use euphony_dsp::sample::Sample;
3
4#[derive(Debug)]
5pub struct Mono<W: Writer>(W);
6
7impl<W: Writer> Mono<W> {
8 #[inline]
9 pub fn new(w: W) -> Self {
10 Self(w)
11 }
12
13 #[inline]
14 pub fn finish(self) -> W {
15 self.0
16 }
17}
18
19impl<W: Writer> Mixer for Mono<W> {
20 type Error = W::Error;
21
22 #[inline]
23 fn skip(&mut self, frames: usize) -> Result<(), Self::Error> {
24 self.0.skip(frames)
25 }
26
27 #[inline]
28 fn mix(&mut self, samples: &[crate::SpatialSample]) -> Result<(), Self::Error> {
29 let mut sample = 0.0f64;
30 for s in samples.iter() {
31 sample += s.value;
32 }
33 let sample: W::Sample = sample.to_sample();
34 let frame = W::Frame::from_fn(|_| sample);
35 self.0.write(frame)?;
36 Ok(())
37 }
38}