-
Notifications
You must be signed in to change notification settings - Fork 140
ALSA
Mkchromecast can cast to google cast without the need of pulseaudio. One advantage I have seen, is that delay is maximum 4 seconds. For that, you have to use the ffmpeg
or avconv
backends together with the Mkchromecast's --alsa-device
flag. If you find any problems, please report it here.
Example:
python mkchromecast.py --encoder-backend ffmpeg --alsa-device hw:2,1
However, some previous configuration is needed. We will try to figure out how to build the hw:X1,Y1
alsa device needed to complete a .asoundrc
configuration file, and the virtual alsa device hw:X2,Y2
needed by the --alsa-device
flag in Mkchromecast. It seems that always Y1
has to be 0
while Y2
is 1
.
First, check what are the cards available in your system in /proc/asound/cards
. Below an example:
% cat /proc/asound/cards
0 [PCH ]: HDA-Intel - HDA Intel PCH
HDA Intel PCH at 0xc1814000 irq 57
1 [HDMI ]: HDA-Intel - HDA Intel HDMI
HDA Intel HDMI at 0xc1810000 irq 61
In the case above, the principal card is 0 [PCH]: HDA-Intel - HDA Intel PCH
for which the index X1
is 0
. Normally, our needed alsa sound card (hw:X1,Y1
) can be built as hw:0,0
. We will need it in the next step.
Second, we need to create the ~/.asoundrc
shown below. Note that this file may not exist. You will need to changehw:X1,Y1
accordingly (in the case shown in this wiki is hw:0,0
):
pcm.!default {
type asym
playback.pcm "LoopAndReal"
#capture.pcm "looprec"
capture.pcm "hw:X1,Y1"
}
pcm.looprec {
type hw
card "Loopback"
device 1
subdevice 0
}
pcm.LoopAndReal {
type plug
slave.pcm mdev
route_policy "duplicate"
}
pcm.mdev {
type multi
slaves.a.pcm pcm.MixReale
slaves.a.channels 2
slaves.b.pcm pcm.MixLoopback
slaves.b.channels 2
bindings.0.slave a
bindings.0.channel 0
bindings.1.slave a
bindings.1.channel 1
bindings.2.slave b
bindings.2.channel 0
bindings.3.slave b
bindings.3.channel 1
}
pcm.MixReale {
type dmix
ipc_key 1024
slave {
pcm "hw:X1,Y1"
rate 48000
#rate 44100
periods 128
period_time 0
period_size 1024 # must be power of 2
buffer_size 8192
}
}
pcm.MixLoopback {
type dmix
ipc_key 1025
slave {
pcm "hw:Loopback,0,0"
rate 48000
#rate 44100
periods 128
period_time 0
period_size 1024 # must be power of 2
buffer_size 8192
}
}
Test that this is working. For that, open any audio file to see if it is playing correctly.
We now need to load the snd-aloop
module:
sudo modprobe snd-aloop
This will create a new virtual device called Loopback
that we above referenced as hw:X2,Y2
and we will pass it to the --alsa-device
flag of Mkchromecast:
% cat /proc/asound/cards
0 [PCH ]: HDA-Intel - HDA Intel PCH
HDA Intel PCH at 0xc1814000 irq 57
1 [HDMI ]: HDA-Intel - HDA Intel HDMI
HDA Intel HDMI at 0xc1810000 irq 61
2 [Loopback ]: Loopback - Loopback
Loopback 1
As it can be seen, Loopback
has an index X2
equals 2
. This device is then hw:2,1
. This won't survive reboot. If you want to make this permanent, add snd-aloop
to /etc/modules
.
Now we can execute Mkchromecast passing all desired parameters:
python mkchromecast.py --encoder-backend ffmpeg --alsa-device hw:2,1 -c aac --volume
This will cast all your internal sound to your Google cast device. You can mute your speakers to listen only in your cast device.
Happy Casting!