Skip to content

Commit

Permalink
Linear reading.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamiPerttu committed May 3, 2024
1 parent c2ffcc4 commit 9d44466
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,18 @@ impl AtomicTable {
let i3 = (i1 + 2) & mask;
super::math::spline(self.at(i0), self.at(i1), self.at(i2), self.at(i3), w)
}
/// Read linear interpolated value at the given `phase` (in 0...1).
#[inline]
pub fn read_linear(&self, phase: f32) -> f32 {
let p = self.table.len() as f32 * phase;
// Safety: we know phase is in 0...1.
let i0 = unsafe { f32::to_int_unchecked::<usize>(p) };
let w = p - i0 as f32;
let mask = self.table.len() - 1;
let i0 = i0 & mask;
let i1 = (i0 + 1) & mask;
super::math::lerp(self.at(i0), self.at(i1), w)
}
/// Read nearest value at the given `phase` (in 0...1).
#[inline]
pub fn read_nearest(&self, phase: f32) -> f32 {
Expand All @@ -350,7 +362,6 @@ impl AtomicTable {
let mask = self.table.len() - 1;
self.at(i & mask)
}

}

/// Wavetable oscillator with cubic interpolation that reads from an atomic wavetable.
Expand Down

0 comments on commit 9d44466

Please sign in to comment.