本文整理汇总了Java中javax.sound.sampled.DataLine.Info方法的典型用法代码示例。如果您正苦于以下问题:Java DataLine.Info方法的具体用法?Java DataLine.Info怎么用?Java DataLine.Info使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.sampled.DataLine
的用法示例。
在下文中一共展示了DataLine.Info方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doMixerTDL
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
private static void doMixerTDL(Mixer mixer, AudioFormat format) {
if (mixer==null) return;
try {
System.out.println("TDL from mixer "+mixer+":");
DataLine.Info info = new DataLine.Info(
TargetDataLine.class,
format);
if (mixer.isLineSupported(info)) {
TargetDataLine tdl = (TargetDataLine) mixer.getLine(info);
doLine1(tdl, format);
doLine2(tdl, format);
} else {
System.out.println(" - Line not supported");
}
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
}
}
示例2: createSourceDataLine
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
private boolean createSourceDataLine() {
if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSourceDataLine()");
try {
DataLine.Info info = new DataLine.Info(SourceDataLine.class, loadedAudioFormat);
if (!(AudioSystem.isLineSupported(info)) ) {
if (DEBUG || Printer.err)Printer.err("Line not supported: "+loadedAudioFormat);
// fail silently
return false;
}
SourceDataLine source = (SourceDataLine) AudioSystem.getLine(info);
datapusher = new DataPusher(source, loadedAudioFormat, loadedAudio, loadedAudioByteLength);
} catch (Exception e) {
if (DEBUG || Printer.err)e.printStackTrace();
// fail silently
return false;
}
if (datapusher==null) {
// fail silently
return false;
}
if (DEBUG || Printer.debug)Printer.debug("Created SourceDataLine.");
return true;
}
示例3: test
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
private static void test(final AudioFormat format, final byte[] data)
throws Exception {
final Line.Info info = new DataLine.Info(Clip.class, format);
final Clip clip = (Clip) AudioSystem.getLine(info);
go = new CountDownLatch(1);
clip.addLineListener(event -> {
if (event.getType().equals(LineEvent.Type.START)) {
go.countDown();
}
});
clip.open(format, data, 0, data.length);
clip.start();
go.await();
while (clip.isRunning()) {
// This loop should not hang
}
while (clip.isActive()) {
// This loop should not hang
}
clip.close();
}
示例4: run
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
public static int run(String argv[], java.io.PrintStream out) {
String testCaseID = "LineListener2001";
log.println("===== " + testCaseID + " =====");
boolean failed = false;
Line l = null;
// get the default SourceDataLine
DataLine.Info s_info = new DataLine.Info(SourceDataLine.class, null);
Line.Info infos[] = AudioSystem.getSourceLineInfo( s_info );
if( infos.length < 1 ) {
log.println("Line.Info array == 0");
return STATUS_PASSED;
}
try {
l = AudioSystem.getLine(infos[0]);
} catch(SecurityException lue) {
log.println("SecurityException");
return STATUS_PASSED;
} catch (LineUnavailableException e1) {
log.println("LUE");
return STATUS_PASSED;
} catch (IllegalArgumentException iae) {
log.println("IllegalArgumentException should not be thrown "
+ "for supported line");
iae.printStackTrace(log);
return STATUS_FAILED;
}
out.println("Passed.");
return STATUS_PASSED;
}
示例5: main
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
boolean res = true;
try {
AudioInputStream ais = new AudioInputStream(
new ByteArrayInputStream(new byte[2000]),
new AudioFormat(8000.0f, 8, 1, false, false), 2000); //
AudioFormat format = ais.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format,
((int) ais.getFrameLength()
* format
.getFrameSize()));
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open();
FloatControl rateControl = (FloatControl) clip.getControl(
FloatControl.Type.SAMPLE_RATE);
int c = 0;
while (c++ < 10) {
clip.stop();
clip.setFramePosition(0);
clip.start();
for (float frq = 22000; frq < 44100; frq = frq + 100) {
try {
Thread.currentThread().sleep(20);
} catch (Exception e) {
break;
}
rateControl.setValue(frq);
}
}
} catch (Exception ex) {
ex.printStackTrace();
res = ex.getMessage().indexOf(
"This method should not have been invoked!") < 0;
}
if (res) {
System.out.println("Test passed");
} else {
System.out.println("Test failed");
throw new Exception("Test failed");
}
}
示例6: DirectSDL
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
private DirectSDL(DataLine.Info info,
AudioFormat format,
int bufferSize,
DirectAudioDevice mixer) {
super(info, mixer, format, bufferSize, mixer.getMixerIndex(), mixer.getDeviceID(), true);
if (Printer.trace) Printer.trace("DirectSDL CONSTRUCTOR: completed");
}
示例7: SoftMixingDataLine
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
SoftMixingDataLine(SoftMixingMixer mixer, DataLine.Info info) {
this.mixer = mixer;
this.info = info;
this.control_mutex = mixer.control_mutex;
controls = new Control[] { gain_control, mute_control, balance_control,
pan_control, reverbsend_control, chorussend_control,
apply_reverb };
calcVolume();
}
示例8: doMixerClip
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
private static void doMixerClip(Mixer mixer) throws Exception {
boolean waitedEnough=false;
try {
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip clip = (Clip) mixer.getLine(info);
clip.open(format, soundData, 0, soundData.length);
// sanity
if (clip.getMicrosecondLength()/1000 < 9900) {
throw new Exception("clip's microsecond length should be at least 9900000, but it is "+clip.getMicrosecondLength());
}
long start = System.currentTimeMillis();
System.out.println(" ---------- start --------");
clip.start();
// give time to actually start it. ALSA implementation needs that...
Thread.sleep(300);
System.out.println("drain ... ");
clip.drain();
long elapsedTime = System.currentTimeMillis() - start;
System.out.println("close ... ");
clip.close();
System.out.println("... done");
System.out.println("Playback duration: "+elapsedTime+" milliseconds.");
waitedEnough = elapsedTime >= ((clip.getMicrosecondLength() / 1000) - TOLERANCE_MS);
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
return;
}
if (!waitedEnough) {
throw new Exception("Drain did not wait long enough to play entire clip.");
}
successfulTests++;
}
示例9: commandline
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
public static void commandline(String[] subArgs) {
final Mixer mixer = AudioSystem.getMixer(null);
System.out.println("Listing audio channels...");
for(Info info: mixer.getTargetLineInfo())
{
DataLine.Info di=(DataLine.Info) info;
System.out.println("Line: "+di);
for(AudioFormat f: di.getFormats())
{
System.out.println("Supported format: "+f);
}
}
System.out.println("Listing audio channels DONE");
}
示例10: record
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
private byte[] record() throws LineUnavailableException {
AudioFormat format = AudioUtil.getAudioFormat(audioConf);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
// Checks if system supports the data line
if (!AudioSystem.isLineSupported(info)) {
LOGGER.error("Line not supported");
System.exit(0);
}
microphone = (TargetDataLine) AudioSystem.getLine(info);
microphone.open(format);
microphone.start();
LOGGER.info("Listening, tap enter to stop ...");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int numBytesRead;
byte[] data = new byte[microphone.getBufferSize() / 5];
// Begin audio capture.
microphone.start();
// Here, stopped is a global boolean set by another thread.
while (!stopped) {
// Read the next chunk of data from the TargetDataLine.
numBytesRead = microphone.read(data, 0, data.length);
// Save this chunk of data.
byteArrayOutputStream.write(data, 0, numBytesRead);
}
return byteArrayOutputStream.toByteArray();
}
示例11: createClip
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
private boolean createClip() {
if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createClip()");
try {
DataLine.Info info = new DataLine.Info(Clip.class, loadedAudioFormat);
if (!(AudioSystem.isLineSupported(info)) ) {
if (DEBUG || Printer.err)Printer.err("Clip not supported: "+loadedAudioFormat);
// fail silently
return false;
}
Object line = AudioSystem.getLine(info);
if (!(line instanceof AutoClosingClip)) {
if (DEBUG || Printer.err)Printer.err("Clip is not auto closing!"+clip);
// fail -> will try with SourceDataLine
return false;
}
clip = (AutoClosingClip) line;
clip.setAutoClosing(true);
if (DEBUG || Printer.debug) clip.addLineListener(this);
} catch (Exception e) {
if (DEBUG || Printer.err)e.printStackTrace();
// fail silently
return false;
}
if (clip==null) {
// fail silently
return false;
}
if (DEBUG || Printer.debug)Printer.debug("Loaded clip.");
return true;
}
示例12: doMixerSDL
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
private static boolean doMixerSDL(Mixer mixer, AudioFormat format) {
if (mixer==null) return false;
try {
System.out.println("Trying mixer "+mixer+":");
DataLine.Info info = new DataLine.Info(
SourceDataLine.class,
format,
(int) samplerate);
SourceDataLine sdl = (SourceDataLine) mixer.getLine(info);
System.out.println(" - got sdl: "+sdl);
System.out.println(" - open with format "+format);
sdl.open(format);
System.out.println(" - start...");
sdl.start();
System.out.println(" - write...");
sdl.write(buffer, 0, buffer.length);
Thread.sleep(200);
System.out.println(" - drain...");
sdl.drain();
System.out.println(" - stop...");
sdl.stop();
System.out.println(" - close...");
sdl.close();
System.out.println(" - closed");
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
return false;
}
return true;
}
示例13: Mic
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
public Mic(AbstractCliArgs args, Mixer mixer, AudioFormat format, int frameSamples) throws LineUnavailableException {
super();
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
t= args.platform.openTargetDataLine(mixer, info);
t.open(format, frameSamples*2);
System.out.println("Recording buffer size: "+t.getBufferSize());
}
示例14: DirectClip
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
private DirectClip(DataLine.Info info,
AudioFormat format,
int bufferSize,
DirectAudioDevice mixer) {
super(info, mixer, format, bufferSize, mixer.getMixerIndex(), mixer.getDeviceID(), true);
if (Printer.trace) Printer.trace("DirectClip CONSTRUCTOR: completed");
}
示例15: SoftMixingMixer
import javax.sound.sampled.DataLine; //导入方法依赖的package包/类
public SoftMixingMixer() {
sourceLineInfo = new javax.sound.sampled.Line.Info[2];
ArrayList<AudioFormat> formats = new ArrayList<AudioFormat>();
for (int channels = 1; channels <= 2; channels++) {
formats.add(new AudioFormat(Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED, 8, channels, channels,
AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
AudioSystem.NOT_SPECIFIED, 8, channels, channels,
AudioSystem.NOT_SPECIFIED, false));
for (int bits = 16; bits < 32; bits += 8) {
formats.add(new AudioFormat(Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED, bits, channels, channels
* bits / 8, AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
AudioSystem.NOT_SPECIFIED, bits, channels, channels
* bits / 8, AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED, bits, channels, channels
* bits / 8, AudioSystem.NOT_SPECIFIED, true));
formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
AudioSystem.NOT_SPECIFIED, bits, channels, channels
* bits / 8, AudioSystem.NOT_SPECIFIED, true));
}
formats.add(new AudioFormat(Encoding.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(Encoding.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
AudioSystem.NOT_SPECIFIED, true));
formats.add(new AudioFormat(Encoding.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(Encoding.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
AudioSystem.NOT_SPECIFIED, true));
}
AudioFormat[] formats_array = formats.toArray(new AudioFormat[formats
.size()]);
sourceLineInfo[0] = new DataLine.Info(SourceDataLine.class,
formats_array, AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED);
sourceLineInfo[1] = new DataLine.Info(Clip.class, formats_array,
AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED);
}