diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 42b18076..3e1bd9d3 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -64,6 +64,8 @@ Engine::Engine() SCLOG(" Version = " << scxt::build::FullVersionStr); SCLOG(" Stream V = " << humanReadableVersion(scxt::currentStreamingVersion)); + memset(cpuAverages, 0, sizeof(cpuAverages)); + id.id = rng.unifU32() % 1024; messageController = std::make_unique(*this); @@ -391,7 +393,11 @@ bool Engine::processAudio() // auto pct = time_span.count / maxtime; // or... auto pct = time_span.count() * sampleRate * blockSizeInv * 100.0; - sharedUIMemoryState.cpuLevel = std::max(sharedUIMemoryState.cpuLevel * 0.9995, pct); + auto ppct = cpuAverages[cpuWP]; + cpuAverages[cpuWP] = pct; + cpuWP = (cpuWP + 1) & (cpuAverageObservation - 1); + cpuAvg += (pct - ppct) / cpuAverageObservation; + sharedUIMemoryState.cpuLevel = cpuAvg; return true; } diff --git a/src/engine/engine.h b/src/engine/engine.h index 14f64779..ac5584b1 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -517,6 +517,11 @@ struct Engine : MoveableOnly, SampleRateSupport std::unique_ptr voiceInPlaceBuffer{nullptr}; std::unique_ptr messageController; std::unique_ptr selectionManager; + + static constexpr size_t cpuAverageObservation{64}; + size_t cpuWP{0}; + float cpuAvg{0.f}; + float cpuAverages[cpuAverageObservation]; }; } // namespace scxt::engine #endif