类javax.sound.sampled.TargetDataLine源码实例Demo

下面列出了怎么用javax.sound.sampled.TargetDataLine的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: dragonwell8_jdk   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码2 项目: TencentKona-8   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码3 项目: chart-fx   文件: TestDataSetSource.java
protected void openLineIn() {
    final AudioFormat format = new AudioFormat(samplingRate, N_SYNTHESISER_BITS, 1, true, true);
    final DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);

    // checks if system supports the data line
    if (!AudioSystem.isLineSupported(info)) {
        LOGGER.atError().addArgument(info).addArgument(format).log("Line not supported '{}' format was '{}'");
        throw new IllegalArgumentException("Line not supported");
    }

    try {
        line = (TargetDataLine) AudioSystem.getLine(info);
        line.open(format);
        if (LOGGER.isInfoEnabled()) {
            LOGGER.atInfo().log("opened audio line-in, format = " + format);
        }
    } catch (final LineUnavailableException e) {
        LOGGER.atError().setCause(e).addArgument(DATA_SOURCE_FILE).log("'{}' does not seem to be recognised as a Midi file");
    }
}
 
源代码4 项目: oim-fx   文件: VoicePlay.java
public VoicePlay() {

		try {

			format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100.0f, 16, 1, 2, 44100.0f, false);
			DataLine.Info listenInfo = new DataLine.Info(TargetDataLine.class, format);
			boolean l = AudioSystem.isLineSupported(listenInfo);
			if (l) {
				listenLine = (TargetDataLine) AudioSystem.getLine(listenInfo);
			}

			DataLine.Info playInfo = new DataLine.Info(SourceDataLine.class, format);
			boolean p = AudioSystem.isLineSupported(listenInfo);
			if (p) {
				playLine = (SourceDataLine) AudioSystem.getLine(playInfo);
			}
			lineSupported = l && p;
		} catch (LineUnavailableException e) {
			e.printStackTrace();
		}
	}
 
源代码5 项目: jdk8u60   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码6 项目: openjdk-jdk8u   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码7 项目: openjdk-jdk8u-backup   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码8 项目: Bytecoder   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class<?> typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码9 项目: openjdk-jdk9   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class<?> typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码10 项目: openjdk-jdk9   文件: LineDefFormat.java
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());
    }
}
 
源代码11 项目: jdk8u-jdk   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码12 项目: hottub   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码13 项目: openjdk-8-source   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String value;
    String propertyName = typeClass.getName();
    value = JSSecurityManager.getProperty(propertyName);
    if (value == null) {
        value = getProperties().getProperty(propertyName);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码14 项目: openjdk-8   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String value;
    String propertyName = typeClass.getName();
    value = JSSecurityManager.getProperty(propertyName);
    if (value == null) {
        value = getProperties().getProperty(propertyName);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码15 项目: jdk8u_jdk   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码16 项目: jdk8u-jdk   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码17 项目: jdk8u-dev-jdk   文件: JDK13Services.java
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
源代码18 项目: jsyn   文件: JavaSoundAudioDevice.java
@Override
public void start() {
    DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
    if (!AudioSystem.isLineSupported(info)) {
        // Handle the error.
        logger.severe("JavaSoundInputStream - not supported." + format);
    } else {
        try {
            line = (TargetDataLine) getDataLine(info);
            int bufferSize = calculateBufferSize(suggestedInputLatency);
            line.open(format, bufferSize);
            logger.fine("Input buffer size = " + bufferSize + " bytes.");
            line.start();
        } catch (Exception e) {
            e.printStackTrace();
            line = null;
        }
    }
}
 
源代码19 项目: jsyn   文件: JavaSoundAudioDevice.java
@Override
public void start() {
    DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
    if (!AudioSystem.isLineSupported(info)) {
        // Handle the error.
        logger.severe("JavaSoundInputStream - not supported." + format);
    } else {
        try {
            line = (TargetDataLine) getDataLine(info);
            int bufferSize = calculateBufferSize(suggestedInputLatency);
            line.open(format, bufferSize);
            logger.fine("Input buffer size = " + bufferSize + " bytes.");
            line.start();
        } catch (Exception e) {
            e.printStackTrace();
            line = null;
        }
    }
}
 
源代码20 项目: cloudExplorer   文件: SoundRecorderThread.java
public void run() {
    try {
        AudioFormat format = getAudioFormat();
        DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
        if (!AudioSystem.isLineSupported(info)) {
            NewJFrame.jTextArea1.append("\nError: Line not supported");
            calibrateTextArea();
        } else {
            line = (TargetDataLine) AudioSystem.getLine(info);
            line.open(format);
            line.start();
            NewJFrame.jTextArea1.append("\nRecording has started.");
            calibrateTextArea();
            AudioInputStream ais = new AudioInputStream(line);
            File wavFile = new File(temp_file);
            AudioSystem.write(ais, fileType, wavFile);
        }
    } catch (Exception recording) {
        NewJFrame.jTextArea1.append("\n" + recording.getMessage());
    }
}
 
源代码21 项目: attach   文件: DesktopAudioRecordingService.java
public TimedAudioCapture(TargetDataLine line, AudioFormat format, int chunk) {
    this.format = format;
    thread = new Thread(() -> {
        try {
            isRunning = line != null;
            final String fileName = String.format("audioFile-%03d-%s", chunk, LocalDateTime.now().format(pattern));
            if (debug) {
                LOG.log(Level.INFO, String.format("Start recording chunk %d", chunk));
            }

            byte[] buffer = new byte[BUFFER_SIZE];
            recordBytes = new ByteArrayOutputStream();
            while (isRunning && line != null) {
                int bytesRead = line.read(buffer, 0, buffer.length);
                recordBytes.write(buffer, 0, bytesRead);
            }

            if (debug) {
                LOG.log(Level.INFO, String.format("Save recorded chunk %d", chunk));
            }
            save(fileName);
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, "Error in timedAudioCapture ", ex);
        }
    });
    thread.setName("TimedAudioCapture");
}
 
源代码22 项目: google-assistant-java-demo   文件: AudioRecorder.java
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();
}
 
源代码23 项目: openjdk-jdk9   文件: ClipOpenException.java
public static void test(Line line) {
    for (int format = 0; format < formats.length; format++) {
        try {
            println("  Opening the line with format "+(format+1));
            if (line instanceof Clip) {
                ((Clip) line).open(formats[format], audioData, 0, audioData.length);
            } else
            if (line instanceof SourceDataLine) {
                ((SourceDataLine) line).open(formats[format]);
            } else
            if (line instanceof TargetDataLine) {
                ((TargetDataLine) line).open(formats[format]);
            } else {
                println("    Unknown type of line: "+line.getClass());
                return;
            }
            println("    No exception! not OK.");
            failed = true;
        } catch (IllegalArgumentException iae) {
            println("    IllegalArgumentException: "+iae.getMessage());
            println("    OK");
        } catch (LineUnavailableException lue) {
            println("    LineUnavailableException: "+lue.getMessage());
            println("    Probably incorrect, but may happen if the test system is correctly set up.");
        } catch (Exception e) {
            println("    Unexpected Exception: "+e.toString());
            println("    NOT OK!");
            failed = true;
        }
        println("    Closing line.");
        line.close();
    }
}
 
源代码24 项目: aws-doc-sdk-examples   文件: Microphone.java
public static TargetDataLine get() throws Exception {
    AudioFormat format = new AudioFormat(16000, 16, 1, true, false);
    DataLine.Info datalineInfo = new DataLine.Info(TargetDataLine.class, format);

    TargetDataLine dataLine = (TargetDataLine) AudioSystem.getLine(datalineInfo);
    dataLine.open(format);

    return dataLine;
}
 
public static TargetDataLine get() throws Exception {
    AudioFormat format = new AudioFormat(16000, 16, 1, true, false);
    DataLine.Info datalineInfo = new DataLine.Info(TargetDataLine.class, format);

    TargetDataLine dataLine = (TargetDataLine) AudioSystem.getLine(datalineInfo);
    dataLine.open(format);

    return dataLine;
}
 
源代码26 项目: jtransc   文件: Issue246.java
static private void soundSampled(
	TargetDataLine tdl,
	AudioFormat.Encoding afe,
	AudioFormat af,
	AudioSystem as
) {
}
 
源代码27 项目: jmg   文件: SimpleAudioRecorder.java
public SimpleAudioRecorder(TargetDataLine line,
			     AudioFileFormat.Type targetType,
			     File file)
{
	m_line = line;
	m_audioInputStream = new AudioInputStream(line);
	m_targetType = targetType;
	m_outputFile = file;
}
 
源代码28 项目: Quelea   文件: RecordingsHandler.java
/**
 * Initialize a new recording. Captures the sound and saves it to a WAV file
 *
 * @param pb
 * @param textField
 * @param tb
 */
public void start(ProgressBar pb, TextField textField, ToggleButton tb) {
    try {
        isRecording = true;
        String fileName = timeStamp;
        wavFile = new File(path, fileName + ".wav");
        Platform.runLater(() -> {
            textField.setText(fileName);
        });
        format = getAudioFormat();
        DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);

        // checks if system supports the data line
        if (AudioSystem.isLineSupported(info)) {
            LOGGER.log(Level.INFO, "Capturing audio");
            targetLine = (TargetDataLine) AudioSystem.getLine(info);
            targetLine.open(format);
            targetLine.start();   // start capturing
            ais = new AudioInputStream(targetLine);
            startBuffering(pb, tb);
        } else {
            LOGGER.log(Level.INFO, "No recording device found");
            Platform.runLater(() -> {
                Dialog.Builder setRecordingWarningBuilder = new Dialog.Builder()
                        .create()
                        .setTitle(LabelGrabber.INSTANCE.getLabel("recording.no.devices.title"))
                        .setMessage(LabelGrabber.INSTANCE.getLabel("recording.no.devices.message"))
                        .addLabelledButton(LabelGrabber.INSTANCE.getLabel("ok.button"), (ActionEvent t) -> {
                            noDevicesDialog.hide();
                            noDevicesDialog = null;
                        });
                noDevicesDialog = setRecordingWarningBuilder.setWarningIcon().build();
                noDevicesDialog.show();
            });
            Platform.runLater(() -> {
                QueleaApp.get().getMainWindow().getMainToolbar().stopRecording();
            });
        }
    } catch (LineUnavailableException ex) {
        LOGGER.log(Level.WARNING, "Line unavailable", ex);
    }
}
 
源代码29 项目: openjdk-jdk9   文件: DefaultMixers.java
private static boolean testMixer(Mixer mixer, Class lineType,
                                 String providerClassName,
                                 String instanceName) {
    boolean allOk = true;

    try {
        String propertyValue = (providerClassName != null) ? providerClassName: "" ;
        propertyValue += "#" + instanceName;
        out("property value: " + propertyValue);
        System.setProperty(lineType.getName(), propertyValue);
        Line line = null;
        Line.Info info = null;
        Line.Info[] infos;
        AudioFormat format = null;
        if (lineType == SourceDataLine.class || lineType == Clip.class) {
            infos = mixer.getSourceLineInfo();
            format = getFirstLinearFormat(infos);
            info = new DataLine.Info(lineType, format);
        } else if (lineType == TargetDataLine.class) {
            infos = mixer.getTargetLineInfo();
            format = getFirstLinearFormat(infos);
            info = new DataLine.Info(lineType, format);
        } else if (lineType == Port.class) {
            /* Actually, a Ports Mixer commonly has source infos
               as well as target infos. We ignore this here, since we
               just need a random one. */
            infos = mixer.getSourceLineInfo();
            for (int i = 0; i < infos.length; i++) {
                if (infos[i] instanceof Port.Info) {
                    info = infos[i];
                    break;
                }
            }
        }
        out("Line.Info: " + info);
        line = AudioSystem.getLine(info);
        out("line: " + line);
        if (! lineType.isInstance(line)) {
            out("type " + lineType + " failed: class should be '" +
                lineType + "' but is '" + line.getClass() + "'!");
            allOk = false;
        }
    } catch (Exception e) {
        out("Exception thrown; Test NOT failed.");
        e.printStackTrace();
    }
    return allOk;
}
 
源代码30 项目: openjdk-jdk9   文件: Has16and32KHz.java
public static void showMixerLines(Line.Info[] lineinfo) {
    for (int j = 0; j < lineinfo.length; j++) {
        boolean isSDL=false; // SourceDataLine
        Line.Info thisInfo=lineinfo[j];
        System.out.println("  " + thisInfo);
        String impl="";
        if (thisInfo.getLineClass().equals(SourceDataLine.class)) {
            isSDL=true;
            impl+="SourceDataLine";
        }
        if (thisInfo.getLineClass().equals(Clip.class)) {
            impl+="Clip";
        }
        if (thisInfo.getLineClass().equals(DataLine.class)) {
            impl+="DataLine";
        }
        if (thisInfo.getLineClass().equals(TargetDataLine.class)) {
            impl+="TargetDataLine";
        }
        if (thisInfo.getLineClass().equals(Mixer.class)) {
            impl+="Mixer";
        }
        System.out.println("  implements "+impl);
        try {
            AudioFormat[] formats = ((DataLine.Info)lineinfo[j]).getFormats();
            for (int k = 0; k < formats.length; k++) {
                System.out.println("    " + formats[k] + ", "+ formats[k].getFrameSize()+" bytes/frame");
                if (isSDL) {
                    if ((formats[k].getSampleRate()==AudioSystem.NOT_SPECIFIED)
                        || (formats[k].getSampleRate()==32000.0f)) {
                        ok32=true;
                    }
                    if ((formats[k].getSampleRate()==AudioSystem.NOT_SPECIFIED)
                        || (formats[k].getSampleRate()==16000.0f)) {
                        ok16=true;
                    }
                }
            }
        } catch (ClassCastException e) {
        }
    }
}