Today this project has reached a milestone: For the first time there is a full program running on Compy, not just a simple test code to check if some feature is working or not, but an application that uses several areas of this computer: the operating system, storage access, screen and keyboard handling, and more importantly, the audio.
What I did was to take the Raster Music Tracker player and port it to Compy adding a full user interface to select songs and play them. Porting RMT was quite easy, I changed the audio port addresses and modified the code a bit to handle mono and stereo songs using the same code (it was hardcoded). The rest of the application is another story, but it was a great exercise to test how easy/hard is to program this computer and I made a lot of changes here and there to add some library functions for common tasks like scrolling, handling strings and more.
Audio on Compy
Very early in the design I wanted to have at least two audio options, a simple one and a more advanced one so anyone can use what they are more confortable with, or both! For example a game could use the advanced audio for music and the simple audio for special effects. Now, with the right tools even the most simple audio can give great results as you can hear in the RMT player above.
For the simple audio option I chose the POKEY chip. This is a 4 channel chip that was used in the Atari800 and it is very very simple to program, just write a note in one register and the effect + volume in another register and you have sound.
On these days it is common that people modify their Atari computers to use two chips for stereo sound. I wanted something similar but I find that this can be a bit restrictive. Using two POKEY chips you have 4 channels at the left and 4 channels at the right, if you want to produce a sound on both sides you have to use 2 channels. I modified the POKEY emulator to add a new register where you can specify where every channel will sound, so you can use one channel for both left and right at the same time.
Now, the emulator code that I used had a bug when more than one chip was used and I spent a lot of hours tracking it down. But as master Bob Ross says, this was a happy accident, because this forced me to understand how the POKEY works and that takes us to the next step.
A better POKEY
The POKEY produces sounds using a simple square wave with an amplitude from 0 to 15. This square wave can be distorted using a polycounter, which is basically a sequence of 1s and 0s that indicates if the square wave is cut off or not. Periodic sequences of 1s and 0s produce motor like sounds and more random sequences produce steam like sounds.
Now, this is a very simple device and still produces amazing sounds, but why not take it one step further! I will be modifying the code to add ADSR and more waveforms, so this chip will be able to produce sounds like the PSG (AY-8910) and the SID chip at some extent. Ironically, adding these kind of features is easier to do in FPGA rather than software, but software will come first.
By default the POKEY will behave like the original chip, but you will have additional registers to use the extra features.
For advanced audio I still evaluating different options. I would like to have FM synthesis and a simple PCM processor. One could just throw an OPL4 chip with multi-channel hardware mixed PCM audio but that would be overkill for this computer, and it would not be realistic for a computer made in 1988. Not to mention that the 6502 / Z80 would struggle handling something like that.
Fortunately, there are some configurations from that era where I can get some inspiration. The MSX had audio expansions with FM and PCM, and even the C64 had an FM one.
Let’s see what are the options available.
Options for FM Audio
Yamaha is the king in this area, and they have at least three lines of FM synthesizers that I would call the low end, consumer and arcade lines.
Most people know the consumer line where we can find the OPL2, OPL3 and OPL4 synths, because they were used in the Adlib and Soundblaster PC sound cards. From this line I would only consider the OPL2, the other two are more appropriate for the CLC-92 Compu.
In the arcade line there are several interesting chips, including the one used in the Sega Genesis. Again, these are more appropriate for Compu and not Compy except for the OPM (YM2151).
In the low end there are more alternatives for a computer from 1988. In this range I would consider the Y8950, the OPL and OPLL (YM3256 and YM2413).
Follow the links for sound examples of each one.
Options for PCM Audio
For PCM audio there are two limiting factors. First, it cannot be handled by the CPU, it is just not fast enough to produce sound and do other interesting stuff at the same time. Second, the amount of memory limits the length and the quality of the sound.
I see two options here, one is to just create a dedicated processor and the other is to use a chip like the Y8950 that already has this part using a kind of compressed PCM (ADPCM).
The PCM would be designed for short mid-quality sounds, like explosions or drum sounds. The CPU would write the start address and length and the PCM chip would just play that. How many channels and stereo options are not decided yet. Another decision that must be taken is to add exclusive memory for PCM or not.
The MSX has good examples of this simple PCM feature and probably I would take more ideas from there.