Problem Play Raw file using Naudio

Feb 17 at 5:27 AM
Hello sir i have following code to play raw file.my raw file duration is 25 second. this code is working fine but after sometime my program play raw file very slow almost 50% speed and my raw file duration is increase 36 second when i restart my pc and run my program its working normaly again. i need to restart my pc every one hour to work correctly please check what is wrong with my code here is my code

Try
        Dim rawStream = File.OpenRead("C:\myFile.raw")
        Dim waveFormat = New NAudio.Wave.WaveFormat(8000, 16, 1)
        Dim rawSource = New RawSourceWaveStream(rawStream, waveFormat)
        Dim audioBufferSize = 320
        Dim offset As Integer = 0
        Dim buffer As Byte() = New Byte(audioBufferSize - 1) {}
        Dim buffer2 As Byte() = New Byte(320) {}
        While (rawSource.Read(buffer2, offset, audioBufferSize) > 0)
            msport.Write(buffer2, offset, audioBufferSize)
            Thread.Sleep(20)
        End While
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
Feb 17 at 12:41 PM
Not sure but perhaps the "Thread.Sleep(20)" line is causing the problem?
Coordinator
Feb 17 at 12:45 PM
If its playing at 50%, you're probably sending the wrong sample rate / channel count.
Really you should be looking for help in the documentation of whatever serial port audio device you are using. NAudio isn't necessary at all in the code sample you are showing. All it does is sends the contents of a raw file to msport.
Feb 17 at 2:07 PM
but sir if i sending wrong sample rate channel count then why this code working perfactly for sometime its happened after 30 min or 40 min or after one hour when my raw file playing speed slow then i checked gsm modem default software and play file gsm modem with default software its working perfactly.
Coordinator
Feb 17 at 4:03 PM
well you're probably sending audio too fast or slow. But this has nothing to do with NAudio. NAudio is contributing nothing to your code, and you don't need RawSourceWaveStream at all.