Getting audio working in chroot under KitKat 4.4.2 #223
I have a LG Volt and everything is so nice but I cannot get audio working. I have Arch Linux installed in the chroot. When I try to run alsamixer I get "cannot load mixer controls: Invalid argument". I've done a bit of googling but I haven't found any solutions. Do you have any ideas how to get audio working?
Sound can be a bit of a pain in chroot environments for a very long time. Some people had success with sound but others won't. When I got sound working. (Or at least the programs didn't throw andy errors.) It ramped up my cpu to like 75%-90% usage. I am using GS2 Pac-Man rom (CM11, AOKP and Paranoid android all-in-one rom before switching to wizzedkat.)
I HAVE AUDIO!! Here is what I did. After disabling consolekit pulseaudio module inside /etc/pulse/default.pa (afaik you don't really need it) pulseaudio starts up on my chroot automatically with a "dummy output" and a "dummy output monitor". I next run "pactl load-module module-simple-protocol-tcp rate=48000 format=s16le channels=2 source=auto_null.monitor record=true port=8000" with auto_null.monitor being the "dummy output monitor". I can play the stream that is created back using "simple protocol player" from the play store https://play.google.com/store/apps/details?id=com.kaytat.simpleprotocolplayer I notice no issues with playback and I can play multiple audio sources inside the chroot at the same time if I wanted to. On the android side the app acts like a music player so anything else trying to play music will kill it but other sounds like system notifications are fine. I also notice no overload of cpu running this setup.
I got the solution from here http://superuser.com/a/750324
Solution working with a LG Volt running Cyanogenmod 11 and a Chroot with Arch Linux
I'll write here some comments for getting audio inside chroot. Hope it'll be useful for someone.
my device is nexus 4, debian stable (no pulseaudio)
first - find out which of the devices in /proc/asound/card0/ is used for playing audio via speaker. I started playing tuneinradio stream from android - then grep -v closed
OK - so I know my audio is served via pcm14p.
Next - alsactl monitor - while starting playback from tuneinradio - I see:
Then I searched inside sources of cyanogenmod:
looks quite similar:
Then I may direct alsa to hw:0,14 and sound works fine. For line-out it's similar.
Can someone confirm it works also for other devices?
I no longer have the original device on which I was testing that. So here's the same, done on LG G2 (d802) - running lineageOS 14.1 weekly (android 7.1.2).
Debian stable in linuxdeploy, only one additional package installed (alsa-utils).
So first I start music on android and find which device is used:
= pcm0p is used.
= alsa device is hw:0,0
Next, I stop music, wait a moment, run # alsactl monitor, start music, stop music
Point here is to use amixer commands to mimic what android is doing. First 3 lines appeared when starting music, last 3 when stopping.
Only problem is that alsactl monitor is not actually showing the "VALUE". Last time I was looking in android sources for them - but there's a better way - asking amixer itself.
I have 3 controls to enable/disable (563,58,441), how are they named in amixer?
Now I can start music again and ask amixer for values:
Value to set is shown as "values=x". Running the same commands when the music is NOT playing reveals the values for "music_stopped_state".
So, to setup linux chroot for music playback I can run (probably by shellscript):
and direct alsa to hw:0,0 (via .asoundrc)
When finished playing, I run:
to revert settings to original state.
Similar concept applies for line-out/headphones. Just watch what android does via # alsactl monitor and do the same via amixer.
This can help: