processing: use faster unsafe truncate

This commit is contained in:
Robert Jördens 2020-11-24 09:27:47 +01:00
parent 769cfdfb7f
commit b0e0b5144f
1 changed files with 10 additions and 2 deletions

View File

@ -779,7 +779,11 @@ const APP: () = {
let x0 = f32::from(a as i16);
let y0 =
c.resources.iir_ch[1].update(&mut c.resources.iir_state[1], x0);
y0 as i16 as u16 ^ 0x8000
// note(unsafe): The filter limits ensure that the value is in range.
// The truncation introduces 1/2 LSB distortion.
let y0 = unsafe { y0.to_int_unchecked::<i16>() };
// convert to DAC code
y0 as u16 ^ 0x8000
};
c.resources.dac1.send(output).unwrap();
@ -792,7 +796,11 @@ const APP: () = {
let x0 = f32::from(a as i16);
let y0 =
c.resources.iir_ch[0].update(&mut c.resources.iir_state[0], x0);
y0 as i16 as u16 ^ 0x8000
// note(unsafe): The filter limits ensure that the value is in range.
// The truncation introduces 1/2 LSB distortion.
let y0 = unsafe { y0.to_int_unchecked::<i16>() };
// convert to DAC code
y0 as u16 ^ 0x8000
};
c.resources.dac0.send(output).unwrap();