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 (a RIFF chunk ending short of the file, then raw MP3).
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 none
of them is told apart by a signature. An SFX file is caught by position: it
has no RIFF at the start and a RIFF at byte 470, where its real payload
begins.
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:
riff_size + 8 falls short of the file’s length, and the MP3 starts there.
Trusting the tag and stopping yields an empty WAVE and treats the actual
audio as padding. classify_wav applies both tests.
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 - Which of the engine’s three forms a
.wavfile takes. Seeclassify_wav. - WavWrite
Mode - WAV write target mode.
Constants§
- WAV_
CLASSIFY_ LEN - How many leading bytes
classify_wavreads: through theRIFFa prefixed file carries at0x1D6.
Functions§
- classify_
wav - Which of the engine’s three forms a
.wavfile takes. - 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.