Sound Test
Source: src/sound_test.c · 83 lines · 4 functions.
Screen captures
Views of this part running on the Mini Arcade.

Screen / module overview
- Enter Sound Test
Stop tone, WAV and MP3 playback. Select the 740 Hz test tone frequency.
- Audio available?
Ignore action requests if audio is not ready; the display shows the I2S error.
- Handle controls
A / K toggles the tone. Volume requests adjust the persistent setting in five-percent steps. E toggles the Othello MP3 test.
- Draw status
Show audio wiring, tone/MP3 state and error information.
- Leave the screen
Stop all diagnostic playback and clear running.
Module entry points
These functions are exposed to the rest of the project. Open one to follow its decisions and the helpers it calls.
How to read these diagrams
Each function has its own expandable diagram using the actual expressions and statements from this file. Decisions split into True and False; loop bodies are indented. Returns end the function immediately; break and continue follow their C meanings. Arrows between statements show their order when execution reaches them.
These are structural source diagrams before preprocessing, not runtime traces. Conditional compilation and macros remain source expressions. Ternary choices remain inside their statement. Calls are linked separately; callback execution and task scheduling are not inferred.
Functions in this file
startSoundTest() · source line 34
void startSoundTest(void)
Calls into this documentation:
- Execute
running = true; - Execute
selected_note = SOUND_TEST_DEFAULT_NOTE; - Execute
audioStopTestTone(); - Execute
audioStopTestWav(); - Execute
audioStopTestMp3(); - Execute
audioSetTestToneFrequency(notes[selected_note].frequency_hz);
Read original function source
void startSoundTest(void) {
running = true;
selected_note = SOUND_TEST_DEFAULT_NOTE;
audioStopTestTone();
audioStopTestWav();
audioStopTestMp3();
audioSetTestToneFrequency(notes[selected_note].frequency_hz);
}stopSoundTest() · source line 42
void stopSoundTest(void)
Calls into this documentation:
- Execute
audioStopTestTone(); - Execute
audioStopTestWav(); - Execute
audioStopTestMp3(); - Execute
running = false;
Read original function source
void stopSoundTest(void) { audioStopTestTone(); audioStopTestWav(); audioStopTestMp3(); running = false; }soundTestAction() · source line 43
void soundTestAction(bool toggle_tone, bool volume_down, bool volume_up, bool toggle_mp3)
Calls into this documentation:
- Decision
!running || !audioReady()True- Exit this function
return;
FalseContinue after this decision.
- Execute
const uint8_t volume = audioMasterVolume(); - Decision
volume_down && volume >= SOUND_TEST_VOLUME_STEPTrue- Execute
settingsSetVolume(volume - SOUND_TEST_VOLUME_STEP);
FalseContinue after this decision.
- Decision
volume_up && volume <= 100U - SOUND_TEST_VOLUME_STEPTrue- Execute
settingsSetVolume(volume + SOUND_TEST_VOLUME_STEP);
FalseContinue after this decision.
- Decision
toggle_toneTrue- Decision
audioTestToneEnabled()True- Execute
audioStopTestTone();
False- Execute
audioStartTestTone(notes[selected_note].frequency_hz);
FalseContinue after this decision.
- Decision
toggle_mp3True- Decision
audioTestMp3Enabled()True- Execute
audioStopTestMp3();
False- Execute
(void)audioStartTestMp3();
FalseContinue after this decision.
Read original function source
void soundTestAction(bool toggle_tone, bool volume_down, bool volume_up, bool toggle_mp3) {
if (!running || !audioReady()) return;
const uint8_t volume = audioMasterVolume();
if (volume_down && volume >= SOUND_TEST_VOLUME_STEP) {
settingsSetVolume(volume - SOUND_TEST_VOLUME_STEP);
}
if (volume_up && volume <= 100U - SOUND_TEST_VOLUME_STEP) {
settingsSetVolume(volume + SOUND_TEST_VOLUME_STEP);
}
if (toggle_tone) {
if (audioTestToneEnabled()) audioStopTestTone();
else audioStartTestTone(notes[selected_note].frequency_hz);
}
if (toggle_mp3) {
if (audioTestMp3Enabled()) audioStopTestMp3();
else (void)audioStartTestMp3();
}
}drawSoundTest() · source line 61
void drawSoundTest(uint16_t *frame)
Calls into this documentation:
- Decision
!running || frame == NULLTrue- Exit this function
return;
FalseContinue after this decision.
- Execute
clear(frame, COLOR_BLACK); - Execute
draw_text_centred(frame, 160, 12, "SOUND TEST", 2, COLOR_CYAN); - Execute
draw_text_centred(frame, 160, 45, "GLOBAL AUDIO / MAX98357A", 1, COLOR_WHITE); - Execute
draw_text_centred(frame, 160, 62, "GPIO11 BCLK GPIO12 LRC", 1, COLOR_LIGHTGRAY); - Execute
draw_text_centred(frame, 160, 79, "GPIO13 DIN", 1, COLOR_LIGHTGRAY); - Decision
audioReady()True- Execute
char status[48]; - Execute
const bool mp3_playing = audioTestMp3Enabled(); - Execute
snprintf(status, sizeof(status), "OTHELLO MP3 %s", mp3_playing ? "PLAYING" : "READY"); - Execute
draw_text_centred(frame, 160, 101, status, 2, mp3_playing ? COLOR_YELLOW : COLOR_LIME); - Execute
draw_text_centred(frame, 160, 120, "DIRECT NATIVE MP3 LEVEL", 1, COLOR_CYAN); - Execute
draw_text_centred(frame, 160, 133, audioTestToneEnabled() ? "A/K STOP 740HZ TONE" : "A/K PLAY 740HZ TONE", 1, COLOR_WHITE); - Execute
draw_text_centred(frame, 160, 146, mp3_playing ? "E STOP OTHELLO MP3" : "E PLAY OTHELLO MP3", 1, COLOR_WHITE); - Execute
draw_text_centred(frame, 160, 157, audioTestMp3Error() == ESP_OK ? "NATIVE MONO HELIX PCM" : "MP3 OPEN OR DECODE ERROR", 1, audioTestWavError() == ESP_OK ? COLOR_CYAN : COLOR_RED);
False- Execute
char error[32]; - Execute
snprintf(error, sizeof(error), "I2S ERROR %d", audioLastError()); - Execute
draw_text_centred(frame, 160, 105, error, 2, COLOR_RED);
- Execute
draw_text_centred(frame, 160, 166, "BOOT BACK", 1, COLOR_LIGHTGRAY);
Read original function source
void drawSoundTest(uint16_t *frame) {
if (!running || frame == NULL) return;
clear(frame, COLOR_BLACK);
draw_text_centred(frame, 160, 12, "SOUND TEST", 2, COLOR_CYAN);
draw_text_centred(frame, 160, 45, "GLOBAL AUDIO / MAX98357A", 1, COLOR_WHITE);
draw_text_centred(frame, 160, 62, "GPIO11 BCLK GPIO12 LRC", 1, COLOR_LIGHTGRAY);
draw_text_centred(frame, 160, 79, "GPIO13 DIN", 1, COLOR_LIGHTGRAY);
if (audioReady()) {
char status[48];
const bool mp3_playing = audioTestMp3Enabled();
snprintf(status, sizeof(status), "OTHELLO MP3 %s", mp3_playing ? "PLAYING" : "READY");
draw_text_centred(frame, 160, 101, status, 2,
mp3_playing ? COLOR_YELLOW : COLOR_LIME);
draw_text_centred(frame, 160, 120, "DIRECT NATIVE MP3 LEVEL", 1, COLOR_CYAN);
draw_text_centred(frame, 160, 133, audioTestToneEnabled() ? "A/K STOP 740HZ TONE" : "A/K PLAY 740HZ TONE", 1, COLOR_WHITE);
draw_text_centred(frame, 160, 146, mp3_playing ? "E STOP OTHELLO MP3" : "E PLAY OTHELLO MP3", 1, COLOR_WHITE);
draw_text_centred(frame, 160, 157,
audioTestMp3Error() == ESP_OK ? "NATIVE MONO HELIX PCM" : "MP3 OPEN OR DECODE ERROR",
1, audioTestWavError() == ESP_OK ? COLOR_CYAN : COLOR_RED);
} else { char error[32]; snprintf(error, sizeof(error), "I2S ERROR %d", audioLastError()); draw_text_centred(frame, 160, 105, error, 2, COLOR_RED); }
draw_text_centred(frame, 160, 166, "BOOT BACK", 1, COLOR_LIGHTGRAY);
}Complete original file, including constants and data
/* Coded By JD(2026) */
#error "Reference listing only — not provided as build-ready source."
#include "sound_test.h"
#include "audio.h"
#include "game_colors.h"
#include "game_graphics.h"
#include "PET2001_font.h"
#include "settings.h"
#include "esp_err.h"
#include <stdio.h>
typedef struct {
const char *name;
uint16_t frequency_hz;
} sound_test_note_t;
static const sound_test_note_t notes[] = {
{"C3", 131U}, {"C#3", 139U}, {"D3", 147U}, {"D#3", 156U},
{"E3", 165U}, {"F3", 175U}, {"F#3", 185U}, {"G3", 196U},
{"G#3", 208U}, {"A3", 220U}, {"A#3", 233U}, {"B3", 247U},
{"C4", 262U}, {"C#4", 277U}, {"D4", 294U}, {"D#4", 311U},
{"E4", 330U}, {"F4", 349U}, {"F#4", 370U}, {"G4", 392U},
{"G#4", 415U}, {"A4", 440U}, {"A#4", 466U}, {"B4", 494U},
{"C5", 523U}, {"C#5", 554U}, {"D5", 587U}, {"D#5", 622U},
{"E5", 659U}, {"F5", 698U}, {"F#5", 740U}, {"G5", 784U},
{"G#5", 831U}, {"A5", 880U}, {"A#5", 932U}, {"B5", 988U},
{"C6", 1047U}, {"C#6", 1109U}, {"D6", 1175U}, {"D#6", 1245U},
{"E6", 1319U}, {"F6", 1397U}, {"F#6", 1480U}, {"G6", 1568U},
{"G#6", 1661U}, {"A6", 1760U}, {"A#6", 1865U}, {"B6", 1976U},
};
#define SOUND_TEST_NOTE_COUNT (sizeof(notes) / sizeof(notes[0]))
#define SOUND_TEST_DEFAULT_NOTE 32U
#define SOUND_TEST_VOLUME_STEP 5U
static uint8_t selected_note;
static bool running;
void startSoundTest(void) {
running = true;
selected_note = SOUND_TEST_DEFAULT_NOTE;
audioStopTestTone();
audioStopTestWav();
audioStopTestMp3();
audioSetTestToneFrequency(notes[selected_note].frequency_hz);
}
void stopSoundTest(void) { audioStopTestTone(); audioStopTestWav(); audioStopTestMp3(); running = false; }
void soundTestAction(bool toggle_tone, bool volume_down, bool volume_up, bool toggle_mp3) {
if (!running || !audioReady()) return;
const uint8_t volume = audioMasterVolume();
if (volume_down && volume >= SOUND_TEST_VOLUME_STEP) {
settingsSetVolume(volume - SOUND_TEST_VOLUME_STEP);
}
if (volume_up && volume <= 100U - SOUND_TEST_VOLUME_STEP) {
settingsSetVolume(volume + SOUND_TEST_VOLUME_STEP);
}
if (toggle_tone) {
if (audioTestToneEnabled()) audioStopTestTone();
else audioStartTestTone(notes[selected_note].frequency_hz);
}
if (toggle_mp3) {
if (audioTestMp3Enabled()) audioStopTestMp3();
else (void)audioStartTestMp3();
}
}
void drawSoundTest(uint16_t *frame) {
if (!running || frame == NULL) return;
clear(frame, COLOR_BLACK);
drawPet2001TextCentredTransparent(frame, 160, 12, "SOUND TEST", COLOR_CYAN, 2);
drawPet2001TextCentredTransparent(frame, 160, 45, "GLOBAL AUDIO / MAX98357A", COLOR_WHITE, 1);
drawPet2001TextCentredTransparent(frame, 160, 62, "GPIO11 BCLK GPIO12 LRC", COLOR_LIGHTGRAY, 1);
drawPet2001TextCentredTransparent(frame, 160, 79, "GPIO13 DIN", COLOR_LIGHTGRAY, 1);
if (audioReady()) {
char status[48];
const bool mp3_playing = audioTestMp3Enabled();
snprintf(status, sizeof(status), "OTHELLO MP3 %s", mp3_playing ? "PLAYING" : "READY");
drawPet2001TextCentredTransparent(frame, 160, 101, status,
mp3_playing ? COLOR_YELLOW : COLOR_LIME, 2);
drawPet2001TextCentredTransparent(frame, 160, 120, "DIRECT NATIVE MP3 LEVEL", COLOR_CYAN, 1);
drawPet2001TextCentredTransparent(frame, 160, 133, audioTestToneEnabled() ? "A/K STOP 740HZ TONE" : "A/K PLAY 740HZ TONE", COLOR_WHITE, 1);
drawPet2001TextCentredTransparent(frame, 160, 146, mp3_playing ? "E STOP OTHELLO MP3" : "E PLAY OTHELLO MP3", COLOR_WHITE, 1);
drawPet2001TextCentredTransparent(frame, 160, 157,
audioTestMp3Error() == ESP_OK ? "NATIVE MONO HELIX PCM" : "MP3 OPEN OR DECODE ERROR",
audioTestWavError() == ESP_OK ? COLOR_CYAN : COLOR_RED, 1);
} else { char error[32]; snprintf(error, sizeof(error), "I2S ERROR %d", audioLastError()); drawPet2001TextCentredTransparent(frame, 160, 105, error, COLOR_RED, 2); }
drawPet2001TextCentredTransparent(frame, 160, 166, "BOOT BACK", COLOR_LIGHTGRAY, 1);
}