public void run(String local, String remote, InputStream pin, OutputStream pout) { try { microphone = SoundMixerEnumerator.getInputLine(pcmformat, DefaultPhonePCMBlockSize); } catch (LineUnavailableException lue) { System.out.println( "\3b" + getClass().getName() + ".<init>:\n\tCould not create microphone input stream.\n\t" + lue); } try { speaker = SoundMixerEnumerator.getOutputLine(pcmformat, DefaultPhonePCMBlockSize); } catch (LineUnavailableException lue) { microphone.close(); System.out.println( "\3b" + getClass().getName() + ".<init>:\n\tCould not create speaker output stream.\n\t" + lue); } if ((speaker == null) || (microphone == null)) { super.run(local, remote, pin, pout); return; } try { recorder = new Recorder(pout); recorder.start(); gui = openMonitorGUI("Remote " + remote + " Local " + local); pin.skip(pin.available()); // waste whatever we couldn't process in time super.run(local, remote, new PhoneCallMonitorInputStream(pin), pout); recorder.interrupt(); gui.dispose(); } catch (Exception e) { System.out.println("3\b" + getClass().getName() + ".run:\n\t" + e); e.printStackTrace(); } finally { deactivate(); microphone.close(); speaker.close(); if (gui != null) { gui.dispose(); } } }
public void close() throws IOException { if (line.isActive()) { line.flush(); line.stop(); } line.close(); }
public TargetDataLine getInputLine(AudioFormat format) throws LineUnavailableException { TargetDataLine in; DataLine.Info info = new DataLine.Info(TargetDataLine.class, format); in = (TargetDataLine) mixer.getLine(info); in.open(format, in.getBufferSize()); return in; }
public void deactivate() { active = false; microphone.stop(); microphone.flush(); speaker.stop(); speaker.flush(); }
public static TargetDataLine getTargetDataLine(AudioFormat format, Mixer.Info mixerinfo) throws LineUnavailableException { TargetDataLine line = (TargetDataLine) getMixer(mixerinfo).getLine(new Line.Info(TargetDataLine.class)); line.open(format); return line; }
// $$fb 2001-07-16: added this method to correctly close the underlying TargetDataLine. // fixes bug 4479984 public void close() throws IOException { // the line needs to be flushed and stopped to avoid a dead lock... // Probably related to bugs 4417527, 4334868, 4383457 if (line.isActive()) { line.flush(); line.stop(); } line.close(); }
public void activate() { active = true; microphone.flush(); speaker.flush(); speaker.start(); blocker.release(); microphone.start(); microphone.flush(); }
public int read(byte[] b, int off, int len) throws IOException { try { return line.read(b, off, len); } catch (IllegalArgumentException e) { throw new IOException(e.getMessage()); } }
public int read(byte[] b, int off, int len) throws IOException { // System.out.print("'"+len+"'"); try { int ret = line.read(b, off, len); // if (ret > 50 && DEBUG_TRANSPORT && !printedBytes) { // printedBytes = true; // out("AudioCapture: first bytes being captured:"); // String s = ""; // for (int i = 0; i < 50; i++) { // s += " " + b[i]; // } // out(s); // } if (isMuted()) { muteBuffer(b, off, ret); } // run some simple analysis if (ret > 0) { calcCurrVol(b, off, ret); } return ret; } catch (IllegalArgumentException e) { throw new IOException(e.getMessage()); } }
/** * Constructs an audio input stream that reads its data from the target data line indicated. The * format of the stream is the same as that of the target data line, and the length is * AudioSystem#NOT_SPECIFIED. * * @param line the target data line from which this stream obtains its data. * @see AudioSystem#NOT_SPECIFIED */ public AudioInputStream(TargetDataLine line) { TargetDataLineInputStream tstream = new TargetDataLineInputStream(line); format = line.getFormat(); frameLength = AudioSystem.NOT_SPECIFIED; frameSize = format.getFrameSize(); if (frameSize == AudioSystem.NOT_SPECIFIED || frameSize <= 0) { frameSize = 1; } this.stream = tstream; framePos = 0; markpos = 0; }
public int read() throws IOException { byte[] b = new byte[1]; int value = read(b, 0, 1); if (value == -1) { return -1; } value = (int) b[0]; if (line.getFormat().getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) { value += 128; } return value; }
public int available() throws IOException { return line.available(); }
public String toString() { Mixer.Info info = mixer.getMixerInfo(); String s = "\nMixer [" + id + "]"; s += "\n\t Name: " + info.getName(); s += "\n\t Desc: " + info.getDescription(); s += "\n\t Ven : " + info.getVendor(); s += "\n\t Ver : " + info.getVersion(); s += "\n\t Str : " + info.toString(); Line.Info[] infos = mixer.getSourceLineInfo(); s += "\n\nSourceLine count : " + infos.length; for (int i = 0; i < infos.length; i++) { if (infos[i] instanceof DataLine.Info) { s += "\n\t\tData Line Source [" + i + "]"; s += "\n\t\t\t Str : " + infos[i].toString(); } else if (infos[i] instanceof Port.Info) { s += "\n\t\tPort Source [" + i + "]"; s += "\n\t\t\t Name: " + ((Port.Info) infos[i]).getName(); s += "\n\t\t\t is Src: " + ((Port.Info) infos[i]).isSource(); s += "\n\t\t\t Str : " + infos[i].toString(); } else /*if(infos[i]!=null)*/ { s += "\n\t\tSource [" + i + "]"; s += "\n\t\t\t Str : " + infos[i].toString(); } } s += "\n\nOUTPUT\n"; for (int i = 0; i < formats.length; i++) { try { SourceDataLine out = getOutputLine(formats[i]); out.close(); s += "\n" + formats[i].toString(); } catch (Exception e) { // s+="\n"+e.getMessage(); } } infos = mixer.getTargetLineInfo(); s += "\n\nTargetLine count : " + infos.length; for (int i = 0; i < infos.length; i++) { if (infos[i] instanceof DataLine.Info) { s += "\n\t\tData Line Target [" + i + "]"; s += "\n\t\t\t Str : " + infos[i].toString(); } else if (infos[i] instanceof Port.Info) { s += "\n\t\tPort Target [" + i + "]"; s += "\n\t\t\t Name: " + ((Port.Info) infos[i]).getName(); s += "\n\t\t\t is Src: " + ((Port.Info) infos[i]).isSource(); s += "\n\t\t\t Str : " + infos[i].toString(); } else /*if(infos[i]!=null)*/ { s += "\n\t\tTarget [" + i + "]"; s += "\n\t\t\t Str : " + infos[i].toString(); } } s += "\n\nINPUT\n"; for (int i = 0; i < formats.length; i++) { try { TargetDataLine out = getInputLine(formats[i]); out.close(); s += "\n" + formats[i].toString(); } catch (Exception e) { // s+="\n"+e.getMessage(); } } return s; }
protected void openLineImpl() throws Exception { TargetDataLine tdl = (TargetDataLine) line; tdl.open(lineFormat, bufferSize); ais = new TargetDataLineMeter(tdl); ais = AudioSystem.getAudioInputStream(netFormat, ais); }
TargetDataLineMeter(TargetDataLine line) { super(new ByteArrayInputStream(new byte[0]), line.getFormat(), AudioSystem.NOT_SPECIFIED); this.line = line; }