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 (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§

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
Which of the engine’s three forms a .wav file takes. See classify_wav.
WavWriteMode
WAV write target mode.

Constants§

WAV_CLASSIFY_LEN
How many leading bytes classify_wav reads: through the RIFF a prefixed file carries at 0x1D6.

Functions§

classify_wav
Which of the engine’s three forms a .wav file 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.