yashsingh1/xdaforums huggingface dataset:
[Samsung Galaxy Alpha] modpunk:
Strange, sometimes bluetooth audio streaming doesn't work, because the framework doesn't select the correct audio device:

10-04 15:38:29.426 I/audio_a2dp_hw(23585): adev_open_output_stream: opening output

10-04 15:38:29.426 I/audio_a2dp_hw(23585): skt_connect: connect to /data/misc/bluedroid/.a2dp_ctrl (sz 10240)

10-04 15:38:29.426 I/audio_a2dp_hw(23585): skt_connect: connected to stack fd = 24

10-04 15:38:29.426 I/audio_a2dp_hw(23585): check_a2dp_ready: state AUDIO_A2DP_STATE_STOPPED

10-04 15:38:29.426 I/audio_a2dp_hw(23585): a2dp_command: A2DP COMMAND A2DP_CTRL_CMD_CHECK_READY

10-04 15:38:29.427 I/audio_a2dp_hw(23585): a2dp_command: A2DP COMMAND A2DP_CTRL_CMD_CHECK_READY DONE STATUS 0

10-04 15:38:29.427 I/audio_a2dp_hw(23585): adev_open_output_stream: success

10-04 15:38:29.431 W/LocalBluetoothProfileManager(30487): StateChangedHandler mProfile = A2DP new state = 2

10-04 15:38:29.432 D/CachedBluetoothDevice(30487): onProfileStateChanged: profile A2DP newProfileState 2

10-04 15:38:29.433 V/audio_hw_primary(23585): select_devices called

10-04 15:38:29.434 V/audio_hw_primary(23585): select_devices() new_route_id == adev->cur_route_id - devices: 0x2, input src: 0, output route: none input route none

10-04 15:38:29.434 V/audio_hw_primary(23585): start_output_stream: stream out device: 2, actual: 2

10-04 15:38:29.440 D/A2dpStateMachine(31855): A2DP Playing state : device: 44:74:6C:FE:63:EB State:10->11

10-04 15:38:29.452 D/A2dpService(31855): getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@28240c90

10-04 15:38:29.457 V/BluetoothAdapterProperties(31855): device is added to list

10-04 15:38:29.458 V/HeadsetService(31855): Received BluetoothA2dp Conn State changed

10-04 15:38:29.458 V/HeadsetService(31855): Received BluetoothA2dp Play State changed

10-04 15:38:29.458 D/HeadsetStateMachine(31855): Connected process message: 19, size: 1

10-04 15:38:29.459 D/HeadsetStateMachine(31855): A2dp State Changed: Current State: 2Prev State: 1A2pSuspend: false

10-04 15:38:29.461 D/HeadsetStateMachine(31855): Connected process message: 18, size: 1

10-04 15:38:29.462 D/HeadsetStateMachine(31855): A2dp Play State Changed: Current State: 11Prev State: 10A2pSuspend: false

Here we can see it calls select_devices() but it did not set it to bluetooth output "devices: 0x2" means it select the speaker, which has been used before ...
[Samsung Galaxy Alpha] modpunk:
Ok, bluetooth fixed again. bt_did.conf issue ....

Can someone with a STOCK ROM Android 5.0 and root do the following for me:

Get https://xor.cryptomilk.org/android/tinymix

Push it to /tmp and get a shell

$ chmod +x /tmp/tinymix

Do a normal phone call and while in the call do:

$ tinymix > /sdcard/incall_mixer.txt

Then do a phone call with a bluetooth headset and while in the call do:

$ tinymix > /sdcard/incall_bt_sco_mixer.txt

Then upload the two txt files here. Thanks ....
[Samsung Galaxy Alpha] modpunk:
The rest of the issue we see are probably all in mixer_paths.xml!!! I tried to explain how it works. Some basics about Linux programming and unix tools are needed:

ok, then you can help

The issues we have left are probably only in mixer_paths.xml

So our audio hal is different from the stock rom

we use audio_route from android which uses mixer_paths.xml

stock rom uses something called TinyUCM which uses tinyucm.conf and default_gain.conf

the important thing is to understand our hal

but it is really easy

there is the function select_devices() -> https://git.cryptomilk.org/projects....git/tree/hal/audio/audio_hw.c?h=TESTING#n409

it translates what the framework provides into a routing table

you have an output route and an input route

you can find the routing table here -> https://git.cryptomilk.org/projects...g_slte.git/tree/hal/audio/routing.h?h=TESTING

so if the framework says play a ringtone

the ouput route "speaker" is selected input route is none

so if you look into the routing table

it is media-speaker

the routing for media-speaker is here -> https://git.cryptomilk.org/projects...configs/audio/mixer_paths.xml?h=TESTING#n1333

this is applied in the order you see

mixer_paths.xml is a translation from tinyucm.conf -> https://git.cryptomilk.org/projects...git/tree/configs/audio/tinyucm.conf?h=TESTING

and default_gain.conf -> https://git.cryptomilk.org/projects...ree/configs/audio/default_gain.conf?h=TESTING

All the remaining bugs are in mixer_paths.xml

and audio_route with mixer_paths.xml is a bit more picky then tinyucm.conf

tinyucm.conf is not very clean and I'm not 100 sure how things are correctly applied

so in mixer_paths.xml it is important that in a path for a route are no duplicates

we need to find out the correct configuration for a route

this means if you are in a voice call

output route: voice-earpiece input route: voice-earpiece-main-mic-wb

and it switches to output route: media-speaker input route: none

then it is likely that we missed resetting something

this is probably missing in the top of the mixer_path.xml with is the default configuration

so what you can do to find out what is wrong

reboot your phone

speaker is working

tinymix > speaker_working.txt

well

you need to play some music that you get the mixer state for speaker

reboot your phone and play some music

tinymix > speaker_working.txt

do a phone call

play some music (but you hear no sound)

tinymix > speaker_not_working.txt

diff -u speaker_working.txt speaker_not_working.txt

the diff will show us what we need to fix
[Samsung Galaxy Alpha] surfin-bobby:
Hi,

I did the test and got this file. I don't understand why the DSP4 Firmware does not switch back to DSM after the end of the call, do you have a clue? Maybe the DSM log gives us info on this at the end?

However, once the sound is back (through starting the camera stock app) I don't have the problem on future phone calls. I will keep on trying.

Thanks;)
[Samsung Galaxy Alpha] modpunk:
The DSP4 Frimware is probably the issue. But scenario-speaker-default sets the Firmware to DSM.

Hmm ...

Can you try https://xor.cryptomilk.org/android/mixer_paths.xml
[Samsung Galaxy Alpha] nuno.f.ferreira:
Gave it a quick try and makes no difference in my case. Good outgoing call and no ringing on incoming call although I have incall audio. Test done on beta5.

---------- Post added at 05:40 PM ---------- Previous post was at 05:00 PM ----------

Hmm, not really sure so please just interpret it a tentative correction. I took a little car trip (bt-enabled) and then back to standard voice calls and I think it's possible that the only problem now is getting into a state of lack of ringing in incoming calls. incall audio seems(!) fine for all types of calls having switched between some states already.

If anyone can confirm....
[Samsung Galaxy Alpha] surfin-bobby:
Thanks, I tried this file but did not change anything. In my case the DSP4 Firmware is not beeing set back to DSM at the end of the call, so I get no device sound after it. Starting the stock camera app sets it back correctly, and then everything works as should.

I tried something else tonight, made a fully clean new install of Beta6 to test it, and I have a fully different behaviour: no audio at all during call, in or outgoing.:confused:

So I made the same with Beta5 (clean new install), which gave better results: the first calls are OK, but as soon as I start the stock camera app once, no audio during calls anymore.

Now I am back to my old Beta6 which apparently has the opposite behaviour than the vanilla Beta5, i.e. stock camera app either fixing device sounds or muting call audio.:crying:

Will continue trying to figure out what is going on.;)
[Samsung Galaxy Alpha] modpunk:
Ok, next try:

https://xor.cryptomilk.org/android/mixer_paths.xml

https://xor.cryptomilk.org/android/audio.primary.universal5430.so
[Samsung Galaxy Alpha] modpunk:
Ah wait, the kernel doc states:

To load a firmware, or to reboot the ADSP with different firmware you must:

- Disconnect the ADSP from any active audio path so that it will be powered-down

- Set the firmware control to the firmware you want to load

- Connect the ADSP to an active audio path so it will be powered-up
[Samsung Galaxy Alpha] surfin-bobby:
Hi, unfortunately no fix using these. Do you think it makes sense for me to try out stuff modifying only the xml, or has the problem to be solved somewhere else deeper in code?

---------- Post added at 10:07 AM ---------- Previous post was at 10:05 AM ----------

Sounds good, I also have the impression that we do not reset things properly when switching firmwares.
[Samsung Galaxy Alpha] modpunk:
Ok, here we go ...

https://xor.cryptomilk.org/android/mixer_paths.xml

https://xor.cryptomilk.org/android/audio.primary.universal5430.so
[Samsung Galaxy Alpha] surfin-bobby:
Still no sound after first call using these...
[Samsung Galaxy Alpha] Blubberor:
first try did not work, but might have been the other site, 2nd try directly after and without changing worked.
[Samsung Galaxy Alpha] surfin-bobby:
Blubberor what did you test exactly?
[Samsung Galaxy Alpha] modpunk:
Can you provide logcat and diff of mixer state, before and after?

I have the same issue now. I can investigate it here ...
[Samsung Galaxy Alpha] Blubberor:
Tried outgoing call

First one no so und,2nd was fine.

But now using during the day.if anything Pops up I will post feedback.
[Samsung Galaxy Alpha] modpunk:
https://xor.cryptomilk.org/android/audio.primary.universal5430.so

https://xor.cryptomilk.org/android/mixer_paths.xml

This fixes it for me ...
[Samsung Galaxy Alpha] Blubberor:
now only the universal5430.so was changed, right?

a completely but less important point - the mixer_paths.xml from I guess yesterday made the alarm sound not working...

Will try now the updated version and post feedback
[Samsung Galaxy Alpha] modpunk:
Yes, only the audio HAL changed, but the mixer_paths.xml is needed for this HAL. If you already have it on your device you don't have to update it.
[Samsung Galaxy Alpha] Blubberor:
working perfectly.

first try outgoing call - working

first incoming call - working!

BT not tested as well as over time. crossing my fingers.

Best and many thanks!!!
[Samsung Galaxy Alpha] modpunk:
[MENTION=4724491]surfin-bobby[/MENTION] are those working for you too?
[Samsung Galaxy Alpha] modpunk:
I've looked at the latest changes Samsung did to the Note4 kernel tree some days ago. So I updated the arizona kernel driver and part of that was an update to the kernel documentation which finally explained firmware loading ...

https://git.cryptomilk.org/projects...ade05bf45ab763d66db6aeba57fbcf367101d429#n164
[Samsung Galaxy Alpha] nuno.f.ferreira:
Not really the person you're asking but quick test here (beta5 and these changes) doesn't make a difference to me, with beta5 incall audio is fine for me on earpiece and bt but not audio on speaker (ringing). With beta6 I have no audio whatsoever.
[Samsung Galaxy Alpha] surfin-bobby:
Not working for me, sorry. [MENTION=6930324]nuno.[/MENTION], I had the same behaviour as yours testing Beta5 and Beta6 vanilla yesterday.
[Samsung Galaxy Alpha] modpunk:
I was able to reproduce it. The issue is still the same, the Firmware is not changed. So the questions is what does "Disconnect the ADSP from any active audio path" mean.
[Samsung Galaxy Alpha] modpunk:
https://xor.cryptomilk.org/android/audio.primary.universal5430.so

New try ...
[Samsung Galaxy Alpha] surfin-bobby:
still nothing...

My bet is that we are trying to switch firmwares when audio is still in use, as you wrote.

Starting the stock camera app sets the firmware correctly because no audio path is beeing used at this moment.

It is apparently not the case when I hang up the phone, so no switch is beeing made.

Do you need mixer states perhaps also during the call?
[Samsung Galaxy Alpha] Blubberor:
With the version before (not tested with this one)

No speaker playback, but calls outgoing regular and BT work fine.
[Samsung Galaxy Alpha] modpunk:
Well, the issue is that the Firmware for the speaker is not loaded. And currently I'm out of ideas what is wrong ...
[Samsung Galaxy Alpha] modpunk:
Last try for today:

https://xor.cryptomilk.org/android/audio.primary.universal5430.so

https://xor.cryptomilk.org/android/mixer_paths.xml
[Samsung Galaxy Alpha] surfin-bobby:
Blubberor, when you are in this situation, does starting the stock camera app bring back speaker sound?
[Samsung Galaxy Alpha] nuno.f.ferreira:
For me it does. (Still haven't tried latest iteration).
[Samsung Galaxy Alpha] surfin-bobby:
Still nothing, but thanks a lot!
[Samsung Galaxy Alpha] Blubberor:
Right now its working, so need to wait until it stops working. Will post feedback.
[Samsung Galaxy Alpha] nuno.f.ferreira:
Do you mean that you make a call and then someone calls you and your phone rings? If so than that is probably relevant because it's not so in my case, so either we have different software (I'm using beta 5 and modpunk's audio half and mixer_paths) or there are HW differences...
[Samsung Galaxy Alpha] Blubberor:
No, was talking about alarm and General speaker output. Today only Vibration made me get awake.

Concerning latest files.

No sound in outgoing calls via bt :\
[Samsung Galaxy Alpha] nuno.f.ferreira:
Hmm, still haven't tried latest version but with beta 5 plus next-to-last version modpunk has sent I'm one step away from perfection. All incall audio (earpiece and bt, haven't tried loudspeaker) calls is okay. I also have speaker after bt calls, I just don't have speaker after normal calls, opening the camera app fixes it.
[Samsung Galaxy Alpha] surfin-bobby:
I did some logcat tonight, using the last files you gave me:

-Phone starts:

[ 10-14 21:59:04.908 2400: 2863 V/audio_hw_primary ]

***** select_devices: devices=0x2, input src=0 -> output route: media-speaker, input route: none

-Then, start a call:

[ 10-14 21:59:40.271 2400: 2936 V/audio_hw_primary ]

***** select_devices: devices=0x1, input src=4 -> output route: voice-earpiece, input route: voice-earpiece-main-mic

-Phone switch to wideband:

[ 10-14 21:59:43.640 2400: 7155 V/audio_hw_primary ]

***** select_devices: devices=0x1, input src=4 -> output route: voice-earpiece-wb, input route: voice-earpiece-main-mic-wb

-End of the call, phone switching to wrong state:

[ 10-14 21:59:55.788 2400: 2400 V/audio_hw_primary ]

*** stop_call: Reset route to default

[ 10-14 21:59:55.788 2400: 2400 V/audio_hw_primary ]

***** select_devices: devices=0x1, input src=0 -> output route: media-earpiece, input route: none

-Opening camera app which switches it back:

[ 10-14 22:00:19.639 2400: 2897 V/audio_hw_primary ]

***** select_devices: devices=0x2, input src=0 -> output route: media-speaker, input route: none

I am not sure about this, but is it normal that at the end of a call media-earpiece is triggered?
[Samsung Galaxy Alpha] modpunk:
Well it looks like the framework selected meda-earpiece before. I can force it to media-speaker on the end of a call ...
[Samsung Galaxy Alpha] surfin-bobby:
Yes it could partially solve the problem if you set the device to 0x2 prior to running select_devices. But I still didn't find out why the camera solves the sound problem definitively, logically the sound should mute on future calls too, but it doesn't...
[Samsung Galaxy Alpha] modpunk:
Please flash BETA7 so we are on the same base.

I had the same issue as you, that after a call the device did not play any audio. We need to find out why.

So select_devices() is interesting, which route is configured. If it is always media-earpiece if this happens, then we can try to be a bit more intelligent.
[Samsung Galaxy Alpha] nuno.f.ferreira:
Installed beta7.

Normal/earpiece calls

Outgoing ok

Then incoming no ringing

Open camera app

Then incoming ok

Goto carkit

Outgoing ok

Incoming ok

Goto earpiece calls

Outgoing no incall audio

Reboot

Outgoing Ok
[Samsung Galaxy Alpha] modpunk:
Which route has select_devices() set here?? Check logcat! This is the important thing!
[Samsung Galaxy Alpha] saxmydix:
Here, sory for not cleaned logcat. Just using my phone app.
[Samsung Galaxy Alpha] surfin-bobby:
Thanks a lot for beta7, great improvements, good news you are already working on CM13, time for a beer!;)

I have the same behaviour as before on it, so we can keep on trying to figure out what is wrong. I analysed some mixer files today, got a hint on the speaker switch which maybe has to be off before switching to DSM firmware, will try it out. Otherwise I am ready to test a config where device is set to 0x2 instead of 0x1 prior to quit the call function.
[Samsung Galaxy Alpha] nuno.f.ferreira:
There are multiple. Logs attached, out.log is good outgoing call, in.log is bad (no ringing) incoming call.
[Samsung Galaxy Alpha] modpunk:
V/audio_hw_primary( 2388): stop_voice_call: Closing active PCMs

V/audio_hw_primary( 2388): stop_voice_call: Successfully closed 2 active PCMs

V/audio_hw_primary( 2388): *** stop_call: Reset route to default

V/audio_hw_primary( 2388): ***** select_devices: devices=0x1, input src=0 -> output route: media-earpiece, input route: none

Looks like after the call it selects the earpiece ...

lets try:

https://xor.cryptomilk.org/android/audio/test01/

Please post logcat ...
[Samsung Galaxy Alpha] surfin-bobby:
Thanks, still not working. The logcat shows that media-speaker is now triggered correctly, but still the firmware is not set to dsm. The camera app does not set back the firmware itself either, it seems to reset some parameter in a way that it enables the next trigger of media_speaker to set the firmware right.
[Samsung Galaxy Alpha] nuno.f.ferreira:
Confirm. Logs attached.
[Samsung Galaxy Alpha] modpunk:
Please try test02
[Samsung Galaxy Alpha] nuno.f.ferreira:
After replacing audio hal and just respawning mediaserver, had no incall audio for outgoing call. Rebooted and retested, same as before (beta7 and test01). Logs attached for calls after reboot.
[Samsung Galaxy Alpha] modpunk:
test03 is up
[Samsung Galaxy Alpha] nuno.f.ferreira:
Getting worst, sorry. The other side doesn't hear (before and after reboot) and still ringing/speaker not fixed after outgoing call. Logs attached.
[Samsung Galaxy Alpha] modpunk:
Ok, I contacted a friend who works on ALSA. I think we have a timing issue here.

He said to find out if the ADSP is disconnected and we can load a new firmware we need to check the debugfs of the kernel. Looking at the stock audio HAL it looks like it rights 1 to the DSM LOG mixer control and then checks the dms_log file in /sys

I guess we need checking of that and wait till the DSP Is unloaded and then set the new audio route.
[Samsung Galaxy Alpha] nuno.f.ferreira:
Makes a lot of sense. Feel free to use me for testing.
[Samsung Galaxy Alpha] nuno.f.ferreira:
I will make a correction here. It's not leaving car kit and going back to earpiece calls that breaks incall audio in next outgoing call. It's doing that *and* opening the camera app to fix the speaker. IOW the camera app change mixer state for speaker and for mic and in this case it fixes it for speaker and breaks it for mic.
[Samsung Galaxy Alpha] modpunk:
test08 is up and looks promising. It seems to be a timing issue. I've have hacked it together and it seems to be working right now.

Reset the mixer (turn off all devices)

Sleep for 1 second (we have to wait till the devices are powered-down)

Set the audio route (speaker, earpiece, mic)

Sleep for 200 ms

Turn on the device (e.g. speaker)

We need a way to detect if all devices are powered down. I'm not sure how to do that right now ...
[Samsung Galaxy Alpha] surfin-bobby:
Hi, I ran my set of tests using these 2 files, I am not seeing any enhancements. Kyasus rom had no audio problem at all, would it be any help to do some cross checks perhaps?
[Samsung Galaxy Alpha] modpunk:
I would say it worked with some luck. Also before on my device. You need to switch firmware for different devices. The default factory firmware setting is the Narrow Band (NB) firmware and only switching the DSP4 firmware is needed.

The firmware can only be changed if the audio path using it is powered down. We need to wait till the power down happened, switch the firmware and turn it on again. Currently I just wait for a second and this works (at least on my device).

Read the source and check yourself ...
[Samsung Galaxy Alpha] modpunk:
I increased the sleep time, still test08. I've also contacted the contact of the kernel driver. Maybe I can get a better explanation ...
[Samsung Galaxy Alpha] Olangu:
Could you point me to the code in question?

Never mind, I guess its in SM-G850F_EUR_LL_Opensource.zip...

- downloading now.
[Samsung Galaxy Alpha] modpunk:
https://git.cryptomilk.org/projects/android/android_device_samsung_slte.git/log/?h=TESTING

This is my work in progress branch. Currently it is using usleep() to wait for the device power down. Takashi said the right way is to check the dapm of the codec in debugfs if the device has been powered down.

root@slte:/ # cat /d/asoc/Pacific\ WM5110\ Sound/dapm/SPK
SPK: Off in 0 out 1
in "static" "HPOUT2R"
in "static" "HPOUT2L"
root@slte:/ # cat /d/asoc/Pacific\ WM5110\ Sound/florida-codec/dapm/HPOUT2R\
Input\ 1
HPOUT2R Input 1: Off in 0 out 1
in "DSP4.1" "DSP4"
out "static" "HPOUT2R Mixer"
root@slte:/ # cat /d/asoc/Pacific\ WM5110\ Sound/florida-codec/dapm/HPOUT2L\
Input\ 1
HPOUT2L Input 1: Off in 0 out 2
in "DSP4.1" "DSP4"
out "static" "HPOUT2L Mixer"

Here you can see that DSP4 is loaded for the Speaker ...
[Samsung Galaxy Alpha] surfin-bobby:
Hey, I found out that if mics stay off in the mixer_paths.xml then the speaker sound works after the first call. So it looks like mic setup has some influence here too! Will keep on searching on this.
[Samsung Galaxy Alpha] modpunk:
Yes, they load the DSP4 Firmware ... it is all about firmware loading ...
[Samsung Galaxy Alpha] modpunk:
Did you push the new audio hal AND mixer_paths.xml to the device? It changes the way how audio routes are activated ...
[Samsung Galaxy Alpha] surfin-bobby:
Ok, I get it, it makes a lot of sense : the camera app switches the mics on because they are needed for video. When the camera app stops, it switches the mics off in a clean way, and then the dsp4 firmware is loaded properly, giving us back the speaker sound.

So it seems that we are not switching off the mics properly at the end of the first call?
[Samsung Galaxy Alpha] modpunk:
The question is how this needs to be done correctly and how long it takes till a route is powered down. Or how we can find out if it is powered down.

I can try next to add "device-earpiece-enable" and "device-earpiece-disable". Then call disable before we reset the route to the default mixer settings. Set the new ones enable it again.
[Samsung Galaxy Alpha] nuno.f.ferreira:
I haven't been able to keep up during last few days. Just tried test08 and it seems to make no difference when compared to base beta7.

My main problem is still that speaker goes away after outgoing call, doesn't matter if it's normal or bluetooth.

When I'm in car kit mode and I'm using, for instance, google maps I hear no navigation instructions (speaker or bt) but if I'm on a call the instructions come in on the bluetooth channel over the phone call audio. This is with beta7.
[Samsung Galaxy Alpha] surfin-bobby:
Hi, I just ran my tests, the last files are indeed better, you should make a beta8 soon because beta7 has the following annoying bugs:

-whenever the phone has its speaker on and working, no audio on earpiece on incoming call : fixed in your latest files (bug was also in beta6)

-using the camera to fix the sound problem leads to a muted mic on incoming and outgoing call: fixed too (bug was not there in beta6)

So now if I run the camera app once after the first call, the audio is fully ok.

The remaining problems I have:

-speaker sound gone after first call

-speaker button during a call mutes the call audio completely (was not a bug in beta6)

Keep it up, we are almost done! ;)

---------- Post added at 09:59 PM ---------- Previous post was at 09:55 PM ----------

Hi nuno, what happens if you run the camera app once, is the sound back? If yes, do you have full call functionality then? By that I mean outgoing and incoming calls having mics and earpiece working?
[Samsung Galaxy Alpha] nuno.f.ferreira:
Camera app brings back speaker but looses mic.