示例#1
1
 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();
     }
   }
 }
示例#2
0
 /**
  * Stop recording and give us the clip.
  *
  * @return the clip that was recorded since the last time start was called
  * @see #start
  */
 public short[] stop() {
   synchronized (lock) {
     if (recorder == null) {
       return new short[0];
     }
     ByteArrayOutputStream out = recorder.stopRecording();
     microphone.close();
     recorder = null;
     byte audioBytes[] = out.toByteArray();
     ByteArrayInputStream in = new ByteArrayInputStream(audioBytes);
     try {
       short[] samples = RawReader.readAudioData(in, inFormat);
       if (downsample) {
         samples =
             Downsampler.downsample(
                 samples,
                 (int) (inFormat.getSampleRate() / 1000.0f),
                 (int) (outFormat.getSampleRate() / 1000.0f));
       }
       return samples;
     } catch (IOException e) {
       e.printStackTrace();
       return new short[0];
     }
   }
 }
示例#3
0
 public void close() throws IOException {
   if (line.isActive()) {
     line.flush();
     line.stop();
   }
   line.close();
 }
示例#4
0
 public void run() {
   try {
     b = new byte[6300];
     line.open(new AudioFormat(44100, 16, 1, true, true), 6300);
     line.start();
     while (true) {
       line.read(b, 0, b.length);
       server.writeByteBuffers(b, sourceIndex);
       if (output) serverOutput.write(b, 0, b.length);
     }
   } catch (LineUnavailableException e) {
     e.printStackTrace();
     System.out.println(sourceIndex);
   } finally {
     line.stop();
     line.close();
   }
 }
示例#5
0
  @Override
  protected Object doInBackground() throws Exception {
    try {
      while (!isCancelled()) {
        int bytesRead = microphone.read(tempBuffer, 0, tempBuffer.length);
        if (bytesRead > 0) {
          int currentLevel = (int) (calculateRMSLevel(tempBuffer) * 10);
          if (currentLevel > 100) currentLevel = 100;
          if (currentLevel < 0) currentLevel = 0;
          setProgress(currentLevel);
        }
      }

      microphone.close();
    } catch (Throwable e) {
      System.out.println(e);
      System.exit(-1);
    }

    return null;
  }
示例#6
0
    public void run() {
      // --------------init
      SourceDataLine sdl = Central.getGoutputSelector().getSourceDataLine();
      TargetDataLine tdl = Central.getGinputSelector().getTargetDataLine();

      try {
        tdl.open(af, READ_BUFFER_SIZE);
        sdl.open(af, WRITE_BUFFER_SIZE);

        sdl.start();
        tdl.start();
        while (checkRunning()) {
          tdl.read(sbMove, 0, READSIZE);
          sdl.write(sbMove, 0, READSIZE);
        }
        tdl.close();
        sdl.close();
      } catch (LineUnavailableException e) {
        e.printStackTrace();
      }
      error.log("Continuous Loop Stopped");
    }
 /**
  * Stops the recording.
  *
  * <p>Note that stopping the thread explicitely is not necessary. Once no more data can be read
  * from the TargetDataLine, no more data be read from our AudioInputStream. And if there is no
  * more data from the AudioInputStream, the method 'AudioSystem.write()' (called in 'run()'
  * returns. Returning from 'AudioSystem.write()' is followed by returning from 'run()', and thus,
  * the thread is terminated automatically.
  *
  * <p>It's not a good idea to call this method just 'stop()' because stop() is a (deprecated)
  * method of the class 'Thread'. And we don't want to override this method.
  */
 public void stopRecording() {
   m_line.stop();
   m_line.close();
 }
示例#8
0
  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;
  }