SuperForth for the Tatung Einstein, showing a SuperForth 1.12 session defining a word
← Back to Courses
module
25

Making A Noise

Introduction

The Einstein has a sound chip with three voices, which can each hold a note while the program gets on with something else. SuperForth's sound words are on the disc, in the smallest extension of all: one screen.

Loading

NEWFILE SOUNDS
1 LOAD

Three Steps To A Note

The three voices are called A, B and C. To hear one you have to do three things.

Switch the voice on. CHANNEL takes six flags, 1 for on and 0 for off. The last three are the tones, for C, B and A in that order. (The first three switch on noise instead of a tone; this course does not use them.) So tone on voice A alone is:

0 0 0 0 0 1 CHANNEL

Set the pitch. FREQA takes the pitch in hertz - vibrations a second. 440 FREQA is the A that orchestras tune to. Double the number and the note goes up an octave.

Set the volume. VOLA takes 0 to 15. 0 VOLA is silence.

The note then carries on sounding until you change it or turn it down. SuperForth does not wait for it; the chip holds the note by itself. That is why a tune needs a fourth ingredient: something to make the program wait while each note lasts.

Waiting

An empty loop does it:

3000 0 DO LOOP

That takes about a fifth of a second. It is crude, and honest: the machine counts to three thousand and does nothing else.

The Code

NEWFILE SOUNDS
1 LOAD
: NOTE FREQA 12 VOLA
3000 0 DO LOOP ;
: TUNE 0 0 0 0 0 1 CHANNEL
262 NOTE 294 NOTE 330 NOTE
262 NOTE 0 VOLA ;
TUNE

Starting from

A fresh boot, with SuperForth just started - and, in MAME, with its sound and your computer's turned on.

What you should hear

Four quick notes, a fifth of a second each: C, D, E, and C again. It is the opening of Frere Jacques. Then silence, because TUNE finishes with 0 VOLA. Leave that off and the last note sounds for ever.

Some Notes

NoteHertzNoteHertz
C262G392
D294A440
E330B494
F349C523

More Voices

Voices B and C have their own words: FREQB and VOLB, FREQC and VOLC. Turn on more than one tone in CHANNEL and you can play chords:

0 0 0 1 1 1 CHANNEL
262 FREQA 330 FREQB 392 FREQC
10 VOLA 10 VOLB 10 VOLC

Change One Thing

  • Change the 3000 in NOTE to 9000. How long is each note now?
  • Take the 0 VOLA off the end of TUNE. How do you stop the noise?
  • Play the same tune an octave higher, changing as little as you can.
  • Play the three-voice chord above. Then silence it, with one line.

Exercises

25.1 Finish the first line of Frere Jacques: C D E C, C D E C.

25.2 Define SIREN to sweep the pitch from 300 up to 900 and back, using two loops and +LOOP.

25.3 Define BEEP ( hz -- ) so that a game could call it, and use it in the guessing game from S20: a low beep for a wrong guess, a high one for the right one.

Worked solutions are in Appendix II.

When It Goes Wrong

SymptomCause
SilenceOne of the three steps is missing: CHANNEL, a pitch, and a volume above 0. Or, in MAME, its sound or your computer's is off.
A note that never stopsNothing turned it down. 0 VOLA.
A tune that is over in a blinkNo waiting between the notes.
FREQA?The sounds are not loaded.

Summary

With SOUNDS loaded, CHANNEL switches voices on with six flags, FREQA sets voice A's pitch in hertz and VOLA its volume from 0 to 15. A note sounds until it is turned off, so a tune is notes separated by waiting, with a 0 VOLA at the end.

Next

S26, Decimal Points - numbers that are not whole, and what they cost.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.