10

I'd like my RasPi to send audio to my on board audio out port, and also to my Digital out card (an I2S Hifiberry Digi). This ought to be possible with ALSA. I have the drivers loaded and can send to both sound devices individually, but combining them just isn't working. There are several posts out there explaining how to do this, but I can't get my config to work.

The error from aplay:

Playing WAVE 'sin1000_48khz.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
ALSA lib pcm_params.c:2162:(snd1_pcm_hw_refine_slave) Slave PCM not usable
aplay: set_params:1059: Broken configuration for this PCM: no configurations available

Output of "aplay -l"

**** List of PLAYBACK Hardware Devices ****
card 0: sndrpihifiberry [snd_rpi_hifiberry_digi], device 0: HifiBerry Digi HiFi wm8804-spdif-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 1: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Output of "aplay -L"

null
   Discard all samples (playback) or generate zero samples (capture)
sysdefault:CARD=sndrpihifiberry
    snd_rpi_hifiberry_digi,
    Default Audio Device
sysdefault:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device`

Contents of /etc/asound.conf

pcm.both {
    type route
    slave.pcm {
        type multi    
        slaves.a.pcm "hw:0,0"
        slaves.b.pcm "hw:1,0"
        slaves.a.channels 2
        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
    }

    ttable.0.0 1
    ttable.1.1 1

    ttable.0.2 1
    ttable.1.3 1
}

ctl.both {
    type hw
    card sndrpihifiberry
    device 0
}

pcm.hifiberry {
    type hw    
    card sndrpihifiberry
    device 0
}

ctl.hifiberry {
    type hw
    card sndrpihifiberry
    device 0
}

pcm.audioout {
    type hw
    card ALSA
    device 0
}

ctl.audioout {
    type hw
    card ALSA
    device 0
}

pcm.!default {
    type plug
    slave {
        pcm both
    }
}

#pcm.!default {    
#    type hw
#    card sndrpihifiberry
#    device 0
#}

ctl.!default {
    type hw
    card sndrpihifiberry
    device 0
}
  • I think you should look into pulseaudio. But I might be wrong here – Gerben May 2 '14 at 18:49
  • 3
    I have looked into pulseaudio. My experience was that it basically didn't work. – Christi May 2 '14 at 18:50
  • After further investigation (and a second attempt with pulseaudio), I think that the problem is that this kind of feature requires shared access to the sound card memory and/or mmap support. The RasPi I2S driver doesn't support this. I can't really confirm this, as there is no particularly useful debugging info either from ALSA or PulseAudio - in general, everything works until you try to engage multiple sound sources. I am uncertain whether this will be fixed in the RasPi kernels or not, but trying to fix it would time more time than I'm willing to invest. – Christi May 7 '14 at 12:46
  • I can only suggest trying to get pulseaudio working, as it is capable of doing exactly what you wish to do (including extending to other soundcards on the network). – earthmeLon May 17 '14 at 16:32
  • As I mentioned above, I did get Pulseaudio working. It works fine on each individual device, and then fails when you attempt to create a stream to multiple outputs at once. I believe a lack of memory mapping in the RasPi I2S driver to be the culprit, but further debugging would essentially involve learning the internal structure of ALSA and/or Pulseaudio, which I do not have the time or inclination to do. – Christi May 17 '14 at 20:17
1

It's a bit hacky but have you considered the tee command? Read more on StackExchange on tee re-direction and see Wiki's artical for more examples. I'm thinking that if you have a command that outputs the file name or link to media content, ls perhaps, and use tee to call commands to your prefered media player. Here's how I would script around the problem...


#!/bin/bash
MediaPlayer="$1"
MediaOptions1="$2"
MediaOptions2="$3"
InputParcer="ls $4"
${InputParcer} | tee >(${MediaPlayer} ${MediaOptions1}) >(${MediaPlayer} ${MediaOptions2}) || echo 'Exiting baddly'

Notes:

The above could be hard coded to have sertain options for each out-put forking and the InputParcer variable should be edited if you plan on submitting a directory or web link that contains more than one media file. But one file at a time this should output to both if the MediaOptions1/2 are either hard coded or set on each run. It's a bit hacky, you've been warned.

... after testing and such I'd then likely toss in if [ ${#} < 4]; then echo "error"; fi near the top; editing the 4 for how many arguments I've felt needs to be there. Running as is it would be bash scripted_dule_player 'aplay <common_options>' '<options_output1>' '<options_output2>' '</full/file/path/to/mediafile>' be sure to modify for your system the options and file paths you wished run; the stuff between <>.

Issues with using tee are that it is not very portible between flavors of Linux and it may cause issues with audio not playing in sync between outputs. Instead I would suggest using omxplayer -o both for outputting sound to two seperate devices, but as this has only been tested on an RPi that has HDMI & Audio out plugged in, not quite the setup used by the OP and the OP requested something for alsa.

There is also a nice blog on the subject of alsa multi sound card multi user configurations you may wish to look through; perhaps you've a error in yours that'll make my above code block a moot point; just note that the guide there was geared towards Slaker flavored Linux not Raspbian.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.