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
Dropped A2DP Packets when sending stream to I2S interface for SPDIF (BT_APPL: Pkt dropped) (IDFGH-6738) #8368
Comments
If I send slightly less data than the callback delivers, the drops are gone. EDIT, just to be clear: The audio is then useless of course. I recently added using tasks running on different cores so the bt core has less to do. But that did not help either. 2x16bit 44.1kHz A2DP to 88.2kHz I2S for SPDIF out seems to be impossible to do (for me). |
@joba-1 I played music without any pkt dropping with your code and config. Any suggestions? Thanks! |
@joba-1 And I did not understand how your 'rate control' works... |
Hi, thanks for looking into this. There is no rate control in my code. Do you have a suggestion how to tell the remote bt device to slow down or repeat sending a packet that had to be dropped? |
|
Ah, I see now what you mean. I wasn't aware of this code. This rate limit code does the following:
It assumes, the rate bt sends data and i2s consumes data is out of sync for not more than one sample per callback. Looks promising, thanks for the hint. |
I can only assume that your bt sender is a tiny bit slower than mine or my esp is running a bit slower than yours |
Update: The pattern always looks very similar. The buffer stays rather empty, going from 0-3% up to 11% used, and then suddenly a packet is dropped - I guess because the callback task filling the buffer is not called for too long.
|
dropped even more frames to a maximum of 100 out of 2560 bytes, then drops are gone. |
@joba-1 "Pkt dropped" happens when sink_rx_queue is about full. The root cause is that the Bluetooth Stack is busy to handle Now some information for your reference. The task priority of A possible case is that, your I2S is always busy, Lower down the priority of I2S task to 18, and try again. Turn to us anytime. |
thanks for the update. Will try the prio change. |
@joba-1 Sometimes, there are misunderstandings about the use of |
I can use any guidance, thanks for that. Currently I (or better: amedes) do it like in the original espressif a2dp to i2s example: the cb puts data into a circular buffer and another task fetches it from there. My main problem seems to be not priority, but that a2dp bit rate (which is controlled solely by the external bt device) and the spdif i2s bit rate need to be precisely synchronous but are not. Is it possible to reduce the packet size I get from the bt cb? Else I try to split it up in an intermediate level. |
I tried increasing (and decreasing) the task prios. Did not help. Thanks for your support, your hint on the rate limiting code did it! |
Environment
git describe --tags
to find it): v5.0-dev-1509-g5893797bf0xtensa-esp32-elf-gcc --version
to find it): xtensa-esp32-elf-gcc (crosstool-NG esp-2021r2) 8.4.0Problem Description
Scenario: using I2S to send a bluetooth A2DP stream (clean sine wave) as SPDIF to pin 27
Problem: The stream works for ~1,5 minutes, then starts to have a glitch every ~4-5s.
The problem is not the added SPDIF encoding, the data coming from the esp callback is already wrong.
Expected Behavior
The sine wave sent (or any other sound) gets transferred without continuity problems without time limit.
Actual Behavior
The sine wave is perfect for ~1,5 minutes, then there are short intervals of ~30 samples not matching the sine wave.
After that the sine wave is good for ~4-5s, but not necessarily in phase to before the glitch.
Then the problem repeats until reset of the chip.
Steps to reproduce
// If possible, attach a picture of your setup/wiring here.
Code to reproduce this issue
Full project (not mine): https://github.com/amedes/esp_a2dp_sink_spdif
The whole code is basically the esp_a2dp_sink example with added encoding of the spdif format and other I2S config for the increased bit frequency (to cover the SPDIF overhead).
This is the function that initializes the I2S interface:
Debug Logs
Other items if possible
sdkconfig file (attach the sdkconfig file from your project folder)
sdkconfig.txt
elf file in the
build
folder (note this may contain all the code details and symbols of your project.)esp_a2dp_sink_spdif.zip
coredump (This provides stacks of tasks.)
none
The text was updated successfully, but these errors were encountered: