9

I'm trying to record audio that is being played on separate channels using arecord. 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. But then, the following error is thrown:

ALSA lib pcm_dsnoop.c:606:(snd_pcm_dsnoop_open) unable to open slave
arecord: main:722: audio open error: Device or resource busy

When I run 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

My device definition for input channels in .asoundrc is as follows:

pcm.!default {
    type plug
    slave {
       pcm "hw:1,0"
    }
}

ctl.!default { 
    type hw
    card 1
}

pcm_slave.usb_audio_1 {
    pcm "hw:1,0"
    channels 8
    rate 44100
    buffer_size 4096
    period_size 1024
}

pcm.outch<num> {
    type dshare
    ipc_key <id>
    slave usb_audio_1
    bindings [ <ch_num> ]
    hint.description "USB output/playback channel <num> (from output port <num>)"
}

pcm.inch<num> {
    type dsnoop
    ipc_key <id>
    slave usb_audio_1
    bindings [ <ch_num> ]
    hint.description "USB input/capture channel <num> (from input port <num>)"
}

where <num> takes all values between 1 and 8 and <ch_num> takes all values between 0 and 7.

Since, 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 dsnoop can record/capture from only one channel at a time? Is there another way I can achieve this?

10
  • Does a single such arecord call work on the command line?
    – CL.
    Commented Apr 27, 2017 at 6:42
  • Yes, single arecord call works fine. I can combine arecord with aplay on pipes as well. Commented Apr 27, 2017 at 6:44
  • Does the first arecord call from Python work?
    – CL.
    Commented Apr 27, 2017 at 6:45
  • The very first call itself the above error is observed. I mean at the very instant when those threads are created for recording. Commented Apr 27, 2017 at 6:51
  • 1
    What are the ipc_key values?
    – CL.
    Commented Apr 28, 2017 at 8:58

2 Answers 2

5

The ipc_key is used for communication between the programs that share the same device. This means that you have to use different values for different hardware devices, but that all virtual devices that access the same hardware device (i.e., the same slave usb_audio_1) must use the same ID.

1
  • 1
    Not even in my wildest dreams I had suspected ipc_key to be the cause of this! Obviously, my understanding was flawed. Thanks a lot @CL. for clearing it. Just out of curiosity, in my case, can I put the ipc_key in some other container definition block in order to avoid such mistakes. I mean it is only logical to have a master block in the hierarchy with a common field like ipc_key right? Commented Apr 28, 2017 at 13:14
0

In my case, the device is being blocked for arecord usage if I have VLC open (even if idle and with empty playlist).

Similarly, it is also blocked if I only have the (top-right corner-menu) settings open – presumably because of its sound / mic-test panel.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .