Skip to content

Commit

Permalink
Move CPU meter from max + LPF to 64 block average (#1323)
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul authored Sep 13, 2024
1 parent 8ffc51f commit 34b88bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit 34b88bc

Please sign in to comment.