ecasound in MPD - problem of Device or resource busy

JMF11

Member
2013-12-22 6:40 pm
Hello,

I don't want to spoil Chalies ACD LADSPA plugins thread with my unrelated problems.

I try to encapsulate a working ecasound line command in MPD to stream my music. But playback fails with
Code:
ERROR:  Connecting chainsetup failed: "Enabling chainsetup: AUDIOIO-ALSA:
... Unable to open ALSA-device for playback; error: Device or resource busy"
in the ecasound part of the MPD logs.

The command encapsulated in MPD is
Code:
audio_output {
        type            "pipe"
        name            "DSP crossover"
        mixer_type      "software"
        format          "44100:16:2"
        command         "ecasound -d -z:mixmode,sum -B:rt -b:128 -i:stdin -f:16,2,44100 -o:alsa,hw:1,0 -d"
}

The same command in the shell (replacing stdin by a music file) works perfectly.

The same mpd.conf with only -o:alsa as output works and mpd streams music to my laptop speakers.

Googling, I found that it may be that another process has preempted the access to my sound devices. It is strange to ma as typing the command from the shell works, but...

Googling more, I tried to identify which processes could use the sound cards:
Code:
@ubuntu:~$ fuser -fv /dev/snd/* /dev/dsp*
                     UTIL.       PID ACCÈS  COMMANDE
/dev/snd/controlC0:  jmf        4009 F.... pulseaudio
/dev/snd/controlC1:  jmf        4009 F.... pulseaudio
/dev/snd/controlC2:  jmf        4009 F.... pulseaudio

I tried killall pulsaudio, but it started again... So I modified /etc/pulse/client.conf
Code:
; default-sink =
; default-source =
; default-server =
; default-dbus-server =

; autospawn = no
; daemon-binary = /usr/bin/pulseaudio
; extra-arguments = --log-target=syslog

; cookie-file =

; enable-shm = yes
; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB

; auto-connect-localhost = no

and then sudo killall pulseaudio

But there are still some pulsaudio processes that soon reappear using the soundcards
Code:
[email protected]:~$ ps -ef | grep pulseaudio
jmf       4009  2485  0 12:13 ?        00:00:00 /usr/bin/pulseaudio --start --log-target=syslog
jmf       4014  4009  0 12:13 ?        00:00:00 /usr/lib/pulseaudio/pulse/gconf-helper
jmf       5505  3155  0 12:38 pts/7    00:00:00 grep --color=auto pulseaudio

Last I tried
Code:
pasuspender -- sudo /usr/bin/mpd --stdout --no-daemon --verbose

But I then still have my MPD/ecasound failure: ... Unable to open ALSA-device for playback; error: Device or resource busy

I would be happy to getrid of all pulse audio processes to see if it is the reason or not of my problem...

The distribution is Ubuntu 14.04

Any help welcomed....

JMF
 

JMF11

Member
2013-12-22 6:40 pm
additional info:

A direct alsa conf to my hardware in mpd.conf works:
Code:
audio_output {
        type            "alsa"
        name            "My ALSA Device"
        device          "hw:1,0"        # optional
#       mixer_type      "hardware"      # optional
#       mixer_device    "default"       # optional
#       mixer_control   "PCM"           # optional
#       mixer_index     "0"             # optional
 

JMF11

Member
2013-12-22 6:40 pm
I took the afternoon to port all the setup to the OrangePi, on armbian.

It went not too bad. On armbian, there no pulseaudio... and MPD can drive the two soundcards/amplifiers without any issue.

It went almost straight forward on the Orange Pi (with the preparation and troubleshooting of issues on the laptop).

JMF
 
If your device is busy, the mentioned command will tell you the cuprit.

sudo lsof /dev/snd/*

Disabling pulseaudio in a regular desktop distribution is not straightforward, that daemon is rather resilient. But there are ways, e.g. the pasuspender which is reported to work ok (I have no personal experience with it as I use minimal pulseaudio-free distributions for embedded audio purposes).
 
additional info:

A direct alsa conf to my hardware in mpd.conf works:
Code:
audio_output {
        type            "alsa"
        name            "My ALSA Device"
        device          "hw:1,0"        # optional
#       mixer_type      "hardware"      # optional
#       mixer_device    "default"       # optional
#       mixer_control   "PCM"           # optional
#       mixer_index     "0"             # optional
Since the above works, I suggest you try using an ALSA loopback to connect MPD output to ecasound input.

First, you can temporarily add an ALSA loopback just by typing:
Code:
sudo modprobe snd-aloop
anytime at the command prompt. The loopback will exist until the next reboot.

Now run aplay -l. You should see the Loopback listed. Note the card number.

Change the MPD output (shown above in your post) to use that ALSA card as hardware output. Phoman will caution you that the card number may change and he is right in this case. But for testing purposes this is fine for now.

Now you have the input to the loopback, you can direct ecasound to read from the loopback by using the same card number as input. E.g.
Code:
ecasound -B:rt -b:1024 \
   -a:pre -f:16,2,44100 -i:alsahw,?,0 -pf:pre.ecp -o:loop,1 \
   -a:... etc.
Since I don't know the card number I just used a question mark in the example. Replace that with the actual card number.

Note that you need to tell ecasound what audio format to expect from alsa. It can't detect it on its own.

Does that work?
 
Last edited:
Also, here is the portion of my MPD config file where I set the output and set resampling to a fixed audio format using a high quality sinc resampling algorithm:

Code:
###############################################################################
#
#            ALL AUDIO RELATED SETTINGS ARE CONFIGURED BELOW
#
###############################################################################

audio_output {
	type		"alsa"
	name		"ALSA Output"
	device		"hw:0,0"	# ALSA output used
	format          "48000:16:2"     # audio specifier string; sample_rate:data_format:num_channels
	auto_resample   "no"            # disable alsa resampling
	auto_channels   "no"            # disable alsa from changing the number of channels
	auto_format     "no"            # disable alsa format conversions
	mixer_type      "software"	# optional
	always_on       "no"            # do not try to keep the output connected at all times
}

samplerate_converter	"0"	#Best Quality Sinc Interpolator

audio_buffer_size       "512"    #output buffer size in kB
 

JMF11

Member
2013-12-22 6:40 pm
Hello,

Thank to both of you to provide some information. Now the OrangePi (without pulse audio) delivers music !

I will concentrate now first on the audio part: make sure that all my filtering is as expected, delays on tweeters OK, that the final speakers response is as per specifications.

Then I will have a lot of tidy up and improvements: adjust the MPD/ecasound strams formats (32bits, upsampling if needed...), SOX for dithering, MPD that doesn't work as a daemon, tidy up all the configuration, write the Howto...

I may use your loopback principles for the piping to SOX. Using my virtual device grouping the 2xUSB amps had strange behaviours: sometime it was perfect, sometimes there was some strange digital distorsion. Starting again the track with the ecasound command line could solve or not... At the moment I stream directly to my 2 devices from ecasound chains.

Charlie, your advive to create a bash file to execute the ecasound command in MPD was really good. It does not modify the behaviour, but it is much more easy to manage !

Thanks ! It wouldn't have worked without your help !

This is a steep learning curve for me on at the same time Linux, alsa, ecasound, LADSPA, MPD, headless SBC, DSP...

Best regards,

JMF