The Plus/4 has a total of two voices thanks to its integrated TED chip, which is also responsible for rendering text and graphics on screen. The first voice can play square waves, while the second one can generate either square wave sounds or white noise.
Let’s see how we can make him play a tune.
We can use some BASIC keywords to make the Plus/4 be all musical. First we need to turn up the volume by using the VOL command. We can set this to anything between 0 and 8.
Next we can use the SOUND command to make each channel play a note, like so:
This will play a one-second long note on channel 1.
The first parameter designates the sound channel (1 or 2 to play tones, or 3 to play noise on channel 2). The second parameter is a value between 0 and 1023, indicating how low or high the note is played. The third parameter is the duration in 1/60th increments of a second. So a duration of 60 means the note plays for one whole second.
Here’s an example of a simple sound effect we can create with the above commands:
10 vol 8
20 for x=1 to 5
30 for i=900 to 1023
40 sound 3,i,1
60 next i
70 next x
The values for how high a note is played seem rather arbitrary. For example, 440 does not result in a frequency of 440 Hz (or a reference A note), but some note between a very low F# and G.
There is a secret formula however with which we can figure out what value to plug into the SOUND command to play a desired frequency. Here it is:
Z = 1024 – INT(111860.781/F)
Our result Z will be the numeric value for a Frequency (F) we’d like to play. TO stick with the above example, to play a note with a frequency of 440 Hz, the result would be 770 (as calculated with that special formula).
Thanks to Cyndie Merton and Sarah Meyer for this tip!