Aug. 10., 2012

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

Author: . License: Creative Commons License CC BY-SA 3.0, published on t3node.com

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 ;-)

--> Back to the list of articles

License

Licensed under creative commonsThis article is licensed under the Creative Commons License CC BY-SA 3.0. You are free to share (copy, distribute and transmit) and to remix (to adapt) the work under the following conditions:

  • You must attribute the work by mentioning the name of the author (Steffen Müller) and setting a link back to the original article using its URL.
  • If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.

Comments

  1. tobie wrote on September 7, 2012 at 10:21

    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 wrote on September 7, 2012 at 12:40

    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 wrote on September 19, 2012 at 08:29

    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 wrote on September 19, 2012 at 14:59

    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 wrote on September 19, 2012 at 21:40

    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 wrote on September 20, 2012 at 11:45

    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 wrote on October 3, 2012 at 00:52

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

  8. Steffen wrote on October 3, 2012 at 01:22

    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 wrote on October 8, 2012 at 02:25

    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 wrote on October 8, 2012 at 02:30

    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 wrote on October 9, 2012 at 03:22

    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 wrote on October 9, 2012 at 10:51

    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 wrote on December 5, 2012 at 16:01

    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 wrote on December 5, 2012 at 16:02

    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 wrote on December 5, 2012 at 16:03

    Sorry for double post, was having trouble with captcha

  16. Steffen wrote on December 5, 2012 at 19:49

    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 wrote on January 4, 2013 at 02:27

    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 wrote on January 5, 2013 at 16:33

    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 wrote on January 8, 2013 at 20:51

    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 wrote on January 11, 2013 at 05:53

    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 wrote on January 11, 2013 at 10:55

    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 wrote on January 12, 2013 at 02:32

    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 wrote on January 12, 2013 at 04:28

    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 wrote on January 18, 2013 at 02:17

    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 wrote on January 21, 2013 at 01:14

    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 wrote on January 21, 2013 at 10:04

    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 wrote on January 21, 2013 at 14:36

    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 wrote on January 21, 2013 at 14:41

    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 wrote on January 22, 2013 at 00:38

    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 wrote on January 22, 2013 at 13:36

    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 wrote on January 27, 2013 at 05:13

    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 wrote on January 27, 2013 at 06:45

    Thanks for detailed info! Much appreciated.

  33. Steffen wrote on January 27, 2013 at 19:50

    Tyler, try a preamplifier

  34. Arnold wrote on January 30, 2013 at 16:06

    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 wrote on January 31, 2013 at 18:20

    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 wrote on January 31, 2013 at 21:40

    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 wrote on February 3, 2013 at 11:31

    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 wrote on February 3, 2013 at 23:08

    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 wrote on February 5, 2013 at 01:15

    @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 wrote on February 7, 2013 at 12:00

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

    Peace,
    Benet

  41. Tyler wrote on February 11, 2013 at 02:02

    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 wrote on February 20, 2013 at 10:41

    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 wrote on February 20, 2013 at 11:35

    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 wrote on February 21, 2013 at 00:31

    Ognjen, did you successfully fetch the darkice sources with

    $ apt-get source darkice

    Seems like something went wrong in this step.

  45. Steffen wrote on February 21, 2013 at 00:33

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

  46. Ognjen wrote on February 21, 2013 at 22:44

    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 wrote on February 21, 2013 at 23:17

    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 wrote on February 23, 2013 at 02:50

    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 wrote on February 27, 2013 at 23:37

    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 wrote on March 4, 2013 at 03:29

    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 wrote on March 4, 2013 at 07:12

    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 wrote on March 17, 2013 at 23:23

    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 wrote on March 18, 2013 at 20:31

    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 wrote on March 18, 2013 at 22:59

    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 wrote on March 26, 2013 at 00:53

    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 wrote on March 30, 2013 at 22:28

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

  57. Jason wrote on April 6, 2013 at 19:43

    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 wrote on April 9, 2013 at 11:16

    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 wrote on April 27, 2013 at 17:54

    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 wrote on April 27, 2013 at 23:33

    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 wrote on April 28, 2013 at 12:43

    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 wrote on April 28, 2013 at 17:07

    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 wrote on May 1, 2013 at 15:11

    @Johan

    please see comment #36: the build will fail if debian/rules has spaces instead of tabs. Download the file from here: http://www.t3node.com/fileadmin/user_upload/linux/rules

  64. Steffen wrote on May 1, 2013 at 15:47

    @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

Leave a comment

Sorry, due to technical issues, commenting is disabled at the moment. I'm on it.