-
Notifications
You must be signed in to change notification settings - Fork 189
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
SCO record quality is not great #510
Comments
Please check whether you will have the same results with bluez-alsa 3.1.0. If the result is the same, than you might try to record low level Bluetooth communication e.g.: Does you headset support mSBC? It might be easier with mSBC because there are control bits in the stream, so it will be possible to tell right away whether there are some missing packets. |
One possible cause of this effect is dropped samples. Are you using an RPi with on-board BT adapter by any chance? That is notorious for dropping incoming SCO samples, especially when 2.4GHz Wifi is in use at the same time, |
@arkq, I've attached test-01.zip containing:
Next, I will try going back to 3.1.0 (b09f373). @borine the device is a custom SOM with an onboard wl18xx Ti chip. Not currently using the WiFi capabilities of the chip. |
@hrc-amilcar as for hcidump I thought about all data, not audio only ( EDIT: So the hcidump sounds OK, but the audio recorded with arecord is not OK.... hmmm. We will have to go dipper with that. |
You might also try to record audio data without involving ALSA library (one less element which might cause issues). Please use |
I updated to 3.1.0 (b09f373) and the arecord WAV now sounds identical to the hcidump RAW. i.e. good quality. It would be nice to use the latest since I'm interfacing with DBus in my app. But I can go back to PCMAdded/PCMRemoved and stick to 3.1.0 if necessary. Let me know if you need any other captures! Thank you. EDIT: Will try |
OK. It might be a long way to run, but could you try to pinpoint with |
Will try to bisect. It's only log2(75) tries. :) Also, I believe this affects playback as well. I was getting underruns from my app but not from aplay. The underruns went away with 3.1.0. |
I was afraid that this commit might cause troubles... I'll try to figure out how to fix that. Many thanks for bisect. |
@hrc-amilcar if you have time, please could you try my branch here: https://github.com/borine/bluez-alsa/tree/sco-mtu-bus-check This is actually a work-in-progress implementing changes discussed in #400, but I think that the change in CVSD mtu handlng for UART adapters may also possibly help with the issue reported here. |
@borine, I tried your branch. It sounds good again for both capture (no speed-up) and playback (no underruns). The MTU is now 180 instead of 48, as reported by |
Actually, it is the local adapter which matters when choosing the SCO socket read and write sizes. My patch distinguishes USB adapters (for which the Linux driver, |
Makes sense. It's interesting that the current single-threaded SCO implementation for both Read/Write allows the audio to flow correctly with a small size MTU of 48. I would have thought there would be missed packets regardless. Or that the two thread implementation would be able to feed 48-byte packets more quickly than single-threaded. But maybe there's some inherent delay in the latter implementation for which 180 byte packets hides the issue? |
The critical change in commit 1f82111 that introduced the capture issue is the size of the read buffer in BlueALSA. The read() calls actually ignore the MTU and read all available data into the buffer, limited by the size of the buffer. Before commit 1f82111 the buffer was 128 bytes, but was reduced to MTU size (48 bytes) by that commit. So a simple fix for capture would be to increase the read buffer size - I would suggest 180 bytes or even 256. I admit I cannot immediately explain the change in playback behaviour, nor why my patch would fix it. |
I tried with a read buffer of 256 in |
For reading from a socket the MTU is irrelevant - the read() call just returns whatever data is available at that time, or blocks if no data is available. For write() MTU is important - and for SCO sockets exceeding it can cause failure - certainly for USB, not sure about UART. |
Yes, it seems that this "enhancement" in fact has broken something... However, right now I'm not sure why I have used only a single MTU for read buffer. Maybe unification with write thread, or maybe I've got some issue with other (bigger) value (I do remember that I've got some troubles with CVSD thread separation). Anyway, I think that this read buffer indeed can be bigger than MTU, especially in case when the MTU value is not guaranteed to be correct. |
Yes, and that is precisely the point of my branch referenced above. I am trying to identify where the MTU reported by the socket is correct, and where it is (dangerously) wrong. But as I said, that is most definitely a work in progress. I have a lot more research to do and do not expect to have it ready for at least another year. However, it already seems clear that it is the |
Yes, I think that it will be worth merging into the master. However, I've got a question. Merging your MTU fix will require kernel with patch applied (I'm not up to date what is the final kernel patch and how it maintains backward compatibility)? |
Read less data than the SCO MTU might cause issues with prompt SCO buffer flushing, which in turn might cause audio issues. Fixes #510
@hrc-amilcar could you please check how #511 will work for you? |
Reading less data than the SCO MTU might cause issues with prompt SCO buffer flushing, which in turn might cause audio issues. Fixes #510
@arkq PR #512 includes only the USB adapter check from my SCO work. It does not include any mSBC changes, so is independent of any kernel changes - I do not expect any backwards compatibility issues with this. @hrc-amilcar - I believe my PR #512 is a direct fix for the issue you report here - both capture and playback - could I impose upon you to test this one also please ?. I think #511 and #512 are compatible with each other and are possibly both worth considering for merging |
@arkq, @borine Both #511 and #512 correct the issue independently. Looking forward to the merges. #511: I see the |
Yes, that might happen, but in such a case it will be a fatal error later (there is a check in https://github.com/Arkq/bluez-alsa/blob/master/src/ba-transport.c#L282). |
Hello,
I'm testing recording from two BT headsets. Zebra HS3100 and Plantronics Voyager Legend.
Playback quality is great, but recording is quiet, crackling, and slightly sped up.
I'm using the latest master (24b7300) with and without --enable-debug. Launched as:
/usr/bin/bluealsa --syslog -p a2dp-sink -p a2dp-source -p hfp-hf -p hfp-ag -p hsp-hs -p hsp-ag
Any hints would be a appreciated to improve record quality.
If it helps, here are the logs from arecord:
And here are the logs from BlueAlsa daemon:
The text was updated successfully, but these errors were encountered: