神奇好望角 The Magical Cape of Good Hope

          庸人不必自擾,智者何需千慮?
          posts - 26, comments - 50, trackbacks - 0, articles - 11
            BlogJava :: 首頁 ::  :: 聯(lián)系 :: 聚合  :: 管理

          用 Java Sound API 播放 PCM 音頻

          Posted on 2007-11-27 23:06 蜀山兆孨龘 閱讀(4484) 評論(2)  編輯  收藏
          用 Java Sound API 播放 PCM 音頻 Playing PCM Audio with Java Sound API
            多媒體應用程序,比如因特網電話,需要實時播放音頻,于是就要處理內存中的音頻數(shù)據(jù)。本文將演示如何播放 PCM(脈沖編碼調制)音頻。     Multimedia application, such as an Internet phone, requires playing sound in real time. Thus we are going to deal with in-memery audio data. This article will show how to play PCM (Pulse Code Modulation) audio.
            假設有一個字節(jié)數(shù)組 audioBuffer 用來保存將要播放的音頻塊。做以下的初始化:     Suppose there is a byte array audioBuffer which holds a chunck of audio data to be played. Do the following initializations:
          1. AudioFormat af = new AudioFormat(
          2.         sampleRate, sampleSizeInBits, channels, signed, bigEndian);
          3. SourceDataLine.Info info = new DataLine.Info(
          4.         SourceDataLine.class, af, bufferSize);
          5. SourceDataLine sdl = (SourceDataLine) AudioSystem.getLine(info);
          6. sdl.open(af);
          7. sdl.start();
            接著只要不停地用 sdl 向混頻器寫入字節(jié):     Then just continously write bytes to mixer with sdl:
          1. int offset = 0;
          2. while (offset < audioData.length) {
          3.     offset += sdl.write(audioData, offset, bufferSize);
          4. }
            因為 audioBuffer 被不斷填充和播放,所以最好把上述代碼放入線程。播放結束后像這樣來停止 sdl     Since audioBuffer is filled and played on and on, it's best to put the above code in a thread. When the playing is over, stop sdl like this:
          1. sdl.drain();
          2. sdl.stop();

          評論

          # re: 用 Java Sound API 播放 PCM 音頻  回復  更多評論   

          2013-08-22 17:01 by Stream
          就這樣?

          這么簡潔?

          沒看明白?


          我用android下的 audioRecord通過socket傳到pc機上,可以用這個播放???

          audioRecord傳的是pcm的.


          能詳細點么?

          qq:147654368 求指教啊

          # re: 用 Java Sound API 播放 PCM 音頻  回復  更多評論   

          2013-08-22 22:12 by Stream
          在不斷的嘗試下,我終于成功了,恩,LS的還是我


          LZ為什么不解釋下那幾個參數(shù)呢?
          搞我不斷的換來試......


          ps. 自己不會查API呀-__-

          只有注冊用戶登錄后才能發(fā)表評論。


          網站導航:
           
          主站蜘蛛池模板: 林口县| 涟水县| 即墨市| SHOW| 东乡族自治县| 福海县| 清原| 德惠市| 莱西市| 井陉县| 金坛市| 彭山县| 南木林县| 泰宁县| 临颍县| 津市市| 沅江市| 从化市| 安阳县| 江西省| 奉化市| 武清区| 岚皋县| 遂溪县| 高青县| 江源县| 陇南市| 内江市| 达拉特旗| 娄烦县| 罗定市| 林州市| 甘谷县| 清远市| 德清县| 铜梁县| 台南县| 东丰县| 蒙城县| 绥阳县| 镇坪县|