`
yangxiutian
  • 浏览: 59999 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

测试代码

阅读更多
package test;

import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;

public class TestAudio
{
    public static void main(String[] args) throws LineUnavailableException,
            UnsupportedAudioFileException, IOException//RIFF Chunk DWORD WORD
    {
        AudioInputStream ais = AudioSystem.getAudioInputStream(new File(
                "C:\\Documents and Settings\\zkf57310\\桌面\\2.wav"));
       
        //每秒的样本数、每个样本中的位数、声道数、是否有符号、big-endian(true)/little-endian(false)
        AudioFormat af = new AudioFormat(44100, 16, 2, true, false);//帧大小(字节)= 样本(以字节为单位)* 声道数
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, af);
        SourceDataLine objSDL = (SourceDataLine) AudioSystem.getLine(info);
        objSDL.open(af, 176400);
       
        byte data[] = new byte[1024];
        byte testData[] = new byte[4];
        int buff = 1024;
        long before = 0;
        while ((buff = ais.read(data, 0, buff)) != -1)
        {
            objSDL.write(testData, 0, 4);
            objSDL.start();
           
            //测试时间
            long now = System.currentTimeMillis();
            if (now - before != 0)//不知道为什么会等于0
            {
                System.out.println(now - before);
                before = now;
            }
            //System.out.println(now - before);
        }
    }
}
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics