Skip to content

Commit

Permalink
Convert DetailType to enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
he29-net committed Aug 30, 2023
1 parent d67e0f3 commit d4412c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions include/AudioEngineProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,31 @@ class AudioEngineProfiler

void setOutputFile( const QString& outputFile );

enum DetailType {
enum class DetailType {
NoteSetup,
Instruments,
Effects,
Mixing,
DetailCount
};

void startDetail(const DetailType type) { m_detailTimer[type].reset(); }
void finishDetail(const DetailType type) { m_detailTime[type] = m_detailTimer[type].elapsed(); }
void startDetail(const DetailType type) { m_detailTimer[static_cast<int>(type)].reset(); }
void finishDetail(const DetailType type)
{
m_detailTime[static_cast<int>(type)] = m_detailTimer[static_cast<int>(type)].elapsed();
}

int detailLoad(const DetailType type) const { return m_detailLoad[type]; }
int detailLoad(const DetailType type) const { return m_detailLoad[static_cast<int>(type)]; }

private:
MicroTimer m_periodTimer;
float m_cpuLoad;
QFile m_outputFile;

// Use arrays to avoid dynamic allocations in realtime code
std::array<MicroTimer, DetailCount> m_detailTimer;
std::array<int, DetailCount> m_detailTime{0};
std::array<float, DetailCount> m_detailLoad{0};
std::array<MicroTimer, static_cast<int>(DetailType::DetailCount)> m_detailTimer;
std::array<int, static_cast<int>(DetailType::DetailCount)> m_detailTime{0};
std::array<float, static_cast<int>(DetailType::DetailCount)> m_detailLoad{0};
};

} // namespace lmms
Expand Down
2 changes: 1 addition & 1 deletion src/core/AudioEngineProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void AudioEngineProfiler::finishPeriod( sample_rate_t sampleRate, fpp_t framesPe
m_cpuLoad = std::min(newCpuLoad * 0.1f + m_cpuLoad * 0.9f, 100.f);

// Compute detailed load analysis. Can use stronger averaging to get more stable readout.
for (int i = 0; i < DetailCount; i++)
for (int i = 0; i < static_cast<int>(DetailType::DetailCount); i++)
{
const int newLoad = 100 * m_detailTime[i] / timeLimit;
m_detailLoad[i] = std::min(newLoad * 0.05f + m_detailLoad[i] * 0.95f, 100.f);
Expand Down

0 comments on commit d4412c7

Please sign in to comment.