Skip to content

Correct audio_policy_configuration.xml #57

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

Open
Flamefire opened this issue Nov 8, 2021 · 5 comments
Open

Correct audio_policy_configuration.xml #57

Flamefire opened this issue Nov 8, 2021 · 5 comments

Comments

@Flamefire
Copy link
Contributor

A user noted that e.g. the lilac phone supports 24bit 192kHz audio output but not on our LOS ROMs: https://forum.xda-developers.com/t/rom-lineageos-17-1-18-1-unofficial-update-2021-09-18.4308295/page-11#post-85879703

So far I found the audio_policy_configuration.xml to be responsible for that. Android 9 had the audio*.conf files while Android 10+ has the audio_policy_configuration.xml, so I'd guess something went wrong in the "translation"

@cryptomilk @derfelot How was audio_policy_configuration.xml created exactly? And shouldn't that be a device specific file instead of yoshino-common?

With some experiments I was able to get 24/192 output working: https://forum.xda-developers.com/t/rom-lineageos-17-1-18-1-unofficial-update-2021-09-18.4308295/post-85905893 But basically just pure Trial&error. This is the file I'm using:
audio_policy_configuration.xml.txt

Any input/ideas here?

@derfelot
Copy link
Member

derfelot commented Nov 8, 2021

No idea as to how to get 24/192 working properly. The support should be in kernel and we are using the stock audio hal, so everything should be in place. Maybe we are lacking some kind of prop?

As for the audio_policy_configuration.xml file, that is directly from stock with just some minor modifications, which you can check in the history. The file is identical across all devices.

@Flamefire
Copy link
Contributor Author

Maybe we are lacking some kind of prop?

It should all be in the audio_policy_configuration.xml as my experiments seem to prove.
I'm not sure why we still copy the audio_output_policy.conf, see

$(PLATFORM_PATH)/config/audio_policy/audio_output_policy.conf:$(TARGET_COPY_OUT_VENDOR)/etc/audio_output_policy.conf \
. I'd say we should not. According to https://source.android.com/devices/audio/implement-policy?hl=en

Note: Support for the USE_XML_AUDIO_POLICY_CONF build flag and thus the ability to use the deprecated CONF format was removed in Android 10.

If I compare https://github.com/whatawurst/android_device_sony_yoshino-common/blob/bda77a1cf0fbda2c1ee70002986fe965b4b9feb9/config/audio_policy/audio_output_policy.conf and https://github.com/whatawurst/android_device_sony_yoshino-common/blob/bda77a1cf0fbda2c1ee70002986fe965b4b9feb9/config/audio_policy/audio_policy_configuration.xml it seems to be indeed a "correct translation".

On my experiments with PowerAmp and that XML file I found that adding the 24bit 192kHz format to the deepbuffer was required. Not sure why.
I'd suspect even a bug in the player as according to the comments in the conf file if the player requests an output with flag AUDIO_OUTPUT_FLAG_DIRECT and a format of either AUDIO_FORMAT_PCM_24_BIT_PACKED or AUDIO_FORMAT_PCM_8_24_BIT it should work.
I'm also surprised to NOT see AUDIO_FORMAT_PCM_FLOAT in the config files.

I'll hopefully get a test phone in the next couple days or weeks. Then I can test if it even works on stock XZ1C/lilac.

@Flamefire
Copy link
Contributor Author

As for the audio_policy_configuration.xml file, that is directly from stock with just some minor modifications,

I have just extracted the file from G8441_Vodafone DE_47.2.A.11.228-R4C firmware and compared it to our current file: There is more than just "minor" modifications. E.g. having "Earpiece" and "FM Tuner" in the attached devices list and many new routes. So I guess mostly this commit: ce75be1#diff-79534e6aad8e786df2c39afb15e669d04bbe292a4bff7804146a4da50135d4b6

Also comparing the conf file vs the XML file from stock I see 192kHz in the conf but not in the XML:
E.g.:

  direct_pcm_24 {
    flags AUDIO_OUTPUT_FLAG_DIRECT
    formats AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT|AUDIO_FORMAT_PCM_32_BIT
    sampling_rates 44100|48000|88200|96000|176400|192000|352800|384000
    bit_width 24
    app_type 69940
  }

Pretty strange as if Sony forgot about that...

@Flamefire
Copy link
Contributor Author

Flamefire commented Nov 24, 2021

Some more input: Stock XZ1C supports 24/192 output.
Logcat from PowerAmp trying it:

APM_AudioPolicyManager: getOutputForAttr() device 0x4, sampling rate 192000, format 0x6, channel mask 0x3, flags 0x9
AudioFlinger: openOutput() this 0xea43e000, module 10 Device 0x4, SamplingRate 192000, Format 0x000006, Channels 0x3, flags 0x1
audio_hw_primary: adev_open_output_stream: enter: format(0x6) sample_rate(192000) channel_mask(0x3) devices(0x4) flags(0x1)        stream_handle(0xefb6e000)

BTW: Any reason we don't use the source-build audio module but copy it from the stock rom? vendor/qcom/opensource/audio-hal/primary-hal/configs/msm8998 even has some configs.

@Flamefire
Copy link
Contributor Author

Wow... I think I found the issue: Under accessibility services "Mono-Audio" is enabled by default.
This disables direct output: https://github.com/LineageOS/android_vendor_qcom_opensource_audio/blob/343077c4a5393459bc6b4a5fbccdeb0b33b6e5d4/policy_hal/AudioPolicyManager.cpp#L1727-L1731
This then enables the "deep-buffer" flag: https://github.com/LineageOS/android_vendor_qcom_opensource_audio/blob/343077c4a5393459bc6b4a5fbccdeb0b33b6e5d4/policy_hal/AudioPolicyManager.cpp#L1847-L1848

--> Boom, we run into the 16Bit@48kHz config of that:

<profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>

Instead of
<profile name="" format="AUDIO_FORMAT_PCM_24_BIT_PACKED"
samplingRates="8000,11025,12000,16000,22050,24000,32000,44100,48000,64000,88200,96000,128000,176400,192000,352800,384000"
channelMasks="AUDIO_CHANNEL_OUT_MONO,AUDIO_CHANNEL_OUT_STEREO,AUDIO_CHANNEL_OUT_2POINT1,AUDIO_CHANNEL_OUT_QUAD,AUDIO_CHANNEL_OUT_PENTA,AUDIO_CHANNEL_OUT_5POINT1,AUDIO_CHANNEL_OUT_6POINT1,AUDIO_CHANNEL_OUT_7POINT1"/>

Not sure why the default is Mono-Audio and why deep-buffer doesn't support the high-res output. I'd expect that for Mono it can simply downmix the stereo to mono keeping the original quality...
We might want to improve on this or just keep it...

BTW: Not fully sure why all the compressed formats were removed with 0199389 and 62a5376#diff-79534e6aad8e786df2c39afb15e669d04bbe292a4bff7804146a4da50135d4b6
E.g. lilac has those in stock, wouldn't that mean they are supported in LOS too when copying the audio.primary.so from stock? Or is there more involved in those formats? Should we have a configuration option in yoshino-common to use or not use those configs and e.g. have adjusted files per platform depending on the stock configs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants