Audio app crashes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello there,
I have a little problem with an application i wrote for recording and
playing wavefiles. Everything works all right, but sometimes, especially when
i play an audiofile longer then 30 seconds twice, the application crashes -
without an error to the debugger or anything else, it simply disappears.
I checked the window messages - nothing, too.

Does somebody have an idea why this happens?

Greetings,
Cyberdot
 
Becaue there's a bug in the code? Without some code or more info on what
you're doing that's about all we can offer.

-Chris
 
Sorry, i hoped there is a general problem with the audio api. Here's the code
I use for playing (it's from the p/Invoke example):

Private Sub cmdPlay_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPlay.Click
Dim wo As WaveOut = Nothing
bolStop = False
Try
wo = New WaveOut
Dim numDevices As Integer = wo.NumDevices()
If numDevices < 1 Then
ShowLine("FAILURE: No valid sound drivers detected")
Return
End If

ShowLine(String.Format("{0} device{1} detected:", numDevices,
IIf(numDevices <> 1, "s", "")))
Dim i As Integer
For i = 0 To numDevices - 1
Dim prodName As String = ""
If Wave.MMSYSERR.NOERROR <> wo.GetDeviceName(i, prodName) Then
ShowLine(String.Format(" {0}: Failed to get name", i))
Else
ShowLine(String.Format(" {0}: {1}", i, prodName))
End If
Next

Dim fileName As String =
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase
fileName = Path.GetDirectoryName(fileName)
fileName = Path.Combine(fileName, "test.wav")
ShowLine("Playing sound test.wav")
ShowLine("Setting stream buffers to 1024KB total")
If Wave.MMSYSERR.NOERROR <> wo.Play(fileName, 6 * 1024 * 1024,
&HFFFF, &HFFFF) Then
ShowLine("FAILURE: Failed to play sound test.wav")
End If

Dim soundLength As Integer = wo.Milliseconds()
Dim sleepTime As Integer

ShowLine("Waiting for sound to finish...")
sleepTime = 5
Dim watchDog As Integer = 0
Dim maxLoops As Integer = wo.Milliseconds() / sleepTime

While Not wo.Done()
Thread.Sleep(sleepTime)
Application.DoEvents()
watchDog += 1

If watchDog > maxLoops Then
ShowLine("FAILURE: Failed to detecte end of sound")
Return
End If

If bolStop Then
Exit While
End If
End While

ShowLine("Stopped on " & watchDog & "/" & maxLoops)
ShowLine("Done playing sound")
Finally

If Not (wo Is Nothing) Then
wo.Dispose()
End If
pbStatus.Value = 0

End Try
End Sub

This code uses the waveOut Class from Microsoft. It's a little bit to long
to post it here, but I changed nothing in it, and I don't think there's an
mistake in it...

Greetings,
Cyberdot
 
What waveOut class? Are you referring to a sample on the MSDN? If so, which
one?
 
Back
Top