Skip to content
Snippets Groups Projects
Commit f56b7a67 authored by Stephen D's avatar Stephen D
Browse files

replace i16 with f32

parent bcbab5ed
No related branches found
No related tags found
No related merge requests found
......@@ -46,15 +46,15 @@ impl Parameters {
}
}
pub fn mag(self, samples: &[i16]) -> f32 {
pub fn mag(self, samples: &[f32]) -> f32 {
self.start().add_samples(samples).finish_mag()
}
}
impl Partial {
pub fn add_samples(mut self, samples: &[i16]) -> Self {
pub fn add_samples(mut self, samples: &[f32]) -> Self {
for &sample in samples {
let this = self.params.term_coefficient * self.prev - self.prevprev + (sample as f32);
let this = self.params.term_coefficient * self.prev - self.prevprev + sample;
self.prevprev = self.prev;
self.prev = this;
}
......@@ -77,11 +77,11 @@ impl Partial {
#[test]
fn zero_data() {
let p = Parameters::new(1800., 8000, 256);
assert!(p.start().add_samples(&[0; 256]).finish_mag() == 0.);
assert!(p.start().add_samples(&[0.0; 256]).finish_mag() == 0.);
assert!(
p.start()
.add_samples(&[0; 128])
.add_samples(&[0; 128])
.add_samples(&[0.0; 128])
.add_samples(&[0.0; 128])
.finish_mag()
== 0.
);
......@@ -89,13 +89,13 @@ fn zero_data() {
#[test]
fn sine() {
let mut buf = [0; 8000];
let mut buf = [0.0; 8000];
for &freq in [697., 1200., 1800., 1633.].iter() {
// Generate a 1 second sine wave at freq hz
let step = 1. / 8000.;
for (i, v) in buf.iter_mut().enumerate() {
let time = i as f32 * step;
*v = ((time * freq * PI * 2.).sin() * std::i16::MAX as f32) as i16;
*v = (time * freq * PI * 2.).sin();
}
let p = Parameters::new(freq, 8000, 8000);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment