javax.sound.sampled
public static class: DataLine.Info [javadoc |
source]
java.lang.Object
javax.sound.sampled.Line$Info
javax.sound.sampled.DataLine$Info
Besides the class information inherited from its superclass,
DataLine.Info provides additional information specific to data lines.
This information includes:
- the audio formats supported by the data line
- the minimum and maximum sizes of its internal buffer
Because a
Line.Info knows the class of the line its describes, a
DataLine.Info object can describe
DataLine
subinterfaces such as
SourceDataLine ,
TargetDataLine , and
Clip .
You can query a mixer for lines of any of these types, passing an appropriate
instance of
DataLine.Info as the argument to a method such as
Mixer.getLine(Line.Info) .
Also see:
- Line.Info
- author:
Kara - Kytle
- since:
1.3 -
| Constructor: |
public Info(Class lineClass,
AudioFormat format) {
this(lineClass, format, AudioSystem.NOT_SPECIFIED);
}
Constructs a data line's info object from the specified information,
which includes a single audio format.
This constructor is typically used by an application to
describe a desired line. Parameters:
lineClass - the class of the data line described by the info object
format - desired format
|
public Info(Class lineClass,
AudioFormat format,
int bufferSize) {
super(lineClass);
if (format == null) {
this.formats = new AudioFormat[0];
} else {
AudioFormat[] formats = { format };
this.formats = formats;
}
this.minBufferSize = bufferSize;
this.maxBufferSize = bufferSize;
}
Constructs a data line's info object from the specified information,
which includes a single audio format and a desired buffer size.
This constructor is typically used by an application to
describe a desired line. Parameters:
lineClass - the class of the data line described by the info object
format - desired format
bufferSize - desired buffer size in bytes
|
public Info(Class lineClass,
AudioFormat[] formats,
int minBufferSize,
int maxBufferSize) {
super(lineClass);
if (formats == null) {
this.formats = new AudioFormat[0];
} else {
this.formats = formats;
}
this.minBufferSize = minBufferSize;
this.maxBufferSize = maxBufferSize;
}
Constructs a data line's info object from the specified information,
which includes a set of supported audio formats and a range for the buffer size.
This constructor is typically used by mixer implementations
when returning information about a supported line. Parameters:
lineClass - the class of the data line described by the info object
formats - set of formats supported
minBufferSize - minimum buffer size supported by the data line, in bytes
maxBufferSize - maximum buffer size supported by the data line, in bytes
|
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from javax.sound.sampled.DataLine$Info Detail: |
public AudioFormat[] getFormats() {
AudioFormat[] returnedArray = new AudioFormat[formats.length];
System.arraycopy(formats, 0, returnedArray, 0, formats.length);
return returnedArray;
}
Obtains a set of audio formats supported by the data line.
Note that isFormatSupported(AudioFormat) might return
true for certain additional formats that are missing from
the set returned by getFormats(). The reverse is not
the case: isFormatSupported(AudioFormat) is guaranteed to return
true for all formats returned by getFormats().
Some fields in the AudioFormat instances can be set to
NOT_SPECIFIED
if that field does not apply to the format,
or if the format supports a wide range of values for that field.
For example, a multi-channel device supporting up to
64 channels, could set the channel field in the
AudioFormat instances returned by this
method to NOT_SPECIFIED. |
public int getMaxBufferSize() {
return maxBufferSize;
}
Obtains the maximum buffer size supported by the data line. |
public int getMinBufferSize() {
return minBufferSize;
}
Obtains the minimum buffer size supported by the data line. |
public boolean isFormatSupported(AudioFormat format) {
for (int i = 0; i < formats.length; i++) {
if (format.matches(formats[i])) {
return true;
}
}
return false;
}
Indicates whether this data line supports a particular audio format.
The default implementation of this method simply returns true if
the specified format matches any of the supported formats. |
public boolean matches(Line.Info info) {
if (! (super.matches(info)) ) {
return false;
}
Info dataLineInfo = (Info)info;
// treat anything < 0 as NOT_SPECIFIED
// demo code in old Java Sound Demo used a wrong buffer calculation
// that would lead to arbitrary negative values
if ((getMaxBufferSize() >= 0) && (dataLineInfo.getMaxBufferSize() >= 0)) {
if (getMaxBufferSize() > dataLineInfo.getMaxBufferSize()) {
return false;
}
}
if ((getMinBufferSize() >= 0) && (dataLineInfo.getMinBufferSize() >= 0)) {
if (getMinBufferSize() < dataLineInfo.getMinBufferSize()) {
return false;
}
}
AudioFormat[] localFormats = getFormats();
if (localFormats != null) {
for (int i = 0; i < localFormats.length; i++) {
if (! (localFormats[i] == null) ) {
if (! (dataLineInfo.isFormatSupported(localFormats[i])) ) {
return false;
}
}
}
}
return true;
}
Determines whether the specified info object matches this one.
To match, the superclass match requirements must be met. In
addition, this object's minimum buffer size must be at least as
large as that of the object specified, its maximum buffer size must
be at most as large as that of the object specified, and all of its
formats must match formats supported by the object specified. |
public String toString() {
StringBuffer buf = new StringBuffer();
if ( (formats.length == 1) && (formats[0] != null) ) {
buf.append(" supporting format " + formats[0]);
} else if (getFormats().length > 1) {
buf.append(" supporting " + getFormats().length + " audio formats");
}
if ( (minBufferSize != AudioSystem.NOT_SPECIFIED) && (maxBufferSize != AudioSystem.NOT_SPECIFIED) ) {
buf.append(", and buffers of " + minBufferSize + " to " + maxBufferSize + " bytes");
} else if ( (minBufferSize != AudioSystem.NOT_SPECIFIED) && (minBufferSize > 0) ) {
buf.append(", and buffers of at least " + minBufferSize + " bytes");
} else if (maxBufferSize != AudioSystem.NOT_SPECIFIED) {
buf.append(", and buffers of up to " + minBufferSize + " bytes");
}
return new String(super.toString() + buf);
}
Obtains a textual description of the data line info. |