use std::f32;
pub trait Pulse {
fn pulse_half_linear(&self, rate_spr: f32) -> f32;
fn pulse_full_linear(&self, rate_spr: f32) -> f32;
fn pulse_full_smooth(&self, rate_spr: f32) -> f32;
fn pulse_half_smooth(&self, rate_spr: f32) -> f32;
}
impl Pulse for f32 {
fn pulse_half_linear(&self, rate_spr: f32) -> f32 {
(self % rate_spr) / rate_spr
}
fn pulse_full_linear(&self, rate_spr: f32) -> f32 {
let rtn = (self % rate_spr) / (rate_spr / 2.0);
if rtn > 1.0 {
2.0 - rtn
}else{
rtn
}
}
fn pulse_full_smooth(&self, rate_spr: f32) -> f32 {
1.0 - (((self.pulse_full_linear(rate_spr) * f32::consts::PI)
.cos() + 1.0) / 2.0)
}
fn pulse_half_smooth(&self, rate_spr: f32) -> f32 {
1.0 - (((self.pulse_half_linear(rate_spr) * f32::consts::PI)
.cos() + 1.0) / 2.0)
}
}