40 lines
1.0 KiB
Rust
40 lines
1.0 KiB
Rust
use ringbuf::{Consumer, Producer};
|
|
|
|
use utils::buffers::*;
|
|
use utils::pitch::*;
|
|
|
|
use crate::BUFFER_LEN;
|
|
|
|
pub struct ProcessorInput {
|
|
pub(crate) buffers: Buffers<BUFFER_LEN>,
|
|
pub(crate) sample_rate: u32,
|
|
}
|
|
|
|
pub struct ProcessorOutput {
|
|
pub(crate) buffers: Buffers<BUFFER_LEN>,
|
|
pub(crate) pitch_l: Option<f32>,
|
|
pub(crate) pitch_r: Option<f32>,
|
|
}
|
|
|
|
pub fn tuna(mut inputs: Consumer<ProcessorInput>, mut outputs: Producer<ProcessorOutput>) {
|
|
let mut detector_l = generate_pitch_detector(BUFFER_LEN);
|
|
let mut detector_r = generate_pitch_detector(BUFFER_LEN);
|
|
|
|
loop {
|
|
if let Some(ProcessorInput {
|
|
buffers,
|
|
sample_rate,
|
|
}) = inputs.pop()
|
|
{
|
|
let pitch_l = pitch_detect(&mut detector_l, &buffers.l, sample_rate).map(|a| a.0);
|
|
let pitch_r = pitch_detect(&mut detector_r, &buffers.r, sample_rate).map(|a| a.0);
|
|
|
|
let _ = outputs.push(ProcessorOutput {
|
|
buffers,
|
|
pitch_l,
|
|
pitch_r,
|
|
});
|
|
}
|
|
}
|
|
}
|