Treatment resampleMono

audio/transform::resampleMono


Parameters

↳ var to_rate: u32

Inputs

⇥ info: Block<AudioInfo> (audio/audio_info::AudioInfo)
⇥ signal: Stream<f32>

Outputs

↦ resampled: Stream<f32>


Resample a normalised mono f32 signal from one sample rate to another.

Samples arrive through signal and are emitted through resampled at to_rate samples per second. The source rate is read from info, which is the AudioInfo block produced by decodeMono or recordMono. The amplitude range [-1.0, 1.0] is preserved.

When the source rate already equals to_rate the samples are forwarded unchanged.

Resampling is performed with linear interpolation. This is suitable for voice processing, ML feature extraction, and similar tasks. For applications that require higher spectral fidelity (e.g. professional audio mastering) a sinc-interpolating resampler such as rubato would be preferable.

resampled closes as soon as signal closes, after all pending output samples have been emitted. If info never arrives (e.g. decoding failed before any audio was probed) resampled closes immediately without emitting any samples.

graph LR
     T("resampleMono()")
     S["−0.3 … 0.7"] -->|signal| T
     I["AudioInfo"] -->|info| T
     T -->|resampled| R["−0.3 … 0.7 @ 16000 Hz"]

     style S fill:#ffff,stroke:#ffff
     style I fill:#ffff,stroke:#ffff
     style R fill:#ffff,stroke:#ffff
use audio/decode::decodeMono
use audio/transform::resampleMono
use fs/local::readLocal
use std/engine/util::startup

treatment toMl()
  output signal: Stream<f32>
{
    startup()
    readLocal(path="speech.wav")
    decodeMono(hint="wav")
    resampleMono(to_rate=16000)

    startup.trigger -> readLocal.trigger,data -> decodeMono.data
    decodeMono.signal -> resampleMono.signal,resampled -> Self.signal
    decodeMono.info --> resampleMono.info
}