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
34
35
36
37
38
39
40
41
42
43
44
45
//! # WAV
//! 
//! A wave data player.

use super::*;
use crate::utils::mono_resampler::*;

/// Struct for playing wave files.
#[derive(Clone)]
pub struct MonoWav {
    resam: MonoResampler,
}

impl MonoWav {
    /// Constructs from a given path.
    pub fn from_source(s: &mut dyn std::io::Read) -> Self {
        let (h, t) = utils::read_wav(s)
        .expect("File could not be read");

        MonoWav::from_track(h.sampling_rate as MathT, t.first().expect("No audio data read").clone())
    }

    /// Converts from the given track and source sample rate.
    pub fn from_track(sampling_rate: MathT, t: TrackT) -> Self {
        MonoWav{
            resam: MonoResampler::new(t, sampling_rate, 0, 0)
        }
    }

    /// Borrows the resampler object.
    pub fn get(&self) -> &MonoResampler {
        &self.resam
    }

    /// Mutably borrows the resampler object.
    pub fn get_mut(&mut self) -> &mut MonoResampler {
        &mut self.resam
    }
}

impl Generator for MonoWav {
    fn process(&mut self) -> SampleT {
        self.resam.process()
    }
}