Difference between revisions of "Sound Sample Format (SOUNDS.DAT)"

From WTFwiki
Jump to navigation Jump to search
m (8 revisions)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
''Another copy/paste from ChaosBlackMagic's forum post''
 
 
 
SOUNDS.DAT:
 
SOUNDS.DAT:
  
 
This file contains all the sound effects used by OMF. It is split into a number of blocks, the first of which is a header block describing where in the file each block begins and ends.
 
This file contains all the sound effects used by OMF. It is split into a number of blocks, the first of which is a header block describing where in the file each block begins and ends.
  
Block 0, the header block, is a sequence s of dwords. Block i is stored in the file from offset s to offset s[i+1]-1. The blocks start at the beginning of the file, so the offset of the header block is 0, the first four bytes of the file are 0x00, and next four bytes of the file contain the length of the header block.
+
Block 0, the header block, is a sequence s of dwords. Block '''i''' is stored in the file from offset '''s[i]''' to offset '''s[i+1]-1'''. The blocks start at the beginning of the file, so the offset of the header block is 0, the first four bytes of the file are 0x00, and next four bytes of the file contain the length of the header block. There is one final block which runs from '''s[n]''' to the end of the file.
  
Blocks 1 onwards are sound effects in raw format, with signed 8-bit mono samples. A good typical frequency for playback is 8kHz. OMF has the ability to play these sounds back at other rates, in order to apply a frequency shift to the sound.
+
Blocks 1 onwards are sound effects in raw format, with unsigned 8-bit mono samples. A good typical frequency for playback is 8kHz. OMF has the ability to play these sounds back at other rates, in order to apply a frequency shift to the sound.
  
 +
The block numbers correspond to the sound effect numbers in the Sound Effects Test (press Alt-S-F then look in the Configuration menu). SOUNDS.DAT defines 299 sounds, of which most are entirely silent and only one sample long ("\0\0").
  
----
+
Precisely 65 sounds are non-silent:
  
 +
1-6, 10-17, 19-21, 23-58, 61-72
  
I've only been able to extract 64 sounds from the file using this approach, the rest all report just being "\000\000". I'm not sure if that's all of them or what. I'm also not sure how to figure out which sound corresponds to which index in the animation strings when it calls for a sound to be played back...
+
Note that the sounds are numbered from 1, not 0. BK and AF files reference sounds in SOUNDS.DAT this way. The 30 byte footer for both AF and BK files defines a mapping from AF/BK sound IDs to SOUNDS.DAT sound IDs. See the AF file reference for more information.
 +
 
 +
----
  
 
A useful command to convert the raw files into WAV files is as follows:
 
A useful command to convert the raw files into WAV files is as follows:
Line 19: Line 21:
 
   sox -r 8000 -u -b -c 1 sound.raw sound.wav
 
   sox -r 8000 -u -b -c 1 sound.raw sound.wav
  
 +
== Sample implementations ==
 +
 +
=== Python parser ===
 +
<pre>
 +
def read_sounds(f):
 +
    import struct
 +
    _, size = struct.unpack('<LL', f.read(8))
 +
    blocks = (size,) + struct.unpack('<%dL' % (size/4-2), f.read(size-8)) + (0,)
 +
    return [f.read(j-i) for i, j in zip(blocks, blocks[1:])]
 +
</pre>
  
 
== External Links ==
 
== External Links ==

Latest revision as of 21:47, 4 January 2013

SOUNDS.DAT:

This file contains all the sound effects used by OMF. It is split into a number of blocks, the first of which is a header block describing where in the file each block begins and ends.

Block 0, the header block, is a sequence s of dwords. Block i is stored in the file from offset s[i] to offset s[i+1]-1. The blocks start at the beginning of the file, so the offset of the header block is 0, the first four bytes of the file are 0x00, and next four bytes of the file contain the length of the header block. There is one final block which runs from s[n] to the end of the file.

Blocks 1 onwards are sound effects in raw format, with unsigned 8-bit mono samples. A good typical frequency for playback is 8kHz. OMF has the ability to play these sounds back at other rates, in order to apply a frequency shift to the sound.

The block numbers correspond to the sound effect numbers in the Sound Effects Test (press Alt-S-F then look in the Configuration menu). SOUNDS.DAT defines 299 sounds, of which most are entirely silent and only one sample long ("\0\0").

Precisely 65 sounds are non-silent:

1-6, 10-17, 19-21, 23-58, 61-72

Note that the sounds are numbered from 1, not 0. BK and AF files reference sounds in SOUNDS.DAT this way. The 30 byte footer for both AF and BK files defines a mapping from AF/BK sound IDs to SOUNDS.DAT sound IDs. See the AF file reference for more information.


A useful command to convert the raw files into WAV files is as follows:

 sox -r 8000 -u -b -c 1 sound.raw sound.wav

Sample implementations

Python parser

def read_sounds(f):
    import struct
    _, size = struct.unpack('<LL', f.read(8))
    blocks = (size,) + struct.unpack('<%dL' % (size/4-2), f.read(size-8)) + (0,)
    return [f.read(j-i) for i, j in zip(blocks, blocks[1:])]

External Links