[][src]Struct nnnoiseless::DenoiseState

pub struct DenoiseState<'model> { /* fields omitted */ }

This is the main entry-point into nnnoiseless. It mainly contains the 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

impl DenoiseState<'static>[src]

pub const FRAME_SIZE: usize[src]

A DenoiseState processes this many samples at a time.

pub fn new() -> Box<DenoiseState<'static>>[src]

Creates a new DenoiseState.

pub fn from_model(model: RnnModel) -> Box<DenoiseState<'static>>[src]

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.

impl<'model> DenoiseState<'model>[src]

pub fn with_model(model: &'model RnnModel) -> Box<DenoiseState<'model>>[src]

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 DenoiseStates.

pub fn process_frame(&mut self, output: &mut [f32], input: &[f32]) -> f32[src]

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 f32s, 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

impl<'model> Clone for DenoiseState<'model>[src]

Auto Trait Implementations

impl<'model> !RefUnwindSafe for DenoiseState<'model>[src]

impl<'model> Send for DenoiseState<'model>[src]

impl<'model> Sync for DenoiseState<'model>[src]

impl<'model> Unpin for DenoiseState<'model>[src]

impl<'model> !UnwindSafe for DenoiseState<'model>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<S, T> Duplex<S> for T where
    T: FromSample<S> + ToSample<S>, 

impl<T> From<T> for T[src]

impl<S> FromSample<S> for S

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> ToSample<U> for T where
    U: FromSample<T>, 

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.