I'm attempting to decode a received RTP stream and save it to a .wav file using NAudio, similar to How to decode RTP packets and save it has .wav file.
I've tried a few different approaches but none have resulted in a .wav file that is recognised by Windows Media Player.
Here's how I define my wave file writer.
var waveFileWriter = new WaveFileWriter("out.wav", new WaveFormat(8000, 16, 1));
Then for each RTP packet I receive I use:
private void SampleReceived(byte[] sample)
{
if (sample != null)
{
for (int index = 0; index < sample.Length; index++)
{
short pcm = MuLawDecoder.MuLawToLinearSample(sample[index]);
waveFileWriter.WriteByte((byte)(pcm & 0xFF));
waveFileWriter.WriteByte((byte)(pcm >> 8));
}
}
}
The code runs without an error but when I try to open the .wav file in Windows Media Player I get an error. I've used WireShark to confirm that the RTP stream is ulaw. Is this the right type of approach to use with NAudio?