• Aucun résultat trouvé

26 _

G

H

n

n

1

SID: The Sound Interface Device

60 POKE 54275,8:POKE 54277,9:POKE 54278,0

This sets the attack to a fast rate (0) and the decay to a longer rate (9). The sustain and release have both been set to 0 so that you can more easily hear the difference attack and decay make. Notice how the sound changes as you run this altered version. Lengthening the rate of the attack should be simple for you now. All you have to do is add 128 (which is 8*16) to the decay value of 9. The total is 137, which indicates a longer attack, as well as a long decay rate. Change line 60 again so that it reads:

60 POKE 54275,8:POKE 54277,137:POKE 54278,0 Setting the sustain and release of a note is done in the same way, by POKEing in values from Table 1-2 to the appro priate register. All you have to remember is that the sustain indicates the volume level of the note's sustain, while the release signals the rate at which a note falls from that level to volume 0. Experiment with the sound routine examples you've used so far, changing the sustain/release values POKEd into location 54278, the control register for voice 1. You'll be amazed at the different sounds you can create just by chang ing that one parameter.

Waveforms

In addition to changing the frequency, volume, and ADSR of the notes you produce, the SID also allows you to produce dif ferent waveforms. The forms available are pulse waves (which we've been using in most of the examples), triangle waves, sawtooth waves, and noise. The control register for waveform selection in voice 1 is found in location 54276. Changing the value POKEd into that location changes the waveform used to produce the note.

The pulse waves, which we've used in most of the exam ple routines up to now, have all been symmetrical (That's sometimes called a square waveform.) That is, they rise, remain at the upper peak for a period of time, fall, and remain at the valley for exactly the same length of time before repeating.

Figure 1-8 shows a symmetrical waveform.

1

SID: The Sound Interface Device

U

U

Figure 1*8* Square Waveform

Time

Whenever you select a pulse waveform, you must also place values in the pulse width registers. Read over the earlier explanation of how to select a pulse width if you've forgotten how to place values in these two registers. By adjusting the pulse width of the pulse waves, we can produce sounds that range from very full to very thin. What you're doing, in effect, is creating an asymmetrical pulse waveform.

Program 1-6. Synmietrical/Asymmetrical Waveforms

For mistake-proof program entry, be sure to read "Automatic Proofreader," Appendix C.

10 REM CLEAR SOUND REGISTERS :rem 251 20 FOR R=54272 TO 54296:POKER,0:NEXT :rem 25

30 REM - TURN ON VOLUME - :rem 95

40 POKE 54296,15 :rem 47

50 REM - INITIALIZE SPECIAL REGISTERS - :rem 78

60 POKE 54275,8 :rem 0

65 POKE 54277,0:POKE 54278,240 :rem 52 70 REM - POKE TONE VALUES INTO VOICE 1 :rem 142 80 POKE 54272,48: POKE 54273,28 :rem 55 90 REM - ENABLE TONE REGISTER - :rem 233

100 POKE 54276, 65 :rem 95

110 REM - PLAY TONE FOR 1 SECOND - :rem 16

120 FOR R=0 TO 1000: NEXT :rem 22

125 IF P=l THEN 130 :rem 168

126 P=1:POKE 54275,14: GOTO 65 :rem 54 130 REM - TURN SOUND REGISTER OFF - :rem 228

140 POKE 54276,64 :rem 98

150 REM - TURN VOLUME OFF - :rem 208

160 POKE 54296,0 :rem 44

28

LJ

Li

U u LJ

Lj

n

1

SID: The Sound Interface Device

The first tone produced by this routine is symmetrical, but the second tone is not. That's because the pulse width is first

\ s set to 50 percent in line 60 by POKEing 8 into the upper half of the two-byte pulse width register. Remember that tHe total value of the registers is the lower half value added to the / | upper half value multiplied by 256 (Lower value + (Upper

value * 256)). In this routine, only the upper register (location 54275) is used. Then, in line 126, the pulse width is changed, so that a value of 14 is POKEd into the upper register. That gives you a total of 3584 (14*256), or a pulse width of 87.5 percent. In other words, that percentage of the wave is high, or above the base line volume. If you graphed that second tone, it would look like this:

Figure 1-9. Asymmetrical Pulse Waveform

Time

Triangle waves, as their name implies, look like the tops and bottoms of triangles, just as symmetrical pulse waves look like the tops and bottoms of squares. They are always

symmetrical and produce a very soft, almost subdued sound.

Setting bit 4 of the waveform control register turns on the tri angle waveform generator. Normally, you'll set both the tri angle waveform and the.gate bit by POKEing 17 into the control register. Type in and RUN Program 1-7, which dem onstrates a triangle waveform.

n

29

u

1

SID: The Sound Interface Device r ,

Program 1*7. Triangle Waveform

For mistake-proof program entry, be sure to read "Automatic Proofreader/' Appendix C

10 REM CLEAR SOUND REGISTERS :rem 251 }_j

20 FOR R=54272 TO 54296:POKER,0:NEXT :rem 25

30 REM - TURN VOLUME ON :rem 50

40 POKE 54296,15 :rem 47 j }

50 REM - INITIALIZE SPECIAL REGISTERS - :rem 78 Lj

60 POKE 54275,8:POKE 54277,0:POKE 54278,240 :rem 3 70 REM - GET TONE FROM TONE TABLE - :rem 141 75 READ L,H: IF L=999 THEN RESTORE: GOTO 75

:rem 119 77 REM - POKE TONE VALUES INTO VOICE 1 :rem 149 80 POKE 54272,L: POKE 54273,H :rem 245 90 REM - ENABLE TONE REGISTER - :rem 233

100 POKE 54276,17 :rem 92

110 REM - PLAY TONE FOR 1/8 SECOND AND ADJUST VOLU

ME - :rem 237

120 FOR R=15 TO 0 STEP -1:POKE 54296,R:NEXT:rem 70 130 REM - TURN SOUND REGISTER OFF - :rem 228

140 POKE 54276,16 :rem 95

150 GOTO 75 :rem 59

160 REM - TURN VOLUME OFF - :rem 209

165 POKE 54296,0 :rem 49

170 REM - TONE TABLE - :rem 116

180 DATA 195,16,194,17,208,18,238,19,30,21,95,22,1 80,23,29,25,155,26,48,28,221 :rem 15 190 DATA 29,164,31,134,33,164,31,221,29,48,28,155,

26,29,25,180,23,95,22,30,21 :rem 204 195 DATA 238,19,208,18,194,17,999,999 :rem 83

Figure 1-10 shows a triangle waveform. Note that it's symmetrical, with equal high and low portions. Unlike the pulse waveform, however, you can't control the percentage of the high part of the wave to the low section. A triangle wave form is always symmetrical.

Sawtooth waves are not symmetrical. They rise slowly