Skip to main content

Module mel

Module mel 

Source
Expand description

Mel-filterbank apply as a certified forge kernel.

Projects a row-major power spectrum (n_frames × n_bins) onto a triangular mel filterbank (n_mel × n_bins), producing mel energies (n_frames × n_mel). The operation is the matrix contraction mel_out[f, m] = Σ_b spectrum[f, b] · mel_fb[m, b].

Embeds shaders/audio_mel.wgsl via include_str! (single source of truth), grades it against the exact CPU oracle mel_apply_cpu, and runs it on the auxiliary GPU circuit via mel_apply_forge. The public entry point mel_apply prefers the GPU when one is present and otherwise uses the CPU floor, so the call is never broken.

Circuit placement: the forge kernel runs on the auxiliary circuit (the iGPU when present) so the primary/discrete GPU stays free for the LLM. Device selection goes through crate::gpu_context::device_registry::try_auxiliary_gpu, which falls back auxiliary → primary → None; on None the forge path returns ForgeError::GpuUnavailable and mel_apply drops to the CPU floor — i.e. the effective placement chain is auxiliary → primary → CPU.

Constants§

MEL_APPLY_ENTRY
Entry-point name of MEL_APPLY_WGSL.
MEL_APPLY_WGSL
The mel-apply kernel source (embedded from the canonical .wgsl).

Functions§

mel_apply
Public entry point: run the mel-filterbank apply on the best path available on this machine. If a wgpu adapter is present (caps().wgpu), try mel_apply_forge and return its result on success; otherwise (no adapter, or a runtime GPU failure) fall back to the exact CPU oracle mel_apply_cpu, so the call is never broken.
mel_apply_cpu
Exact CPU oracle for the mel-filterbank apply. Mirrors the WGSL scalar-for-scalar: for each output element (frame, m), accumulates spectrum[frame, b] · mel_fb[m, b] over b in increasing order. spectrum is row-major n_frames × n_bins, mel_fb is row-major n_mel × n_bins; the result is row-major n_frames × n_mel.
mel_apply_forge
Run the mel-filterbank apply on the GPU and read back the result. Runs on the auxiliary GPU circuit (the iGPU when present) to keep the primary/discrete GPU free for the LLM: the device is taken from crate::gpu_context::device_registry::try_auxiliary_gpu (falls back auxiliary → primary → None) and the compute context is built with [WgpuComputeContext::from_device] on that shared device, rather than requesting its own HighPerformance adapter.