本文整理匯總了Java中javax.sound.sampled.LineUnavailableException類的典型用法代碼示例。如果您正苦於以下問題:Java LineUnavailableException類的具體用法?Java LineUnavailableException怎麽用?Java LineUnavailableException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LineUnavailableException類屬於javax.sound.sampled包,在下文中一共展示了LineUnavailableException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: init
import javax.sound.sampled.LineUnavailableException; //導入依賴的package包/類
private static void init() {
try {
// 44,100 samples per second, 16-bit audio, mono, signed PCM, little
// Endian
AudioFormat format = new AudioFormat((float) SAMPLE_RATE, BITS_PER_SAMPLE, 1, true, false);
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
line = (SourceDataLine) AudioSystem.getLine(info);
line.open(format, SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE);
// the internal buffer is a fraction of the actual buffer size, this
// choice is arbitrary
// it gets divided because we can't expect the buffered data to line
// up exactly with when
// the sound card decides to push out its samples.
buffer = new byte[SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE / 3];
} catch (LineUnavailableException e) {
System.out.println(e.getMessage());
}
// no sound gets made before this call
line.start();
}
示例2: upChannel
import javax.sound.sampled.LineUnavailableException; //導入依賴的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;
}
示例3: start
import javax.sound.sampled.LineUnavailableException; //導入依賴的package包/類
@Override
public void start() {
if (line != null) {
LOG.debug("Sound already started");
return;
}
LOG.debug("Start sound");
try {
line = AudioSystem.getSourceDataLine(FORMAT);
line.open(FORMAT, BUFFER_SIZE);
} catch (LineUnavailableException e) {
throw new RuntimeException(e);
}
line.start();
buffer = new byte[line.getBufferSize()];
divider = (int) (Gameboy.TICKS_PER_SEC / FORMAT.getSampleRate());
}
示例4: main
import javax.sound.sampled.LineUnavailableException; //導入依賴的package包/類
public static void main(String[] args) throws IOException, LineUnavailableException {
File folder=new File("/home/rizsi/tmp/video");
byte[] data=UtilFile.loadFile(new File(folder, "remote.sw"));
byte[] data2=UtilFile.loadFile(new File(folder, "local.sw"));
System.out.println("remote.sw max: "+measureMax(data));
System.out.println("local.sw max: "+measureMax(data2));
byte[] data3=sum(data, data2);
UtilFile.saveAsFile(new File(folder, "rawmic.sw"), data3);
AudioFormat format=ManualTestEchoCancel.getFormat();
final Mixer mixer = AudioSystem.getMixer(null);
Play p=new Play(mixer, format, ManualTestEchoCancel.frameSamples)
{
@Override
protected void switchBuffer() {
if(getSample()==data)
{
setSample(data2);
}else if(getSample()==data2)
{
setSample(data3);
}
}
};
p.start();
p.setSample(data);
}
示例5: playSound
import javax.sound.sampled.LineUnavailableException; //導入依賴的package包/類
/**
* Play a sound at a given frequency freq during duration (in seconds) with volume as strenght
* <br/><br/>
* <code>SoundGenerator.playSound(440.0,1.0,0.5,SoundGenerator.FADE_LINEAR,SoundGenerator.WAVE_SIN);</code><br/>
* Available fades : FADE_NONE, FADE_LINEAR, FADE_QUADRATIC<br/>
* Available waves : WAVE_SIN, WAVE_SQUARE, WAVE_TRIANGLE, WAVE_SAWTOOTH<br/>
*/
public static void playSound(double freq,double duration,double volume,byte fade,byte wave){
double[] soundData = generateSoundData(freq,duration,volume,fade,wave);
byte[] freqdata = new byte[soundData.length];
for(int i = 0;i < soundData.length;i++) {
freqdata[i] = (byte)soundData[i];
}
// Play it
try {
final AudioFormat af = new AudioFormat(SAMPLE_RATE, 8, 1, true, true);
SourceDataLine line = AudioSystem.getSourceDataLine(af);
line.open(af, SAMPLE_RATE);
line.start();
line.write(freqdata, 0, freqdata.length);
line.drain();
line.close();
}catch(LineUnavailableException e) {
e.printStackTrace();
}
}
示例6: restartSDL
import javax.sound.sampled.LineUnavailableException; //導入依賴的package包/類
public void restartSDL(){
AudioFormat form = new AudioFormat(sys.getSampleRate(),16,2,true,false);
bufptr=0;
audioints = new int[(int)((sys.getSampleRate()/1000.0)*sys.getBufferSize())*2];
if(scope!=null)
scope.setAudio(audioints);
audiobuffer = new byte[audioints.length*2];
try {
if(sdl!=null)
sdl.close();
sdl = AudioSystem.getSourceDataLine(form);
sdl.open(form,audiobuffer.length*3);
sdl.start();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}
示例7: VirtualDrummerMicrophoneInput
import javax.sound.sampled.LineUnavailableException; //導入依賴的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);
}
示例8: attack
import javax.sound.sampled.LineUnavailableException; //導入依賴的package包/類
/**
* Picks a player to attack
*/
public void attack()
{
Player weakest = null;
for (Entity e : getLevel().getEntities())
if (e.isActive() && e instanceof Player)
if (!getLevel().isThroughWall(getLocation(), e.getLocation()))
{
Player p = (Player) e;
if (weakest == null || p.getHealth() < weakest.getHealth())
weakest = p;
}
weakest.takeDamage(75);
try
{
SoundStuff cam = new SoundStuff();
cam.AWP();
}
catch (UnsupportedAudioFileException | IOException | LineUnavailableException e1)
{
e1.printStackTrace();
}
}
示例9: loadClip
import javax.sound.sampled.LineUnavailableException; //導入依賴的package包/類
private void loadClip() {
try {
clip = AudioSystem.getClip();
InputStream in = getClass().getClassLoader().getResourceAsStream(filePath);
BufferedInputStream bufferedIn = new BufferedInputStream(in);
AudioInputStream audioIn = AudioSystem.getAudioInputStream(bufferedIn);
clip.open(audioIn);
volume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
} catch (LineUnavailableException | UnsupportedAudioFileException | IOException e) {
e.printStackTrace();
System.exit(-1);
}
}
示例10: implOpen
import javax.sound.sampled.LineUnavailableException; //導入依賴的package包/類
void implOpen() throws LineUnavailableException {
if (Printer.trace) Printer.trace(">> PortMixerPort: implOpen().");
long newID = ((PortMixer) mixer).getID();
if ((id == 0) || (newID != id) || (controls.length == 0)) {
id = newID;
Vector vector = new Vector();
synchronized (vector) {
nGetControls(id, portIndex, vector);
controls = new Control[vector.size()];
for (int i = 0; i < controls.length; i++) {
controls[i] = (Control) vector.elementAt(i);
}
}
} else {
enableControls(controls, true);
}
if (Printer.trace) Printer.trace("<< PortMixerPort: implOpen() succeeded");
}
示例11: open
import javax.sound.sampled.LineUnavailableException; //導入依賴的package包/類
public void open() throws LineUnavailableException {
synchronized (mixer) {
// if the line is not currently open, try to open it with this format and buffer size
if (!isOpen()) {
if (Printer.trace) Printer.trace("> PortMixerPort: open");
// reserve mixer resources for this line
mixer.open(this);
try {
// open the line. may throw LineUnavailableException.
implOpen();
// if we succeeded, set the open state to true and send events
setOpen(true);
} catch (LineUnavailableException e) {
// release mixer resources for this line and then throw the exception
mixer.close(this);
throw e;
}
if (Printer.trace) Printer.trace("< PortMixerPort: open succeeded");
}
}
}
示例12: run
import javax.sound.sampled.LineUnavailableException; //導入依賴的package包/類
public void run () {
//create a separate thread for recording
Thread recordThread = new Thread(new Runnable() {
@Override
public void run() {
try {
System.out.println("Start recording...");
recorder.start();
} catch (LineUnavailableException ex) {
ex.printStackTrace();
System.exit(-1);
}
}
});
recordThread.start();
// try {
// Thread.sleep(RECORD_TIME);
// } catch (InterruptedException ex) {
// ex.printStackTrace();
// }
}
示例13: main
import javax.sound.sampled.LineUnavailableException; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
Mixer.Info[] infos = AudioSystem.getMixerInfo();
log("" + infos.length + " mixers detected");
for (int i=0; i<infos.length; i++) {
Mixer mixer = AudioSystem.getMixer(infos[i]);
log("Mixer " + (i+1) + ": " + infos[i]);
try {
mixer.open();
for (Scenario scenario: scenarios) {
testSDL(mixer, scenario);
testTDL(mixer, scenario);
}
mixer.close();
} catch (LineUnavailableException ex) {
log("LineUnavailableException: " + ex);
}
}
if (failed == 0) {
log("PASSED (" + total + " tests)");
} else {
log("FAILED (" + failed + " of " + total + " tests)");
throw new Exception("Test FAILED");
}
}
示例14: getLine
import javax.sound.sampled.LineUnavailableException; //導入依賴的package包/類
@Override
public Line getLine(Line.Info info) throws LineUnavailableException {
if (!isLineSupported(info))
throw new IllegalArgumentException("Line unsupported: " + info);
if ((info.getLineClass() == SourceDataLine.class)) {
return new SoftMixingSourceDataLine(this, (DataLine.Info) info);
}
if ((info.getLineClass() == Clip.class)) {
return new SoftMixingClip(this, (DataLine.Info) info);
}
throw new IllegalArgumentException("Line unsupported: " + info);
}
示例15: recognize
import javax.sound.sampled.LineUnavailableException; //導入依賴的package包/類
/**
* This method allows you to stream a continuous stream of data to the API.
* <p>
* Note: This feature is experimental.
* </p>
*
* @param tl
* TL
* @param af
* AF
* @throws LineUnavailableException
* If the Line is unavailable
* @throws InterruptedException
* InterruptedException
*/
public void recognize(TargetDataLine tl , AudioFormat af) throws LineUnavailableException , InterruptedException {
//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
Thread downChannel = this.downChannel(API_DOWN_URL);
//Opens upChannel
Thread upChannel = this.upChannel(API_UP_URL, tl, af);
try {
downChannel.join();
upChannel.interrupt();
upChannel.join();
} catch (InterruptedException e) {
downChannel.interrupt();
downChannel.join();
upChannel.interrupt();
upChannel.join();
}
}