I'm trying to setup a loopback device so that I can record the audio as it is being outputted through the audio jack. I've got this working on my desktop PC, running Ubuntu 14.04, with the following .asoundrc file, cobbled together from different sources:
pcm.!default {
type asym
playback.pcm "CardAndLoop"
capture.pcm "hw:Loopback,1"
}
pcm.CardAndLoop {
type plug
slave.pcm MultiCh
route_policy "duplicate"
}
pcm.MultiCh {
type multi
slaves.a.pcm pcm.MixCard
#slaves.a.pcm "hw:ALSA,0"
slaves.a.channels 2
slaves.b.pcm pcm.MixLoopback
#slaves.b.pcm "hw:Loopback,0"
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.MixCard {
type dmix
ipc_key 1024
slave {
pcm "hw:PCH,0"
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"
rate 44100
periods 128
period_time 0
period_size 1024 # must be power of 2
buffer_size 8192
}
}
Now, using this config file on my raspberry pi 3 running the latest Raspbian Jessie does not work (I made sure to change the audio card from PCH to ALSA). I've tracked the issue down to the dmix plug in. Anytime there is a dmix in the pipeline, playing audio does not work; it "hangs".
For instance, running
aplay -vvv /usr/share/sounds/alsa/Front_Center.wav`
hangs and shows the following log:
Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
Plug PCM: Route conversion PCM (sformat=S16_LE)
Transformation table:
0 - 0
1 - 0
2 - 0
3 - 0
Its setup is:
stream : PLAYBACK
access : RW_INTERLEAVED
format : S16_LE
subformat : STD
channels : 1
rate : 48000
exact rate : 48000 (48000/1)
msbits : 16
buffer_size : 16128
period_size : 4032
period_time : 84000
tstamp_mode : NONE
period_step : 1
avail_min : 4032
period_event : 0
start_threshold : 16128
stop_threshold : 16128
silence_threshold: 0
silence_size : 0
boundary : 2113929216
Slave: Multi PCM
Channel bindings:
0: slave 0, channel 0
1: slave 0, channel 1
2: slave 1, channel 0
3: slave 1, channel 1
Its setup is:
stream : PLAYBACK
access : MMAP_NONINTERLEAVED
format : S16_LE
subformat : STD
channels : 4
rate : 48000
exact rate : 48000 (48000/1)
msbits : 16
buffer_size : 16128
period_size : 4032
period_time : 84000
tstamp_mode : NONE
period_step : 1
avail_min : 4032
period_event : 0
start_threshold : 16128
stop_threshold : 16128
silence_threshold: 0
silence_size : 0
boundary : 2113929216
Slave #0: Direct Stream Mixing PCM
Its setup is:
stream : PLAYBACK
access : MMAP_INTERLEAVED
format : S16_LE
subformat : STD
channels : 2
rate : 48000
exact rate : 48000 (48000/1)
msbits : 16
buffer_size : 16128
period_size : 4032
period_time : 84000
tstamp_mode : NONE
period_step : 1
avail_min : 4032
period_event : 0
start_threshold : 16128
stop_threshold : 16128
silence_threshold: 0
silence_size : 0
boundary : 2113929216
Hardware PCM card 3 'bcm2835 ALSA' device 0 subdevice 0
Its setup is:
stream : PLAYBACK
access : MMAP_INTERLEAVED
format : S16_LE
subformat : STD
channels : 2
rate : 48000
exact rate : 48000 (48000/1)
msbits : 16
buffer_size : 16384
period_size : 4032
period_time : 84000
tstamp_mode : ENABLE
period_step : 1
avail_min : 4032
period_event : 0
start_threshold : 1
stop_threshold : 1073741824
silence_threshold: 0
silence_size : 1073741824
boundary : 1073741824
appl_ptr : 0
hw_ptr : 0
Slave #1: Direct Stream Mixing PCM
Its setup is:
stream : PLAYBACK
access : MMAP_INTERLEAVED
format : S16_LE
subformat : STD
channels : 2
rate : 48000
exact rate : 48000 (48000/1)
msbits : 16
buffer_size : 16128
period_size : 4032
period_time : 84000
tstamp_mode : NONE
period_step : 1
avail_min : 4032
period_event : 0
start_threshold : 16128
stop_threshold : 16128
silence_threshold: 0
silence_size : 0
boundary : 2113929216
Hardware PCM card 0 'Loopback' device 0 subdevice 0
Its setup is:
stream : PLAYBACK
access : MMAP_INTERLEAVED
format : S16_LE
subformat : STD
channels : 2
rate : 48000
exact rate : 48000 (48000/1)
msbits : 16
buffer_size : 24192
period_size : 4032
period_time : 84000
tstamp_mode : ENABLE
period_step : 1
avail_min : 4032
period_event : 0
start_threshold : 1
stop_threshold : 1585446912
silence_threshold: 0
silence_size : 1585446912
boundary : 1585446912
appl_ptr : 0
hw_ptr : 0
Max peak (4032 samples): 0x0000020a # 1%
Max peak (4032 samples): 0x00003b8d ########## 46%
Max peak (4032 samples): 0x00001d9b ##### 23%
Max peak (4032 samples): 0x00001a94 ##### 20%
After this it hangs and I have to kill it.
I think my issue is the same as reported in this post: https://www.raspberrypi.org/forums/viewtopic.php?t=64936&p=481557
Does anyone have experience with dmix/alsa and can point me in the right direction to solve this?
Thanks!