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

Move CPU meter from max + LPF to 64 block average #1323

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<messaging::MessageController>(*this);
Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions src/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ struct Engine : MoveableOnly<Engine>, SampleRateSupport
std::unique_ptr<uint8_t[]> voiceInPlaceBuffer{nullptr};
std::unique_ptr<messaging::MessageController> messageController;
std::unique_ptr<selection::SelectionManager> selectionManager;

static constexpr size_t cpuAverageObservation{64};
size_t cpuWP{0};
float cpuAvg{0.f};
float cpuAverages[cpuAverageObservation];
};
} // namespace scxt::engine
#endif
Loading