|First Game:||Lunar: Eternal Blue (SCD)|
The PCM file format is used by Lunar: Eternal Blue (SCD) for its music and voice-overs. It is a simple WAV-like format but features looping and a system for emulating reverb using the Sega CD PCM chip.
PCM to ?
|1994-12-22||Lunar: Eternal Blue (SCD)|| |
The PCM format is a straightforward linear PCM audio format in the same vein as WAV files. It supports the following audio formats:
- 16276 Hz sampling rate
- 8-bit PCM samples
- Mono or stereo
It additionally has the following special features absent or very rarely used in WAV files:
- Sample-resolution looping
- Initial silence compression
- Built-in hardware-emulated reverb with file-controlled echo delay, location, and falloff
Reverb is an unusual feature of the PCM format, and understanding it requires some knowledge of the sound chip and how the driver uses it.
The RF5C164 has 64 KB of PCM RAM entirely dedicated to the audio track, and 8 PCM channels with configurable channel start addresses. Channels 1-2 are identical copies of the left (or mono) channel, and channels 3-4 are the right channel if there is one (technically reverb works with stereo tracks, but it has some quirks and is never used this way). The pan position of channels 3-8 are specified in the header (so technically the second channel doesn't have to be the right channel, but in stereo the first channel is hard-coded as left).
x 7.8 ms timer ticks after the driver begins playing, a new channel is started at the beginning of the track and an additional channel is then begun every y timer ticks afterward until all 8 are playing. This effectively produces 6 (for mono) delayed copies of the track at volume levels that are a fraction of channels 1-2 (specified in the header).
It is typical for channels 3, 5, and 7 to be left-panned and 4, 6, and 8 to be right-panned (for mono). As one channel is started after the other, this results in left and right output channels differing on file output even for a mono track.
For stereo the situation is slightly more complicated owing to the two separate audio channels. In this configuration channels 1, 2, 5, and 7 play the first ("left") input channel, and channels 3, 4, 6, and 8 play the second ("right" channel), and the reverb setup must be developed accordingly.
As a simple format, there are two chunks to PCM files: the header and the audio data. Audio data can further be split into two sections: a leading silence that is not stored in the file but specified in the header, and PCM data that follows that silence.
The file structure operates on sectors (2048 bytes) which, for reasons that will be explained, each contain 1024 8-bit samples. The term block will be used to refer to 1024 samples for all channels, and is stored in 1 sector for mono files and 2 consecutive sectors for stereo files.
The file header consumes 1 full sector, most of which is unused. All fields are big endian.
|UINT16||wFormat||Audio format (1 = stereo; 2 = mono)|
|UINT32||dwLoopBlock||Location of the start of the loop as the start of the specified block of samples. There is no format specifier whether a track is looped or not, and 0 is a valid value for both looped and non-looped tracks.|
|UINT32||dwTotalSamples||Total number of samples in the track, which determines the end of the loop for looping tracks.|
|UINT8 * 6||bEchoPanning||Location of each echo from first to last when using reverb. The high nibble contains the volume level of the right channel (regardless of whether the file is stereo or mono), and the low nibble contains the volume level of the left channel. This data is most often 0A A0 0A A0 0A A0.|
|UINT8||bFirstEchoDelay||Delay from start of playback to the first echo in 7.8ms (127.5 sample) increments. A value of 0 disables reverb.|
|UINT8||bEchoDelay||Delay between the previous and next echoes.|
|UINT8 * 3||bEchoVolume||Volume levels for pairs of echoes 1+2, 3+4, 5+6.|
|UINT8||bInitialSilence||Number of blocks of silence at the start of the track before PCM playback begins. It is not clear what the upper bound is, as preloading of audio data will eventually clobber the silence in the playback ring buffer.|
Audio data consists of 16-bit words containing an initial 0 byte followed by an 8-bit sign-magnitude sample. Unlike typical sign-magnitude encoding, a sign bit of 1 indicates positive, and 0 indicates negative. Thus 0-7F correspond to -1 - -128 and 80-FF to 0-127. The initial 0-bytes are an artifact of the way the drive directly reads CD data into PCM RAM and the mismatch between the 16-bit main bus and the 8-bit PCM bus and are entirely unused, needed only to properly align the sample bytes.
For example, the samples -128, -1, 0, 1, 127 would be encoded as 00 7F 00 00 00 80 00 81 00 FF.
Sample words are then bundled into CD sectors. Here each sector contains samples from 1 channel, and stereo tracks contain pairs (blocks) of 1 left channel sector followed by 1 right channel sector.