Personal Computer News


QL Sound Explorer

 
Published in Personal Computer News #094

Make a sound investment of the time it takes to tap in James Lucy's listings.

Sound Barrier

Make a sound investment of the time it takes to tap in James Lucy's listings

The Sinclair QL has brought a new level of computing power within reach of its owners; however, the sound capabilities are a different matter. Compred with even the Vic 20 (of fond memory), the QL sound system looks archaic and crude - a single-channel, no volume control and a piezo-electric transducer.

To make matters worse, the controlling commands from Basic are clumsy and unpredictable, and the process of extracting useful sounds is largely a matter of trial and error. However, all is not lost and we will try to illustrate here that it is possible to produce some exciting sounds on the QL, assisted by two programs - Sound Explorer and Music Maker.

As the QL user manual implies, the only way to learn about the workings of the system is to experiment. The problem is that the BEEP command, the only sound command on the QL, can be followed up to eight parameters which results in experimentation being a tedious and unsatisfactory process. What is more, most parameters are not truly independent, so changing one alters the effect of the others. The answer is provided by Program 1, which I have called a Sound Explorer.

It starts by setting all the BEEP parameters to 1 and produces the resulting sound. All the parameters may then be changed by pressing the appropriate keys while the screen displays the current values and the 'loudspeaker' emits the corresponding noise. The program can be used to see how changes in specific parameters affect the overall sound and for developing specific sounds - when you find one you like, simply make a note of the parameters.

In one sense the range of sounds is almost infinite, although all the sounds I have found so far are of similar type - rather non-musical and very electronic sounding. Nevertheless, if you can bear the noise a half-hour's experimentation will produce some surprising sounds, and there is always the 'peace' facility within the program.

BEEP Parameters

Duration is the first parameter of BEEP which allegedly defines the duration of the sound in units of 72 microseconds. This commendable precision did not seem to apply to my machine although it is quite true that a duration value of 10000 gave the expected duration of approximately 0.72 seconds; however, higher or lower values did not change the actual duration in proportion, a situation made worse by the necessity to start again with a value of -32768 once positive values up to 32767 have been exhausted. (If this sounds complicated it's because it is.) Incidentally, a duration value of 32767 gave about 1.9 seconds of sound on my computer compared to the expected 2.36 seconds.

There is, of course, another way of controlling the duration of a note which seems more reliable, but it has the disadvantage of stopping further program execution while the note is sounding. The method is to BEEP with duration 0, which paradoxically gives indefinite sound, to BEEP the required time, and then to PAUSE with no parameters which kills the sound.

A further problem with duration values is illustrated by this short program:

 10 REPeat loop
 20 BEEP 0,10
 30 PAUSE 25
 40 BEEP -1,10
 50 PAUSE 25
 60 END REPeat loop

You will see that the program should give a continuous high pitched tone, pitch 10, but actually sounds like an out of tune police siren. This illustrates the fact that BEEPing duration 0 affects the specified pitch - all other values for duration give the correct tone. All in all the duration parameter could do with more development.

The second and third parameters of BEEP are pitch1, the main pitch and pitch2, the secondary pitch. The sound will move between these levels if encouraged by grade_x and grad_y, the fourth and fifth parameters. The pitches can take values between 0 and 255, 0 being the highest frequency. Values higher than 255 can be used, but the pitch produced seems to be pitch MOD 255. The range of notes produced is quite wide, but the lower notes are rather unmusical.

Values of 160 downwards produce notes which can be used in music generation and according to my tuning fork the 'C' at 256Mz is approximated by pitch value 33 (assuming avoidance of the pitch varying properties of duration 0). Other approximations are given in program 2, which is a modest attempt to allow playing of short tunes over a range of one octave.

One final point on pitch - it is possible to produce subjectively higher tones than that produced by a pitch value of zero by using appropriate values for other parameters. The sound explorer will let you find out how - try all parameters = 0 except grade_x = -1.

Grad_x and grad_y are the fourth and fifth parameters of the BEEP command. The idea is that the pitch moves in steps of size grad_y between pitch1 and pitch2, the rate of this movement being controlled by grad_x. That is the theory but in practice it proved difficult to see the parameters working as expected. Experimentation with the sound explorer is the best policy here.

Wraps, Fuzziness, and Random are the sixth, seventh and eighth parameters. Wraps is mysteriously named iin that it is difficult to see how the sound wraps or what it wraps round. The effect on the sound is quite dramatic in most cases and seems to be a kind of repeating sound at the end of each movement between pitch1 and pitch2. Lower values of wraps give more comprehensible results.

Fuzziness and Random serve to further modify the sound and to further complicate the situation. Neither is very predictable and they appear to have very little effect until they near their maximum values, when both tend to produce 'noise' rather than tones.

If you have followed this article so far and have tried the sound explorer, you hopefully will have discovered that sound on the QL can be interesting, it can also be infuriatingly convoluted and perverse, in which respect it is quite in keeping with the whole computer.

QL Sound Explorer Program Notes

QL Sound Explorer (the first listing given below) works by setting up a loop in which key presses are detected and the appropriate changes made to the selected BEEP parameters. The loop (lines 210 to 490) is entered after introductory formalities have been completed, and consists of an INKEY instruction (line 230) to wait for a key press, and a SELECT ON instruction (line 240) to take the appropriate action.

Although the method of actually displaying changes to the parameters appears rather lengthily coded the idea has been to 'hide' as many instructions as possible behind the ON instruction, thus speeding program execution. PROCedure instructions simply display instructions if required.

The spaces in the text (lines 520 to 540) have been carefully arranged to give a neat display - ignore them at your peril!

PROCedure keys is responsible for the on screen caption of the keys to be used to change the various parameters, and PROCedure headings displays the names of the parameters being changed, and PROCedure parameter, which uses values passed from the main program, displays the actual value of the parameter. This method was chosen rather than a complete reprint of parameter values to maximise speed around the loop. As PROCedure parameter is widely used in the program, it is suggested it is given a shorter name when typing in, for example 'p'.

The program is largely self-explanatory in use. The seven parameters pitch1,pitch2,grade_x,grad_y,wraps,fuzzy and random are increased by one by pressing the keys 'q-w-e-r-t-y-u', and decreased by one of the keys 'a-s-d-f-g-h-j' (note lower case). In addition the parameters which have a range of values - pitch1, pitch2, grad_x and wraps have a fast forward and rewind in the keys 1-2-3-4, z-x-c-b.

Reference to the keyboard will show that the keys are logically and conveniently arranged. The only other key necessary is 'F1', which in the interests of sanity of the user, mutes the sound.

QL Music Maker Program Notes

QL Music Maker is intended to work on a TV set, but better graphics could be obtained on a monitor in Mode 4. It allows the playing and display in conventional musical notation of a short tune and is intended to be a demonstration of the (rather limited) musical capabilities of the QL. The program can play along quite nicely with someone trying to learn the descant recorder, and would make a useful training aid - one of the more difficult aspects of learning an instrument is knowing how the music should sound.

The program works by loading arrays with pitch and duration in the loader loop (lines 220-520). It passes the pitch and duration values to PROCdrawnote, which draws the appropriate note in the next available position; PROCdrawnote also calls PROCstave, which draws the five line stave when required. For program brevity bar lines and a time signature have been omitted, but could be included by adding an INPUT statement and a counting device in the PROCdrawnote.

Once the arrays have been loaded and terminated using pitch 'z', they are playing using the FOR-END FOR at lines 560 to620. As the notes are played, a white marker line is drawn under the note being sounded. As this marker is drawn and erased in the time between notes the drawing time required can make the music staccato. If this is unacceptable, delete the drawing instructions in lines 550 to 620. The sound is produced by the BEEP command at line 590 - note the use of duration - 1 rather than the expected zero to avoid the pitch distorting effects mentioned elsewhere.

As a final point on this program it would be quite easy to make it a good deal more sophisticated by increasing the range of notes, including rests and providing room for a greater tune length, however, because the notes are approximations, peple with perfect pitch had better try a Commodore 64.

The program requests input of a note and a duration. The 'enter' key should be pressed after each note and each duration. A pitch other than 'a-b-c-d-e-f-g' will be ignored. The duration can be 0.5, 1, 1.5, 2, 3 or 4 where a value of 1 gives a crotchet. Other numerical values will be ignored but a letter will give an error. No harm results - simply type 'continue'.

When 45 notes have been entered, the program will ask you to hit any key to play the tune. If only a short tune is required, terminate the input with note 'z', pitch '1'. Type Ctrl-Space to escape the program.

James Lucy