亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? captureplaybackserver.java

?? java語言編寫的語音聊天室程序
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
      }
      catch (LineUnavailableException ex) {
        shutDown("Unable to open the line: " + ex);
        return;
      }
      //對line的操作次序:open();getBufferSize();start();write(data,0,num);drain();
      /**
       * line的最大BufferSize是16384;一個frame大小由AudioFormat決定;frame大小乘上(buffer里的frame數量)=這里line實際用的bufferData大小
       */
      // 重放捕獲的聲音數據 play back the captured audio data
      //**frame大小由AudioFormat決定,這里為4字節長;
       int frameSizeInBytes = format.getFrameSize();
      //For a source data line, this is maximum size of the buffer to which data can be written.  For a target data line, it is maximum size of the buffer from which data can be read.
      int bufferLengthInFrames = line.getBufferSize() / 8;
      //bufferLengthInBytes為8192----bufferLengthInFrames為2048
      int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
      //在線程里,data被不斷初始化!
      byte[] data = new byte[bufferLengthInBytes];
      int numBytesRead = 0;

      // Allows a line to engage in data I/O.(the line must be flushed or stoped)
      line.start();
      //playbackInputStream->data[]->dataline
      while (thread != null) {
        try {
          //取出playbackInputStream并寫到字節流data[byte]中!返回事實讀取的量,跳出。
          if ( (numBytesRead = playbackInputStream.read(data)) == -1) {
            break;
          }
          int numBytesRemaining = numBytesRead;
          while (numBytesRemaining > 0) {
            //line.write(data, 0, numBytesRemaining)返回已寫入line的數據數量
            numBytesRemaining -= line.write(data, 0, numBytesRemaining);
          }
        }
        catch (Exception e) {
          shutDown("Error during playback: " + e);
          break;
        }
      }
      // 向line寫完字節流,結束when reached the end of the stream,let the data play out, then
      // stop and close the line.
      if (thread != null) {
        //排出Drains queued data from the line by continuing data I/O until line's internal buffer has been emptied.
        line.drain();
        //line.flush()---Flushes queued data from the line.
      }
      line.stop();
      line.close();
      line = null;
      shutDown(null);
    }
  } // End class Playback
//fuwuqi
  /**
   * 從輸入渠道中捕獲數據,并寫到輸出流中;Reads data from the input channel and writes to the output stream
   */
  class Capture
      implements Runnable {

    TargetDataLine line;
    Thread thread;

    public void start() {
      errStr = null;
      thread = new Thread(this);
      //thread是有名字的;
      thread.setName("Capture");
      thread.start();
    }

    public void stop() {
      thread = null;
    }

    private void shutDown(String message) {
      if ( (errStr = message) != null && thread != null) {
        thread = null;
        samplingGraph.stop();
        loadB.setEnabled(true);
        playB.setEnabled(true);
        pausB.setEnabled(false);
        auB.setEnabled(true);
        aiffB.setEnabled(true);
        waveB.setEnabled(true);
        captB.setText("Record");
        System.err.println(errStr);
        samplingGraph.repaint();
      }
    }

    public void run() {
      duration = 0;
      //將audioInputStream置空!
      audioInputStream = null;

      // define the required attributes for our line,
      // and make sure a compatible line is supported.

      AudioFormat format = formatControls.getFormat();
      DataLine.Info info = new DataLine.Info(TargetDataLine.class,
                                             format);

      if (!AudioSystem.isLineSupported(info)) {
        shutDown("Line matching " + info + " not supported.");
        return;
      }

      // 獲得并打開目標dataline來捕獲get and open the target data line for capture.

      try {
        line = (TargetDataLine) AudioSystem.getLine(info);
        //這里將獲得聲音!!
        line.open(format, line.getBufferSize());
      }
      catch (LineUnavailableException ex) {
        shutDown("Unable to open the line: " + ex);
        return;
      }
      catch (SecurityException ex) {
        shutDown(ex.toString());
//        JavaSound.showInfoDialog();
        return;
      }
      catch (Exception ex) {
        shutDown(ex.toString());
        return;
      }

      // line.read(data[])——播放
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      int frameSizeInBytes = format.getFrameSize();
      int bufferLengthInFrames = line.getBufferSize() / 8;
      int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
      byte[] data = new byte[bufferLengthInBytes];
      int numBytesRead;

      line.start();
    //循環——從IO中讀取到data[byte],長為bufferLengthInBytes  !
      while (thread != null) {
        if ( (numBytesRead = line.read(data, 0, bufferLengthInBytes)) == -1) {
          break;
        }
        out.write(data, 0, numBytesRead);
      }

      // we reached the end of the stream.  stop and close the line.
      line.stop();
      line.close();
      line = null;

      // 停止和關閉輸出流stop and close the output stream
      try {
        out.flush();
        out.close();
      }
      catch (IOException ex) {
        ex.printStackTrace();
      }

      // !!!將輸入流載入到audioInputStream對象中!load bytes into the audio input stream for playback

      byte audioBytes[] = out.toByteArray();
      ByteArrayInputStream bais = new ByteArrayInputStream(audioBytes);
      audioInputStream = new AudioInputStream(bais, format,
                                              audioBytes.length /
                                              frameSizeInBytes);

      long milliseconds = (long) ( (audioInputStream.getFrameLength() * 1000) /
                                  format.getFrameRate());
      duration = milliseconds / 1000.0;

      try {
        audioInputStream.reset();
      }
      catch (Exception ex) {
        ex.printStackTrace();
        return;
      }
//在捕獲的線程里調用畫圖!hlf   //kehu---duankai2---huahua
      samplingGraph.createWaveForm(audioBytes);
    }
  } // End class Capture
  //fuwuqi
  /**
   * 畫波形圖.//hlf!!
   */
  class SamplingGraph extends JPanel implements Runnable {

    private Thread thread;
    private Font font10 = new Font("serif", Font.PLAIN, 10);
    private Font font12 = new Font("serif", Font.PLAIN, 12);
    //深色底面
    Color jfcBlue = new Color(204, 204, 255);
    //粉色畫當前位置線
    Color pink = new Color(255, 175, 175);

    public SamplingGraph() {
      setBackground(new Color(20, 20, 20));
    }

    //畫波形圖!
    public void createWaveForm(byte[] audioBytes) {

      lines.removeAllElements(); // clear the old vector

      AudioFormat format = audioInputStream.getFormat();

      if (audioBytes == null) {
        try {
          audioBytes = new byte[ (int) (audioInputStream.getFrameLength()
                                        * format.getFrameSize())];
          audioInputStream.read(audioBytes);
        }
        catch (Exception ex) {
          reportStatus(ex.toString());
          return;
        }
      }
      Dimension d = getSize();
      int w = d.width;
      int h = d.height - 15;
      int[] audioData = null;
      if (format.getSampleSizeInBits() == 16) {
        int nlengthInSamples = audioBytes.length / 2;
        audioData = new int[nlengthInSamples];
        if (format.isBigEndian()) {
          for (int i = 0; i < nlengthInSamples; i++) {
            /* First byte is MSB (high order) */
            int MSB = (int) audioBytes[2 * i];
            /* Second byte is LSB (low order) */
            int LSB = (int) audioBytes[2 * i + 1];
            audioData[i] = MSB << 8 | (255 & LSB);
          }
        }
        else {
          for (int i = 0; i < nlengthInSamples; i++) {
            /* First byte is LSB (low order) */
            int LSB = (int) audioBytes[2 * i];
            /* Second byte is MSB (high order) */
            int MSB = (int) audioBytes[2 * i + 1];
            audioData[i] = MSB << 8 | (255 & LSB);
          }
        }
      }
      else if (format.getSampleSizeInBits() == 8) {
        int nlengthInSamples = audioBytes.length;
        audioData = new int[nlengthInSamples];
        if (format.getEncoding().toString().startsWith("PCM_SIGN")) {
          for (int i = 0; i < audioBytes.length; i++) {
            audioData[i] = audioBytes[i];
          }
        }
        else {
          for (int i = 0; i < audioBytes.length; i++) {
            audioData[i] = audioBytes[i] - 128;
          }
        }
      }

      int frames_per_pixel = audioBytes.length / format.getFrameSize() / w;
      byte my_byte = 0;
      double y_last = 0;
      int numChannels = format.getChannels();
      for (double x = 0; x < w && audioData != null; x++) {
        int idx = (int) (frames_per_pixel * numChannels * x);
        if (format.getSampleSizeInBits() == 8) {
          my_byte = (byte) audioData[idx];
        }
        else {
          my_byte = (byte) (128 * audioData[idx] / 32768);
        }
        double y_new = (double) (h * (128 - my_byte) / 256);
        //增加點!
        lines.add(new Line2D.Double(x, y_last, x, y_new));
        y_last = y_new;
      }

      //repaint();//???
    }

//使用線程畫波形圖!hlf
    public void paint(Graphics g) {
    // 組件JPanel的大小;Returns the size of this component in the form of a <code>Dimension</code> object
      Dimension d = getSize();
      int w = d.width;
      int h = d.height;
      int INFOPAD = 15;
    // 精確控制幾何圖形 Graphics2D——sophisticated control over geometry
    // 在JPanel上畫畫!
      Graphics2D g2 = (Graphics2D) g;
      g2.setBackground(getBackground());
      g2.clearRect(0, 0, w, h);//???300,60
      g2.setColor(Color.white);
      g2.fillRect(0, h - INFOPAD, w, INFOPAD);
    //捕獲出錯的情況1
      if (errStr != null) {
        g2.setColor(jfcBlue);
        g2.setFont(new Font("serif", Font.BOLD, 18));
        g2.drawString("ERROR", 5, 20);
        AttributedString as = new AttributedString(errStr);
        as.addAttribute(TextAttribute.FONT, font12, 0, errStr.length());
        AttributedCharacterIterator aci = as.getIterator();
        FontRenderContext frc = g2.getFontRenderContext();
        LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
        float x = 5, y = 25;
        lbm.setPosition(0);
        while (lbm.getPosition() < errStr.length()) {
          TextLayout tl = lbm.nextLayout(w - x - 5);
          if (!tl.isLeftToRight()) {
            x = w - tl.getAdvance();
          }
          tl.draw(g2, x, y += tl.getAscent());
          y += tl.getDescent() + tl.getLeading();
        }
      }
      //正捕獲中的情況2
      else if (capture.thread != null) {
        g2.setColor(Color.black);
        g2.setFont(font12);
        g2.drawString("Length: " + String.valueOf(seconds), 3, h - 4);
      }
      //捕獲結束的情況3
      else {
        g2.setColor(Color.black);
        g2.setFont(font12);
        g2.drawString("文件名: " + fileName + "  長度: " +
                      String.valueOf(duration) + "  當前位置(秒): " +
                      String.valueOf(seconds), 3, h - 4);

        if (audioInputStream != null) {
          // 畫聲音波形圖.. render sampling graph ..
          g2.setColor(jfcBlue);
          for (int i = 1; i < lines.size(); i++) {
            g2.draw( (Line2D) lines.get(i));
          }
          // 畫當前位置圖.. draw current position ..
          if (seconds != 0) {
            double loc = seconds / duration * w;
            g2.setColor(pink);
            g2.setStroke(new BasicStroke(3));
            g2.draw(new Line2D.Double(loc, 0, loc, h - INFOPAD - 2));
          }
        }
      }
    }

    public void start() {
      thread = new Thread(this);
      thread.setName("SamplingGraph");
      thread.start();
      seconds = 0;
    }

    public void stop() {
      if (thread != null) {
        thread.interrupt();
      }
      thread = null;
    }

    public void run() {
      seconds = 0;
      while (thread != null) {
        if ( (playback.line != null) && (playback.line.isOpen())) {

          long milliseconds = (long) (playback.line.getMicrosecondPosition() /
                                      1000);
          seconds = milliseconds / 1000.0;
        }
        else if ( (capture.line != null) && (capture.line.isActive())) {

          long milliseconds = (long) (capture.line.getMicrosecondPosition() /
                                      1000);
          seconds = milliseconds / 1000.0;
        }

        try {
          thread.sleep(100);
        }
        catch (Exception e) {
          break;
        }

        repaint();

        while ( (capture.line != null && !capture.line.isActive()) ||
               (playback.line != null && !playback.line.isOpen())) {
          try {
            thread.sleep(10);
          }
          catch (Exception e) {
            break;
          }
        }
      }
      seconds = 0;
      repaint();
    }
  } // End class SamplingGraph

  public static void main(String s[]) {
    CapturePlaybackServer CapturePlaybackServer = new CapturePlaybackServer();
    JFrame f = new JFrame("歡迎使用服務端語音系統");
    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
    f.getContentPane().add("Center", CapturePlaybackServer);
    f.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int w = 720;
    int h = 340;
    //使frame居中
    f.setLocation(screenSize.width / 2 - w / 2, screenSize.height / 2 - h / 2);
    f.setSize(w, h);
    f.show();
    //打開監聽
    CapturePlaybackServer.open();
  }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区二区毛片| 首页亚洲欧美制服丝腿| 日韩午夜小视频| 欧美伦理电影网| 欧美猛男超大videosgay| 欧美在线视频不卡| 欧美日韩精品一区二区三区蜜桃 | 日本美女视频一区二区| 一区二区三区在线播| 亚洲黄色在线视频| 亚洲一二三四区不卡| 亚洲成年人影院| 国内精品不卡在线| 成人一区二区三区中文字幕| 成人午夜看片网址| 欧美性受极品xxxx喷水| 3d动漫精品啪啪一区二区竹菊| 日韩精品一区二区三区视频在线观看| 2014亚洲片线观看视频免费| 精品蜜桃在线看| 亚洲欧美自拍偷拍色图| 亚洲黄色片在线观看| 日本亚洲视频在线| 成人一道本在线| 在线亚洲一区二区| 欧美一级片在线看| 国产清纯美女被跳蛋高潮一区二区久久w | 国产乱对白刺激视频不卡 | 一区二区免费在线播放| 日韩在线a电影| 国产精品一区二区不卡| 欧美在线免费视屏| 久久青草国产手机看片福利盒子 | 亚洲乱码国产乱码精品精可以看| 亚洲电影中文字幕在线观看| 精彩视频一区二区| 色久优优欧美色久优优| 精品少妇一区二区三区| 亚洲女同ⅹxx女同tv| 秋霞国产午夜精品免费视频| 成人亚洲一区二区一| 4438x亚洲最大成人网| 中文字幕在线观看不卡| 美女任你摸久久| 色www精品视频在线观看| 精品国偷自产国产一区| 亚洲第一会所有码转帖| 粉嫩欧美一区二区三区高清影视 | 欧美曰成人黄网| 久久久国产精华| 欧美bbbbb| 欧美色电影在线| 亚洲视频在线一区观看| 国产真实精品久久二三区| 欧美精品在欧美一区二区少妇 | 91在线云播放| 亚洲国产精品激情在线观看| 狠狠色综合日日| 欧美一区二区在线观看| 亚洲精品水蜜桃| 成人深夜福利app| 国产视频一区二区在线观看| 麻豆高清免费国产一区| 在线播放国产精品二区一二区四区| 国产精品久久午夜| 成人福利视频网站| 国产精品视频一二三区| 高清久久久久久| 亚洲国产精品二十页| 国产凹凸在线观看一区二区| 久久在线观看免费| 韩国女主播成人在线观看| 精品久久一区二区| 麻豆精品视频在线观看| 欧美电影免费观看高清完整版在 | 1区2区3区精品视频| 国产精品77777| 国产片一区二区三区| 国产99久久久精品| 中文字幕免费一区| eeuss影院一区二区三区| 中文字幕一区在线观看视频| 99国产一区二区三精品乱码| 亚洲精品精品亚洲| 欧美综合亚洲图片综合区| 亚洲一区二区精品视频| 7777精品伊人久久久大香线蕉经典版下载| 一区二区三区久久久| 欧美日韩一区二区在线观看视频| 五月婷婷综合网| 日韩一区二区免费高清| 黑人巨大精品欧美黑白配亚洲| 久久只精品国产| 91丨porny丨国产| 亚洲第一电影网| 日韩免费视频一区| 菠萝蜜视频在线观看一区| 亚洲人精品一区| 日韩欧美卡一卡二| 成人激情校园春色| 亚洲成人高清在线| 久久日一线二线三线suv| www.在线欧美| 日本欧美一区二区| 国产免费成人在线视频| 欧美猛男gaygay网站| 国产麻豆日韩欧美久久| 亚洲精品日韩一| 精品捆绑美女sm三区| 99精品久久只有精品| 美女一区二区久久| 一区二区三区在线播| 久久亚洲春色中文字幕久久久| 一本色道亚洲精品aⅴ| 日韩高清在线电影| 亚洲精品日韩综合观看成人91| 欧美v日韩v国产v| 欧美日韩一区精品| av成人老司机| 加勒比av一区二区| 亚洲福利电影网| 国产精品福利一区二区| 亚洲精品一区二区三区在线观看| 95精品视频在线| 国产999精品久久久久久| 亚洲成人一二三| 亚洲免费在线观看| 国产三级精品在线| 日韩一级视频免费观看在线| 91影院在线免费观看| 国产成人8x视频一区二区| 日韩国产欧美在线观看| 亚洲国产精品一区二区www在线| 中文幕一区二区三区久久蜜桃| 欧美一区国产二区| 欧美日韩一区久久| 欧美在线一二三四区| 色婷婷国产精品久久包臀| 国产一区二区三区免费看| 亚洲成人7777| 午夜免费欧美电影| 五月天丁香久久| 亚洲人成精品久久久久久| 中文字幕一区二区在线播放| 国产午夜精品一区二区三区四区| 日韩精品一区二区三区在线| 日韩三级.com| 欧美浪妇xxxx高跟鞋交| 欧美日本在线播放| 欧美区在线观看| 欧美日韩大陆在线| 欧美一区日韩一区| 精品欧美一区二区三区精品久久| 欧美精品乱码久久久久久| 欧美日韩精品三区| 在线成人av网站| 欧美一级xxx| 欧美一区二区三区男人的天堂 | 韩国视频一区二区| 国产主播一区二区三区| 国产精品一级在线| 成人福利视频网站| 在线精品亚洲一区二区不卡| 欧美性猛交xxxx乱大交退制版| 精品婷婷伊人一区三区三| 91精品国产一区二区三区蜜臀| 日韩小视频在线观看专区| 久久综合视频网| 国产精品福利一区二区| 亚洲一区电影777| 另类小说图片综合网| 国产91对白在线观看九色| 在线观看网站黄不卡| 日韩一级免费观看| 国产精品久久久久久久久免费丝袜| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆 | 国产在线国偷精品产拍免费yy| 国产91在线|亚洲| 欧洲精品一区二区三区在线观看| 91.xcao| 国产精品国产成人国产三级| 亚洲永久精品国产| 激情六月婷婷久久| 色婷婷精品大视频在线蜜桃视频| 欧美一区二区三区白人| 国产精品女同互慰在线看| 日欧美一区二区| 成人三级伦理片| 欧美巨大另类极品videosbest| 亚洲国产精品成人久久综合一区| 亚洲综合一二三区| 懂色av噜噜一区二区三区av| 欧美日韩电影在线| 亚洲人成伊人成综合网小说| 久久精品免费看| 日本精品裸体写真集在线观看| 精品国产伦一区二区三区观看体验| 亚洲一区二区三区美女| 国产成人av一区二区三区在线| 欧美色图12p|