KEMBAR78
c64 Users - Guide 07 Creating - Sound | PDF | Piano | Sound
0% found this document useful (0 votes)
51 views12 pages

c64 Users - Guide 07 Creating - Sound

This document provides information about programming sound on the Commodore 64 computer. It discusses the structure of a typical sound program and explains the important sound settings, including volume, attack/decay, sustain/release, waveform control, and high/low frequency. It also provides a sample sound program for readers to experiment with and demonstrates how to generate different musical tones and sound effects by adjusting the settings.

Uploaded by

PaulBarriwhite
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views12 pages

c64 Users - Guide 07 Creating - Sound

This document provides information about programming sound on the Commodore 64 computer. It discusses the structure of a typical sound program and explains the important sound settings, including volume, attack/decay, sustain/release, waveform control, and high/low frequency. It also provides a sample sound program for readers to experiment with and demonstrates how to generate different musical tones and sound effects by adjusting the settings.

Uploaded by

PaulBarriwhite
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

USING SOUND IF YOU'RE NOT A COMPUTER

"PROGRAMMER"
Most programmers use computer sound for two purposes: making
music and generating sound effects. Before getting into the "intricacies"
of programming sound, let's take a quick look at how a typical sound
program is structured . . . and give you a short sound program you can
experiment with.

STRUCTURE OF A SOUND PROGRAM


To begin with, there are five settings which you should know in order
to generate sound on your COMMODORE 64: VOLUME, ATTACK! DE-
CAY, SUSTAIN/RELEASE(ADSR), WAVEFORM CONTROL and HIGH
FREQUENCY/LOWFREQUENCY.The first three settings are usually set
ONCE at the beginning of your program. The high and low frequency
settings must be set for EACH NOTE you play. The waveform control
starts and stops each note.

SAMPLESOUND PROGRAM
Before you start you have to choose a VOICE. There are 3 voices.
Each voice requires different sound setting numbers for Waveform, etc.
You can play 1, 2 or 3 voices together but our sample uses only VOICE
NUMBER 1. Type in this program line by line . . . be sure to hit the
RETURNkey after each line:
First clear sound chip. 5 FORL=54272T054296:
POKEL,O:NEXT
1. Set VOLUME at highest setting. 113 POKE54296,15
2. Set ATTACK/DECAY rates to 213 POKE54277,1913
define how fast a note rises to and
falls from its peak volume level (0
to 255).
3. Set SUSTAIN/RELEASEto define 313 POKE 54278,248
level to prolong note and rate to
release it.
4. Find the note/tone you want to 40 POKE54273,17:POKE54272,37
play in the TABLE OF MUSICAL
NOTES in Appendix M an~ enter
the HIGH-FREQUENCY and LOW-
FREQUENCY values for that note
(each note requires 2 POKEs).

80
5. S.tart WAVEFORMwith one of 50 POKE54276,17
4 standard settings (17, 33, 65
or 129)..
6. Enter a time loop to set the 60 FORT=1T0250:NEXT
DURATION of the note to be
played (a quarter note is approx.
"250" but may vary since a longer
program can affect the timing).
7. Turn off note. 70 POKE54276,16

To hear the note you just created, type the word RUN and then hit the
.:~;!III~U.key. To view the program type the word LISTand hit .:~;!III:U.,
To change it, retype the lines you want to alter.

MAKINGMUSIC ON YOUR COMMODORE64

You don't have to be a musician to make music on your COMMODORE


64! All you need to know are a few simple numbers which tell your
computer how loud to set the volume, which notes to play, how long to
play them, etc. But first. . . here's a program which gives you a quick
demonstration of the COMMODORE 64's incredible music!:capabilities,
using only ONE of your computer's 3 separate voices.
Type the word NEW and hit .:~;!III:U. to erase your previous pro-
gram, then enter this program, type the word RUN and hit the .:~;!nl:~I.
key.

5 REM MUSICAL SCALE t Titleof p'ogram.

7 FORL =542721054296: POKEL,~:NEXT


10 POKE 54296,15 ( Se" volume at highe.t .e"ing (15).

20 POKE 54277 I 9 ( Set. A"acklOecay


Sustain/Release level (each note)
30 POKE 54276,17 ( Determine. waveform (type of sound).

40 FORT=1T0300:NEXl( Duration (how long) each not. plays.


50 READ A ( Read. fitSt numbe, in line 110 DATA.

81
60 READ B ( Read. .ecand numbe, In line 110 DATA.

70 IFB= -lTHENEND ( ,ENDSwhenI. REAo.-1 In line 900.


80 POKE 54273,A: POKE54272, B '(-POKE. 'he.fi... numbed,omDATA
In line 110(A= 17)
as HIGH FREQUENCY and second numb.r (8=37)

as LOW fREQUENCY. Next time program loops

around it READS A as 19 and B as 63, and so on,

and POKEsthese numbers into the HIGH and LOW

fREQUENCY locations. The number ~4273=HIGH

FREQUENCY fo, VOICE I and 54272=lOW FRE-

QUENCY fo, VOICE I.

85 POKE 54276, 17 ( Sta" nole.

90 FORT=1T0250:NEXT:POKE54276,16 let It play then $lop note


95 FORT=lT050:NEXT( Time fo, ,.1.0...
100 GOT020 ( .loop. back to ,e..' CONTROLoed play new note.

110 I DATA 17,37,19,63,21,154,22,227 Mu.lcal note valued'om no'e value chart In Appendix
120 DATA'25,177,28,214,32,94,34, 175 M. Each pal, of numbe.. ,ep,e.enls one note. Fa,
eJlomple. 17 and 37 represent "C" of the Ath DC-

toye, 19 and 63 repr.sent "0" and so on.

900 DATA-l,-l<, When program reaches -1 it turns oH HIGH/LOW


FREQUENCY se"ing' and ENOs as instructed in

line 70.

To change the sound to a "harpsichord," change Line 85 to read


POKE54276,33 and Line 90 to read FORT=1T0250:NEXT:POKE54276,32
and RUN the program again. (To change the line, hit the 1:1.111''''1111:.11
key
to stop the program, type the word LIST and hit .:4;11I1111_,
then retype
the program line you ""';'antto change; the new line will automatically
replace the old one). What we did here is change the "waveform" from
a "triangular" shaped sound wave to a "sawtooth" wave. Changing the
WAVEFORM can drastically change the sound produced by the COM-
MODORE 64 . . . but. . . waveform is only one of several settings you
can change to make different musical tones and sound effects! You can
also change the ATTACK/DECAYrate of each note. . . for example, to
change from a "harpsichord" sound to a more "banjo" sound try chang-
ing lines 20 and 30 to read:

20 POKE54277,3
30 POKE54278,0 <' Sets no sustoin for bonjo effect.

82
As you've just seen, you can make your COMMODORE 64 sound like
different musical instruments. Let's take a closer look at how each sound
setting works

IMPORTANT SOUND SETTINGS


1 VOLUME-To turn on the volume and set it to the highest level, type:
POKE 54296,15. The volume setting ranges from 0 to 15 but you'll use 15
most of the time. To turn "off" the volume, type:

POKE 54296,0
You only have to set the volume ONCE at the beginning of your pro-
gram, since the same setting activates all three of the Commodore 64's
VOICES. (Changing the volume during a musical note or sound effect
can produce interesting results but is beyond the scope of this introduc-
tion.)
2. ADSR and WAVEFORM CONTROL SmlNG-You've already seen
how changing the waveform can change the sound effect from
"xylophone" to "harpsichord." Each VOICE has its own WAVEFORM
CONTROL SETTING which lets you deflne four different types of
waveforms: Triangle, Sawtooth, Pulse (Square) and Noise. The CON-
TROL also activates the COMMODORE 64's ADSR feature, but we'll
come back to this in a moment. A sample waveform start setting looks
like this:
POKE 54276,17
where the flrst number (54276) represents the control setting for VOICE 1
and the second number (17) represents the start for a triangular
waveform. The settings for each VOICE and WAVEFORM combination
are shown in the table below.

ADSR AND WAVEFORM CONTROL SETTINGS


CONTROL Note Start/Stop Numbers
REGISTER TRIANGLE SAWTOOTH PULSE NOISE
VOICE 1 54276 17/16 33/32 65/64 129/128
VOICE 2 54283 17/16 33/32 65/64 129/128
VOICE 3 54290 17/16 33/32 65/64 129/128

Although the control registers are different for each voice the
waveform settings are the same for each type of waveform. To see how
83
this works, look at lines 85 and 90 in the musical scale program. In this
program, immediately after setting the frequency in line 80, we set the
CONTROL SETTING for VOICE 1 in line 85 by POKEing 54276,17. This
turned on the CONTROL for VOICE 1 and set it to a TRIANGLE
WAVEFORM (17). In line 70 we POKE 54276,16, stopping the note. la-
ter, we changed the waveform start setting from 17 to 33 to create a
SAWTOOTH WAVEFORMand this gave the scale a "harpsichord" effect.
See how the CONTROL SETTING and WAVEFORM interact? Setting the
waveform is similar to setting the volume, except each voice has its own
setting and instead of POKEing volume levels we're defining waveforms.
Next, we'll look at another aspect of sound. . . the ADSR feature.
3. AnACKIDECAY SEnING-As we mentioned before, the ADSR
CONTROL SETTING not only defines the waveform but it also activates
the ADSR, or AnACKIDECAY/SUSTAIN/RELEASEfeature of the COM-
MODORE 64. We'll begin by looking at the ATTACK/DECAY setting. The
following chart shows the various ATTACKand DECAYlevels for each
voice. If you're not familiar with the concepts of sound attack and de-
cay, you might think of "attack" as the rate at which a note/sound arises
to its MAXIMUM VOLUME. The DECAY is the rate at which the note/
sound falls from its highest volume level back to the SUSTAIN level. The
following chart shows the ATTACK/DECAYsetting for each voice, and the
numbers for each attack and decay setting. Note that YOU MUST
COMBINE ATTACK AND DECAY SETTINGS BY ADDING THEM UP AND
ENTERINGTHE TOTAl. For example, you can set a HIGH ATTACK rate
and a LOW DECAY rate by adding the high attack number (64) to the
low decay number (1). The total (65) will tell the computer to set the high
attack rate and low decay rate. You can also increase the attack rates
by adding them together (128 + 64 + 32 + 16 = MAX. ATTACKRATE
of 240).
AnACKIDECAY RATESEnlNGS
ATTACK/DECAY HIGH MEDIUM LOW LOWEST HIGH MED. LOW LOWEST
SETTING ATTACK ATTACK ATTACK ATTACK DECAY DECAY DECAY DECAY
VOICE 1 54277 128 64 32 16 8 4 2 1
VOICE 2 54284 128 64 32 16 8 4 2 1
VOICE 3 54291 128 64 32 16 8 4 2 1

If you set an attack rate with no decay, the decay is automatically


zero, and vice-versa. For example, if you POKE 54277,64 you set a
medium attack rate with zero decay for VOICE 1. If you POKE 54277,66
you set a medium attack rate and a low decay rate (because 66=64+2
and sets BOTH settings). You can also add up several attack values, or
several decay values. For example, you can add a low attack (32) and a

84
medium attack (64) for a combined attack rate of 96, then add a
medium decay of 4 and. . . presto. . . POKE 54277,100.
At this point, a .sample program will better illustrate the effect. Type
the word NEW, hit .:~:lImu. and type in this program and RUN it:

5 FOR L=54272T054296:POKEL,0:NEXT ~ Duration the not. pia)".

10 PRINT"HIT ANY KEY" ~ Scr..n meuage.

20 POKE54296, 15 ~
30 POKE54277,64 ~ Set AttocWDecay.

40 POKES4273, 17:POKE54272,37~ Poke on. note into VOICE 1.

60 GETK$:IFK$=""THEN60 ~ Check the keyboard.

70 POKES4276,17:FORT=lT0200:NEXT~ Set v.bveform comrol (triangle).

S0 POKES4276, 16:FORT=lTOS0:NEXT ~ Turn off settings.

90 GOT020 ~ Loop back ond do it again.

Here, we're using VOICE 1 to create one note at a time . . . with a


MEDIUMATTACKRATEand ZERO DECAY.The key is Line 40. POKEing the
ATTACK/DECAY setting with the number 64 activates a MEDIUM attack
rate. The result sounds like someone bouncing a ball in an oil drum.
Now for the fun part. Hit the I:Ullr"'III:I key to stop the program, then
type the word LISTand hit .:~IIIII:~I.. Now type this line and hit .:~IIIII:U.
(the new line 40 automatically replaces the old line 40):

40 POKE 54277,190

Type the word RUN and hit .:~IIIII~I. to see how it sounds. What we've
done here is combine several attack and decay settings. The settings
are: HIGH ATTACK(128) + LOW ATTACK(32) + LOWEST ATTACK(16)
+ HIGH DECAY(8) + MEDIUMDECAY(4)+ LOW DECAY(2)= 190.
This effect sounds like a sound an oboe or other "reedy" instrument
might make. If you'd like to experiment, try changing the waveform and
attack/decay numbers in the musical scale example to see how an
"oboe" sounds. Thus . . . you can see that changing the attack/decay
rates can be used to create different types of sound effects.
4. SUSTAIN/RELEASE SEnING-Like , Attack/Decay, the SUSTAIN!
RELEASEsetting is activated by the ADSRiWAVEFORMControl. SUSTAINI
RELEASElets you "extend" (SUSTAIN)a portion of a particular sound, like
the "sustain pedal" on a piano or organ which lets you pr~long a note.
Any note or sound can be sustained at anyone of 16 levels. The
SUSTAIN!RELEASESetting may be used with a FOR. . . NEXT loop to

85
determine how long the note will be held at SUSTAIN volume before
being released. The following chart shows the numbers you have to
POKE to reach different SUSTAIN/RELEASE,rates.

SUSTAIN/RELEASE RATE SETTINGS


SUSTAIN! HIGH LOWEST
CONTIIOL SUSTAIN SUSTAIN

As an example, if you're using VOICE1, you can set a HIGH SUSTAIN


lEVELby typing: POKE 54278,128 or you could combine a HIGH SUSTAIN
lEVEl with a lOW RELEASERATE by adding 128 + 2 and then POKE
54278,130. Here's the same sample program we used in the ATTACK!
DECAY section above. . . with a SUSTAIN/RELEASEfeature added.
Notice the difference in sounds.

5 FORl=54272T.054296:POKEl,0:NEXT <; Duration the note plays.

10 POKE54296,15 ., Set volume at highest level.

20 POKE54277,64 ., Set Attack/Decay.

30 POKE54278, 128., Set Sustain/Release

40 POKE54273, 17:POKE54272,37 ., POKE one note into VOICE 1.

50 PRINT"HIT ANY KEY"., .Scr..n message.

60 GETK$:IFK$=" "THEN60 ., Check the keyboard.

70 POKE54276, 17:FORT=lT0200:NEXT ., Set v.bvefonn control (triangle).

80 POKE54276,16:FORT=lT050:NEXT<; Turn off settings.

90 GOT060 <; loop back and do it agoin.

In line 30, we tell the computer to SUSTAINthe note at a HIGH SUS-


TAIN lEVEL(128 from chart above) . . . after which the tone is released
in line 80. You can vary the duration of a note by changing the "count"
in line 70. To see the effect of using the release function try changing
line 30 to POKE54278,89 (SUSTAIN = 80, RELEASE = 9),
5. CHOOSING VOICES AND SETTING HIGH/LOW FREQUE'NCY
SOUND VALUES-Each individual note on the Commodore 64 requires
TWO SEPARATEPOKE COMMANDS. . . one for HIGH FREQUENCYand
one for lOW FREQUENCY.The MUSICALNOTE VALUEtable in Appendix
M shows you the corresponding POKEs you need to play any note in the

86
Commodore 64's eight octave range. The HIGHand LOW FREQUENCY
POKE COMMANDS are different for each VOICE you use-this allows
you to program all 3 voices independently to create 3-voice music or
exotic sound effects.
The HIGH and LOW FREQUENCYPOKE COMMANDS for each voice
are shown in the chart below, which also contains the NOTE VALUESfor
the middle (fifth) octave.

VOICE NUMBER POKE SAMPLE MUSICAL NOTES-fiFTH OCTAVE


!ER C C# D D# E f f# G G# A A# B C C#
VOICE1/HIGH 54273 34 36 38 40 43 45 48 51 54 57 61 64 68 72
VOICE1/l0W 54272 75 85 126 200 52 198 127 .97 111 172 126 188 149 169
VOICE2/HIGH 54280 34 36 38 40 43 45 48 51 54 57 61 64 68 72
VOICE2/l0W 54279 75 85 126 200 52 198 127 97 111 172 126 188 149 169
VOICE3/HIGH 54287 34 36 38 40 43 45 48 51 54 57 61 64 68 72
VOICE3/l0W 54286 75 85 126 200 52 198 127 97 111 172 126 188 149 169

As you can see, there are 2 settings for each voice, a HIGH FRE-
QUENCY setting and a LOW FREQUENCYsetting. To playa musical note,
you must POKE a value into the HIGH FREQUENCYlocation and POKE
another value into the LOW FREQUENCYlocation. Using the settings in
our VOiCE/FREQUENCY/NOTEVALUEtabJe, here's the setting that plays
a C note from the 5th octave (VOICE1):

POKE 54273,34:POKE 54272,75.

The same note on VOICE2 would be:

POKE 542813,34:POKE 54279,75.

Used in a program, it looks like this:

5 FORL=54272T054296:POKEL,0:NEXT
10 V=54296:W=54276:A=54277: (-- Set numbers equal to letters.

S=54278:H =54273:L=54272
20 POKEV,15:POKEA,190:POKES,89 <; POKE volume, waveform, attack/decay.

30 POKEH,34:POKEL,75 -: POKE hi/lo freq. notes

40 POKEW,33:FORT=1T0200:NEXl-: start note, let it play

50 POKEW,32 ~ stop note

87
PLAYING A SONG ON THECOMMODORE64

The following program can be used to compose or playa song (using


VOICEl). There are two important lessons in this program: First, note
how we abbreviate all the long control numbers in the first line of the
program. . . after that, we can use the letter W for "Waveform" instead
of the number 54276.
The second lesson concerns the way we use the DATA.This program
is set up to let you enter 3 numbers for each note: the HIGH FREQUENCY
NOTE VALUE,the LOW FREQUENCY NOTE VALUE,and the DURATION
THE NOTE WILLBE PLAYED.
For this song, we used a duration "count" of 125 for an eighth note,
250 for a quarter note, 375 for a dotted quarter note, 500 for a half
note and 1000 for a whole note. These number values can be increased
or decreased to match a particular tempo, or your own musical taste.
To see how a song gets entered, look at Line 100. We entered 34
and 75 as our HIGHand LOWFREQUENCYsettings to playa "C" note
(from the sample scale shown previously) and then the number 250 for a
quarter note. So the first note in our song is a quarter note C. The
second note is also a quarter note, this time the note is "E" . . . and so
on to the end of our tune. You can enter almost any song this way,
adding as many DATAstatement lines as you need. You can continue the
note and duration numbers from one line to the next but each line must
begin with the word DATA. DATA-l,-I,-1 should be the last line in your
program. This line "ends" the song.
Type the word NEW to erase your previous program and type in the
following program, then type RUN to hear the song.

MICHAELROW THE BOATASHORE-l MEASURE

2 FORL=54272T054296:POKEL,0:NEXT .
5 V=54296: W=5427 6:A=54277: HF=54273:LF =54272:5 =54278:
PH=54275:PL=54274
10 POKEV,15:POKEA,88:POKEPH,15:POKEPL,15:POKE5,89
20 READH:IFH= -HHENEND
30 READL
40 READD
60 POKEHF,F:POKELF,L:POKEW,65
80 FORT=lTOD:NEXT:POKEW,64
85 FORT=H050:NEXT

88
90 GOT010
100 DATA34,75,250,43,52,250,51 ,97,375,43,52, 125,51 ,97
105 DATA250,57,172,250
110 DATA51,97,500,0,0, 125,43,52,250,51 ,97,250,57, 172
115 DATA1000,51,97,500
120 DATA-1,-1,-1

CREATING SOUND EFFECTS


Unlike music, sound effects are more often tied to a specific pro-
gramming "action" such as the explosion made by an astro-fighter as it
crashes through a barrier in a space game. . . or the warning buzzer in
a business program that tells the user he's about to erase his disk by
mistake.
You have a wide range of options available if you want to create
different sound effects. Here are 10 programming ideas which might
help you get started experimenting with sound effects:

1. Change the volume while a note is playing, for example to create


an "echo" effect.
2. Vary between two notes rapidly to create a sound "tremor."
3. Waveform . . . try different settings for each voice.
4. Attack/Decay. . . to alter the rate a sound rises toward its "peak"
volume and rate it diminishes from that peak.
5. Sustain/Release. . . to change sustain to volume of a sound effect,
and rate it diminishes from that volume.
6. Multivoice effects . . . playing more than one vO,ice at the same
time, each voice independently controlled, or one voice playing
longer or shorter than another, or serving as an "echo" or response
to a first note.
7. Changing notes on the scale, or changing octaves, using the values
in the MUSICAL NOTE VALUEtable.
8. Use the Square Waveform and different Pulse Settings to create
different effects.
9. Use the Noise Waveform to generate "white noise" for accenting
tonal sound effects or creating explosions, gunshots or footsteps.
The same musical notes that create music can also be used with the
Noise Waveform to create different types of white noise.
1O. Combine several HIGH/LOW frequencies in rapid succession across
different octaves.
11. Filter . . . try the extra POKE setting in Appendix M.

89
SAMPLE SOUND EFFECTSTO TRY

The following programs may be added to almost any BASIC program.


They are included to give you some programming ideas and demon-
strate the Commodore 64's sound effect range.
Notice the programming shortcut we're using in line 10. We can
abbreviate those long cumbersome sound setting numbers by defining
them as easy-to-use letters (numeric variables). line 10 simply means
that these easy to remember LETTERScan be used instead of those long
numbers. Here, V = Volume, W=Waveform, A=Attack/Decay, H=High
Frequency (VOICE1), and L= Low Frequency (VOICEl). We then use these
letters instead of numbers in our program . . . making our program
shorter, typing faster, and the sound settings easier to remember and
spot.

DOLL CRYING

10 V=54296:W=54276:A=54277: H=54273:L=54272
20 POKEY,15:POKEW,65:POKEA, 15
30 FORX= 200T05STEP-2: POKEH,40: POKEL,X:NEXT
40 FORX= 150T05STEP-2:POKEH,40:POKEL,X:NEXT
50 POKEW,0

SHOOTINGSOUND. . . USINGVOICE1,NOISEWAVEFORM,
FADING
VOLUME

10 V=54296:W=54276:A=54277:H =54273:L=54272
20 FORX= 15T00STEP-l:POKEV,X:POKEW, 129:POKEA,
15:POKEH,40:POKEL,200:NEXT
30 POKEW,0:POKEA,0

90

You might also like