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

项目:java-google-speech-api    文件:GSpeechDuplex.java   
/**
 * Streams data from the TargetDataLine to the API.
 * 
 * @param urlStr
 *            The URL to stream to
 * @param tl
 *            The target data line to stream from.
 * @param af
 *            The AudioFormat to stream with.`
 * @throws LineUnavailableException
 *             If cannot open or stream the TargetDataLine.
 */
private Thread upChannel(String urlStr , TargetDataLine tl , AudioFormat af) throws LineUnavailableException {
    final String murl = urlStr;
    final TargetDataLine mtl = tl;
    final AudioFormat maf = af;
    if (!mtl.isOpen()) {
        mtl.open(maf);
        mtl.start();
    }
    Thread upChannelThread = new Thread("Upstream Thread") {
        public void run() {
            openHttpsPostConnection(murl, mtl, (int) maf.getSampleRate());
        }
    };
    upChannelThread.start();
    return upChannelThread;

}
项目:jaer    文件:VirtualDrummerMicrophoneInput.java   
/** 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);

    }
项目:OpenJSharp    文件: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;
}
项目: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;
}
项目:openjdk-jdk10    文件: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;
}
项目:openjdk-jdk10    文件: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());
    }
}
项目:openjdk9    文件: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;
}
项目:screencast4j    文件:SampledSoundRecorder.java   
@Override
 public String setUp() {
   String   result;

   result = super.setUp();

   if (result == null) {
     m_AudioFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
m_Frequency, 16, 2, 4, m_Frequency, false);
     m_DataLineInfo = new DataLine.Info(TargetDataLine.class, m_AudioFormat);
     try {
m_TargetDataLine = (TargetDataLine) AudioSystem.getLine(m_DataLineInfo);
m_TargetDataLine.open(m_AudioFormat);
     }
     catch (Exception e) {
return "Unable to get recording line: " + Utils.throwableToString(e);
     }
     m_AudioInputStream = new AudioInputStream(m_TargetDataLine);
   }

   return result;
 }
项目: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;
}
项目:lookaside_java-1.8.0-openjdk    文件: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;
}
项目:cloudturbine    文件:AudioStream.java   
/**
 * Implementation of the abstract start() method from DataStream
 */
public void start() throws Exception {
    if (queue != null) { throw new Exception("ERROR in AudioStream.start(): LinkedBlockingQueue object is not null"); }
    // Make sure we can open the audio line
    try {
        format = getFormat();
        DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
        line = (TargetDataLine) AudioSystem.getLine(info);
        line.open(format);
        line.start();
    } catch (LineUnavailableException e) {
        throw new Exception("Audio stream error, could not open the audio line:\n" + e.getMessage());
    }
    bIsRunning = true;
    // Make sure there is no other audio capture running
    stopAudio();
    queue = new LinkedBlockingQueue<TimeValue>();
    // start the audio capture
    audioThread = new Thread(this);
    audioThread.start();
    updatePreview();
}
项目:Tuntuni    文件:MicrophoneAudio.java   
@Override
public void start() {
    try {
        // start target line
        mTargetInfo = new DataLine.Info(
                TargetDataLine.class, VideoFormat.getAudioFormat());
        mTargetLine = (TargetDataLine) AudioSystem.getLine(mTargetInfo);
        mTargetLine.open(VideoFormat.getAudioFormat());
        // start audio thread
        mAudioThread = new Thread(this);
        mAudioThread.setDaemon(true);
        mAudioThread.start();
    } catch (LineUnavailableException ex) {
        Logs.error(getClass(), "Failed to open. {0}", ex);
    }
}
项目:SpeechRaspberrySmartHouse    文件:GSpeechDuplex.java   
/**
 * This method allows you to stream a continuous stream of data to the API.
 * <p>
 * Note: This feature is experimental.</p>
 *
 * @param tl
 * @param af
 * @throws IOException
 * @throws LineUnavailableException
 */
public void recognize(TargetDataLine tl, AudioFormat af) throws IOException, LineUnavailableException {
    //Generates a unique ID for the response. 
    final long PAIR = MIN + (long) (Math.random() * ((MAX - MIN) + 1L));

    //Generates the Downstream URL
    final String API_DOWN_URL = GOOGLE_DUPLEX_SPEECH_BASE + "down?maxresults=1&pair=" + PAIR;

    //Generates the Upstream URL
    final String API_UP_URL = GOOGLE_DUPLEX_SPEECH_BASE
            + "up?lang=" + language + "&lm=dictation&client=chromium&pair=" + PAIR
            + "&key=" + API_KEY + "&continuous=true&interim=true"; //Tells Google to constantly monitor the stream;

    //Opens downChannel
    this.downChannel(API_DOWN_URL);

    //Opens upChannel
    this.upChannel(API_UP_URL, tl, af);
}
项目:SpeechRaspberrySmartHouse    文件:GSpeechDuplex.java   
/**
 * This method allows you to stream a continuous stream of data to the API.
 * <p>
 * Note: This feature is experimental.</p>
 *
 * @param tl
 * @param af
 * @throws IOException
 * @throws LineUnavailableException
 */
public void recognize(TargetDataLine tl, AudioFormat af) throws IOException, LineUnavailableException {
    //Generates a unique ID for the response. 
    final long PAIR = MIN + (long) (Math.random() * ((MAX - MIN) + 1L));

    //Generates the Downstream URL
    final String API_DOWN_URL = GOOGLE_DUPLEX_SPEECH_BASE + "down?maxresults=1&pair=" + PAIR;

    //Generates the Upstream URL
    final String API_UP_URL = GOOGLE_DUPLEX_SPEECH_BASE
            + "up?lang=" + language + "&lm=dictation&client=chromium&pair=" + PAIR
            + "&key=" + API_KEY + "&continuous=true&interim=true"; //Tells Google to constantly monitor the stream;

    //Opens downChannel
    this.downChannel(API_DOWN_URL);

    //Opens upChannel
    this.upChannel(API_UP_URL, tl, af);
}
项目:SpeechRaspberrySmartHouse    文件:GSpeechDuplex.java   
/**
 * This method allows you to stream a continuous stream of data to the API.
 * <p>
 * Note: This feature is experimental.</p>
 *
 * @param tl
 * @param af
 * @throws IOException
 * @throws LineUnavailableException
 */
public void recognize(TargetDataLine tl, AudioFormat af) throws IOException, LineUnavailableException {
    //Generates a unique ID for the response. 
    final long PAIR = MIN + (long) (Math.random() * ((MAX - MIN) + 1L));

    //Generates the Downstream URL
    final String API_DOWN_URL = GOOGLE_DUPLEX_SPEECH_BASE + "down?maxresults=1&pair=" + PAIR;

    //Generates the Upstream URL
    final String API_UP_URL = GOOGLE_DUPLEX_SPEECH_BASE
            + "up?lang=" + language + "&lm=dictation&client=chromium&pair=" + PAIR
            + "&key=" + API_KEY + "&continuous=true&interim=true"; //Tells Google to constantly monitor the stream;

    //Opens downChannel
    this.downChannel(API_DOWN_URL);

    //Opens upChannel
    this.upChannel(API_UP_URL, tl, af);
}
项目:SpeechRaspberrySmartHouse    文件:GSpeechDuplex.java   
/**
 * This method allows you to stream a continuous stream of data to the API.
 * <p>
 * Note: This feature is experimental.</p>
 *
 * @param tl
 * @param af
 * @throws IOException
 * @throws LineUnavailableException
 */
public void recognize(TargetDataLine tl, AudioFormat af) throws IOException, LineUnavailableException {
    //Generates a unique ID for the response. 
    final long PAIR = MIN + (long) (Math.random() * ((MAX - MIN) + 1L));

    //Generates the Downstream URL
    final String API_DOWN_URL = GOOGLE_DUPLEX_SPEECH_BASE + "down?maxresults=1&pair=" + PAIR;

    //Generates the Upstream URL
    final String API_UP_URL = GOOGLE_DUPLEX_SPEECH_BASE
            + "up?lang=" + language + "&lm=dictation&client=chromium&pair=" + PAIR
            + "&key=" + API_KEY + "&continuous=true&interim=true"; //Tells Google to constantly monitor the stream;

    //Opens downChannel
    this.downChannel(API_DOWN_URL);

    //Opens upChannel
    this.upChannel(API_UP_URL, tl, af);
}
项目:SpeechRaspberrySmartHouse    文件:GSpeechDuplex.java   
/**
 * This method allows you to stream a continuous stream of data to the API.
 * <p>
 * Note: This feature is experimental.</p>
 *
 * @param tl
 * @param af
 * @throws IOException
 * @throws LineUnavailableException
 */
public void recognize(TargetDataLine tl, AudioFormat af) throws IOException, LineUnavailableException {
    //Generates a unique ID for the response. 
    final long PAIR = MIN + (long) (Math.random() * ((MAX - MIN) + 1L));

    //Generates the Downstream URL
    final String API_DOWN_URL = GOOGLE_DUPLEX_SPEECH_BASE + "down?maxresults=1&pair=" + PAIR;

    //Generates the Upstream URL
    final String API_UP_URL = GOOGLE_DUPLEX_SPEECH_BASE
            + "up?lang=" + language + "&lm=dictation&client=chromium&pair=" + PAIR
            + "&key=" + API_KEY + "&continuous=true&interim=true"; //Tells Google to constantly monitor the stream;

    //Opens downChannel
    this.downChannel(API_DOWN_URL);

    //Opens upChannel
    this.upChannel(API_UP_URL, tl, af);
}
项目:SpeechRaspberrySmartHouse    文件:GSpeechDuplex.java   
/**
 * This method allows you to stream a continuous stream of data to the API.
 * <p>
 * Note: This feature is experimental.</p>
 *
 * @param tl
 * @param af
 * @throws IOException
 * @throws LineUnavailableException
 */
public void recognize(TargetDataLine tl, AudioFormat af) throws IOException, LineUnavailableException {
    //Generates a unique ID for the response. 
    final long PAIR = MIN + (long) (Math.random() * ((MAX - MIN) + 1L));

    //Generates the Downstream URL
    final String API_DOWN_URL = GOOGLE_DUPLEX_SPEECH_BASE + "down?maxresults=1&pair=" + PAIR;

    //Generates the Upstream URL
    final String API_UP_URL = GOOGLE_DUPLEX_SPEECH_BASE
            + "up?lang=" + language + "&lm=dictation&client=chromium&pair=" + PAIR
            + "&key=" + API_KEY + "&continuous=true&interim=true"; //Tells Google to constantly monitor the stream;

    //Opens downChannel
    this.downChannel(API_DOWN_URL);

    //Opens upChannel
    this.upChannel(API_UP_URL, tl, af);
}
项目:SpeechRaspberrySmartHouse    文件:GSpeechDuplex.java   
/**
 * This method allows you to stream a continuous stream of data to the API.
 * <p>
 * Note: This feature is experimental.</p>
 *
 * @param tl
 * @param af
 * @throws IOException
 * @throws LineUnavailableException
 */
public void recognize(TargetDataLine tl, AudioFormat af) throws IOException, LineUnavailableException {
    //Generates a unique ID for the response. 
    final long PAIR = MIN + (long) (Math.random() * ((MAX - MIN) + 1L));

    //Generates the Downstream URL
    final String API_DOWN_URL = GOOGLE_DUPLEX_SPEECH_BASE + "down?maxresults=1&pair=" + PAIR;

    //Generates the Upstream URL
    final String API_UP_URL = GOOGLE_DUPLEX_SPEECH_BASE
            + "up?lang=" + language + "&lm=dictation&client=chromium&pair=" + PAIR
            + "&key=" + API_KEY + "&continuous=true&interim=true"; //Tells Google to constantly monitor the stream;

    //Opens downChannel
    this.downChannel(API_DOWN_URL);

    //Opens upChannel
    this.upChannel(API_UP_URL, tl, af);
}
项目:SpeechRaspberrySmartHouse    文件:GSpeechDuplex.java   
/**
 * This method allows you to stream a continuous stream of data to the API.
 * <p>
 * Note: This feature is experimental.</p>
 *
 * @param tl
 * @param af
 * @throws IOException
 * @throws LineUnavailableException
 */
public void recognize(TargetDataLine tl, AudioFormat af) throws IOException, LineUnavailableException {
    //Generates a unique ID for the response. 
    final long PAIR = MIN + (long) (Math.random() * ((MAX - MIN) + 1L));

    //Generates the Downstream URL
    final String API_DOWN_URL = GOOGLE_DUPLEX_SPEECH_BASE + "down?maxresults=1&pair=" + PAIR;

    //Generates the Upstream URL
    final String API_UP_URL = GOOGLE_DUPLEX_SPEECH_BASE
            + "up?lang=" + language + "&lm=dictation&client=chromium&pair=" + PAIR
            + "&key=" + API_KEY + "&continuous=true&interim=true"; //Tells Google to constantly monitor the stream;

    //Opens downChannel
    this.downChannel(API_DOWN_URL);

    //Opens upChannel
    this.upChannel(API_UP_URL, tl, af);
}
项目:SpeechRaspberrySmartHouse    文件:GSpeechDuplex.java   
/**
 * This method allows you to stream a continuous stream of data to the API.
 * <p>
 * Note: This feature is experimental.</p>
 *
 * @param tl
 * @param af
 * @throws IOException
 * @throws LineUnavailableException
 */
public void recognize(TargetDataLine tl, AudioFormat af) throws IOException, LineUnavailableException {
    //Generates a unique ID for the response. 
    final long PAIR = MIN + (long) (Math.random() * ((MAX - MIN) + 1L));

    //Generates the Downstream URL
    final String API_DOWN_URL = GOOGLE_DUPLEX_SPEECH_BASE + "down?maxresults=1&pair=" + PAIR;

    //Generates the Upstream URL
    final String API_UP_URL = GOOGLE_DUPLEX_SPEECH_BASE
            + "up?lang=" + language + "&lm=dictation&client=chromium&pair=" + PAIR
            + "&key=" + API_KEY + "&continuous=true&interim=true"; //Tells Google to constantly monitor the stream;

    //Opens downChannel
    this.downChannel(API_DOWN_URL);

    //Opens upChannel
    this.upChannel(API_UP_URL, tl, af);
}
项目:ether    文件:JavaSoundSource.java   
public synchronized static String[] getSources() {
    if(sources.isEmpty()) {
        for(Mixer.Info mixerInfo : AudioSystem.getMixerInfo()) {
            try(Mixer mixer = AudioSystem.getMixer(mixerInfo)) {
                for(Line.Info lineInfo : mixer.getTargetLineInfo()) {
                    if(TargetDataLine.class.isAssignableFrom(lineInfo.getLineClass()))
                        sources.add(new Pair<>(mixerInfo, lineInfo));
                }
            }
        }
    }

    String[] result = new String[sources.size()];
    int idx = 0;
    for(Pair<Mixer.Info, Line.Info> src : sources)
        result[idx++] = src.first.getName();
    return result;
}
项目:JavaVAD    文件:CommonUtilTest.java   
/**
     * Test method for {@link com.deb.vad.utility.CommonUtil#getAudioFormatMp3()}.
     */
    public final void testGetAudioFormatMp3() {
//      package com.ibm.emb.test.mfb; study this package.
//      Not working [PCM_SIGNED, PCM_UNSIGNED, ALAW, ULAW]
//      interface TargetDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 16000 bytes/frame, 16.0 frames/second, big-endian

//      Working
//      interface TargetDataLine supporting format PCM_SIGNED 16000.0 Hz, 8 bit, mono, 1 bytes/frame, 

        AudioFormat mp3Format = CommonUtil.getAudioFormatMp3();
        Encoding[] encoding = AudioSystem.getTargetEncodings(mp3Format);
        System.out.println(Arrays.toString(encoding));
        DataLine.Info info = new DataLine.Info(TargetDataLine.class, mp3Format);
        System.out.println(info.toString());
        if (!AudioSystem.isLineSupported(info)) {

            assertFalse("Line not supported. Sorry I am leaving...",true);

        }
    }
项目:sdrtrunk    文件:MixerTuner.java   
/**
 * Wrapper class to add basic Tuner functionality to the ComplexMixer.  
 * Subclasses should couple this functionality with a tuner controller class
 * to support tuning.
 */
public MixerTuner( String name,
                   TunerController tunerController,
                   MixerTunerType mixerTunerType,
                   TargetDataLine targetDataLine,
                   ISampleAdapter sampleAdapter )
{
    super( name, tunerController );

    mMixerTunerType = mixerTunerType;

       mComplexMixer = new ComplexMixer( targetDataLine, 
                                      mMixerTunerType.getAudioFormat(),
                                      name,
                                      sampleAdapter,
                                      (Listener<ComplexBuffer>)this );
}
项目:screencast4j    文件:SampledSoundRecorder.java   
@Override
 public String setUp() {
   String   result;

   result = super.setUp();

   if (result == null) {
     m_AudioFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
m_Frequency, 16, 2, 4, m_Frequency, false);
     m_DataLineInfo = new DataLine.Info(TargetDataLine.class, m_AudioFormat);
     try {
m_TargetDataLine = (TargetDataLine) AudioSystem.getLine(m_DataLineInfo);
m_TargetDataLine.open(m_AudioFormat);
     }
     catch (Exception e) {
return "Unable to get recording line: " + Utils.throwableToString(e);
     }
     m_AudioInputStream = new AudioInputStream(m_TargetDataLine);
   }

   return result;
 }
项目:project-bianca    文件:AudioCapture.java   
public void captureAudio() {
    try {
        // Get everything set up for
        // capture
        audioFormat = getAudioFormat();
        DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
        targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
        targetDataLine.open(audioFormat);
        targetDataLine.start();

        // Create a thread to capture the
        // microphone data and start it
        // running. It will run until
        // the Stop button is clicked.
        Thread captureThread = new Thread(new CaptureThread());
        captureThread.start();
    } catch (Exception e) {
        Logging.logError(e);
    }// end catch
}
项目:project-bianca    文件:GoogleSTT.java   
public void captureAudio() {
    try {
        audioFormat = getAudioFormat();
        log.info("sample rate         " + sampleRate);
        log.info("channels            " + channels);
        log.info("sample size in bits " + sampleSizeInBits);
        log.info("signed              " + signed);
        log.info("bigEndian           " + bigEndian);
        log.info("data rate is " + sampleRate * sampleSizeInBits / 8 + " bytes per second");
        // create a data line with parameters
        DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
        // attempt to find & get an input data line with those parameters
        targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
        targetDataLine.open(audioFormat);
        targetDataLine.start();

        // create buffer for root mean square level detection
        buffer = new FloatSampleBuffer(targetDataLine.getFormat().getChannels(), bufferSize, targetDataLine.getFormat().getSampleRate());

        // capture from microphone
        captureThread = new CaptureThread(this);
        captureThread.start();
    } catch (Exception e) {
        log.error(Service.stackToString(e));
    }
}
项目:KaraOK    文件:FreqThread.java   
public FreqThread(){


            try
            {
                    target = (TargetDataLine) AudioSystem.getLine(info);
                    target.open(format);
                    target.toString();
            }
            catch (LineUnavailableException e)
            {
                    System.out.print("unable to get a recording line");
                    e.printStackTrace();
                    System.exit(1);
            }



            // Begin audio capture.
            target.start();


        }
项目:MakamBox    文件:PitchTracking.java   
public void captureAudio() {                                    
    try {                                                       
        bufferSize = 2048;                                          // Define Buffer size
        buffer = new byte[bufferSize];                              // Buffer array
        info = new DataLine.Info(TargetDataLine.class, format);     // Dataline info
        recLine = (TargetDataLine) AudioSystem.getLine(info);       // Getting mixer line from driver (system selected)
        recLine.open(format);                                       // Opening recording line (make connection)
        recLine.start();                                            // Start draining line
        runner();                                                   // Create new runner for thread
        captureThread = new Thread(runner);                         // Define new thread
        captureThread.start();                                      // Start for capture, invoke thread
    } catch (LineUnavailableException e) {
        System.err.println("Line unavailable: " + e);
        System.exit(-2);
    }
}
项目:infobip-open-jdk-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;
}
项目: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;
}
项目:frinika    文件:JVSTSynthMidiDeviceTest.java   
@Test
public void testOpenMidiDevice() throws Exception
{
    FrinikaJVSTSynth synth = (FrinikaJVSTSynth) MidiSystem.getMidiDevice(new FrinikaJVSTSynthProvider.FrinikaJVSTSynthProviderInfo());
    final TargetDataLine line = (TargetDataLine)((Mixer)synth).getLine( new Line.Info(TargetDataLine.class));
    AudioFormat.Encoding PCM_FLOAT = new AudioFormat.Encoding("PCM_FLOAT");
    AudioFormat format = new AudioFormat(PCM_FLOAT, 44100, 32, 2, 4*2, 44100, ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN));
    line.open(format);

    AudioInputStream ais = new AudioInputStream(line);
    assertTrue(AudioSystem.isConversionSupported(Encoding.PCM_SIGNED, ais.getFormat()));

    AudioInputStream convertedAis = AudioSystem.getAudioInputStream(Encoding.PCM_SIGNED, ais);
    SourceDataLine sdl = AudioSystem.getSourceDataLine(convertedAis.getFormat());
    sdl.open();
    sdl.start();
    byte[] buf = new byte[16384];        
    ShortMessage shm = new ShortMessage();
    shm.setMessage(ShortMessage.NOTE_ON, 1, 40, 127);
    synth.getReceiver().send(shm,-1);
    for(int n=0;n<20;n++)
    {
        int read = convertedAis.read(buf);            
        sdl.write(buf, 0, read);
    }        
}
项目:frinika    文件:MixerAudioDeviceHandle.java   
/**
 *@deprecated To be rpelaced with COnnections
 */
public TargetDataLine getLine() { // DataLine.Info infoIn) {
    try {
        System.out.println(this + " **** " + af);
        DataLine.Info infoIn = new DataLine.Info(TargetDataLine.class, af);

        // lineIn =
        // (TargetDataLine)AudioSystem.getMixer(mixers.get(0)).getLine(infoIn);

        line = (TargetDataLine) mixer.getLine(infoIn);


    } catch (LineUnavailableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
项目:openimaj    文件:JavaSoundAudioGrabber.java   
/**
 * Open a line to the Java Sound APIs.
 *
 * @throws Exception
 *             if the Java sound system could not be initialised.
 */
private void openJavaSound() throws Exception {
    // Convert the OpenIMAJ audio format to a Java Sound audio format object
    final javax.sound.sampled.AudioFormat audioFormat = new javax.sound.sampled.AudioFormat(
            (int) (this.getFormat().getSampleRateKHz() * 1000), this
                    .getFormat().getNBits(), this.getFormat()
                    .getNumChannels(), this.getFormat().isSigned(), this
                    .getFormat().isBigEndian());

    System.out.println("Creating Java Sound Line with " + this.getFormat());

    // Create info to create an output data line
    final DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);

    try {
        // Get the output line to write to using the given
        // sample format we just created.
        this.mLine = (TargetDataLine) AudioSystem.getLine(info);

        // If no exception has been thrown we open the line.
        this.mLine.open(audioFormat);
    } catch (final LineUnavailableException e) {
        throw new Exception("Could not open Java Sound audio line for"
                + " the audio format " + this.getFormat());
    }
}
项目: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;
        }
    }
}
项目:jdk7-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 value;
    String propertyName = typeClass.getName();
    value = JSSecurityManager.getProperty(propertyName);
    if (value == null) {
        value = getProperties().getProperty(propertyName);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
项目:simpleguitartuner    文件:SimpleTuner.java   
public void start() {
    System.out.println("Simple Guitar Tuner");
    System.out.println("To exit the progeramm, press <CTRL> + <C>");
    System.out.println("Which guitar string you want to tune: \033[0;1me1, a, d, g, h, e2\033[0;0m?");

    AudioFormat audioFormat = new AudioFormat(8000.0F, 8, 1, true, false);
    DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
    try {
        TargetDataLine targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
        targetDataLine.open(audioFormat);

        CaptureThread captureThread = new CaptureThread(targetDataLine);

        UserKeyboardInputThread ukit = new UserKeyboardInputThread(captureThread);
        ukit.start();

        captureThread.start();
    } catch (Exception e2) {
        System.out.println("Error: Unable to start sound data acqusition: " + e2.getLocalizedMessage());
    }
}
项目:SoundCenterClient    文件:Recorder.java   
public Recorder() {

        try {
            //Get microphone targetline
            AudioFormat format = getAudioFormat();
            DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, format, bufferSize);
            targetLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
            targetLine.open(getAudioFormat(), bufferSize);
        } catch (LineUnavailableException e) {
            App.logger.w("No supported microphone found.", e);
        }

        //Initialize the speex encoder
        if (!mEncoder.init(1, 8, 16000, 1)) {
            App.logger.w("Failed to initialize speex encoder!", null);
        }
    }
项目:openjdk-source-code-learn    文件: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;
}
项目:myrobotlab    文件:AudioCapture.java   
public void captureAudio() {
  try {
    // Get everything set up for
    // capture
    audioFormat = getAudioFormat();
    DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
    targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
    targetDataLine.open(audioFormat);
    targetDataLine.start();

    // Create a thread to capture the
    // microphone data and start it
    // running. It will run until
    // the Stop button is clicked.
    Thread captureThread = new Thread(new CaptureThread());
    captureThread.start();
  } catch (Exception e) {
    Logging.logError(e);
  } 
  broadcastState();
  // end catch
}