001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.sound.sampled;
019:
020: public interface DataLine extends Line {
021:
022: class Info extends Line.Info {
023: private AudioFormat[] formats;
024: private int minBufferSize;
025: private int maxBufferSize;
026:
027: public Info(Class<?> lineClass, AudioFormat format) {
028: super (lineClass);
029:
030: this .formats = new AudioFormat[] { format };
031: this .minBufferSize = AudioSystem.NOT_SPECIFIED;
032: this .maxBufferSize = AudioSystem.NOT_SPECIFIED;
033: }
034:
035: public Info(Class<?> lineClass, AudioFormat[] formats,
036: int minBufferSize, int maxBufferSize) {
037: super (lineClass);
038:
039: this .formats = formats;
040: this .minBufferSize = minBufferSize;
041: this .maxBufferSize = maxBufferSize;
042: }
043:
044: public Info(Class<?> lineClass, AudioFormat format,
045: int bufferSize) {
046: super (lineClass);
047:
048: this .formats = new AudioFormat[] { format };
049: this .minBufferSize = bufferSize;
050: this .maxBufferSize = bufferSize;
051: }
052:
053: public AudioFormat[] getFormats() {
054: return formats;
055: }
056:
057: public boolean isFormatSupported(AudioFormat format) {
058: if (formats == null) {
059: return false;
060: }
061: for (AudioFormat supported : formats) {
062: if (format.matches(supported)) {
063: return true;
064: }
065: }
066: return false;
067: }
068:
069: public int getMinBufferSize() {
070: return minBufferSize;
071: }
072:
073: public int getMaxBufferSize() {
074: return maxBufferSize;
075: }
076:
077: @Override
078: public boolean matches(Line.Info info) {
079:
080: if (!super .matches(info)) {
081: return false;
082: }
083:
084: DataLine.Info inf = (DataLine.Info) info;
085: if ((minBufferSize != AudioSystem.NOT_SPECIFIED
086: && inf.getMinBufferSize() != AudioSystem.NOT_SPECIFIED && minBufferSize < inf
087: .getMinBufferSize())
088: || (maxBufferSize != AudioSystem.NOT_SPECIFIED
089: && inf.getMaxBufferSize() != AudioSystem.NOT_SPECIFIED && maxBufferSize > inf
090: .getMaxBufferSize())) {
091: return false;
092: }
093:
094: for (AudioFormat supported : formats) {
095: if (!inf.isFormatSupported(supported)) {
096: return false;
097: }
098: }
099:
100: return true;
101: }
102:
103: @Override
104: public String toString() {
105: String formatStr = (formats.length == 1 ? "format " + formats[0].toString() //$NON-NLS-1$
106: : formats.length + " audio formats"); //$NON-NLS-1$
107: String bufStr = ""; //$NON-NLS-1$
108: if (minBufferSize != AudioSystem.NOT_SPECIFIED) {
109: bufStr = "and buffers of " + minBufferSize + //$NON-NLS-1$
110: " to " + maxBufferSize + " bytes"; //$NON-NLS-1$ //$NON-NLS-2$
111: }
112: return getLineClass()
113: + " supporting " + formatStr + ", " + bufStr; //$NON-NLS-1$
114: }
115: }
116:
117: int available();
118:
119: void drain();
120:
121: void flush();
122:
123: int getBufferSize();
124:
125: AudioFormat getFormat();
126:
127: int getFramePosition();
128:
129: float getLevel();
130:
131: long getLongFramePosition();
132:
133: long getMicrosecondPosition();
134:
135: boolean isActive();
136:
137: boolean isRunning();
138:
139: void start();
140:
141: void stop();
142: }
|