Struct nnnoiseless::DenoiseState[][src]

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

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

A DenoiseState processes this many samples at a time.

Creates a new DenoiseState.

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.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.