flesh out synthesizer module
This commit is contained in:
parent
96e26ce493
commit
9417e6edbf
3 changed files with 44 additions and 7 deletions
|
|
@ -1,7 +1,8 @@
|
|||
pub trait Wavetable {
|
||||
type OutputType;
|
||||
type OutputType: Default + Copy;
|
||||
/// get next sample
|
||||
fn next(&mut self) -> Self::OutputType;
|
||||
fn size(&self) -> usize;
|
||||
}
|
||||
|
||||
/// non-interpolated, simple wavetable that produces the next sample
|
||||
|
|
@ -13,19 +14,23 @@ pub struct SimpleWavetable<'a, T: Copy> {
|
|||
index: usize,
|
||||
}
|
||||
|
||||
impl<'a, T: Copy> Wavetable for SimpleWavetable<'a, T> {
|
||||
impl<'a, T: Copy + Default> Wavetable for SimpleWavetable<'a, T> {
|
||||
type OutputType = T;
|
||||
fn next(&mut self) -> Self::OutputType {
|
||||
let value = self.table[self.index];
|
||||
self.index += 1;
|
||||
if self.index > self.table.len() {
|
||||
if self.index > self.table.len() - 1 {
|
||||
self.index = 0;
|
||||
}
|
||||
value
|
||||
}
|
||||
|
||||
fn size(&self) -> usize {
|
||||
self.table.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Copy> SimpleWavetable<'a, T> {
|
||||
impl<'a, T: Copy + Default> SimpleWavetable<'a, T> {
|
||||
pub fn new(table: &'a [T]) -> Self {
|
||||
Self { table, index: 0 }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue