1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/// A forever stream of samples of value 0 (creating no sound).
pub struct Silence {
    channel_count: u16,
    sample_rate: u32,
}

impl Silence {
    /// Create a new sound that will return 0 samples forever and
    /// return the specified channel count and sample rate from
    /// their respective methods.
    pub fn new(channel_count: u16, sample_rate: u32) -> Silence {
        Silence {
            channel_count,
            sample_rate,
        }
    }
}

impl crate::Sound for Silence {
    fn channel_count(&self) -> u16 {
        self.channel_count
    }

    fn sample_rate(&self) -> u32 {
        self.sample_rate
    }

    fn next_sample(&mut self) -> Result<crate::NextSample, crate::Error> {
        Ok(crate::NextSample::Sample(0))
    }

    fn on_start_of_batch(&mut self) {}
}