title: How do I attenuate a WAV file by a given decibel value?
body: <p>If I wanted to reduce a WAV file's amplitude by 25%, I would write something like this:</p>
  
  <pre><code>for (int i = 0; i &lt; data.Length; i++)
  {
      data[i] *= 0.75;
  }
  </code></pre>
  
  <p>A lot of the articles I read on audio techniques, however, discuss amplitude in terms of decibels.  I understand the logarithmic nature of decibel units in principle, but not so much in terms of actual code.  </p>
  
  <p>My question is:  if I wanted to attenuate the volume of a WAV file by, say, 20 decibels, how would I do this in code like my above example?</p>
  
  <p><strong>Update</strong>:  formula (based on Nils Pipenbrinck's answer) for attenuating by a given number of decibels (entered as a positive number e.g. 10, 20 etc.):</p>
  
  <pre><code>public void AttenuateAudio(float[] data, int decibels)
  {
      float gain = (float)Math.Pow(10, (double)-decibels / 20.0);
      for (int i = 0; i &lt; data.Length; i++)
      {
          data[i] *= gain;
      }
  }
  </code></pre>
  
  <p>So, if I want to attenuate by <strong>20</strong> decibels, the gain factor is <strong>.1</strong>.</p>