libretro / hatari

New rebasing of Hatari based on Mercurial upstream. Tries to be a shallow fork for easy upstreaming later on.
25 stars 41 forks source link

Audio distortion fix #64

Closed bbbradsmith closed 3 years ago

bbbradsmith commented 3 years ago

After f8c35958ec1c93c32d41d61fa4903b2f5daec78c and #59 fixed the most glaring issue with audio generation, finally delivering uninterrupted audio from Hatari, I've been able to look more carefully to the audio being generated.

I found that we were getting a large amount of distortion from Hatari's sound generation. This is due to a strange polarized lowpass filter implementation in Hatari itself, which shapes the waveform differently on a rising than falling edge.

So: I've created a more traditional implementation of a lowpass filter to substitute, and created an option to switch back to the distorting filters for anyone that prefers it.

The current version of Hatari does not sound as distorted, but the underlying polarized filter operation seems to be the same. I think in a later version they may have increased the resolution that the audio is simulated at before applying the filter, pushing most of its distortion effects out of the audible range by accident, hiding the problem? Given how different the generated sound is from real Atari ST recordings I've compared against, I'm not sure that code in Hatari works quite as it was intended.

...but at any rate, whether or not that's a bug in Hatari is a separate issue. I added an alternative as an option, on by default, and I think it sounds a lot nicer (i.e. cleaner, clearer). The relevant code changes are quite small and have no new performance implications.

bbbradsmith commented 3 years ago

An audio comparison of the old vs new: bb_compare_sound.zip

A real hardware recording example of the same tune, you can hear how it does not sound like the old version (different playback rate because it's a different revision of the game, but the music is the same): https://youtu.be/7EkJwYqJ_WM?t=45

Dunno if there's some other version of the hardware that was really distorted this much, but the current version of Hatari does not sound like the "old" clip anyway. (I made it optional, though, in case someone does want this distortion.)

A visual comparison, on top using the new code, on bottom the old code. You can clearly see the "square" wave had become very sawlike: bb_compare

hizzlekizzle commented 3 years ago

Oh yeah, there's definitely some crunchy stuff going on in that bb_old clip. Much cleaner in bb_new.

Good stuff!