<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>


10 Sound

The sound chip built into the TI-99/4A has three sound channels and a single noise channel. All channels can be in use simultaneously.

The stack signature for the SOUND word is as follows:

    SOUND ( pitch volume channel -- )

Where:

Note: When addressing the noise channel, valid values for pitch are 0 to 7 inclusive.

If you are used to TI BASIC you are probably wondering where the duration value is. There isn't one. It's entirely dumb. SOUND simply writes to the sound chip and it's done. It's up to you to end notes/sounds at the appropriate time in your code. To end a note, simply set the volume of that channel to 15.

10.1 Supplementary Sound Words

The only sound-related word in the TurboForth ROM is SOUND, as described above. However, the following supplementary words are very useful and offer a superior level of control over the sound chip:

10.1.1 Example Usage

To use:

   0 1017 TONE

Will play a low A on channel 0. Note: the codes for the notes are given below.

   0 0 VOLUME

...will set channel 0 to maximum volume (15 is off).

Here is an A chord:

   0 1017 TONE
   1 807 TONE
   2 679 TONE

Then set the volume:

   0 0 VOLUME
   1 0 VOLUME
   2 0 VOLUME

Note: You only have to set the volume for each channel once. Unless you want to change the volume, of course.

To stop a tone from playing, set its volume to 15.

Here is a test program:

   1 VALUE STEP
   : TEST 0 0 VOLUME 1017 20 DO 0 I TONE STEP +LOOP 0 15 VOLUME ;

Now, you can play around like this:

   1 TO STEP TEST
   2 TO STEP TEST
   10 TO STEP TEST

etc. etc.

The noise channel takes a value from 0 to 7 for the different types of noise. Use a value of 3 for the channel number number when you want to change the volume of the noise channel.

10.2 Code Equivalents of the Supplementary Sound Words

The words given above are very useful and quite fast. They are also useful to see how to address the sound chip in high-level code. However, in normal use, one would want sound-related words to process as quickly as possible in order to give more time to other things, especially when developing games etc. To that end, machine code versions of the above words are given below. Usage is identical to the words given above. They occupy 114 bytes of memory.

10.3 Frequency Constants

The values corresponding to musical notes are given here. They are taken from the Editor/Assembler Owner's Manual by Texas Instruments (see pages 318 to 320) © 1982 . If anyone has a more accurate table then please get in touch (see contact information on the home page).

Frequency Constants for all three Tone Generators
Octave 0 Octave 1 Octave 2 Octave 3 Octave 4 Octave 5 Octave 6
Note Decimal Hex Decimal Hex Decimal Hex Decimal Hex Decimal Hex Decimal Hex Decimal Hex
C n/a n/a 855 357 428 1AC 214 D6 107 6B 53 35 27 1B
C# n/a n/a 807 327 404 194 202 CA 101 65 50 32 25 19
D n/a n/a 762 2FA 381 17D 190 BE 95 5F 48 30 24 18
D# n/a n/a 719 2CF 360 168 180 B4 90 5A 45 2D 22 16
E n/a n/a 679 2A7 339 153 170 AA 85 55 42 2A 21 15
F n/a n/a 641 281 320 140 160 A0 80 50 40 28 20 14
F# n/a n/a 605 25D 302 12E 151 97 76 4C 38 26 n/a n/a
G n/a n/a 571 23B 285 11D 143 8F 71 47 36 24 n/a n/a
G# n/a n/a 539 21B 269 10D 135 B7 67 43 34 22 n/a n/a
A 1017 3F9 508 1FC 254 FE 127 7F 64 40 32 20 n/a n/a
A# 960 3C0 480 1E0 240 F0 120 78 60 3C 30 1E n/a n/a
B 906 38A 453 1C5 226 E2 113 71 57 39 28 1C n/a n/a

<-- Back to Tutorials


<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>