Skip to content

Commit a3a482a

Browse files
committed
Expose buffer size
1 parent 91e534c commit a3a482a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/jvm/be/tarsos/dsp/io/jvm/AudioPlayer.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public AudioPlayer(final AudioFormat format, int bufferSize) throws LineUnavaila
7777
final DataLine.Info info = new DataLine.Info(SourceDataLine.class,format,bufferSize);
7878
this.format = format;
7979
line = (SourceDataLine) AudioSystem.getLine(info);
80-
line.open();
80+
line.open(format,bufferSize*2);
81+
System.out.println("Buffer size:" + line.getBufferSize());
8182
line.start();
8283
}
8384

@@ -88,6 +89,9 @@ public AudioPlayer(final TarsosDSPAudioFormat format) throws LineUnavailableExce
8889
this(JVMAudioInputStream.toAudioFormat(format));
8990
}
9091

92+
public long getMicroSecondPosition(){
93+
return line.getMicrosecondPosition();
94+
}
9195

9296
@Override
9397
public boolean process(AudioEvent audioEvent) {
@@ -99,6 +103,14 @@ public boolean process(AudioEvent audioEvent) {
99103
}
100104
// overlap in samples * nr of bytes / sample = bytes overlap
101105

106+
/*
107+
if(byteStepSize < line.available()){
108+
System.out.println(line.available() + " Will not block " + line.getMicrosecondPosition());
109+
}else {
110+
System.out.println("Will block " + line.getMicrosecondPosition());
111+
}
112+
*/
113+
102114
int bytesWritten = line.write(audioEvent.getByteBuffer(), byteOverlap, byteStepSize);
103115
if(bytesWritten != byteStepSize){
104116
System.err.println(String.format("Expected to write %d bytes but only wrote %d bytes",byteStepSize,bytesWritten));

0 commit comments

Comments
 (0)