18045010223
7 天以前 afe371d39a054b2f2a9e5875b945584eec8a8141
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cn.org.hentai.jtt1078.test;
 
import cn.org.hentai.jtt1078.util.ByteUtils;
import cn.org.hentai.jtt1078.util.Packet;
 
import java.io.FileInputStream;
import java.io.FileOutputStream;
 
/**
 * Created by matrixy on 2019/12/18.
 */
public class WAVTest
{
    public static void main(String[] args) throws Exception
    {
        int len;
        byte[] block = new byte[1024 * 2048];
        FileInputStream fis = new FileInputStream("d:\\temp\\xxoo.pcm");
        Packet p = Packet.create(1024 * 2048);
        while ((len = fis.read(block)) > -1)
        {
            p.reset();
            p.addBytes("RIFF".getBytes())
                    .addBytes(ByteUtils.toLEBytes(len + 36))
                    .addBytes("WAVE".getBytes())                                    // wave type
                    .addBytes("fmt ".getBytes())                                    // fmt id
                    .addInt(0x10000000)                                             // fmt chunk size
                    .addShort((short)0x0100)                                        // format: 1 -> PCM
                    .addShort((short)0x0100)                                        // channels: 1
                    .addBytes(ByteUtils.toLEBytes(8000))                            // samples per second
                    .addBytes(ByteUtils.toLEBytes(1 * 8000 * 16 / 8))               // BPSecond
                    .addBytes(ByteUtils.toLEBytes((short)(1 * 16 / 8)))             // BPSample
                    .addBytes(ByteUtils.toLEBytes((short)(1 * 16)))                 // bPSecond
                    .addBytes("data".getBytes())                                    // data id
                    .addBytes(ByteUtils.toLEBytes(len));                            // data chunk size
 
            p.addBytes(block, len);
 
            FileOutputStream fos = new FileOutputStream("d:\\fuck.wav");
            fos.write(p.getBytes());
            fos.flush();
            fos.close();
        }
    }
}