According to Javadocs, when I used javax.sound.sampledTargetDataLine‘s following method:
public void open(AudioFormat format,int bufferSize)
Which says:
Invoking this method with a requested buffer size that does not meet this requirement may result in an IllegalArgumentException.`
So when I implement the following Java code:
AudioFormat format = getAudioFormat();
DataLine.Info info = new DataLine.Info(TargetDataLine.class,format);
// open the TargetDataLine for capture.
try {
TargetDataLine line = (TargetDataLine) AudioSystem.getLine(info);
line.open(format, line.getBufferSize()+3000);
}
catch (LineUnavailableException ex)
{
ex.printStackTrace();
}
But when I run the above code it does not throw any exception. Now according to documentation:
public int getBufferSize()
Obtains the maximum number of bytes of data that will fit in the data line’s internal buffer. For a source data line, this is the size of the buffer to which data can be written. For a target data line, it is the size of the buffer from which data can be read. Note that the units used are bytes, but will always correspond to an integral number of sample frames of audio data.
Which says maximum size will be returned, and the I had added 3000
line.open(format, line.getBufferSize()+3000);
As show above, why does it do not throw any exception?
You left out some important descriptions from the JavaDoc for
open. More completely, it says:So, the buffer size you specify may not be the size of the internal buffer and may even exceed it.
However, it must “represent an integral number of sample frames” or it will throw
IllegalArgumentException. If you request more memory than it can allocate internally, then you’ll receiveLineUnavailableException. This doesn’t mean requesting a larger size than the current internal buffer will result inLineUnavailableException.At least that’s my reading of the docs.