GizStack
View .mdOpen in ChatGPTOpen in Claude

gizai/video/wav

WAV files and resampling.

gizlang
import * as Wav from "gizai/video/wav";

Types

Wave

gizlang
type Wave = { rate: i64; samples: Tensor; }

Audio samples: channels rows of the same length ([channels, n] f32 on the host) at rate a second.

  • rate: i64
  • samples: _gizlang_lib_ai__tensor__storage.Tensor<f32>

Functions

wav

gizlang
function wav(data: bytes): Wave throws string

The samples of a WAV file (RIFF WAVE: PCM of 8, 16, 24 or 32 bits, or IEEE floats of 32 or 64 bits, also in WAVE_FORMAT_EXTENSIBLE), as floats in [-1, 1) the way libsndfile reads them (a signed integer over 2^(bits - 1); 8 bits are unsigned around 128).

Effects: fail, alloc.

wavFile

gizlang
function wavFile(samples: Vec<f32>, rate: i64, channels: i64 = 1): bytes

A WAV file of 16-bit PCM of samples at rate (channels interleaved; mono by default), as libsndfile writes floats: x 32767 rounded, clipped.

Effects: fail, alloc.

resampled

gizlang
function resampled(wave: Wave, to: i64): Wave

wave at rate to, as torchaudio's resample makes it (a windowed sinc of 6 zero crossings, Hann window, rolloff 0.99): each channel padded with zeros, then each output phase the filter of its offset.

Effects: fail, read, write, console, io, alloc.