STM32 audio processing part3

If you are really  stubborn enough to get this audio processing thing going on a STM32 MCU you might have discovered the excellent series of videos by YetAnotherElectronicChannel


He is using one of these relatively cheap i2s boards from Pmod stocked with Cirrus Logic chips. The big advantage of these tiny ADDA convertors is that they don't need any extra programming (by i2c or spi)

Sonically they are not the most brilliant and rather susceptible to all kinds of weird interference. But to get the concept going: just fine!


I will not repeat everything mentioned in his videos about circular buffers or data type casting. So check these first. However, there is some problems:

One of the most commonly used group of STM chips is the STM32F407 (and 405). If you are going to use the HAL libraries (yes, you will) be aware that there is 1 bug and 1 conceptual error in the libraries used in full duplex modus.

For future reference:

1. The DMA complete doesn't trigger the Hal_CompleteCallback

2. Both DMA interrupts (both send and receive) do trigger the Callback (if you get 1. going)

https://github.com/STMicroelectronics/stm32f4xx_hal_driver/issues/1

In my comments to the yetanotherelectronic videos and in the above bug report you can find the work around. Be aware that if you do change the HAL libraries, CubeMX will change them back if you use the cube-regenerate-code options!

 Edit feb 2022: somebody did finally rewrite the Hal_i2s_ex libraries..yeee!!

 

Now with these all going wouldn't it be nice to have a dedicated board instead of everything breadboarded / dupont wired?

This is one of my early attempts with some never heard of chinese brand of ADDA that do actually work quite well.

Again the mix between 'audiophile' capacitor in THT and SMD components. Which is way more easy nowadays as these PCB manufactures also provide SMD assembly services.




 


Image slider

1 / 4
Caption Text
2 / 4
Caption Two
3 / 4
Caption Three
4 / 4
Caption Four

Magnitude + Phase ... Bodeplots

Part1:  Bode plots.

Some 150 years ago a couple of brilliant guys like Fourier, Hertz and Helmholtz proved that every periodic signal (like music) can be seen as a combination of sine waves:


So, when we do understand the behaviour of sine waves in our system we do understand our system.
Two parameters of sine waves are quite obvious, amplitude for loudness and wavelength for pitch.
Taken in to account that both these are perceived in a logarithmic manner we often use magnitude in dB's and frequency in Hz for these two parameters.

Ok, so far everybody with only a wee bit of audio knowledge will know this and work with these two concepts on a daily base.

Now for a more tricky concept.
Phase:

Actually music consisting of only 1 sine wave at the time can be a bit boring ;)
So normally when we would decompose our music into sine waves we would see really a lot of them.
At this point we also have to include the way they are related in time, in the analytic description of our systems.
Phase expresses this in a manner of how these frequencies are related to each other, rather then absolutely, in time.
Certainly we could express this relation in much more intuitive units like seconds (or ms). (actually we sometimes do and call this groupdelay)
But 1ms of time shift on wave of 10kHz has a completely different impact (in terms of phase) than the same time shift on a wave of 100 Hz.
So expressing this time difference in phase degrees will work better in our case.


Now we all know these pictures and the concept of describing a system in terms of frequency response:


More highs, more lows and for the more literate we also have mids... ;)
By now we should know that this is only half the story.
If we do a frequency analyses like the above (also called a bode plot) we should  also include the phase behaviour.


So for correctly describing how system X responses to a input one should see this kind of pictures:


Don't think this will be a nice sounding loudspeaker system, but hey..

Time (delay) and phase are intertwined and there is really a lot of confusion out there.
Let's agree to some conventions:
  • For now lets define phase difference as every time related difference between the sine components of our signals where one of them will be set to zero-time or 0' degrees shift. (usually the highest frequency).
  • Furthermore: if a group of these sine components are delayed by a equal amount of time I will not regard this as a phase difference! (for example in a two way system in which both sources have a physical distance)

next part2: FFT analyses