I'm considering this a major milestone because audio can be very resource-hungry in a tight loop of an emulator running on a microcontroller. I had to rework a huge part of v06x in order to make it work on this board. I started with something like 1/4 of desired frame rate and in the end of optimisation I had it running at 65fps instead of required 50. This was very handy because now I can burn those extra cycles on audio support.
v06x has relatively simple sound: it samples outputs on every clock, then the result is downsampled to 48kHz using polyphase rational resampler. So that all strange PWM effects on the 8253 and Beeper sound nice in emulation. Unfortunately it's impossible to call timer on every clock cycle on ESP32 so the audio is processed in chunks and sampled twice per video line, that's 624 samples/frame, or 31200 samples/second.
This works for most regular sounds, but breaks when a music routine goes for a frequency above sample rate. I'm just cutting down those frequencies for now.
AY support is mostly borrowed from the amazing ZX-ESPectrum project. It's cleverly done because it processes the required amount of samples on demand, so only before an OUT instruction and at the frame end. This reduces overhead a lot. Unfortunately because of what I believe is a bug in the LCD driver, I can't fully offset the processing in one fat call without altering my emulator loop significantly. Instead, I broke the processing into 6-line chunks, just like video. This still stresses out the system a bit too much near the top of the screen, but in most cases it's not visible.
I should borrow some of the ideas from ZX-ESPectrum for my 8253 and beeper implementation. But that's for the future. For now I think keyboard support should be the next most important milestone.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.