Example Assets Needed:
To follow along with this chapter's examples, you'll need these sound files:
- Sound Effects (.wav): jump.wav, land.wav, hurt.wav, coin.wav, pickup.wav, laser.wav, explosion.wav, shoot.wav
- Music (.mp3): background_music.mp3 or game_music.mp3
You can find free sound effects at OpenGameArt.org, Freesound.org, or use tools like BFXR/SFXR to generate retro game sounds. For music, check out Incompetech or the Free Music Archive.
What's the difference between a game and an experience?
Sound.
Think about it. Picture Mario without the jump sound. Sonic without the ring ding. Zelda without that triumphant chest-opening fanfare. Half the magic would be GONE.
Sound isn't just decoration—it's feedback. It tells players "yes, you did that!" It builds tension. It creates atmosphere. It makes your game feel ALIVE.
And guess what? Adding sound to Crash BASIC is super easy. Let's get LOUD!
The Simplest Sound: BEEP
Let's start with the most basic sound possible:
SCREEN 13
PRINT "Press any key to BEEP!"
PAUSE
BEEP
PRINT "You beeped!"
PAUSEBEEP does exactly what you think—it makes a beep. It's not exciting, but it's SOMETHING. Great for quick feedback when you don't have custom sounds yet.
SOUND: Old-School Synthesized Tones
Want more control? SOUND lets you specify a frequency and duration:
SCREEN 13
' SOUND frequency, duration (in milliseconds)
SOUND 440, 500 ' A4 note for half a second
SOUND 880, 500 ' A5 note (one octave higher)
SOUND 220, 1000 ' A3 note (one octave lower) for 1 second
PAUSEThis creates pure synthesized tones—like an old computer! Here are some musical frequencies to play with:
| Note | Frequency |
|---|---|
| C4 (Middle C) | 262 |
| D4 | 294 |
| E4 | 330 |
| F4 | 349 |
| G4 | 392 |
| A4 | 440 |
| B4 | 494 |
| C5 | 523 |
A Simple Melody
SCREEN 13
PRINT "Playing a scale..."
' C major scale
SOUND 262, 300 ' C
SOUND 294, 300 ' D
SOUND 330, 300 ' E
SOUND 349, 300 ' F
SOUND 392, 300 ' G
SOUND 440, 300 ' A
SOUND 494, 300 ' B
SOUND 523, 600 ' C (hold longer)
PRINT "Done!"
PAUSEReal Sound Effects: WAV Files
Okay, synthesized beeps are fun for retro games, but you probably want REAL sounds—explosions, laser blasts, footsteps, the works!
That's where WAV files come in. WAV is a standard sound format that works great for short sound effects.
Loading and Playing WAV Files
SCREEN 13
' First, load the sound (do this at the start of your program)
LOADWAV "laser.wav", "laser"
LOADWAV "explosion.wav", "boom"
LOADWAV "coin.wav", "ding"
PRINT "Press L for laser, E for explosion, C for coin!"
PRINT "Press Q to quit."
DO
k$ = INKEY$
IF k$ = "l" OR k$ = "L" THEN
PLAYWAV "laser"
END IF
IF k$ = "e" OR k$ = "E" THEN
PLAYWAV "boom"
END IF
IF k$ = "c" OR k$ = "C" THEN
PLAYWAV "ding"
END IF
DELAY 16
LOOP UNTIL k$ = "q" OR k$ = "Q"The pattern is simple:
LOADWAV "filename.wav", "nickname"— Load the file and give it a short namePLAYWAV "nickname"— Play it whenever you want!
Why Load First?
Loading sounds takes time—the computer has to read the file from disk. If you loaded sounds in your game loop, there'd be a tiny pause every time you played one. Yuck!
By loading everything at the START of your program, all your sounds are ready to go instantly. No lag, no stutter.
' ===== LOADING PHASE (do this ONCE at startup) =====
LOADWAV "jump.wav", "jump"
LOADWAV "land.wav", "land"
LOADWAV "hurt.wav", "ouch"
LOADWAV "pickup.wav", "item"
' ===== GAME LOOP (sounds play instantly!) =====
DO
' ... game logic ...
IF playerJumped THEN
PLAYWAV "jump"
END IF
' ... more game logic ...
LOOPBackground Music: MP3 Files
WAV files are great for sound effects, but they're BIG. A 3-minute song as a WAV file could be 30+ megabytes!
For music, use MP3 files. They're compressed, so a whole song might only be 3-5 megabytes.
SCREEN 13
' Load the music
LOADMP3 "background_music.mp3", "bgm"
' Start playing (the 1 means LOOP forever)
PLAYMP3 "bgm", 1
PRINT "Music is playing!"
PRINT "Press S to stop, P to play again, Q to quit."
DO
k$ = INKEY$
IF k$ = "s" OR k$ = "S" THEN
STOPMP3 "bgm"
PRINT "Music stopped."
END IF
IF k$ = "p" OR k$ = "P" THEN
PLAYMP3 "bgm", 1
PRINT "Music playing!"
END IF
DELAY 16
LOOP UNTIL k$ = "q" OR k$ = "Q"
STOPMP3 "bgm"The Loop Parameter
PLAYMP3 "bgm", 0 ' Play once, then stop
PLAYMP3 "bgm", 1 ' Loop forever (for background music)For background music, you almost always want 1 (loop). For a victory fanfare or game over jingle, use 0 (play once).
MML: Music Macro Language
Here's something really cool—you can write music directly in your code using MML (Music Macro Language)! It's like a mini programming language just for music.
SCREEN 13
' Play a simple tune
PLAY "C D E F G A B >C"
PAUSEThe > means "go up one octave." The < means "go down one octave."
MML Commands
| Command | Meaning | Example |
|---|---|---|
| C D E F G A B | Notes | PLAY "C D E" |
| R | Rest (silence) | PLAY "C R E" |
| > | Octave up | PLAY "C >C" |
| < | Octave down | PLAY ">C <C" |
| O | Set octave (1-8) | PLAY "O4 C" |
| L | Note length (1=whole, 4=quarter, 8=eighth) | PLAY "L8 C D E" |
| T | Tempo (beats per minute) | PLAY "T120 C D E" |
| + or # | Sharp | PLAY "C+ D" |
| - | Flat | PLAY "B- C" |
| I | Instrument (0-66) | PLAY "I5 C D E" |
| V | Volume (0-15) | PLAY "V10 C D E" |
Synthesized Instruments
Here's where MML gets REALLY fun. The I command lets you choose from 67 different synthesized instruments! These are all generated in real-time—no sound files needed.
Basic Waveforms (I0-I9):
| # | Instrument | Sound |
|---|---|---|
| I0 | Sine beep | Pure, clean tone |
| I1 | Square chiptune | Classic retro game sound |
| I2 | Square + vibrato | Warbling chiptune |
| I3 | Pulse narrow | Thin, bright |
| I4 | Pulse wide | Fuller pulse |
| I5 | Sawtooth | Buzzy, bright |
| I6 | Sawtooth + vibrato | Expressive sawtooth |
| I7 | Triangle | Mellow, flute-like |
| I8 | Triangle + vibrato | Expressive triangle |
| I9 | Square + tremolo | Volume modulation |
Lead Instruments (I10-I19):
| # | Instrument | Sound |
|---|---|---|
| I10 | Sawtooth bass | Deep, rich low-end |
| I11 | Square lead | Bright lead |
| I12 | Sine pitch sweep | Swooping attack |
| I13 | Sawtooth lead | Sharp melodic lead |
| I14 | Triangle chorus | Spacious triangle |
| I15 | Noise channel | Percussion/effects |
| I16 | Bell | Sine with harmonics |
| I17 | Organ | Multiple harmonic layers |
| I18 | Pluck | Fast decay (string-like) |
| I19 | Pad | Slow attack (atmospheric) |
Advanced Synthesis (I20-I29):
| # | Instrument | Sound |
|---|---|---|
| I20 | FM synthesis | Complex frequency modulation |
| I21 | Distorted square | Overdriven chiptune |
| I22 | Brass-like | Rich harmonic content |
| I23 | String-like | Bowed string simulation |
| I24 | Flute-like | Airy woodwind |
| I25 | Choir-like | Multiple voice layers |
| I26 | Synth bass | Electronic bass |
| I27 | Acid bass | Filtered sawtooth |
| I28 | PWM | Pulse width modulation |
| I29 | Vocoder-like | Formant synthesis |
Percussion & Drums (I30-I39):
| # | Instrument | Sound |
|---|---|---|
| I30 | Kick drum | Deep bass drum |
| I31 | Snare drum | Snappy with noise |
| I32 | Hi-hat | Crisp high-frequency |
| I33 | Crash cymbal | Sustained crash |
| I34 | Tom drum | Pitched tom |
| I35 | Rim shot | Sharp rim click |
| I36 | Clap | Hand clap |
| I37 | Wood block | Percussive wood |
| I38 | Cowbell | Metallic bell tone |
| I39 | Shaker | High-frequency rhythm |
Special Effects (I40-I50):
| # | Instrument | Sound |
|---|---|---|
| I40 | Laser zap | Sci-fi laser |
| I41 | Explosion | Dramatic explosion |
| I42 | Power-up | Ascending game sound |
| I43 | Coin pickup | Classic arcade coin |
| I44 | Jump sound | Character jump |
| I45 | Damage sound | Hit/damage effect |
| I46 | Door creak | Slow creaking |
| I47 | Wind sound | Atmospheric wind |
| I48 | Water drop | Liquid drop |
| I49 | Bubble pop | Small bubble burst |
| I50 | Alien voice | Otherworldly vocal |
Futuristic NES Patches (I51-I58):
| # | Instrument | Sound |
|---|---|---|
| I51 | Futuristic Lead | Authentic NES 12.5% duty |
| I52 | Futuristic Arpeggio | Fast triad cycling |
| I53 | Futuristic Bass | Triangle wave, punchy |
| I54 | Futuristic Kick | Triangle pitch drop |
| I55 | Futuristic Pulse Bass | NES 25% duty |
| I56 | Futuristic Snare | Noise burst with pitch |
| I57 | Futuristic Echo Lead | 50% duty with delay |
| I58 | Futuristic Tom | Tuned triangle drum |
Gothic NES Patches (I59-I66):
| # | Instrument | Sound |
|---|---|---|
| I59 | Gothic Lead | Dramatic square vibrato |
| I60 | Gothic Strings | Sawtooth with vibrato |
| I61 | Gothic Bass | Deep, dark triangle |
| I62 | Gothic Organ | Church organ harmonics |
| I63 | Gothic Melody | NES 25% + gentle vibrato |
| I64 | Gothic Bell | Clock tower atmosphere |
| I65 | Gothic Pad | Atmospheric background |
| I66 | Gothic Accent | Sharp dramatic attack |
Using Instruments
SCREEN 13
' Play a chiptune melody
PLAY "I1 T140 L8 O4 C E G >C <G E C"
' Drum beat
PLAY "I30 L4 C P4 I31 C P4 I30 C I32 L8 C C"
' Sound effect
PLAY "I43 L16 C E G >C" ' Coin pickup!
PAUSEA Real Melody
SCREEN 13
' "Mary Had a Little Lamb" in MML
PLAY "T120 L4 E D C D E E E R D D D R E G G R"
PLAY "E D C D E E E E D D E D C"
PAUSEBackground MML Music
By default, PLAY waits until the music finishes. But what if you want the music to play while your game runs? Use the BACKGROUND keyword:
SCREEN 13
' Start music in the background
PLAY BACKGROUND "T120 L8 O4 C D E F G A B >C <B A G F E D C"
' Game can run while music plays!
FOR i = 1 TO 100
PRINT "Game running... "; i
DELAY 50
NEXT i
' Stop the background music when done
STOP PLAY
PAUSEStopping Sounds
Sometimes you need to stop a sound—maybe the player paused the game, or the background music needs to change.
' Stop specific sounds
STOPWAV "laser" ' Stop a WAV sound
STOPMP3 "bgm" ' Stop MP3 music
STOP PLAY ' Stop MML music
' Sounds can be played again after stopping
PLAYMP3 "bgm", 1 ' Resume musicReal Example: A Game with Sound
Let's put it all together! Here's a simple dodge game with full audio:
SCREEN 13
' =============================================
' LOADING PHASE - Load all sounds up front!
' =============================================
LOADWAV "jump.wav", "jump"
LOADWAV "coin.wav", "coin"
LOADWAV "hurt.wav", "ouch"
LOADMP3 "game_music.mp3", "music"
' Start background music
PLAYMP3 "music", 1
' =============================================
' GAME SETUP
' =============================================
playerX = 160
playerY = 180
playerVY = 0
onGround = TRUE
score = 0
lives = 3
coinX = INT(RND * 280) + 20
coinY = INT(RND * 100) + 50
enemyX = 320
enemyY = 180
enemySpeed = 3
' =============================================
' GAME LOOP
' =============================================
DO
' --- INPUT ---
IF KEYDOWN("LEFT") AND playerX > 10 THEN
playerX = playerX - 4
END IF
IF KEYDOWN("RIGHT") AND playerX < 310 THEN
playerX = playerX + 4
END IF
IF KEYDOWN("SPACE") AND onGround THEN
playerVY = -12
onGround = FALSE
PLAYWAV "jump" ' JUMP SOUND!
END IF
' --- PHYSICS ---
playerVY = playerVY + 1 ' Gravity
playerY = playerY + playerVY
IF playerY >= 180 THEN
playerY = 180
playerVY = 0
onGround = TRUE
END IF
' --- ENEMY MOVEMENT ---
enemyX = enemyX - enemySpeed
IF enemyX < -20 THEN
enemyX = 340
enemySpeed = enemySpeed + 0.2 ' Get faster!
END IF
' --- COLLISION: Coin ---
IF ABS(playerX - coinX) < 15 AND ABS(playerY - coinY) < 15 THEN
PLAYWAV "coin" ' COIN SOUND!
score = score + 10
coinX = INT(RND * 280) + 20
coinY = INT(RND * 100) + 50
END IF
' --- COLLISION: Enemy ---
IF ABS(playerX - enemyX) < 15 AND ABS(playerY - enemyY) < 15 THEN
PLAYWAV "ouch" ' HURT SOUND!
lives = lives - 1
enemyX = 340 ' Reset enemy
IF lives <= 0 THEN
STOPMP3 "music" ' Stop music on game over
CLS
PRINT "GAME OVER!"
PRINT "Final Score: "; score
PAUSE
END
END IF
END IF
' --- RENDER ---
BEGIN FRAME
CLS
' Ground
LINE (0, 190)-(319, 199), 2, BF
' Player (yellow circle)
CIRCLE (playerX, playerY), 10, 14, 14
' Coin (gold circle)
CIRCLE (coinX, coinY), 8, 14
' Enemy (red square)
LINE (enemyX - 10, enemyY - 10)-(enemyX + 10, enemyY + 10), 4, BF
' UI
LOCATE 1, 1
PRINT "Score: "; score; " Lives: "; lives
END FRAME
DELAY 16
LOOPNotice how sound makes the game feel so much more responsive:
- Jump sound confirms the player's action
- Coin sound provides satisfying feedback for collecting
- Hurt sound makes damage feel impactful
- Background music keeps the energy up
Sound Best Practices
1. Load Everything at the Start
' GOOD: Load once, play many times
LOADWAV "shoot.wav", "shoot"
DO
IF shooting THEN PLAYWAV "shoot"
LOOP
' BAD: Loading in the game loop causes stuttering!
DO
IF shooting THEN
LOADWAV "shoot.wav", "shoot" ' DON'T DO THIS!
PLAYWAV "shoot"
END IF
LOOP2. Use WAV for Effects, MP3 for Music
- WAV: Sound effects (short, need instant playback)
- MP3: Music (long, can afford slight delay, much smaller files)
3. Keep Sound Effects Short
Sound effects should be 1-3 seconds max. Long sounds can overlap weirdly and eat up memory.
4. Don't Overlap the Same Sound Too Much
If the player fires 10 lasers per second, you might get weird audio artifacts. Consider limiting how often a sound can play:
lastLaserTime = 0
IF shooting AND TIMER - lastLaserTime > 100 THEN
PLAYWAV "laser"
lastLaserTime = TIMER
END IF5. Stop Music When Appropriate
Don't let background music play during menus or cutscenes if it doesn't fit:
' Pause menu
STOPMP3 "game_music"
' ... show pause screen ...
PLAYMP3 "game_music", 1 ' Resume when unpausedQuick Reference
| Command | What It Does |
|---|---|
BEEP |
Play a simple beep |
SOUND freq, duration |
Play a tone (frequency in Hz, duration in ms) |
LOADWAV "file", "name" |
Load a WAV file |
PLAYWAV "name" |
Play a loaded WAV |
STOPWAV "name" |
Stop a playing WAV |
LOADMP3 "file", "name" |
Load an MP3 file |
PLAYMP3 "name", loop |
Play MP3 (loop: 0=once, 1=forever) |
STOPMP3 "name" |
Stop playing MP3 |
PLAY "notes" |
Play MML music |
PLAY BACKGROUND "notes" |
Play MML in background |
PLAY "I# notes" |
Play with instrument (0-66) |
PLAY "V# notes" |
Set volume (0-15) |
STOP PLAY |
Stop background MML |
Try It Yourself!
Create a "Simon Says" style game where you have to repeat a sequence of tones using SOUND
Add sound effects to one of your earlier games—jump, shoot, collect, die
Write a short song using MML notation
Create a jukebox program that lets the player switch between different MP3 tracks
Make a "sound board" with buttons that play different sounds
Your games are about to sound AMAZING!
See you in Chapter 14!
Next Chapter: We'll learn about saving and loading—because losing all your progress is NO fun!