video: (https://www.youtube.com/watch?v=qGgl6kaOK0E)
An STM32-based DJ controller for real-time audio playback and effects. Designed for smooth performance with responsive controls.
This project demonstrates how to convert a song into raw digital data and play it back using a DAC on a microcontroller. It includes audio conversion with Python, playback using timer interrupts, and streaming via UART with DMA for memory efficiency.
To play a song on the DAC, the audio must first be digitized and embedded into the firmware.
- A Python script is used to convert a raw PCM audio file into a C array.
- The raw audio file is prepared in Audacity by trimming, resampling to 8kHz, and exporting as raw (unsigned 8-bit PCM).
- The script reads the raw binary data and outputs a
.c
file containing anunsigned char
array of samples.
🎯 Sample rate: 8000 samples per second
📦 Bit depth: 8-bit unsigned integers
🔧 This step allows the song to be compiled directly into the firmware for playback.
Accurate timing is crucial for clean audio playback. If samples are sent to the DAC at inconsistent intervals or incorrect frequencies, the pitch and tempo will be off.
To maintain proper timing:
- A hardware timer interrupt is configured to trigger exactly every 125 microseconds (8kHz).
- On each interrupt, the next sample is written to the DAC.
- Changing the timer prescaler adjusts the playback tempo.
This ensures the song is played back at the correct pitch and speed.
Flash memory on most microcontrollers is limited, which restricts the size of audio files that can be embedded.
To overcome this:
- Audio data is streamed over UART from a PC in small chunks.
- A DMA controller buffers the incoming data.
- Playback continues smoothly while new data is received.
This allows for songs of unlimited length, stored on the host computer and streamed in real time.
- Microcontroller: STM32 Nucleo F446ZE
- Audio Codec: RAW DAC
- Firmware: STM32 HAL/CubeMX
- Development Tools: STM32CubeIDE
- Clone the repo:
git clone https://github.com/dagsion/STM32-DJ-Controller.git
- Open in STM32CubeIDE and flash firmware.
- Connect hardware components.
David Xu and Osiris Xiao