stmllr.net

Live mp3 streaming from audio-in with DarkIce and Icecast2 on Raspberry Pi

by on stmllr.net

As a response to my lastest article about Streaming audio with MPD and Icecast2 on Raspberry Pi, I was asked for some ideas about live streaming. I took the chance to plug in an usb audio device with microphone to RasPi and tried to get it working.

Update (2012/08/11): Added a step to update package version number and added "devscripts" to the list of suggested packages .

What you need to have

  • Raspberry Pi with Raspbian installed,
  • USB sound stick with an input device,
  • DarkIce to capture audio from the audio input and send it to Icecast2,
  • Icecast2 to distribute the audio stream.

Compiling and installing DarkIce

The default darkice package comes without mp3 support. Since mp3 is the most widespread codec, I decided to build my own package of darkice with mp3 support.

Add a deb-src repository to your sources list at /etc/apt/sources.list:

$ sudo sh -c "echo 'deb-src http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi' >> /etc/apt/sources.list"
$ sudo apt-get update
(...)

To fullfill the build dependencies, you have to install some additional packages:

$ sudo apt-get --no-install-recommends install build-essential devscripts autotools-dev fakeroot dpkg-dev debhelper autotools-dev dh-make quilt ccache libsamplerate0-dev libpulse-dev libaudio-dev lame libjack-jackd2-dev libasound2-dev libtwolame-dev libfaad-dev libflac-dev libmp4v2-dev libshout3-dev libmp3lame-dev
(...)

(Not sure if you need all these packages. But it won't hurt.)

Create a working directory:

$ mkdir src && cd src/

Get the source package of darkice:

$ apt-get source darkice
(...)

Change the compile configuration to match Raspbian environment:

$ cd darkice-1.0/
$ vi debian/rules

 

#!/usr/bin/make -f

%:
dh $@

.PHONY: override_dh_auto_configure
override_dh_auto_configure:
ln -s /usr/share/misc/config.guess .
ln -s /usr/share/misc/config.sub .
dh_auto_configure -- --prefix=/usr --sysconfdir=/usr/share/doc/darkice/examples --with-vorbis-prefix=/usr/lib/arm-linux-gnueabihf/ --with-jack-prefix=/usr/lib/arm-linux-gnueabihf/ --with-alsa-prefix=/usr/lib/arm-linux-gnueabihf/ --with-faac-prefix=/usr/lib/arm-linux-gnueabihf/ --with-aacplus-prefix=/usr/lib/arm-linux-gnueabihf/ --with-samplerate-prefix=/usr/lib/arm-linux-gnueabihf/ --with-lame-prefix=/usr/lib/arm-linux-gnueabihf/ CFLAGS='-march=armv6 -mfpu=vfp -mfloat-abi=hard'

Please consider to download the rules file from here instead of copy&paste the lines above. The build will fail if line beginnings contains spaces instead of tabs.

Before you start to build the package, change the version of the package to reflect mp3 support. debchange will ask you to add some comments to the changelog.

$ debchange -v 1.0-999~mp3+1

darkice (1.0-999~mp3+1) UNRELEASED; urgency=low

  * New build with mp3 support

 --  <pi@raspberrypi>  Sat, 11 Aug 2012 13:35:06 +0000

Build and install the darkice package:

$ dpkg-buildpackage -rfakeroot -uc -b
(...)
$ sudo dpkg -i ../darkice_1.0-999~mp3+1_armhf.deb
(...)
Preparing to replace darkice 1.0-999 (using .../darkice_1.0-999~mp3+1_armhf.deb) ...
Unpacking replacement darkice ...
Setting up darkice (1.0-999~mp3+1) ...
(...)

Now you have installed DarkIce with mp3 support.

Configuring DarkIce

Add a configuration by copying the template file:

$ sudo cp /usr/share/doc/darkice/examples/darkice.cfg /etc/

Here's an example configuration to have:

  • read input from an usb device using the alsa audio device hw1,0
  • stream mp3 output to an icecast2 server
# see the darkice.cfg man page for details

# this section describes general aspects of the live streaming session
[general]
duration      = 0                # duration of encoding, in seconds. 0 means forever
bufferSecs    = 5                # size of internal slip buffer, in seconds
reconnect     = yes              # reconnect to the server(s) if disconnected

# this section describes the audio input that will be streamed
[input]
device        = hw:1,0           # Alsa soundcard device for the audio input
sampleRate    = 44100            # sample rate in Hz. try 11025, 22050 or 44100
bitsPerSample = 16               # bits per sample. try 16
channel       = 1                # channels. 1 = mono, 2 = stereo

# this section describes a streaming connection to an IceCast2 server
# there may be up to 8 of these sections, named [icecast2-0] ... [icecast2-7]
# these can be mixed with [icecast-x] and [shoutcast-x] sections
[icecast2-0]
bitrateMode   = vbr              # variable bit rate
format        = mp3              # format of the stream: mp3
quality       = 0.6              # quality of the stream sent to the server
server        = localhost        # host name of the server
port          = 8000             # port of the IceCast2 server, usually 8000
password      = SOURCE_PASSWORD  # source password to the IceCast2 server
mountPoint    = raspi         # mount point of this stream on the IceCast2 server
name          = RasPi            # name of the stream
description   = DarkIce on RasPi # description of the stream
url           = http://localhost # URL related to the stream
genre         = my genre         # genre of the stream
public        = no               # advertise this stream?
localDumpFile = recording.mp3    # Record also to a file

This is just an example and neither optimized nor secure! Learn more about darkice in the documentation section below /usr/share/doc/darkice/. The configuration options are explained in the manpage:

$ man darkice.cfg

Btw., to find your alsa input devices, ask arecord:

$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: U0x46d0x825 [USB Device 0x46d:0x825], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

This particular input device is the microphone of a Logitech H270 webcam. It can be addressed using hw:1,0 (Card 1, Subdevice 0).

Keep in mind that Raspberry Pi has no input audio devices on board. You have to plug additional soundcard hardware to usb.

Installing Icecast2

If you don't have an icecast2 server running somewhere, you could set one up on RasPi.

$ sudo aptitude install icecast2

The package manager will ask you to configure Icecast2. You should do so and set a hostname and passwords for source, relay and administration. Needless to say to use strong passwords. The source password will be needed in the darkice.cfg configuration. (See SOURCE_PASSWORD in the above example)

Running DarkIce to stream audio

$ darkice
(...)
Using config file: /etc/darkice.cfg
Using ALSA DSP input device: hw:1,0
Could not set POSIX real-time scheduling, this may cause recording skips.
Try to run darkice as the super-user.

When you run into the following "sink error" message, check if icecast is running and passwords are matching:

DarkIce: LameLibEncoder.cpp:75: lame lib opening underlying sink error [0]

Now grab your favorite instrument and start a live jam. To listen to it, open your browser, navigate to the Raspberry Pi host at http://your.raspberry.hostname:8000/raspi and hook up into the stream with your favorite player.

Performance

I have done some very basic measurements. With the above configurations, the CPU load is about 50%. Very nice!

Did this article help you? Spread the word!

If you liked this article, please share it in your preferred social media circles (twitter, g+, facebook, etc.)

Credits

Thanks to Patrick Adams for inspiration. Looking forward for a turntable session to listen to ;-)

Related articles

Tags

Comments

  1. tobie

    hi, could I ask about audio input quality?

    I'm using arecord to get audio in from a usb device at plughw:1,0, but sound quality is not good.

    Are you getting good quality sound input? Are you using a USB hub?

  2. Steffen

    Hi tobie,

    I have a clear signal with my device. Whatever "clear" means to the microphone of my Logitech H270 webcam ;-)
    The device is connected directly to one of the USB ports.

    Just a wild guess: the reason for your problem could be the samplerate.

    Try to find out which samplerate your device supports and then set ALSA accordingly.
    I had similar problems on a Seagate Dockstar with C-Media Audio USB Adapter. I fixed it by adding the following settings to /etc/asound.conf:

    pcm.rate_convert {
    	type plug
    	slave {
    		pcm "hw:1,0"
    		rate 48000
    	}
    }

    See opensrc docs: http://alsa.opensrc.org/.asoundrc#Converting_Sample_Rates_On_Input
    and also the official alsa docs: http://www.alsa-project.org/main/index.php/Asoundrc

  3. Ben

    Hi,

    How much delay is there in the recording (provided the pi and the listening device are on the same network)?
    I tried both RTP and HTTP Streaming successfully but with ~15s delay (no buffering used) and 30% CPU.


  4. Steffen

    Hi Ben,

    mainly you have two buffers which need to get filled:

    1) Darkice buffer, configured with "bufferSecs" (5 seconds in my example cfg)
    2) Icecast2 buffer aka "queue-size" and eventually "burst-size>", which need some time to get filled.

    Not sure about how much delay is caused by resampling, but mpeg is not designed for low latency transport/transition. Maybe aac or ogg perform better here. I would be glad if you'd try and report back here.

    If you have both Darkice and icecast2 on one host, you can reduce the Darkice buffer. not sure if 0 is a good choice, but you could also try and frankly report here.
    However, if you want to provide a stable stream for clients on the network, you should not turn off icecast2 buffers completely.

  5. Ben

    Thanks for documenting this!

    What was the latency you experienced when listening on the same network? By latency, i mean the time between the moment a sound is recorded and the moment it is received on the remote device.

    Fyi, the best I have managed is ~15s. Not really real time...

  6. Steffen

    I have experienced approx. the same 15 seconds.

    If you like to nail down the root of your latency, you could sniff the network traffic e.g. with wireshark. Then you should roughly see how much time goes by until darkice starts streaming to icecast.

    Latency is nothing unusual for consumer (aka "mp3") audio streams in the internet.

  7. Seva

    Have you done any load testing with actual users connected? I wonder how many listeners the RPi could handle..

  8. Steffen

    Though I haven't tested this, I guess the network would be the bottleneck.

    RPi has only a network capacity of 100MBit/s, which theoretically means approx. 800 concurrent listeners with a 128k stream. This does not consider any overhead caused by network protocols and the ones.

    If you like to test this, have a look at this article, including a basic test script: http://www.icecast.org/loadtest1.php

  9. J@y

    I love this tutorial it was exactly what i needed. But I'm just getting static noise when its recording from mic and nothing else.

  10. J@y

    by the way this is what my asound.conf looks like - not sure what most of it means tho:

    pcm.mmap0 {
    type mmap_emul;
    slave {
    pcm "hw:0,0";
    }
    }

    pcm.!default {
    type plug;
    slave {
    pcm mmap0;
    }
    }

  11. Guilherme Rambo

    My sound is sort of chunky, here's a sample: http://cl.ly/0y0n3y2q1g04 (the static noise is on purpose, notice it clips a few times every second).

    I've tried sample rates 44100, 48000 and 22050. 48000 seems to yield the best result, but still has that clipping.

    Also tried that asound.conf stuff. Tried different bufferSecs like 5, 10, 15... but no luck...

    I'm using a Behringer UCA200.

    Any thoughts?

  12. Steffen

    J@y and Guilherme Rambo,

    please have a look at the ALSA docs, I referred to at http://www.t3node.com/blog/live-streaming-mp3-audio-with-darkice-and-icecast2-on-raspberry-pi/#comment-2

    You could also get in touch with the ALSA community via Mailinglists, Newsgroups etc. I am not really experienced with ALSA and can't help you out.

  13. Casey

    Thank you so much for this guide. My only problem is that darkice seems to crash after a while, still figuring that part out though.

    My question is how to add this to the boot initialization. I went through a couple forums and blogs on adding items to startup but my linux just isn't strong enough to pull out the pertinent information. If you can assist in instructions to start darkice after bootup that would be amazing.

    Thank you!

  14. Casey

    Thank you so much for this guide. My only problem is that darkice seems to crash after a while, still figuring that part out though.

    My question is how to add this to the boot initialization. I went through a couple forums and blogs on adding items to startup but my linux just isn't strong enough to pull out the pertinent information. If you can assist in instructions to start darkice after bootup that would be amazing.

    Thank you!

  15. Casey

    Sorry for double post, was having trouble with captcha

  16. Steffen

    Hi Casey,

    you probably need a bootscript and add that to your rc. Find a howto at http://www.debian-administration.org/articles/28

  17. Pedro

    Hi, great tutorial.

    I'm getting the right message from darkice as you can see below.
    However at the icecast level, after opening the URL ao don't hear anything. Its necessary to use arecord?

    I want to stream audio directly from my webcam. I tested with aplay and is working fine.

    Help me please.

    BR,
    Pedro Guerreiro



    pedro@raspberrypi ~ $ sudo darkice
    [sudo] password for pedro:
    DarkIce 1.0 live audio streamer, http://code.google.com/p/darkice/
    Copyright (c) 2000-2007, Tyrell Hungary, http://tyrell.hu/
    Copyright (c) 2008-2010, Akos Maroy and Rafael Diniz
    This is free software, and you are welcome to redistribute it
    under the terms of The GNU General Public License version 3 or
    any later version.

    Using config file: /etc/darkice.cfg
    Using ALSA DSP input device: plughw:1,0
    Using POSIX real-time scheduling, priority 98

  18. Steffen

    Hi Pedro,

    using arecord is not necessary here. Darkice directly fetches the input signal and streams it to icecast2.

    Can you see your stream in icecast2 when you open http://your.raspberry.hostname:8000/raspi in your browser? (as shown in the article screenshot above)

    If so, then make sure, you have configured the correct device in darkice.cfg as given from arecord -l

    [input]
    device = hw:1,0

    Maybe you setting hw:1,0 instead of plughw:1,0 helps.

    If your stream is not shown up in icecast2 at all, then check if mountpoint, password and url in the darkice AND icecast2 configuration match.
    icecast2 configuration can be found in /etc/icecast2/icecast.xml
    Also have a look at the log from icecast2. could be that the logging needs to be turned on first. This is also configured in the config file mentioned above.

  19. Axel

    Hi Steffen,

    thanks for publishing this HowTo. Almost everyone should be able to follow the instructions on this page.

    I wanted to stream music - especially my CD collection - from my raspberry to my local network without first converting the CD's to MP3 files. I have a Sonos network and a NOXON radio which work well with this solution.

    For me this is the perfect solution:

    audio CD - Player is connected to a behringer_ufo_202 audio interface which is connected to my raspberry. At first I tried to use a cheap usb-soundcard which was mono and has a very bad sampling quality. After connecting the Behringer Interface, I had a clear sound sampling. Any other good interface will do the same I think. For Vinyl samplings this one has a audio pre amplifier built in. Do not waste time with poor audio equipment. I will test audio quality with a 96 Khz sampling rate soon.

    One word to the configuration: You should set

    pcm.rate_convert {
    type plug
    slave {
    pcm "hw:1,0"
    rate 48000
    }
    }

    So now I can automatically stream every sound input to my network and connect any streaming client to the raspberry Icecast server.

  20. teratech

    Hi Steffen,

    What a great tutorial! I have been running Darkice on Single Board Computer and now want to try the same on a Rasp Pi. After following your tutorial, I get the following information when trying to start Darkice on the Rasp Pi;


    Using config file: /etc/darkice.cfg
    Using ALSA DSP input device: hw:1,0
    Using POSIX real-time scheduling, priority 98
    DarkIce: TcpSocket.cpp:251: connect error [111]

    Can you suggest what I am missing?

    If you need more information like the config file, then let me know.

    Thanks!

    teratech

  21. Steffen

    Hi teratech,

    seems like Darkice is not able to connect with your Icecast2 server. Check server and port settings in the [icecast2-0] section of the Darkice config file.

    And also test if icecast2 is running and accepting incoming TCP connections on the specified host address/port.

    $ sudo netstat -ltpn | grep icecast2
    
    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    tcp 0 0 xx.xx.xx.xx:8000 0.0.0.0:* LISTEN 1751/icecast2

  22. teratech

    Hey Steffen,
    Thanks for the quick reply. I tried to run the netstat command but nothing came back. Then it struck me that your instruction were to install both Darkice and Icecast on a Rasp Pi. When using the SBC I also had an external server running Icecast2. I am using the same configuration information to point Darkice on the Rasp Pi to the external server. I am using the same server, port, password and mountPoint as I used on the SBC which connects to the Icecast server without an issue. Is there another way to check the Rasp Pi connectivity to the remote server? Am I catching all the important network configuration information with server, port, password and mountPoint data?

    Here is the config file data for server connection:


    bitrateMode = abr # average bit rate
    format = mp3 # format of the stream: mp3
    bitrate = 128 # bitrate of the stream sent to the server
    server = 66.55.xxx.xx # host name of the server
    port = 80xx # port of the IceCast2 server, usually 8000
    password = xxxxxxxx # source password to the IceCast2 server
    mountPoint = live # mount point of this stream on the IceCast2 server

    I deeply appreciate your assistance! teratech

  23. teratech

    Hey Steffen,

    I figured what the problem was. I needed to comment out the additional options in the config file that were below the Icecast2 examples. I am referring to the shoutcast and Icecast parts of the example config file. So Darkice is working on the Rasp Pi for me now. Thanks again for your help and tutorial! teratech

  24. Naomi Most

    Thanks for this guide, definitely saved me a ton of time.

    I just wanted to comment that the single snafu I ran into was in creating the debian/rules file.

    If you copy and paste the provided code into the file, there's the danger of the tabs being converted into spaces, which results in a "missing separator" error when you go to compile the source, which will probably look like this:

    debian/rules:4: *** missing separator. Stop.

    To remedy, you just need to delete all spaces at the beginning of lines, but make sure there is a single tab at the front of every line that follows a colon.

    I'm mentioning this so that this page will be searchable for that error and so people will know how to deal with it. :)

    Cheers and thanks again.

  25. squiregeek

    I've been trying to install icecast2 to no avail. I've used sudo apt-get install icecast2 and sudo install aptitude icecast2 and they both return no packages. I'm running raspbian wheezy. Has something changed?

  26. Steffen

    Hi squiregeek,

    can you post the content of your file /etc/apt/sources.list please?

    Alternatively download the package from here: http://archive.raspbian.org/raspbian/pool/main/i/icecast2/

    Drawback: Then you will not receive updates.

  27. squiregeek

    The sources.list is: deb-src http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi

    I haven't changed it since install.

    I found a deb at the German Debian site, but it failed to install with no useful messages.

    Thanks for the quick response. I'll try the download you've pointed out and see how it goes.

  28. squiregeek

    Son of a gun, it installed. Now I have a project to use up the rest of my day!

    Thanks for the help, and for showing the way to doing some streaming with this remarkable little machine.

  29. Andrew

    Is there a way this could be configured to take an analogue audio in through the 3.5mm jack on the Pi?

    I'm wondering if I can set up an R-Pi attached to an audio source (e.g. Radio) and then be able to listen to that audio feed over the net?

  30. Steffen

    Andrew,

    the 3,5mm jack onboard the Pi only is audio out.
    You need an additional, external USB sound device for audio-in.

  31. Tyler

    Thanks for the tutorial! So far seems good, got Icecast2 and darkice running. However, there doesn't seem to be any audio from the microphone.

    I am using an XLR to USB cable so I have a feeling that it isn't amplifying the sound from the mic enough. When I tap the mic I can hear faint clicks in the stream.

    I have turned everything up in the alsamixer so I have a feeling I just need a different type of input device. Can anyone give me a suggestion on what devices they are connecting to RPi for audio input?

    Thanks!

  32. iffe

    Thanks for detailed info! Much appreciated.

  33. Steffen

    Tyler, try a preamplifier

  34. Arnold

    Steffen,
    Thanks for your step-by-step explanation. It is really helpful.
    I like to use the darkice part only. Download and building all went well until the 'sudo dpkg -i ../darkice_1.0-999~mp3+1_armhf.deb' statement. Actually that went well too, but no darkice binary in /usr/bin ............ (I presume it should be there?)
    Also no cfg file, since there is no Examples dir in the existing /usr/share/docs/darkice dir.

    The exact output of the 'sudo dpkg' statement was this (differs from your example):
    Selecting previously unselected package darkice.
    (Reading database ... 62652 files and directories currently installed.)
    Unpacking darkice (from .../darkice_1.0-999~mp3+1_armhf.deb) ...
    Setting up darkice (1.0-999~mp3+1) ...
    pi@raspberry $

    What is going wrong here ?

    Canyou shed some light in my darkness?
    Kind regards,
    Arnold

  35. Steffen

    Hi Arnold,

    to see the files of a package try:

    $ dpkg -L darkice


    AFAIK the package does not ship a default configuration file.

  36. Arnold

    I found the reason: no tab nor space before the dh_auto_configure statement in debian/rules!
    That was clearly not allowed.

    But right now it has recompiled (with the tab in debian/rules), and I expect it to work now. Building gives way more output than the first try.
    Builds successful, and after dpkg -i there is a /usr/bin/darkice and even an example.cfg !
    Thanks for your time,
    Arnold

    Btw: dpkg -L darkice yielded this (without the tab):
    /.
    /etc/defaults
    /etc/defaults/darkice
    /etc/init.d
    /etc/init.d/darkice
    /usr
    /usr/bin
    /usr/share
    /usr/share/doc
    /usr/share/doc/darkice
    /usr/share/doc/darkice/changelog.gz
    /usr/share/doc/darkice/copyright
    /usr/share/doc/darkice/changelog.Debian.gz
    /usr/share/doc/darkice/README.Debian
    $
    That was all.

  37. Adrian yo9hzn

    Works great. At first i had a problem with choppy audio in, but this link solve my problem http://wsprnet.org/drupal/node/3689 . All you have to do is change the usb speed to usb1.1 .

  38. JJ

    Great tutorial. Tried to implement this on a raspberry pi running Wheezy. However, I did the steps twice (some of them more) and still get the same message.

    "DarkIce: AudioSource.cpp:122: trying to open ALSA DSP device without support compiled"

    Googling this error indicates that I compiled darkice without ALSA support. Is this possible? Isn't this what the with-alsa-support flag is for?

    Thanks

  39. Gordon

    @JJ.... Sounds like you missed something (even if you did it all twice).. because I did this on a RasPi with wheezy and darkice is working great. (I did not install icecast). I got that error before I added the mp3 support (libmp3lame). be sure you copy the entire strings (they run off the screen) and have done all updates using apt-get. GL

  40. Benet Hitchcock

    Thanks so much for all the work and great instructions! Rocking some Radiohead as I type.

    Peace,
    Benet

  41. Tyler

    Hey again,

    Was able to get sound to come through using a mixer with phantom power. However, there is high amounts of distortion when talking into the mic. I'm using an XLR to USB adapter and I think it is causing the distortion (I tried every sample rate and messed with options in darkice.cfg for awhile). What kinds of setups are you guys using to live stream to the raspberry pi usb input?

    Thanks!
    Tyler

  42. Ognjen

    I have problem,when I type this
    $ cd darkice-1.0/
    I have this
    bash: cd: darkice-1.0/ No such file directory

    What is a problem,please help me

    Thanks

  43. Milos

    When i start darkice I got this

    Using config file: /etc/darkice.cfg
    Darkice: AudioSource.cpp:122: trying to open ALSA DSP device without support compiled/hw>1,0 [0]

    What is this???????

  44. Steffen

    Ognjen, did you successfully fetch the darkice sources with

    $ apt-get source darkice

    Seems like something went wrong in this step.

  45. Steffen

    Milos, it looks like darkice was compiled without support for alsa. Check if you have installed all suggested dependency packages.

  46. Ognjen

    AFTER
    apt-get source darkice
    I have this
    E:you must put some `source` URis in your sources.list

    how to do that????

  47. Steffen

    Ognjen, did you follow the foregoing step to add a deb-src repository to your sources list at /etc/apt/sources.list?

    Please try to follow the tutorial step by step. This should fix your problems.

  48. Im stuck

    pi@raspberry ~/src/darkice-1.0 $ dpkg-buildpackage -rfakeroot -uc -b
    dpkg-buildpackage: source package darkice
    dpkg-buildpackage: source version 1.0-999~mp3+1
    dpkg-buildpackage: source changed by
    dpkg-buildpackage: host architecture armhf
    dpkg-source --before-build darkice-1.0
    fakeroot debian/rules clean
    debian/rules:4: *** missing separator. Stop.
    dpkg-buildpackage: error: fakeroot debian/rules clean gave error exit status 2


    So how do i fix this?

  49. Steffen

    Hi "Im stuck", this question has already been addressed in the comments above. See: http://www.t3node.com/blog/live-streaming-mp3-audio-with-darkice-and-icecast2-on-raspberry-pi/#comment-24

  50. Kumar McMillan

    In case anyone else runs into this: I was getting nothing but silence when recording from my card. I was testing like this:

    arecord -f S16_LE -d 20 -D plughw:1,0 record.wav

    I had to run alsamixer, select my sound card, press F4, and press page up to increase the line-in level. Then darkice was was streaming the line input.

  51. Kumar McMillan

    My Creative Sound Blaster X-Fi Go! Pro would only play distorted until I switched back to USB 1.1. I put this in my /boot/cmdline.txt to get it working:

    dwc_otg.speed=1

    Kinda lame though since that bumps USB speed down. Maybe I'm missing some drivers, I'm not sure.

  52. Michael M

    Hello. When I try to start darkice with aacp as format, I get the following error: "DarkIce not compiled with AAC+ support, thus can't aacp stream: icecast2-0 [0]"
    How can I compile it with aac+ support?

  53. Steffen

    Hi Michael M,

    could be that this is a bug in darkice. I found the following issue which seems to be related:
    http://code.google.com/p/darkice/issues/detail?id=41

    Can you please rebuild the package and have a look, if the output of the "configure" part contains: "build with aacplus library"

    If you this output, than I'd say it's a bug which needs to be fixed in darkice and then backported to the debian src package.

    If you get "building without aacplus" or "not found, building without aacplus", then you probably miss some package dependency. If you'd post the corresponding aacplus lines (please NOT the complete output) I could have a look.

  54. Michael M

    Hi Steffen. Thank you for the fast answer! These are the errors I get:
    checking for faac library at /usr/lib/arm-linux-gnueabihf/ ... configure: WARNING: not found, building without faac
    checking for aacplus library at /usr/lib/arm-linux-gnueabihf/ ... configure: WARNING: not found, building without aacplus

    How can that be fixed?

  55. Steffen

    Hi Michael M,

    you probably miss the libaacplus packages (and libfaac). Unfortunately they are not available in the Raspbian distribution.

    You could instead install them from http://www.deb-multimedia.org/ Since this resource doesn't support special builds for RasPi (aka hardfloat) chances are that you end up in performance problems while encoding. But you should give it a try. After the installation you have to rebuild darkice as described in the article above.

    I tried to, but darkice failed to compile with error
    aacPlusEncoder.h:45:30: fatal error: libaacplus/cfftn.h: No such file or directory

    I gave up since it would take too much time to debug and fix it.

  56. Michael M

    Hi Steffen!
    Thank you very much. (Danke für die Mühe ;))

  57. Jason

    Hi Steffen,

    Your tutorial is fantastic, much appreciated.

    One problem I've encounter though: Im using a headless RasPi on a hardwired ethernet connection and a cheap USB sound card, but when I start streaming the audio I get this strange choppy/glitchy sound (other than that, it would sound pretty good). I thought it might be the darkice.cfg or the AlsaDspSource.cpp buffers - i tried increasing both by 5 secs, but no go. I also tried using 64kpbs, varying sample rates, low quality, mono channel etc...am I missing something here?

    You're help would be much appreciated!

  58. Steffen

    Jason, the reason could be samplerate and alsa configuration. But I am not a pro when it comes to hardware configuration and alsa, so I'd suggest you to ask google for help :)

  59. Thierry

    Hello

    and congratulation for this work ,but i cant start Darkice...

    i have this :
    Using config file: /etc/darkice.cfg
    Using ALSA DSP input device: hw:1,0
    DarKice: configSection.ccp 117: format missing in section icecast-0 [0]

    and no workink have you a idea ?

    Thank's and good week !

    Thierry

  60. Steffen

    Hi Thierry,

    did you set "format" in your /etc/darkice.cfg file as shown in the example?

    [icecast2-0]
    ...
    format = mp3
    ...

    If setting format does not fix your issue, please post your darkice.cfg file to http://pastebin.com or the like and add the link here.

  61. Thierry

    Hello Steffen,

    And thank's for your speed respond,my .cfg is :

    # this section describes general aspects of the live streaming session
    [general]
    duration = 0 # duration of encoding, in seconds. 0 means forever
    bufferSecs = 5 # size of internal slip buffer, in seconds
    reconnect = yes # reconnect to the server(s) if disconnected

    # this section describes the audio input that will be streamed
    [input]
    device = hw:1,0 # OSS DSP soundcard device for the audio input
    sampleRate = 44100 # sample rate in Hz. try 11025, 22050 or 44100
    bitsPerSample = 16 # bits per sample. try 16
    channel = 2 # channels. 1 = mono, 2 = stereo

    # this section describes a streaming connection to an IceCast2 server
    # there may be up to 8 of these sections, named [icecast2-0] ... [icecast2-7]
    # these can be mixed with [icecast-x] and [shoutcast-x] sections
    [icecast2-0]
    bitrateMode = vbr # average bit rate
    format = mp3 # format of the stream: ogg vorbis
    bitrate = 128 # bitrate of the stream sent to the server
    server = yp.yourserver.com
    # host name of the server
    port = 8490 # port of the IceCast2 server, usually 8000
    password = ******* # source password to the IceCast2 server
    mountPoint = stream # mount point of this stream on the IceCast2 server
    name = DarkIce trial
    # name of the stream
    description = This is only a trial
    # description of the stream
    url = http://www.yourserver.com
    # URL related to the stream
    genre = my own # genre of the stream
    public = no # advertise this stream?
    localDumpFile = recording.mp3 # local dump file

    Thank's Thierry

  62. Johan

    I have followed all the steps and compiled the binary. But after I install the package the binary is not to be found:

    johan@raspberrypi ~/src/darkice-1.0 $ sudo dpkg -i ../darkice_1.0-999~mp3+1_armhf.deb
    Selecting previously unselected package darkice.
    (Reading database ... 62619 files and directories currently installed.)
    Unpacking darkice (from .../darkice_1.0-999~mp3+1_armhf.deb) ...
    Setting up darkice (1.0-999~mp3+1) ...

    When I try to tab complete I only get the existing commands, not darkice:

    johan@raspberrypi ~/src/darkice-1.0 $ da
    dash date

    During compilation and installation of the package there are no critical errors whatsoever. What could I be doing wrong?

  63. Steffen

    @Johan

    please see comment #36: the build will fail if debian/rules has spaces instead of tabs. Download the file

  64. Steffen

    @Thierry

    It seems your darkice.cfg is incomplete or wrong. Your posted configuration does not cause the error you mentioned before:

    DarKice: configSection.ccp 117: format missing in section icecast-0 [0]


    In your post, you have [icecast2-0] instead of icecast-0

    Please double check is you use the coorect cfg file. You could try to explicitly set it with:
    darkice -c /path/to/your/darkice.cfg


    Also you the bitrateMode requires you to set bitrate or quality:

    If you use
    bitrateMode = vbr

    then you have to set quality instead of bitrate. So either you switch to something like:
    bitrateMode = cbr
    format = mp3
    bitrate = 128
    

    or:
    bitrateMode = vbr
    format = mp3
    quality = 0.6

  65. Gianni

    @Thierry At the section section icecast-0 add the line command

    format = mp3
    I have the same problem and I see that line left. After line adding my darkice is running

  66. Andreas

    Hi! I'm running icecast and darkice on a RPi successfully, but when I turn the RPi off all statistics will be lost.
    Anyone could tell me how to analyze the listeners statistics so that I can monitor the accesses while streaming and afterwards of course?
    I'd like to know how many users have been listening that day and how many users where listening at the same time (p.e. 100 users that day with a max. of 20 users at the same time).

    Thank you very much!!!

  67. Steffen

    Andreas, you can query the statistics in a machine readable format, e.g. json or xml: http://icecast.org/docs/icecast-2.4.1/server-stats.html
    That's all I know. Good luck.

  68. Andy

    Hey Steffen,
    Awesome Post!
    If I am able to do a real time Analog to MP3 conversion before it hits the PI should I theoretically be able to get low latency streaming?? I'm trying to get the Analog to Digital Stream in under 75ms do you think this is possible? How would I figure out the actual conversion time from packaging to receiving?
    Thank you!!!

  69. Brad

    Hi,
    i'm trying to setup a live stream to broadcastify. I was able to connect to their web server fine, but I have no audio. i did the following step:
    -Plug the USB sound card into the Raspberry Pi
    -Plug your scanner's headphone jack into the mic jack on the USB sound card dongle
    -Start alsamixer
    -pi@bcfypi1:~# alsamixer
    -press F6, choose the "USB Headphone Set" entry
    -press your tab key to select the "Capture" device volume control
    use your "up arrow" key to adjust the level to it's lowest level possible (6)
    -press escape to exist alsamixer
    -run the following command to save the volume settings
    -sudo alsactl store


    I'm not sure what i missed, if you could help, thank you

  70. Eike

    Hello,
    does this work for Rasbian Jessie on a Raspberry Pi 2 with USB Soundcard Hercules Muse including Line-In ???
    Thanks.

  71. Vervito

    Hi guys, do you have a idea how i can handle this problem ?
    DarkIce: AlsaDspSource.cpp:265: No such device [0]
    I plugin a usb PnP soundcard, work fine for a while but after about 15 seconds or sometimes a bit longer it stop playing and i get the above error, at this moment the red led on the usb device stop blinking. Thanks.

  72. jonathan

    Btw, teratech on January 12, 2013 at 04:28,
    Commenting out the extra configs in the darkice config worked for me too.
    Thank you Stefan and teratech

  73. Noel Petit

    The build fails with the May 2016 version of Jessie/Raspbian. Is there an updated debian/rules that will build and run with the USB audio adapter?

  74. michel jacobs

    Updating darkice to latest version: change to your src directory and download the latest version of darkice, wget http://sourceforge.net/projects/darkice/files/darkice/1.3/darkice-1.3.tar.gz .
    Copy the subdirectory debian from darkice-1.0 to darkice-1.3 (rules should be edited allready!) proceed like before!

  75. dominic

    any tips on improving/filtering the audio to remove a background hiss. This is only evident at high gain/volume, but i'd love to play with this in order to extend the working range of my mic

  76. Matt

    Hi,
    I've set this up before very succesfully, but with a new raspberry pi 3 I get the following error when starting darkice and I can't work out what has changed. Can anyone help?

    DarkIce: TcpSocket.cpp:251: connect error [111]

    I'm confident darkice has the right server and port settings in the config file.
    Thanks

  77. Randy

    One other thing about the:
    DarkIce: LameLibEncoder.cpp:75: lame lib opening underlying sink error [0]

    I got this, and my password and ports and hosts were all correct. I was using icecast2. I needed to delete all the entries for [icecast1-0] and leave [icecast2-0]

    I know the thread is old, but since it is the standard for RasPi I thought I'd add it.

  78. Ethan Hall

    hello I am getting an error when doing the final step and running darkice, here is the error, you you find anything to fix this please email me at nitrothechameleon@gmail.com thanks! :

    pi@raspberrypi:~ $ sudo darkice
    DarkIce 1.0 live audio streamer, http://code.google.com/p/darkice/
    Copyright (c) 2000-2007, Tyrell Hungary, http://tyrell.hu/
    Copyright (c) 2008-2010, Akos Maroy and Rafael Diniz
    This is free software, and you are welcome to redistribute it
    under the terms of The GNU General Public License version 3 or
    any later version.

    Using config file: /etc/darkice.cfg
    Using OSS DSP input device: /dev/dsp
    DarkIce: ConfigSection.cpp:117: format missing in section icecast-0 [0]

  79. jackorta

    i have streamed with paid shoutcast successfuly but failed with free shoutcast , is it possible to work with free shoutcast ??

  80. PiGeek

    I have darkice and icecast2 installed and running and am getting audio from my Logitech C920 Webcam on hw;2:0. (I also have a second USB Soundcard installed at hw:1.0, but not using it right now - that's for something I plan to use later). Anyway, I can hear sound but it sounds like chipmunks - very high pitched. Is there a way to correct so the pitch is normal?

  81. Maurice

    Is there a darkice for icecast2 working image available for download that has most of the perimeters already set up for the pi3?

  82. Finnister

    Hey Steffen. Great HOWTO. Looking to raspian stretch you don't have to built the darkice. You only have to install by using apt-get or aptitude or what else the packages darkice and icecast2. That's it. Following your introduction it will run streaming the audio input of the usb dongle as an m3u-link via your network. It's great. Using pi Zero w it need between 17 ... 21 percentage of cpu-usage. Thanks & regards mein.schpam<AT>gmail.com

  83. Nguyen Thanh

    Hello. When I try to start darkice with mp3 as format, I get the following error: "DarkIce: DarkIce.cpp:609: DarkIce not compiled with lame support, thus can't create mp3 stream: icecast2-0 [0]"
    How can I compile it with lame support?

  84. vicent lozano

    hi steff my problem is that
    Using config file: /etc/darkice.cfg
    Using ALSA DSP input device: hw:1,0
    Could not set POSIX real-time scheduling, this may cause recording skips.
    Try to run darkice as the super-user.
    ALSA lib pcm_hw.c:1667:(_snd_pcm_hw_open) Invalid value for card
    DarkIce: DarkIce.cpp:1273: can't open connector [0]
    please say me about it thank

  85. rob

    How many people can connect to the PI before it becomes an issue of too many connections?

  86. Paul

    Hello Steffen, I would like to monitor live audio from a remote location(250 kms away) over the internet, which I assume is possible using IceCast2, Can DarkIce and IceCast2 be installed and run on the same RaspPi or do I need two separate RaspPi devices? Thanks, Paul.

  87. Steffen

    Hi Paul, darkice and icecast can run on the same device.

  88. Roozano

    Hi, while installing darkice i got this msg:
    :~/src/darkice-1.2# debchange -v 1.0-999~mp3+1
    debchange: fatal error at line 1106:
    New version specified (1.0-999~mp3+1) is less than
    the current version number (1.2-0.2)! Use -b to force.
    what should I change n type?
    Thx

  89. Steffen

    Hi Roozano, try with:

    debchange -v 1.2-999~mp3+1

  90. Roozano

    Hi Steffen, thx a lot, it works...

  91. Roozano

    Hi Steffen, I had another problem:
    root@streamer:~/src/darkice-1.2# debchange -v 1.2-999~mp3+1
    darkice (1.2-999~mp3+1) UNRELEASED; urgency=medium
    * New build with mp3 support
    -- root <root@streamer> Tue, 24 Jul 2018 11:08:20 +0700
    darkice (1.2-0.2) unstable; urgency=medium
    * Non-maintainer upload.
    * Add patch to prevent FTBFS on kfreebsd.
    -- Alessio Treglia <alessio@debian.org> Fri, 20 Jun 2014 17:16:25 +0100
    "Should I deleted from darkice (1.2-0.2) unstable; urgency=medium, down below?"
    and I got this msg
    root@streamer:~/src/darkice-1.2# dpkg-buildpackage -rfakeroot -uc -b
    dpkg-buildpackage: warning: using a gain-root-command while being root
    dpkg-buildpackage: source package darkice
    dpkg-buildpackage: source version 1.2-999~mp3+1
    dpkg-buildpackage: source distribution UNRELEASED
    dpkg-buildpackage: source changed by root <root@streamer>
    dpkg-buildpackage: host architecture armhf
    dpkg-source --before-build darkice-1.2
    dpkg-checkbuilddeps: Unmet build dependencies: libopus-dev
    dpkg-buildpackage: warning: build dependencies/conflicts unsatisfied; aborting
    dpkg-buildpackage: warning: (Use -d flag to override.)
    root@streamer:~/src/darkice-1.2# sudo dpkg -i ../darkice_1.2-999~mp3+1_armhf.deb dpkg: error processing archive ../darkice_1.2-999~mp3+1_armhf.deb (--install):
    cannot access archive: No such file or directory
    Errors were encountered while processing:
    ../darkice_1.2-999~mp3+1_armhf.deb

  92. Steffen

    Hi Roozano, it seems you need to install libopus dependencies:

    apt-get install libopus-dev