title: How to convert PCM data to wav file?
body: <p>I have all the data in rawData1 aray it is short array.
  I have converted it to byte aray.Then I created wav file header and then that header and byte array data is written in file. But I am getting error "Windows media player getting problem while playing file".Can any body help me?</p>
  
  <pre><code>        public void save file
          {
           byte[] byte_array = new byte[rawData1.Length * 2];
          for (int i = 0; i &lt; rawData1.Length; ++i)
          {
              //byte_array[2 * i] = getByte1(rawData1[i]);
              //byte_array[2 * i + 1] = getByte2(rawData1[i]);
              byte_array[2 * i] = getByte2(rawData1[i]);
              byte_array[2 * i + 1] = getByte1(rawData1[i]);
          }
  
          uint numsamples = 44100;
          ushort numchannels = 2;
          ushort samplelength = 1; // in bytes
          uint samplerate = 22050;
  
          StorageFolder storageFolder = KnownFolders.MusicLibrary;
          StorageFile file = await storageFolder.CreateFileAsync("sample.wav",     CreationCollisionOption.GenerateUniqueName);
  
          Stream stream = await file.OpenStreamForWriteAsync();
          BinaryWriter wr = new BinaryWriter(stream);
  
          wr.Write("RIFF".ToCharArray());
          wr.Write(36 + numsamples * numchannels * samplelength);
          wr.Write("WAVEfmt".ToCharArray());
          wr.Write(16);
          wr.Write((ushort)1);
          wr.Write(numchannels);
          wr.Write(samplerate);
          wr.Write(samplerate * samplelength * numchannels);
          wr.Write(samplelength * numchannels);
          wr.Write((ushort)(8 * samplelength));
          wr.Write("data".ToCharArray());
          wr.Write(numsamples * samplelength);
          wr.Write(byte_array);
          wr.Dispose();
          stream.Dispose();
         }
         public static byte getByte1(short s)
         {
          return (byte)s;
         }
  
         public static byte getByte2(short s)
         {
          int temp= s &gt;&gt; 8;
          return (byte)temp;
         }
  </code></pre>
  
  <p>Can anybody help me?</p>