An instrument is an ins list in lins. It has a header, a list
of regions and, optionally, articulation that applies to all its regions. A region says
which keys and velocities it answers, which wave it plays and how. Sections 1.4, 1.14.6 to
1.14.8, 2.7, 2.8 and 2.11 of Downloadable Sounds Level 2.2, and the Level 1
document. All numbers are little-endian.
insh: the instrument header
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | cRegions | the number of regions of this instrument |
| 4 | 4 | u32 | Locale.ulBank | the MIDI bank: see below |
| 8 | 4 | u32 | Locale.ulInstrument | the MIDI program change value: bits 0 to 6; bits 7 to 31 are reserved and should be zero |
The two Locale fields form a MIDILOCALE structure. An
insh chunk is typically (but not necessarily) the second chunk of its
ins list; the others are an optional dlid, the
lrgn list, optional lart and lar2 lists and an
optional INFO list.
ulBank
| Bits | Meaning |
|---|---|
| 0 to 6 | MIDI controller 32 (bank select LSB) |
| 7 | reserved, written as zero |
| 8 to 14 | MIDI controller 0 (bank select MSB) |
| 15 to 30 | reserved, written as zero |
| 31 | F_INSTRUMENT_DRUMS (0x80000000): 1 for a drum instrument, 0 for a melodic one |
The bank select MSB and LSB are joined as 8-bit bytes: the bank space is 16,384 banks of
128 instruments. Level 2.2 says bit 31 is informative. A channel that selects MSB
0x79 uses the device’s default melodic bank, and MSB 0x78 its
default drum bank; a device with General MIDI or General MIDI 2 puts the percussion
programs at MSB 0x78, LSB 0, program 0 and the melodic programs at MSB
0x79, LSB 0 (GM2: LSB 0 to 9). A bank and program from a DLS file may reuse
those numbers and then temporarily replaces the built-in program until it is unloaded.
Content authors must send bank select MSB, LSB and program change in that order.
The explorer shows bank MSB, bank LSB, program and the drum flag, and reports reserved
bits that are set. The number of regions that the header gives is checked against the
lrgn list.
Regions: lrgn, rgn and rgn2
The lrgn list holds the regions: rgn lists (Level 1) or
rgn2 lists (Level 2). A region holds a rgnh header, a
wsmp wave sample chunk (optional in Level 1), a wlnk wave link
(required in Level 1), articulation lists and an INFO list; a
cdl chunk can come first. An rgn2 list takes only
lar2 lists, and a rgn list takes lart and
lar2. Layering is made by regions that overlap in key range, with one
oscillator for each region; velocity splits by overlapping regions with different
velocity ranges, key splits by different key ranges.
Level 1 limits an instrument to 16 regions if it is melodic and 128 if it is a drum
kit; Level 1 regions must not overlap (splits, not layers) and have velocity range 0 to
127 (RangeVelocity is not supported).
rgnh: the region header
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 2 | u16 | RangeKey.usLow | the lowest MIDI note the region plays |
| 2 | 2 | u16 | RangeKey.usHigh | the highest MIDI note |
| 4 | 2 | u16 | RangeVelocity.usLow | the lowest velocity |
| 6 | 2 | u16 | RangeVelocity.usHigh | the highest velocity |
| 8 | 2 | u16 | fusOptions | flags; the only one defined is bit 0, F_RGN_OPTION_SELFNONEXCLUSIVE (0x0001) |
| 10 | 2 | u16 | usKeyGroup | the key group: 0 for none, 1 to 15 a group; all other values reserved |
| 12 | 2 | u16 | usLayer | optional: present when the chunk is 14 bytes; 0 for no layer information, otherwise the layer of the region for editors |
F_RGN_OPTION_SELFNONEXCLUSIVE is off by default: a second note-on of the
same note on a MIDI channel shuts the first down (the volume envelope goes to its
release with EG1_SHUTDOWNTIME). With the flag set, both play. Regions of a
drum instrument with the same key group turn each other off “as soon as possible”, for
example open, closed and pedal hi-hat. The Level 2.1 text put the flag in
usKeyGroup and described it as a “self-exclusive” flag; the Level 2.2
summary of changes corrects both. usLayer has no effect on the sound: a
program that does not know it must preserve it when it writes the file, and must read
the chunk size to know whether it is there.
The explorer reports a range that runs down, a range above 127, undefined option bits and a key group above 15.
wlnk: the wave link
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 2 | u16 | fusOptions | flags; undefined bits must be 0: bit 0 F_WAVELINK_PHASE_MASTER (0x0001), bit 1 F_WAVELINK_MULTICHANNEL (0x0002) |
| 2 | 2 | u16 | usPhaseGroup | the group number of samples that are phase locked, or 0 |
| 4 | 4 | u32 | ulChannel | the channel placement of the sample: one bit for each channel (table below) |
| 8 | 4 | u32 | ulTableIndex | the 0-based index of the cue in the pool table |
| Bit | Channel | Bit | Channel |
|---|---|---|---|
| 0 | left (or mono) | 9 | side left |
| 1 | right | 10 | side right |
| 2 | centre | 11 | top |
| 3 | low frequency energy | 12 | top front left |
| 4 | surround left | 13 | top front centre |
| 5 | surround right | 14 | top front right |
| 6 | left of centre | 15 | top rear left |
| 7 | right of centre | 16 | top rear centre |
| 8 | surround centre | 17 | top rear right |
Bits 18 to 31 are reserved: do not use. A Level 1 file may use only the left channel
(WAVELINK_CHANNEL_LEFT, 0x0001) and default values for the other
fields. To phase lock samples (for the two channels of a stereo piano, say), give
every wave link of the group the same non-zero usPhaseGroup and set
F_WAVELINK_PHASE_MASTER on one and only one of them. All oscillators then
take their frequency from the master’s: connections to DST_PITCH, the
sample rate and the fine tuning of the slaves are ignored, and the samples must stay in
lock to within half a sample. With F_WAVELINK_MULTICHANNEL set the channel
is fixed by ulChannel and the channel steering of the articulation is
ignored; the mode is optional for devices, and cross-platform content must guard it
with a conditional chunk.