java 实现wav头信息生成byts数组
public WavHeader(long totalAudioLen, int longSampleRate, int channels, int SamplesBits){
if(SamplesBits == AudioFormat.ENCODING_PCM_16BIT)
this.SamplesBits = 16;
else if(SamplesBits == AudioFormat.ENCODING_PCM_8BIT)
this.SamplesBits = 8;
if(channels == AudioFormat.CHANNEL_IN_STEREO )
this.channels = 2;
else
this.channels = 1;
this.totalAudioLen = (int)totalAudioLen;
ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder();
byteArrayBuilder.write("RIFF".getBytes());
byteArrayBuilder.write(intToByteArray((int) (totalAudioLen + 44)));
byteArrayBuilder.write("WAVE".getBytes());
byteArrayBuilder.write("fmt ".getBytes());
byteArrayBuilder.write(intToByteArray(this.SamplesBits));
byteArrayBuilder.write(charToByteArray((char)1));
byteArrayBuilder.write(charToByteArray((char)this.channels));
byteArrayBuilder.write(intToByteArray(longSampleRate));
byteArrayBuilder.write(intToByteArray(longSampleRate * channels * (this.SamplesBits/8)));
byteArrayBuilder.write(charToByteArray((char)(channels*(this.SamplesBits/8))));
byteArrayBuilder.write( charToByteArray((char)this.SamplesBits));
byteArrayBuilder.write("data".getBytes());
byteArrayBuilder.write(intToByteArray((int) totalAudioLen));
bytes = byteArrayBuilder.toByteArray();
};