SCI Sound Resource Format (incomplete)                             Revision 2
Ravi I.                                                          Jan 16, 1999


Preface

   The sound resource is basically just a MIDI file. Much of what I write
   here comes from outside documents, and I would direct anyone seeking
   further information to various MIDI specifications. There are quite a few
   floating around - I leave it to the reader to find individual documents.

   Some people prefer the one-based numbering system for channel and program
   numbers. I personally prefer the zero-based system, and use it here. If
   you're familiar with channels 1-16, be aware that I will call them 0-15.
   My intention is not to be deviant from other programs but to be more
   accurate in representing the way information gets stored. The same is true
   for programs 0-127 as opposed to 1-128.

   Sierra may have changed its sound file format in the switch to SCI1.
   Resources extracted from "Quest for Glory II" (which uses the odd
   in-between engine) will not strictly follow this specification. I haven't
   had a chance to look at true SCI1 files yet, but will when I can. For now,
   I refer only to SCI0 sound files. Games which are known to follow this
   specification include:
      Conquests of Camelot
      Hero's Quest I (Retitled Quest for Glory, but I only have the original)
      King's Quest IV

   Please post comments or questions to the SCI webboard:
      http://www.InsideTheWeb.com/mbs.cgi/mb173941


About the output medium

   The output medium (Adlib, MT-32, PC Speaker, etc.) greatly affects the way
   music will sound. They may even affect the way sound resources get used.
   Not having anything else, I can only play sounds with the Adlib and PC
   Speaker drivers. I'd like to get my hands on an MT-32 firstly because it
   would make the music sound quite a bit better and secondly because I think
   Sierra's composers might have used them.

   I have not yet tried to create sounds which play out the PC speaker. My
   suspicion is that either the header specifies which channel should be used
   for speaker output or the speaker always plays a certain channel. I have
   been able to create sounds which play with an Adlib or compatible. If
   other devices do not play sounds correctly, I'd appreciate it if people
   with them could do some byte twiddling to help me figure out why.

   Another issue to deal with in the output medium is the fact that the same
   song may exist in two different files. In Conquest for Camelot, the
   version of the title music which gets played by an Adlib is in sound.001.
   The speaker version is in sound.201. The speaker version will play on the
   Adlib (with more than one channel, I might add) but the Adlib version will
   not play on the Speaker. While I haven't looked at patch files yet, I
   think that different mediums have their own instrument format as well.


First two bytes

   The first two bytes in an extracted sound file (they aren't actually part
   of the resource) will be 84h 00h. This is the resource type OR-ed with 80h
   and stored as a word.


Header

   The header is 33 bytes long. The format appears to be:
      byte - always 0
      2 bytes - initialization for channel 0
      2 bytes - initialization for channel 1
      .
      .
      .
      2 bytes - initialization for channel 15

   The first byte is zero for every extracted file I've seen. Changing it
   makes the sound resources I tested not play. Perhaps this is a format
   version number: if Sierra wanted to expand the sound resource, they would
   increment this byte to signal the player that it won't recognize the file
   and should not try to play it.

   After the first byte, each channel gets two bytes of initialization. The
   first byte seems to initialize controls 4Bh and 4Eh (see command Bx).

   The second byte's function is unknown.


Events

   The actual music is stored in a series of events. The generic form for an
   event is:
      <byte - delta time> [byte - status] [byte - p1 [p2]]

   Delta time is the number of ticks to wait after executing the previous
   event before executing this event. Standard MIDI stores this as a variable
   length value. In sound resources, it will be exactly one byte and the most
   significant bit is in fact used as part of the value.

   The status byte is basically a command. The most significant bit is always
   set. This feature is important because the status byte will not always be
   present. If you read a byte expecting it to be a command but the most
   significant bit is not set, that byte is actually a paramater and you
   should repeat the last status byte used. This is know as running status
   mode and appears to get used relatively often.

   There generic form for a status byte is (in bits) 1xxxcccc - The lower
   nibble designates which channel the command affects. The upper nibble is
   the command, but as stated earlier, the most significant bit must be 1.
   That leaves space for 8 commands, most of which require at least one
   paramater. Paramaters will never have their most significant bit set as a
   way of distinguishing them from status bytes.


Status reference

   8x n v - Note off: Stop playing note n on channel x, releasing the key
            with velocity v. If a hold pedal is pressed, the note will
            continue to play after this status is received and end when the
            pedal is released. Note 60 corresponds to middle-c on a keyboard,
            but the patch selection can change the actual pitch. Often, a
            zero-velocity note on gets used instead of a note off.

   9x n v - Note on: Play note n on with velocity v on channel x. Note 60
            corresponds to middle-c on a keyboard, but the patch selection
            can change the actual pitch. The velocity is the speed with
            which the key gets pressed, which basically means how loud the
            note should be played. Playing a note with velocity 0 is a way
            of turning the note off.

   Ax n p - Key pressure (after-touch): Set key pressure to p for note n on
            channel x. This is to modify key pressure for a note that is
            already playing.

   Bx c s - Control: Set control c to s on channel x. This can be confusing
            because there isn't just one meaning. Changing the settings on
            different controls will, of course, have different outcomes.

            Controls which handle any value are continuous controllers. They
            have a continuous range. Controls which are only on/off are
            switches. Their defined range is only 01h (OFF) and 7Fh (ON).
            However, in order to respond to all values, 01h-3Fh is treated as
            OFF and 40h-7Fh is treated as ON. While in practice they may only
            use bit 6 as a flag, my personal opinion is that values between
            01h and 7Fh should be avoided for the sake of clarity.

            Common controls seem to be 07h, 0Ah, 40h, 4Bh, and 4Eh.

            Control Refrence (tentative)

               07h - Volume: Set the volume. This is a continuous controller
                        where a value of 00h is muted and a value of 7Fh is
                        loudest. There is a wide range of recorded values.

               0Ah - Panning: Set the pan. This is a continuous controller
                        where 00h is hard left, 40h is center, and 7Fh is
                        hard right. There is a wide range of recorded values.

               40H - Hold 1 Pedal: This is a switch that defines the state of
                        the hold pedal. When ON, the pedal is pressed. When
                        OFF, the pedal is not pressed. When the pedal is
                        pressed, notes continue to play after a key is
                        released. The notes will then stop once the pedal is
                        released. Recorded values are 1 and 127.

               4Bh - Polyphonic / monophonic: The value determines the number
                        of voices which may be played at once on the channel.
                        Recorded values are 0, 1, 2, 4, 6, and 8. This seems
                        to be a non-standard control.

               4Eh - Unknown: I had originally thought this control was some
                        sort of volume enable. A non-zero will allow volume
                        to be determined on a per-note basis with the
                        velocity paramater to command 9x while a zero value
                        means the channel will play at channel volume
                        regardless of the velocity paramater. This doesn't,
                        however, seem to be the case. Its odd interactions
                        with control 4Bh make me suspicious that it might be
                        some parallel to omni mode. Recorded values are 0 and
                        1. This seems to be a non-standard control.

   Cx p - Program change: Set program (patch / instrument / ect.) to p for
          channel x. This is a simple instrument change.

   Dx p - Pressure (after-touch): Set key pressure to p on channel x. This is
          similar to Ax but differs in its scope. Command Ax is applied on a
          per-note basis while command Dx is applied to an entire channel.

   Ex t b - Pitch wheel: Set the pitch wheel to tb. The setting is actually
            a 14 bit number with the least significant 7 bits stored in b
            and the most significant 7 bits stored in t. (Remember the top
            bit can't be used for either byte.) The range of settings is
            0000h to 3FFFh. A setting of 2000h means the pitch wheel is
            centered. Larger values raise pitch and smaller values lower it.

   FC - The only command I've seen which starts with F is FC and that denotes
        the end of a file. Note that the lower nibble does not signify a
        channel.


Revision history

   Revision 2 - Jan. 16, 1999
      - Got rid of the HTML. I originally intented to post this as a message
        on the webboard, but ended up distributing the file. If I'm going to
        distribute it as a file, there's no need to bother with the HTML
        since I can do all my formatting as plain text.
      - I found refrences to command 8x in the 1988 Christmas Card, so my
        comment about not seeing one got removed. To date, I haven't seen any
        examples of commands Ax or Dx.
      - Expanded the header section.
      - Added information about controls.
      - Added information about the output mediums.
      - Tried to be more consistent with terminology

   Revision 1 - Dec. 29, 1998
      - First release of the specification

