Struct nnnoiseless::DenoiseState
source · pub struct DenoiseState<'model> { /* private fields */ }
Expand description
This is the low-level entry-point into nnnoiseless
: by using the DenoiseState
directly,
you can denoise your audio while keeping copying to a minimum. For a higher-level
denoising experience, try DenoiseSignal
.
This struct directly contains various memory buffers that are used while denoising. As such, this is quite a large struct, and should probably be kept behind some kind of pointer.
Example
// One second of 440Hz sine wave at 48kHz sample rate. Note that the input data consists of
// `f32`s, but the values should be in the range of an `i16`.
let sine: Vec<_> = (0..48_000)
.map(|x| (x as f32 * 440.0 * 2.0 * std::f32::consts::PI / 48_000.0).sin() * i16::MAX as f32)
.collect();
let mut output = Vec::new();
let mut out_buf = [0.0; DenoiseState::FRAME_SIZE];
let mut denoise = DenoiseState::new();
let mut first = true;
for chunk in sine.chunks_exact(DenoiseState::FRAME_SIZE) {
denoise.process_frame(&mut out_buf[..], chunk);
// We throw away the first output, as discussed in the documentation for
//`DenoiseState::process_frame`.
if !first {
output.extend_from_slice(&out_buf[..]);
}
first = false;
}
Implementations§
source§impl DenoiseState<'static>
impl DenoiseState<'static>
sourcepub const FRAME_SIZE: usize = 480usize
pub const FRAME_SIZE: usize = 480usize
A DenoiseState
processes this many samples at a time.
sourcepub fn new() -> Box<DenoiseState<'static>>
pub fn new() -> Box<DenoiseState<'static>>
Creates a new DenoiseState
.
sourcepub fn from_model(model: RnnModel) -> Box<DenoiseState<'static>>
pub fn from_model(model: RnnModel) -> Box<DenoiseState<'static>>
Creates a new DenoiseState
owning a custom model.
The main difference between this method and DenoiseState::with_model
is that here
DenoiseState
will own the model; this might be more convenient.
source§impl<'model> DenoiseState<'model>
impl<'model> DenoiseState<'model>
sourcepub fn with_model(model: &'model RnnModel) -> Box<DenoiseState<'model>>
pub fn with_model(model: &'model RnnModel) -> Box<DenoiseState<'model>>
Creates a new DenoiseState
using a custom model.
The main difference between this method and DenoiseState::from_model
is that here
DenoiseState
will borrow the model; this might create some lifetime-related pain, but
it means that the same model can be shared between multiple DenoiseState
s.
sourcepub fn process_frame(&mut self, output: &mut [f32], input: &[f32]) -> f32
pub fn process_frame(&mut self, output: &mut [f32], input: &[f32]) -> f32
Processes a chunk of samples.
Both output
and input
should be slices of length DenoiseState::FRAME_SIZE
, and they
are assumed to be in 16-bit, 48kHz signed PCM format. Note that although the input and
output are f32
s, they are supposed to come from 16-bit integers. In particular, they
should be in the range [-32768.0, 32767.0]
instead of the range [-1.0, 1.0]
which
is more common for floating-point PCM.
The current output of process_frame
depends on the current input, but also on the
preceding inputs. Because of this, you might prefer to discard the very first output; it
will contain some fade-in artifacts.
Trait Implementations§
source§impl<'model> Clone for DenoiseState<'model>
impl<'model> Clone for DenoiseState<'model>
source§fn clone(&self) -> DenoiseState<'model>
fn clone(&self) -> DenoiseState<'model>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more