More on internet radio buffering

  • 3 April 2005
  • 4 replies

Userlevel 2
I had a similar problem to the WBUR listener in another thread -- my local NPR station broadcasts MP3, but only in 16Khz, which Sonos will grudgingly attempt to play, but it doesn't work very well.

So I did some fooling around on my linux machine, and managed to produce an icecast stream reesampled to 128k at 44.1Khz. I can go into more detail about how that all works if anyone is interested. It's pretty kludgey at the moment, but I'm just trying to figure out what's possible. In theory, this would work for just about any stream, since mplayer can produce PCM audio from lots of formats. My stream uses mpg123 to pull in the stream off the net, feeds it as PCM to lame, which reencodes to the proper rates and sends it off to a FIFO, which is what icecast broadcasts.

So the problem I have now seems to be beyond my ability to fix. My icecast stream works great on this machine and on my wireless laptop played through xmms. But on sonos, it skips and stutters terribly. I know it's not a bandwidth issue, because the weak card on my laptop has no trouble with it. I notice that the sonos stream is slightly ahead of my laptop, from which I deduce that sonos is not doing very much buffering at all. And I suspect that's why it's stuttering. The stream works fine when xmms buffers 32K, so it must be less than that.

So, is there any hope? Do radio streams have to be absolutely perfect to work? I listened to Philly NPR for hours tonight with no problems whatsoever.

(Also, an aside: I know that the ZPs are perfectly capable of resampling streams that aren't 44.1kHz. Why don't they? That struck me as pretty weak.)

This topic has been closed for further comments. You can use the search bar to find a similar topic, or create a new one by clicking Create Topic at the top of the page.

4 replies

I've posted about this issue before. We REALLY need better buffer control on Sonos. Either manual or automatic, there needs to be a better buffering mechanism that either lets me set the buffer size, or does it automatically when it loses a stream. I can play several radio stations on my computer flawlessly, but sonos just stutters or drops them all together. Extremely irritating. If you have a perfect internet connection, maybe internet radio might work better, but many of us do not.

By the way - very slick idea to rebroadcast from your Linux server.. Willing to share? I have a Linux server already doing web serving and that sounds like a nice way to get more control! Good job! 🆒
Userlevel 2
Like I said, my method is incredibly crude and hacky at the moment. I was pretty much just trying to get something going so I could see if it would work, with the idea of writing better tools when I figure out what the solution space looks like.

FWIW, what I did was just this:

* Create a FIFO for the encoder to stream into and for icecast to broadcast from (icecast will happily stream a FIFO. Shoutcast, I discovered, will not):

$] mknod /music/mpbc.mp3 p

* Read in the radio stream and reencode it using mpg123 and lame, with abstruse command line options thusly:

$] mpg123 -b 1024 -s | lame -r -s 11.025 -x --resample 44.1 - /music/mpbc.mp3

As long as that's running it will be streaming 128k 44.1kHz mp3 into /music/mpbc.mp3. More work is needed on making it reconnect if it loses the input stream and so on, obviously.

* Install icecast and ices (not the newest version of ices! It only streams .ogg. The 0.4 streams mp3). Then read the docs and configure icecast to run and ices to provide /music/mpbc.mp3 as a stream to icecast. These are both pretty easy to configure if you're not doing anything complicated.

And that's basically it. On all my machines except for sonos, it streams beautifully. And I'm sure that one day soon we will have an update that will bring Sonos up to scratch as well. Maybe by then I'll have a nice little package developed to automate the restreaming of any source. :-)

Also, if the stream is in a windows media format, mplayer can read it and dump wav audio with the -dumpaudio switch. A command line something like:

$] mplayer -ao pcm -aofile somefile.wav -vc dummy -vo null -cache 64

will produce perfectly good WAV audio for reencoding. From there it's nearly the same as above, except I think the format flags for lame would be slightly different (since it's a stream, it probably won't have usable WAV headers so you have to tell the encoder what it is).

And while I'm wishlisting here, there isn't any real good reason why I shouldn't be able to just put the FIFO on my music share and have Sonos play it like any other mp3. XMMS will play the bare FIFO no problem. That would save a whole lot of extra trouble all around.
Userlevel 2
I agree with eldoran that we need buffer control. The internet radio streams drop on my zp's but I have no issue with my wireless laptop.
listen to Tunein radio and I do not have that problem