BFWAV (File Format)

From MK8
Jump to navigation Jump to search

BFWAV (Binary caFe WAVe) is common file format for storing sound. The format is structured similarly to WAV, where there is one info section ("fmt " in WAV, "INFO" in BFWAV) and one data section ("data" in WAV, "DATA" in BFWAV). The file consists of a header and two sections, INFO and DATA. All offsets in the file may be 0xFFFFFFFF if it links to nothing.

File Format

Header

The file starts with a header as follows:

Offset Type Description
0x00 String File magic. Always FWAV in ASCII.
0x04 UInt16 Byte Order Mark (BOM): 0xFEFF for big endian and 0xFFFE for little endian.
0x06 UInt16 Header size. Always 0x40 due to alignment.
0x08 UInt32 Version number of the file format.
0x0C UInt32 File size in bytes.
0x10 UInt16 Number of sections. Always 2.
0x12 UInt16 Padding.
0x14 UInt16 INFO section flag. Always 0x7000.
0x16 UInt16 Padding.
0x18 UInt32 INFO offset.
0x1C UInt32 INFO size in bytes.
0x20 UInt16 DATA section flag. Always 0x7001.
0x22 UInt16 Padding.
0x24 UInt32 DATA offset.
0x28 UInt32 DATA size in bytes.
0x2C Byte[0x14] Padding to align the data.
0x40 End of header

INFO

The INFO section contains general information about the sound.

Offset Type Description
0x00 String Section magic. Always INFO in ASCII.
0x04 UInt32 Section size in bytes.
0x08 Byte Sound encoding. 0 = PCM8, 1 = PCM16, 2 = DSP ADPCM, 3 = IMA ADPCM.
0x09 Byte Loop. 0 = no loop, 1 = loop.
0x0A UInt16 Padding.
0x0C UInt32 Sample rate.
0x10 UInt32 Loop start in frames. 0 if not looping.
0x14 UInt32 Loop end in frames. 0 if not looping.
0x18 UInt32 Original loop start frame. 0 if not looping.

Then follows a reference table which points to the channel infos. The section flag is 0x7100.

Channel Info

The Channel Info section contains an offset to the data and may contain ADPCM information. Each entry has the following structure:

Offset Type Description
0x00 UInt16 Sound data offset flag. Always 0x1F00.
0x02 UInt16 Padding.
0x04 Int32 Sound data offset, relative to 0x08 into the DATA section.
0x08 UInt16 ADPCM info flag. Always 0x0300.
0x0A UInt16 Padding.
0x0C Int32 ADPCM info offset, relative to the start of this structure.
0x10 UInt32 Reserved.

ADPCM Info

Offset Type Description
0x00 UInt16[8][2] 16-bit Coefficients.
0x20 UInt16 Pred scale.
0x22 UInt16 Yn 1.
0x24 UInt16 Yn 2.
0x26 UInt16 Loop Pred Scale.
0x28 UInt16 Loop Yn 1.
0x2A UInt16 Loop Yn 2.
0x2C UInt16 Padding.

DATA

The DATA section contains all the sound data.

Offset Type Description
0x00 String Section magic. Always DATA in ASCII.
0x04 UInt32 S = Section size in bytes.
0x08 Byte[S] Sound data.

Reference Table

A reference table is used to reference multiple structures. It has the following structure:

Offset Type Description
0x00 UInt32 Number of references.

The following structure follows. The amount is specified above.

Offset Type Description
0x00 UInt16 Section flag, to identify what structure it links to.
0x02 UInt16 Padding.
0x04 Int32 Offset to a structure, relative to the start of the header structure.

Tools

The following tools can handle BFWAV files: