The Machine Can Sing
Make a sound in one line. BEEP plays a note — you give it a length and a pitch — and a FOR loop turns a row of notes into a rising fanfare. The title card gets its voice.
The Spectrum makes sound with a single keyword. BEEP plays one tone — you tell it how
long and how high — and that's enough to build a fanfare, a warning, or the blip
under a footstep. This unit is for the ears: each result is a clip to play.
Milestone 1 — one note
10 BEEP 1, 0
BEEP 1, 0 plays for 1 second at pitch 0. The pitch is counted in semitones
from middle C, so 0 is middle C itself. One line, one note:
The first number is the length in seconds; the second is the pitch. Change either and the note changes.
Milestone 2 — a fanfare
Put BEEP inside a FOR loop and the count becomes the pitch. Each pass plays a note one
semitone higher, so the notes climb:
10 FOR n = 0 TO 12
20 BEEP 0.1, n
30 NEXT n
n runs 0 to 12 — a full octave — and BEEP 0.1, n plays each step for a tenth of a
second. The title card has its fanfare:
Twelve semitones is an octave, so the last note is exactly one octave above the first. The loop you learned in Unit 7 just became music.
Milestone 3 — a low buzz
A negative pitch goes below middle C. A short, deep note makes a "wrong answer" buzz:
10 BEEP 0.4, -24
BEEP 0.4, -24 is two octaves below middle C (24 semitones down), short and low:
A high quick beep reads as "yes"; a low buzz as "no". You'll use both in every game — for a hit, a win, a loss, a tick of the clock.
When it doesn't work
- No sound at all. Check the length isn't
0—BEEP 0, 0plays for no time. And the volume on your machine or emulator needs to be up. - The program froze for a moment. That's
BEEPworking — it holds the program while the note plays. ABEEP 5, 0ties it up for five whole seconds. Integer out of rangeor a silent note. Extreme pitches fall outside what the beeper can play; keep within a few octaves of middle C.
Before and after
You started with a silent machine and finished giving it a voice — a single note, a
rising fanfare, and a low buzz — all from one keyword. The idea underneath: BEEP length, pitch plays a tone; pitch is semitones from middle C, negative for lower; and a
loop turns notes into a tune.
Try this
- A falling buzz. Loop
nfrom 0 down to -12 withSTEP -1for a descending run. - Two-tone alert. Play a high note, then a low one, twice — a two-note alarm.
- Tune the fanfare. Change
0.1to0.05for a quicker flourish, or widen the range past 12 for more than an octave.
What you've learnt
BEEP length, pitchplays one tone: length in seconds, pitch in semitones from middle C.- Negative pitch is below middle C; 12 semitones is an octave.
BEEPholds the program until the note finishes.- A
FORloop over the pitch turns single notes into a tune.
What's next
The title card has a place, a palette, and a voice. One surface left: shapes. In Unit
12 we draw with light — PLOT, DRAW, and CIRCLE put pixels on the screen, and a
frame goes round the title.