GeeCON Prague 2014*
The moose likes Sockets and Internet Protocols and the fly likes how to send sound buffer in UDP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "how to send sound buffer in UDP" Watch "how to send sound buffer in UDP" New topic
Author

how to send sound buffer in UDP

Priya Kubher
Greenhorn

Joined: Jan 07, 2003
Posts: 10
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

Joined: Jan 30, 2002
Posts: 3451
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


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Pearlo Muthukumaran
Ranch Hand

Joined: Sep 17, 2002
Posts: 79
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
 
GeeCON Prague 2014
 
subject: how to send sound buffer in UDP