Skip to content
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

Getting audio working in chroot under KitKat 4.4.2 #223

Closed
ShapeShifter499 opened this issue May 14, 2015 · 18 comments

Comments

Projects
None yet
10 participants
@ShapeShifter499
Copy link

commented May 14, 2015

Hi,

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?

@dyharlan

This comment has been minimized.

Copy link

commented Jun 3, 2015

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.)

@ShapeShifter499

This comment has been minimized.

Copy link
Author

commented Jun 19, 2015

@dyharlan What did you do exactly to get sound working for you? So far I was able to mess with the volume but that was only good for other apps and not the chroot.

@dyharlan

This comment has been minimized.

Copy link

commented Jun 19, 2015

I installed alsa and made some modifications to asound.conf/.asoundrc. But after testing a wav file, it sorta worked but again it just overloaded my cpu.

@ShapeShifter499

This comment has been minimized.

Copy link
Author

commented Jun 23, 2015

I'm not sure what modifications to make to my system but I did try a kde install and that flat out causes hard reboots when ran. Someone suggested on irc that it could be using my audio and android doesn't like it.

@ShapeShifter499

This comment has been minimized.

Copy link
Author

commented Jun 23, 2015

@dyharlan

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

@radosd

This comment has been minimized.

Copy link

commented Apr 1, 2016

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:
card 0, #334 (2,0,0,SLIM TX3 MUX,0) VALUE
card 0, #364 (2,0,0,RX3 MIX1 INP2,0) VALUE
card 0, #365 (2,0,0,RX3 MIX1 INP1,0) VALUE
card 0, #372 (2,0,0,RX4 DSM MUX,0) VALUE
card 0, #271 (2,0,0,SLIMBUS_0_RX Audio Mixer MultiMedia5,0) VALUE

Then I searched inside sources of cyanogenmod:
https://github.com/CyanogenMod/android_device_lge_mako/blob/cm-13.0/mixer_paths.xml

looks quite similar:
<path name="speaker"> <ctl name="SLIM_0_RX Channels" value="One" /> <ctl name="RX3 MIX1 INP1" value="RX1" /> <ctl name="RX3 MIX1 INP2" value="RX6" /> <ctl name="RX4 DSM MUX" value="DSM_INV" /> <ctl name="SLIM TX3 MUX" value="RMIX3" /> </path>
So in fact - what was needed:
amixer sset 'SLIMBUS_0_RX Audio Mixer MultiMedia5' on
amixer sset 'SLIM TX3 MUX' 'RMIX3'
amixer sset 'RX3 MIX1 INP2' 'RX6'
amixer sset 'RX3 MIX1 INP1' 'RX1'
amixer sset 'RX4 DSM MUX' 'DSM_INV'

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?

@dyharlan

This comment has been minimized.

Copy link

commented Jun 8, 2016

radosd, This looks confusing. Is there a step-by-step?

@dyharlan

This comment has been minimized.

Copy link

commented Jun 12, 2016

@radosd how did you perform the grep -v command?

@raghavsingh219

This comment has been minimized.

Copy link

commented Oct 22, 2016

Is there any way to enable sound in linux without pulseaudio ? Actually I m fed up of a lot of errors and i need an easy way to enable sound on samsung galaxy tab 4 SM-t231.android 4.4.2 kitkat.

@Aeysir

This comment has been minimized.

Copy link

commented Oct 23, 2017

I really want to get sound to work I know this is and old post but I'm so desperate. How did you use the grep -v command I cant get it to work. please any help is appreciated!

@radosd

This comment has been minimized.

Copy link

commented Oct 24, 2017

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:

root@localhost:/proc/asound/card0# grep -v closed */sub0/status
pcm0p/sub0/status:state: RUNNING

= pcm0p is used.

root@localhost:/proc/asound/card0# cat pcm0p/info
card: 0
device: 0
subdevice: 0

= alsa device is hw:0,0

Next, I stop music, wait a moment, run # alsactl monitor, start music, stop music

root@localhost:~# alsactl monitor
card 0, #563 (2,0,0,RX7 MIX1 INP1,0) VALUE
card 0, #58 (2,0,0,RX7 Digital Volume,0) VALUE
card 0, #441 (2,0,0,SLIMBUS_0_RX Audio Mixer MultiMedia1,0) VALUE
card 0, #441 (2,0,0,SLIMBUS_0_RX Audio Mixer MultiMedia1,0) VALUE
card 0, #58 (2,0,0,RX7 Digital Volume,0) VALUE
card 0, #563 (2,0,0,RX7 MIX1 INP1,0) VALUE

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?

root@localhost:~# amixer controls | egrep "numid=441,|numid=58,|numid=563,"
numid=58,iface=MIXER,name='RX7 Digital Volume'
numid=563,iface=MIXER,name='RX7 MIX1 INP1'
numid=441,iface=MIXER,name='SLIMBUS_0_RX Audio Mixer MultiMedia1'

Now I can start music again and ask amixer for values:

root@localhost:~# amixer cget numid=563,iface=MIXER,name='RX7 MIX1 INP1'
numid=563,iface=MIXER,name='RX7 MIX1 INP1'
; type=ENUMERATED,access=rw------,values=1,items=12
; Item #0 'ZERO'
; Item #1 'SRC1'
; Item #2 'SRC2'
; Item #3 'IIR1'
; Item #4 'IIR2'
; Item #5 'RX1'
; Item #6 'RX2'
; Item #7 'RX3'
; Item #8 'RX4'
; Item #9 'RX5'
; Item #10 'RX6'
; Item #11 'RX7'
: values=5

root@localhost:~# amixer cget numid=58,iface=MIXER,name='RX7 Digital Volume'
numid=58,iface=MIXER,name='RX7 Digital Volume'
; type=INTEGER,access=rw---R--,values=1,min=0,max=100,step=0
: values=67
| dBscale-min=0.00dB,step=0.01dB,mute=0

root@localhost:~# amixer cget numid=441,iface=MIXER,name='SLIMBUS_0_RX Audio Mixer MultiMedia1'
numid=441,iface=MIXER,name='SLIMBUS_0_RX Audio Mixer MultiMedia1'
; type=BOOLEAN,access=rw------,values=1
: values=on

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):
amixer cset numid=563,iface=MIXER,name='RX7 MIX1 INP1' 5
amixer cset numid=58,iface=MIXER,name='RX7 Digital Volume' 67
amixer cset numid=441,iface=MIXER,name='SLIMBUS_0_RX Audio Mixer MultiMedia1' on

and direct alsa to hw:0,0 (via .asoundrc)

When finished playing, I run:
amixer cset numid=441,iface=MIXER,name='SLIMBUS_0_RX Audio Mixer MultiMedia1' off
amixer cset numid=58,iface=MIXER,name='RX7 Digital Volume' 84
amixer cset numid=563,iface=MIXER,name='RX7 MIX1 INP1' 0

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.

@Aeysir

This comment has been minimized.

Copy link

commented Oct 26, 2017

I got it working!! thank you very much! It works really well!

one more thing though is there any way to adjust volume??

@nachum37

This comment has been minimized.

Copy link

commented Nov 13, 2017

@radosd all devices are closed... what i can do?

@dyharlan

This comment has been minimized.

Copy link

commented Jan 20, 2018

@radosd when typing in grep -v closed in /proc/asound/card0, nothing appears.

@WilsonBradley

This comment has been minimized.

Copy link

commented Aug 16, 2018

Are there real instructions somewhere to get this running ?

@twaik

This comment has been minimized.

Copy link

commented Aug 21, 2018

@meefik meefik closed this Aug 21, 2018

@mirfatif

This comment has been minimized.

Copy link

commented Oct 9, 2018

This can help:

#!/bin/bash

sudo apt install alsa-utils

echo Play music or start recording and press enter.
read key

c=$(grep RUNNING /proc/asound/card*/pcm*/sub*/status | grep -o 'card[0-9]*' | grep -o [0-9]*) && echo "Card: $c"
p=$(grep RUNNING /proc/asound/card*/pcm*/sub*/status | grep -o 'pcm[0-9]*p' | grep -o [0-9]*) && { echo "Playback device: $p"; echo "i.e. alsa device is hw:$c,$p"; }
r=$(grep RUNNING /proc/asound/card*/pcm*/sub*/status | grep -o 'pcm[0-9]*c' | grep -o [0-9]*) && { echo "Recording device: $r"; echo "i.e. alsa device is hw:$c,$r"; }

echo
printf 'Stop playback / recording and press enter.'
read key

# alsactl doesn't seem to work when piped to grep
echo 'Start and stop playback / recording and observe values changes.'
sleep 3
echo 'Terminate when done.'
echo
trap 'pkill -1 alsactl' SIGINT
alsactl monitor

trap "kill $$" SIGINT
echo
printf 'Write Control Identifier (nmuid) of changed values with space: '
read -a val

for v in ${val[@]}
do
	printf 'Play music / start recording and press enter.'
	read key
	v1="$(amixer cget "$(amixer controls | grep "numid=${v},")" | grep ': values=' | cut -d= -f2)"
	printf 'Stop playback / recording and press enter.'
	read key
	sleep 3
	v2="$(amixer cget "$(amixer controls | grep "numid=${v},")" | grep ': values=' | cut -d= -f2)"

	if [ "$v1" = "$v2" ]; then
		echo "ERROR: No change in values detected for Control Identifier $v."
		continue
	fi

	V1="$(printf '%s\n%s' "$V1" "amixer cset $(amixer controls | grep "numid=${v},") $v1")"
	V2="$(printf '%s\n%s' "$V2" "amixer cset $(amixer controls | grep "numid=${v},") $v2")"
done

[ -z "$V1" ] || { printf '\n To start:'; echo "$V1"; }
[ -z "$V2" ] || { printf '\n To stop:'; echo "$V2"; }

@mirfatif

This comment has been minimized.

Copy link

commented Oct 9, 2018

@radosd brilliant work. Can we record sound in similar way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.