Skip to main content

developerWorks >  developerWorks article template feedback  >  developerWorks

Problem With Java Sound Recording!!!    Point your RSS reader here for a feed of the latest messages in this thread


     

 
 

My developerWorks
 Welcome, Guest
Sign in or register
Permlink Replies: 2 - Pages: 1 - Last Post: Mar 31, 2009 1:19 AM Last Post By: Heidi123 Threads: [ Previous | Next ]
Heidi123

Posts: 2
Registered: Mar 26, 2009 04:46:24 AM
Problem With Java Sound Recording!!!
Posted: Mar 26, 2009 05:05:55 AM
Click to report abuse...   Click to reply to this thread Reply
Problems with Java Audio Recording
Hi all,
First of all thank you for all for reading this post.. i'm new to this forum and now i need help with java audio recording...

I'm doing a project in java and for that i have to record a particular sound generated on another device and have extract data from the recorded audio signal..
Before startin in java we implemented a prototype of our project in matlab. There its working perfectly fine and the same thing we did using java. i'm using TargetDataLine object for recording it. But while we record it using java with the same audio format and time line we are getting a large number of samples when compared to that recorded using matlab. And also the range of values also differ a lot.We tried out many ways but we were not able to find the bug...

i'm attaching the code hereby

public void recordWhisper()
{
try
{
ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
DataLine.Info dataLine=new DataLine.Info(TargetDataLine.class,audioFormat);
TargetDataLine targetDataLine=(TargetDataLine)AudioSystem.getLine (dataLine);
targetDataLine.open(audioFormat);
targetDataLine.start();
byte tempBuffer[] = new byte10000;
byteArrayOutputStream =new ByteArrayOutputStream();
byte[] data;
System.out.println("sss");
while(stopCapture==false)
{
int cnt = targetDataLine.read(tempBuffer,0,tempBuffer.length );
if(cnt > 0){
byteArrayOutputStream.write(tempBuffer, 0, cnt);
}//end if
}//end while
byteArrayOutputStream.close();
data =byteArrayOutputStream.toByteArray();
audioData=new doublehttp://data.length;
for(int i=0;i<data.length;i++)
{ audioData[i]=new Byte(data[i]).doubleValue();

}

}
catch (Exception e)
{
e.printStackTrace();
System.exit(0);
}//end catch
}


is that is due to buffer overwriting or something..
can anybody suggest a method to correct it..
waiting for your sudden response
Thank you..

jackptester

Posts: 30
Registered: Jan 17, 2007 04:17:07 PM
Re: Problem With Java Sound Recording!!!
Posted: Mar 26, 2009 01:46:28 PM   in response to: Heidi123 in response to: Heidi123's post
Click to report abuse...   Click to reply to this thread Reply
I spoke with the developerWorks Java editor and she suggested using following resources for an answer to your question:

Start with the Client-side Java programming or Java Filter forums accessible from:

http://www.ibm.com/developerworks/forums/dw_jforums.jspa

Alternatively, look at the Java Sound API page at java.sun.com: http://java.sun.com/products/java-media/sound/
and view the following article: http://www.ibm.com/developerworks/java/library/j-mer0730/ (be aware of what version of Java is being used).

Hope this helps.
Heidi123

Posts: 2
Registered: Mar 26, 2009 04:46:24 AM
Re: Problem With Java Sound Recording!!!
Posted: Mar 31, 2009 01:19:34 AM   in response to: jackptester in response to: jackptester's post
Click to report abuse...   Click to reply to this thread Reply
thank you for your response..
will try it and will let u know about it
thank you once again

Point your RSS reader here for a feed of the latest messages in all forums