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 byte
10000;
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 double
http://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..