Saturday, 7 September 2013

recording timestamps of audio samples while recording using a java applicatin

recording timestamps of audio samples while recording using a java applicatin

I've made a java audio recorder and would like to know the system
timestamp of each audio sample that I record. I am recording for 1sec at
44.1KHz. For each sample (theres 441000) I would like to record the time
(system timestamp) that the microphone detected the sound. How would I do
this, if it is possible? I would like an accuracy of +-1ms.
this is a snap shot of the code im using.
AudioFormat format = new AudioFormat(44100f, 8, 1, true, false);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
TargetDataLine line = (TargetDataLine) AudioSystem.getLine(info);
line.open(format);
line.start();
byte[] buff = new byte[line.getBufferSize()];
while(recording){
int index = line.read(buff, 0, buff.length);
out.write(buff, 0, index);
}
line.stop();
line.close();
byte[] audio = out.toByteArray();
Thanks
Edit
Getting a timestamp ever other sample, or even every 10 samples would be
ok as long as its accurate.

No comments:

Post a Comment