Sinclair ZX Spectrum
The W must be followed by a number from 0 to 7 which controls how the sound builds up (the attack) or fails off (the decay). This is the full range of numbers and what they do

Volume effects diagram; 4641 bytes. 0 single decay then off
1 single attack then off
2 single decay then hold
3 single attack then hold
4 repeated decay
5 repeated attack
6 repeated attack-decay
7 repeated decay-attack

This program plays the same note with each effect in turn to let you hear what they sound like

10 LET a$="UX1000W0C&W1C&W2C&W3C&W4C&W5C&W6C&W7C"
20 PLAY a$

Notice the U to turn on the effect, then the series of W numbers.

There is one other new command used here, the letter X. This can be followed by a number from 0 to 65535 to set the length of the sound effect - the larger the number, the longer the effect is drawn out.

You do not have to include an X setting. If you do not, the Spectrum 128 will automatically choose the longest. In general, repetitive effects (W4 to 7) are more effective with quite short settings, e.g. X300.'Single shot' effects (W0 to W3) need a longer period, eg X1000. Try changing the value after X in the program above to hear the difference.


The speed at which a piece of music is played can be set with the command T followed by the number of crotchet beats per minute (bpm) in the range 60 to 240. The command controls the speed at which all notes are played, but can only be included in channel A (the first string after the PLAY command) otherwise it is ignored, e.g.

10 LET a$="T180cdefg"
20 PLAY a$

If no tempo is specified, the music will be played at 120 bpm.

Repeated phrases

Any musical phrase can be repeated by enclosing the appropriate string or part of a string in brackets. For example

10 LET a$="abC(DEFG)"

will repeat the last four notes. If there is an unequal number of brackets, the phrase will be repeated back to the last bracket. If there is only a closing bracket, the phrase will be repeated back to the beginning of the string, e.g.

10 LET a$="abCDEFG)"

will repeat all seven notes. Double closing brackets

10 LET a$="O2CEGA))"

will cause an 'infinite' repeat. This is particularly useful for things like repetitive bass lines. To turn off an 'infinite' repeat you use the H command.

The H command

An H included in any string immediately turns off the PLAY command. The main use of this is where you have an infinitely repeated bass line in one string. You can stop this at the end of the tune by putting an H on the end of the string which plays the melody.

Sinclair ZX Spectrum

  Previous Page Back Next Page