当前位置: 首页>>代码示例>>Java>>正文


Java TargetDataLine.open方法代码示例

本文整理汇总了Java中javax.sound.sampled.TargetDataLine.open方法的典型用法代码示例。如果您正苦于以下问题:Java TargetDataLine.open方法的具体用法?Java TargetDataLine.open怎么用?Java TargetDataLine.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sound.sampled.TargetDataLine的用法示例。


在下文中一共展示了TargetDataLine.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: VirtualDrummerMicrophoneInput

import javax.sound.sampled.TargetDataLine; //导入方法依赖的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: upChannel

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
/**
 * 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;
	
}
 
开发者ID:goxr3plus,项目名称:java-google-speech-api,代码行数:30,代码来源:GSpeechDuplex.java

示例3: setUp

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
@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;
 }
 
开发者ID:fracpete,项目名称:screencast4j,代码行数:24,代码来源:SampledSoundRecorder.java

示例4: start

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
/**
 * 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();
}
 
开发者ID:cycronix,项目名称:cloudturbine,代码行数:25,代码来源:AudioStream.java

示例5: start

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:dipu-bd,项目名称:Tuntuni,代码行数:17,代码来源:MicrophoneAudio.java

示例6: captureAudio

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
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
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:21,代码来源:AudioCapture.java

示例7: captureAudio

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
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));
	}
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:27,代码来源:GoogleSTT.java

示例8: FreqThread

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
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();

  
        }
 
开发者ID:kara71,项目名称:KaraOK,代码行数:24,代码来源:FreqThread.java

示例9: captureAudio

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
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);
	}
}
 
开发者ID:miracatici,项目名称:MakamBox,代码行数:17,代码来源:PitchTracking.java

示例10: testOpenMidiDevice

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
@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);
    }        
}
 
开发者ID:petersalomonsen,项目名称:frinika,代码行数:27,代码来源:JVSTSynthMidiDeviceTest.java

示例11: start

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
@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;
        }
    }
}
 
开发者ID:philburk,项目名称:jsyn,代码行数:20,代码来源:JavaSoundAudioDevice.java

示例12: start

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
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());
	}
}
 
开发者ID:mirkoebert,项目名称:simpleguitartuner,代码行数:22,代码来源:SimpleTuner.java

示例13: Recorder

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
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);
		}
	}
 
开发者ID:WegFetZ,项目名称:SoundCenterClient,代码行数:18,代码来源:Recorder.java

示例14: captureAudio

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
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
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:23,代码来源:AudioCapture.java

示例15: upChannel

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
/**
 * 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 void 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();
	}
	new Thread ("Upstream Thread") {
		public void run() {
			openHttpsPostConnection(murl, mtl, maf);
		}

	}.start();

}
 
开发者ID:CMPE272Project,项目名称:SpeakJava,代码行数:24,代码来源:GSpeechDuplex.java


注:本文中的javax.sound.sampled.TargetDataLine.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。