📄 form1.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Begin VB.Form Form1
Caption = "RS232 PWM file maker"
ClientHeight = 870
ClientLeft = 60
ClientTop = 360
ClientWidth = 6150
LinkTopic = "Form1"
ScaleHeight = 870
ScaleWidth = 6150
StartUpPosition = 3 '窗口缺省
Begin MSComctlLib.ProgressBar ProgressBar1
Height = 375
Left = 0
TabIndex = 2
Top = 480
Width = 6135
_ExtentX = 10821
_ExtentY = 661
_Version = 393216
Appearance = 1
End
Begin VB.CommandButton Command2
Caption = "Convert to PWM file"
Height = 495
Left = 3120
TabIndex = 1
Top = 0
Width = 3015
End
Begin MSComDlg.CommonDialog CommonDialog2
Left = 3480
Top = 0
_ExtentX = 847
_ExtentY = 847
_Version = 393216
CancelError = -1 'True
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 3000
Top = 0
_ExtentX = 847
_ExtentY = 847
_Version = 393216
CancelError = -1 'True
End
Begin VB.CommandButton Command1
Caption = "Open 11520sps stereo WAV file"
Height = 495
Left = 0
TabIndex = 0
Top = 0
Width = 3015
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim taskhandle As Long
Dim sampsPerChanWritten As Long
Dim databf() As Integer
Dim data() As Byte
Dim head(43) As Byte
Dim sizef As Long
Dim sizel As Long
Dim bitx(9) As Byte
Dim s As Double
Dim x As Double
Dim leng As Long
Private Sub Command1_Click()
On Error GoTo ex1
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then Exit Sub
Open CommonDialog1.FileName For Binary As #1
Get #1, , head()
sizef = head(24) + CLng(head(25)) * 256
sizel = head(4) + CLng(head(5)) * 256 + CLng(head(6)) * 65536 + CLng(head(7)) * 65536 * 256
If sizef <> 11520 Then
MsgBox ("请使用采样率为11520Hz的立体声WAV格式")
Exit Sub
End If
leng = (sizel - 36) / 4
Close #1
ex1:
End Sub
Private Sub Command2_Click()
On Error GoTo ex2
CommonDialog2.ShowSave
If CommonDialog1.FileName = "" Then Exit Sub
Open CommonDialog1.FileName For Binary As #1
Get #1, , head()
sizef = head(24) + CLng(head(25)) * 256
sizel = head(4) + CLng(head(5)) * 256 + CLng(head(6)) * 65536 + CLng(head(7)) * 65536 * 256
ReDim databf((sizel - 36) / 2)
ReDim data((sizel - 36) / 4)
Get #1, , databf()
Close #1
For i = 0 To (sizel - 36) / 2 - 1 Step 2
x = (CDbl(databf(i)) + CDbl(databf(i + 1))) / 2
kk = x / 3641 + 9
data(i / 2) = bitx(CLng(kk / 2))
data(i / 2 + 1) = bitx(CLng(kk - CLng(kk / 2)))
ProgressBar1.Value = i * 200 / (sizel - 36)
Next i
If CommonDialog2.FileName = "" Then Exit Sub
Open CommonDialog2.FileName For Binary As #1
Put #1, , data()
Close #1
ex2:
End Sub
Private Sub Form_Load()
CommonDialog1.FileName = ""
CommonDialog2.FileName = ""
s = 0
bitx(0) = &HFF
bitx(1) = &HEF
bitx(2) = &HBB
bitx(3) = &H6B
bitx(4) = &H55
bitx(5) = &H4A
bitx(6) = &H22
bitx(7) = &H8
bitx(8) = &H0
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -