-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crackling/Distortion after a few seconds of playback #55
Comments
Is there anything supicious in your logs? Maybe related to DSP/Software volume? Could you test without? Also could you try using standard sdkconfig and do settings for psram, board etc. yourself. Maybe sdkconfig_PSRAM_lyrat_v4.3 is faulty for some reason. If that doesn't help maybe go back in time, you could start by trying commit 06161ae |
I redid the Unfortunately the logs are pretty empty and do not indicate any issues.
Also the issue still persists when disabling the DSP functionality - except now there is also some distortion from the poor speaker struggling with the volume ;) I then cherry-picked the commit The crackling is gone for a few seconds everytime i switch snapcast sources or pause the playback on the source. Are there some debug logs regarding the i2s/playback buffer stats that i could activate? See if there are some buffers that run dry. |
You could enable logs around here https://github.com/CarlosDerSeher/snapclient/blob/master/components%2Flightsnapcast%2Fplayer.c#L1510 but I don't think it will help here. Still, please try. Because of the loud volume could you just lower the volume on your input source to the server to ensure it isn't a dsp issue. I guess you are unable to hear the crackling with soft volume disabled because of the speaker distortion? Also did you ensure it isn't a server issue? Do other architecture clients have this issue too (probably not)? Another thing you could try is to disable apll tuning temporarily. The DAC doesn't have a MCLK line does it? I am not sure how this affects operation. I don't think it should be a problem as the others signal timings also change with MCLK timing but who knows. I don't have this particular DAC so maybe someone else can report if he has similar issues, you could check if the DAC is correctly initialized by the driver. Maybe something is wrong there? |
Other clients on my network play fine. I have a few around the house (Raspberry Pi 4B, Raspberry Pi 5, Snapweb). Even without DSP and softvolume i can still hear the crackling over the slight distortion of the overdriven speaker. Reducing volume on the source side was a good idea. Just had to enable volume on the mopidy instance again. I enabled the log in L1510 as mentioned. I get the feeling that the distortion is tied to the APLL direction switching. When it gets to the point where it oscillates the distortion becomes the strongest.
With the APLL disabled it sounds a lot better - i am unsure if all artifacts are gone and its just the DAC and cheap speaker that is still not sounding great. I will see if i can set up a simple playback from file to check that.
Edit: I think there is still some distortion but i will try to get a comparison running. |
I am using pcm5102a dac without MCLK (it is optional for this dac) and don't have any distortion/crackling issues. |
Try playing a sine wave and maybe record it somehow. Using a oscilloscope maybe. There isn't a line out on this dac I guess so you could record it using a pc soundcard? |
Ahhh and I see another possible problem on your setup. The wifi antenna is very close to your audio board. This could also be to source of your troubles. Try to get as much space between the antenna and audio! |
I put the DAC on a second breadboard. Unfortunately this did not improve anything.
The DAC does not need any runtime configuration. It should just play any I2S data sent to it.
Unfortunately this DAC does not have a line level output. I added a voltage divider to ground on both speaker leads (with the speaker still connected) and fed that into the line in of a usb soundcard. One file is from a direct loop on the soundcard playing the same file and the other one from the esp32 playing the file. It is a 440Hz sine wave. |
Honestly I am not sure where this is coming from. To me it kind of looks like noise from the power supply. Could yo try to use a different supply for the DAC. At the moment you are using to power supply from the ESP module don't you? How do you supply everything at the moment, 5V from USB or through 3.3V regulator on the board? |
Here is the same file played on a raspberrypi connected to the DAC: esp32-snapcast-workbench_via_raspberry.zip Maybe my way of recording is not perfect. Still the sound does seem a little better coming from the raspberry pi - but also farm from really good. I will try to wire up a separate power supply for the DAC to avoid getting interference from the usb lines or ESP32 cpu noise. |
So then i will put this aside as problem of the DAC for now. I was hoping to use this simple DAC for testing and switch to something more useful once i am happy with the basic playback and behaviour of the software. Something like the HiFiBerry AMP2 (TAS5713) or IQaudio DigiAMP+ (TAS5756M). I am already using the IQaudio DigiAmp+ on one of my raspberry pi snapcast clients and it sounds great. So the only 'real' problem with the crackling was probably the APLL correction. Could this also be something the DAC does not like? If so, I could try switching to the IQaudio amplifier and adding it as a custom board (I may have one lying around somewhere). |
@BenediktMueller91 USB is really noisy and I can confirm with other dacs that the sound quality is not the best if the power supply is noisy. |
I read something about jitter correction in the datasheet but I doubt this is the problem. I don't think that apll correction is the problem. Did you try to change the power supply of the DAC? Also @normanalie could be of help here maybe, he did add the codec and maybe has some input here. |
I added a separate lab power supply for the DAC and now the quality is overall quite good. ESP32 and DAC share only ground and the i2s lines now. It looks like even when feeding the ESP32 with a really good power supply via the USB plug the power rail became quite noisy. Edit: All this with the apll correction still disabled! With the apll correction enabled it still sounds and looks terrible: |
I've never encountered this problem with this DAC. |
The Adafruit Max98357A Board already includes the resistor for the L+R operation mode when supplying 5V (see https://learn.adafruit.com/assets/32642).
Unfortunately i don't have any kind of logic analyzer at the moment. I have ordered a cheap amazon usb logic analyzer (https://www.amazon.de/dp/B01MUFRHQ2) and will have a look at the i2s lines once it arrives and i can find some time. |
On the schematic, R1 is 1mOhm, thats too much for 3.3V logic. Based on the data sheet, SD_MODE pull-up resistor should be 632ohms on 3.3V I/O. I don't think this will solve your problem but it will eliminate a potential problem and your electronic design will follow the recommendations. https://www.analog.com/media/en/technical-documentation/data-sheets/max98357a-max98357b.pdf |
Are you sure it is 1m? To me it looks more like 1M Did you ever try a different speaker? Maybe your speaker's impedance isn't supported by the DAC? |
I switched to a Visaton SC 5.9 (10W, 8 Ohms). The same issues persist. But it still sounds a lot better with the bigger speaker. The spectrograms i posted where already recored from this speaker.
In Table 5 The pictured board is currently the only ESP32 available to me so I also ordered another ESP32-WROVER based board to make sure it is not something about this specific board. I will report back once the logic analyzer is running and i tested the new board. |
tl;dr: When apll correction is active, i still have crackling but in a way that sounds more like short interruptions/pops. On the i2s lines the data looks fine in both cases. Ok, so the logic analyzer did not make it any better 😕. And with the ESP32-WROVER CAM Board the issues are the same. Now only the DAC and the software are left as culprits imho. In Sigrok/PulseView i recorded 50 MSamples at 6Mhz and added an i2s decoder. With a simple python script i transformed the exported i2s text data files into binary data files and imported them into audacity. In both cases when selecting 2-channel 16 bit signed pcm on the raw importer in audacity, a good looking/sounding sine wave was the result. As far as i can tell the BCLK as well as LRCLK and DATA look fine and have no relevant timing inconsistencies. Maybe one of you can spot something in the recorded data? And thats the script i used to convert the data exported from PulseView:
|
@BenediktMueller91 BCK width jitters a little for both apll/no_apll but I guess thats because of sample rate of logic analyzer not beeing high enough. Also I get an error using yourt conversion script:
|
The script does not work on the *.sr files but the decoded/exported i2s data. You get the file when right-clicking on the i2s track and export that row. The file should look like this:
|
I figured that out later, but still the same error
esp32-i2s-playback_sine_stereo_apll.txt:
|
Oh, maybe the encoding is something different on your system by default. Probably the file will be ISO-8859-1 instead of UTF-8. Try wether it works when explicitly specifying the encoding like this: filename_out = filename_in + ".raw"
-infile = open(filename_in, "r")
+infile = open(filename_in, "r", encoding="ISO-8859-1")
outfile = open(filename_out, "wb") |
Ok now I am getting somewhere. audio sample rate is 48kHz and it is big endian format isn't it? |
So you recorded the I2S signals coming from ESP32 and we get a clean audio if we listen to it on a PC. At least it sounds / looks clean to me on my PC. This leaves your DAC as the problem I guess? Question is what is different for your hardware as it seems to work for others with this DAC type... |
Can you see the APLL direction switch with the logic analyzer? maybe there is a glitch on the line when this is happening? Not sure how we could visualize that as we cant really trigger on the direction switch. maybe toggle a gpio when it is happening and use a scope to trigger on that signal? |
And you talked about the raspberry behaving similar with this DAC connected? If that is the case then your DAC is the problem |
And here is yet another possible problem I found: In line https://github.com/CarlosDerSeher/snapclient/blob/d3e20fe0eb4d8d562d97a02f43cbccb79e9c8505/main/main.c#L2777C13-L2777C13 I activate the I2S interface before I initialize the DAC. I did that for ADAU1961 DAC but it seems yours needs a different startup sequence. Maybe just comment the I2S initialization in main for a quick test? |
@BenediktMueller91 ... Try also soldering the dac to the esp32 loose connection can cause also issues. I don't know the bandwidth but higher clock frequencies like 5mhz need short cables. Before looking that deep into software be sure that your hardware is connected properly. |
It has to somehow be connected to software. I tried to change as little as possibel between the tests (same snapcast server, same stream, same/similar volume):
Note: I added a short log with the
🙁 Did not work:
dir = -1;
+ gpio_set_level(GPIO_NUM_4, 0);
} else if ((shortMedian > shortOffset) && (miniMedian > miniOffset) &&
(avg > miniOffset)) { // we are late
dir = 1;
+ gpio_set_level(GPIO_NUM_4, 1);
} Will continue investigating - Thanks for your help so far! 😄 |
There is a gpio_configure function you'll need to call first for the hpio to work. And it still could be hardware related. Maybe this particular dac doesn't like the apll/clock jitter we are introducing on purpose. It's still strange that others won't report this behavior |
@BenediktMueller91 Where I've implemented a different syncing approach. It's still experimental, maybe you are willing to test. |
@CarlosDerSeher - const int64_t shortOffset = 2; // µs, softsync
- const int64_t miniOffset = 1; // µs, softsync
+ const int64_t shortOffset = 128; // µs, softsync
+ const int64_t miniOffset = 64; // µs, softsync Thanks again for all your work and help :) |
Awesome :) |
Signed-off-by: Karl Osterseher <[email protected]>
With current
master
on my setup there is crackling/distortion building up after a few seconds. The audio then stays in a listenable but distorted state after that. This is best discernable in speech.Current Setup:
snapserver v0.27.0
on archlinuxsdkconfig_PSRAM_lyrat_v4.3
plus DSP and MAX98357 (diff)The text was updated successfully, but these errors were encountered: