You are not logged in.

#1 2013-12-13 06:42:29

ramboman
Member
Registered: 2010-01-23
Posts: 35

How to process the audio from mpd before it is streamed

I have no trouble to stream music from mpd without processing:
e.g.:
~/mpd/config:

audio_output {    
	type		"httpd"    
	name		"My HTTP Stream"
	encoder		"lame"		# optional, vorbis or lame
	port		"8000"

	bitrate		"128"			# do not define if quality is defined
	format		"44100:16:1"
}

When I have to process the audio before it is streamed, I have almost no idea on how to proceed.
The closest thing I have done after some research is to use a pipe:

e.g. that does not work very well:
~/mpd/config:

audio_output {
	type		"pipe"
	name		"my pipe"
	command		"lame -S -r -x -s 44100 -b 128 - | sox -q -t mp3 - -t alsa default"
}

I tried to pipe the raw audio from mpd to lame so it can be encoded and then be processed by sox, but the result is a slow audio with a lot of noise.

I have a few question regarding this problem:
1) What is the best way to process the output of an audio player and stream it?
[bonus] 2) Is there anyway to do the processing live and/or interactively (a bit like a DJ)?

Offline

#2 2013-12-13 08:04:02

ondoho
Member
Registered: 2013-04-30
Posts: 319

Re: How to process the audio from mpd before it is streamed

thoughts:

wouldn't sox be able to stream that for you after processing?

there's another audio output type "recorder", maybe that works better than "pipe"
for me type "fifo" has worked well for various (but not exactly yours) purposes.

obvious question - what exactly are you trying to achieve, maybe it can be solved differently.

esp. with regard to [bonus] i'd say, this is coming close to a linux studio, for which installing jack audio is the way to go.

Last edited by ondoho (2013-12-13 08:04:54)

Offline

#3 2013-12-14 09:55:26

ramboman
Member
Registered: 2010-01-23
Posts: 35

Re: How to process the audio from mpd before it is streamed

ondoho wrote:

wouldn't sox be able to stream that for you after processing?

I don't think so. Pardon me if I am wrong but sox is only a sound processor and it can't send music data to the network without the help of some other command like netcat.

ondoho wrote:

there's another audio output type "recorder"

In the mpd documentation, it is written that ther "recorder" plugin writes the audio played by MPD to a file, which is different from the "fifo". The file will grow has long as the music plays which is not what I am looking for.

ondoho wrote:

for me type "fifo" has worked well for various (but not exactly yours) purposes.

This is quite similar as the "pipe" plugin. To reproduce the same thing as what I have done with the pipe I can do this:

Working solution 1:
~/.mpd/config:

...
audio_output {
  type    "fifo"
  name    "my_fifo"
  path    "/tmp/mpd.fifo"
  format  "44100:16:2"
}
...

stream.sh:

#!/bin/sh
sox --buffer 32 -t raw -b 16 -e signed -c 2 -r 44100 /tmp/mpd.fifo -t wav - \
		equalizer 33 1.5 4.5 \
		equalizer 66 1.5 3.75 \
		equalizer 132 1.5 -1.5 \
		equalizer 264 1.5 -4.5 \
		equalizer 528 1.5 -3.57 \
		equalizer 1056 1.5 -1.5 \
		equalizer 2112 1.5 1.5 \
		equalizer 4224 1.5 4.5 \
		equalizer 8448 1.5 4.5 \
		equalizer 16896 1.5 4.5 \
	| oggenc - \
	| oggfwd localhost 8000 source_password /stream.ogg

This method works but there are several strong and weak points:
Advantages:

  • Lightweight script ideal for final setup.

Disadvantages:

  • Knowing no other commandline streaming method to icecast other than oggfwd, I can only stream in ogg format.

  • The equalizer cannot be changed live.

  • There are no metadata (song names, band, album etc.) transfered from mpd to icecast.

  • When I stop mpd for several second before playing an other song the script exits with the exit code 141.

ondoho wrote:

obvious question - what exactly are you trying to achieve, maybe it can be solved differently.

I would like to have a flexible way to process the sound_data coming from the Music_server to the Stream_Server so that the Stream_Server can output my processed sound_data and the metadata coming with it.
The image below describs a general setup I am trying to do:
7BHeHKG.png

The general setup, when translated to my specific "Working Solution 1" mentioned earlier, looks like this:
Music_Server = MPD
Sound_Data1 = /tmp/mpd.fifo
Sound_Processor =

sox --buffer 32 -t raw -b 16 -e signed -c 2 -r 44100 /tmp/mpd.fifo -t wav - \
		equalizer 33 1.5 4.5 \
		equalizer 66 1.5 3.75 \
		equalizer 132 1.5 -1.5 \
		equalizer 264 1.5 -4.5 \
		equalizer 528 1.5 -3.57 \
		equalizer 1056 1.5 -1.5 \
		equalizer 2112 1.5 1.5 \
		equalizer 4224 1.5 4.5 \
		equalizer 8448 1.5 4.5 \
		equalizer 16896 1.5 4.5 \
	| oggenc - ...

Sound_Data2 = ogg formated sound data piped to "oggfwd localhost 8000 hackme /stream.ogg"
Streaming_Server = icecast
Metadata = ?? No way to transfer the metadata yet ??

ondoho wrote:

esp. with regard to [bonus] i'd say, this is coming close to a linux studio, for which installing jack audio is the way to go.

I am going to take a look at jack audio.

There are still several problems pending:

  • Is there an oggfwd that can transfer an other format than ogg e.g. mp3?

  • Is there an interactive sound processor (e.g. equalizer) that I can put in between for example MPD and icecast to process the sound before it is sent to the net?

  • How can I read the metadata from MPD server and send it manually to Icecast?

Last edited by ramboman (2013-12-14 10:27:29)

Offline

#4 2013-12-14 11:48:51

ondoho
Member
Registered: 2013-04-30
Posts: 319

Re: How to process the audio from mpd before it is streamed

preserving metadata is a problem, i can see that.
there's various ways to have an equalizer with mpd, before starting to mess around with jack, have a look at this or this or this.

When I stop mpd for several second before playing an other song the script exits with the exit code 141.

well you shouldn't do that when streaming, no?

apart from that, what's wrong with .ogg?

but i say it again, if you're planning to build up some sort of live radio studio, you'll want jack.

Offline

Board footer

Powered by FluxBB