Skip to main content

WaveNetModel

Struct WaveNetModel 

Source
pub struct WaveNetModel<const CH: usize, const K: usize, const HEAD: usize> {
    pub array1: WaveNetLayerArray<1, 1, CH, K, HEAD>,
    pub array2: WaveNetLayerArray<CH, 1, HEAD, K, 1>,
    pub head_scale: f32,
    pub receptive_field_size: usize,
    pub prewarm_on_reset: bool,
}
Expand description

Complete WaveNet Model containing Two Heterogeneous Layer Array Blocks.

Scientific Reference: van den Oord, A., et al. (2016). “WaveNet: A Generative Model for Raw Audio.” DeepMind.

CH = Array1 channels (layer 0 of the JSON, e.g., 16 for Standard) K = kernel size (always 3) HEAD = Array1 head_size = Array2 channels (e.g., 8 for Standard)

Array2 uses HEAD channels and projects to 1 output (HEAD2=1), following the C++ pattern: WaveNetLayerArrayT<CH, 1, 1, HEAD, K, Dilations, true>.

Fields§

§array1: WaveNetLayerArray<1, 1, CH, K, HEAD>

Inner array 01: IN=1, COND=1, CH channels, HEAD outputs, no HeadBias.

§array2: WaveNetLayerArray<CH, 1, HEAD, K, 1>

Inner array 02: IN=CH, COND=1, HEAD channels, 1 output, with HeadBias.

§head_scale: f32

Final voltage compensation scale (Target Output Scale).

§receptive_field_size: usize

Largest circular buffer required at the Kernel’s temporal root.

§prewarm_on_reset: bool

Whether to execute prewarm during reset(). Default: true.

Implementations§

Source§

impl<const CH: usize, const K: usize, const HEAD: usize> WaveNetModel<CH, K, HEAD>

Source

pub fn set_effective_layers(&mut self, n: usize)

Sets the effective number of layers on both arrays for soft-degrade.

Source

pub fn backup_buffer_starts(&self, starts: &mut [usize], offset: &mut usize)

Backs up the buffer_start pointers of both layer arrays into a slice.

Source

pub fn restore_buffer_starts(&mut self, starts: &[usize], offset: &mut usize)

Restores the buffer_start pointers of both layer arrays from a slice.

Source

pub fn process(&mut self, input: &[f32], output: &mut [f32])

Resolves the full forward pass and produces waveform samples in zero allocation (DSP).

Combines the outputs of both arrays: sum(head1) + sum(head2) × head_scale.

For Scientists and Devs: The dispatch_simd! macro monomorphizes this function via the SimdMath trait, matching the global hardware configuration once at the call site. The compiler generates branchless assembly optimized for your processor (AVX2, AVX-512, or AVX-512 VNNI BF16) without v-table or dynamic dispatch overhead.

Source

pub fn prewarm(&mut self)

Stabilizes the model by processing silence (Zero Input) for pre-warm.

Dispatches via dispatch_simd! macro — a single static match on the globally detected SIMD_MATH.instruction_set — to run the AVX2, AVX-512, or AVX-512 VNNI BF16 kernel without runtime feature detection per call.

Source

pub unsafe fn prewarm_avx512(&mut self)

Prewarm strictly optimized for AVX-512 architecture.

§Safety

Requires a supported processor (AVX-512).

Source

pub unsafe fn prewarm_avx2(&mut self)

Prewarm strictly optimized for AVX2 architecture.

§Safety

Requires an x86-64-v3 (AVX2) processor.

Trait Implementations§

Source§

impl<const CH: usize, const K: usize, const HEAD: usize> NamModel for WaveNetModel<CH, K, HEAD>

Source§

fn process(&mut self, input: &[f32], output: &mut [f32])

Invoked by the DSP RT-Thread to process acoustic sample blocks (Float32).
Source§

fn prewarm(&mut self, _num_samples: usize)

“Heats up” the virtual tubes of the neural engine (prewarm).
Source§

fn prewarm_samples(&self) -> usize

Returns the number of samples needed to fully stabilize the model’s internal state (receptive field / recurrent memory depth). Read more
Source§

fn prewarm_on_reset(&self) -> bool

Returns whether prewarm should be executed on reset(). Read more
Source§

fn set_prewarm_on_reset(&mut self, val: bool)

Sets whether prewarm should be executed on reset(). Read more
Source§

fn reset(&mut self, _sample_rate: u32, max_buffer_size: usize) -> Result<()>

Resets the model’s internal state with a new sample rate and max buffer size. Read more
Source§

fn set_max_buffer_size(&mut self, _max_buf: usize) -> Result<()>

Reallocates internal buffers to support the given maximum block size. Read more
Source§

fn slimmable_breakpoints(&self) -> Vec<f64>

Returns the breakpoints at which slimmable quality transitions occur. Read more

Auto Trait Implementations§

§

impl<const CH: usize, const K: usize, const HEAD: usize> Freeze for WaveNetModel<CH, K, HEAD>

§

impl<const CH: usize, const K: usize, const HEAD: usize> RefUnwindSafe for WaveNetModel<CH, K, HEAD>

§

impl<const CH: usize, const K: usize, const HEAD: usize> Send for WaveNetModel<CH, K, HEAD>

§

impl<const CH: usize, const K: usize, const HEAD: usize> Sync for WaveNetModel<CH, K, HEAD>

§

impl<const CH: usize, const K: usize, const HEAD: usize> Unpin for WaveNetModel<CH, K, HEAD>

§

impl<const CH: usize, const K: usize, const HEAD: usize> UnsafeUnpin for WaveNetModel<CH, K, HEAD>

§

impl<const CH: usize, const K: usize, const HEAD: usize> UnwindSafe for WaveNetModel<CH, K, HEAD>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.