如何使用BinaryReader读取midi文件(格式规范为here)
我正在使用vb.net,但我愿意看到其他代码(大多数只是C#,我可以转换它)。我正在做一个大项目,这有点像一个速度爆炸。
这是我目前的代码:
Private Function convertCharArrayToString(ByVal chars() As Char) As String
Dim tReturn As String = ""
For Each v As Char In chars
tReturn &= v
Next
Return tReturn
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
midiStatus = "Reading..."
Dim midiStream As New StreamReader(midiFile)
Dim nBR As New BinaryReader(midiStream.BaseStream)
midiStatus = "Validating Midi File..."
Dim HeaderA As String = convertCharArrayToString(nBR.ReadChars(4))
If Not HeaderA = "MThd" Then Return
Dim HeaderB() As Byte = nBR.ReadBytes(4)
'Get Track Type
midiStatus = "Reading Header Data..."
Dim TrackType1 As Integer = nBR.ReadInt16()
Dim TrackType2 As Integer = nBR.ReadInt16()
MsgBox(TrackType1 & TrackType2)
End Sub
当我开始阅读实际的标题数据时,一切正常。关于我如何继续,我完全迷失了。任何帮助或代码示例都会很好!