Sound Off
What you'll learn:
- Use `POKE` to trigger simple tones via the SID chip.
- Control pitch, duration, and envelope for basic sound effects.
- Combine loops and sound to build a short melody or alert.
Lesson 7 – Sound Off
You’ve made the screen move—now let’s make the C64 sing. The SID chip is legendary for a reason, and with a few POKE
s you can coax it into bleeps, bloops, and budding melodies. Today’s goal: trigger a tone, shape it, and use loops to stitch notes together.
[📷 suggested: photo of a C64 with speakers pulsing]
The One-Minute Tour
- SID voice 1 lives at addresses
$D400
–$D40E
(decimal54272
–54286
). - Frequency = two bytes; envelope = attack/decay (
$D405
), sustain/release ($D406
). - Gate bit turns the sound on/off.
- Use delay loops to control note length.
Example Program
NEW
10 REM --- INITIALISE SID VOICE 1 ---
20 POKE 54295,15 : REM maximum volume
30 POKE 54296,0 : REM no filters for now
40 POKE 54273,0 : REM low byte of frequency
50 POKE 54272,50 : REM high byte (50 ≈ middle C)
60 POKE 54275,17 : REM attack/decay (1 frame attack, 7 frame decay)
70 POKE 54276,240 : REM sustain/release (full sustain, fast release)
80 POKE 54277,33 : REM waveform = triangle + gate on (32+1)
90 FOR T=1 TO 200: NEXT T
100 POKE 54277,32 : REM gate off (leave waveform select)
Run it: you’ll hear a soft triangle wave blip around middle C.
Lines 40–50 set the pitch.
Lines 60–70 define the volume envelope (how quickly the note ramps up and fades).
Line 80 opens the gate; line 100 closes it.
Tip: Frequencies come from tables—
50
in the high byte is a decent starting point. We’ll refine pitch selection soon.
Experiment Section
- Change the waveform:
POKE 54277,65
(pulse + gate) or129
(sawtooth + gate). - Adjust attack/decay:
POKE 54275,33
for slower attack, shorter decay. - Try different frequencies: set line 50 to
100
(higher pitch) or25
(lower). - Build a siren: loop frequency from low to high using
FOR F=20 TO 120
. - Combine with animation—play a tone each time your bouncing star hits a wall.
[🎥 suggested: clip showing a simple pitch sweep and animation sync]
Concept Expansion
The SID has three voices; we’ve used one. Each voice can play a waveform with its own envelope. Later you’ll mix voices for chords, add filters, and even trigger arpeggios inside the Assembly course. For now, learn the anatomy of a single note.
Game Integration
- UI cues: play a short tone when menus open or choices register.
- Collision sound: different frequencies for hits vs. misses.
- Victory jingle: loop through a small array of notes to celebrate success.
- Alarm: randomly choose from a set of pitches for warning effects.
From the Vault
- SID: The Sound of the C64 — deep dive into waveforms, envelopes, and why the SID sounds so rich.
Quick Reference
REM SID Voice 1 essentials
POKE 54295, V : REM master volume (0-15)
POKE 54272, FHI : REM frequency high byte
POKE 54273, FLO : REM frequency low byte
POKE 54275, AD : REM attack/decay packed into one byte
POKE 54276, SR : REM sustain/release packed into one byte
POKE 54277, WF : REM waveform + gate bit (1=triangle, 17=triangle+gate)
- Frequencies are little-endian: low byte at 54273, high byte at 54272.
- Waveform bits: triangle 16, sawtooth 32, pulse 64, noise 128; add 1 to set the gate.
- Always gate off (
AND 254
) before changing waveforms to avoid clicks.
What You’ve Learnt
- How to address the SID registers for voice 1.
- How attack, decay, sustain, and release shape the note.
- Controlling pitch and note duration with loops and gate toggles.
- Your programs can now accent their graphics with sound cues and simple tunes.
Next lesson: Mini-Game: Typing Turmoil — combine input, timing, and sound into your first eight-lesson showdown.