#[derive(Clone)]
pub struct Audio {
hz: u16,
samples: Vec<u16>,
}
impl Audio {
pub fn new(hz: u16, samples: Vec<u16>) -> Audio {
Audio { hz, samples }
}
pub fn sample(&self, index: usize) -> u16 {
self.samples[index]
}
pub fn index(&self, seconds: f32) -> usize {
(seconds / (self.hz as f32)) as usize
}
}