输出wav文件主要格式在于文件头
WaveHeader header = new WaveHeader(sun);//sun为文件字节数
//length field = size of the content (PCMSize) + size of the header field (excluding the first 4 bytes of the identifier RIFF and the fileLength itself 4 bytes)
header.fileLength = sun + (44 - 8);
header.FmtHdrLeth = 16;
header.BitsPerSample = 16;
header.Channels = 6;//通道数
header.FormatTag = 0x0001;
header.SamplesPerSec = 4000000; //采样率
header.BlockAlign = (short)(header.Channels * header.BitsPerSample / 8);
header.AvgBytesPerSec = header.BlockAlign * header.SamplesPerSec;
header.DataHdrLeth = sun;
byte[] h = header.getHeader();
assert h.length == 44; //WAV standard, the header should be 44 bytes 去掉44就是pcm
其次输出多个通道数据数据格式
for(int i=0;i<bytes.length;i+2){
out.write(byte1,i,i+2);//1号通道 数据为2个字节数据
out.write(byte1,i,i+2);//2号通道
out.write(byte1,i,i+2);//3号通道
}
//依次轮巡输出数据可形成多个通道为1个wav文件
多通道数据格式
单通道数据格式为
InputStream fis = new FileInputStream(src[0]);
// Calculate the length
byte[] buf = new byte[1024 * 4];
int size = fis.read(buf);
int PCMSize = 0;
while (size != -1) {
PCMSize += size;
size = fis.read(buf);
}
fis.close();
// Fill in the parameters, bit rate and so on. Here is the 16-bit mono 8000 hz
WaveHeader header = new WaveHeader(PCMSize);
//length field = size of the content (PCMSize) + size of the header field (excluding the first 4 bytes of the identifier RIFF and the fileLength itself 4 bytes)
header.fileLength = PCMSize + (44 - 8);
header.FmtHdrLeth = 16;
header.BitsPerSample = 16;
header.Channels = 1;
header.FormatTag = 0x0001;
header.SamplesPerSec = 4000000; //采样率
header.BlockAlign = (short)(header.Channels * header.BitsPerSample / 8);
header.AvgBytesPerSec = header.BlockAlign * header.SamplesPerSec;
header.DataHdrLeth = PCMSize;
byte[] h = header.getHeader();
assert h.length == 44; //WAV standard, the header should be 44 bytes 去掉44就是pcm
byte[] b = new byte[10];
FileOutputStream fs = new FileOutputStream(src[1]);
fs.write(h);
FileInputStream fiss = new FileInputStream(src[0]);
byte[] bb = new byte[10];
int len = -1;
while((len = fiss.read(bb))>0) {
fs.write(bb, 0, len);
}
fs.close();
fiss.close();
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。