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§
Structs§
- Wav
- In-memory WAV payload.
- WavEncoding
Code - Lossless WAVE encoding tag wrapper.
- WavWave
Metadata - Metadata fields for WAVE-format payloads.
- WavWrite
Options - WAV writer options.
Enums§
- WavAudio
Format - Audio payload format represented by
Wav. - WavEncoding
- Known WAVE encoding tags.
- WavError
- WAV parse/write errors.
- WavType
- KotOR-facing wrapper type used when writing.
- WavWrapper
Kind - WAV wrapper variant detected in source bytes.
- WavWrite
Mode - 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.