Need help saving .wav file from RTP G711

Wed at 4:12 AM
I'm having a problem with NAudio 1.8 when creating a .wav file from a G711 RTP stream. Can anyone help?

The wav files created by NAudio have loud machine-gun noise that obscures the voice audio. Intelligible audio is present, but it's masked by the pulsating, clicking noise. Wireshark plays audio from the pcap files without a problem. Wireshark shows the sample rate is 8K ulaw.

Here's my code:

if (wavOutput == null)
{
string today = DateTime.Now.ToString("yyyy-MM-dd");
wavOutput = new WaveFileWriter("D:\Calls\" + today + "\" + CallID + ".wav", new WaveFormat(8000, 16, 1));
}

for (int index = 0; index < udpPacket.PayloadData.Length; index++)
{
short pcm = MuLawDecoder.MuLawToLinearSample(udpPacket.PayloadData[index]);
wavOutput.WriteByte((byte)(pcm & 0xFF));
wavOutput.WriteByte((byte)(pcm >> 8));

}

Fri at 8:29 PM
The error is in these lines I assume:
wavOutput.WriteByte((byte)(pcm & 0xFF));
wavOutput.WriteByte((byte)(pcm >> 8));
Rest seems correct to me. I recommend to use "bitconverter.getbytes()" instead.
Sat at 2:33 AM
Freefall, thanks for the idea. Unfortunately, I get the same result when using bitconverter.getbytes(). Also, I confirmed I am calling wavOutput.Dispose(). Other ideas?
Sun at 12:01 PM
Edited Sun at 12:02 PM
Noise may be also caused by the g711 compression, anyway, if wireshark plays it better there might be a bug in the NAudio mulaw decoder...