Finally, the PSG (Programmable Sound Generator AY-3-8910) is coming to life. It was harder than I thought. But it now has the 3 channels for tone or noise, with independent frequency and volume control. Only the the envelope generator is not present yet [edit: a month later, envelope was also working]. The sound is generated by microcode, no actual AY-3-8910 is used, but the sound is controlled in the same way as on a real sound chip.
It generates the typical sound of the eighties computer games.
It can now provide sound for the SymbOs operating system ! And here you see the first Youtube video of Isetta running SymbOs (made by Prodatron):
(The start-up screen of Isetta will have to be modified, it's quite a mess at the moment.)
A new version of the Isetta programming manual is now in the file section. It includes the commands to control the sound generator.
OPERATION
There are four 1 kB sound buffers, one for each of the three channels, and a fourth one for noise.
The squarewave sounds are generated in an unrolled loop. So if a wave has 5 samples 'high' and 5 samples 'low', to generate one period there will be two sequences that each put samples in the buffer, with each having five "(pc++) <- T" micro-instructions in a row. (Note the program counter is used as auto-incrementing pointer to the buffer).
The value in T is the required amplitude for this sound (positive value for high samples, negative value for low samples). So there is no separate volume-control stage, like the real PSG has.
At each scanline interrupt, a byte-sized sample is taken from each of the four buffers, the four samples are added and sent to the D/A converter (resistor array RN1). So the sample frequency is the same as the VGA line frequency, 31.25 kHz.
To control this, there are two Z80-output ports. One to select a AY-3-8910 register, and another one to write a byte to that register. The Z80 output ports can also be used by the 6502 processor.
EFFICIENCY
For each channel, producing samples takes around 3 cycles per sample. (The unrolled loop produces 8 samples on average, single cycle per sample, with also 16 cycles overhead).
For a full 525-line frame, this is 1575 cycles per channel. Noise has it's own channel, so there are 4 channels, together taking 6300 cycles each frame.
In each frame, 120 lines are for the CPU, minus interrupt it's around 350 usable cycles per line. Per frame, this is 120 * 350 = 42000 available cycles. So the sound takes 15% of the CPU time. For frequencies higher than 1kHz, there are just a few samples produced in each loop, so there is more overhead.
LINKS
There are several very nice articles about sound generation.
Want to know everything about synthesizers:
https://www.soundonsound.com/series/synth-secrets-sound-sound
Building the AY-3-8910 fully from TTL chips:
https://github.com/mengstr/Discrete-AY-3-8910
Very good description of the AY-3-8910:
https://www.cpcwiki.eu/index.php/PSG
Article about Linear-feedback shift registers, used to generate noise:
https://en.wikipedia.org/wiki/Linear-feedback_shift_register
The Isetta noise generator comes from this article. It's a 16-bit Galois type, quite simple:
unsigned msb = (int16_t) lfsr < 0; /* Get MSB (i.e., the output bit). */
lfsr <<= 1; /* Shift register */
if (msb) /* If the output bit is 1, */
lfsr ^= 0x002Du; /* apply toggle mask. */
Sound generation in the Novasaur TTL computer:
https://hackaday.io/project/164212-novasaur-cpm-ttl-retrocomputer/log/184708-roll-your-own-sid-chip
Interactive demo, shows harmonics of square waves and triangle waves:
https://www.desmos.com/calculator/emfmoefwqu
A suitable IC for driving a small speaker: LM4862, info HERE. Or use LM4991 (cheaper). Small Speaker could be 665-ASE03008MRLW150R. Or 179-CMS-30204-18L250. Or 497-SM500308-1.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Roel: amazing! This is such a cool project, very nice, congratulations with this milestone that brings 8 bit sounds back to our ears. I am actually really curious to understand how this actually all can be done in microcode without impacting the overall CPU speed too much.!
All the best Guido from south nl
Are you sure? yes | no
Thanks Guido ! I added a section about the sound operation in this log.
Are you sure? yes | no