indigodarkwolf / box16

A fork of the official X16 emulator, converted to C++20 and with a bunch of features tweaked and added.
MIT License
41 stars 19 forks source link

add better resampling method for YM2151 #64

Closed biermanncarl closed 1 year ago

biermanncarl commented 1 year ago

I tried fixing the R8Brain resampling and was able to remove the crackling noise. However, it then suffered from huge latency, which made it unusable.

Hence I decided to write my own simple resampling algo, which removes most of the aliasing that the YM2151 was plagued with.

indigodarkwolf commented 1 year ago

If there's one thing I've learned, it's that I have a terrible ear for these things. @ZeroByteOrg, on the other hand, seems to have a great ear for this stuff, so I'd really like his opinion on how this sounds.

indigodarkwolf commented 1 year ago

Also, setting aside the build warnings-as-errors on Windows, do you happen to have a working sound player you can upload to this discussion thread? Mine all seem to be out-of-date.

indigodarkwolf commented 1 year ago

I got one of the zsound examples working, so there's that at least. But I'd still like to get Zero's opinion on how much better this is over the existing audio.

biermanncarl commented 1 year ago

Thanks for taking a look! I tested with TUNE.PRG, which uses both PSG and YM2151, so it is also useful to detect latency. The difference between old and new resampling method should be fairly apparent in SOLO.PRG, which is basically one phrase out of TUNE.PRG, where the aliasing is very prominent. sound_examples.zip

biermanncarl commented 1 year ago

Should I add documentation on how I obtained the filter coefficients, so that the filter can be adjusted if need be? And should the filter coefficients perhaps be offloaded into a .inl file?

indigodarkwolf commented 1 year ago

Well, the truth of the matter is that I'm not sure if anyone else would be able to take up the task of improving the collection of values unless they know what the values mean, and I'm not sure I follow the magic, personally, without a link to some article describing the algorithm, or at least a description of what the algorithm is called so I could look it up on my own.

indigodarkwolf commented 1 year ago

@ZeroByteOrg asked me to generate some audio clip examples, et voila. wav-examples.zip

Personally, I think even I can hear the difference and think this is somewhat better. Not perfect, but improved over what's there. (The "with" examples are using this PR, the "without" examples are using the latest available build of Box16.)

indigodarkwolf commented 1 year ago

Caught up with Zero, and he agrees it sounds much better.

ZeroByteOrg commented 1 year ago

Sounds pretty good to me. Certainly good enough to accept IMO.

biermanncarl commented 1 year ago

Thanks for the feedback and for checking out the sound examples! Albeit I think the current status is already an improvement, I still would like to tweak the settings. The algo introduces a tiny bit of latency, which could be improved.

biermanncarl commented 1 year ago

I have added some documentation on the approach with external links, and also adjusted the filter settings a bit. Probably no one will ever care about it, but incase they will, here it is... ;)

indigodarkwolf commented 1 year ago

Thank you so much! This is even more than I'd hoped for. :3