WavPlayDsp




Option Explicit
Private Sub Command1_Click()
Dim FileNumber As Integer
Dim I As Single
Dim Min As Single
Dim Max As Single
Dim Temp As Integer
Dim XZoomrate As Single
Dim YZoomrate As Single
Dim LastX As Single
Dim LastY As Single
'On Error GoTo ErrorHandler

'Enable Cancel error

With CommonDialog1
.CancelError = True
.Filter = "Wave files (*.wav)|*.wav"
.ShowOpen
'Change the caption of the form

Me.Caption = .filename
I = 44 ' Set I To 44, since the wave sample is begin at Byte 44.
' Open file to get the length of the wave file.

FileNumber = FreeFile
Open .filename For Random As #FileNumber
Do
Get #FileNumber, I, Temp
I = I + 1
'Get the smallest and largest number. T

'hey will be use for the adjustment

'of the vertical size.

If Temp < Min Then Min = Temp
If Temp > Max Then Max = Temp
Loop Until EOF(FileNumber)
Close #FileNumber
'Adjust values and reset values

XZoomrate = (Width / I)
YZoomrate = (Max - Min) / (Height / 2)
CurrentX = 100
CurrentY = Height / 2
LastX = 100
LastY = Height / 2
Picture1.AutoRedraw = True
I = 44
'Reopen file using a different FileNumber

FileNumber = FileNumber + 1
Picture1.Cls
Open .filename For Random As #FileNumber
Do
Get #FileNumber, I, Temp
'Set CurrentX and CurrentY

CurrentX = CurrentX + XZoomrate
CurrentY = (Temp / YZoomrate) + Height / 2
'Plot graph

Picture1.Line (LastX, LastY)-(CurrentX, CurrentY), vbBlack
'Reset values

LastX = CurrentX
LastY = CurrentY
I = I + 1
If CurrentX > Width Then Exit Do
Loop Until EOF(FileNumber)
Close #FileNumber
End With
ErrorHandler:
'Do nothing

End Sub

Private Sub Form_Resize()
On Error Resume Next
'Resize control

With Picture1
.BackColor = vbWhite
.ForeColor = vbBlack
.Move 50, 500, Width - 200, Height - 800
End With
End Sub











( wavplaydsp.html )- by Paolo Puglisi - Modifica del 17/12/2023