Classic Computer Magazine Archive COMPUTE! ISSUE 52 / SEPTEMBER 1984 / PAGE 146


Mike Steed

The Commodore 64 has an amazing sound chip, and anyone who has heard it knows this. However, anyone who has tried to program it may have been surprised or discouraged, because everything had to be done with POKEs. That is, until now. "SYSound" will make creating sounds much easier, using absolutely no POKEs at all. Also included is an example program to show how easy programming 64 music can be.

Type in Program 1 and be sure to save a copy before running it. Program 1 loads in SYSound, which is a machine language program, and one typing mistake can crash SYSound when you use it. You may wish to save a copy of just the machine language once it's loaded, if you have a machine language monitor. Program 1 will specify the start and end addresses.

To use SYSound, all you need to do is type SYS 49152 followed by any of several possible parameters, each separated by a comma. The number 49152 could (and probably should) be put into a variable, such as S or SOUND.

A list of possible parameters for the SYS statement and their meanings follows:

  • Vx, where x is the voice number used for the note (one, two, or three). More than one voice may be used at the same time.
  • Ax, where x is the attack rate of the note. This is the time it takes the sound to reach its highest volume. The value of x must be between 0 and 15; the larger the number, the more time it takes. (See the figure for a further description of attack, decay, sustain, and release.)
  • Dx, where x is the decay rate of the note (0–15). This is the time it takes the sound to soften to the sustain volume.
  • Sx, where x is the sustain level of the note (0–15). The sound remains at this volume until the release starts.
  • Rx, where x is the release rate of the note (0–15). The release rate is the time it takes the sound to drop from the sustain volume to silence.
  • Wy[x], where y is a letter representing the waveform used for the sound. This can be N (noise), S (sawtooth), T (triangle), or P (pulse). If the pulse waveform is chosen, then a pulse rate x (0–4095) must be entered after the waveform letter, such as WP2048 for a square wave.
  • Fx, where x is the frequency of the note (0–65535). Higher frequencies will produce higher notes.
  • Lx, where x is the volume (loudness) of the note (0–15). Note that this is the overall volume, so all the voices will be affected by this setting.
  • C clears the sound chip. This is equivalent to the following in BASIC:
10 S = 54272 : FOR I = 0 TO 24 : POKE S + I, 0 : NEXT

Once a parameter has been entered, it need not be entered the next time the routine is used. For example, if all your sound effects are going to be done with voice 1, at volume 15, with the sawtooth waveform, attack 0, decay 9, and sustain and release 0, you could set all these at the beginning of your program:

10 S = 49152 : SYS S, C, V1, L15, WS, D9

(All parameters default to zero initially, so A, S, and R needn't be entered.) Then all that would need to be done to play a note would be:

20 SYS S, F5000

(Any valid numeric expression may be used after the parameter letter.) Also, if a parameter is entered more than once, only the last case will be considered. For example, SYS S, WS, WT, A0, A6 is effectively the same as SYS S, WT, A6.

Program 2 provides an example of SYSound in action, and 'shows how much simpler music programming can be accomplished.