CHAPTER 17

Sound


Generating sound can be very simple. For simple sounds there are four audio channels, each controlled by two control registers.


GENERATING SOUNDS

To generate a sound in channel 1, put the frequency and volume codes into the frequency and control registers. The frequency register for channel 1, AUDF1 [$D200 (53760)] can have any number from 0 to $FF (255). 0 causes the highest frequency; 255 causes the lowest. The volume/noise (control) register for channel 1, AUDC1 [$D201 (53761)] is more complicated.

            Audio channel control (volume/noise) register

7 6 5 4 3 2 1 0 ----------------- AUDCx | noise | volume| ----------------- 1 6 3 1 8 4 2 1 2 4 2 6 8

The noise bits can have various values. The best way to learn to use them is by experimentation. The technical details of the polynomial counters which generate the noise has little bearing on what is heard. The two special values of interest are: $1 (volume+16 in decimal), which causes a DC voltage proportional to the volume bits and; $A (volume+160), which causes a pure tone (square wave). The volume bits select the relative volume, 0=off. Therefore, the number, $A8 (168 [8+160]) in AUDC1, will cause the frequency selected by AUDF1 to be a pure tone of medium volume.

In BASIC the dirty work is done fore you. The SOUND command will do all the calculations for you. The Sound command format is shown below.

The BASIC sound command format

      SOUND channel,frequency,noise,volume

The channel numbers is 0 to 3 instead of 1 to 4. The frequency, 0 to 255, is put into the frequency register. The noise is put into the high bits of the channel control register with volume in the low bits. Therefore...

      SOUND 0,125,10,8

will produce a pure tone of medium frequency and volume in channel 0 (called channel 1 in assembly language).


ADVANCED SOUND

The Audio Control register, AUDCTL [$D208 (53768)], (not to be confused with the four audio channel control registers), adds more control for assembly language programmers. Again, to go into technical details will be less productive than experimentation.

             The audio control register. (AUDCTL)

7 6 5 4 3 2 1 0 ----------------- AUDCTL | | | | | | | | | ----------------- 1 6 3 1 8 4 2 1 2 4 2 6 8

7 0 = 17 bit polynomial noise 1 = 9 bit below polynomial noise 6 0 = clock channel 1 with 64 KHz 1 = clock channel 1 with 1.79 MHz 5 0 = clock channel 3 with 64 KHz 1 = clock channel 3 with 1.79 MHz 4 0 = clock channel 2 with 64 KHz 1 = clock channel 2 with channel 1 3 0 = clock channel 4 with 64 KHz 1 = clock channel 4 with channel 3 2 1 = insert logical high-pass filter in channel 1, clocked by channel 3 1 1 = insert logical high-pass filter in channel 2, clocked by channel 4 0 0 = 64 KHz main clock 1 = 16 KHz main clock

All bits of AUDCTL are normally zero. The BASIC sound command causes it to be reset to zero.

By clocking one channel with another, the range can be increased. This essentially allows two channels with twice the range as each of the four normal channels. This is called 16 bit sound.

To calculate exact frequencies, use the following formulas. The exact clock frequencies are also given if more accuracy is needed. The clock frequencies are acquired by dividing the signal from the TV color-burst crystal. This crystal has a frequency of 3.579545 MHz.

                      Clock frequencies:

1.7897725 MHz (color-burst/2)

63.920446 Khz (color-burst/56)

15.699759 KHz (color-burst/228)

Formulas:

For 1.79 MHz

clock clock f = ------------ f = ------------ 2(AUDFn + 7) 2(AUDFn + 4)

16 bit 8 bit

AUDFn is the number in the audio frequency register.

For 16 KHz and 64 KHz

clock f = ------------ 2(AUDFn + 1)


AUDIO TIMER INTERRUPTS

When the audio timers count down to zero they generate IRQ interrupts (if enabled). The timers can be reset by writing any number to STIMER [D209 (53769)].


THE CONSOLE SPEAKER

The console speaker is where key clicks and the cassette signals come from. On XL and XE models this speaker is heard through the TV speaker. It is operated by toggling bit 3 of CONSOL [$D01F (53279). This bit always reads 0 but it is actually set to 1 during vertical blank.

     Useful data base variables and OS equates

     CONSOL $D01F          (53279): bit 3 controls console speaker
     AUDF1  $D200          (53760): Audio frequency 1
     AUDC1  $D201          (53761): audio control 1
     AUDF2  $D202          (53762): Audio frequency 2
     AUDC2  $D203          (53763): audio control 2
     AUDF3  $D204          (53764): Audio frequency 3
     AUDC3  $D205          (53765): audio control 3
     AUDF4  $D206          (53766): Audio frequency 4
     AUDC4  $D207          (53767): audio control 4
     AUDCTL $D208          (53768): general audio control
     STIMER $D209          (53769): audio timer reset


Go to chapter 16
Go to chapter 18