# friedhamcheese/stm32synth architecture

> Architecture diagram of the GitHub repository friedhamcheese/stm32synth, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/friedhamcheese/stm32synth
- Repository: https://github.com/friedhamcheese/stm32synth

## Overview

This repository implements an embedded polyphonic synthesizer for STM32F401 boards. Its principal workflow scans key sensors on slave boards, transfers key frames over I²C to the master, converts key changes into voice events, synthesizes and mixes audio, and drives timer-based output. Knob controls, ADSR envelopes, waveform generation, volume oscillation, and autoplay are additional product capabilities. The main loop and module dependencies are visible in the excerpts and SOURCE INDEX; several internal call details are not, so uncertain links are omitted or dashed.

Main entry points: [`STM32/Core/Src/main.c`](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/main.c) (Main Loop), [`STM32/Core/Src/audio_out.c`](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/audio_out.c) (Audio Output), [`STM32/Core/Src/voice_manager.c`](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/voice_manager.c) (Voice Manager), [`STM32/Core/Src/synth_comms.c`](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/synth_comms.c) (Key Scan)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Key Input"]
  node_key_scan["Key Scan<br/>[synth_comms.c]"]
  node_sensor_read["Mux ADC<br/>[mux_adc.c]"]
  node_key_transport["I²C Key Frames<br/>[synth_comms.c]"]
  node_key_events["Key Events<br/>[synth_comms.c]"]
end

subgraph group_engine["Synthesis Engine"]
  node_controls["Controls<br/>[controls.c]"]
  node_autoplay["Autoplay<br/>[autoplay.c]"]
  node_voices["Voice Manager<br/>[voice_manager.c]"]
  node_envelope["ADSR Envelopes<br/>[adsr.c]"]
  node_waveforms["Waveform Generator<br/>[waveform.c]"]
  node_sine["Sine Lookup<br/>[sine_lookup.c]"]
  node_volume_mod["Volume Oscillation"]
end

subgraph group_output["Audio Output"]
  node_audio_mix["Audio Output<br/>[audio_out.c]"]
end

subgraph group_platform["Board Platform"]
  node_main["Main Loop<br/>[main.c]"]
  node_timers["Timer / Interrupts<br/>[stm32f4xx_it.c]"]
  node_adc["ADC Peripheral<br/>[adc.c]"]
  node_i2c["I²C Peripheral<br/>[i2c.c]"]
  node_gpio["GPIO<br/>[gpio.c]"]
end

node_player(("Player / Keys"))
node_hardware["STM32F401 Board"]

node_player -.->|"presses keys"| node_key_scan
node_main -.->|"updates scan"| node_key_scan
node_key_scan -.->|"reads channels"| node_sensor_read
node_key_scan -.->|"updates frames"| node_key_transport
node_key_transport -.->|"transfers frames"| node_i2c
node_main -->|"polls slaves"| node_key_transport
node_main -->|"processes keys"| node_key_events
node_key_events -->|"dispatches notes"| node_voices
node_main -->|"updates settings"| node_controls
node_main -->|"initializes voices"| node_voices
node_main -.->|"configures playback"| node_autoplay
node_voices -.->|"uses envelopes"| node_envelope
node_voices -.->|"generates samples"| node_waveforms
node_waveforms -.->|"uses lookup"| node_sine
node_audio_mix -.->|"mixes voices"| node_voices
node_audio_mix -.->|"applies modulation"| node_volume_mod
node_main -->|"initializes output"| node_audio_mix
node_main -->|"starts timers"| node_timers
node_timers -.->|"triggers audio"| node_audio_mix
node_main -->|"initializes ADC"| node_adc
node_main -->|"initializes I²C"| node_i2c
node_main -->|"initializes GPIO"| node_gpio
node_hardware -.->|"provides sensor input"| node_sensor_read
node_audio_mix -.->|"outputs audio"| node_hardware

click node_main "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/main.c"
click node_key_scan "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/synth_comms.c"
click node_sensor_read "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/mux_adc.c"
click node_key_transport "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/synth_comms.c"
click node_key_events "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/synth_comms.c"
click node_controls "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/controls.c"
click node_autoplay "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/autoplay.c"
click node_voices "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/voice_manager.c"
click node_envelope "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/adsr.c"
click node_waveforms "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/waveform.c"
click node_sine "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/sine_lookup.c"
click node_volume_mod "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/volume_oscillation.c"
click node_audio_mix "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/audio_out.c"
click node_timers "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/stm32f4xx_it.c"
click node_adc "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/adc.c"
click node_i2c "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/i2c.c"
click node_gpio "https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/gpio.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_key_scan,node_sensor_read,node_key_transport,node_key_events toneBlue
class node_controls,node_autoplay,node_voices,node_envelope,node_waveforms,node_sine,node_volume_mod toneAmber
class node_audio_mix toneMint
class node_main,node_timers,node_adc,node_i2c,node_gpio toneRose
class node_player,node_hardware toneIndigo
```

## Components

### Key Input

- [Key Scan](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/synth_comms.c): `STM32/Core/Src/synth_comms.c`
- [Mux ADC](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/mux_adc.c): `STM32/Core/Src/mux_adc.c`
- [I²C Key Frames](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/synth_comms.c): `STM32/Core/Src/synth_comms.c`
- [Key Events](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/synth_comms.c): `STM32/Core/Src/synth_comms.c`

### Synthesis Engine

- [Controls](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/controls.c): `STM32/Core/Src/controls.c`
- [Autoplay](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/autoplay.c): `STM32/Core/Src/autoplay.c`
- [Voice Manager](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/voice_manager.c): `STM32/Core/Src/voice_manager.c`
- [ADSR Envelopes](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/adsr.c): `STM32/Core/Src/adsr.c`
- [Waveform Generator](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/waveform.c): `STM32/Core/Src/waveform.c`
- [Sine Lookup](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/sine_lookup.c): `STM32/Core/Src/sine_lookup.c`
- [Volume Oscillation](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/volume_oscillation.c): `STM32/Core/Src/volume_oscillation.c`

### Audio Output

- [Audio Output](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/audio_out.c): `STM32/Core/Src/audio_out.c`

### Board Platform

- [Main Loop](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/main.c): `STM32/Core/Src/main.c`
- [Timer / Interrupts](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/stm32f4xx_it.c): `STM32/Core/Src/stm32f4xx_it.c`
- [ADC Peripheral](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/adc.c): `STM32/Core/Src/adc.c`
- [I²C Peripheral](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/i2c.c): `STM32/Core/Src/i2c.c`
- [GPIO](https://github.com/friedhamcheese/stm32synth/blob/main/STM32/Core/Src/gpio.c): `STM32/Core/Src/gpio.c`

### Other components

- **Player / Keys**
- **STM32F401 Board**

## Connections

- Player / Keys → Key Scan: presses keys
- Main Loop → Key Scan: updates scan
- Key Scan → Mux ADC: reads channels
- Key Scan → I²C Key Frames: updates frames (evidence: `STM32/Core/Src/synth_comms.c`)
- I²C Key Frames → I²C Peripheral: transfers frames
- Main Loop → I²C Key Frames: polls slaves (evidence: `STM32/Core/Src/main.c`)
- Main Loop → Key Events: processes keys (evidence: `STM32/Core/Src/main.c`)
- Key Events → Voice Manager: dispatches notes
- Main Loop → Controls: updates settings (evidence: `STM32/Core/Src/main.c`)
- Main Loop → Voice Manager: initializes voices (evidence: `STM32/Core/Src/main.c`)
- Main Loop → Autoplay: configures playback
- Voice Manager → ADSR Envelopes: uses envelopes
- Voice Manager → Waveform Generator: generates samples
- Waveform Generator → Sine Lookup: uses lookup
- Audio Output → Voice Manager: mixes voices
- Audio Output → Volume Oscillation: applies modulation
- Main Loop → Audio Output: initializes output (evidence: `STM32/Core/Src/main.c`)
- Main Loop → Timer / Interrupts: starts timers (evidence: `STM32/Core/Src/main.c`)
- Timer / Interrupts → Audio Output: triggers audio
- Main Loop → ADC Peripheral: initializes ADC (evidence: `STM32/Core/Src/main.c`)
- Main Loop → I²C Peripheral: initializes I²C (evidence: `STM32/Core/Src/main.c`)
- Main Loop → GPIO: initializes GPIO (evidence: `STM32/Core/Src/main.c`)
- STM32F401 Board → Mux ADC: provides sensor input
- Audio Output → STM32F401 Board: outputs audio
