I have a very specific question. I'd like to know precisely how to draw a waveform for a .wav file. Even more specifically I need help on getting the waveform x and y co-ordinates from the wav file, the process of drawing these points is not the subject of this question. I have no relevant code to post as all of my attempts thus far have been based on other peoples work and I am not able to get them working.
Thanks.
I've started working from the code in the first link below. The original code comes up with a number of errors as things are not defined, although this is relatively easy to fix.
Private Sub cmdDefault_Click(……) Handles cmdDefault.Click
Try
SoundDevice = New Microsoft.DirectX.DirectSound.Device
SoundDevice.SetCooperativeLevel(Me.Handle_
, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal)
SbufferOriginal = New _ Microsoft.DirectX.DirectSound._
SecondaryBuffer(SoundFile, SoundDevice)
SbufferOriginal.Play(0,_
Microsoft.DirectX.DirectSound.BufferPlayFlags.Looping)
Catch ex As Exception
End Try
End Sub
I've basically added a 'Dim x as y' for each undefined variable. The only variable the type for which isn't clear is "SoundFile", I've found it should be of the type "Microsoft.DirectX.DirectSound.BufferDescription". So the above becomes:
Private Sub cmdDefault_Click(……) Handles cmdDefault.Click
Try
Dim SoundDevice = New Microsoft.DirectX.DirectSound.Device
SoundDevice.SetCooperativeLevel(Me.Handle, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal)
Dim SbufferOriginal = New Microsoft.DirectX.DirectSound.SecondaryBuffer(Microsoft.DirectX.DirectSound.BufferDescription, SoundDevice)
SbufferOriginal.Play(0, Microsoft.DirectX.DirectSound.BufferPlayFlags.Looping)
Catch ex As Exception
End Try
End Sub
The issue is I'm lost as where to go from here. THIS IS MY QUESTION.
Here SoundFile
can be a BufferDescription
, but from the context I would guess that it is most likely here either a Stream
(could be FileStream, MemoryStream, etc) or a string
for the file path to the .wav file. See the various constructor overloads for SecondaryBuffer
.
The only other incomplete thing about the code you've posted is that it has scrapped the Sub arguments for the sake of brevity (it is a Click
handler so it needs the standard arguments). To make this work you would only need to do something like this :
Private Sub PlaySound(ByVal SoundFilePath as String)
Try
SoundDevice = New Microsoft.DirectX.DirectSound.Device
SoundDevice.SetCooperativeLevel(Me.Handle, _
Microsoft.DirectX.DirectSound.CooperativeLevel.Normal)
SbufferOriginal = New _ Microsoft.DirectX.DirectSound._
SecondaryBuffer(SoundFilePath, SoundDevice)
SbufferOriginal.Play(0, _
Microsoft.DirectX.DirectSound.BufferPlayFlags.Looping)
Catch ex As Exception
'do something for exception
End Try
End Sub
Where you would call it like
PlaySound("C:\MySounds\Foo.wav")
This should probably get you started. If you continue working through the tutorial you originally posted (where this code came from) and post back here with questions when you get stuck you should be able to work to a point where you can get the visualizations you are after. Most of what you need is in that tutorial.