I ran into audio-quality limitations while experimenting with sound output on a Pimoroni Tufty and RP2040. The issues included gaps during display refresh, a poor-sounding piezo speaker, and background noise during tests with a separate speaker.
I set the audio output level to 0 or 1, like the real output bit.
I can change the volume setting the wrap-value for the PWM counter, which changes the duty cycle.
I described the sound as “a bit like my grandpa farts.”
I said, “if we tick the CPU, audio is produced”; if we don't, audio is not produced, after we removed the buffer.
I refresh the display 20 times per second, for 15 milliseconds each time; “the audio is not actually playing any more” during the refresh, which I identified as the first artifact.
I said, “You don't hear much the issue with sounds effects like the ones in Jetpac,” but with music the issue is more noticeable.
The piezo speaker I'm using has a very bad frequency response, but it is very power efficient.
I can drive the piezo buzzer with just the output of the RP2040 pin, and I connected the QW/ST plug of the @pimoroni Tufty to my piezo without any other electronic; I found that convenient.
I tested a real 4 ohm speaker connected via a 330 ohm resistor and ticked the CPU without updating the display; it improves, but still I can hear a background noise of some kind.
For my usage, the audio quality was good enough, and the implementation was extremely simple, so I was content to leave it as it was for now.
In the emulator, recent versions ran much faster because no video decoding is performed in the zx_tick() function.
I reported 40ms of runtime versus 108ms of screen update time, a comparison I called “Unfair :).”
I said I could theoretically use the second code to update the screen, but I was using it for audio; it waits for the buffer most of the time, so multiplexing it was possible in principle but the timing would be super tricky.