Skip to content
Game 0 Unit 11 of 15 1 hr learning time

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.

73% of Meet BASIC

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:

ZX Spectrum beeper · BEEP
BEEP 1, 0 — one second of middle C

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:

ZX Spectrum beeper · BEEP in a FOR loop
A rising octave — thirteen short beeps climbing one semitone at a time

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:

ZX Spectrum beeper · BEEP
BEEP 0.4, -24 — a short, low buzz, two octaves below middle C

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 0BEEP 0, 0 plays for no time. And the volume on your machine or emulator needs to be up.
  • The program froze for a moment. That's BEEP working — it holds the program while the note plays. A BEEP 5, 0 ties it up for five whole seconds.
  • Integer out of range or 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 n from 0 down to -12 with STEP -1 for a descending run.
  • Two-tone alert. Play a high note, then a low one, twice — a two-note alarm.
  • Tune the fanfare. Change 0.1 to 0.05 for a quicker flourish, or widen the range past 12 for more than an octave.

What you've learnt

  • BEEP length, pitch plays one tone: length in seconds, pitch in semitones from middle C.
  • Negative pitch is below middle C; 12 semitones is an octave.
  • BEEP holds the program until the note finishes.
  • A FOR loop 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.