Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to send sound buffer in UDP

 
Priya Kubher
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi iam trying to record from microphone to a buffer like
byte []buffer;
and then trying to send it over the net using udp.
I trying the the following code at client side
ds = new DatagramSocket(serverPort);
InetAddress Addr1 = InetAddress.getByName("c1635229-a");
ds.send(new DatagramPacket(abBuffer,pos,Addr1,clientPort));
and this code at server side
DatagramPacket p = new DatagramPacket(buffer, buffer.length);
ds.receive(p);
abBuffer = p.getData();
This code worked fine when i was using to read and write from command line....but does not work for sound, My program does not deliver the sound to the server side. Also I am using TargetDataLine to read into the buffer and iam sending abBuffer to SourceDataLine to write output to the speakers.
Please tell me what I am doing wrong...
Thanks a million
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Priya,
Are you sure that your buffer size on the server is large enough to accommodate what the client is sending? DatagramSocket.receive() will silently truncate the received bytes if the buffer is not larger enough. Also, sound samples are usually pretty big. Are you trying to send several seconds worth at a time or are you framing it up and sending multiple packets? If you are sending multiple packets, you need some method of tagging their position since the UDP protocol does not guarantee that packets will be delivered in order or even that they will all be delivered. So for a basic streaming audio system, you really need a framing class on the client and an assembling class on the server. You also need some means for the server to request a resend for any missing or corrupted packets.
Hope this is helpful,
Michael Morris
 
Pearlo Muthukumaran
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Priya,
Methinks what u actually need is a RTP(Realtime Transmission Protocol) which nicely wraps the said functionality by Michael. This is what is used in Voice chat programs and in VoIP applications. You could take a look at JMF
(Java Media Framework) which contains packages for RTP.
Hope this pointer helps.
Rgds
Muthukumaran
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic