Sound is a very
important part of any high action arcade game. Ever since my first CoCo
game Neutroid II, I have always tried to present plenty of noise in my
games. I wanted to showcase what the CoCo was capable of producing.
many of the 8-bit computers of that era such as the Commodore 64, Atari
800, MSX and Texas Instruments, sound was a matter of using the built
in sound chip to play sound effects and music with minimal CPU
the CoCo was never gifted with such hardware luxuries and the
generation of sound during play in many games comprised of mostly
simple beeps and clicks.
With my first
CoCo game Neutroid II in
1984, I wanted to show what the CoCo's built in DAC circuitry could be
made to do.
to listen to the sound effects in Neutroid II.
The evolution of the Sound
I began creating
sound effects for my games back when I was programming my TRS-80 Model
1. The TRS-80 only had 1-bit sound via the cassette output. The most
advanced sound I created back then used a table of data that
represented the on/off state of the cassette audio. These tables were
pre-generated via a BASIC program. The table data was sent a few bytes
at a time during the game play to allow multi-tasking of the game
graphics and reduce any graphics stutter during play.
When I moved to
the CoCo, I expanded this technique to utilize the 6-bit DAC which
allowed the sound to vary in amplitude and offer the ability to soften
the end of a sound with a short fade to silence.
When I moved to
the CoCo 3, I began to experiment with interrupts. By the time I got to
my game Cosmic Ambush, I was using interrupts to drive a two channel
sound output by combining sample tables via additive synthesis.
When I did
Pac-man, I refined the code to take up less CPU cycles to allow more
time for the game itself.
refinement came with Pop*Star Pilot which shared the interrupt handling
to include scanline based video effects such as the split screen
hardware scrolling and multi-color/animated background control.
For Gunstar, the
Page Copy routine explained in the previous chapter of this blog
consumed a lot of CPU time so it was back to the 2 channel sound
routine of Pac-man but further optimized to take up as few CPU cycles
as I could muster.
As you can see,
over my 30 years of programming games, I have been evolving the sound
routine as I learned more.
One area I have
not explored has been in-game music. To include music as well as the
sound effects required for the game, I needed to consume more CPU
cycles. Spare CPU cycles is dependent on the game itself. A turned
based or slow paced game would have cycles to spare but a game like
Gunstar where much of the CPU is being spent on the graphic routines,
spare cycles were not available.
I did try though
and had some success but it involved turning to a very low sample rate
and I felt the musical tones where too low in fidelity and it wasn't
worth the CPU cycle loss for the end result.
maybe having an option of choosing between sound effects and music but
I decided that the game had to
have the sound effects of laser gun fire and meaty explosions... so the
in-game music was dropped.
To be done
properly, in-game music requires the support of a dedicated sound chip.
I chose to plug along with my existing 2 channel routine for sound
effects. This will allow everyone with a CoCo3 to hear the sound
effects without the need to purchase additional hardware.
Look Ma! No Sound
the internet, I was able to locate suitable sound samples from the many
free online resources available. The files I found were in WAV format
which I down sampled to 8000Khz. I then wrote a BASIC program on the
CoCo to input these files, downscaled them from 16-bit to 6-bit for use
by the CoCo's DAC and clipped them all so they could all be stored in
the 5 allocated MMU blocks (40K total). The actual playback sample rate
is 7498Khz although I can adjust this easily.
Click on the
image to the right to listen to the sound effects I have chosen for
Gunstar. These sound effects were being played in real-time while
multi-tasking with the Page Copy routine.
I inserted code
to allow me to trigger each sound effect by pressing the numeric keys.
Pressing the 1 key would
trigger the laser fire sound effect, key 2 would trigger the explosion effect
and so forth. Two sound effects could be triggered simultaneously while
the main code ran continuously, copying the graphics buffers used for the graphics engine.
The audio was
recorded directly off a real
CoCo3, no additional hardware was used. It shows what can be achieved
with the standard built-in 6-bit DAC and the advanced interrupt
handling of the CoCo3.
This test is a
good indication of how much CPU time is consumed in generating the two
most CPU intensive tasks in the game and lets me see how much time I
can devote to the rest of the game. So far, so good.
This has been a
short chapter that doesn't reflect the amount of time spent
experimenting with the various sound effects, fine tuning each sample
and exploring the prospects of in-game music.
Stay tuned for
the next chapter where, if successful, I will announce another new
feature to be included in Gunstar.