Sound Test

Source: src/sound_test.c · 83 lines · 4 functions.

Screen captures

Views of this part running on the Mini Arcade.

Sound Test running on the physical Mini Arcade
Sound Test displayed on the physical Mini Arcade.

Screen / module overview

  1. Enter Sound Test

    Stop tone, WAV and MP3 playback. Select the 740 Hz test tone frequency.

  2. Audio available?

    Ignore action requests if audio is not ready; the display shows the I2S error.

  3. Handle controls

    A / K toggles the tone. Volume requests adjust the persistent setting in five-percent steps. E toggles the Othello MP3 test.

  4. Draw status

    Show audio wiring, tone/MP3 state and error information.

  5. 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:

  1. Executerunning = true;
  2. Executeselected_note = SOUND_TEST_DEFAULT_NOTE;
  3. ExecuteaudioStopTestTone();
  4. ExecuteaudioStopTestWav();
  5. ExecuteaudioStopTestMp3();
  6. ExecuteaudioSetTestToneFrequency(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:

  1. ExecuteaudioStopTestTone();
  2. ExecuteaudioStopTestWav();
  3. ExecuteaudioStopTestMp3();
  4. Executerunning = 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:

  1. Decision!running || !audioReady()
    True
    1. Exit this functionreturn;
    False

    Continue after this decision.

  2. Executeconst uint8_t volume = audioMasterVolume();
  3. Decisionvolume_down && volume >= SOUND_TEST_VOLUME_STEP
    True
      1. ExecutesettingsSetVolume(volume - SOUND_TEST_VOLUME_STEP);
    False

    Continue after this decision.

  4. Decisionvolume_up && volume <= 100U - SOUND_TEST_VOLUME_STEP
    True
      1. ExecutesettingsSetVolume(volume + SOUND_TEST_VOLUME_STEP);
    False

    Continue after this decision.

  5. Decisiontoggle_tone
    True
      1. DecisionaudioTestToneEnabled()
        True
        1. ExecuteaudioStopTestTone();
        False
        1. ExecuteaudioStartTestTone(notes[selected_note].frequency_hz);
    False

    Continue after this decision.

  6. Decisiontoggle_mp3
    True
      1. DecisionaudioTestMp3Enabled()
        True
        1. ExecuteaudioStopTestMp3();
        False
        1. Execute(void)audioStartTestMp3();
    False

    Continue 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:

  1. Decision!running || frame == NULL
    True
    1. Exit this functionreturn;
    False

    Continue after this decision.

  2. Executeclear(frame, COLOR_BLACK);
  3. Executedraw_text_centred(frame, 160, 12, "SOUND TEST", 2, COLOR_CYAN);
  4. Executedraw_text_centred(frame, 160, 45, "GLOBAL AUDIO / MAX98357A", 1, COLOR_WHITE);
  5. Executedraw_text_centred(frame, 160, 62, "GPIO11 BCLK GPIO12 LRC", 1, COLOR_LIGHTGRAY);
  6. Executedraw_text_centred(frame, 160, 79, "GPIO13 DIN", 1, COLOR_LIGHTGRAY);
  7. DecisionaudioReady()
    True
      1. Executechar status[48];
      2. Executeconst bool mp3_playing = audioTestMp3Enabled();
      3. Executesnprintf(status, sizeof(status), "OTHELLO MP3 %s", mp3_playing ? "PLAYING" : "READY");
      4. Executedraw_text_centred(frame, 160, 101, status, 2, mp3_playing ? COLOR_YELLOW : COLOR_LIME);
      5. Executedraw_text_centred(frame, 160, 120, "DIRECT NATIVE MP3 LEVEL", 1, COLOR_CYAN);
      6. Executedraw_text_centred(frame, 160, 133, audioTestToneEnabled() ? "A/K STOP 740HZ TONE" : "A/K PLAY 740HZ TONE", 1, COLOR_WHITE);
      7. Executedraw_text_centred(frame, 160, 146, mp3_playing ? "E STOP OTHELLO MP3" : "E PLAY OTHELLO MP3", 1, COLOR_WHITE);
      8. Executedraw_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
      1. Executechar error[32];
      2. Executesnprintf(error, sizeof(error), "I2S ERROR %d", audioLastError());
      3. Executedraw_text_centred(frame, 160, 105, error, 2, COLOR_RED);
  8. Executedraw_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);
}