[GUIDE][MAGISK]Apple USB-C to 3.5mm DAC dongle and Android - remove the power limit - Xiaomi Mi A3 Guides, News, & Discussion

(basically a small fine tuning of my previous guide)
Mi A3 doesn't have powerfull headphone amplifier, so for "hifi" headphones it's necessary to use external DAC. The first obvious choice would be a Pixel dongle, but for some reason Apple is selling a better performing dongle. Being cheaper and available in a mortar store, it was a no brainer purchase. I can definitely say that it works great and sound is crystal clear. However for yet another reason, Apple dongle is by default quite limited in power, being usable mainly by sensitive IEMs. After several attempts of various methods, I found a reliable way of removing this limit.
Ingredients needed:
1. Apple DAC dongle
2. Tasker
3. Magisk
4. AlsaMixer app (https://apkpure.com/alsamixer-root/com.skvalex.alsamixer)
Recipe:
1. Extract AlsaMixer app and locate "assets\alsa\system" folder
2. Create a Magisk module from this folder (mount everything under "system" to "system") with 755/755 rights
3. Install Magisk module
4. Create a Tasker event "headphones connected", task "shell script", run as root, command "alsa_amixer -c 1 sset PCM 120"
5. Connect Apple dongle
Voila, you suddenly moved from -40dB limit to 0db for max volume. Limit is automatically reset on each DAC re-connection, so Tasker intent is mandatory.
Verification:
1. In terminal write as root "alsa_amixer -c 1" to see the current playback limit. It obviously works only with DAC connected.
Note: this method works only for USB-C DACs, not for analog audio jack.
Default:
Code:
# [B]alsa_amixer -c 1[/B]
Simple mixer control 'PCM',0
Capabilities: pvolume pswitch pswitch-joined penum
Playback channels: Front Left - Front Right
Limits: Playback 0 - 120
Mono:
Front Left:[B] Playback 80 [67%] [-40.00dB][/B] [on]
Front Right:[B] Playback 80 [67%] [-40.00dB][/B] [on]
Headphones with no mic:
Code:
# [B]alsa_amixer -c 1 sset PCM 120[/B]
Simple mixer control 'PCM',0
Capabilities: pvolume pswitch pswitch-joined penum
Playback channels: Front Left - Front Right
Limits: Playback 0 - 120
Mono:
Front Left: [B]Playback 120 [100%] [0.00dB][/B] [on]
Front Right: [B]Playback 120 [100%] [0.00dB][/B] [on]
Headset with a mic:
Code:
# [B]alsa_amixer -c 1 sset Headset,0 120[/B]
Simple mixer control 'Headset',1
Capabilities: pvolume pswitch pswitch-joined penum
Playback channels: Front Left - Front Right
Limits: Playback 0 - 120
Mono:
Front Left: [B]Playback 120 [100%] [0.00dB][/B] [on]
Front Right: [B]Playback 120 [100%] [0.00dB][/B] [on]

How does one make a magisk module?
Edit: figured it out , had to use new template

How do you create the Magisk Module please ?
And where do you put the code displayed under
Default:
or
Headset with a mic:

what dongle u use then

Lalulilelo said:
How do you create the Magisk Module please ?
And where do you put the code displayed under
Default:
or
Headset with a mic:
Click to expand...
Click to collapse
1. how to create a Magisk module - https://topjohnwu.github.io/Magisk/guides.html
(or download some module and adapt it to your needs)
2. command needs to be used in Terminal emulator app to verify that it's working, after that you need to either type it manually every time you connect the dongle or use an automation app (Tasker)
Sami Devo said:
what dongle u use then
Click to expand...
Click to collapse
None at the moment, dongle was needed for Mi A1 phone as it had very bad headphone output. On Mi A3 it isn't so essential and since I moved to Mi 10T lite phone, I don't need the dongle at all.

_mysiak_ said:
1. how to create a Magisk module - https://topjohnwu.github.io/Magisk/guides.html
(or download some module and adapt it to your needs)
Click to expand...
Click to collapse
Thanks for the documentation.
At the time, I did not get it, got discouraged and gave up.
I am trying again since today.
You said in your first post :
mount everything under "system" to "system"
Click to expand...
Click to collapse
Does this mean copy the content of "assets\alsa\system" in "adb/modules/alsa_mixer/system" ?

Lalulilelo said:
Thanks for the documentation.
At the time, I did not get it, got discouraged and gave up.
I am trying again since today.
You said in your first post :
Does this mean copy the content of "assets\alsa\system" in "adb/modules/alsa_mixer/system" ?
Click to expand...
Click to collapse
Basically yes, you want to have folder "system" in your module with the content of "assets\alsa\system". My old Magisk module attached - no idea if it still works as I don't use it anymore, but it might help you.

_mysiak_ said:
Basically yes, you want to have folder "system" in your module with the content of "assets\alsa\system". My old Magisk module attached - no idea if it still works as I don't use it anymore, but it might help you.
Click to expand...
Click to collapse
Thanks !
I managed to make it work (for a short time ).
I had a problem in my tasker profiles.
I have 1 profile for headset with mic and 1 profile for headset without mic.
But, when I put my earpiece with mic, both profiles were activated causing both "alsa_amixer -c 1 sset PCM 120" and "alsa_amixer -c 1 sset Headset,0 120" to be sent.
Desactivating the "no mic" profile allowed the proper script to work.
BUT !
I updated my Oneplus 7T to Android 11 and the script doesn't work anymore
Maybe the audio system has changed ?
I will try to uninstall and reinstall everything.

Lalulilelo said:
Thanks !
I managed to make it work (for a short time ).
I had a problem in my tasker profiles.
I have 1 profile for headset with mic and 1 profile for headset without mic.
But, when I put my earpiece with mic, both profiles were activated causing both "alsa_amixer -c 1 sset PCM 120" and "alsa_amixer -c 1 sset Headset,0 120" to be sent.
Desactivating the "no mic" profile allowed the proper script to work.
BUT !
I updated my Oneplus 7T to Android 11 and the script doesn't work anymore
Maybe the audio system has changed ?
I will try to uninstall and reinstall everything.
Click to expand...
Click to collapse
I haven't noticed any problem when sending both commands to alsa_amixer, one will just fail to execute because of missing audio device (PCM or Headset) - I used only one Tasker profile to send both commands (in Tasker tasks mark checkbox "continue task after error" and it will work fine).
Android 11 might have changed audio device names - keep the module installed and headset/headphones connected and from terminal emulator type "alsa_amixer -c 1". You should see currently active device and corresponding limit.

_mysiak_ said:
I haven't noticed any problem when sending both commands to alsa_amixer, one will just fail to execute because of missing audio device (PCM or Headset) - I used only one Tasker profile to send both commands (in Tasker tasks mark checkbox "continue task after error" and it will work fine).
Android 11 might have changed audio device names - keep the module installed and headset/headphones connected and from terminal emulator type "alsa_amixer -c 1". You should see currently active device and corresponding limit.
Click to expand...
Click to collapse
Well even on Android 10 Termux returned "alsa_amixer : command not found"
It's weird because it was working, i even had tested different values after PCM and had settled for 105.

Update :
I don't know why but the script works well in Android 11 now.
It still says "alsa_amixer : command not found" in terminal but whatever.
Thanks for your time @_mysiak_

thanks for the guide.
For anyone who having issues installing alsa,
I have updated this magisk module so that it can work with latest Android.
Works on my OnePlus 7 Pro running oos11
So should also would on other devices.
For headset (with mic)
Run this
Bash:
alsa_amixer sset Headset 120
And for Headphones (without mic)
Run this
Bash:
alsa_amixer sset Headphone 120

bubundas17 said:
thanks for the guide.
For anyone who having issues installing alsa,
I have updated this magisk module so that it can work with latest Android.
Works on my OnePlus 7 Pro running oos11
So should also would on other devices.
For headset (with mic)
Run this
Bash:
alsa_amixer sset Headset 120
And for Headphones (without mic)
Run this
Bash:
alsa_amixer sset Headphone 120
Click to expand...
Click to collapse
Hi, I know nothing about android development, I am just an audiophile that wants good audio quality and have an apple dongle and can't get full power with it. I can't spend money to get UAPP.
I wanted to follow along and do what this guide says, but I am completely lost and have no clue what any of any of this means.
No idea what a Magisk is, can't find it in the app store, or alsamixer...
I'm just an average android user and want to fix my apple dongle to work fully.
Any possibility to get instructions for someone that doesn't know anything about this?
I would be extremely grateful, and there's several others like myself in the r/audiophile and r/headphones subreddits as well that want to fix this issue.

Related

auto BT headphone pairing?

Anyone know of a way to get a bluetooth headphone paired up and ready to listen with a single click? Currently I have to activate BT via Comm manager, then enter BT settings, select the headphones and "Set as wireless stereo" all before I actually start any music playing. Ideally it would be good to be able to chain those commands into a macro which also launched the music player - kind a music mode button.
Maybe this is a feature of later roms? I'm currently still using Black 2.5, waiting for compelling reasons to move on.
Cheers
PP
You can write a script but you must have MortScript installed (available here http://www.sto-helit.de/index.php?module=page&entry=ms_overview&action=view)
Basically you can get it to check the registry and if the Headphone profile has been detected (i.e. when you switch on your headphones), a series of keystokes can then set the 'wireless setreo' mode by opening the Bluetoock devieces screen ect, then your favorites music player can be launched.
You can also get it to close your music player when you switch off your headphones by checking the registry fir when headset profile is disabled.
Downsides are that Bluetooth must already be actived on the handset (so 2click solution ) before headphones are switched on. Also, the keystrokes will fail to start wireless stereo if you add/remove bluetooth devices because the relative positions of the listed devices will change...
Here is an example that works on my device - may need changes for yours;
RunCheck = 0
While (1)
HandsFreeState = RegRead("HKLM", "System\State\Hardware", "Handsfree")
If (HandsFreeState = 1 && RunCheck = 0)
ToggleDisplay(1)
Run "Windows\Bluetooth Shortcut.lnk"
Sleep 2000
MouseDown 25, 286
Sleep 1000
MouseUp 25,286
Sleep 500
SendDown
SendDown
SendCR
SendDown
SendCR
MouseDown 196, 309
Sleep 1000
MouseUp 196,309
Sleep 1000
SendCR
SendDown
SendCR
MouseDown 196, 309
Sleep 1000
MouseUp 196,309
Sleep 2000
Close "Settings"
Sleep 2000
RunCheck = 1
EndIf
If (HandsFreeState = 0 && RunCheck = 1)
# - Enter any code you wish to execute on disconnect here.
ToggleDisplay(0)
RunCheck = 0
EndIf
Sleep (1000)
EndWhile
Thanks for that. Do you find it's stable - I used to do similar things with the old Windows 3 macro recorder, but it often used to screw up when a window didn't open in time. It would be nice if there was a program to do it, I imagine one day the music app will do a quick poll to see if a device is available.
Yes its stable -I have it run on startup so it constantly running in the background. There maybe some battery usage whilst it is doing this.
I heard some BT stereo headphones automatically connect properly once you update to the latest drivers for the headphones.
Bil
I dont understand. Why do you need to constantly re-pair your headset?
With mine (iclip r35) it was only a 5 click job anyway.
1 click on Comm Mgr
2 Click on BT
1 Click switch on Headset
2 Click pair headset
3 click play music button on headset.
Takes less time to do than it does to write it!
That was with Black 2.5 too. only one problem I noticed was that B2.5 absolutely having the h/s powered off before activating bt via com mgr.
Black Majik is the same but seems slight better range and quality than B2.5
secret_squirrel said:
I dont understand. Why do you need to constantly re-pair your headset?
With mine (iclip r35) it was only a 5 click job anyway.
1 click on Comm Mgr
2 Click on BT
1 Click switch on Headset
2 Click pair headset
3 click play music button on headset.
Takes less time to do than it does to write it!
Click to expand...
Click to collapse
I don't have to re-pair. I have to:
1. click on CommMgr
2. click on BT
3. turn on phones
4. Settings, Bluetooth to bring up the BT settings window
5. click-hold on Bluephone entry under paired devices
6. select "Set as wireless audio" - phones are now active and linked
7. close BT dialog
8. close CommMgr
9. start music software
Your setup seems less fiddly, somehow your headphones are doing some of the work.
Auto BT Pairing
Have your enabled the (Make this device visible to other devices?) Under Start/Settings/Connections/Bluetooth then select Mode. If that doesn't work there might be another fix if you check out:
http://www.jetwaremobile.com

[Q] DTS/DD passthrough

Has anyone got this working? This is really my main complaint with this device. Stereo is like so 1980s!
XBMC have DD/DTS passthrough.
I'm using xbmc. Is there a certain test version you use to get it to work?
Sent from my Nexus 4 using Tapatalk 2
I use the one from july 14th. The passthrough is enabled in settings when you select HDMI as output.
Settings - > System - > Audio - > HDMI as output and 5.1 (or more) as number of speakers.
And it actually works? It shows up on mine too, but nothing comes out. I don't recall which version I'm using. I'll check it out later and report back. Thanks.
Sent from my Nexus 4 using Tapatalk 2
I'm using this one http://mirrors.xbmc.org/test-builds...ec63cd-adddroidlibstagefright-armeabi-v7a.apk
But I had it working also with other stagefright versions.
dalamario said:
I'm using this one http://mirrors.xbmc.org/test-builds...ec63cd-adddroidlibstagefright-armeabi-v7a.apk
But I had it working also with other stagefright versions.
Click to expand...
Click to collapse
I tried the linked version as well as the latest nightly and test versions. None have worked with DTS for me. I even tried on receivers from 2 different brands. They both do the exact same thing and release this loud noise instead of any sound. Does your receiver actually say DTS on it when playing the files?
Someone got it working on their Onkyo. I've been watching stuff with DTS and DD 5.1 this way on my TX-SR606 for several weeks on XBMC (libstagefright nightly builds). I checked my speakers, it does work.
"Go into Settings > Hardware Setup > HDMI >
Turn Off HDMI Control RIHD
This will now show an option called Audio TV Out (This passes audio to the TV when you don't want to use your speakers)
Turn this on and Voila you now have DD/DTS on every video you play"
This is from the "DTS audio via XBMC possible?" thread on Ouyaforum_dot_com (I can't post links yet).
If that doesn't work on your receiver, there's another (annoying) way: Start playing movie file, turn off receiver, wait a couple of seconds, turn it back on. The DTS or DD audio should light up. Sometimes it takes a couple of tries for it to work. If you pause or stop and replay, you have to do that same power cycling again.
reposter432 said:
Someone got it working on their Onkyo. I've been watching stuff with DTS and DD 5.1 this way on my TX-SR606 for several weeks on XBMC (libstagefright nightly builds). I checked my speakers, it does work.
"Go into Settings > Hardware Setup > HDMI >
Turn Off HDMI Control RIHD
This will now show an option called Audio TV Out (This passes audio to the TV when you don't want to use your speakers)
Turn this on and Voila you now have DD/DTS on every video you play"
This is from the "DTS audio via XBMC possible?" thread on Ouyaforum_dot_com (I can't post links yet).
If that doesn't work on your receiver, there's another (annoying) way: Start playing movie file, turn off receiver, wait a couple of seconds, turn it back on. The DTS or DD audio should light up. Sometimes it takes a couple of tries for it to work. If you pause or stop and replay, you have to do that same power cycling again.
Click to expand...
Click to collapse
Ok just got mine to work. I have a Denon and changing my Audio out to TV only stopped any audio for me. What I did was have to go into input setting and change the decode from Auto to to DTS (which stopped the audio) then back to auto and it works for DD and DTS. Turning my receiver off and on and changing channels didn't work either for me.
I tried fast forwarding and once in a while it would kick back to the loud sound and I would have to change it back. Tomorrow I'll watch a whole movie without fast forwarding it and see if it does it randomly or just with occasional FF.
Thanks for the help.
Actually, leaving it on DTS mode works too if you're watching a DTS movie. I have no DD only option, so going back to auto seems to work best for me.
I'm just happy there's hope for this to work automatically in the future. Then I will finally be done with my HTPC! Yay!
Hello guys,
I have a big issue with HDMI passthrough on XBMC on my Ouya. May be (I hope) you can help me :fingers-crossed:
My install is a little bit strange : I have an old audio receiver with no HDMI connector So, I connect my HDMI devices on my TV (Sony KDL-V5500) and use optical output from my TV to my Audio receiver (passthrough) that will decode audio stream.
With all my devices (XBOX, Raspberry Pi and XBMC, Internet provider TV box), it works very well... My TV has sound, and if I want best quality, it is possible to start receiver (and decrease sound on TV).
With my Ouya, sound is not sound but noise... With DD or DTS sound it is the same thing. I tried to stop TV and restart it to reset audio hardware but no way.
An idea ? Is my TV not compliant with HDMI passthrough from my Ouya ?
Thank you for your help...
Guys, playing movies on my ouya was the main reason for me to get it.
I've managed to solve dts issue, but only partly.
Follow these steps:
1. Hookup ouya to amplituner
2. Hookup amplituner to tv
3. Turn everything on, and set hdmi source on amplituner to ouya
4. Make sure hdmi output is set in xbmc settings for sound on ouya and you selected 5.1 speaker config or better
5. Start playing dts movie in xbmc ( it must not be dts-ma hd)
6. You get static in your speakers
7. Turn of amplituner so it switches to pass through mode
8. Wait couple seconds
9. Power on amplituner, so it recreates hdmi handshake with ouya
10. Profit, you have valid hdmi session and dts plays nice
There are some drawbacks.
1. If you pause a movie you have to redo steps 7,8 and 9
2. It doesn't work for dts-ma hd sound
Can someone tell me if dts-ma hd doesn't work because android kernel doesn't support it or for some other reason ?
I googled it A LOT, and found only bits and pieces of information, some say it's android kernel limitation and some say it depends on app I'm using. Anyway I'd like to enjoy all types of sound in my movies.

FireSound - Volume control for USB Audio devices on Amazon Fire TV

Motivation
The Fire TV outputs the audio signal along to the video signal over
HDMI by default. Therefore, if a display is used which does not support
audio over HDMI, such as a computer monitor, there won't be any sound.
On the other hand, the Fire TV box offers a USB port which can be used
for external audio devices, such as speakers or head phones. Luckily, the
Android based software which runs on the Fire TV (Fire OS) supports
audio output via USB, but with a snag: The is no user interface for volume
control.
The default output of digital audio via HDMI does not need (or support?) any
volume control, respectively mixing.
Description
There is one script listen_fireremote.sh which listens for Fire TV Remote
events. Button presses of UP or DOWN while holding the MENU button
increases or decreases the volume.
Another script listen_soundbar.sh listens for wheel events of the
Dell AC511 SoundBar in order to increase or decrease the volume.
Currently, volume control is supported for USB audio devices only.
HDMI is not supported because I do not have access to an HDMI
receiver with audio support for testing.
This volume control is carried out on a rather low level of the system and
is expected to work everywhere, across all apps.
Requirements
* a rooted Fire TV
* Script Manager - SManager app
Disclaimer
As usual, please be careful: these scripts run as root with nearly maximum
privileges and thus might break your Fire TV! They work for me but
might fail elsewhere. Make sure to review the code before running it.
Installation
1. Get the latest release package: github.com/ibressler/firesound/releases
2. Extract it to a path somewhere in /data/media/0 on your Fire TV box.
3. Set up one or both of the event listening scripts to be started at boot
time with superuser permissions as shown below:
(screenshots of a German Fire TV localization)
Implementation
The underlying Android system is based on a minimal Linux which
supports audio mixing via the tinyALSA tools.
Specifically on Android, tinymix can be used for this purpose.
The script collection at hand uses the tinymix program to find an audio
device which provides a linear playback volume mixer control.
Additionally, it sets up a background process querying the getevent builtin
command for certain user input events, for example from the Fire TV Remote or
another USB device.
This in turn, is used to control the initially determined playback volume via
tinymix.
Providing an arbitrary argument to the listener scripts listen_fireremote.sh
or listen_soundbar.sh keeps them in the foreground and outputs debug
information for each input event. Otherwise, during normal operation a log file
is created in the log subdirectory of the scripts directory: firesound/log.
Licensing: GPLv3.
Nice work!
Did you think it is possbible to add your script to XPosed Edge Pro, to getting it to work with specific buttons on the remote.
XPosed Edge Pro is working quit well on my FireTV bueller device.
Greetings by Idijt

[MOD] Codec-level Audio Mods for Pixel Devices: BiQuads, Stereo Capture and Playback

Attached is an installer for up to three hardware-level audio mods that I've created over the last few years.
Important: This installer is not flashable via TWRP, but needs to be installed using an adb root shell as outlined below.
The three mods that can be installed in any combination are
The dual speaker playback mod as originally presented in this thread. When installing this mod, an app will also be installed that offers the following functionality:
when the screen is on, the main loudspeaker level is reduced significantly to bring down its volume to the one that is attainable with the earpiece speaker. The idea is that when the screen is on you may want to use it to watch a movie or play a game where the stereo effect may enhance the listening experience. This is a "personal" use-case where the lower overall volume may not be a huge problem
when the screen is off the main loudspeaker level is again raised to its maximum capability to not miss notifications and alarms, etc
There is an option offered to force maximum gain also in case the screen is on, for instance when sharing a YouTube video with friends or when using the speakers in the car in navigation mode
The above functionality can be controlled with a new permanent notification with three buttons: "stereo", "mono", and "mode", which can be "adaptive" or "stock". If you install the dual speaker mod, an accompanying app/service will be installed that automatically shows the above referenced permanent notification. This "app" has no UI other than the permanent notification. It is really a service that automatically starts upon boot. Keep in mind that you will need to unlock the phone twice after the boot process has been completed for the service to become active. The reason for this is that Android only makes most services available only after the initial unlock as a security feature. After that the screen needs to turn off at least once for the speaker control service to detect the screen state. Also, this service requires root privileges to function properly.
Stereo camcorder audio recording mod. Any app that uses the CAMCORDER device is now capable of recording stereo sound. Examples are Google's stock camcorder or "Easy Voice Recorder Pro".
Headphone biquad filtering for frequency response compensation as first made available here. This option will also install the accompanying biQuads app and relevant files. REQUIREMENTS: system-less root and @flar2 's excellent ElementalX kernel starting with version 1.02, with codec power gating option disabled in the installer.
There are actually two installer provided:
chdloc_hardware_audio_mods_pixel__ull.tar.gz : retains ultra-low latency (ULL) audio playback, but only supports the main loudspeaker to be active in cases where ULL is being asked for
chdloc_hardware_audio_mods_pixel__no_ull_*.tar.gz: allows both loudspeakers to be active even when ULL is being asked for by an app. However, under the hood ULL is converted to low-latency playback only.
I was unable to get both loudspeakers to play simultaneously in ULL mode on a stock system/kernel. ULL seems to invoke very different data handling code inside the kernel (from IRQ-based to non-IRQ-based). It appears that two backends (SLIMBUS_0_RX and QUAT_MI2S_RX) cannot be simultaneously active in non-IRQ mode. It is possible that this "problem" can be fixed with a custom kernel, but I really don't want to go that route. That's why I opted to re-route the ULL plumbing to make use of the low-latency path instead. According to the AOSP source code (platform.c), ULL promises 7 ms of latency while low-latency promises 13 ms. Whether that delta makes a difference in day-to-day use, particularly in VR mode, I don't know (yet).
To install, download the attached archive to your PC and push it to /data/local/tmp on your Pixel
Code:
adb shell rm -rf /data/local/tmp/chdloc* && adb push chdloc_hardware_audio_mods_pixel*.tar.gz /data/local/tmp/
Then enter an adb shell and copy the following string of commands into a root shell:
Code:
cd /data/local/tmp && gzip -d chdloc_hardware_audio_mods_pixel__*.tar.gz && tar -xf chdloc_hardware_audio_mods_pixel*.tar && gzip chdloc_hardware_audio_mods_pixel*.tar && chmod -R a+rw chdloc* && cd chdloc_hardware_audio_mods_pixel && chmod 744 install_chdloc_mods.sh
to install type
Code:
./install_chdloc_mods.sh
and select your install option, which also includes "revert to stock".
The following hidden text shows the original OP for reference:
It has been a tradition in the Android community to enable the earpiece speaker for multimedia playback to somewhat mitigate the drawback of having only one bottom-firing loudspeaker. I have been running a "true stereo" mod on my Nexus 5 for almost two years with great success.
The Pixel is a little bit different. Like some other phones with the SD820/821 it uses a separate speaker DAC/amp, which makes this mod quite a bit more tricky. Let me get this out of the way: the bottom speaker gets *much* louder than, for instance, the one on the Nexus 5. You cannot expect the earpiece to get this loud to create any form of "surround" effect. The only way to get there is to lower the volume of the main loudspeaker. This is what I'm describing below. This work is in no way, shape or form complete. For now, I'm giving here an outline on what needs to be done to enable dual-loudspeaker playback. I encourage others to try it out and chime in. So here it goes:
First of all you need to be rooted. Then modify the following /system/etc/mixer_paths.xml {...}.
The installation process is now described here
Now you need to save the file and reboot your phone. When you play audio you will notice that the earpiece is barely audible against the main speaker. The only way around this is to lower the speaker gain. This can be done by writing to a register in the amplifier which sits on the i2c bus:
Code:
echo 0xZZ0f > /sys/kernel/debug/tfa98xx-34/regs/06-AUDIO_CTR
where ZZ is the gain. By default, the speaker is set to 0 dB of gain with ZZ=00, i.e.
Code:
echo 0x000f > /sys/kernel/debug/tfa98xx-34/regs/06-AUDIO_CTR
Now each "tick" in the upper eight bits in this 16-bit number lowers the gain by 0.5 dB. The last two gain settings are FE which is -127 dB and FF which mutes the speaker.
In my short tests I have found the a gain of -16 dB for the main speaker, i.e.
Code:
echo 0x210f > /sys/kernel/debug/tfa98xx-34/regs/06-AUDIO_CTR
and a gain of +6 dB for the earpiece (see above) gives fairly balanced left-right volume. The speaker volume could be adjusted via an app depending on the use-case or upon boot via a script in /su/su.d
Note that the mod at this stage is dual-mono only.
Going forward I'll try to enable true stereo or something like the HTC10 tweeter-woofer arrangement.
I understand that all of this appears fairly complicated, so work needs to go into making this actually useful for others with flashable zip and control app. Any volunteers...?
Updates
November 9: first release of a speaker control app
November 7: the no-sound on the earpiece speaker during an incoming call has been fixed. For details, refer to this post. Please test and report back
November 3: stereo support, the left channel is played by the earpiece and the right channel is played by the main speaker. Note the updated "speaker" device above. The line in red (QUAT ...) tells the mixer to send two channels to the speaker dac/amplifier. By default, the dac/amp mixes the two channels into a mono stream. If you want stereo, then issue
Code:
echo 0x8093 > /sys/kernel/debug/tfa98xx-34/regs/04-I2SREG # right channel only
at any time on the command line or add to a script in /su/su.d so it gets applied on boot. If you want to go back to left+right on the main speaker then issue
Code:
echo 0x809b > /sys/kernel/debug/tfa98xx-34/regs/04-I2SREG # mono mix
. With the above changes the earpiece always plays the left channel.
November 2: Initial revision
Known limitations
Speakerphone telephony resets the DAC/amp of the main speaker and the above modifications get wiped. Hence, it would be ideal to control this mod with Tasker or some other native app.
There currently is an issue with RX audio on the earpiece with an incoming phone call. There will be nothing coming out of the earpiece. Switching to speakerphone works fine. Outgoing calls are fine. This has to do with the above (necessary) changes to mixer_paths.xml and the timing on how audio devices are set up and torn down in specific use cases. An explanation and possible solutions are given below. fixed (?)
So here is the problem: A call comes in and the system plays the ringtone using the "speaker" device. With the changes above, the speaker device now also activates the earpiece speaker by default. When you answer the call, the audio HAL switches the audio devices by activating the relevant capture and playback devices. The playback device is different from the "speaker" device, but it involves the earpiece unless the phone is connected to a (potentially bluetooth) headset. Unfortunately, the "speaker" device gets disabled last, which means that the earpiece gets disabled. Here is the sequence of events as caught by logcat:
Phone is RINGING
17:30:04.578 adev_set_mode: mode 1
17:30:04.904 out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
17:30:04.908 select_devices: changing use case low-latency-playback output device from(1: handset, acdb 7) to (2: speaker, acdb 15)
17:30:04.908 enable_snd_device: snd_device(2: speaker) {=> chdloc: this line enables the earpiece}
17:30:04.924 enable_audio_route: usecase(1) apply and update mixer path: low-latency-playback speaker
Phone is answered in HANDSET mode
17:30:11.020 adev_set_mode: mode 2
17:30:11.123 out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=1
17:30:11.126 enable_snd_device: snd_device(19: voice-handset-tmus) {=> chdloc: this line enables the earpiece}
17:30:11.128 enable_snd_device: snd_device(55: voice-dmic-ef-tmus)
17:30:11.153 enable_audio_route: usecase(15) apply and update mixer path: voicemmode1-call
17:30:11.220 select_devices: changing use case low-latency-playback output device from(2: speaker, acdb 15) to (19: voice-handset-tmus, acdb 88)
17:30:11.220 disable_audio_route: usecase(1) reset and update mixer path: low-latency-playback speaker
17:30:11.277 disable_snd_device: snd_device(2: speaker) {=> chdloc: this line disables the earpiece}
17:30:11.304 enable_audio_route: usecase(1) apply and update mixer path: low-latency-playback
17:30:14.058 disable_audio_route: usecase(1) reset and update mixer path: low-latency-playback
I see three options to fix the issue:
Have the earpiece constantly enabled. I'm currently testing this method to see whether there are any side effects. I would be in favor of this method if it works.
Use Tasker to detect an incoming phone call and have Tasker enable the earpiece. This is actually very doable, but kludgy. I'd use this approach if the first one proves problematic.
Mess with the audio HAL to disable the speaker *before* the voice-handset-*** device is enabled. As this involves source code changes and, therefore, a modified audio HAL (/system/lib/hw/audio.primary.msm8996.so), this would be my least favorite option.
Great work mate!
YESSSSS!!!! Been waiting for this!! Excellent work!!
This mod plus viper4android is amazing! Sounds so good! Thank you!
Sent from my Pixel XL using XDA-Developers mobile app
Update: Full stereo support added to the OP. Note that for best stereo imaging, the gain for the main speaker needs to be reduced significantly. Stereo media playback is likely only useful for personal media consumption or gaming in a relatively quiet environment. This mod lends itself nicely to Tasker (or native app) integration with which stereo can be enabled on-demand.
Next, I'll look into an HTC 10 like setup where the earpiece is used as a tweeter. The idea is that the earpiece (and by extension the main speaker) gain can be kept higher because distortions that are caused by high frequency clipping are less audible than the ones that result from low-frequency clipping.
Update: There currently is a problem with this implementation in that there is, initially, no audio coming out of the earpiece when *receiving* a phone call. You can force audio to come out of the earpiece by quickly toggling to and from speakerphone mode. Outgoing phone calls are fine. Please keep this in mind when trying the mod. I'm currently investigating the exact cause.
Update 2: I think I'm understanding the problem. See the OP for an explanation and possible solutions
Edit: All working well.
So what you're saying is when answering a call, switch to loudspeaker then ear piece?
I'm a bit lost. 1. Do I need to change everything from "this" to " with" as above for the mod to work and 2. Once necessary files are replaced do I just save and let root create the XML.bak file or does the file I create go in su etc? Thanks
Sent from my Pixel XL using XDA-Developers mobile app
Juzman said:
So what you're saying is when answering a call, switch to loudspeaker then ear piece?
Click to expand...
Click to collapse
Yes, that is the current workaround. I'm currently testing additional mixer_path.xml mods that may address this issue.
treIII said:
I'm a bit lost. 1. Do I need to change everything from "this" to " with" as above for the mod to work and
Click to expand...
Click to collapse
Yes
2. Once necessary files are replaced do I just save and let root create the XML.bak file or does the file I create go in su etc? Thanks
Click to expand...
Click to collapse
Well, to stay in the spirit of system-less root, you don't want to modify /system. Instead, copy the modified mixer_paths.xml file to /su/etc
and create a file (bind mount) called 10mixer_paths in /su/su.d/
Code:
#!/su/bin/sush
mount -o bind /su/etc/mixer_paths.xml /system/etc/mixer_paths.xml
change the permissions to 700 (rwx------), and reboot.
chdloc said:
Yes, that is the current workaround. I'm currently testing additional mixer_path.xml mods that may address this issue.
Yes
Well, to stay in the spirit of system-less root, you don't want to modify /system. Instead, copy the modified mixer_paths.xml file to /su/etc
and create a file (bind mount) called 10mixer_paths in /su/su.d/
change the permissions to 700 (rwx------), and reboot.
Click to expand...
Click to collapse
Does I need to make a file bind mount inside of su/su.d/ thanks
treIII said:
Does I need to make a file bind mount inside of su/su.d/ thanks
Click to expand...
Click to collapse
Yes, you need to bind mount the 10mixer_paths file I quoted above in /su/su.d and simply copy the modified mixer_paths.xml to /su/etc
from what i read, the mod seems applicable on the OP3 as well, or is the S821 having a different hardware setup than the S820 ?
Mostafa Wael said:
from what i read, the mod seems applicable on the OP3 as well, or is the S821 having a different hardware setup than the S820 ?
Click to expand...
Click to collapse
The main codec is identical, but they may have a different speaker DAC/amp. As root run the following two shell commands
Code:
ls /sys/module | grep snd_soc
and
Code:
find /sys -name '*AUDIO_CTR*'
and post the result.
chdloc said:
The main codec is identical, but they may have a different speaker DAC/amp. As root run the following two shell commands
and
and post the result.
Click to expand...
Click to collapse
Here are my results. I guess it could not be applicable here
Are there any chances this mod becomes available as a script or zip eventually?
airmaxx23 said:
Are there any chance this mod becomes available as a script or zip eventually?
Click to expand...
Click to collapse
Yes
Update: The procedure described below is outdated. See this post for the new method.
I think I found a way to fix the silent earpiece speaker when a call comes in. It requires additional mixer_paths edits. I have attached an archive with three files:
mixer_paths.xml.stereo: copy (and rename!) to /su/etc/mixer_paths.xml; I dialed the earpiece gain back to 84 dB to get rid of distortions.
20speakerctrl: copy to /su/su.d and make executable (700, rwx------). This script is executed on boot and sets the speakers for stereo and lowers the level of the main speaker by around 18 dB.
mixer_paths.xml.stock: this is the stock mixer_paths file; if you want to go back to stock behavior, copy this file to /su/etc/mixer_paths.xml and delete /su/su.d/20speakerctrl
Please test this setup and report back. Note that you can currently only modify the main speaker gain and have it "stick" with the 'echo' command as described in the OP. To play around with the earpiece volume while media is playing you can use the following command in a root shell
Code:
tinymix "RX0 Mix Digital Volume" X
where X={0,1,...,84,85,...,124}. The default is X=84 which applies 0 dB of gain. Each "tick" up or down changes the gain by 1 dB. Add gain very carefully. At maximum volume, I would highly advise not to go beyond 90. Note that changing the earpiece volume this way does not "stick" and it defaults back to 84 as soon as you change the media stream (skip, different app, etc). You will need to run a custom kernel with sound control to be able to fully control the volume of the earpiece speaker.
There is still the issue that a speakerphone call resets the main speaker's volume to default. Over the next couple of weeks, I'll come up with a Tasker app -- which means you do not need to have Tasker installed -- which initially
re-applies the currently chosen gains after a phone call
lets you quickly toggle between the low-volume stereo setup and the high-volume stock setup
Other things this app could do is go back to stock behavior when the screen is off, so you won't miss notifications and/or alarms due to the lower overall volume of the stereo mod.
chdloc said:
There is still the issue that a speakerphone call resets the main speaker's volume to default.
Click to expand...
Click to collapse
So, after each call, we have to run the script in /su/su.d to reapply the volumes correctly? If that's the case, can always use Script Manager, and set a widget icon on home screen. After a call, tap the widget to execute the script again.
Juzman said:
So, after each call, we have to run the script in /su/su.d to reapply the volumes correctly? If that's the case, can always use Script Manager, and set a widget icon on home screen. After a call, tap the widget to execute the script again.
Click to expand...
Click to collapse
Correct. The idea, though, is to eventually have this done automatically by a Tasker app.
chdloc said:
Correct. The idea, though, is to eventually have this done automatically by a Tasker app.
Click to expand...
Click to collapse
Sweet as. Question two:
mixer_paths.xml.stock: this is the stock mixer_paths file; if you want to go back to stock behavior, copy this file to /su/etc/mixer_paths.xml and delete /su/su.d/20speakerctrl
Could we not just delete /su/etc/mixer_paths.xml instead? Since we will still have original in /etc/
Juzman said:
Sweet as. Question two:
mixer_paths.xml.stock: this is the stock mixer_paths file; if you want to go back to stock behavior, copy this file to /su/etc/mixer_paths.xml and delete /su/su.d/20speakerctrl
Could we not just delete /su/etc/mixer_paths.xml instead? Since we will still have original in /etc/
Click to expand...
Click to collapse
Sure, but then you probably also may want to delete the bind mount in /su/su.d as I'm not sure what would happen if the file the mount points to has been deleted.
In addition, there are a few more mods I'm going to release soon that some folks may want to play with (stereo camcorder recording and hardware audio filtering), so keeping that file around may come in handy.

Audio Gain Trick (need others check)

Pls, let me know if this work 4 u in speaker/headphones
Call *#546368#*710*
Hiddenmenu>devicetest>saat>manualtest>loopback test.
Scroll the trigger to other possition.
Wait 2 sec
Scroll the 2nd trigger
Wait for noise and them scroll again to disable.
Now play music or like to high volume.
Did increased? Idk if my volumes are down due to modifications and modules, and it reset the levels. Or if this enables a free gain mode for all of us.
Pls feedback, i need to know.
After reboot this gain disables for me. This "new" gain, will be the normal volume, and i ****ed up my mediaserver and its under-gained for any reason??
Or is a trick that i have discovered, and really gain the volume without any reason?
If is normal volume, i wish to know what i did for get an under-gain in my sound ... Is curious
for now, my headphones on dac, are beating up my Sennheiser Momentum like a 999Ohm auric. Really, for me is a huge gain.
OK. First thing to check: Which headphones are you using to tests? Are they over 50 ohm impedance?
If you can call hidden menu, then i assume that you have stock system.
EDIT:
I checked that. Volume is exactly like AVC = 0 (high impedance mode). For me it looks like forcing High Impedance Mode (HIM).
But if you have root you can manually set AVC like whatever you want forever
This phone according to mixer_paths_tavil.xml have three modes of analog gain: Normal mode (AVC = 14 or 15), AUX Mode (AVC = 6) and High Impedance Mode (AVC = 0)
By default HIM turns on headphones which have more than 50 ohm impedance, and it unleashes all power of amplifier in that DAC.
ShadoV90 said:
OK. First thing to check: Which headphones are you using to tests? Are they over 50 ohm impedance?
If you can call hidden menu, then i assume that you have stock system.
EDIT:
I checked that. Volume is exactly like AVC = 0 (high impedance mode). For me it looks like forcing High Impedance Mode (HIM).
But if you have root you can manually set AVC like whatever you want forever
This phone according to mixer_paths_tavil.xml have three modes of analog gain: Normal mode (AVC = 14 or 15), AUX Mode (AVC = 6) and High Impedance Mode (AVC = 0)
By default HIM turns on headphones which have more than 50 ohm impedance, and it unleashes all power of amplifier in that DAC.
Click to expand...
Click to collapse
I know that bro, thanks for ur info, but i already installed a magisk module dualspeaker, and ive edited the tavil file, setting all Hifi-dac avc to 0. This mean that i have an issue with the module or like, did not activated properly.
Because everytime stock system runs even with module, you need to kill audioserver at the start to make things work.
For some reason system loads default values instead of modded. After type in terminal
su -c killall audioserver
you will notice the difference. I made file in module "service.sh" and only command there is killall audioserver. With that every modification of audio is working properly due to restarting audioserver after start system.
ShadoV90 said:
Because everytime stock system runs even with module, you need to kill audioserver at the start to make things work.
For some reason system loads default values instead of modded. After type in terminal
su -c killall audioserver
you will notice the difference. I made file in module "service.sh" and only command there is killall audioserver. With that every modification of audio is working properly due to restarting audioserver after start system.
Click to expand...
Click to collapse
Man, i love u, thanks. U fixed my headaches of months with audio in one post. Really, thanks, i remember days with 10-15 kdz flashes, every time triying one different trick for make this module and others (killed my sound) work properly. Thank u again.
it really feels like a great change tested on a kz zsn pro, is there a way to maintain that volume level? i am on android 10 stock with root
Ricky Almonte said:
it really feels like a great change tested on a kz zsn pro, is there a way to maintain that volume level? i am on android 10 stock with root
Click to expand...
Click to collapse
It can be mantained if u do no reboot, but I memorized the code, and now, on reboots, other than accepting the system error message at startup, I also have to do the test loopback hahah (my kernel gives Android error at startup, it was just a joke). Finally after doing that at every start, I have the power of the speakers in stock as if I hadn't rooted. It's a shame to have to do all that in the stock rom, but Dad LG shielded his cell phone like a nuclear shelter.
manuhuelva said:
Man, i love u, thanks. U fixed my headaches of months with audio in one post. Really, thanks, i remember days with 10-15 kdz flashes, every time triying one different trick for make this module and others (killed my sound) work properly. Thank u again.
Click to expand...
Click to collapse
@manuhuelva please check your pms, thanks
kadyt said:
@manuhuelva please check your pms, thanks
Click to expand...
Click to collapse
Here is ur request bro
I do the workaround of "Loop Test" every reboot for properly start the module

Categories

Resources