-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
I2S APLL Clock is inaccurate at 44100Hz 16-bit 2ch (IDFGH-1058) #3380
Comments
If apll parameters are then fout = 40000000 * (4 + 5 + 8/256 + 28/65536)) = 361267089.84375 If clkm_num = 8, a = 0, b = 1 If bck_div_num = 256 / (16 * 2) = 8 and sample rate = 1411199.5697021484375 / (16 * 2) = 44099.986553192138671875 so yeah the driver is not doing a good job calculating apll parameters. Unless you have a rev0 chip which can't do fractional apll factors. If apll parameters are then sample rate = 44099.998602648629653807277628032 Another: SUGGESTION: optimized parameter values for common sample rates should be determined externally and hardcoded |
Now my workaround is:
It did help, there is no
The hardcoded parameter values are from previous 63ddae5 removed
@negativekelvin Thanks for your reply! I tried to use these values you calculated, but it seems that they won't work unless the i2s_set_clk() function were modified. |
Have you experienced glitches in the output like I have been experiencing? #3407 I've been seeing zeroes in the SD output which is audible as clicking and cracking |
Same issue here, still not resolved: #2634 |
Try the attached patch. It has solved the inaccurate apll clock rate issue. The patch is w.r.t. latest IDF i.e. 4.0. Kindly help to share the result. |
Just a couple of changes to the original calculation are needed as I already provided in #2634 If I have any spare time away from work I'll clone modify and submit a pull request if possible. There is no need for major changes my patch will get you as close as the PLL can do, which is usually 10-20ppm or something. (+/- the source clock ppm obviously) I have measured hundreds of arbitrary clock rates on MCLK with a high resolution frequency counter and have been using this in Audio projects for over a year now. There is nothing wrong with the APLL it's a good PLL, this original code was erroneous in that it would overshoot the more significant sdm parameters because it would choose the value closer to the target even if it was slightly higher than the target value, forever setting the accuracy at the resolution of that coarser parameter. Choosing the closest value should only be done on the least significant parameter. I also have a cheap way to measure the input frequency if you're running I2S in slave mode if anyone's interested. |
The attached patch give is percentage difference of 0.001. |
Yeah no the APLL can do better than that with this fix:
MCLK is off by 4 parts in 24.576 Million So I guess I was wrong it's usually off less than 10 parts per million. I'll say it again: It's a good proper Audio PLL, and it is much better than esspresif is apparently OK with. The patch is simple, it was just a brain fart by the original developer, what is disappointing is that it STILL HASN'T BEEN FIXED. |
Also still got that MP3 encoder if anyone's interested. Otherwise I have work to do. |
@ajita02 @fknrdcls Hi, I made a comparison between these two patches. From the results, they are all very accurate. So it's time to submit them.
@fknrdcls 's patch:
The unmodified version:
|
Hi, How can I apply this patch file on Windows? Thanks |
This seems to have been fixed ages ago in ESP-IDF: espressif/esp-idf#3648 espressif/esp-idf#3380
Environment
Problem Description
When the i2s APLL clock is set to 44100Hz 16-bit 2ch, the real rate is 43945.238, which is inaccurate and causes
BT_APPL: Pkt dropped
problem when using A2DP streaming.Expected Behavior
Real rate should be 44099.xxx or 44100.xxx
Actual Behavior
Real rate is 43945.238(~155Hz Error)
Steps to repropduce
a2dp_sink
example from esp-idf v3.2..use_apll = 1,
toi2s_config
to enable APLL.Code to reproduce this issue
The
a2dp_sink
example from esp-idf v3.2Debug Logs
The text was updated successfully, but these errors were encountered: