schreibfaul1 / ESP32-audioI2S

Play mp3 files from SD via I2S
GNU General Public License v3.0
1.12k stars 288 forks source link

Distorted signal, sound distortion #563

Closed bhpjean closed 9 months ago

bhpjean commented 1 year ago

Why do I hear large distortions on loud sounds in the new library? what has been broken? using the older version is ok. There is an effect like it would be too loud. I am using PCM5102A

When I compile the program using the older i2s Audio library, the sound quality is very good.

schreibfaul1 commented 1 year ago

A sinus tone 1KHz, 100% modulation at maximum volume: Audacity image

Oscilloscope at the output of the PCM5102: image Testton_1.0.mp3.zip

bhpjean commented 1 year ago

I did the signal measurements, for me the results came out like this. The first oscillogram is for the old library from Dec 31.2021 dso_01_01_00_32_04

the second oscillogram is for the latest library available on github dso_01_01_00_22_20

I didn't change anything in my internet radio program, I only replaced the ESP32-audioI2S library and recompiled the program. In my opinion, the volume in the new library is greatly exaggerated, which in the case of Internet stations can be manifested by large distortions at maximum volume. As you can see, at the standard level at which you generated the mp3 file, the sine wave is ok. However, the stations do not always control the volume level correctly. and a few stations have distorted volume.

schreibfaul1 commented 1 year ago

Now I see what you mean. Digital filters are used, which not only attenuate the signal but can also amplify it. In the old version, the level was lower so that any amplification of the filters would not lead to distortion. With the new version, the overall level is lowered by the gain of the filters. Example: if the high pass is boosted by 6dB, the volume is lowered by 6dB beforehand. This ensures that the range from INT16_MIN ... INT16_MAX is not exceeded at 100% amplitude deviation. I suspect that the output signal is now larger in amplitude (at the output of the DAC) than the connected amplifier can handle.

bhpjean commented 1 year ago

No, it's not the amplifier's fault that it can't handle it. The amplifier has a volume control on the input. The problem is on the DAC side. he's not making it. I think the previous method was better, but that's just my opinion. In analog equipment, the bass and treble control does not work so that the overall volume is lowered and the timbre of the sound is boosted (boosted or lowered). in good audio equipment they do not use such methods because the sound is somewhat compressed and the signal level fluctuates. In my opinion, this is a bad method that degrades the sound. But you are the developer of the software and you decide it. Anyway, thank you for the great software and the time you spend creating it. I'll stay with the old method. For me it is better and the sound is much nicer, although it plays a bit quieter. It resembles and refers to the analog sound.

My internet tuners, which were created thanks to your software. Aren't they pretty? Thank you radmory

Arielhh commented 1 year ago

I agree there is distortion in the sound in the new version 3.0. Is there a way to "play" with the sound amplitude or other filters?

schreibfaul1 commented 1 year ago

The old version ran at 15 bits/sample (50% level) because the digital filters can also amplify and there shouldn't be any overflow. The problem has now been solved and 16 bits/sample are the standard. The DAC should be able to do that, maybe there is a problem with the operating voltage

BoloKonstruktor commented 1 year ago

Exactly, the normalized 16 bit signal is reproduced correctly without distortion. If, however, the audio stream has an abnormal level and in addition the filters are set to gain, the value of the coefficient 'm_corr' may not be sufficient to lower the level sufficiently to avoid distortion.

Arielhh commented 1 year ago

Exactly, the normalized 16 bit signal is reproduced correctly without distortion. If, however, the audio stream has an abnormal level and in addition the filters are set to gain, the value of the coefficient 'm_corr' may not be sufficient to lower the level sufficiently to avoid distortion.

Thanks :)

Arielhh commented 1 year ago

Exactly, the normalized 16 bit signal is reproduced correctly without distortion. If, however, the audio stream has an abnormal level and in addition the filters are set to gain, the value of the coefficient 'm_corr' may not be sufficient to lower the level sufficiently to avoid distortion.

The old version ran at 15 bits/sample (50% level) because the digital filters can also amplify and there shouldn't be any overflow. The problem has now been solved and 16 bits/sample are the standard. The DAC should be able to do that, maybe there is a problem with the operating voltage

Thanks, there is no issue with the operating voltage. I tried better DAC chips but still the sound has some kind of distortion (not completely clear, which is a bit annoying).

Arielhh commented 1 year ago

Exactly, the normalized 16 bit signal is reproduced correctly without distortion. If, however, the audio stream has an abnormal level and in addition the filters are set to gain, the value of the coefficient 'm_corr' may not be sufficient to lower the level sufficiently to avoid distortion.

The old version ran at 15 bits/sample (50% level) because the digital filters can also amplify and there shouldn't be any overflow. The problem has now been solved and 16 bits/sample are the standard. The DAC should be able to do that, maybe there is a problem with the operating voltage

Thanks, there is no issue with the operating voltage. I tried better DAC chips but still the sound has some kind of distortion (not completely clear, which is a bit annoying).

The old version ran at 15 bits/sample (50% level) because the digital filters can also amplify and there shouldn't be any overflow. The problem has now been solved and 16 bits/sample are the standard. The DAC should be able to do that, maybe there is a problem with the operating voltage

I played with the setTone() function and managed to improve the sound to a minimum distortion level. Thanks again.

renatoianhez commented 1 year ago

Hi! What tone combination did you find ideal? I have been using audio.setTone(4, 0, 4); and I notice that some stations with higher volume give distortion in the lower tones. Examples: https://italianradio.streamingmedia.it/play https://27343.live.streamtheworld.com/RADIO_ALVORADAAAC.aac

Arielhh commented 1 year ago

Hi! What tone combination did you find ideal? I have been using audio.setTone(4, 0, 4); and I notice that some stations with higher volume give distortion in the lower tones. Examples: https://italianradio.streamingmedia.it/play https://27343.live.streamtheworld.com/RADIO_ALVORADAAAC.aac

I used audio.setTone(0, 6, 4); for a small 4cm speaker but after further thinking I replaced the DAC with PCM5102 and the sound is great now. If you are using the MAX chip consider replacing it as the DAC in this chip is not of good quality.

renatoianhez commented 1 year ago

I'll test this 0,6,4... I use PCM5102 exactly, with a PAM8403 amp, 2'' speakers, stereo. This is my radio.

renatoianhez commented 1 year ago

I'll test this 0,6,4... I use PCM5102 exactly, with a PAM8403 amp, 2'' speakers, stereo. This is my radio.

Its combination greatly reduced the noise!

Arielhh commented 1 year ago

With the PCM DAC you should not have a problem. I guess that the issue you experience will not be fixed by playing with the tone values. In my opinion you should look somewhere else. See that project https://github.com/Arielhh/ESP32-Radio-Internet

On Fri, Sep 29, 2023 at 02:06 renatoianhez @.***> wrote:

I'll test this 0,6,4... I use PCM5102 exactly, with a PAM8403 amp, 2'' speakers, stereo. This is my radio https://github.com/renatoianhez/Lolin32-radio.

Its combination greatly reduced the noise!

— Reply to this email directly, view it on GitHub https://github.com/schreibfaul1/ESP32-audioI2S/issues/563#issuecomment-1740142838, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABE77IAK7JTQQ5P6XRI4ZPTX4YGJJANCNFSM6AAAAAA2DPBPPA . You are receiving this because you commented.Message ID: @.***>

renatoianhez commented 1 year ago

With the PCM DAC you should not have a problem. I guess that the issue you experience will not be fixed by playing with the tone values. In my opinion you should look somewhere else. See that project https://github.com/Arielhh/ESP32-Radio-Internet On Fri, Sep 29, 2023 at 02:06 renatoianhez @.> wrote: I'll test this 0,6,4... I use PCM5102 exactly, with a PAM8403 amp, 2'' speakers, stereo. This is my radio https://github.com/renatoianhez/Lolin32-radio. Its combination greatly reduced the noise! — Reply to this email directly, view it on GitHub <#563 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABE77IAK7JTQQ5P6XRI4ZPTX4YGJJANCNFSM6AAAAAA2DPBPPA . You are receiving this because you commented.Message ID: @.>

I noticed that the SPI mode option was in DIO, and not QIO as I usually do. Is there any influence? image

github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 9 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.