Sounds

Developer(s): George Chambers
Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Sound

This program is a collection of sound effects and audio demonstrations implemented as independent BASIC routines, each accessible by running from a specific line number. The effects include a BPO telephone ring, two-tone siren, galloping horses, motor noise, a digital watch beep, and an explosion sequence. Most routines use nested FOR loops with carefully tuned BEEP durations and pitches to simulate acoustic characteristics. The “Stop Tape” warning (line 111) is a reusable subroutine that cycles INK and PAPER colors via a swap idiom and displays a flashing banner across all 22 screen rows. Line 131 uses SOUND with multiple channel parameters for the explosion effect, which is distinct from the BEEP-based routines.


Program Structure

The listing is organized as a set of self-contained sound routines, each preceded by a REM label and occupying a block of lines at round-number boundaries (10, 20, 30, …, 130). There is no menu or dispatcher; the user runs a desired routine by typing GO TO followed by the appropriate line number. Each routine either loops indefinitely with GO TO back to itself, uses STOP, or (in the case of the “Stop Tape” warning) falls through to a continuation message.

Individual Routines

LinesEffectLoop style
10–15BPO telephone ringingInfinite GO TO 10
20–25Background ambienceInfinite GO TO 20
30–31Motor runningInfinite GO TO 30
40–45Fast descending scaleSingle pass, STOP
50–51Two-tone sirenInfinite GO TO 50
60–61Filler soundInfinite GO TO 60
70–75Warning signalInfinite GO TO 70
80–85Digital watchInfinite GO TO 80
90–100Galloping horsesInfinite GO TO 90
110–120Stop Tape warningSelf-contained, exits to demo loop
130–131ExplosionSingle pass (no loop-back)

BEEP Technique

All audio except the explosion uses BEEP duration, pitch. Durations are kept very short (as low as .003 seconds) to create percussive or rapid-fire effects. Pitch values are in semitones relative to middle C; negative values (e.g., BEEP .005,-2 in the motor routine) produce sub-middle-C tones. The galloping horses routine (lines 90–100) modulates PAUSE duration using 6-f/5 and 25-f, expressions that tighten the inter-beat gap as the loop variable f increases, then loosen it on the return sweep, simulating acceleration and deceleration.

SOUND-Based Explosion

Line 131 uses SOUND with a multi-register syntax (6,x;7,7;8,16;9,16;12,140;13,1) rather than BEEP, giving direct access to the sound chip’s noise, envelope, and mixer registers. The loop counts x from 30 down to 10, varying the noise period register to sweep the character of the explosion. This is the only routine in the collection that goes beyond the BEEP abstraction.

Stop Tape Warning Routine

Lines 111–120 implement a reusable “Stop Tape” display. A classic color-swap idiom is used: LET c=a:LET a=b:LET b=c alternates INK and PAPER between values 1 and 6 on each of the 22 screen rows, producing a striped flashing banner. FLASH 1 is applied inside the PRINT AT statement. Line 115 prints to stream #1 (the lower screen) to show a prompt without disturbing the main display. The keypress detection loop at lines 116–118 plays a BPO-style ring tone; INKEY$ is checked at line 117 and branches to GO TO 119 (CLS and continuation) when any key is pressed. Note that the NEXT g and NEXT f on line 118 reference loop variables whose FOR statements are on line 116, which is syntactically valid but results in the outer loops being abandoned on a keypress.

Potential Anomalies

  • The galloping horses routine uses PAUSE 6-f/5; when f reaches 20, this evaluates to 2, which is still positive, but if f exceeded 30 the expression would go negative — PAUSE with a negative argument behaves as PAUSE 0, so the loop bounds prevent an actual error here.
  • Line 118 has NEXT g:NEXT f but the enclosing FOR g is opened on line 116 and the FOR f loop wraps both. If the keypress branch at line 117 fires, the interpreter jumps to 119, leaving the FOR–NEXT stack in an undefined state; a CLS at line 119 does not clear the stack, which could cause issues if this routine is embedded in a larger program.
  • Line 120 loops indefinitely on a PRINT statement with no exit, intended only as a demonstration placeholder.

Key BASIC Idioms

  • Nested FOR loops with computed pitch arithmetic (e.g., f+g-h, g+h-f, h+f-g) in the background sound routine to generate pseudo-random tonal variation.
  • Immediate GO TO at the end of a block to create infinite sound loops without using GO SUB.
  • Combined BEEP/PAUSE interleaving to shape rhythm, as in the telephone and digital watch routines.

Content

Appears On

Related Products

Related Articles

Related Content

Image Gallery

Source Code

    1 REM 
    2 REM  A collection of sounds           for use in programs    
    3 REM   Taken from the book           "Better programming for         your Spectrum and ZX81"  
    4 REM Entered by G F Chambers
    5 REM 
   10 REM  BPO telephone ringing
   11 FOR f=1 TO 10:FOR g=1 TO 2:FOR h=1 TO 8:BEEP .03,24:NEXT h:PAUSE 6:NEXT g:PAUSE 50:NEXT f
   15 PAUSE 200:GO TO 10
   20 REM     Background sound
   21 FOR f=2 TO 10 STEP 2:FOR g=1 TO 10 STEP 2:FOR h=1 TO 10 STEP 2:BEEP .1,f+g-h:BEEP .1,g+h-f:BEEP .1,h+f-g:NEXT h:NEXT g:NEXT f
   25 PAUSE 200:GO TO 20
   30 REM  Sound of motor running
   31 BEEP .005,5:BEEP .005,-2:PAUSE 2:GO TO 30
   40 REM  Fast descending scale
   41 FOR f=1 TO 50:BEEP .05,60-f:NEXT f
   45 STOP 
   50 REM  Sound of 2-tone Siren
   51 BEEP .6,18:BEEP .7,14.5:GO TO 50
   60 REM  Filler Sound
   61 FOR f=1 TO 10:BEEP .1,1+f:BEEP .1,10:NEXT f:GO TO 60
   70 REM  Warning signal
   71 FOR f=1 TO 30:BEEP .05,20:BEEP .05,0:NEXT f
   75 GO TO 70
   80 REM  Digital Watch
   81 FOR f=1 TO 10:BEEP .5,40:PAUSE 7:BEEP .5,40:PAUSE 35:NEXT f
   85 GO TO 80
   90 REM  Galloping Horses
   91 FOR f=10 TO 20:BEEP .003,10:PAUSE 6-f/5:BEEP .003,5:PAUSE 6-f/5:BEEP .003,1:PAUSE 25-f:NEXT f
  100 FOR f=20 TO 10 STEP -1:BEEP .003,10:PAUSE 6-f/5:BEEP .003,5:PAUSE 6-f/5:BEEP .003,1:PAUSE 25-f:NEXT f:GO TO 90
  110 REM  A STOP TAPE warning
  111 LET a=1:LET b=6:FOR i=0 TO 21
  112 PRINT AT i,8; INK a; PAPER b; FLASH 1;" STOP THE TAPE "
  113 LET c=a:LET a=b:LET b=c:NEXT i
  115 PRINT #1; AT 1,3; INK 9;"PRESS ANY KEY TO CONTINUE"
  116 FOR f=1 TO 10:FOR g=1 TO 2:FOR h=1 TO 10:BEEP .03,24:NEXT h:PAUSE 6:NEXT g
  117 IF INKEY$ <>"" THEN GO TO 119
  118 NEXT g:NEXT f
  119 CLS 
  120 FLASH 0:PRINT AT 10,1;"YOUR PROGRAM CONTINUES HERE":GO TO 120
  130 REM  An Explosion
  131 FOR x=30 TO 10 STEP -1:SOUND 6,x;7,7;8,16;9,16;12,140;13,1\{16}\{0}:NEXT x
 9999 SAVE "sounds"

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

Scroll to Top