YetAnotherElectronicsChannel / ESP32_Bluetooth_Audio_Receiver

48 stars 12 forks source link

About changing the volume #4

Open amweu opened 3 years ago

amweu commented 3 years ago

Hi, your example has helped me a lot. But when I was finishing my project, I found out some things around the Volumen control. In my electronics, the dac is connected to an adc and then the signal goes into an adau1701 dsp. The dac-adc chain is my solution for a sample rate converter. The Volumen control actually happens inside the dsp. And that might be the reason why the Volumen control was not part of the original esp32 example Code. So I just removed the Digital Volumen control from your Code. But when I did this I found out, that still I had to Dividende the audio samples by 4. So my question is: How many bits are generate by the blue tooth (I thing those are 16bit samples) and why do I have to stift right the samples by 2 bits to avoid clipping? I want to avoid the division by 4 since I think it will reduce the Overall dynamics in the audio signal. Any hinter are welcome. Andrea

YetAnotherElectronicsChannel commented 3 years ago

Hi Andrea,

I found meanwhile the problem. The external audio-DAC is expecting a real I2S signal (which means that MSB starts in the second clock-cycle after WCLK is toggling). However the audio-driver in the ESP32 is configured for left-justified protocol (which is basically the same as I2S but the MSB of a new word starts in the first cycle after WCLK is toggling). For that reason, the sound is starting to sound crappy always when the amplitude of the audio goes over the +/- 2^14 range because. It doesn't seem to be a real problem until this point because all audio-DACs have some sort of low-frequency highpass filters integrated so that the DC-offset which is seen by the DAC is compensated. When I made this video I was not aware of that problem, so I just fixed it by shifting it to the right by some bits. But the real solution is to fix the audio-driver to drive a real I2S protocol. The SBC codec will output you a 16-Bit signed-integer data-stream. Clipping cannot occur in that configuration. I would recommend to you to use one of the higher-rated ADAU chips which have an integrated sample-rate converter and then interface directly via digital I2S to the DSP chip. BR

amweu commented 3 years ago

Hi, thank you for your quick reply. That is very helpful! I belive the I2S driver can be set to the data format you mentioned when it is initializing the i2s peripheral. I'll check that.

Your proposal to use a newer dsp is something I am already on. Actually I have already developed another board with esp32 and adau1452 dsp. But there is some bringup work to be done on it and meanwhile I will use the older hardware in some projects. The adau1701 is a very handy dsp and I use the learning module from China together with the DAC and ADC modules from China, so that my PCB has no SMD components on it. Changing from adau1701 to adau1452 impies a complete SMD board which I cannot manufacture myself. That's why I love the adau1701 still.. Thank you, Andrea