diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 8aec593..7d052bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,16 +103,15 @@ impl DDS { let mut out_i = Vec::with_capacity(len); let mut out_q = Vec::with_capacity(len); for _ in 0..len { - let phase = self.phase as i32; // get current carrier phase, add phase mod, calculate table index - let phase_idx_i = (phase - self.phase_delta) >> TRIG_TABLE_SHIFT; - let phase_idx_q = (phase + self.phase_delta) >> TRIG_TABLE_SHIFT; + let phase_idx_i = self.phase.overflowing_sub(self.phase_delta as u32).0 >> TRIG_TABLE_SHIFT; + let phase_idx_q = self.phase.overflowing_add(self.phase_delta as u32).0 >> TRIG_TABLE_SHIFT; if phase_idx_q > 255 || phase_idx_i > 255 { panic!("Phase IDX out of bounds"); } - self.phase = phase as u32 + self.phase_step; + self.phase = self.phase.overflowing_add(self.phase_step).0; let amp = (self.amplitude * 32767.0) as i32; // 0..15 let amp_i = amp * self.trig_table_inphase[phase_idx_i as usize] as i32; // 0..31 @@ -295,7 +294,6 @@ fn main() { } let pdslope = slope * modulation_index * INT32_MAX_AS_FLOAT; - println!("Samp = {}, Slope {} = {} * {} * {}", sample, pdslope, slope, modulation_index, INT32_MAX_AS_FLOAT); if pdslope < MIN_VAL || pdslope > MAX_VAL { panic!("pdslope out of bounds {}", pdslope); } |