为什么写入 BinaryWriter 两次?
Why write to BinaryWriter twice?
我正在实施这个音调发生器程序并且效果很好:
我想不通的是为什么下面两行代码:
BW.Write(Sample)
BW.Write(Sample)
一个"write"是有道理的,但为什么第二个"write"?
示例有点含糊,但波形文件配置为 2 个通道,因此两次写入只是将相同的音频数据发送到两个通道。
波头是这个硬编码位:
Dim Hdr() As Integer = {&H46464952, 36 + Bytes, &H45564157, _
&H20746D66, 16, &H20001, 44100, _
176400, &H100004, &H61746164, Bytes}
解码后的意思是:
H46464952 = 'RIFF' (little endian)
36+Bytes = Length of header + length of data
H45564157 = 'WAVE' (little endian)
H20746D66 = 'fmt ' (little endian)
16 = length of fmt chunk (always 16)
H20001 = 0x0001: PCM,
0x0002: 2 channels
44100 = sampleRate
176400 = sampleRate*numChannels*bytesPerSample = 44100*2*2
H100004 = 0x0004: numChannels*bytesPerSample,
0x0010: bitsPerSample (16)
H61746164 = 'data'
Bytes = size of data chunk
我正在实施这个音调发生器程序并且效果很好:
我想不通的是为什么下面两行代码:
BW.Write(Sample)
BW.Write(Sample)
一个"write"是有道理的,但为什么第二个"write"?
示例有点含糊,但波形文件配置为 2 个通道,因此两次写入只是将相同的音频数据发送到两个通道。
波头是这个硬编码位:
Dim Hdr() As Integer = {&H46464952, 36 + Bytes, &H45564157, _
&H20746D66, 16, &H20001, 44100, _
176400, &H100004, &H61746164, Bytes}
解码后的意思是:
H46464952 = 'RIFF' (little endian) 36+Bytes = Length of header + length of data H45564157 = 'WAVE' (little endian) H20746D66 = 'fmt ' (little endian) 16 = length of fmt chunk (always 16) H20001 = 0x0001: PCM, 0x0002: 2 channels 44100 = sampleRate 176400 = sampleRate*numChannels*bytesPerSample = 44100*2*2 H100004 = 0x0004: numChannels*bytesPerSample, 0x0010: bitsPerSample (16) H61746164 = 'data' Bytes = size of data chunk