bluetooth audio fix on Q

426 views
Skip to first unread message

Francescodario Cuzzocrea

unread,
Apr 20, 2020, 3:52:03 PM4/20/20
to Android-x86
Hi ! 

this evening I got bluetooth audio working on my bay trail tablet, that is the fix : https://gitlab.com/lineageos-x86/android_hardware_libaudio/-/commit/dcb86b91f54c8d34cf9f84a7094a4c0f3fdc1311

In substance, I added missing routes to primary_audio_policy_configuration.xml copying the one in audio_policy.conf, and created a local copy of audio_policy_configuration.xml which includes policies for both usb and a2dp audio. 
Now audio over bluetooth heades works fine here (tested with xiaomi mi airdots).

Still I have an audio routing problem left, but I do not think is related to audio policy. My bay trail tablet got an bytcrrt5640 audio card. Audio from the speaker works, but when I insert headphones jack I hear sound from both speaker and headphones, so it seems like alsa does not shut down pc speaker leaving only headphones route on. Could anyone help me with that ?

As a side note, with kernel 5.6 it seems that this hax is needed to correctly register RTL8723BS bt chipset https://gitlab.com/lineageos-x86/android_device_generic_common/-/commit/bb2e0658511ec44124cd92f406025ee5e1639b55

As post scriptum, it seems also that this https://gitlab.com/lineageos-x86/android_device_generic_common/-/commit/f8d5691602700d86fc02ae41ce2416b8bf01db35 fixes mp4 playing on stock gallery

youling 257

unread,
Apr 20, 2020, 4:35:32 PM4/20/20
to Android-x86

Francescodario Cuzzocrea

unread,
Apr 20, 2020, 6:16:19 PM4/20/20
to andro...@googlegroups.com
unfortunately it did not worked, audio still come up from both speaker and headphones

Il giorno lun 20 apr 2020 alle ore 22:35 youling 257 <youli...@gmail.com> ha scritto:
--
You received this message because you are subscribed to the Google Groups "Android-x86" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-x86...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-x86/824544e1-6af5-4c82-85f6-492c168994c4%40googlegroups.com.

youling 257

unread,
Apr 21, 2020, 12:49:25 AM4/21/20
to Android-x86
remove Androidx86 audio.primary.x86 alsa-lib and alsa-utils.
if you interest with Minecrell how to make his Bay-trail tablet work on lineage 16, you can study his project.
i think his hal audio is a advanced method.
you can use tasker app auto run alsa_amixer command when plug headphone on Androidx86 hal audio.

在 2020年4月21日星期二 UTC+8上午6:16:19,Francescodario Cuzzocrea写道:
unfortunately it did not worked, audio still come up from both speaker and headphones

Il giorno lun 20 apr 2020 alle ore 22:35 youling 257 <youli...@gmail.com> ha scritto:

--
You received this message because you are subscribed to the Google Groups "Android-x86" group.
To unsubscribe from this group and stop receiving emails from it, send an email to andro...@googlegroups.com.

Francescodario Cuzzocrea

unread,
Apr 21, 2020, 3:57:28 AM4/21/20
to andro...@googlegroups.com
Alright, but someone correct me if I am wrong, but I guess the issue here is that alsa is not muting speaker when the jack event is detected instead of being fault of the audio hal. Normal linux has alsa+pulse audio and alsa UCM files to handle audio routing, but we have not that (apart from the hardcoded .state files)

To unsubscribe from this group and stop receiving emails from it, send an email to android-x86...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-x86/e17cfa0c-80b4-4453-b322-610da8b9d56e%40googlegroups.com.

Francescodario Cuzzocrea

unread,
Apr 21, 2020, 6:41:44 PM4/21/20
to andro...@googlegroups.com
I tried poking a little bit more with the audio hal, trying to get in stuff both from project celadon and from minecrell, and adapting it for our use case, but unfortunately noting worked well. During one experiment I got audio muting from speaker while plugging in headphones jack (while video was still going on), but the audio from the headphones was not coming out properly (like one crackling sound every minute or so). I guess for now I will live with bt headphones.

Francescodario Cuzzocrea

unread,
Apr 22, 2020, 5:27:10 AM4/22/20
to andro...@googlegroups.com

Chih-Wei Huang

unread,
Apr 22, 2020, 11:25:57 AM4/22/20
to Android-x86
Francescodario Cuzzocrea <bosco...@gmail.com> 於 2020年4月21日 週二 上午3:52寫道:
I'll apply the patches.
Thanks a lot!



--
Chih-Wei
Android-x86 project
http://www.android-x86.org

Francescodario Cuzzocrea

unread,
Apr 22, 2020, 11:28:57 AM4/22/20
to andro...@googlegroups.com
thanks to you for keeping alive the project ! 

I further updated the patch, here you can find the last version https://gitlab.com/lineageos-x86/android_hardware_libaudio/-/commits/lineage-17.1

--
You received this message because you are subscribed to the Google Groups "Android-x86" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-x86...@googlegroups.com.

Francescodario Cuzzocrea

unread,
Apr 23, 2020, 7:56:46 AM4/23/20
to andro...@googlegroups.com
I figured out also the headphone stuff.

You need to have a specific mixer path adapted for those baytrail sound soc

Here I attach what works for me, adapted from minecrell one but designed to work with our audio hal


mixer_paths.xml

Francescodario Cuzzocrea

unread,
Apr 23, 2020, 9:13:38 AM4/23/20
to andro...@googlegroups.com
ok, I think I am starting to understand this stuff and at the end youling was right, the culprit is of the audio hal.
I was able to get both headphone and speaker audio working on this baytrail tablet by ditching completely what we are doing on init.
The audio route is handled automatically by android if we declare correct paths in mixer_path.xml .


So my thinking is that instead of setting up the sound card in init, we should maybe add different mixer_paths.xml (so lets say, mixer_paths_bytcrrt5640,xml, mixer_paths_chtrt5645.xml and so on for those weird audio socs, plus one other mixer_paths_generic.xml for doing what the scripts currently does when does not find a .state file), maybe by adding the logic to load different xmls in here : https://gitlab.com/lineageos-x86/android_hardware_libaudio/-/blob/lineage-17.1/audio_route.c#L33 instead of hardcoding the file.

What do you think about it ?


Chih-Wei Huang

unread,
Apr 23, 2020, 10:31:28 AM4/23/20
to Android-x86
Francescodario Cuzzocrea <francescodar...@mail.polimi.it> 於
2020年4月23日 週四 下午9:13寫道:
>
> ok, I think I am starting to understand this stuff and at the end youling was right, the culprit is of the audio hal.
> I was able to get both headphone and speaker audio working on this baytrail tablet by ditching completely what we are doing on init.
> The audio route is handled automatically by android if we declare correct paths in mixer_path.xml .
>
> To clarify what I am speaking about, I did : https://gitlab.com/lineageos-x86/android_device_generic_common/-/commit/283654f00feccbe73bcba15e1eb4f64ce99f0f88
> and added : https://gitlab.com/lineageos-x86/android_device_generic_common/-/blob/lineage-17.1/mixer_paths.xml
>
> and everything started working as it should.
>
> So my thinking is that instead of setting up the sound card in init, we should maybe add different mixer_paths.xml (so lets say, mixer_paths_bytcrrt5640,xml, mixer_paths_chtrt5645.xml and so on for those weird audio socs, plus one other mixer_paths_generic.xml for doing what the scripts currently does when does not find a .state file), maybe by adding the logic to load different xmls in here : https://gitlab.com/lineageos-x86/android_hardware_libaudio/-/blob/lineage-17.1/audio_route.c#L33 instead of hardcoding the file.
>
> What do you think about it ?

Sounds like a good idea.

But would it be too device specific?
I mean, we may need to create a mixer_paths.xml for each sound card.
Right? Or is it really possible to create a generic xml for most sound cards?

Given a sound card, how to create the mixer_paths.xml exactly?
Is it possible to generate it automatically?
Any doc to explain that?

Francescodario Cuzzocrea

unread,
Apr 23, 2020, 10:55:43 AM4/23/20
to andro...@googlegroups.com
well, it would be device specific for all those devices for which audio routing is complex and do need an UCM file, so for all those listed here: https://github.com/alsa-project/alsa-ucm-conf/tree/master/ucm2

while I think the generic one, which should reproduce this behaviour (which I assume is what is done now) :

   alsa_amixer -c $c set Master on
   alsa_amixer -c $c set Master 100%
   alsa_amixer -c $c set Headphone on
   alsa_amixer -c $c set Headphone 100%
   alsa_amixer -c $c set Speaker 100%
   alsa_amixer -c $c set Capture 80%
   alsa_amixer -c $c set Capture cap
   alsa_amixer -c $c set PCM 100 unmute
   alsa_amixer -c $c set SPO unmute
   alsa_amixer -c $c set IEC958 on
   alsa_amixer -c $c set 'Mic Boost' 1
   alsa_amixer -c $c set 'Internal Mic Boost' 1

which in terms of mixer_pats could be translated roughly into 

<mixer>
<!-- These are the initial mixer settings -->
<ctl name="Master Playback Volume" value="100" />
<ctl name="Master Playback Switch" value="1" />
<ctl name="Headphone Playback Switch" value="0" />
<ctl name="Speaker Playback Switch" value="0" />
<ctl name="Capture Switch" value="0" />
<path name="speaker">
<ctl name="Master Playback Switch" value="1" />
<ctl name="Speaker Playback Switch" value="1" />
</path>
<path name="headphone">
<ctl name="Master Playback Switch" value="1" />
<ctl name="Headphone Playback Switch" value="1" />
</path>
<path name="main-mic">
<ctl name="Capture Switch" value="1" />
<ctl name="Capture Volume" value="80" />
</path>

</mixer>

which is taken from https://github.com/projectceladon/device-androidia/blob/master/celadon_tablet/audio/default/mixer_paths_0.xml and is very simple, should be ok for the rest.
I think we only need to figure out the right ctl name by looking the correct names in asound.state on a machine for which setting
 
   alsa_amixer -c $c set Master on
   alsa_amixer -c $c set Master 100%
   alsa_amixer -c $c set Headphone on
   alsa_amixer -c $c set Headphone 100%
   alsa_amixer -c $c set Speaker 100%
   alsa_amixer -c $c set Capture 80%
   alsa_amixer -c $c set Capture cap
   alsa_amixer -c $c set PCM 100 unmute
   alsa_amixer -c $c set SPO unmute
   alsa_amixer -c $c set IEC958 on
   alsa_amixer -c $c set 'Mic Boost' 1
   alsa_amixer -c $c set 'Internal Mic Boost' 1

works.

I do not think that it is possible to generate automatically mixer_paths nor I was able to find documentation for that, but I think that for the vast majority of machines the generic one which would be the translation of alsa_amixer does at init would work, while the custom one should be loaded only if we detect a card which we know need a custom state file.
--
You received this message because you are subscribed to the Google Groups "Android-x86" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-x86...@googlegroups.com.
Message has been deleted

youling 257

unread,
Apr 23, 2020, 12:00:10 PM4/23/20
to Android-x86
I test mixer_paths.xml, a lot of warning cause speaker no sound.
switch from headphone to speaker, need wait few time will has sound.

04-23 22:26:16.798 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:16.831 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:16.864 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:16.897 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:16.930 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:16.964 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:16.997 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.030 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.063 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.096 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.129 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.162 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.196 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.229 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.262 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.295 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.328 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.361 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.393 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.426 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.459 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.492 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.525 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.558 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.593 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.626 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.658 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...
04-23 22:26:17.692 7763 7773 W audio_hw_primary: out_write error: -1, sleeping...

Francescodario Cuzzocrea

unread,
Apr 23, 2020, 12:01:54 PM4/23/20
to andro...@googlegroups.com
I had that too. Try to plug headphones in jack, then unplug it out and sound should just work also from speaker

We need to found a way to tell the hal to default start the speaker route, as by default it sets everything off. If you plug headphones it sets headphone route on, and speaker off, when you unplung it it set speaker on and headphone on


Il giorno gio 23 apr 2020 alle ore 17:57 youling 257 <youli...@gmail.com> ha scritto:
I test mixer_paths.xml, a lot of warning cause speaker no sound.

--
You received this message because you are subscribed to the Google Groups "Android-x86" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-x86...@googlegroups.com.

Francescodario Cuzzocrea

unread,
Apr 23, 2020, 12:02:35 PM4/23/20
to andro...@googlegroups.com
yeah I was writing just that.

I think that when we start the device, the hal does not set the right default route, so we need to check this thing

--
You received this message because you are subscribed to the Google Groups "Android-x86" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-x86...@googlegroups.com.

Francescodario Cuzzocrea

unread,
Apr 23, 2020, 12:04:04 PM4/23/20
to andro...@googlegroups.com
well I have the delay too, but it is not 10 second, only a couple of seconds. but I definitely prefer to live with tose caveats and with working speaker\headphones than with half working headphones

Francescodario Cuzzocrea

unread,
Apr 23, 2020, 12:15:48 PM4/23/20
to andro...@googlegroups.com
I could try to look into reworking a bit the audio hal after I learn proper c/c++ programming 

Michael Goffioul

unread,
Apr 23, 2020, 12:34:10 PM4/23/20
to Android-x86
Speaking of audio route, do you (or anybody) know what is the overall process when you plugin headphones in/out? How does Android OS get notified?


Francescodario Cuzzocrea

unread,
Apr 23, 2020, 12:39:34 PM4/23/20
to andro...@googlegroups.com

Michael Goffioul

unread,
Apr 23, 2020, 1:23:27 PM4/23/20
to Android-x86
Thanks, that was it. I get how it works now (and why I can't use that on my custom hardware :)).

youling 257

unread,
May 7, 2020, 12:35:19 AM5/7/20
to Android-x86
As post scriptum, it seems also that this https://gitlab.com/lineageos-x86/android_device_generic_common/-/commit/f8d5691602700d86fc02ae41ce2416b8bf01db35 fixes mp4 playing on stock gallery

fix stock gallery play mp4? what encoder mp4? OMX.google.h264.decoder? where can find test OMX.google.h264.decoder mp4 video?
x-plore and stock gallery can't play 'OMX.ffmpeg.h264.decoder' mp4 video, mxplayer HW can't play it, HW+ can play it, H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
media_codecs_ffmpeg.xml can work?

youling 257

unread,
May 7, 2020, 12:49:16 AM5/7/20
to Android-x86
As a side note, with kernel 5.6 it seems that this hax is needed to correctly register RTL8723BS bt chipset https://gitlab.com/lineageos-x86/android_device_generic_common/-/commit/bb2e0658511ec44124cd92f406025ee5e1639b55

you only has 8250_dw load problem on kernel 5.x?
kernel 5.x many modules not load on Android 10 because - _ , https://groups.google.com/forum/#!topic/android-x86/svYCyJAX6eg
how do you fix it?

youling 257

unread,
May 7, 2020, 1:40:24 AM5/7/20
to Android-x86
'OMX.ffmpeg.h264.decoder' can't play is because many modules not load on kernel 5.x.
i use this command to rename - to _
find . -type f -name "*-*" -print |
while read name; do
na=$(echo $name | tr '-' '_')
if [[ $name != $na ]]; then
mv "$name" $na
fi
done

now, kernel 5.x can load modules and play 'OMX.ffmpeg.h264.decoder' mp4.

youling 257

unread,
May 7, 2020, 2:09:36 AM5/7/20
to Android-x86
kernel 5.6/5.7, rename - to _ , depmod -a, can load all the necessary modules for Bay trail.
but the hack init.sh,  modprobe -r 8250_dw modprobe 8250_dw, cause kernel panic reboot ! remove it can boot enter Android 10, everything work normal on kernel 5.6/5.7 for Bay trail.
Reply all
Reply to author
Forward
0 new messages