Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 7th, 2008, 7:47 PM   #1
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 251
Rep Power: 4 Brent is on a distinguished road
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
Brent is offline   Reply With Quote
Old Feb 7th, 2008, 8:13 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,034
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
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.

Last edited by Sane; Feb 7th, 2008 at 8:25 PM.
Sane is offline   Reply With Quote
Old Feb 7th, 2008, 8:27 PM   #3
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 251
Rep Power: 4 Brent is on a distinguished road
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.
Brent is offline   Reply With Quote
Old Feb 7th, 2008, 8:49 PM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,034
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Old Feb 7th, 2008, 9:16 PM   #5
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 251
Rep Power: 4 Brent is on a distinguished road
Re: Streaming Audio over network

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
Attached Files
File Type: zip voice.zip (5.0 KB, 15 views)
Brent is offline   Reply With Quote
Old Feb 7th, 2008, 9:33 PM   #6
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,034
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Old Feb 7th, 2008, 10:03 PM   #7
PhilBon
Hobbyist Programmer
 
PhilBon's Avatar
 
Join Date: Nov 2005
Posts: 172
Rep Power: 4 PhilBon is on a distinguished road
Send a message via AIM to PhilBon Send a message via MSN to PhilBon
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.
PhilBon is offline   Reply With Quote
Old Feb 8th, 2008, 3:37 PM   #8
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 251
Rep Power: 4 Brent is on a distinguished road
Re: Streaming Audio over network

Yes, The program does use UDP.
Brent is offline   Reply With Quote
Old Feb 8th, 2008, 5:31 PM   #9
PhilBon
Hobbyist Programmer
 
PhilBon's Avatar
 
Join Date: Nov 2005
Posts: 172
Rep Power: 4 PhilBon is on a distinguished road
Send a message via AIM to PhilBon Send a message via MSN to PhilBon
Re: Streaming Audio over network

@brent, Sorry then. Other the other hand, Great Job.
PhilBon is offline   Reply With Quote
Old Feb 8th, 2008, 8:54 PM   #10
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 251
Rep Power: 4 Brent is on a distinguished road
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.
Brent is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Network Simulator design renato Software Design and Algorithms 2 Dec 11th, 2007 11:54 PM
An Audio and Video class for ruby Master Ruby 3 Mar 24th, 2006 6:49 AM
Streaming audio songs? java_roshan Coder's Corner Lounge 1 Oct 27th, 2005 2:35 PM
Code Request - Onboard Audio Meecher Other Programming Languages 7 Sep 20th, 2005 2:53 AM
Checking source codes of image, audio and video files on_auc C++ 3 Feb 21st, 2005 9:36 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:10 AM.

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