Okay, check this shit.
You have two bits, A and B. They can be 0 or 1, as bits are wont to do. You can combine them in various ways to get another bit value.
- With an AND operation, the result is 1 only if A and B are both 1. 0 AND 1 is still 0.
- With an OR operation, the result is 1 if A or B is 1. If both A and B are 1, that's fine too.
- With an XOR operation, the result is 1 if A and only A, or B and only B is 1. An exclusive OR.
A byte is just eight bits in a row, and a short is 16 of them. Here endeth
that lesson.
channelMask is considered in the SCI Companion source code to be a short (
uint16_t, or "unsigned integer, 16 bits", where unsigned means it can't go below zero so you get a 0-65535 range), but from what I understand it's actually
two separate bytes, one of them being the channel mask and the other the initial voices count. The
<< 8 bit is only there so the values from
enum DeviceType end up in the channel mask byte, not the initial voices byte.
What the
|= means is "take the channel mask value so far, and
OR-combine this new value with it." This is done bit-by-bit.
And these are the bits:
MT-32 | 0x01 | 0000.0001 |
FB-01 | 0x02 | 0000.0010 |
AdLib | 0x04 | 0000.0100 |
Casio | 0x08 | 0000.1000 |
Tandy | 0x10 | 0001.0000 |
PC Spkr | 0x20 | 0010.0000 |
Ami/Mac | 0x40 | 0100.0000 |
GM | 0x80 | 1000.0000 |
Notice how each of them has a different bit set? That means a channel meant to play on MT-32 and AdLib both would have the bits
0000.0101 set, which is 0x05 in hexadecimal.
<THEORY>
But because apparently (and this is entirely my conjecture here) the channel mask isn't a 16-bit value but only 8-bit, and the other eight are the initial voice value, that means they have to be shifted up eight spaces.
0x05 0x03
| |____ Initial voices value: we'll play at most three notes at once on this track.
|_________ Channel mask: this is for MT-32 and AdLib.
And that would thus be packed into a single 16-bit value, 0x0503.
</THEORY>