Skip to main content

Play a sound

SCRIPT_PLAY_SOUND · opcode 0xf6 · 4 bytes

Script virtual machine · Opcode list · Sound and delay

Plays a sound effect at once, or as coming from a block, louder the nearer the block is to the party.

Encoding​

Offsets count from the opcode byte. Words are little-endian.

OffsetTypeFieldMeaning
0u8opcode0xf6
1s8sound_rawSound effect number, sign-extended by the handler.
2u16leblockZero to play the sound at once; otherwise the block it comes from.

Example (level 1): f6 4f 00 00 plays sound effect 79 at once.

Behavior​

The sound number is an index into the game's table of 120 sound effects: nothing is played for a negative number, for 120 or more, for an entry of the table marked as absent, or while the "Sounds" option is off. The other game routines play their sounds through the same table, for example sound effect 21 when a character is hurt; sound effects lists them all. The audio behind each number is not covered here.1

  • A zero block plays the sound immediately, with no level given.
  • Another block makes it an environmental sound. The request first plays the environmental sound still waiting, if any. Then, if the block is at a distance of 15 or less from the party, the new sound waits, with the level (15 − distance) × 16; farther away it is dropped. A waiting sound plays at the next environmental request or at the end of the current pass of the game loop, whichever comes first.

The distance is the one the game uses for monsters: the larger of the column and row differences plus half the smaller one, rounded down. Only a sound number above zero is kept waiting: a sound 0 or a negative number with a block plays nothing, and only flushes the sound already waiting.1

The sound-effect table​

The table is not part of the executable: it is the start of the current sound file. At every level load, the game takes the sound name of the level's INF sublevel record (sound_name_slot) and loads name.ADL with sound driver 1, or name.SND with drivers 2 and 3; with no sound driver it loads nothing. The game start loads INTRO in the same way. The first 120 bytes of the file become the table, and the rest of the file is handed to the sound driver.2 With driver 1 an entry is the number of a program of the ADL file, started by the driver: a single sound, or a tune of several voices. With drivers 2 (PC speaker) and 3 (Tandy sound chip) it is the number of a program of the SND file, a short melody that replaces the sound in progress; bit 7 of the entry is ignored.

Sound effect n reads entry n of that table. The value 255 means that the sound is absent and nothing is played; any other value is passed to the driver, which plays from the data it received with the file. A sound number is therefore not tied to one sound: what it plays depends on the current level's sound file and on the driver. Two consequences visible in the reference files:

  • In the .ADL files of the levels, 76 of the 120 entries are the same in all seven files and the others differ; sound effect 79, for example, is 29 in all of them, while 52 is 103 in FOREST.ADL and 105 in MEZANINE.ADL.
  • In the .SND files, many numbers share one value: sound effects 52 to 55 and 79 are all 16 in FOREST.SND and MEZANINE.SND, so with drivers 2 and 3 the scripts that use them on levels 4 and 5 play the same short chirp. No .SND entry is 255; an entry of 0 plays a program that stops at once, which silences the sound in progress.

The .ADL files of the introduction and the ending fill only the first entries, 16 in INTRO.ADL, 11 in FINALE1.ADL and 3 in FINALE2.ADL; all others are 255.

Edge cases​

  • The handler sign-extends the sound number, so values above 127 reach the sound routines as negative numbers and play nothing.

Observed use​

The reference scripts contain 846 instructions of this kind, with sound numbers 0 to 98. 409 play at once and 437 come from a block; three of those use sound 0 and are silent.

Sources​

Footnotes​

  1. Handler for 0xf6, the sound effect player, the environmental sound, the distance between two blocks and the option settings. Comparative source: oeob_playSoundEffect in REF-SCUMM-003. Usage comes from decoding the scripts reachable in the 16 reference INF files. ↩ ↩2

  2. Load the sound file, start a speaker or Tandy sound, its caller in the sublevel loader, the sound-effect table and the sound effect player. Values from the first 120 bytes of the reference .ADL and .SND files listed in the file inventory. ↩