-
-
Notifications
You must be signed in to change notification settings - Fork 299
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
IOS poor quality audio #533
Comments
With my old IOS devices it is working w/o any problems. |
Is there a way to add AAC codec support? I think it may be due to ios not liking the SBC codex too much.
|
No, as far as I know, only SBC is supported by Espressif |
I found this by esperiff https://docs.espressif.com/projects/esp-adf/en/latest/api-reference/codecs/aac_decoder.html |
I don't understand, where is the connection with A2DP ? |
Oh okay, in your linked document AAC is mentioned in this uint8_t m24[ESP_A2D_CIE_LEN_M24] do you know what this means? |
But I did not find any method where you could provide this information.... |
I dont really understand the documentation or what you mean by that, i will try to search if theres a way to add AAC support but seems im out of luck with this one |
no updates? |
I never did manage to get the setup working, i think the esp32's and iphones bt codecs are just incompitable so that it struggles with the audio. Iphone prefers to use AAC codec while esp32 only supports SBC codec. |
I worked out that if the volume on the IPhone is all the way up and ignoring the background noise issue mentioned in a different issue then the sound is as good as you would expect, it’s only when the volume is part way that it sounds horrible, and I testing with a cheap android I have laying around and fount the same thing, is there any way of “blocking” the volume from changing when connected, like how on Mac when connected to a usb DAC the volume bar is greyed out and can’t be changed |
do you have an example for "very poor audio quality"? |
I’ll try recording it and come back here later with a link |
https://audio.com/bfulham/audio/esp32-test it came out different to how it sounded straight off the esp32 as the recording has more background noise even at the full volume and didnt distort as much when at part volume compared to earphones off the esp32 |
I have ordered an external dac and amp (Adafruit I2S 3W Class D Amplifier Breakout - MAX98357A) to test if this is still an issue without using the internal dac |
If this is with your internal DAC, my first guess would be a noisy power supply |
I did not but as I have ordered the DAC I am not going to worry about doing further testing, I also noticed an error on the readme for that test sketch and have submitted changes |
I can record the sound later with my 16bit dac i have for the project and connecting that to an aux speaker. I will also try with the esp32S3 instead of the basic, maybe it has some improvments made. |
Out of necessity, I installed Squeezelite on the ESP. I had no problem with the same DAC using an iPhone. Unfortunately, since I do not own an iPhone myself, I couldn't generate logs with A2DP. However, the issue with the DAC can be ruled out. |
I had some luck with the OP's issue, see here. Might be something else, but it worked for me. |
I am having same issue, I have the latest of iOS and macOS devices and some older ones. Old iOS: 12.5.7 All Apple versions do not work for me giving the same stuttering result. The audio is super choppy, it seems a buffering / flow rate problem on the a2dp side. |
Did you try
|
let me give that a try. I was trying changing this values, if event_queue_size gets smaller the sound becomes somewhat better, but even then not usable. |
Hmm, that does not make any sense: I would have expected the opposite. |
Cool thanks. Right now I need to eat - my nerves are itching and my patience fading :) I am pretty sure from all the trials and errors so far, it's just a data rate / buffer missmatch. Also when I make drastic value changes, the BT connection has problems remaining connected and drops out quit quickly. Your diagnostic tip will certainly give me more insights ! |
Hi, I built a MeasuringStream sketch and ran it back to back on iOS and Android. Here is the measure sketch:
Apple iOS 18.2 | Source AppleMusic: Android 14 | Source AppleMusic I played the same song from the same platform to be sure. On Android the sound is fine, on iOS choppy. |
Ah, no just do the following to measure the transmission speed:
Sending the output to i2s is throtteling it down to the output speed. If you would want to send it to both you would need to use a MultiOutput. With your logic you copy half of the data to I2S and the other half to the MeasuringStream. |
hence me sharing the sketch - I thought I missed something... started with your library about 4 days ago... |
Off tangent - so StreamCopy empties the buffer after each copy, hence the splitting of the data half here and half there ? |
Strange: I would have expected these values to be much bigger. |
When i had this issue, i tried all kinds of resolutions but nothing worked. My goal was to convert bluetooth audio to aux for my car and control the playback, so I ended up using a dedicated bluetooth audio conversion device that supports AAC and an ESP32 to control the playback through acting as a ble keyboard and using keyboard playback controls |
I am at sea level - hence the air density is highest here - maybe more resistive to push data packages through the air :) |
If the issue is really that the receiving speed is not fast enough you could try to play with the i2s sample rate (e.g. setting it to 44050) or by resampling with a small factor e.g. 1.05 to provide more samples. For this you would need to do the output via the callback, because in the standard functionality, the sample rate is updated from the source. |
Ok, yet both the Android and iOS bit rates look about the same, one works fine the other stutters. |
I think it is just the other way round. Set the log level to debug: this should show the i2s write size |
Here we go, Apple sends larger junks, most likely overflowing the buffer slightly ? Apple iOS 22:58:17.868 -> [D] I2SCodecStream.h : 125 - I2SStream::write: 4096 Android 2:57:06.853 -> [D] I2SCodecStream.h : 125 - I2SStream::write: 3584 |
Did you try to set the A2DP_I2S_MAX_WRITE_SIZE to different values. I added it to split up the write into smaller sizes. |
I am trying those things right now, but you know 2-3min of compile and upload with each change... I think I2S_BUFFER_SIZE 1024 should be in the same ballpark as A2DP_I2S_MAX_WRITE_SIZE ? |
No, that should be independent: I think the total i2s buffer size is I2S_BUFFER_SIZE * I2S_BUFFER_COUNT |
What if the problem is actually not in the handling of the data, but the BT implementation in Esspressive has a buffer limit ? |
If that would be the case, there is nothing we could do about this here. But lets double check if adjusting the output sample rate makes a difference. In BluetoothA2DPOutput.cpp goto set_sample_rate() and try something like this
And try to play around with this factor. |
To test your assumption you could write the data to a file |
I tried your suggestion of info.sample_rate = m_sample_rate * 0.98;, but it does not make an audible difference - It stills sounds like a bad techno dance party, stuck inside a washing machine... |
What happens if you decrease this value ? |
That is what is happening just right now * 0.5 ;) |
It's a bit like somebody tries to make music using morse code... much worse on this low setting. |
I even snuck a typo into the code, just to make sure it is the actual file that I am modifying that is being compiled... And the compiler threw an error - hence the chances correct but ineffective. |
That would speak for your theory. Another thing you could try is to double check if Arduino ESP32 2.0.17 or 3.10 RC3 are having the same issue |
I am downgrading the ESP Libraries... but its slow as snails... |
Another thought: does it make a difference if you call a2dp_sink.set_avrc_metadata_attribute_mask(0); before begin ? |
It's still downloading the Espressif board definitions, I think their server has a. buffer problem too... it's now like 30min downloading. Its now our internet line, I am above 120Mbs download speed... I will try above when I am ready to compile again. I still like where you where going with the SD card, writing the data back into an audio file to see if its complete ? I am also following some breadcrumbs into the A2DP implementation, it seems there is a ring buffer at the core, but I could not figure out the size definitions yet. |
the a2dp_sink.set_avrc_metadata_attribute_mask(0); did not change anything. I think you thought if no meta data is requested it would lower the data rate ? |
Just wanted to make sure that the metadata was not the cause for this issue! |
Would not surprise me, if DRM has something do with it. Apple might 'scramble' the data on purpose... Some Bluetooth stacks enforce the SCMS-T digital rights management (DRM) scheme. In these cases, it is impossible to connect certain A2DP headphones for high quality audio |
Here is another insight, this time taken on macOS when connected to the a2dp device. I assume the ReTX value is re-transmit after failed AK or other Error... bluetoothd A2DP LinkQualityReport: Handle = 19 ReTx = 70.4% (133 / 189), NAK = 0, NoSync = 133, TxPwr = 11 dBm, RSSI = -48, {50,75,90}th Noise = { -97, -96, -96} for 20 ch, 2EDR pkts = 0, 3EDRTx pkts = 0, HDR4Tx pkts = 0, HDR8Tx pkts = 0, 1SlotTx pkts = 0, 3SlotTx pkts = 0, 5SlotTx pkts = 0, CoexDenial = 0, CoexRequest = 0, 3EDRRx pkts = 0, HDR4Rx pkts = 0, HDR8Rx pkts = 0, 1SlotRx pkts = 0, 3SlotRx pkts = 0, 5SlotRx pkts = 0, TxFlush pkts = 0, Tx2Flush pkts = 0, rate = 327 kbps Flow off = 0 devicename = |
And I can confirm the iOS/macOS is selecting the 'correct' codec - not defaulting to AAC as somewhere suggested. 14:22:16.572299+0300 bluetoothd A2DP configured at 44.1 KHz. Codec: SBC, Bitpool: 53 (327 kbps). 8 frames * 119 bytes = 952 per RTP (max=988) every 23.22 ms |
Problem Description
No matter how i play with the settings, it seems i only get very poor audio quality when i stream audio from IOS device through A2DP, with android it works flawlessly. Is there a solution for this? I checked all realted issues and searched online but did not find a solutrion myself
Device Description
ESP32-WROOM and Iphone 12
External DAC PCM5102A
Sketch
Other Steps to Reproduce
No response
Provide your Version of the EP32 Arduino Core (or the IDF Version)
2.3.2
I have checked existing issues, discussions and online documentation
The text was updated successfully, but these errors were encountered: