當前位置: 首頁>>代碼示例>>Java>>正文


Java AudioSystem.isLineSupported方法代碼示例

本文整理匯總了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);

    }
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:20,代碼來源:VirtualDrummerMicrophoneInput.java

示例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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:JavaSoundAudioClip.java

示例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;
	}
}
 
開發者ID:CognitiveModeling,項目名稱:BrainControl,代碼行數:40,代碼來源:Microphone.java

示例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();
}
 
開發者ID:mautini,項目名稱:google-assistant-java-demo,代碼行數:34,代碼來源:AudioRecorder.java

示例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;
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:35,代碼來源:JavaSoundAudioClip.java

示例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);
    }
}
 
開發者ID:ksg14,項目名稱:duncan,代碼行數:32,代碼來源:SoundRecordingUtil.java

示例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!");
	}
}
 
開發者ID:RalleYTN,項目名稱:SimpleAudio,代碼行數:32,代碼來源:Recorder.java


注:本文中的javax.sound.sampled.AudioSystem.isLineSupported方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。