title: Edit Wav File Samples for Increasing Amplitude using c#
body: <p>I have the following c# code which reads a wave file into a byte array and then writes it into another array, creating a new wave file. I found it online and dont have much knowledge about it.</p>
  
  <p>I want to change the values being written into the new array so that my amplitude is increased by let's say a value 'x' for the new wave file being generated.. Where and what should be the changes made?</p>
  
  <pre><code>    private void ReadWavfiles(string fileName)
      {
          byte[] fa = File.ReadAllBytes(fileName);
  
          int startByte = 0;
  
          // look for data header
          for (var x = 0; x &lt; fa.Length; x++)
              if (fa[x] == 'd' &amp;&amp; fa[x + 1] == 'a' &amp;&amp; fa[x + 2] == 't' &amp;&amp; fa[x + 3] == 'a')
              {
                      startByte = x + 8;
                      break;
              }
  
  
          var buff = new byte[fa.Length / 2];
          var y = 0;
          var length = fa.Length;
  
          for (int s = startByte; s &lt; length; s = s + 2)
              buff[y++] = (byte)(fa[s + 1] * 0x100 + fa[s]);
  
          write(buff, "D:\\as1.wav", "D:\\us1.wav");
  
          WaveOut obj = new WaveOut();
          obj.Init(new WaveFileReader("D:\\as1.wav"));
          obj.Play();
      }
  
      private void write(byte[] buffer, string fileOut, string fileIn)
      {
          WaveFileReader reader = new WaveFileReader(fileIn);
          int numChannels = reader.WaveFormat.Channels, sampleRate = reader.WaveFormat.SampleRate;
          int BUFFER_SIZE = 1024 * 16;
  
          using (WaveFileWriter writer = new WaveFileWriter(fileOut, new WaveFormat(sampleRate, 16, numChannels)))
          {
              int bytesRead;
  
              while (true)
              {
                  bytesRead = reader.Read(buffer, 0, BUFFER_SIZE);
                  if (bytesRead != 0)
                      writer.Write(buffer, 0, bytesRead);
                  else break;
              }
  
              writer.Close();
          }
      }
  </code></pre>