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?