Tymbal: Neural Synthesizer on a Single Chip
Tymbal is a real-time polyphonic synthesizer running on a single STM32N657 microcontroller (Cortex-M55 + Neural-ART NPU). It uses a TCN neural network as a residual refiner to add nonlinear character to a deterministic harmonic skeleton, all within strict cycle budgets and zero underruns. The project details extensive optimization, from graph transformations to memory management, achieving the final real-time performance on-device.
Tymbal is a polyphonic real-time synthesizer on a single NUCLEO-N657X0-Q board (STM32N657: Cortex-M55 at 800 MHz + Neural-ART NPU), controlled via MIDI keyboard, with I2S-DAC output. The audio is computed in 4 ms blocks; at 800 MHz that's 3.2 million cycles per hop for everything: voices, harmonic synthesis, neural network, filter bank, detune, limiter, with zero underruns. The architecture uses a PQMF four-subband domain (12 kHz each) to reduce cost and give the network a compact input. The harmonic skeleton is rendered directly into subbands using complex filter responses, with an anti-chiptune layer (auto-unison, spectral bloom, micro-drift). A causal TCN with 12 layers, dilations 1..32, C=88 channels runs on the NPU as a residual refiner, quantized to int8 via PTQ. The key insight was that a network trained naively on residual prediction loses to a linear FIR of 520 coefficients; the fix was to freeze the linear part as a 'zero layer' (pred = FIR(x) + net(x)), so the network learns only the nonlinear residual. Final eval: FIR alone gives +11.25 dB suppression, FIR+net fp32 +17.16, int8 +16.89, with network contributing +5.64 dB. Extensive bring-up findings include ECC random content after reset, disabled AXISRAM banks, NOR-flash path issues, NPU clock divider incorrect (400 instead of 800 MHz), and a false assert. Budget optimization started at 4.18M cycles/hop, finally achieving 2.47M worst-case chord, 0 underrun. Techniques included a measurement loop (QEMU vs board cycles), NPU epoch profiling, pumping (non-blocking NPU calls interleaved with rendering), moving hot tables to DTCM, and MVE-based memory copy for state ring.
- Abbreviations
- TCN = Temporal Convolutional Network — временная свёрточная сеть
- PQMF = Pseudo-Quadrature Mirror Filter — псевдоквадратурное зеркальное фильтрование
- NPU = Neural Processing Unit — нейропроцессор
- DTCM = Data Tightly Coupled Memory — тесно связанная память данных
- DWT = Data Watchpoint and Trace — трассировка и точки останова данных
- QEMU = Quick Emulator — быстрый эмулятор
- FIR = Finite Impulse Response — конечная импульсная характеристика
- PTQ = Post-Training Quantization — квантование после обучения
- MVE = M-profile Vector Extension — векторное расширение для M-профиля
- I2S = Integrated Interchip Sound — цифровой аудиоинтерфейс
- DAC = Digital-to-Analog Converter — цифро-аналоговый преобразователь
- MIDI = Musical Instrument Digital Interface — цифровой интерфейс музыкальных инструментов
- SGD = Stochastic Gradient Descent — стохастический градиентный спуск
- ONNX = Open Neural Network Exchange — открытый формат обмена нейронными сетями
- CRC = Cyclic Redundancy Check — циклический избыточный код
- ECC = Error Correction Code — код исправления ошибок
- AXI = Advanced eXtensible Interface — расширяемый интерфейс (протокол шины)
- NOR = NOR (Not OR) flash — флеш-память типа NOR
- SPI = Serial Peripheral Interface — последовательный периферийный интерфейс
Source: Habr — хаб ML —
original
