4

I use mpd to stream music to my phone (connected to Hi-Fi) via http.

Yet, this only works for songs in my mpd database. I oftentimes want to play stuff in my browser and would like that to be streamed over mpd, too.

Is there a way to route the pulse audio output to mpd instead of the speakers?

5

mpd doesn't accept pulseaudio input sources, so there is no direct way to route pulseaudio through mpd.

However, what you want to accomplish is still possible, with the help of gstreamer and some cleverness. I accomplished this a few years ago.

I wrote this program which implements the "Gstreamer Pipeline Script" component of this diagram:

stream diagram http://tiyukquellmalz.org/sean/stream.svg

To sum up the diagram, here is what happens:

  • mpd reads music files off of the disk, decodes them, and "plays" them to a module-null-sink type audio output of pulseaudio.
  • Any other programs you want to run on your computer that output sound -- Adobe Flash, beeps from the gnome shell, the web browser, etc. also send their audio output to the module-null-sink of pulseaudio (it's made the default audio device of the system).
  • The module-null-sink output has a .monitor source, which lets you take the audio that's pushed out to a null sink and "capture" it back in as if it were an input device (like a microphone).
  • Pulseaudio performs software mixing on the fly of all the audio programs on the entire computer, including mpd, web browsers, and everything else using pulseaudio.
  • The tribblify program that I wrote uses GStreamer to capture the pulseaudio null sink monitor audio, which contains mixed audio of both mpd as well as any other programs on the system; perform MP3 encoding; then stream it to a shoutcast / icecast server. tribblify essentially becomes a "streaming source".
  • The tribblify program automatically detects when mpd changes tags of the playing audio and pushes those tags down the shoutcast stream.
  • The icecast or shoutcast server, which can be on the same computer or a different one, streams out the results to all the connected clients.
  • That’s an epic setup. I don’t need to stream my system sounds anymore, but I’m sure this is going to help lots of people. – Profpatsch Jan 14 '14 at 21:07
0

yes - the key here is the ALSA loopback capabilities. so first you need to enable loopback device in ALSA, which will appear in the PulseAudio Volume Control as an input device (and an output device as well).

sudo modprobe snd_aloop

this device then can be added to an mpd server:

mpc add alsa://hw:1,1

where hw:1,1 is the loopback input device can be listed with the command aplay -l

then you need to configure a http output plugin for the mpd. the following example would look like in /etc/mpd.conf

 audio_output {
    type            "httpd"
    name            "My HTTP Stream"
    encoder         "vorbis"          # optional, vorbis or lame
    port            "8000"
    bind_to_address "192.168.1.38"               # optional, IPv4 or IPv6
    quality         "5.0"                   # do not define if bitrate is d$
#   bitrate         "128"                   # do not define if quality is d$
    format          "44100:16:1"
    max_clients     "0"                     # optional 0=no limit
 }  

that is it. Select the looback device for your audio source in Volume Control Playback tab.
Finally, you can use VLC or any other stream renderer at the destination point using the httpd url address: http://192.168.1.38:8000

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.