STM32F103 minimal synth

What are you developing?
ag123
Posts: 767
Joined: Thu Jul 21, 2016 4:24 pm

Re: STM32F103 minimal synth

Post by ag123 » Thu Apr 06, 2017 4:17 pm

oops, at hi-fi speeds, this scope
http://www.stm32duino.com/viewtopic.php?f=19&t=107
is all i've or can make, probably can't measure up to those hi-fi mhz traces
nevertheless would check out the synth :D

victor_pv
Posts: 1679
Joined: Mon Apr 27, 2015 12:12 pm

Re: STM32F103 minimal synth

Post by victor_pv » Thu Apr 06, 2017 11:58 pm

I dont think I have something fast enough either. I would think you may be getting no more than 36Mhz. From the datasheet, the DMA will share access to RAM with the cpu, but will not block it. I dont remember how many cpu ram IO cycles are allowed before the DMA is allowed one, but sure no less than 50% goes to the cpu. It's probably lower than that thought.
That would give 36Mbit in a single pin.
The SPI port can do 36Mbit in a single pin too, but with 16bit transfers it only needs to read from ram 1 per 16 bits. So the DMA controller is able to maintain the SPI 1 word buffer full all the time.
Now if you wanted to use multiple pins with the SPI you could use both SPI, but with the GPIO ports I guess up to 16 channels if they are all in the same GPIO port, you are not adding any extra DMA transfer, would be interesting to push it to the limit...

Anyway, about using the SPI, you can set the DMA transfer pretty much similar to how you set it for GPIO, but need to enable the SPI port DMA request flag. Check the SPI library where we added dmaSend functions to do DMA transfers to get ideas.
You could also set the port to a different speed, since the speed is known, you can refill the buffer at the required rate, and keep the DMA in circular mode as you do for the GPIO.

ChrisMicro
Posts: 308
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

Re: STM32F103 minimal synth

Post by ChrisMicro » Sun Apr 16, 2017 2:36 pm

Hi Victor,

I just realized that there is an upcoming Arduino sound library:
https://www.arduino.cc/en/Reference/ArduinoSound

Because you wrote the SD card audio player it could be a good idea to make the API somehow compatible.

victor_pv
Posts: 1679
Joined: Mon Apr 27, 2015 12:12 pm

Re: STM32F103 minimal synth

Post by victor_pv » Sun Apr 16, 2017 2:41 pm

ChrisMicro wrote:Hi Victor,

I just realized that there is an upcoming Arduino sound library:
https://www.arduino.cc/en/Reference/ArduinoSound

Because you wrote the SD card audio player it could be a good idea to make the API somehow compatible.
Chris I wrote an i2s driver that should be mostly compatible with the Arduino i2s API (plus uses dma). It this library uses the i2s driver, shouldn't be difficult to port.
Have you seen the source to that Sound library somewhere?

ChrisMicro
Posts: 308
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

Re: STM32F103 minimal synth

Post by ChrisMicro » Sun Apr 16, 2017 3:48 pm

Have you seen the source to that Sound library somewhere?
I think it is this one:
https://github.com/arduino-libraries/Ar ... master/src

and also very important, the I2S-class:
https://github.com/arduino/ArduinoCore- ... rc/I2S.cpp

victor_pv
Posts: 1679
Joined: Mon Apr 27, 2015 12:12 pm

victor_pv

Post by victor_pv » Sun Apr 16, 2017 5:44 pm

ChrisMicro wrote:
Have you seen the source to that Sound library somewhere?
I think it is this one:
https://github.com/arduino-libraries/Ar ... master/src

and also very important, the I2S-class:
https://github.com/arduino/ArduinoCore- ... rc/I2S.cpp
The i2s is the same API I followed, I'll have to check the audio library, hopefully not much low level hardware access on that.

EDIT: had a look and the rest of the files don't seem to have direct hardware access, so they should work with my i2s library. If you have a board with i2s, give it a shot. The mcus with i2s are the rct6 and higher.

ChrisMicro
Posts: 308
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

Re: STM32F103 minimal synth

Post by ChrisMicro » Mon Apr 17, 2017 4:03 am

EDIT: had a look and the rest of the files don't seem to have direct hardware access, so they should work with my i2s library. If you have a board with i2s, give it a shot. The mcus with i2s are the rct6 and higher.
The only board with I2S codec I have is a STM32F4 discovery.

I think for quick an cheap solutions the I2S DAC can be replaced by any other audio output device like
- built in PWM
- the DMA sigma delta
- SD-Card ( to store sounds )

As audio input
- a mircrophone
- a build in ADC
- built in synthesizer routines
- or stored sounds on a SD-card
could serve.

The sound library is made for attaching different in- and output devices but the only low level driver directly usable with it is for the Arduino Zero witch a SAMD21 microcontroller.

Because I think in general solutions usable for all people it would be useful if for any board supports a driver compatible to the Arduino sound library. Probably the best people suitable for this tasks are the core developers.

victor_pv
Posts: 1679
Joined: Mon Apr 27, 2015 12:12 pm

Re: STM32F103 minimal synth

Post by victor_pv » Mon Apr 17, 2017 4:53 am

ChrisMicro wrote:
EDIT: had a look and the rest of the files don't seem to have direct hardware access, so they should work with my i2s library. If you have a board with i2s, give it a shot. The mcus with i2s are the rct6 and higher.
The only board with I2S codec I have is a STM32F4 discovery.

I think for quick an cheap solutions the I2S DAC can be replaced by any other audio output device like
- built in PWM
- the DMA sigma delta
- SD-Card ( to store sounds )

As audio input
- a mircrophone
- a build in ADC
- built in synthesizer routines
- or stored sounds on a SD-card
could serve.

The sound library is made for attaching different in- and output devices but the only low level driver directly usable with it is for the Arduino Zero witch a SAMD21 microcontroller.

Because I think in general solutions usable for all people it would be useful if for any board supports a driver compatible to the Arduino sound library. Probably the best people suitable for this tasks are the core developers.
From looking at the source it seems like the only In/Out device they have implemented is the i2s anyway, but as you said the library is writen to support multiple devices, so something else could be used, ADC and DAC, delta/sigma...
I really do not have time to try to test this at the moment, but if you decide to give it a shot I would guess adapting your delta sigma DAC shoul not be too hard.
Have you tried adapting the delta/sigma to use the SPI port for output? I still do not understand how the decoding from a PCM stream to delta sigma 1 bit output works, but I can give you some advice on setting the SPI port the right way if you tell me what is needed.
As a start, the SPI port can run up to 36Mhz, and from that down to 560Khz or so I believe, dividing by powers of 2.
The spi port can be sent to transfer 16 bits at once, and we have functions to send using DMA.
So if we decide what speed to set the port to, can you generate the bit stream that would need to be sent to achieve a certain sample rate?
Say we set the port to 1.125Mbps, can you take a PCM stream samples at 44.1Khz and generate the 16bit works to send thru the SPI port at 1.125 Megabits?

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: STM32F103 minimal synth

Post by madias » Fri May 19, 2017 5:54 pm

Maybe you have read my version of a STM32duino synth in this project tab:
viewtopic.php?f=19&t=533
I never finished the project 100% (maybe 95%) because I lost interest & totally busy with my 2 kids
In short:
The best idea is to buy some cheap PT8211 DAC's to get a "true" 16-bit sound. (they are in the (Euro) Cent region, so buy 20 or 50 for a few bugs)
There are two things you can do:
1. Using a STM32F103xx without I2s - I pretty shure (as I can remember) to get the DAC with only SPI to work. I think Victor did this.
2. Using a cheap STM32F103 board with activated I2s, like this one:
https://www.aliexpress.com/item/STM32F1 ... 62693.html
I was using the board above to get a wavetable synth with 4 voice polyphony AND 4 individual outputs! (2 DAC - stereo = 4 mono) AND using the third SPI for everything else (like SD-Card, Flash RAM, Display)
The I2S-wavetable routine was totally slim and DMA driven (thanks to Victor) without MCU wasting (you have to read my complete thread to get the code, because I can't remember everything)
The next advantage over the board above (I thing the xxxVET board is even much better): 256kb Flash and 48 RAM. So more RAM more accurate wavetables.

Also search this forum for: USB MIDI HID. I managed to get the STM32 via USB recognized as MIDI device. So no external MIDI hardware neccessary (if not needed).

A next level of synth MCU programming would be the STM32F4, because of it's floting point features, so no stupid oldschool wavetables, but realtime processing sounds.

Edit: There must be another (at least one) thread about the PT8211 in this forum, can be easily found with the search function.

Edit 2: Found the SPI version of the PT8211 DAC, originally written by Vassilis (not Victor, sorry for that): viewtopic.php?f=18&t=519

Edit 3: I see, ChrisMicro, that you found already the thread :)

ag123
Posts: 767
Joined: Thu Jul 21, 2016 4:24 pm

Re: STM32F103 minimal synth

Post by ag123 » Sat May 20, 2017 5:38 pm

i think besides working as a 'synth' one of the main feature here is that delta sigma DAC which uses little other than simply 'bit bang' a digital pin and using an RC filter to get the resulting analog signal. accordingly this can possibly scale to very high precision e.g. 24 bits dependent on the signal-to-noise radio and the bit bang frequency. for 24 bits, my guess is that the bit bang bit rates would be in the order of million bits per secs to achieve those s/n ratios
http://www.beis.de/Elektronik/DeltaSigm ... Sigma.html

i't guess it is possible to imagine that given stm32f103 is a full usb device, it may be possible to create usb-audio on the usb side and for those digital audio, bit bang that on the pin, do that RC filter, some simple amplifiers (e.g. some transistors) and a 3.5mm jack and perhaps you may achieve a 24 bit stereo USB HD audio
i think it isn't really very different from PWM DAC

did a little 'crazy' computations, assuming that we have single channel audio at 48 ksps, and lets say we want a 24 bit gratuity, so that means 2^24 ~ 16,777,216 'levels' so that means a sample rate of 16.77 million bits / s x 48,000 ~ 805,306,368,000 ~ 805.3 gigabits per second? :shock:
hmm, strange, but even if you do super max overclock for stm32f103 u may 'never' get there 805 gigahertz not even intel i7 with the most powerful processor gets there :lol:

Post Reply