SREEKANTH SREEKUMAR
2017-04-28 07:28:07 UTC
I have M-Audio M-Track Eight, a USB based soundcard that I use to play and record audio files using a python based tool I wrote. My device definitions in .asoundrc looks like this:
pcm.!default {
type plug
slave {
pcm "hw:1,0"
}
}
ctl.!default {
type hw
card 1
}
pcm_slave.m-audio_m-track_eight_1 {
pcm "hw:1,0"
channels 8
rate 44100
buffer_size 4096
period_size 1024
}
pcm.outch1 {
type dshare
ipc_key 1111
slave m-audio_m-track_eight_1
bindings [ 0 ]
hint.description "M-Audio M-Track Eight output/playback channel 1 (from output port 1)"
}
pcm.inch1 {
type dsnoop
ipc_key 2111
slave m-audio_m-track_eight_1
bindings [ 0 ]
hint.description "M-Audio M-Track Eight input/capture channel 1 (from input port 1)"
}
pcm.outch2 {
type dshare
ipc_key 1112
slave m-audio_m-track_eight_1
bindings [ 1 ]
hint.description "M-Audio M-Track Eight output/playback channel 2 (from output port 2)"
}
pcm.inch2 {
type dsnoop
ipc_key 2112
slave m-audio_m-track_eight_1
bindings [ 1 ]
hint.description "M-Audio M-Track Eight input/capture channel 2 (from input port 2)"
}
pcm.outch3 {
type dshare
ipc_key 1113
slave m-audio_m-track_eight_1
bindings [ 2 ]
hint.description "M-Audio M-Track Eight output/playback channel 3 (from output port 3)"
}
pcm.inch3 {
type dsnoop
ipc_key 2113
slave m-audio_m-track_eight_1
bindings [ 2 ]
hint.description "M-Audio M-Track Eight input/capture channel 3 (from input port 3)"
}
pcm.outch4 {
type dshare
ipc_key 1114
slave m-audio_m-track_eight_1
bindings [ 3 ]
hint.description "M-Audio M-Track Eight output/playback channel 4 (from output port 4)"
}
pcm.inch4 {
type dsnoop
ipc_key 2114
slave m-audio_m-track_eight_1
bindings [ 3 ]
hint.description "M-Audio M-Track Eight input/capture channel 4 (from input port 4)"
}
pcm.outch5 {
type dshare
ipc_key 1115
slave m-audio_m-track_eight_1
bindings [ 4 ]
hint.description "M-Audio M-Track Eight output/playback channel 5 (from output port 5)"
}
pcm.inch5 {
type dsnoop
ipc_key 2115
slave m-audio_m-track_eight_1
bindings [ 4 ]
hint.description "M-Audio M-Track Eight input/capture channel 5 (from input port 5)"
}
pcm.outch6 {
type dshare
ipc_key 1116
slave m-audio_m-track_eight_1
bindings [ 5 ]
hint.description "M-Audio M-Track Eight output/playback channel 6 (from output port 6)"
}
pcm.inch6 {
type dsnoop
ipc_key 2116
slave m-audio_m-track_eight_1
bindings [ 5 ]
hint.description "M-Audio M-Track Eight input/capture channel 6 (from input port 6)"
}
pcm.outch7 {
type dshare
ipc_key 1117
slave m-audio_m-track_eight_1
bindings [ 6 ]
hint.description "M-Audio M-Track Eight output/playback channel 7 (from output port 7)"
}
pcm.inch7 {
type dsnoop
ipc_key 2117
slave m-audio_m-track_eight_1
bindings [ 6 ]
hint.description "M-Audio M-Track Eight input/capture channel 7 (from input port 7)"
}
pcm.outch8 {
type dshare
ipc_key 1118
slave m-audio_m-track_eight_1
bindings [ 7 ]
hint.description "M-Audio M-Track Eight output/playback channel 8 (from output port 8)"
}
pcm.inch8 {
type dsnoop
ipc_key 2118
slave m-audio_m-track_eight_1
bindings [ 7 ]
hint.description "M-Audio M-Track Eight input/capture channel 8 (from input port 8)"
}
But, with the above, I figured out that it is not possible to play and record on multiple channels simultaneously. I do this by executing the following command in separate threads in a python script:
arecord -D plug:"+str(in_id)+" -c 1 -d "+str(duration)+" -f S16_LE -r "+str(rate)+" "+rec_filename
where `in_id` is the input channel variable that I pass to each of the threads.
More specifically, the `arecord` throws the error:
"ALSA lib pcm_dsnoop.c:606:(snd_pcm_dsnoop_open) unable to open slave
arecord: main:722: audio open error: Device or resource busy"
I tried to debug this by running `lsof /dev/snd/pcm*` right before I start recording using `arecord` in my record function in the program, I see the following:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
aplay 12236 user4 mem CHR 116,3 493 /dev/snd/pcmC1D0p
aplay 12236 user4 4u CHR 116,3 0t0 493 /dev/snd/pcmC1D0p
Then I came across the following two posts:
https://www.spinics.net/linux/fedora/alsa-user/msg14391.html
https://askubuntu.com/questions/27416/record-8-separate-line-in-channels-from-m-audio-delta-1010-card
The user in the first post seems to have solved by adding the following to his .asoundrc:
pcm.D44_cslave {
type dsnoop
ipc_key 223456
slave {
pcm "hw:0,0"
rate 48000
period_time 0 # in microseconds
buffer_size 256 # in bytes
period_size 64 # in bytes
channels 4
format S32_LE
}
bindings {
0 0
1 1
2 2
3 3
}
}
pcm.D44_ch12_capture {
type plug
ttable.0.0 1
ttable.1.1 1
slave.pcm D44_cslave
}
pcm.D44_ch34_capture {
type plug
ttable.0.2 1
ttable.1.3 1
slave.pcm D44_cslave
}
as mentioned in this message of the particular thread:
https://www.spinics.net/linux/fedora/alsa-user/msg14409.html
The second user on the other hand appears to have solved it by modifying his .asoundrc as follows:
pcm.capt {
type dsnoop
ipc_key 223456
slave {
pcm "hw:0,0"
rate 8000
period_time 0
period_size 320
channels 12
format S32_LE
}
}
pcm.c1 {
type plug
ttable.0.0 1
slave.pcm capt
}
pcm.c2 {
type plug
ttable.0.1 1
slave.pcm capt
}
pcm.c3 {
type plug
ttable.0.2 1
slave.pcm capt
}
pcm.c4 {
type plug
ttable.0.3 1
slave.pcm capt
}
pcm.c5 {
type plug
ttable.0.4 1
slave.pcm capt
}
pcm.c6 {
type plug
ttable.0.5 1
slave.pcm capt
}
pcm.c7 {
type plug
ttable.0.6 1
slave.pcm capt
}
pcm.c8 {
type plug
ttable.0.7 1
slave.pcm capt
}
Now, my questions are :
1. What could be the right configuration for me if I want to use the input and output channels exclusively for capture/record and playing respectively? Also, are my `arecord` and `aplay` commands fine?
2. If the error shows that dsnoop is indeed busy, then why was it not being shown in the output of `lsof /dev/snd/pcm*`. The error clearly says there is a definite problem with `dsnoop`, does that mean that it is not meant for simultaneous/multi-channel recording? I mean is there a conflict between `dsnoop` and `dshare` or if multiple instances of `dsnoop` is what is causing the problem?
It would be of great help if someone could educate me on the above and help me out with the configurations.
pcm.!default {
type plug
slave {
pcm "hw:1,0"
}
}
ctl.!default {
type hw
card 1
}
pcm_slave.m-audio_m-track_eight_1 {
pcm "hw:1,0"
channels 8
rate 44100
buffer_size 4096
period_size 1024
}
pcm.outch1 {
type dshare
ipc_key 1111
slave m-audio_m-track_eight_1
bindings [ 0 ]
hint.description "M-Audio M-Track Eight output/playback channel 1 (from output port 1)"
}
pcm.inch1 {
type dsnoop
ipc_key 2111
slave m-audio_m-track_eight_1
bindings [ 0 ]
hint.description "M-Audio M-Track Eight input/capture channel 1 (from input port 1)"
}
pcm.outch2 {
type dshare
ipc_key 1112
slave m-audio_m-track_eight_1
bindings [ 1 ]
hint.description "M-Audio M-Track Eight output/playback channel 2 (from output port 2)"
}
pcm.inch2 {
type dsnoop
ipc_key 2112
slave m-audio_m-track_eight_1
bindings [ 1 ]
hint.description "M-Audio M-Track Eight input/capture channel 2 (from input port 2)"
}
pcm.outch3 {
type dshare
ipc_key 1113
slave m-audio_m-track_eight_1
bindings [ 2 ]
hint.description "M-Audio M-Track Eight output/playback channel 3 (from output port 3)"
}
pcm.inch3 {
type dsnoop
ipc_key 2113
slave m-audio_m-track_eight_1
bindings [ 2 ]
hint.description "M-Audio M-Track Eight input/capture channel 3 (from input port 3)"
}
pcm.outch4 {
type dshare
ipc_key 1114
slave m-audio_m-track_eight_1
bindings [ 3 ]
hint.description "M-Audio M-Track Eight output/playback channel 4 (from output port 4)"
}
pcm.inch4 {
type dsnoop
ipc_key 2114
slave m-audio_m-track_eight_1
bindings [ 3 ]
hint.description "M-Audio M-Track Eight input/capture channel 4 (from input port 4)"
}
pcm.outch5 {
type dshare
ipc_key 1115
slave m-audio_m-track_eight_1
bindings [ 4 ]
hint.description "M-Audio M-Track Eight output/playback channel 5 (from output port 5)"
}
pcm.inch5 {
type dsnoop
ipc_key 2115
slave m-audio_m-track_eight_1
bindings [ 4 ]
hint.description "M-Audio M-Track Eight input/capture channel 5 (from input port 5)"
}
pcm.outch6 {
type dshare
ipc_key 1116
slave m-audio_m-track_eight_1
bindings [ 5 ]
hint.description "M-Audio M-Track Eight output/playback channel 6 (from output port 6)"
}
pcm.inch6 {
type dsnoop
ipc_key 2116
slave m-audio_m-track_eight_1
bindings [ 5 ]
hint.description "M-Audio M-Track Eight input/capture channel 6 (from input port 6)"
}
pcm.outch7 {
type dshare
ipc_key 1117
slave m-audio_m-track_eight_1
bindings [ 6 ]
hint.description "M-Audio M-Track Eight output/playback channel 7 (from output port 7)"
}
pcm.inch7 {
type dsnoop
ipc_key 2117
slave m-audio_m-track_eight_1
bindings [ 6 ]
hint.description "M-Audio M-Track Eight input/capture channel 7 (from input port 7)"
}
pcm.outch8 {
type dshare
ipc_key 1118
slave m-audio_m-track_eight_1
bindings [ 7 ]
hint.description "M-Audio M-Track Eight output/playback channel 8 (from output port 8)"
}
pcm.inch8 {
type dsnoop
ipc_key 2118
slave m-audio_m-track_eight_1
bindings [ 7 ]
hint.description "M-Audio M-Track Eight input/capture channel 8 (from input port 8)"
}
But, with the above, I figured out that it is not possible to play and record on multiple channels simultaneously. I do this by executing the following command in separate threads in a python script:
arecord -D plug:"+str(in_id)+" -c 1 -d "+str(duration)+" -f S16_LE -r "+str(rate)+" "+rec_filename
where `in_id` is the input channel variable that I pass to each of the threads.
More specifically, the `arecord` throws the error:
"ALSA lib pcm_dsnoop.c:606:(snd_pcm_dsnoop_open) unable to open slave
arecord: main:722: audio open error: Device or resource busy"
I tried to debug this by running `lsof /dev/snd/pcm*` right before I start recording using `arecord` in my record function in the program, I see the following:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
aplay 12236 user4 mem CHR 116,3 493 /dev/snd/pcmC1D0p
aplay 12236 user4 4u CHR 116,3 0t0 493 /dev/snd/pcmC1D0p
Then I came across the following two posts:
https://www.spinics.net/linux/fedora/alsa-user/msg14391.html
https://askubuntu.com/questions/27416/record-8-separate-line-in-channels-from-m-audio-delta-1010-card
The user in the first post seems to have solved by adding the following to his .asoundrc:
pcm.D44_cslave {
type dsnoop
ipc_key 223456
slave {
pcm "hw:0,0"
rate 48000
period_time 0 # in microseconds
buffer_size 256 # in bytes
period_size 64 # in bytes
channels 4
format S32_LE
}
bindings {
0 0
1 1
2 2
3 3
}
}
pcm.D44_ch12_capture {
type plug
ttable.0.0 1
ttable.1.1 1
slave.pcm D44_cslave
}
pcm.D44_ch34_capture {
type plug
ttable.0.2 1
ttable.1.3 1
slave.pcm D44_cslave
}
as mentioned in this message of the particular thread:
https://www.spinics.net/linux/fedora/alsa-user/msg14409.html
The second user on the other hand appears to have solved it by modifying his .asoundrc as follows:
pcm.capt {
type dsnoop
ipc_key 223456
slave {
pcm "hw:0,0"
rate 8000
period_time 0
period_size 320
channels 12
format S32_LE
}
}
pcm.c1 {
type plug
ttable.0.0 1
slave.pcm capt
}
pcm.c2 {
type plug
ttable.0.1 1
slave.pcm capt
}
pcm.c3 {
type plug
ttable.0.2 1
slave.pcm capt
}
pcm.c4 {
type plug
ttable.0.3 1
slave.pcm capt
}
pcm.c5 {
type plug
ttable.0.4 1
slave.pcm capt
}
pcm.c6 {
type plug
ttable.0.5 1
slave.pcm capt
}
pcm.c7 {
type plug
ttable.0.6 1
slave.pcm capt
}
pcm.c8 {
type plug
ttable.0.7 1
slave.pcm capt
}
Now, my questions are :
1. What could be the right configuration for me if I want to use the input and output channels exclusively for capture/record and playing respectively? Also, are my `arecord` and `aplay` commands fine?
2. If the error shows that dsnoop is indeed busy, then why was it not being shown in the output of `lsof /dev/snd/pcm*`. The error clearly says there is a definite problem with `dsnoop`, does that mean that it is not meant for simultaneous/multi-channel recording? I mean is there a conflict between `dsnoop` and `dshare` or if multiple instances of `dsnoop` is what is causing the problem?
It would be of great help if someone could educate me on the above and help me out with the configurations.