Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Feb 10th, 2008, 8:59 AM   #21
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 247
Rep Power: 4 Brent is on a distinguished road
Re: Streaming Audio over network

Input and Output data is successfully being added to the queues, but now I am having trouble with the PlayOutput and SendInput functions. It seems these functions aren't correctly looping through the queues, but I dont know.



Here is what I have so far:
c++ Syntax (Toggle Plain Text)
  1.  
  2. struct waveBuffers
  3. {
  4. char data[BUFFERSIZE];
  5. };
  6.  
  7. waveBuffers InQueue[MAX_BUFFERS];
  8. waveBuffers OutQueue[MAX_BUFFERS];
  9.  
  10. int In,Out;
  11. int WriteIndex = 0;
  12. int ReadIndex = 0;
  13.  
  14. int WriteIndex2=0;
  15. int ReadIndex2=0;
  16.  
  17. DWORD WINAPI FillInput(LPVOID lpParameter)
  18. {
  19. char data[BUFFERSIZE];
  20. int a;
  21.  
  22. while(threadEnd == false)
  23. {
  24. if ( (WriteIndex2 + 1) % MAX_BUFFERS != ReadIndex2)
  25. {
  26. sound.GetInput(data);
  27. strcpy(InQueue[WriteIndex2].data,data);
  28. WriteIndex2 = (WriteIndex2 + 1) % MAX_BUFFERS;
  29. }
  30. }
  31. return 0;
  32. }
  33.  
  34. DWORD WINAPI FillOutput(LPVOID lpParameter)
  35. {
  36. char data[BUFFERSIZE];
  37. int addrlen=sizeof(sin),a;
  38.  
  39. while(threadEnd == false)
  40. {
  41. if ( (WriteIndex + 1) % MAX_BUFFERS != ReadIndex)
  42. {
  43. recvfrom(client,data,sizeof(data),0,(struct sockaddr*)&sin,&addrlen);
  44. strcpy(OutQueue[WriteIndex].data,data);
  45. WriteIndex = (WriteIndex + 1) % MAX_BUFFERS;
  46. }
  47. }
  48.  
  49. return 0;
  50. }
  51.  
  52. DWORD WINAPI PlayOutput(LPVOID lpParameter)
  53. {
  54. char data[BUFFERSIZE];
  55. int a;
  56.  
  57. while(threadEnd == false)
  58. {
  59. for(a=WriteIndex; a<=ReadIndex; a++) //set 'a' equal to WriteIndex
  60. {
  61. sound.Play(OutQueue[a].data);
  62. ZeroMemory(OutQueue[a].data, BUFFERSIZE);
  63. }
  64. }
  65.  
  66. return 0;
  67. }
  68.  
  69. DWORD WINAPI SendInput(LPVOID lpParameter)
  70. {
  71. char data[BUFFERSIZE];
  72. int a;
  73.  
  74. while(threadEnd == false)
  75. {
  76. for(a=WriteIndex2; a<=ReadIndex2; a++) //set 'a' equal to WriteIndex2
  77. {
  78. sendto(client,InQueue[a].data,sizeof(InQueue[a].data),0,(struct sockaddr*)&sin,sizeof(sin));
  79. ZeroMemory(InQueue[a].data, BUFFERSIZE);
  80. }
  81. }
  82.  
  83. return 0;
  84. }
Brent is offline   Reply With Quote
Old Feb 10th, 2008, 4:09 PM   #22
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 810
Rep Power: 4 The Dark is on a distinguished road
Re: Streaming Audio over network

You need to change readindex when you have read something out of the queue, similar to how you are updating WriteIndex. So that the ReadIndex is chasing the WriteIndex.

Something like:
c++ Syntax (Toggle Plain Text)
  1. DWORD WINAPI PlayOutput(LPVOID lpParameter)
  2. {
  3. char data[BUFFERSIZE];
  4.  
  5. while(threadEnd == false)
  6. {
  7. while (ReadIndex != WriteIndex)
  8. {
  9. sound.Play(OutQueue[ReadIndex].data);
  10. ZeroMemory(OutQueue[ReadIndex].data, BUFFERSIZE);
  11. ReadIndex = (ReadIndex + 1) % MAX_BUFFERS;
  12. }
  13. }
  14.  
  15. return 0;
  16. }

Note that this loop will use up as much CPU as it can. You will need to add some signalling so that the reader knows when there is data available, rather than looping and checking ReadIndex against WriteIndex.

Also note that you will need to take care that your threads don't try to access the same memory at the same time.
The Dark is offline   Reply With Quote
Old Feb 10th, 2008, 5:30 PM   #23
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 247
Rep Power: 4 Brent is on a distinguished road
Re: Streaming Audio over network

Thanks for the replies and advice.
Brent is offline   Reply With Quote
Old Feb 12th, 2008, 8:11 PM   #24
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 247
Rep Power: 4 Brent is on a distinguished road
Re: Streaming Audio over network

I have revised my code a bit. The program runs, but the playback is extremely choppy. I have posted the code for anyone who wants to look at it.


Brent
Attached Files
File Type: zip voice.zip (20.6 KB, 3 views)
Brent is offline   Reply With Quote
Old Feb 13th, 2008, 8:09 PM   #25
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 247
Rep Power: 4 Brent is on a distinguished road
Re: Streaming Audio over network

I have found some audio streaming source code online using google, and have modified it for my uses. The code compiles and runs fine, but does not seem to be transmitting audio correctly. The program is supposed to create two queues, one for input and one for output. It is supposed to constantly updates these queues( send data from input queue, and play data from output queue) but does not seem to be working. Like I said the progam compiles and runs fine by just isn't doing what it's told. I am posting the code as an attachment. Im using Borland C++ BuilderX on Win dows XP. Thanks for any help.



brent
Attached Files
File Type: cpp AudioCode.cpp (11.6 KB, 2 views)
Brent is offline   Reply With Quote
Old Feb 21st, 2008, 6:25 PM   #26
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 247
Rep Power: 4 Brent is on a distinguished road
Re: Streaming Audio over network

I have made some progress in my program. I have created a UDP receive class to handle all received data. It now receives audio and adds it to a queue, but it doesn't seem to be capturing input from the microphone like it is supposed to, or sending data, for that matter. I am posting the code. Could someone please point me in the right direction. I am using Borland C++ BuilderX on Windows XP. Thanks in Advance.


Brent


And here is the output of the program:

no free buffers
no free buffers
no free buffers
no free buffers
no free buffers
no free buffers
no free buffers
no free buffers
no free buffers
udp: 1330210
free: 0
play: 0
In: 0
Out: 0
Attached Files
File Type: zip source.zip (4.8 KB, 3 views)
Brent is offline   Reply With Quote
Old Feb 21st, 2008, 7:29 PM   #27
Harakim
Hobbyist Programmer
 
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3 Harakim is on a distinguished road
Re: Streaming Audio over network

Are you sending uncompressed wave files? At 192KB/s , that could be choppy. You would need to buffer quite a bit.
Harakim is offline   Reply With Quote
Old Feb 21st, 2008, 8:04 PM   #28
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 247
Rep Power: 4 Brent is on a distinguished road
Re: Streaming Audio over network

The program streams uncompressed voice(Wave PCM) over a network (LAN or internet). At the moment, I am only testing this on my local machine and over my LAN, so there shouldn't be any latency.
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 10:54 PM
An Audio and Video class for ruby Master Ruby 3 Mar 24th, 2006 5:49 AM
Streaming audio songs? java_roshan Coder's Corner Lounge 1 Oct 27th, 2005 1:35 PM
Code Request - Onboard Audio Meecher Other Programming Languages 7 Sep 20th, 2005 1:53 AM
Checking source codes of image, audio and video files on_auc C++ 3 Feb 21st, 2005 8:36 PM




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

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