Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Streaming Audio over network (http://www.programmingforums.org/showthread.php?t=15137)

Brent Feb 7th, 2008 7:47 PM

Streaming Audio over network
 
I am in the process of building a simple Voice Chat application in C++ with WINAPI. Im now in the process of formulating a method of streaming the the audio data. I have searched google but haven't found a whole lot, and was wondering if anyone knows of a good way to approach this or knows of any articles that could help me out. I am using an Open Watcom compiler on Windows XP. Thanks in advance for any help.


Brent

Sane Feb 7th, 2008 8:13 PM

Re: Streaming Audio over network
 
As far as I understand, streaming audio is a matter of how the client decides to handle the socket stream. The audio information, as it's being sent through, is already being streamed. But whether or not the client decides to save the chunks into memory and then play it, as opposed to playing it as it comes in (streaming it), is strictly up to what the client does with the socket stream.

This is why different applications, ranging from VLC to Windows Media Player, all stream media a little differently (sometimes less effectively). The audio is sent in discrete packets by default, and so the streaming is left completely up to how the application decides to handle these packets. This may be why you've been having a difficult time finding information on it.

What this means for you, is you have to make your client efficiently insert each packet into a queue, and constantly playback the audio from the queue. This gets tricky, so someone might be able to recommend some prexisting libraries, or coding tips, to help you with this task. Have you at least been able to send an audio file, or a chunk of information, over? That would be a good start.

Brent Feb 7th, 2008 8:27 PM

Re: Streaming Audio over network
 
Thank you for the quick response Sane, it was very helpful. And yes, the program sends and receives audio data fine, but there is an annoying gap between each audio chunk. I am currently in the process of programming a queue class, when I have finished it and implemented it in my program, I will post some code.

Sane Feb 7th, 2008 8:49 PM

Re: Streaming Audio over network
 
And while I'm still here, if you have constant playback from a queue, but still get gaps in the audio, it could mean a number of things:
  • Your queue doesn't have enough time to accumulate a reasonable amount of data before attempting to playback what's there. This could result in rapidly chopped output. You could solve this problem by making sure that you don't pull any data from the queue, unless its length exceeds a defined threshold. The size of this threshold will increase the offset between the audio source and destination. But the greater the threshold, the more stable the stream will be.
  • It could also mean that data is not transferred quickly enough. Run some tests between local machines and see if it is still choppy. If it is still choppy, then your algorithm is not sufficient. If it only happens between distant machines, you should consider lowering the quality of the stream, by using a lower bitrate if you aren't already.

Brent Feb 7th, 2008 9:16 PM

Re: Streaming Audio over network
 
1 Attachment(s)
I have created a quick solution. Took about 5 minutes, heh. And I am experiencing very choppy playback. Im going to look into your solutions. And by the way, thanks a bunch for your help, I really appreciate it.


The source code is attached.


Brent

Sane Feb 7th, 2008 9:33 PM

Re: Streaming Audio over network
 
No problem. And for clarification, I meant "until its length exceeds a defined threshold". In other words, only start the playback when your queue gets to a certain size. After it starts playing, withold from asserting the threshold. Then don't enforce the size restriciton again until your queue runs out (it may eventually run out if there's lag, disconnection, or simply a slow connection).

I'll let someone strong in C++ take over and point out what could be inefficient about your implementation. It's all very finicky stuff that you will need to play around with, and test strenuously, to get just right.

PhilBon Feb 7th, 2008 10:03 PM

Re: Streaming Audio over network
 
I didn't look at your code, but I'd suggest using UDP rather than TCP, as UDP does not wait on confirmation of successful packet and just sends and sends.

Brent Feb 8th, 2008 3:37 PM

Re: Streaming Audio over network
 
Yes, The program does use UDP.

PhilBon Feb 8th, 2008 5:31 PM

Re: Streaming Audio over network
 
@brent, Sorry then. Other the other hand, Great Job.

Brent Feb 8th, 2008 8:54 PM

Re: Streaming Audio over network
 
Heh, it's alright. The program isn't all that great at this point. The streaming is an utter disaster, but its coming along.


All times are GMT -5. The time now is 3:54 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC