Synthesizer DSP STM32 resources

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
justinjools
Posts: 3
Joined: Thu May 02, 2024 11:10 am

Synthesizer DSP STM32 resources

Post by justinjools »

Hi, I have built a 2 voice mono digital synth with Arduino Nano and would now like to try this out using the STM32 blue/black MCU's I have. Are there any useful resources, libraries for DSP STM32. I know there is STM32Duino but very little example and nothing about audio, DSP here. Does anyone have experience coding audio, synth projects with STM32 who could give some advice on where to start? I am also wondering how easy, difficult it would be to port the Arduino synth example I have done to STM32.
User avatar
Bakisha
Posts: 143
Joined: Fri Dec 20, 2019 6:50 pm
Answers: 5
Contact:

Re: Synthesizer DSP STM32 resources

Post by Bakisha »

As arduino, STM32 can use high PWM pulses to create audio. With even higher resolution because of better timers hardware. STM32 have some boards with 12bit DAC ( like cheap WeAct STM32G431CBU6 ).

For a start, you could use example from https://github.com/stm32duino/STM32Exam ... llback.ino to trigger at samplerate.

All arduino UNO/nano examples i found on net are using direct register access on timers, but if you understand how timers works on arduino, there is chance that it can be ported to STM32.

You could try RTTTL player from https://github.com/ag88/stm32duino_rtttl

or some sound effects from https://github.com/Bakisha/STM32-SID-PL ... s_barebone
justinjools
Posts: 3
Joined: Thu May 02, 2024 11:10 am

Re: Synthesizer DSP STM32 resources

Post by justinjools »

Interesting I have the WeAct BlackPill STM32F411CEU6 which also has two 12-bit ADCs (2 Msps) and one 12-bit DAC (1 Msps).
I tried some barbones tutorial series but found it was a bit too demanding for me. I'm comfortable with high level DSP programming libraries and this was to too abtract for me.
I have been using Mozzi with Arduino Uno for a 2 voice mono digital synth using Mozzi so my first idea was to see if I could port this code to STM32 and someone on Reddit has told me it should work. Other than this I haven't found any DSP libraries for STM32. It feels like I am lone explorer wanting to do DSP programming using libraries with STM32.
ag123
Posts: 1680
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: Synthesizer DSP STM32 resources

Post by ag123 »

Unfortunately, F411 do not have DACs.
https://www.st.com/en/microcontrollers- ... 411ce.html
Hence, for this chip PWM is about the only way to do some DAC.

stm32g431, stm32f407, stm32f405 etc has DAC, check the specs
https://www.st.com/en/microcontrollers- ... 2g4x1.html
https://www.st.com/en/microcontrollers- ... 5-415.html
https://www.st.com/en/microcontrollers- ... 7-417.html

Think Adafruit carries a decent stm32f405 feather board
https://www.adafruit.com/product/4382
Micropython originally has a F405 board
https://store.micropython.org/product/PYBv1.1
Olimex carries a F405 board as well
https://www.olimex.com/Products/ARM/ST/STM32-H405/
and WeAct carries a g431 board etc
https://www.aliexpress.com/item/1005006552207317.html

I've not actually played with the DAC on stm32s hence can't say much about them.

But that for DAC or even PWM DACs, you would need to hook them up with some amplifiers at the output stage as stm32s are not designed to produce that much power e.g. to drive a speaker etc.
ag123
Posts: 1680
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: Synthesizer DSP STM32 resources

Post by ag123 »

for synthesizer codes I'd guess it'd take quite a lot of c/c++ codes etc to synthesize
https://www.google.com/search?q=softwar ... er+c%2B%2B

if you're keen on midi there are things like gus patches the soundfonts files can easily be like > 100 megs
https://www.google.com/search?q=midi+sy ... es+c%2B%2B

full gus soundfont based polyphonic midi synthesis takes
- huge storage resources (> 100 megs for soundfonts alone for full set of gus patches)
- huge amount of memory (possibly megabytes)
- intensive cpu processing (with likely floating point processing as well)

Those are possibly better to run on cortex-A type processors e.g. like Raspberry Pi (4, 5 etc)
or possibly like stm32mp1 type boards
https://www.st.com/en/evaluation-tools/ ... a-dk1.html
or possibly stm32h7xx type processors preferably with external dram on board
https://www.st.com/en/microcontrollers- ... 3-733.html
User avatar
Bakisha
Posts: 143
Joined: Fri Dec 20, 2019 6:50 pm
Answers: 5
Contact:

Re: Synthesizer DSP STM32 resources

Post by Bakisha »

I tried Mozzi library and it's compatible with stm32duino core. Tested on stm32F103CB, STM32F401CC and STM32F411CE. All using pin PA8 PWM as audio output (as ag123 mention, STM32F411CE don't have DAC).
But it's little complex for me, and i think it would be easier for me to implement double-buffered sound playback from zero, then to understand how Mozzi work...
As for DSP, i can't help much, there is only one example in "File->Examples->CMSIS_DSP->arm_sin_cos_example_f32"
justinjools
Posts: 3
Joined: Thu May 02, 2024 11:10 am

Re: Synthesizer DSP STM32 resources

Post by justinjools »

That sounds good. The tutorial I have been following for Arduino Uno uses pin 9 for PWM out and then an opamp circuit for audio out. I also have some SPI MCP4822 DAC's to play around with - like some of the Mutable Instruments designs. I will play around with this, and will definately tryout the stm32F103CB in future, sounds more convenient to have on-board DAC's.
Post Reply

Return to “General discussion”