The following code reads a .wav file into a byte array then calls the sub to draw the sine wave onto a picturebox. The attached bitmap shows what the resultant sine wave looks like.
What I need to do is to modify the code in sub DisplaySineWave so that instead of sending the entire byte array of data at one time I want to send smaller segments of the buffer to the sub and call the sub many times and get the same results as I play the sound data. This will cause the sine wave to be displayed little by little as the sound is being played instead of showing the sine wave all at once. If it wasn't for the Picture1.Scale (X1, Y1)-(X2, Y2) I could probably figure it out by just drawing each segment of the wave, keeping track of where I am in the X-position, drawing more wave from each previous position but when I try to do it this way I just wind up with a garbage sine wave that looks nothing like the original picture. I'm sure one of my problems is I don't know how to adjust the Picture1.Scale for each time I call the sub or even if I should.
What I need to do is to modify the code in sub DisplaySineWave so that instead of sending the entire byte array of data at one time I want to send smaller segments of the buffer to the sub and call the sub many times and get the same results as I play the sound data. This will cause the sine wave to be displayed little by little as the sound is being played instead of showing the sine wave all at once. If it wasn't for the Picture1.Scale (X1, Y1)-(X2, Y2) I could probably figure it out by just drawing each segment of the wave, keeping track of where I am in the X-position, drawing more wave from each previous position but when I try to do it this way I just wind up with a garbage sine wave that looks nothing like the original picture. I'm sure one of my problems is I don't know how to adjust the Picture1.Scale for each time I call the sub or even if I should.
Code:
'
'
Private SoundData() As Byte
'
'
Private Sub Command1_Click()
Dim c_Ptr As Long
Open App.Path & "\test1.wav" For Binary As #1
ReDim SoundData(LOF(1) - 1)
Get #1, , SoundData
Close #1
c_Ptr = 44 ' Offset 44 is where actual sound data begins
DisplaySineWave c_Ptr, SoundData
End Sub
Private Sub DisplaySineWave(ptrData As Long, ByRef SoundBuffer() As Byte)
Dim X1 As Long, Y1 As Long, X2 As Long, Y2 As Long
X1 = 0
Y1 = 32767
X2 = UBound(SoundBuffer) / 2
Y2 = -32768
Picture1.Scale (X1, Y1)-(X2, Y2)
'
' Start drawing the Sine Wave
'
For i = X1 To X2 - 2
Picture1.PSet (i, ReadInteger(ptrData, byteBuffer)) ' map the wave data to picture box
ptrData = ptrData + 2
Next i
End Sub
Private Function ReadInteger(Ptr As Long, ByRef byteBuffer() As Byte) As Integer
'
' Read an Integer (2 byte) Value
'
CopyMemory ReadInteger, byteBuffer(Ptr), 2&
End Function