▸ MIDI → ESP32 poly synth

core 3.x · polyphonic square waves · PWM output on one pin
no file selected
Higher = cleaner. 22 kHz is a safe default. Values that divide 80 MHz cleanly (16k, 20k, 25k, 32k, 40k) drift less over long tracks.
Simultaneous notes. SMW overworld stacks 5-note chords; 24–32 is safe.
waiting for midi file
▸ why this works everywhere · the ISR touches only RAM and integer arithmetic — no ledcWrite, no floats, no register addresses. It just advances voice phases and writes one byte to a volatile uint8_t. ledcWrite is called from loop(), where flash is accessible and the LEDC peripheral is properly initialized by ledcAttach. The PWM carrier keeps running at full rate, so audio quality is unchanged.
▸ wiring · GPIO25 ── 1kΩ ──┬── 10nF ── GND · the junction feeds an amp or piezo. Add a 10 µF DC blocker before the amp. Without the RC filter you'll hear the 62.5 kHz carrier whine over the music.