Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

audio varying buffer fill times

76601aa5-3859-4e40-a3e6-53e0937e3984Mar 10 2018 — edited Mar 10 2018

I have been working for a while on a realtime audio analysis application and things have been going well,  however I am currently running into problems to do with varying buffer fill times. 

I started discovering that my buffer was taking a varying time to fill, which raises alarm bells.  Using the code below:

DataLine.Info info1 = new DataLine.Info(TargetDataLine.class, format1);

  
try (TargetDataLine line = (TargetDataLine) m1.getLine(info1)) {
  line
.open(format1);
  line
.start();

  
while (!pauseInput){
  
long time1 = System.currentTimeMillis();


  
int numBytesRead1 = line.read(buffer1, 0, buffer1.length);

  
//chan1double = deinterleaveAudio(buffer1, chan1selectedchannel, chan1totalchannels);
  
long time2 = System.currentTimeMillis();
  
System.out.println(threadName + " Capture time = " + (time2-time1));
  
}
  line
.stop();

  
}

I have tried copying this to a brand new application that has no GUI and no other processes going on and sure enough this varies. If I am receiving a 48kHz stereo channel at 16bit,  and my buffer is 48000 bits, I would expect the buffer to fill up in 250ms.  However this varies between 250-259ms, but every now and then this comes back at 127ms, which is impossible unless there's some weird offset going on behind the scenes.  Can anyone see anything I am doing wrong here? 

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 7 2018
Added on Mar 10 2018
0 comments
250 views