Simple 2FSK
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use std::f64::consts::PI;
|
||||
use std::{f64::consts::PI, ops::Neg};
|
||||
|
||||
use crate::map;
|
||||
|
||||
@ -15,7 +15,7 @@ impl DigitalFrequency
|
||||
{
|
||||
// Frequnecy wraps arround : Going at 2 pi radians per second
|
||||
// Is like not oscillating at all
|
||||
let f = radians_per_sample.rem_euclid(radians_per_sample);
|
||||
let f = radians_per_sample.rem_euclid(2. * PI);
|
||||
|
||||
// Then we map the [0, 2*PI] range into the 0 to usize range
|
||||
DigitalFrequency(map(f, 0., 2. * PI, 0., usize::MAX as f64).floor() as usize)
|
||||
@ -36,3 +36,13 @@ impl DigitalFrequency
|
||||
map(self.0 as f64, 0., usize::MAX as f64, 0., sample_rate)
|
||||
}
|
||||
}
|
||||
|
||||
impl Neg for DigitalFrequency
|
||||
{
|
||||
type Output = Self;
|
||||
|
||||
fn neg(self) -> Self::Output
|
||||
{
|
||||
DigitalFrequency(usize::MAX - self.0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user