Electronics » the v3 Z80 project » sound tweaks
I'd hadn't really done much with the soundchip since version
2 of the Z80 Project - even then I'd only had it produce a few test beeps.
Ideally I wanted it to play music - not the latest bangin' mp3s of course
(its soooo not capable and well, that would be dead boring and un-retro anyway:)
No, music as in 80's / early 90's game tunes! I'm absolutely *not* a musician
myself so I needed it to play existing music files - the most usable and readily
available being Amiga Protracker modules (I couldnt really use C64 SID tunes
as there's no standard replay routine, PC players have to emulate the C64's
CPU as well as the sound hardware). So... there was my challenge,
write a Protracker replay routine in Z80 that'd work with my hardware.
Slight snag: the Amiga's sound hardware is a 4 channel sample player and my
soundchip is more like a 4 channel version of the C64's SID chip, ie: a tone
generator. It *can* play sampled sound using interrupts but due it only having
a 64 byte internal buffer and no DMA abilities, it can only manage one sampled
voice at a time. Some dodgy multiplexing shennanigans could've had it playing x
sampled voices of course but that would hog the CPU and be useless for games and demos.
Clearly another approach was required.
I decided to try to strip out the sample data from the Protracker modules
and only use the note/fx sequence data. I then could synthesize voices in software
to approximate the original samples. With a software voice generator I figured
it would be perfectly adequate for "chip tunes" (small modules with simple
waveforms as samples). This wouldnt need to be very complicated: a wide variety of
voices would be generated by modulating the pulse width of the square wave
generator, rapidly switching wave types, creating an envelope to add shape
to the sounds etc. Each voice would be numbered and triggered using the data that the Protracker replay routine would normally be
sending to the Amiga's hardware registers. And so I set to work (whilst I was
at it I made a front end for the wave editor, shown in the pic on the right).
The first tune I converted was one I'd used in Giddy3 as the game completion tune
(called Skogen's Djur 20 written by Daniel Johansson) - I've put an mp3 of the
Z80 project playing it below. Its a nice crisp tune that doesnt use anything
too fancy in terms of waveforms - it came out quite well I think.
Some of the tunes I tried next had distinctive sounding wave shapes and I was
having trouble matching them accurately in software so I had another think about
playing digital sound. As the waves for such voices were really tiny (about 32 bytes)
I realized I could download them to the SX28's internal SRAM (I had 64 bytes to play with -woo!)
when the parent module was initalized. From there they could be played by all 4 channels
at once if required. So, a new wavetype was added to the soundchip firmware: "Play sample loop
from internal registers" - some pointers to the start and end locations were required
and then away it could go just like any of the synthetic waveforms.
Whilst I was looking into this I remembered how the SID chip did "ring modulation"
effects by flipping the output of the triangle wave generator based on the square
wave output of another channel (ie the MSB of another channel's accumulator), its
probably not going to be much use for music but it makes some interesting FX so
I implemented this wave type too.
The SX28 has 2048 12-bit locations that can be used for its program. My
sound firmware had used about 500 of these words and I wondered if I could employ up
the rest usefully. Most modules use drum sounds, so I decided it'd be a reasonable
idea to put a micro drumkit in there: a bass drum, a snare and a hi-hat would
just about fit with some radical downsampling and 6-bit conversion - and hopefully still
sound like drums :) The SX28 IREAD instruction made it easy to read the program
word locations as data so I wrote a small routine in Pure Basic to convert the samples
to source code and included them as data in the SX28 program. Of course the sounds
can also be chopped and mixed by the synth code just like the other voices so a
variety of FX can be spawned from the raw samples.
Source code etc can be found in the file base.. Here's some mp3s of the tunes I've converted so far:
- Skogen's Djur 20 (196KB MP3) (Module By Daniel Johansson)
- Monty O.T.R Hi Score (1.3MB MP3) (Original tune by Rob Hubbard, Protracker version by dreamfish)
- Her Numbness (943KB MP3) (Original module by estrayk ^ paradox)
- Monday (543KB MP3) (Original module By Random Voice)
- Skogen's Djur 8 (450KB MP3) (Original module By Daniel Johansson)
- Hawkeye Highscore (524KB MP3) (Original by Jeroen Tel, Protracker vers by Pink of $ceptic/Abyss
|