initial commit of dac files

This commit is contained in:
sigil-03 2025-07-27 14:58:02 -06:00
parent d06329a725
commit 8502ed75bf
6 changed files with 54 additions and 0 deletions

33
src/dac.rs Normal file
View file

@ -0,0 +1,33 @@
use crate::interface::DacInterface;
pub struct Dac<'a, T: DacInterface> {
output: T,
data: Option<&'a [u8]>,
index: usize,
}
impl<'a, T: DacInterface> Dac<'a, T> {
pub fn new(output: T) -> Self {
Self {
output,
data: None,
index: 0,
}
}
pub fn load_data(&mut self, data: &'a [u8]) {
self.data = Some(data);
}
pub fn seek_to_sample(&mut self, index: usize) {
self.index = index;
}
pub fn output_next(&mut self) {
if let Some(data) = self.data {
self.index = self.index + 1;
// reset the index to 0 if we roll over
if (self.index >= data.len()) {
self.index = 0;
}
self.output.write_amplitude(data[self.index]);
// self.output.write_amplitude(100);
}
}
}