ekeeke / Genesis-Plus-GX

An enhanced port of Genesis Plus - accurate & portable Sega 8/16 bit emulator
Other
673 stars 193 forks source link

Increasing YM2612 emulation performance #486

Closed fcipaq closed 1 year ago

fcipaq commented 1 year ago

Hey,

First of all I really appreciate all your hard and great work and I am sorry to open an issue that is not directly related to this project - it was the only way I could think of to get in touch with you guys. Now, I am looking for a way to reduce the computing power needed to run the YM2612 emulation. I was thinking of reducing the number of samples per second - is that possible and also will this approach result in a reduction of hardware demands? The reason why I'm asking is that I am currently trying to port an already existing Genesis emulator (https://github.com/bzhxx/gwenesis) - which uses the YM2612 emulator from this project - to the super lightweight RP2040, which is (as you most certainly already know) a dual core Cortex-M0+. I can achieve an acceptable frame rate as long as sound is not being emulated. With sound emulation, however the frame rate drops to an unacceptable level. Even though the sound emulation is done on the second core. Any input is highly appreciated.

Thank you in advance and best regards

fcipaq

ekeeke commented 1 year ago

This is not directly answering your question but, looking at the linked repository, it seems that you could gain significant performance by replacing MAME 68K and Z80 CPU cores with ARM optimized Cyclone and DrZ80 cores (I think Picodrive emulator uses them to run at decent speed on lightweight ARM based platforms like the 3DS).

As for YM2612 emulation, reducing the output samplerate shouldn't help much since the YM2612 core (at least the one from this project) is emulated at the native rate (one sterero FM sample rendered every 144 68k CPU cycles) then is resampled to wanted output rate. Apart from replacing the core with an ARM optimized one (again, Picodrive emu probably would be a good source for that), another solution would be to modify the core to run directly at the wanted output rate but this is not trivial as it implies modifying all internal frequency calculations and lookup tables to apply a ratio (I know this was done initially in original MAME core implementation but that version is long gone).

fcipaq commented 1 year ago

Thank you very much for the useful hints. I am definitely going to look into the ARM optimized CPU emulators. I think that I found the YM2612 emulator version you previously mentioned. Using that version, I am able to choose the sampling rate to be one third of the original rate, giving me a good sound quality/performance ratio. In case anyone ever stumbles across this post having the same issue - The latest version still supporting a custom sampling rate can be found here:

https://github.com/ekeeke/Genesis-Plus-GX/blob/02999945ea1dc4f559e69237a21c78e2dc42598a/source/sound/ym2612.c

Thanks again!