MSX & Music
MSX micros are already establishing a foothold in the UK market. We give you the info to harness their sound chips and create music with MSX.
Like most micros MSX computers will be used for music making. Jeremy Vine gives you the BASIC information.
The MSX range of computers has introduced not only the notion of compatibility but also that using the sound chip of a micro need not require the brains of a computer whizz-kid! Micros like the BBC and Commodore have extensive sound facilities but the programming involved can be something of a headache. Utilising General Instrument's AY-2-8910 sound chip, all MSX micros can produce a wide range of sounds and effects with little effort though in fairness to the other micros mentioned, the control structures for the more advanced handling of sound is difficult.
In this article I'm going to look briefly at the BASIC commands which control the sound structures and in particular those responsible for altering the waveforms of sounds.
The MSX hardware allows the user to input a range of notes over an eight octave range and three separate sound (voice) channels can be used. There are two main commands, PLAY and SOUND, which between them can directly control the sound chip. The easier of the two commands is PLAY and it's that which I'll look at first.
When you first look at a typical program line using the PLAY statement, it seems a jumble of meaningless letters, for example:
If you've got an MSX micro at hand you'll hear the scale of C Major.
The principle behind the PLAY statement is that it's a command with a host of subcommands hidden within the main statement. Therefore to sound the musical note 'D', you would type: Play "D"
All notes are written in this fashion and to flatten or sharpen a note, the stage '—' or '+' are added respectively. Therefore G Sharp would be written as: Play "G+"
The notes played will always be in the octave from middle C to B above middle C unless you specify a certain octave, which is a quirk in the MSX BASIC language. To do this you use the letter 'D' followed by a number (1 to 8), where 1 is the lowest octave and 8 the highest. So to play two octaves of the scale C Major from middle C, we might write the program like this:
20 Play A$
Note that I have put all the commands within a string variable, A$ which can be interpreted by the PLAY command. An alternative to the above would be use the same data but inserting a new octave when appropriate as in the next example.
20 PLAY "04"
30 PLAY C$
40 PLAY "05"
50 PLAY C$
60 PLAY "06C"
Remember that the default octave is 4 (middle C onwards) but once a new octave is specified, all the notes following the command will be played in the new octave range unless re-specified.
The remaining sub-commands control various parameters such as volume, duration and tempo. They work in a similar way and are embedded within the PLAY statement usually just before the note(s) to which they refer. I'll not cover these as they can be found in any MSX manual and it is the control of the physical structure of a waveform to which I now turn.
This is the most complicated aspect of the MSX sound chip and requires careful thought if any meaningful sound is to be achieved. To understand how the waveform can be manipulated requires a basic knowledge of how the sound chip works and its limitations. Don't worry if the following is a bit jargonised as you'll be able to proceed to create effects without an in-depth comprehension, though the more you understand, the wider your range of effects will be.
The PSG (Programmable Sound Generator) has fourteen 8-bit registers, in the range 0 to 13. These registers can be written to with a range between 0 to 255. The registers control all aspects of the sound output of the machine and by writing directly to these registers, the sound produced can be directly manipulated by the user.
The first six registers (0 to 5) are concerned with the 3 voice channels. Register 0 controls the lower 8 bits of the frequency of voice channel A whilst register 1 controls the upper 4 bits of voice A. The same applies to voice B, which is set from registers 2 and 3, and registers 4 and 5 control channel C.
Before looking at the remaining 8 registers let's consider the waveforms that the PSG can generate. To a certain extent the shape of a sound wave can be altered and within an MSX machine it is possible to use 8 different waveforms. Figure 1 shows these waveforms.
We can use the PLAY command to see their effect and in doing so we have to use two further sub-commands, 'M' and 'S'. These will allow sound effects to be produced which are normally outside the range of sounds in the PLAY command. Try the following:
10 PLAY "m805s8a"
This will play the note 'A' but using 'M' and 'S' commands. 'M' sets the envelope period used by the PSG. The range for this is 1 to 65535. The shape of the waveform is altered by the 'S' parameter and this value can be in the range 1 to 15. However, take note that there are only 8 waveforms, those being the shapes shown in Figure 1. The other numbers merely repeat another waveform.
The best way of understanding how these commands work is to replace the number after 'S' with each of the 8 waveform numbers. Try altering the 'M' value as well. You should be able to see how altering the 'M' statement affects the 'S' command. To help you, try the following line using 50, 255, 600, 900, 1500, 1800, 5000 and 8000 for 'M' and also varying the 'S' variable as appropriate.
10 PLAY "m200s1404cdefgabo5c"
For a piano-like sound try 'M' at 5000 and 'S' at 11.
Now back to the SOUND command. I earlier described the first few registers of the sound chip. The command that controls these registers is the SOUND statement and this has two partners. The first parameter indicates the register being used and the second value a figure between 0 to 255. As I described the first six parameters are concerned with the three voice channels. Life now becomes more difficult! The remaining eight registers determine the amplitude control, noise and manipulation of the envelope. Let's start with the easiest first.
Register 13 controls the envelope shape. Registers 8 to 10 are similar except they refer to channels A to C respectively, so I'll just explain register 8. This determined the control of amplitude for the voice channels. The setting in this register will fix whether the amplitude is fixed or variable and therefore under envelope selection.
Register 6 is the noise generator and register 7 is the mixed control register. This allows the mixing of tone and noise and is controlled by the bottom 3 bits which enable tone control and the middle 3 bits enabling noise control. These are arranged in reverse order where channel C comes first, B second and A last (ie least significant). 0 enables mixing and 1 disables the voice.
Finally registers 11 and 12 control the envelope period, where 11 is the lower 8 bits and 12 the upper 8 bits.
Confused? Well it's not really so bad. The effective way of mastering the SOUND command is to play around with the various registers bearing in mind what each register is controlling. To enable a sound or noise a string of SOUND commands need to be played in sequence. For instance the next example is an explosive sound effect.
10 SOUND 0,0: SOUND 6,250: SOUND 7.82
20 SOUND 2,130: SOUND 8,16: SOUND 13.0
Another way of sampling the seemingly endless range of effects is to write a short sampling program to try out different ideas. The next program will allow you to set all 13 registers and create as many sounds as you like.
10 DIM REG (255)
20 REM *****
30 REM Line 50 clears all the sound registers
40 REM *****
50 FOR Y=0 TO 13: SOUND Y, 0: NEXT
60 REM *****
70 REM lines 90 to 120 — input loop for register info
80 REM *****
90 FOR Y=0 TO 13
100 PRINT "Enter value for register";Y
110 INPUTREG (Y)
130 REM *****
140 REM Lines 160 to 180—execute SOUND commands
150 REM *****
160 FOR Y=0 TO 13
170 SOUND Y, REG (Y)
190 PRINT "Do you want another sound (Y/ N)?"
200 A$ = INKEY$: IF A$= "" THEN 200
210 IF A$="Y" OR A$="y" THEN 55
And finally! You don't need a CX5M to use a keyboard. It's possible to utilise the QWERTY keyboard as a means of playing a makeshift piano-like keyboard. The final program will allow you to play the top row of alphabetic keys (QWERTY etc) as the 'white' keys of a piano and the row above (the numeric keys) as the 'black' keys.
10 DIM X$(14)
20 PLAY "V15T255"
40 FOR Y = 1 TO 13
50 READ X$(Y)
60 NEXT Y
70 X$=INKEY$:IF X$= "" THEN 70 ELSE 80
80 FIND = INSTR (S$,XS)
90 PLAY X$(FIND): GOTO 70
When running the program ensure the CAPS LOCK is 'on' as 'S$' uses upper case characters. If you wish to combine more than one voice it is possible to play channels in unison by placing them together in one statement and separating them by a coma, such as:
PLAY "CDECEDE", "EFGEGEG", "GABGBGB"
And that concludes this brief introduction to sound and music on the MSX micro. The above should give you a firm basis from which to build and with some work you should be able to create a range of effects."