nukeykt / Nuked-SC55

Roland SC-55 series emulation
Other
383 stars 40 forks source link

Optimization? #8

Open OpenRift412 opened 6 months ago

OpenRift412 commented 6 months ago

As it stands right now, Nuked SC-55 uses 15% of my i5 9600K CPU while idle and the MIDI playback will slow briefly whenever there's a usage spike. Is there still room for optimization while still maintaining accurate sound reproduction?

johnnovak commented 6 months ago

Kinda makes sense as there's no "idling" when emulating a hardware like this. I'm getting around 3-3.5% CPU usage on my 24-core Ryzen 7900, so who cares 😎 15% on an i5 9600K is still small potatoes.

OpenRift412 commented 6 months ago

Kinda makes sense as there's no "idling" when emulating a hardware like this. I'm getting around 3-3.5% CPU usage on my 24-core Ryzen 7900, so who cares 😎 15% on an i5 9600K is still small potatoes.

Sure, though the concern is mostly with slowdown during playback because like I said, it's really sensitive with usage spikes on even relatively mid-range hardware. Like even just loading web pages and changing channels on discord can cause it to chug a bit.

NicknineTheEagle commented 6 months ago

Can confirm, on lower-end CPUs like i3, any CPU usage spike causes Nuked to stall for a bit.

KainXVIII commented 6 months ago

More than 20% usage on my i5-3570 and don't you dare to alt-tab the dosbox emulation or music will hang for a few seconds πŸ˜…

johnnovak commented 6 months ago

More than 20% usage on my i5-3570

"The Intel Core i5 3rd Gen is a processor that was released in 2012"

Time to upgrade guys πŸ˜„ State-of-the-art emulation and 10+ year old hardware don't mix well 😎 Or live with FluidSynth...

KainXVIII commented 6 months ago

More than 20% usage on my i5-3570

"The Intel Core i5 3rd Gen is a processor that was released in 2012"

Time to upgrade guys πŸ˜„ State-of-the-art emulation and 10+ year old hardware don't mix well 😎 Or live with FluidSynth...

Not an option for me, unfortunately πŸ˜…

giulioz commented 6 months ago

If you look at the source code the pcm emulator is currently oversampling, you can disable that to save some cpu time

nukeykt commented 6 months ago

Can you check if midi comman stalls are gone with latest release?

I don't think it is possible to drasticallly optimize it due to the way I emulate SC-55 hardware. It runs original firmware on emulated CPUs and PCM emulation accurately replicates original chip algorithms.

NicknineTheEagle commented 6 months ago

Can you check if midi comman stalls are gone with latest release?

I don't think it is possible to drasticallly optimize it due to the way I emulate SC-55 hardware. It runs original firmware on emulated CPUs and PCM emulation accurately replicates original chip algorithms.

It improved, I still get stalls during CPU usage spikes on i3-1115G4 but they're not nearly as frequent and much briefer.

OpenRift412 commented 6 months ago

Can you check if midi comman stalls are gone with latest release?

It improved, I still get stalls during CPU usage spikes on i3-1115G4 but they're not nearly as frequent and much briefer.

Yeah, same here. There's still some hitching/slowdown during certain tasks (launching photoshop, spamming the start menu button somehow?), but it's not nearly as sensitive as before.

I don't think it is possible to drasticallly optimize it due to the way I emulate SC-55 hardware. It runs original firmware on emulated CPUs and PCM emulation accurately replicates original chip algorithms.

Would adding some sort of buffer be possible, where it processes MIDI signals and renders the sound like x amount of time ahead to compensate for CPU spikes? Or is that not really a viable option with the nature of the emulation?

johnnovak commented 6 months ago

slowdown during certain tasks (launching photoshop

😐 Seriously? That causes glitches in any audio software, probably...

OpenRift412 commented 6 months ago

slowdown during certain tasks (launching photoshop

😐 Seriously? That causes glitches in any audio software, probably...

That's just an example. I've already mentioned browsing the web and other rather normal tasks as another trigger of playback issues, so I didn't want to repeat myself. Opening task manager was also a trigger as well.

I feel like you're kind of just downplaying this issue, which isn't really helping. 24-core CPUs aren't in everyone's budget, so I think it's reasonable to ask about optimizing things to run properly on a wider set of specs, otherwise it's basically useless to most people. Let's just focus on seeing what can be done instead of derailing the issue. I'm clearly not the only person who's encountered this problem, so this isn't a niche case.

Kappa971 commented 6 months ago

I have a fairly recent CPU (R7 5700x), the emulator seems to be fine, but for example in Road Rash I have the same problems described by others here, the music skips/slows down. We're talking about a 1996 Windows game and a 2022 CPU πŸ˜†

kode54 commented 6 months ago

I built on Linux and used CMake, and set the build type to Release, and the idle cpu usage went from 78% of a core down to 38%. And it doesn’t seem to increase under load.

Kappa971 commented 6 months ago

I built on Linux and used CMake, and set the build type to Release, and the idle cpu usage went from 78% of a core down to 38%. And it doesn’t seem to increase under load.

The strange thing is that I only have problems with that game (for now). I'm on Windows, I'll try to compile the program with build type "Release". Thanks

ghogan42 commented 6 months ago

I'm on an m3 max based macbook. Midi doesn't seem to work at the moment, but with the demo songs, the release version is 56-57% of one core and the default compile is 100% cpu usage and had some stutter every few seconds.

Kappa971 commented 6 months ago

I compiled by choosing Release but the problem in Road Rash remains. Strangely it seems that if I Alt+Tab during the race, the problem goes away. I don't think it's a CPU usage issue. SCVA works.

Kappa971 commented 6 months ago

In Road Rash I use the cnc-ddraw wrapper (otherwise the game won't start), it seems Nuked-SC55 doesn't like it. I enabled the option Fix bad performance and sound issues in cnc-ddraw-config.exe and it seems to fix the stuttering issues in SC-55 emulation. This emulator seems to be very sensitive.

sirbaratusii commented 6 months ago

I am running this on a i9-10850K with loopMIDI and even in some MIDIs, not only I get slow downs every now and then but crackles too. Even some instruments don't play well either. I provided a sample with one of the MID files included for those willing to test it.

sample.zip

A bit off-topic but would a command line that increases voices and polyphony be possible or is that out of scope?

UPDATE : Somehow the problem went away after I restarted my PC. Odd.

pachuco commented 6 months ago

I think a nice portion of performance/stability can be gained by cleaning up threading use.

Also, in MCU_Run(), try disabling LCD_Update(ouch), or at least making SDL_Delay higher value, like 100.

Gerwin2k commented 5 months ago

Was testing this Synth on some slower hardware. Sandy Bridge Intel Core i3-2310M with OS Windows XP can just run it. One core usually at 80-90% use. But the strange thing was when I was setting core-affinity manually, at some point the workload was spread out over two cores. See image. In that way the CPU could handle the Synth with good margin. But this is not how the Synth is typically scheduled.

Nuked-SC55

arrowgent commented 4 months ago

linux 65-75% of one cpu core while idle, not playing anything.

reported by HTOP its quite high, but it is emulation...

johnnovak commented 4 months ago

linux 65-75% of one cpu core while idle, not playing anything.

reported by HTOP its quite high, but it is emulation...

Btw, with this approach, it's probably better to call it simulation, then suddenly things make a lot more sense. All those chips on the real physical board "do work all the time", so whether there's audio or not, they are being simulated.

Similarly to those FPGA recreations which are more like simulations of the real hardware behaviour down to the component level rather than just emulating the observable high-level behaviour as a black box.

Good thing is virtually you can't get a CPU that has less than 4 physical cores these days.