Sounds in MSX BASIC Part 2
by admin on Mai.28, 2009, under Music Creation
SOUND
Syntax: SOUND (register),(data)
SOUND is probably the most powerful command, since you can control all the AY-3-8910 Registers with it. You can use all the 3 channels, add noise and do everything the Chip is able to. Here are the Registers and the possible values with an explanation afterwards, you might also want to look at the AY-3-8910 Datasheet for some reference.
| Register # | Function | Data |
|---|---|---|
| 0 | Channel 1 Frequency (Lo-Bit) | 0 – 255 |
| 1 | Channel 1 Frequency (Hi-Bit) | 0 – 15 |
| 2 | Channel 2 Frequency (Lo-Bit) | 0 – 255 |
| 3 | Channel 2 Frequency (Hi-Bit) | 0 – 15 |
| 4 | Channel 3 Frequency (Lo-Bit) | 0 – 255 |
| 5 | Channel 3 Frequency (Hi-Bit) | 0 – 15 |
| 6 | Noise Frequency | 0 – 31 |
| 7 | Channel Mask / Mixer | 128 – 191 |
| 8 | Channel 1 Volume | 0 – 15 |
| 9 | Channel 2 Volume | 0 – 15 |
| 10 | Channel 3 Volume | 0 – 15 |
| 11 | Envelope | 0 – 15 |
| 12 | Envelope Speed (Lo-Bit) | 0 – 255 |
| 13 | Envelope Speed (Hi-Bit) | 0 – 255 |
Register R0 – R5:
The Hi-Bit sets the “Main” Frequency of the tone generator and the Lo-Bit is there to finetune it, which results in 4096 possible frequencies. For example, if you set the Hi-Bit to 3 and want to pitch it down a bit you would write something like 50 in the Lo-Bit.
Register R6:
This sets the frequency of the Noise Generator from 0-31.
Register R7:
This Register controls the Mixer. You can mute single Channels or Add Noise to them. The number has to be calculated from an 8-Bit binary code:
| Bit | Function | Value |
|---|---|---|
| B7 | Enable I/O | Always 1 |
| B6 | Enable I/O | Always 0 |
| B5 | Enable Channel 3 Noise | 0 – 1 |
| B4 | Enable Channel 2 Noise | 0 – 1 |
| B3 | Enable Channel 1 Noise | 0 – 1 |
| B2 | Enable Channel 3 Tone | 0 – 1 |
| B1 | Enable Channel 3 Tone | 0 – 1 |
| B0 | Enable Channel 3 Tone | 0 – 1 |
0 = Enabled, 1 = Disabled
Example: You want to hear the Tones from Channel 1 – 3 and add Noise to Channel 1, this means you come up with 10110000 in Binary, or 176 in decimal. To set the Register this way, write “SOUND 7,176″.
Register R8 – R10:
The Volume of the Tone Generators. 0 = mute, 15 = max. The default is 0, so there will be silence until you move the volume up.
Register R11:
Selects the waveform that comes from the Envelope Generator. To see the table have a look at Part 1.
Register R12 – R13:
This is our cycle speed once again, a.k.a. the time it takes to cycle through one loop of the envelope. Again this is Hi-Bit * Lo-Bit, with a maximum value of 255 for each.
Examples
To make a long tone, all you need to do is to turn up the volume of one of the channels:
10 SOUND 8,15
Now lets use some more registers. For example to change the frequency, use 2 channels and add some noise on the third channel:
10 SOUND 1,2 //give channel 1 a rather low frequency
20 SOUND 3,5 //a higher frequency for channel 2
30 SOUND 7,156 //this is the channel mask. we want a Tone from Channel 1 & 2 + Noise from Channel 3. In Binary thats 10011100 or 156 in decimal.
40 sound 8,15 //turns the volume up (Channel 1)
50 sound 9,15 //turns the volume up (Channel 2)
60 sound 10,10 //turns the volume up (a bit less for Channel 3)
This sounds like crap, but you get the idea behind it
. Other things that can be done easily and sound way better would be sweeps (Change the Frequency with a loop) or things like that. On the other hand this is all you need to control everything this soundchip is able to, so you could program a full fledged music editor or something