This project has moved. For the latest updates, please go here.

.Net UDP Streaming playback

Mar 27, 2014 at 5:56 PM
I have tried to resolve this one myself using various suggestions found is discussions here and elsewhere but I cannot.
            Dim stream1 As WaveStream = New RawSourceWaveStream(memStm, New Gsm610WaveFormat)
            Dim pcmStream = WaveFormatConversionStream.CreatePcmStream(stream1)
            player.Init(New LoopStream(pcmStream))
            player.Play()
Where LoopStream is something Mark Heath posted on an earlier discussion, I have been using it to force the WaveOutEvent to keep playing.
Class LoopStream
    Inherits WaveStream
    Public Sub New(ByVal source As WaveStream)
        _sourceStream = source
    End Sub
    Dim _sourceStream As WaveStream
    Public Overrides ReadOnly Property Waveformat As WaveFormat
        Get
            Return _sourceStream.WaveFormat
        End Get
    End Property
    Public Overrides ReadOnly Property Length As Long
        Get
            Return Long.MaxValue / 32
        End Get
    End Property
    Public Overrides Property Position As Long
        Get
            Return _sourceStream.Position
        End Get
        Set(value As Long)
            _sourceStream.Position = value
        End Set
    End Property
    Public Overrides Function HasData(ByVal count As Integer) As Boolean
        'infinite loop
        Return True
    End Function
    Public Overrides Function Read(ByVal Buffer() As Byte, ByVal offset As Integer, ByVal count As Integer) As Integer
        Read = 0
        While (Read < count)
            Dim required As Integer = count - Read
            Dim readThisTime As Integer
            readThisTime = _sourceStream.Read(Buffer, offset + Read, required)
            If readThisTime < required Then
 
            End If
            If _sourceStream.Position >= _sourceStream.Length Then
   
            End If
            Read += readThisTime
        End While
        Return Read
    End Function
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        _sourceStream.Dispose()
        MyBase.Dispose(disposing)
    End Sub
End Class
Basically, this setup works but is crackling and not playing back well. I've tried to modify the LoopStream Class to provide silence when there is nothing in the buffer, but I am really not sure what I am doing.

I have also tried to use a BufferedWaveProvider as that would be ideal but when I use it like this
    Dim bufferedProvider As New BufferedWaveProvider(New Gsm610WaveFormat)
            player.Init(bufferedProvider)
            player.Play()
I get the exception WaveBadFormat calling waveOutOpen making me think that I can't use one with the Gsm610WaveFormat.

And some other info in advance, I am successfully writing the data to a file using a WaveFileWriter and the files are crystal clear. I am using NAudio v1.7.
Thanks for any comments or suggestions!
Coordinator
Apr 4, 2014 at 1:56 PM
you can't play compressed formats directly, you must convert to PCM (using WaveFormatConversionSteam or AcmStream for lower level)
Apr 4, 2014 at 2:08 PM
Thanks for the reply. I believe that is what I am doing up top. But how can I create an input buffer to keep the audio from being choppy as it enters? I can't pass a PCM stream to a bufferedwaveprovider that I can tell. The Loopstream class is the closest to accomplishes this I've come and I've tried several different ways. I've also tried to use the ACMStream code from the web chat example but I had some trouble. Thanks for NAudio, greatly appreciate it!
Coordinator
Apr 4, 2014 at 2:21 PM
you can put PCM into a buffered wave provider. That's how the network chat demo with the NAudio source code works
Apr 4, 2014 at 2:41 PM
Okay, I will spend some more time in that example. I think I was getting pretty close. Thank you.