title: Create a .wav file from the microphone's data
body: <p>I want just record audio from the microphone and save it in a .wav file.
  This is my c# code:</p>
  
  <pre><code>            IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(Filename, FileMode.Create, myIsolatedStorage);
  
              // Add wave header:
  
              BinaryWriter bw = new BinaryWriter(fileStream);
              bw.Write(new char[4] { 'R', 'I', 'F', 'F' });
  
              bw.Write((int)fileStream.Length + 36);
  
              bw.Write(new char[8] { 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ' });
  
              bw.Write((int)16);
  
              bw.Write((short)1);
              short channels = 2;
              bw.Write(channels);
              int samplerate = 8000;
              bw.Write(samplerate);
              short BitsPerSample = 8;
              bw.Write((int)(samplerate * ((BitsPerSample * channels) / 8)));
  
              bw.Write((short)((BitsPerSample * channels) / 8));
  
              bw.Write(BitsPerSample);
  
              bw.Write(new char[4] { 'd', 'a', 't', 'a' });
              int DataLength = (int)fileStream.Length;
              bw.Write(DataLength);
  
  
              fileStream.Write(stream.GetBuffer(), 44, (int)stream.Position);
  
              fileStream.Position = 0;
  
              bw.Close();
              fileStream.Close();
  </code></pre>
  
  <p>if I open the .wav file with VLC, it doesn't reproduce anything.
  If instead I open the file in this way ( see below ), just after I saved it, then it reproduce the sound correctly:</p>
  
  <pre><code> byte[] buffer = new byte[microphone.GetSampleSizeInBytes(duration)];
   using (IsolatedStorageFile userStore = IsolatedStorageFile.GetUserStoreForApplication())
   using (IsolatedStorageFileStream openfilestream = userStore.OpenFile(Filename, FileMode.Open))
              {
                  openfilestream.Read(buffer, 0, buffer.Length);
              }
  
    SoundEffect sound = new SoundEffect(buffer, microphone.SampleRate, AudioChannels.Mono);
    soundInstance = sound.CreateInstance();
    soundIsPlaying = true;
    soundInstance.Play();
  </code></pre>
  
  <h2>Edited code</h2>
  
  <p>I just edit the code above as Adriano said (but it doesn't work):</p>
  
  <pre><code>            IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(Filename, FileMode.Create, myIsolatedStorage);
              fileStream.Write(stream.GetBuffer(), 44, (int)stream.Position);
  
  
              // Aggiunta wav header:
  
              BinaryWriter bw = new BinaryWriter(fileStream);
              bw.Write(new char[4] { 'R', 'I', 'F', 'F' });
  
              bw.Write((int)fileStream.Length - 8);
  
              bw.Write(new char[8] { 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ' });
  
              bw.Write((int)16);
  
              bw.Write((short)1);
              short channels = 1;
              bw.Write(channels);
              int samplerate = 8000;
              bw.Write(samplerate);
              short BitsPerSample = 8;
              bw.Write((int)(samplerate * ((BitsPerSample * channels) / 8)));
  
              bw.Write((short)((BitsPerSample * channels) / 8));
  
              bw.Write(BitsPerSample);
  
              bw.Write(new char[4] { 'd', 'a', 't', 'a' });
              int DataLength = (int)fileStream.Length - 44;
              bw.Write(DataLength);
  
              fileStream.Position = 0;
  
              bw.Close();
              fileStream.Close();
  </code></pre>