Question

I want to write something like Skype, i.e. I have a constant audio stream on one computer and then recompress it in a format that's suitable for a latent internet connection, receive it on the other end and play it.

Let's also assume that the internet connection is fairly modern and fast, i.e. DSL or alike, no slow connections over phone and such. The involved computers will also be rather modern (Dual Core Intel CPUs at 2GHz or more).

I know how to handle the audio on the machines. What I don't know is how to transmit the audio in an efficient way.

The challenges are:

  1. I'd like get good audio quality across the line.

  2. The stream should be received without drops. The stream may, however, be received with a little delay (a second delay is acceptable). I imagine that the transport software could first determine the average (and max) latency, then start the stream and tell the receiver to wait for that max latency before starting to play the audio. With that, if the latency doesn't get any higher, the entire stream will be playable on the other side without stutter or drops.

  3. If, due to unexpected IP latencies or blockages, the stream does get cut off, I want to be able to notice this so that I can take actions (e.g. abort the stream) and eventually start a new transmission.

What are my options if I want do use ready-made software for the compression and tranmission? I have no intention to write my own audio compression engine, really. OTOH, I plan to sell the solution in a vertical market, meaning I can afford a few dollars of license fees per copy, but not $100s.

I guess the simplest solution would be to just open a TCP stream, send a few packets back and forth to determine their running time (or even use UDP for that), then use the results as the guide for my max latency value, then simply fire the audio data in its raw form (uncompressed 16 bit stereo), along with a timing code over the TCP connection. The receiver reads the data and plays it with the pre-determined delay. That might just work with the type of fast connection I expect.

I just wonder if there are better solutions to reach this goal, with better performance (lower latency) and less data (compressed).

BTW, I first try to implement this on OS X, but might want to do it on Windows, too, if it proves successful.

Was it helpful?

Solution

For transmitting audio over the Internet you should probably look at using RTP. It is used for SIP, H.323, and many others use this for streaming audio content. You might even want to look at just using a SIP lirbary. It already has much of what it sounds like you want. SIP can have pretty good quality if you have a good codec, and sufficient bandwidth.

OTHER TIPS

VLC supports various types of audio and video transcoding. Might be something you want to check out.

I know that thread is kind-a old, however, one insight that I want to share with you is this: you can't use TCP for this that you are trying to do because of the latency you require - you said 1 second is acceptable, and from that I assume that over 1sec isn't.

Your latency with TCP isn't determined with PING to host. The problem with TCP is that when you connect, and you accept to live with certain latency, ANY problem with a connection will shrink TCP window, all data that is received will be dropped and underlying protocol will have to handle it. At this time, you will lose your 1sec advantage over real-time and the stream will be dropped.

TCP is good for the situation where large delays are acceptable (say 10 seconds or more) which will allow you to always have enough data to eat and play out before connection is re-established.

If I was in your shoes, I'll try the following:

  • UDP for transport
  • some low-delay encoding - AAC-LD for example, but mp3 would also be OK
  • have some mathematical overhead set-up over the UDP so if one packet is lost, audio stream can recover.

BTW, frames at mp3 are 40msec long. With some 'magic' you could mask few dropped frames.

ShoutCAST + SAM Broadcaster or Winamp. Will do the trick easily.

If you’re looking to start your own Internet radio station using icecast2 you can:

  • install icecast on your VPS
    #sudo apt-get install icecast
  • install ezstream also on you VPS
    #sudo apt-get install ezstream
  • create a playlist file with your files

playlist.m3u (you can read more form wikipedia)

    #EXTM3U

    #EXTINF:123, Sample artist - Sample title
    Sample.mp3

    #EXTINF:321,Example Artist - Example title
    Example.ogg
  • create an ezstream config file xml

config.xml

<ezstream>
    <url>http://localhost:8000/stream</url>
    <!--
      If a different user name than "source" should be used, set it in
      <sourceuser/>:
     -->
    <!-- <sourceuser>mr_stream</sourceuser> -->
    <sourcepassword>hackme</sourcepassword>
    <format>MP3</format>
    <filename>playlist.m3u</filename>
    <stream_once>1</stream_once>
    <svrinfoname>My Stream</svrinfoname>
    <svrinfourl>http://www.oddsock.org</svrinfourl>
    <svrinfogenre>RockNRoll</svrinfogenre>
    <svrinfodescription>This is a stream description</svrinfodescription>
    <svrinfobitrate>128</svrinfobitrate>
    <svrinfochannels>2</svrinfochannels>
    <svrinfosamplerate>44100</svrinfosamplerate>
    <svrinfopublic>0</svrinfopublic>
</ezstream>

Or you can try this: nodejs application

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top