Skip to main content

SND field reference

File page · Format catalogue · Schema source

This page is generated from the Kaitai schema SND.ksy each time the site is built. The schema is the authoritative description; statements are established unless marked inferred or unknown, and the evidence is listed on the file page (see the reading guide).

  • Schema: Eye of the Beholder II DOS PC speaker and Tandy sound file (SND)
  • Byte order: little-endian
  • File extension: snd
  • Schema license: MIT

Description​

Sounds for the built-in PC speaker (sound driver 2) and the three-voice sound chip of Tandy computers (sound driver 3). The game loads one file at a time, the one named by the current level, or INTRO and FINALE1/FINALE2 for the introduction and the ending, exactly as it loads the ADL files of driver 1.

The first 120 bytes are the sound-effect table, which the game keeps for itself; the rest of the file is copied to the sound buffer unchanged. It starts with two tables of 250 pointers each, followed by the programs. A program is a stream of notes and commands; a sound is played by starting a program. All pointers count from byte 120, the end of the sound-effect table; 0 means that the entry is absent. The second pointer table has the place of the instrument pointers of the ADL files: the game relocates it with the first one but never reads it, and it is zero in every original file.

In the original files the program data starts right after the pointer tables, at pointer value 1000 (byte 1120); the programs follow one another in number order and the last one ends on the last byte of the file. The game reads at most 15,120 bytes after the sound-effect table. The seven level files hold the same 68 programs and differ only in a few entries of their sound-effect tables. See the format overview.

File structure​

FieldTypeSize, repetition and constraints
sound_effect_tableu1repeated 120 times
program_offsetsu2repeated 250 times
unused_offsetsu2repeated 250 times

sound_effect_table

Program number to start for each game sound number 0-119; 255 means that the sound plays nothing. Bit 7 is ignored: values 128-254 start program value − 128. Game sound n reads entry n. See the sound-effect table. No original file holds 255. Many entries are 0, which starts program 0, a program that stops at once; the level files hold one value with bit 7 set, 130 for sound 119.

program_offsets

Offset of each program from byte 120 of the file; 0 when the program is absent. Several sound numbers may share one program. In the original files the numbers used run from 0 without gaps: 0-67 in the level files, 0-7 in INTRO.SND and FINALE2.SND, 0-6 in FINALE1.SND.

unused_offsets

A second table of 250 offsets, at the place of the instrument offsets of the ADL files. The game adds the address of the sound buffer to each word when it loads the file and reads none of them. All zero in the original files.

Derived values and positioned data:

FieldTypeSize, repetition and constraints
programsprogram_slot(_index)repeated 250 times

programs

The 250 program entries, in number order.

Type program_slot​

Parameters: index (u1)

Derived values and positioned data:

FieldTypeSize, repetition and constraints
offsetcomputed: _root.program_offsets[index]—
bodyprogramonly if offset != 0; at position 120 + offset; in stream _root._io

body

The program, absent when the offset is 0.

Type program​

A stream of notes and commands, read from its first byte. Starting a program always replaces the one playing: there is no priority and only one program plays at a time.

The speaker driver plays the stream on one voice. The Tandy driver plays the same stream on three voices: the second starts 35 ticks after the first and the third 70 ticks after it, with decreasing loudness, as an echo. Each voice keeps its own position, tempo factor and loop counters, and stops at the first end byte; the sound ends when every voice has stopped. The driver takes one step on each interrupt of the system timer, 291.3 times per second.

A note or a frequency command sounds until the next one: the next element is read (duration + 1) × tempo factor + 2 steps later. A rest silences the voice for the same time. Commands other than notes take effect at once, on the same step as the next note. The tempo factor starts at 1 for each sound; the loop counters keep their last value from one sound to the next.

This schema reads elements in sequence up to the first end byte. In the original files every program ends with 0xff and its loops jump backwards inside the program.

FieldTypeSize, repetition and constraints
elementselementrepeated until _.is_end

Type element​

A note (first byte 0x00-0x5f), a command (0xcd, 0xce, 0xd1, 0xd2, 0xe2, 0xe6, 0xe8, 0xe9) or an end byte (every other value).

FieldTypeSize, repetition and constraints
codeu1—
operandu1only if code == 0xcd or code == 0xd1 or code == 0xe2 or code == 0xe8 or code == 0xe9
back_offsetu2only if code == 0xce or code == 0xd2
frequencyu2only if code == 0xe6
durationu1only if code < 0x60 or code == 0xe6

code

For a note: the note number 0-95, 0 for a rest. For a command: the opcode.

operand

Loop count for 0xcd and 0xd1 (0 counts as 1), tempo factor for 0xe2 (0 counts as 1), amount subtracted from (0xe8) or added to (0xe9) the tempo factor.

back_offset

Loop jump: while the counter is not yet exhausted, reading goes back to the byte that lies back_offset bytes before this word. A jump whose subtraction overflows as a signed 16-bit number ends the voice.

frequency

Frequency in hertz, 20 to 20,000 in the original files. The speaker driver plays 1,193,180 / frequency as the timer divisor and the Tandy driver 111,860 / frequency, at most 1023. A value below 19 overflows the speaker driver's division, and a value below 2 the Tandy driver's (see the anomaly).

duration

Length of the note: the next element is read (duration + 1) × tempo factor + 2 steps later. 0-64 in the original files. A duration of 255 gives the shortest note (see the anomaly).

Derived values and positioned data:

FieldTypeSize, repetition and constraints
opcodecomputed: codeonly if code >= 0x60; values: opcode
is_endcomputed: code >= 0x60 and code != 0xcd and code != 0xce and code != 0xd1 and code != 0xd2 and code != 0xe2 and code != 0xe6 and code != 0xe8 and code != 0xe9—

opcode

The command or end byte, for codes 0x60 and above.

is_end

True for an end byte. 0x60-0x7f and every byte from 0x80 that is not a command stop the voice; the original files use 0xff only.

Enumerations​

Enumeration opcode​

ValueNameMeaning
205set_loop_count_aSet the counter of loop A to the operand (0 counts as 1).
206loop_aCount down loop A; when it reaches 0, go on after the command, otherwise jump back by back_offset.
209set_loop_count_bSet the counter of loop B to the operand (0 counts as 1).
210loop_bCount down loop B, as 0xce does for loop A.
226set_tempo_factorSet the tempo factor to the operand (0 counts as 1).
230frequency_notePlay a frequency given in hertz for a duration, like a note.
232decrease_tempo_factorSubtract the operand from the tempo factor. The floor of 1 that the code tries to apply is never applied (see the anomaly). Not used in the original files.
233increase_tempo_factorAdd the operand to the tempo factor; the result is set to 255 when the signed addition overflows. Not used in the original files.
255endStop the voice. The only end byte of the original files.