Skip to content

Commit

Permalink
AudioApplets: Display CPU and MEM
Browse files Browse the repository at this point in the history
  • Loading branch information
qiemem committed Oct 17, 2024
1 parent 8b9150e commit 629fc24
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
25 changes: 23 additions & 2 deletions software/src/AudioAppletSubapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,17 @@ class AudioAppletSubapp {
for (size_t i = 0; i < Slots; i++) {
print_applet_line(i);
}

if (edit_state == EDIT_LEFT) {
HemisphereAudioApplet& applet = IsStereo(left_cursor)
? get_stereo_applet(left_cursor)
: get_mono_applet(LEFT_HEMISPHERE, left_cursor);
applet.BaseView();
gfxFrame(64, 0, 64, 64);
} else {
gfxPrint(65, 2, "R Channel");
// gfxPrint(65, 2, "R Channel");
gfxPos(65, 2);
graphics.printf("MEM%3d%%) R", mem_percent);
gfxDottedLine(64, 10, 126, 10);
}
if (edit_state == EDIT_RIGHT) {
Expand All @@ -118,9 +121,23 @@ class AudioAppletSubapp {
applet.BaseView();
gfxFrame(0, 0, 64, 64);
} else {
gfxPrint(1, 2, "L Channel");
// gfxPrint(1, 2, "L Channel");
gfxPos(1, 2);
graphics.printf("L (CPU%3d%%", cpu_percent);
gfxDottedLine(0, 10, 62, 10);
}

// Recall that unsigned substraction rolls over correclty, so when millis()
// rolls over, this will still work.
if (millis() - last_stats_update > 250) {
last_stats_update = millis();
mem_percent = static_cast<int16_t>(
100 * static_cast<float>(AudioMemoryUsageMax()) / OC::AudioIO::AUDIO_MEMORY
);
cpu_percent = static_cast<int16_t>(AudioProcessorUsageMax());
AudioProcessorUsageMaxReset();
AudioMemoryUsageMaxReset();
}
}

void HandleEncoderButtonEvent(const UI::Event& event) {
Expand Down Expand Up @@ -320,6 +337,10 @@ class AudioAppletSubapp {

uint32_t last_update = 0;

int16_t mem_percent = 0;
int16_t cpu_percent = 0;
uint32_t last_stats_update = 0;

enum EditState {
EDIT_NONE,
EDIT_LEFT,
Expand Down
2 changes: 1 addition & 1 deletion software/src/AudioIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace OC {
}

void Init() {
AudioMemory(128);
AudioMemory(AUDIO_MEMORY);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions software/src/AudioIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace OC {
namespace AudioIO {
const int AUDIO_MEMORY = 128;
AudioInputI2S2& InputStream();
AudioOutputI2S2& OutputStream();
void Init();
Expand Down

0 comments on commit 629fc24

Please sign in to comment.