Modules

Wav_File

moduleSource

Available on macOS, Linux, Windows, Wasm

#import "Wav_File";

Procedures#

(file_data: string) -> (format: Waveformatex, samples: string, success: bool = false, extra: Wave_Extra_Info)

Reads the format and sample data out of a WAV file held in memory. samples points into file_data; nothing is copied. success is false when the file is not a RIFF/WAVE with a readable fmt and data chunk in PCM or ADPCM.

bytes: [48] u8 = .[
    82, 73, 70, 70, 40, 0, 0, 0, 87, 65, 86, 69,               // "RIFF", size, "WAVE"
    102, 109, 116, 32, 16, 0, 0, 0, 1, 0, 1, 0,                // "fmt ", PCM, mono
    0x40, 0x1f, 0, 0, 0x40, 0x1f, 0, 0, 1, 0, 8, 0,            // 8000 Hz, 8 bits
    100, 97, 116, 97, 4, 0, 0, 0, 1, 2, 3, 4];                 // "data", 4 samples
file: string = .{48, bytes.data};
format, samples, ok := get_wav_header(file);
assert(ok && format.nChannels == 1 && format.nSamplesPerSec == 8000 && samples.count == 4);
↗

Types#

:: struct

Reads the format and sample data of WAV files held in memory: get_wav_header.

wFormatTag: s16
nChannels: s16
nSamplesPerSec: s32
nAvgBytesPerSec: s32
nBlockAlign: s16
wBitsPerSample: s16
cbSize: s16
:: struct

Extra facts a WAV file can carry for ADPCM data: samples per block, and the sample count the fact chunk claims.

wSamplesPerBlock: s32
wSamplesAccordingToFactChunk: s32

Constants#

:: 0x0001

Waveformatex.wFormatTag values get_wav_header accepts: plain PCM and IMA/DVI ADPCM.