Bit Rate Reduced
The SPC-700 is a custom Sony audio coprocessor used inside the Super Nintendo Entertainment System. The SPC-700 has its own instruction set and memory space and runs programs uploaded by the main SNES CPU. The SPC-700 manages 8 independent audio channels that play samples from somewhere in the memory space. These channels only play samples that are encoded in a format called bit rate reduced (BRR).
BRR coding offers close to 4:1 compression. Technically, the ratio is 32:9 as blocks of 16 16-bit samples are packed into 16 4-bit nibbles with a 1-byte preamble for the whole block. Thus, each block is 9 bytes long. The preamble byte has the following bit definitions:
bits 7-4 range bits bits 3-2 filter definition bit 1 loop bit bit 0 end bit
If the end bit is set, this block is the last of the series of blocks. The loop bit is set in each constituent block of a sample that loops. The filter definition bits allow the sample to be filtered in a variety of ways. For more information on the filter types, consult "The Bit Rate Reduction Sound Encoding Scheme" at http://sgc.jandar.net/files/docs/brr.txt.
Each of the bytes in the block from offset 1..8 are decoded top nibble first (bits 7-4), then bottom nibble. In order to expand a nibble, shift the sample left by the number of bits specified by the range. Note that the nibble is encoded as a two's complement signed number and must be sign-extended before the shift. Also note that range values from 12..15 would shift some or all of the coded nibble bits out of the final sample and are thus invalid.