OBD:SNDD: Difference between revisions
m (→WAVE-like format header ("8" flag): oops) |
m (→WAVE-like format header ("8" flag): oops) |
||
Line 266: | Line 266: | ||
;PCM vs ADPCM | ;PCM vs ADPCM | ||
:Although Vanilla Oni SNDDs only ever use MS ADPCM waveforms, some mods have successfully used the (bloated!!!) PCM format. | :Although Vanilla Oni SNDDs only ever use MS ADPCM waveforms, some mods have successfully used the (bloated!!!) PCM format. | ||
:For PCM, the format ID (at 0x0C) is set to 1, the block size | :For PCM, the format ID (at 0x0C) is set to 1, the block size is either 2 or 4, the data rate formula is simplified, and everything between 0x1C and 0x3E is ignored. | ||
:See [[/wav#PCM_.28with_.22fmt_.22.29|HERE]] for more details on the importing procedure, but keep in mind that PCM waveforms are ''not'' recommended! | :See [[/wav#PCM_.28with_.22fmt_.22.29|HERE]] for more details on the importing procedure, but keep in mind that PCM waveforms are ''not'' recommended! | ||
;ADPCM coefficients | ;ADPCM coefficients |
Revision as of 13:48, 30 July 2021
|
- For metadata instances used to group sounds together, randomize them, adjust their volume or frequency, etc, see OSBD and its subtypes: OSAm, OSIm and OSGr.
SNDD instances is where Oni stores sound data. In Vanilla Oni game data, sounds are either mono or stereo waveforms (with sampling frequencies of either 22.05 kHz or 44.1 kHz), compressed to save on storage space. Both the PC and Mac versions use a form of ADPCM compression (Adaptive Differential Pulse-Code Modulation), where 16-bit sound samples are encoded as 4-bit "nibbles" (resulting roughly in a 4:1 compression ratio as compared to uncompressed 16-bit PCM).
- On PC (both retail and demo), sounds are encoded using Microsoft's ADPCM codec (implemented in FFmpeg as adpcm_ms). See HERE for a quick description.
- On Mac, sounds are encoded using QuickTime's IMA4 codec (implemented in FFmpeg as adpcm_ima_qt). See HERE for a quick description.
As a unique feature of Oni game data, SNDD files have a significantly different structure depending on the engine version. For PC retail (.dat/.raw storage, no .sep files), the SNDD files are larger and include a 50-byte chunk of data that is equivalent to the "fmt " chunk of a WAVE file. For the other two versions (PC demo and Mac, .dat/.raw/.sep storage), this 50-byte block is missing. It turns out that the extra format data allows the PC retail to support both MS ADPCM and IMA4, as well as uncompressed PCM, whereas PC demo and Mac engines only support MS ADPCM and IMA4, respectively. (It has not been confirmed whether the PC retail engine supports other WAVE formats beyond PCM and MS ADPCM, such as Mu-Law or A-Law PCM, IEEE float PCM, etc.)
For clarity, the simpler and more straightforward SNDDs of PC demo and Mac are documented first, followed by the more complex and versatile PC retail SNDDs.
- (Historically, though, the PC retail implementation is older, and the PC demo and Mac versions were trimmed-down iterations of PC retail.)
Mac and PC demo
The below example was taken from Mac Oni. In PC demo the file would look the same, except for possibly different res_id (at 0x00) and smaller raw data size (at 0x10).
Offset | Type | Raw Hex | Value | Description |
---|---|---|---|---|
0x00 | res_id | 01 D6 08 00 | 2262 | SNDDcomguy_dth2.aif, instance number #2262 |
0x04 | lev_id | 01 00 00 06 | 3 | level 3 |
0x08 | uint32 | 01 00 00 00 | 1 | flags
|
0x0C | uint16 | 37 00 | 55 | duration in 1/60 seconds (game ticks) |
0x0E | uint16 | 00 00 | 0x0000 | padding (unused in Vanilla Oni) |
0x10 | uint32 | 5E 2A 00 00 | 10846 | size of the part in the raw file, in bytes |
0x14 | offset | 00 B1 01 00 | 0x1B100 | at this position starts the part in the raw file |
0x18 | char[8] | AD DE | dead | 8 unused bytes (padding; not part of the SNDD file) |
- Padding
- The 8 bytes at the end are not part of the SNDD template. They are not loaded by the Oni engine.
- The uint16 at 0x0E is loaded by the engine, and thus constitutes a potentially useful 16-bit field.
- Duration
- The duration (number of game ticks) is rounded to the lower value (a.k.a. "floor") in Vanilla Oni data.[1] In other words, it indicates the number of complete game ticks spanned by the sound's playback.
- Compression
- The effect of the "1" flag (or rather of its absence) is different in the PC demo and Mac engines.
- On Mac, the flag seems to have no effect at all (the .raw data is still passed to the IMA4 decoding algorithm even if the "1" flag is missing).
- On PC demo, a missing "1" flag causes playback to fail.[2] If the sound is part of a looping permutation, the game crashes (because playback keeps failing on the same sound, over and over).
- The bottom line is that, both for PC demo SNDDs and for Mac SNDDs, the "1" flag should always be set.
The compressed storage of .raw data is described in the following two sections.
IMA4 ADPCM .raw data (Mac)
For an overview of the IMA ADPCM algorithm and IMA4 header (if interested), see HERE. For an actual implementation example, see, e.g., FFmpeg.
- The IMA4 ADPCM stream data (stored in the .raw file) consists of 34-byte blocks (in the case of stereo, there is an even number of such blocks, with Left and Right blocks interleaved).
- The first two bytes of each block form a header that sets the initial predictor (upper 9 bits) and step (lower 7 bits) for decoding the block's samples. Typically they are used only for the first block, or for sudden changes of the waveform's value range.
- The other 32 bytes consist of 64 samples stored as nibbles (half-bytes). In the case of stereo, all the nibbles in a block belong to the same channel (either all Left or all Right).
- All the 32-byte blocks must be stored in their entirety, meaning that the overall sample count of the waveform is a multiple of 64 (this is a major difference from MS ADPCM storage in PC retail and PC demo, where the final block is truncated after the last actual sample).
- For this reason, identical sounds do not have the same sample count on PC (both retail and demo) and on Mac. As an example, here are the stats for the main menu music:
|
MS ADPCM .raw data (PC demo)
For a detailed overview of the ADPCM algorithm (if interested), see HERE. For an actual implementation example, see, e.g., FFmpeg.
- The MS ADPCM stream data (stored in .raw) consists of 512- or 1024-byte blocks (512 bytes for 22.05 kHz mono, 1024 bytes for 22.05 kHz stereo)
- Each block starts with a 7- or 14-byte header (7 bytes for mono, 14 bytes for stereo), which includes the 16-bit values of the block's first two samples.
- The remaining 505 or 1010 bytes of each block consist of nibbles (half-bytes), each coding for a sample. In the case of stereo, Left and Right nibbles are interleaved.
- Thus the block has room for 1010 samples encoded as nibbles, and the total number of samples per block (including the header) is 1012, be it for mono or stereo 22.05 kHz.
- For space efficiency, the MS ADPCM stored in .raw deviates from the standard, in that the final block is truncated after the last actual sample. In a WAVE file, ADPCM blocks are stored in their entirety, and the actual sample count is specified in a "fact" chunk. In Oni there is no such thing, instead the actual sample count is inferred from the block size and truncated raw data size.
PC retail
Below is the .dat file part used in the PC retail version.
Offset | Type | Raw Hex | Value | Description |
---|---|---|---|---|
0x00 | res_id | 01 D7 08 00 | 2263 | SNDDcomguy_dth2.aif, instance number #02263 |
0x04 | lev_id | 01 00 00 06 | 3 | level 3 |
0x08 | uint32 | 08 00 00 00 | 8 | flags
|
0x0C | block[50] | format header (MS ADPCM variant here; can also be IMA4, see below) | ||
0x3E | uint16 | 37 00 | 55 | duration in 1/60 seconds (game ticks), rounded to the lower value |
0x40 | uint32 | 56 28 00 00 | 10326 | size of the part in the raw file in bytes |
0x44 | offset | 20 10 59 00 | 0x591020 | at this position starts the part in the raw file |
0x48 | char[24] | AD DE | dead | 24 unused bytes (padding) |
- Padding
- The 24 bytes at the end are not part of the SNDD template. They are not loaded by the Oni engine.
- Duration
- Same as for PC demo and Mac, the duration (number of game ticks) is rounded to the lower value (a.k.a. "floor") in Vanilla Oni data.[1] In other words, it indicates the number of complete game ticks spanned by the sound's playback.
- Compression modes (flags)
- Unlike for PC demo, there is no single compressed/uncompressed flag in PC retail SNDDs, and no stereo/mono flag either.
- The channel count is specified in the 50-byte header if said header is enabled, otherwise it is inferred from OSGr.
- As for compression, PC retail actually has three primary compression modes, commanded by the flag values. Only the first is used in Vanilla Oni.
WAVE-like format header ("8" flag)
If the "8" flag of the SNDD (at 0x08) is ON and the "4" flag is OFF (as is always the case in Vanilla Oni), the 50-byte block is interpreted as a standard "fmt " chunk that you find in WAVE files (see HERE for details).
Offset | Type | Raw Hex | Value | Description |
---|---|---|---|---|
0x0C | int16 | 02 00 | 2 | format ID (2 = MS ADPCM format)
|
0x0E | int16 | 01 00 | 1 | number of channels (1 = mono)
|
0x10 | int32 | 22 56 00 00 | 22050 | sample rate in Hz (samples per second), a.k.a. "sampling frequency" |
0x14 | int32 | 93 2B 00 00 | 11155 | File:Sndd hd1.gif
|
0x18 | int16 | 02 00 | 512 | block alignment a.k.a "block size", in bytes
|
0x1A | int16 | 04 00 | 4 | bits per sample (per channel); typically 4 bits for ADPCM, 16 bits for PCM |
Special extended ADPCM wav format header (black outline); fully ignored if the format ID is 1 | ||||
0x1C | int16 | 20 00 | 32 | size of the extra ADPCM parameters, in bytes; typically always 32 |
0x1E | int16 | F4 03 | 1012 | File:Sndd hd2.gif |
0x20 | int16 | 07 00 | 7 | number of the following coefficient pairs; always 7 in practice |
0x22 | int16-16 | 00 01 00 00 | 256, 0 | The coefficient pairs themselves (always the same in practice). |
0x26 | int16-16 | 00 02 00 FF | 512, -256 | |
0x2A | int16-16 | 00 00 00 00 | 0, 0 | |
0x2E | int16-16 | C0 00 40 00 | 192, 64 | |
0x32 | int16-16 | F0 00 00 00 | 240, 0 | |
0x36 | int16-16 | CC 01 30 FF | 460, -208 | |
0x3A | int16-16 | 88 01 18 FF | 392, -232 |
- PCM vs ADPCM
- Although Vanilla Oni SNDDs only ever use MS ADPCM waveforms, some mods have successfully used the (bloated!!!) PCM format.
- For PCM, the format ID (at 0x0C) is set to 1, the block size is either 2 or 4, the data rate formula is simplified, and everything between 0x1C and 0x3E is ignored.
- See HERE for more details on the importing procedure, but keep in mind that PCM waveforms are not recommended!
- ADPCM coefficients
- The 14 coefficients are de-facto standard, but custom values are formally allowed by the MS ADPCM algorithm.
- Therefore, each MS ADPCM waveform is always accompanied by the coefficient pairs that were used to encode it.
- Thus, even though these numbers are practically always the same, they are required; don't ever mess with them.
- Standard sets of ADPCM parameters
Below are the three types of headers occurring for Vanilla Oni's sounds (MS ADPCM).
22.05 kHz mono (used for the vast majority of sounds):
- 1 channel; sample rate 22050 Hz; average data rate 11155 B/s (truncated from ~11155.7312253 = 22050*512/1012);
- block alignment 512 bytes; 4 bits per sample; 1012 samples per block (= 2 + (512 - 7)*8/4/1); standard coefficient table.
0x00: | °° | °° | °° | °° | °° | °° | °° | °° | 08 | 00 | 00 | 00 | 02 | 00 | 01 | 00 | °°°°°°°°°°°°°°°° |
0x10: | 22 | 56 | 00 | 00 | 93 | 2B | 00 | 00 | 00 | 02 | 04 | 00 | 20 | 00 | F4 | 03 | °°°°°°°°°°°°°°°° |
0x20: | 07 | 00 | 00 | 01 | 00 | 00 | 00 | 02 | 00 | FF | 00 | 00 | 00 | 00 | C0 | 00 | °°°°°°°°°°°°°°°° |
0x30: | 40 | 00 | F0 | 00 | 00 | 00 | CC | 01 | 30 | FF | 88 | 01 | 18 | FF | °° | °° | °°°°°°°°°°°°°°°° |
22.05 kHz stereo (used for music and some ambients):
- 2 channels; sample rate 22050 Hz; average data rate 22311 B/s (truncated from ~22311.4624506 = 22050*1024/1012);
- block alignment 1024 bytes; 4 bits per sample; 1012 samples per block (= 2 + (1024 - 2*7)*8/4/2); standard coefficient table.
0x00: | °° | °° | °° | °° | °° | °° | °° | °° | 08 | 00 | 00 | 00 | 02 | 00 | 02 | 00 | °°°°°°°°°°°°°°°° |
0x10: | 22 | 56 | 00 | 00 | 27 | 57 | 00 | 00 | 00 | 04 | 04 | 00 | 20 | 00 | F4 | 03 | °°°°°°°°°°°°°°°° |
0x20: | 07 | 00 | 00 | 01 | 00 | 00 | 00 | 02 | 00 | FF | 00 | 00 | 00 | 00 | C0 | 00 | °°°°°°°°°°°°°°°° |
0x30: | 40 | 00 | F0 | 00 | 00 | 00 | CC | 01 | 30 | FF | 88 | 01 | 18 | FF | °° | °° | °°°°°°°°°°°°°°°° |
44 kHz mono (used for ap_hit_shld and the 45 zap## sounds):
- 1 channel; sample rate 44100 kHz; average data rate 22179 B/s (truncated from ~22179.9607073 = 44100*1024/2036);
- block alignment 1024 bytes; 4 bits per sample; 2036 samples per block (= 2 + (1024 - 7)*8/4/1); standard coefficient table.
0x00: | °° | °° | °° | °° | °° | °° | °° | °° | 08 | 00 | 00 | 00 | 02 | 00 | 01 | 00 | °°°°°°°°°°°°°°°° |
0x10: | 44 | AC | 00 | 00 | A3 | 56 | 00 | 00 | 00 | 04 | 04 | 00 | 20 | 00 | F4 | 07 | °°°°°°°°°°°°°°°° |
0x20: | 07 | 00 | 00 | 01 | 00 | 00 | 00 | 02 | 00 | FF | 00 | 00 | 00 | 00 | C0 | 00 | °°°°°°°°°°°°°°°° |
0x30: | 40 | 00 | F0 | 00 | 00 | 00 | CC | 01 | 30 | FF | 88 | 01 | 18 | FF | °° | °° | °°°°°°°°°°°°°°°° |
Only the 22.05 kHz sounds (mono and stereo) are played back correctly by the PC retail engine. The forty-six 44.1 kHz sounds are interpreted as 22.05 kHz waveforms, and therefore are played back two times slower/lower than intended.
For any other combinations of PCM or ADPCM parameters, please refer to the importing routine, HERE.
IMA ADPCM decoding ("4" flag)
If the "4" flag of the SNDD (at 0x08) is ON, then (regardless of the "4" flag), the .raw data will be interpreted as IMA ADPCM blocks, and the 50-byte format block will be mostly ignored, as well as the ".raw data size" field at 0x40.
Here is what the .dat part of the above SNDDcomguy_dth2 would have looked like in IMA4 mode:
0x00: | 01 | D7 | 08 | 00 | 01 | 00 | 00 | 06 | 04 | 00 | 00 | 00 | 00 | 00 | 01 | 00 | °×°°°°°°°°°°°°° |
0x10: | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 52 | 01 | 00 | 00 | 00 | 00 | 00 | 00 | °°°°°°°°4°°°°°°° |
0x20: | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | °°°°°°°°°°°°°°°° |
0x30: | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | °°°°°°°°°°°°°°°° |
0x40: | 00 | 00 | 00 | 00 | 20 | 10 | 59 | 00 | AD | DE | AD | DE | AD | DE | AD | DE | °°°° °Y°°°°°°°°° |
0x50: | AD | DE | AD | DE | AD | DE | AD | DE | AD | DE | AD | DE | AD | DE | AD | DE | °°°°°°°°°°°°°°°° |
- The channel count field in the 50-byte "format" block (at 0x0C) is used in the same way as for a WAVE-like header.
- The "block alignment" field (at 0x18) is used (somewhat counterintuitively) to store the number of IMA4 "packets":
- for a mono IMA4 sound, packets are 34-byte blocks carrying 64 mono samples each (two bytes of header data and 64 "nibbles", or half-bytes);
- for a stereo IMA4 sound, packets are pairs of consecutive 34-byte blocks (the 64 Left samples are stored first, then the 64 Right samples).
- (The actual duration of SNDDcomguy_dth2 is, which at 22.05 kHz requires 338 64-sample blocks, hence the value 0x152 appearing at 0x18.)
- Everything else in the 50-byte format block is ignored, as well as the ".raw data size" usually found at 0x40 (Oni uses the number of packets instead).
Raw PCM (no flags)
If neither the "4" nor the "8" flags are set (at 0x08 in the .dat part of the SNDD), then the .raw data is apparently copied as-is into the playback buffer.
In this "raw" playback mode, the sound will not be reproduced correctly unless it's linear PCM (Little Endian) with 16-bit sample depth, 22.05 kHz sampling rate, and a channel count consistent with the SNDD's OSGr (i.e., the metadata used by Oni's engine to set up the sound's playback).
Here is what the .dat part of the above SNDDcomguy_dth2 would have looked like in raw PCM mode:
0x00: | 01 | D7 | 08 | 00 | 01 | 00 | 00 | 06 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | °×°°°°°°°°°°°°° |
0x10: | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | °°°°°°°°°°°°°°°° |
0x20: | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | °°°°°°°°°°°°°°°° |
0x30: | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | °°°°°°°°°°°°°°°° |
0x40: | 00 | 00 | 00 | 00 | 20 | 10 | 59 | 00 | AD | DE | AD | DE | AD | DE | AD | DE | °°°° °Y°°°°°°°°° |
0x50: | AD | DE | AD | DE | AD | DE | AD | DE | AD | DE | AD | DE | AD | DE | AD | DE | °°°°°°°°°°°°°°°° |
- Effect of "1" and "2" flags
- It is possible that the "1" and "2" flags used to affect playback in raw PCM mode (something about swapping the .raw data to allow both for Little Endian and Big Endian PCM samples), but currently they do not seem to have any effect.
Exporting and importing tips
- For manual converting between SNDD (PC retail or demo) and a WAVE file, see HERE.
- For manual converting between SNDD (PC retail or Mac) and an AIFC file, see HERE.
For automatic conversion, please use a sufficiently recent version of OniSplit.
Known engine issues
- Custom sample/data rates
- The PC retail engine formally allows for an arbitrary sample rate (and a corresponding data rate) to be specified in the WAVfmt header, but actually the engine interprets all waveforms as 22.05 kHz.
- If the WAVEfmt header is enabled and specifies MS ADPCM encoding (format ID 2), then the sample rate and data rate are completely ignored (you can fill those fields with zeroes or garbage, and it will still work).
- If the WAVEfmt header is enabled and specifies PCM storage (format ID 1), then fully arbitrary (inconsistent) sample rate and data rate will cause playback glitches or interruption, whereas mutually consistent pairs ("data rate" equal to "sample rate"x"block size") are eventuall ignored. In other words, you have to specify a valid sample rate and data rate, but the engine will end up using 22.05 kHz anyway.
- If the IMA4 header is enabled (overriding WAVEfmt), then the header only specifies the channel count and the "number of packets", and the sample/data rates are again completely ignored.
- PCM playback
- PCM playback is only known to work in PC retail builds, either with IMA4 and WAVEfmt headers disabled (the stream is simply copied to the output buffer, as Little-Endian 16-bit linear PCM, with the channel count specified at OSGr level) or with the WAVEfmt header enabled (in which case the stream can have a custom bit depth and channel count).
- In the case of PC demo, the PCM playback fails (the engine identifies the stream as already uncompressed and skips the initialization of ACM headers, but then proceeds with decompression anyway and stops because of zero input size). This causes no problems for impulse sounds (other than silence), but results in a crash for looping permutations (the same playback keeps failing over and over).
- On the Mac, the stream is interpreted as IMA4 regardless of the 0x00000001 flag, therefore if you put PCM data in the .raw, it will play back as noise.
Known data issues
- PC SNDD data
- The MS ADPCM data used by Vanilla Oni on Windows (both retail and demo) is somewhat coarser (lossier) than the IMA4 ADPCM used on Mac. This is because of the much larger block size, and how the same predictor must be used for the whole block: whenever a block spans both high- and low-amplitude samples, the predictor adapts to the higher amplitudes, and the low-amplitude resolution is lost.
- As a minor issue, the lack of an exact sample count (similar to a WAVE's "fact") makes it impossible to specify an odd number of samples for a mono block (because there is no way to tell if the last byte's second nibble counts or not). It is also impossible to have only one sample in the last block, be it for mono stereo (because the block header reads as two samples by default).
- Mac SNDD data
- Unlike Oni's implementation of MS ADPCM, which cuts off the last block after the last actual sample, IMA4 data consists of full 64-sample blocks, with no way to determine the actual sample count other than by comparing with the same sound from PC Oni. (The "padding" of IMA4 sounds is not always zero, and even if it was, truncation based on trailing zeroes would be somewhat arbitrary.) The padding of IMA4 samples to multiples of 64 leads to silences at the end of Mac sounds that can be up to 3 milliseconds long. This is not a problem for impulse sounds or looping sounds that are quiet near the end, but for loud music (e.g. the main menu's "Trailer" theme) the gap is noticeable. It has been confirmed that the gap is actually heard in Mac Oni, apparently without bothering anyone.
- As a hypothetical fix, the Oni engine could implement a sample count parameter (similar to a WAVE file's "fact"), or truncate the last 64-sample block after the last actual sample, upon encoding (the latter is slightly less straightforward for stereo – because there are two last blocks, one for each channel – but still not a big problem).
- Mac sound data also seems to suffer from encoding artifacts: there are spurious transients at the start of waveforms that prevent ambients and music from looping seamlessly even when cut at the right length. Unlike the padding, this cannot be remedied at all, therefore if one wishes to produce seamless tracks from Oni data (e.g. music) it is recommended to turn to PC SNDDs, which have no looping issues (but are slightly lossier because of the larger block size, as mentioned above).
Modern support
OniSplit
Newer releases (OniSplit v0.9.99.3 and newer) include an implementation of the MS ADPCM and IMA4 codecs, along with the ability to generate .dat/.raw./sep game data compatible with the PC-demo based OniX engine. The codecs allow OniSplit to transcode from Mac's IMA4 or from 44.1 kHz MS ADPCM to standard 22.05 kHz MS ADPCM. PCM is also supported both ways (both as .wav output coming from IMA4 or MS ADPCM, or as uncompressed SNDD intended for the PC retail or demo engines). Finally, for exotic sample rates, there is an option to store the waveform as-is (without resampling) and merely report the appropriate rate multiplier that can be used in OSGr to adjust the speed/pitch upon playback.
Older releases (OniSplit v0.9.99.2 and older) did not support ADPCM encoding or decoding, so there was no way to transcode between IMA4, MS ADPCM and PCM. Generating instance files for the demo engine was not supported either.
The hybrid SNDD format (aligned with OniX's planned features) has not been implemented in OniSplit yet. The recently discovered PC retail engine features (IMA4 support, or default PCM support) are also not covered by OniSplit at the time of writing.
OniX
Starting with v1.1, OniX will likely support all three standard streams (IMA4, MS ADPCM and PCM) with their default encoding/storage settings:
- for IMA4, 32-byte blocks with 64 samples per block (interleaved Left-channel and Right-channel blocks if stereo), sample rate 22.05 kHz;
- for MS ADPCM, 512-byte blocks for mono, 1024-byte blocks for stereo, 1012 samples per block in both cases, sample rate 22.05 kHz;
- for PCM, signed linear 16-bit samples, Little Endian storage, sample rate 22.05 kHz.
The engine will determine between the three types of streams using flags in the short SNDD header. Possibly another flag will allow for doubled sample rate (44.1 kHz); in this configuration the default block size will probably be 1024 bytes for mono and 2048 bytes for stereo, with 2036 samples per block in each case.
Finally, even with a short SNDD header, it is possible for OniX to read a custom WAVEfmt chunk just like the PC retail engine does, by putting the chunk at the start of the .raw part and announcing its presence and/or size through another flag and/or the unused uint at 0x0E. The typical size of this ".raw header" will be 16 bytes for PCM and 50 bytes for ADPCM (the use of other WAVE formats will probably be discouraged).
Alternatively, both the flags and the uint at 0x0E can be used to specify a custom sample rate and/or block size (either as fully custom values or as power-of-two multiplicative factors), without the need for a detailed WAVEfmt header. Still, it is probably easiest to either adhere to the standard parameters (without too many extra flags) or go fully custom and read all the parameters from a standard-compliant WAVEfmt header.
Notes
- ↑ 1.0 1.1 As an example, on PC (both demo and retail), SNDDmus_ot7.aif consists of 152360 samples, which at 22.05 kHz corresponds to 6.90975 seconds, or 414.585 ticks; the duration, however, is indicated as 414 ticks and not 415. In other words, "duration" corresponds to the number of whole game ticks spanned by the sound's playback.
- ↑ If a SNDD misses the "1" flag ("compressed"), the PC demo engine does identify the stream as already uncompressed (PCM samples) and skips the initialization phase of the decompression routine, but then proceeds with decompression anyway, and immediately stops because of zero input size.
ONI BINARY DATA |
---|
QTNA << Other file types >> StNA |
SNDD : Sound Data |
Generic file |