29 lines
698 B
Rust
29 lines
698 B
Rust
use crossbeam::atomic::AtomicCell;
|
|
use std::sync::Arc;
|
|
|
|
#[derive(Default)]
|
|
pub struct AudioProcessor {
|
|
df: Option<::df::DFState>,
|
|
}
|
|
|
|
impl AudioProcessor {
|
|
pub fn new_denoising() -> Self {
|
|
let df = ::df::DFState::default();
|
|
AudioProcessor { df: Some(df) }
|
|
}
|
|
}
|
|
|
|
impl AudioProcessor {
|
|
pub fn process(&mut self, audio: &[f32]) -> Box<[f32]> {
|
|
let mut output: Box<[f32]> = vec![0f32; audio.len()].into();
|
|
if let Some(df) = &mut self.df {
|
|
df.process_frame(audio, &mut output);
|
|
} else {
|
|
output.copy_from_slice(audio);
|
|
}
|
|
output
|
|
}
|
|
}
|
|
|
|
pub type AudioProcessorSender = Arc<AtomicCell<Option<AudioProcessor>>>;
|