Sunday, July 1, 2012

Streaming Audio with Supercollider: Ustream vs Icecast

Live Audio Streaming of Supercollider on Backrtrace

So I've been messing around again with long-playing generative music on Supercollider.  Sequencers that play incremental variations on things on an infinite loop, with some external data thrown in here or there to tweak certain parameters.  Here's an example:

I started writing this kind of music back around 1998, while living in Florida, on a 25mhz 486 PC that I had purchased at a thirft store for $50, using the internal speaker no less.  It was a few months before I figured out how to program for the SoundBlaster in QBasic.

I had done a few installation shows or performances with this kind of music, but getting it on the internet as a continuous stream has been a goal for about 10 years.  With my involvement in Occupy I came into contact with a lot of livestreaming  - I'd actually used some of the services in 2009 while working at a digital marketing agency but that association kind of made me forget that this was also something that ordinary users could set up for themselves very easily.

So this week I set up a Ustream channel for myself and started streaming with Supercollider off of my Mac Mini.  You can hear some of the archived recordings on that page.

Ustream has been kind of a mixed bag.  On the one hand, getting up and running is dead simple - you can use a web-based broadcast app (no need to install software) and use Soundflower to grab sound from your desktop.  You can't do any video this way, only audio.   However, getting a screencast going is pretty simple with their desktop capture software.  It's also very easy to make lengthy recordings that can be played back on your channel homepage - just hit the record button and they will record and archive your stream.  Not sure what the restrictions are on how many hours you can have archived and how long they last.

Ease of use is about all I can say is positive for Ustream for this (admittedly non-standard) use case.  The commercials are hugely disruptive and seem to come about every 10 minutes.  Commercials are also played on the archived streams.  In order to stream without commercials, I'd have to get a Pro broadcaster account, which would cost several hundred dollars per month (it's paid per viewer minute, so more viewers = more cost).  Totally out of the question.  The sound quality is also unacceptably poor - and mp3 stream compressed at 96kpbs might be fine for speech, but doesn't work for music.

Ustream is working on an audio-only mode, which could provide a better experience for people who want to stream music from their desktops.

I've had an Icecast server running on backtrace.us for something like a year now.  Finally got it up and running on a proper subdomain too, instead of having the port 8000 showing up in the url.  (I did this thru reverse proxying with nginx.  I'll put up an example of the conf file in a later post.)  I've been experimenting with running a supercollider server on a headless Linux virtual machine in the cloud but overall that's been a mixed bag too.  It's cool to have a dedicated computer that can render audio forever without having to tie up your home computer (right now if I want to watch a DVD, the music streaming stops, but I'll probably separate out the music streaming to another computer eventually).   And datacenters are generally more reliable than home computers in terms of uptime as well.  Downside is that the scserver and sclang processes are finnicky on a virtual machine - they crash alot, probably due to cpu spikes from other processes running on the physical machines that share with my virtual.  Plus there's all the moving parts of syncing SC with Jack and ices in order to actually get your audio data broadcasting over the web.

What I did realize though this week from playing around with the Ustream studio software was that I could use my homecomputer as a source for the streaming server on backtrace.us.  Just like how a person uses their phone / laptop camera to get a video stream, but doesn't have 100's of viewers connect directly to their laptop, I could do the same with supercollider and sound.  I had been using Nicecast studio mostly just to archive recordings of Supercollider locally, or listen around the house, but I had never tried setting it up as a source for my streaming server.  Doing this was a snap - just go to the server tab in Nicecast and enter the url for the streaming server, plus the password for "source" users (this is defined in your /etc/icecast2/ icecast.xml).  No need to mess around with compiling a version of Ices on your linux box that will play mp3's or messing with Jackd - just set Nicecast to broadcasting and have it grab the signal from Supercollider.   If you're rendering on multiple servers (to spread the load out over multiple cores), don't forget to have Nicecast capture all sub-processes from your source (this is in the "Advanced" settings when you do Source: Application).  You can use inline effects on your stream to improve sound quality  (like compression or EQ) , and you can broadcast at whatever bitrate you want.  Nicecast isn't free, but it's pretty reasonably priced for a lifetime license.

TL DR Summary:


Streaming Audio with Ustream:


Pros:

  • Easy to set up
  • Free
  • Simple recording and playback of streams online - good for sharing
  • You can control Supercollider while it's playing
  • Screencasting is an option if you want to do livecoding performances
Cons:
  • Too many commercials
  • Low quality audio
  • Premium Service is very expensive
  • Requires a dedicated home computer

Running Supercollider with Icecast in the Cloud:


Pros:
  • Doesn't tie up your home computer
  • High-quality audio
Cons:
  • High maintenence, unreliable deployment
  • Requires considerable knowledge
  • Have to pay for hosting
  • Can't control Supercollider while it's running

Streaming with Nicecast locally, and Icecast in the Cloud (Best Option)


Pros:
  • High-quality audio
  • Nicecast is easy to set up.  Icecast2 server is not difficult if you know Linux packages
  • Total control over the stream - no commercials, no 3rd-party services
  • You can control Supercollider locally while it's playing
Cons: 
  • Requires a dedicated home computer and reliable internet connection
  • Have to pay for hosting / bandwidth for the Cloud server
  • Have to upload and host archived recordings
  • Have to pay for Nicecast
You can check out the stream here in your browser.

Or here in your mp3 player.

Next up is a walkthrough of the code used to generate the music here.


2 comments:

  1. Hey Tom.. I'm trying to get Icecast to work over port 80 via NginX. I'm familiar with the basics of NginX, but not how all the pieces fit together. I've tried playing with my Icecast settings but no luck on port 80, it seems to get it to work I need to run it as root - probably not the best idea.. ... could you share your method, maybe the NginX config?

    If so, please let me know asap, looking to get this up for an installation Wednesday.. thanks!
    -Steven

    ReplyDelete
    Replies
    1. Hi.

      server {
      ## This is to avoid the spurious if for sub-domain name
      ## "rewriting".
      listen 80;

      server_name icecast

      location / {
      proxy_pass http://127.0.0.1:8000;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_buffering off;
      chunked_transfer_encoding off;
      proxy_redirect default;
      }

      Than put your saved mountname.m3u into ../share/icecast/web/ directory

      Delete