Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Basic CPU Load Implementation #6576

Closed
danielhoey opened this issue Aug 27, 2022 · 10 comments
Closed

A Basic CPU Load Implementation #6576

danielhoey opened this issue Aug 27, 2022 · 10 comments
Labels
Feature Request New feature request UI Issues related to UI look&feel

Comments

@danielhoey
Copy link
Contributor

Bug Description:
Playing very many notes with multiple sine OSC with unison voices will produce a lot of clicking/fuzz/digitial distortion.

Surge XT Version
Surge XT 1.0.1.60228e8
64 bit
Stand alone executable

Reproduction Steps:

  1. Initialize patch
  2. Set OSC 1 to Modern/Sine, Unison Voices -> 16
  3. Set OSC 2 to Modern/Sine, Unison Voices -> 16
  4. Set Amp EG release to a high value (0.3s or higher)
  5. Play as many note as possible for a 5+seconds.

Expected Behavior:
The sound produced by pressing the first key should not be significantly different then the sound produced when pressing later keys.

Computer Information (please complete the following!):
Windows 10 - 64bit
Stand alone executable ("Surge XT.exe")

Additional Information
Surge is utilizing about 25% of CPU during this process

@danielhoey danielhoey added the Bug Report Item submitted using the Bug Report template label Aug 27, 2022
@baconpaul
Copy link
Collaborator

It sounds like you are running into the clipper. If you turn the amplitude down for each osc in the mixer does the problem resolfe?

Also 25% is quite a lot of cpu. May want to take that unison count to 7.

@danielhoey
Copy link
Contributor Author

danielhoey commented Aug 27, 2022 via email

@Andreya-Autumn
Copy link
Collaborator

Yeah the 16 voice unison is something of a legacy option at this point. There's severely diminishing returns after around 7 or so anyway, and you're not the first to run into CPU and/or level issues with it.

Seems like the consensus is that the next major update (not strictly scheduled but planned sometime next year maybe) will have a more sensible max to the unison parameters. :)

@mkruselj
Copy link
Collaborator

Yeah those digital artifacts are your CPU being overloaded, not an error in Surge. Since this happens at 25% CPU, this tells me one core (assuming you have a quad core CPU) simply got oversaturated and since Surge doesn't do multicore processing, everything falls over.

At any rate, not a Surge bug.

@baconpaul
Copy link
Collaborator

We really will have to do multi core when we do xt2.

@danielhoey
Copy link
Contributor Author

Just a thought, but would it be useful to have an indicator showing when the CPU is overloaded? It wasn't obvious to me, but I'm newish to software synths so maybe this not such a mystery to most users.

I'm happy to look at implementing this if it is wanted

@baconpaul
Copy link
Collaborator

I’ve thought about doing a hires timer on process and comparing i with sr/32 yeah. If you want to give that a shot lemme know and I will add some more detailed notes here on how I would proceed. Welcome the dev help! I’ll reopen this and if your game add notes tomorrow am

@baconpaul baconpaul reopened this Aug 28, 2022
@danielhoey
Copy link
Contributor Author

danielhoey commented Aug 28, 2022 via email

@baconpaul baconpaul changed the title Digital artefacts present with multiple sine OSC with unison voices A Basic CPU Load Implementation Aug 28, 2022
@baconpaul
Copy link
Collaborator

OK so the basic idea is

  1. Time the main ::process loop and compare it with max time
  2. update a value smoothly with that ratio
  3. Display it in the UI (probably in the VU meter for now)

but before that begins, you want to make sure you can build and change surge. Standard advice is clone, checkout, build, modify one of the strings in src/surge-xt/gui/overlays/AboutScreen.cpp and then see that modification in menu/about in your running environment. For this exercise the standalone will be perfectly fine.

So to each of the steps

Time the main ::process loop.

  1. At the very start and end of SurgeSynthesizer::process add a call to std::chrono::high_resolution_clock::now (https://en.cppreference.com/w/cpp/chrono/high_resolution_clock/now) storing the results in local variables (like auto perf_start = ....)
  2. After you record the end time, subtract to get a duration and use duration_cast (https://en.cppreference.com/w/cpp/chrono/duration/duration_cast) to cast it to microseconds or whatever
  3. The number of microseconds the block has available at the absolute max is BLOCK_SIZE * storage->dsamplerate_inv * 1000000 so then you can make a ratio

Update a value

The UI thread runs much more slowly than the audio thread and you want to smooth the CPU anyway. The way we do this with the VU meter is an exponential decay. So lets do same here

  1. In SurgeSynthesizer.h near the VU stuff add std::atomic<float> cpuLevel{0.f}
  2. We already have a vu_falloff on storage. So we can do the same here, namely CPU is max of cpu and falloff.
    float a = storage.vu_falloff;
    there's how the VU meter works so you can do just the same on cpuLevel

Show the value

first thing I would do is in SurgeGUIEditor::idle just print the synth->cpuLevel on every idle and then see if it basically works to stdout. You can easily make high CPU with a high unison modern oscillator running into vintage ladder filters at high poly count. If it is working then we want to whack the VU meter to show the value if it is above some level.

I would do this as follows, but follow the code

  1. Add a cpuLevel member to the VUMeter class (src/surge-xt/gui/widgets/VuMeter.h) initialized to 0
  2. after that code do the same thing with the cpuLevel from the synth
  3. In the paint method of VuMeter for now just paint the cpu level on the right using g.drawText() with a fixed color
  4. If that works then we need to add a style color and stuff. You can either follow along from the code, ask on discord, or push a PR at this point which we can merge and then help you do that.

Discord is best way for realtime help and questions. Hope this helps!

@mkruselj mkruselj added Feature Request New feature request UI Issues related to UI look&feel and removed Bug Report Item submitted using the Bug Report template labels Aug 28, 2022
@mkruselj mkruselj added this to the Surge XT 1.1.x milestone Aug 28, 2022
@mkruselj
Copy link
Collaborator

mkruselj commented Nov 5, 2022

Oh hey, we have actually implemented this in 1.1.2! So, closing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature request UI Issues related to UI look&feel
Projects
None yet
Development

No branches or pull requests

4 participants