top of page

LOADING...

SCREECH

Vintage & Modern Tech Blog

  • Stephen Nichol

< FIVE MINUTE BASIC #7 - Funky Algebraic Sound

Up until now, my < Five Minute BASIC listings have, once run, only contained text and graphics, both of which are visual elements.

The original ZX Spectrum could also produce sound through it's internal beeper. This was by no means the most advanced sound available on a home computer at the time of it's launch(1982) but, following the soundless ZX80 and the hook-up-to-a-cassette-player or buy an add-on for sound ZX81, it did provide the user with integrated sound capabilities as part of Sir Clive's mission to create an affordable computer programmable by anyone from ages 11 to elderly.

The notes on the 48k ZX Spectrum ran from -60 (described as 'clicks') to 69 (described as 'barely audible'). In between these sat the notes from the bottom to the top of the bass and treble stave, with nought being middle C.

They were controlled with the command 'BEEP duration, pitch' where the duration was a decimal or whole number from 1 to 10 indicating how many seconds the note at pitch -60 to 69 should be played. To save your sanity while using BEEP, you may like to know that 10 seconds can seem like a VERY long time when only one note is playing.

Mathematically, the sequence of numbers representing the notes goes up in twos, with one added or subtracted for a sharp or flat note so, from middle C to the next octave looks like this:

Observe: C# can ambigiously be D flat as can all the sharps be flats of their respective notes.

Musical Note: C C# D D# E F F# G G# A A# B C

ZX BEEP Pitch: 0 1 2 3 4 5 6 7 8 9 10 11 12

For my first short sound program, I'm going to make a sound effect using a FOR...NEXT loop with a LET statement inside that loop. Here's the listing:

1 REM Funky Algebraic Sound

2 REM by Stephen Nichol 2014

10 FOR n=0 TO 11 STEP 1

20 LET t=0.01

30 BEEP t,n

40 BEEP t+0.01,n+1

50 BEEP t+0.02,n+2

60 BEEP t+0.03,n*2

70 NEXT n

Explanation/Refresher (if required)

Lines 1 and 2 are REMarks and have no effect on the running of the program.

Line 10 begins the FOR...NEXT loop makes the value n (in this program representing the pitch or note) go from 0 (middle C) to 11 (note B) in steps of 1 each time the loop occurs.

Line 20 is a LET statement, defining the time. This is how we will make our notes of a different length within the same FOR...NEXT loop using algebra.

Line 30 plays a BEEP sound for time t at not n (so, always 0.01 seconds, and notes 0 to 11 in succession).

Line 40 plays a second note at t + 0.01, which equals 0.02 seconds. The note it plays is n + 1, so one note higher than the note in line 30.

Line 50 plays a third note at t + 0.02 = 0.03 seconds, and n + 2 meaning 2 notes higher than in line 30.

Line 60 is different we do the obvious of adding t + 0.03 to make a total note duration of 0.04 seconds, but this time we multiply the note by 2, meaning the ZX Spectrum produces notes ranging from 0 (because nought time two is zero) to 22 ( Eleven times two ).

Line 70, the NEXT statement loops back to the FOR statement in line 10, and moves the note 'n' up by one.

Further Activities

1. Try changing the values in Line 10 and running the program.

Remember that the highest number in the original program is twice that of the value in Line 10 so, a number of higher than 34 will produce an error in Sinclair BASIC.

2. Try changing the time value in Line 20 to a number of your choice from 0 to 10, then run the program again.

3. Try changing Line 10 so the numbers are the other way around and STEP is a minus value, that is type in 10 FOR n = 11 to 0 STEP -1. For this to work, you must include the minus in front of the number 1 (after step).

28 views

Related Posts

See All
bottom of page