Skip to main content

Module wav

Module wav 

Source
Expand description

WAV audio container support. WAV reader and writer with KotOR obfuscation handling.

KotOR uses multiple wrappers around audio payloads:

  • standard RIFF/WAVE files,
  • SFX files with a 470-byte prefix header,
  • MP3-in-WAV wrappers (58-byte prefix followed by raw MP3 data).

This module implements container-level parsing/serialization only. It does not decode PCM/ADPCM sample streams.

§Telling the three apart

A .wav here is one of three things wearing the same extension, and the discriminators are not alike. An SFX file is caught by magic: it has no RIFF at the start, just the fixed prefix FF F3 60 C4, with the real payload 470 bytes in.

The MP3 wrapper is the one to be careful with, because it does start with RIFF and passes a naive signature check. What exposes it is arithmetic: its header declares a RIFF size of 50, so riff_size + 8 lands at byte 58 with the rest of the file beyond it. Trusting the tag and stopping there yields 58 bytes of wrapper and treats the actual audio as padding.

Byte-level offsets for all three live in docs/src/formats/audio/wav.md, with the engine’s own dispatch sequence.

Modules§

adpcm
ADPCM decoding helpers for WAV data.
pcm
PCM decoding helpers for WAV data.

Structs§

Wav
In-memory WAV payload.
WavEncodingCode
Lossless WAVE encoding tag wrapper.
WavWaveMetadata
Metadata fields for WAVE-format payloads.
WavWriteOptions
WAV writer options.

Enums§

WavAudioFormat
Audio payload format represented by Wav.
WavEncoding
Known WAVE encoding tags.
WavError
WAV parse/write errors.
WavType
KotOR-facing wrapper type used when writing.
WavWrapperKind
WAV wrapper variant detected in source bytes.
WavWriteMode
WAV write target mode.

Functions§

read_wav
Reads WAV data from a reader.
read_wav_from_bytes
Reads WAV data from bytes.
write_wav
Writes WAV data to a writer using WavWriteMode::Game.
write_wav_to_vec
Serializes WAV data to a byte vector using WavWriteMode::Game.
write_wav_to_vec_with_options
Serializes WAV data to a byte vector with explicit options.
write_wav_with_options
Writes WAV data to a writer with explicit options.