本文整理汇总了Java中javax.sound.sampled.AudioSystem.isLineSupported方法的典型用法代码示例。如果您正苦于以下问题:Java AudioSystem.isLineSupported方法的具体用法?Java AudioSystem.isLineSupported怎么用?Java AudioSystem.isLineSupported使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.sampled.AudioSystem
的用法示例。
在下文中一共展示了AudioSystem.isLineSupported方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: VirtualDrummerMicrophoneInput
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/** Creates a new instance of test. Opens the microphone input as the target line.
* To start the reporting, {@link #start} the thread.
* @throws LineUnavailableException if microphone input is not available
*/
public VirtualDrummerMicrophoneInput () throws LineUnavailableException{
// getAudioInfo(); // prints lots of useless information
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,sampleRate,8,1,1,sampleRate,false);
DataLine.Info dlinfo = new DataLine.Info(TargetDataLine.class,
format);
if ( AudioSystem.isLineSupported(dlinfo) ){
targetDataLine = (TargetDataLine)AudioSystem.getLine(dlinfo);
}
targetDataLine.open(format,bufferSize);
bufferSize=targetDataLine.getBufferSize();
gui = new DrumSoundDetectorDemo();
gui.setVirtualDrummerMicrophoneInput(this);
}
示例2: createSourceDataLine
import javax.sound.sampled.AudioSystem; //导入方法依赖的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: initialize
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
* Constructs a Microphone with the given InputStream.
*/
@Override
public void initialize() {
super.initialize();
audioList = new LinkedBlockingQueue<Data>();
DataLine.Info info = new DataLine.Info(TargetDataLine.class, desiredFormat);
/*
* If we cannot get an audio line that matches the desired
* characteristics, shoot for one that matches almost everything we
* want, but has a higher sample rate.
*/
if (!AudioSystem.isLineSupported(info)) {
logger.info(desiredFormat + " not supported");
AudioFormat nativeFormat = DataUtil.getNativeAudioFormat(desiredFormat, getSelectedMixer());
if (nativeFormat == null) {
logger.severe("couldn't find suitable target audio format");
} else {
finalFormat = nativeFormat;
/* convert from native to the desired format if supported */
doConversion = AudioSystem.isConversionSupported(desiredFormat, nativeFormat);
if (doConversion) {
logger.info("Converting from " + finalFormat.getSampleRate() + "Hz to "
+ desiredFormat.getSampleRate() + "Hz");
} else {
logger.info("Using native format: Cannot convert from " + finalFormat.getSampleRate() + "Hz to "
+ desiredFormat.getSampleRate() + "Hz");
}
}
} else {
logger.info("Desired format: " + desiredFormat + " supported.");
finalFormat = desiredFormat;
}
}
示例4: record
import javax.sound.sampled.AudioSystem; //导入方法依赖的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();
}
示例5: createClip
import javax.sound.sampled.AudioSystem; //导入方法依赖的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;
}
示例6: start
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
* Start recording sound.
* @throws LineUnavailableException if the system does not support the specified
* audio format nor open the audio data line.
*/
public void start() throws LineUnavailableException {
format = getAudioFormat();
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
// checks if system supports the data line
if (!AudioSystem.isLineSupported(info)) {
throw new LineUnavailableException(
"The system does not support the specified format.");
}
audioLine = AudioSystem.getTargetDataLine(format);
audioLine.open(format);
audioLine.start();
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = 0;
recordBytes = new ByteArrayOutputStream();
isRunning = true;
while (isRunning) {
bytesRead = audioLine.read(buffer, 0, buffer.length);
recordBytes.write(buffer, 0, bytesRead);
}
}
示例7: Recorder
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
* @param fileFormat the file format to use
* @param audioFormat the audio format to use
* @throws AudioException if something went wrong while initializing the recorder
* @since 1.0.0
*/
public Recorder(FileFormat fileFormat, AudioFormat audioFormat) throws AudioException {
if(fileFormat.isWritingSupported()) {
DataLine.Info info = new DataLine.Info(TargetDataLine.class, this.audioFormat);
if(AudioSystem.isLineSupported(info)) {
try {
this.line = (TargetDataLine)AudioSystem.getLine(info);
this.fileFormat = fileFormat;
this.audioFormat = audioFormat;
} catch(Exception exception) {
throw new AudioException(exception);
}
}
} else {
throw new AudioException("The given file format does not support writing!");
}
}