C
Chad Miller
Public mLength As Integer
Public mChannels As Short
Public mSampleRate As Integer
Public mDataLength As Integer
Public mBitsPerSample As Short
Public Sub CreateWaveHeader(ByRef sPath As String)
Dim fileNumber As Integer
Try
fileNumber = FreeFile()
FileOpen(fileNumber, sPath, OpenMode.Binary, OpenAccess.Write)
'Write the RIFF bit of the header first.
FilePut(fileNumber, "RIFF", 1)
FilePut(fileNumber, mLength, 5)
'Then do the wave header.
FilePut(fileNumber, "WAVEfmt ", 9)
FilePut(fileNumber, CInt(16), 17)
FilePut(fileNumber, CShort(1), 21)
FilePut(fileNumber, mChannels, 23)
FilePut(fileNumber, mSampleRate, 25)
FilePut(fileNumber, CInt(mSampleRate * ((mBitsPerSample *
mChannels) / 8)), 29)
FilePut(fileNumber, CShort((mBitsPerSample * mChannels) / 8),
33)
FilePut(fileNumber, mBitsPerSample, 35)
FilePut(fileNumber, "data", 37)
FilePut(fileNumber, mDataLength, 41)
Catch ex As Exception
Throw ex
Finally
FileClose(fileNumber)
End Try
End Sub
Public Sub CreateWaveHeaderEx(ByRef sPath As String)
Try
Using bw As New BinaryWriter(File.Open(sPath,
FileMode.OpenOrCreate, FileAccess.Write))
'Write the RIFF bit of the header first.
bw.Write("RIFF")
bw.Write(mLength)
'Then the wave header.
bw.Write("WAVEfmt ")
bw.Write(CInt(16))
bw.Write(CShort(1))
bw.Write(mChannels)
bw.Write(mSampleRate)
bw.Write(CInt(mSampleRate * ((mBitsPerSample * mChannels) /
8)))
bw.Write(CShort((mBitsPerSample * mChannels) / 8))
bw.Write(mBitsPerSample)
bw.Write("data")
bw.Write(mDataLength)
bw.Flush()
End Using
Catch ex As Exception
Throw ex
End Try
End Sub
Public mChannels As Short
Public mSampleRate As Integer
Public mDataLength As Integer
Public mBitsPerSample As Short
Public Sub CreateWaveHeader(ByRef sPath As String)
Dim fileNumber As Integer
Try
fileNumber = FreeFile()
FileOpen(fileNumber, sPath, OpenMode.Binary, OpenAccess.Write)
'Write the RIFF bit of the header first.
FilePut(fileNumber, "RIFF", 1)
FilePut(fileNumber, mLength, 5)
'Then do the wave header.
FilePut(fileNumber, "WAVEfmt ", 9)
FilePut(fileNumber, CInt(16), 17)
FilePut(fileNumber, CShort(1), 21)
FilePut(fileNumber, mChannels, 23)
FilePut(fileNumber, mSampleRate, 25)
FilePut(fileNumber, CInt(mSampleRate * ((mBitsPerSample *
mChannels) / 8)), 29)
FilePut(fileNumber, CShort((mBitsPerSample * mChannels) / 8),
33)
FilePut(fileNumber, mBitsPerSample, 35)
FilePut(fileNumber, "data", 37)
FilePut(fileNumber, mDataLength, 41)
Catch ex As Exception
Throw ex
Finally
FileClose(fileNumber)
End Try
End Sub
Public Sub CreateWaveHeaderEx(ByRef sPath As String)
Try
Using bw As New BinaryWriter(File.Open(sPath,
FileMode.OpenOrCreate, FileAccess.Write))
'Write the RIFF bit of the header first.
bw.Write("RIFF")
bw.Write(mLength)
'Then the wave header.
bw.Write("WAVEfmt ")
bw.Write(CInt(16))
bw.Write(CShort(1))
bw.Write(mChannels)
bw.Write(mSampleRate)
bw.Write(CInt(mSampleRate * ((mBitsPerSample * mChannels) /
8)))
bw.Write(CShort((mBitsPerSample * mChannels) / 8))
bw.Write(mBitsPerSample)
bw.Write("data")
bw.Write(mDataLength)
bw.Flush()
End Using
Catch ex As Exception
Throw ex
End Try
End Sub