示例#1
0
 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());
   }
 }
示例#2
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();
   }
 }
示例#3
0
  // Thread logic
  public void run() {
    while (true) {
      // micData = new byte[microphone.available()];
      lastNumBytesRead = microphone.read(micData, 0, micData.length);

      // dp.setData(micData);
      DatagramPacket dp = new DatagramPacket(micData, Math.min(MAXBUFSIZE, micData.length));

      try {
        // System.out.println("input: " + buf[5]);
        dp.setData(micData);
        dSocket.send(dp);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
示例#4
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;
  }
示例#5
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");
    }