Question

Hello 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
Was it helpful?

Solution

NAudio is not having any effect at all in your code sample. All you are doing is reading data from a file, and sending it to the serial port. RawSourceWaveStream simply attaches a WaveFormat to the file stream, but nothing is reading that stream. Whatever device you have listening to the audio data you're sending over the serial port will have an audio format it is expecting. You need to find out what that is. Then you can use NAudio to convert the audio to the correct format if it is not already at the right sample rate / channel count (which would be the two most likely causes of audio playing at 50% speed)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top