求助wave文件格式!

vc_dreamver 2006-09-07 11:57:57
各位好,哪位有详细的wav文件格式,请帮忙提供一下。
我读取了wav文件的前8字节,分别为 “RIFF”与一个整型数,按照一些资料上说,
整型数为文件长度-8,可是我得到的确是文件长度-58,不知为何,请高手指点,谢谢!
...全文
191 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
vc_dreamver 2006-09-11
  • 打赏
  • 举报
回复
谢谢
happy_sea 2006-09-09
  • 打赏
  • 举报
回复
给你一段不完整的读wav文件的代码,你仔细分析一下应该对你有所帮助:

Dim yLec As Long, ydate As Date, ysg As Single
Dim yint As Integer, ybt As Byte
Dim LenData As Long, InData As Long
Dim Nbits As Integer, StMo As String
Me.Caption = "Waveform View - " & "(" & FName & ")"
Label1.Caption = "File: " & FName

Open FName For Binary Access Read As #1
Label2.Caption = "Size: " & LOF(1) & " Bytes"
Label3.Left = Label1.Left + Label1.Width + 500
Label3.Caption = "Last modified: " & FileDateTime(FName)
Label4.Caption = 0 'IniPlay of present Zoom
Label17.Caption = 0 '= selected Samples
For n = 1 To 100
X$ = Input(4, #1)
If n = 2 Then HOLDER$ = X$ ' Hold This for Saving a New Wav
If X$ = "fmt " Then Exit For 'Ignore everything else till this
Next n
'Get the Wave File Header Info
Get #1, , yLec ' 16
Get #1, , yint 'Compression Type (1=PCM)
Get #1, , yint 'is Channels, 1 if mono and 2 if stereo

If yint = 2 Then
Label9.Caption = "Stereo"
ElseIf yint = 1 Then
Label9.Caption = "Mono"
Else
Label9.Caption = "Error!"
GoTo Errhandler
End If
Get #1, , yLec 'is the Sampling frequency of the file

Label8.Caption = yLec
Get #1, , yLec 'is a multiple of the sample frequency

Get #1, , yint 'is the divisor of the number of bytes of
'data which gives the number of Samples in the .wav
yDiv = yint
Label12.Caption = yDiv
Get #1, , yint 'is the number of bits (8 or 16)

If yint = 8 Or yint = 16 Then
Label10.Caption = yint & " bits"
Else
Label10.Caption = "Error"
GoTo Errhandler
End If
GotTheData:
For n = 1 To 100
Y$ = Input(1, #1)

If Y$ = "d" Then Exit For ' Seek for start of Wav Data

Next n
Z$ = Input(3, #1)
If Z$ <> "ata" Then 'Wav Data Starts here
If n > 90 Then GoTo Errhandler
Temp = Seek(1)
Seek #1, Temp - 3
GoTo GotTheData
End If
Get #1, , yLec '= num of bytes of data, start reading data here.

Label13.Caption = yLec
LenData = yLec / yDiv
Label6(0).Caption = LenData
Label6(1).Caption = LenData
LenTemp = LenData / (Label8.Caption)
Extemp = (Int(LenTemp * 1000)) / 1000
If LenTemp - Extemp >= 0.0005 Then
Extemp = Extemp + 0.001
End If
Label14.Caption = "Length: " & Extemp & " seconds"
Label15(0).Caption = LenTemp
Label15(1).Caption = LenTemp
FimPlay = Int(LenTemp * 1000)
InData = Seek(1) 'Loc(1) + 1 is the number of the first sound data byte of the file.
Label11.Caption = InData
StMo = Label9.Caption
Nbits = Val(Label10.Caption)
MousePointer = vbHourglass 'Busy
Call GraphWave(InData, LenData, Nbits, StMo)
Close #1
Call DrawTickMarks
MousePointer = 0 ' Arrow
PlayControls = True
If Label9.Caption = "Stereo" Then
Frame2.Visible = True
Frame1.Height = 1815
Else
Frame2.Visible = False
Frame1.Height = 800
End If
MousePointer = 0
Exit Sub
Errhandler:
MsgBox "Error!!", vbOKOnly
Close #1

809

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧