title: Play buffer by PeriodicWave in Web Audio API, can I set Gain as loud as buffer?
body: <p>I tried to play Oscillator (buffer -> FFT -> PeriodicWave -> Oscillator).</p>
  
  <pre><code>// PeriodicWave (-&gt; Oscillator)
  var wave = fft(buffer), periodicwave = ctx.createPeriodicWave(wave[0], wave[1]);
  function fft(input) {
      var n = input.length, theta = 2 * Math.PI / n,
          ar = new Float32Array(n), ai = new Float32Array(n),
          m, mh, i, j, k, irev,
          wr, wi, xr, xi,
          cos = Math.cos, sin = Math.sin;
  
      for(i=0; i&lt;n; ++i) {
          ar[i] = input[i];
      }
  
      // scrambler
      i=0;
      for(j=1; j&lt;n-1; ++j) {
          for(k = n&gt;&gt;1; k&gt;(i ^= k); k&gt;&gt;=1);
          if(j&lt;i) {
              xr = ar[j];
              xi = ai[j];
              ar[j] = ar[i];
              ai[j] = ai[i];
              ar[i] = xr;
              ai[i] = xi;
          }
      }
      for(mh=1; (m = mh &lt;&lt; 1) &lt;= n; mh=m) {
          irev = 0;
          for(i=0; i&lt;n; i+=m) {
              wr = cos(theta * irev);
              wi = sin(theta * irev);
              for(k=n&gt;&gt;2; k &gt; (irev ^= k); k&gt;&gt;=1);
              for(j=i; j&lt;mh+i; ++j) {
                  k = j + mh;
                  xr = ar[j] - ar[k];
                  xi = ai[j] - ai[k];
                  ar[j] += ar[k];
                  ai[j] += ai[k];
                  ar[k] = wr * xr - wi * xi;
                  ai[k] = wr * xi + wi * xr;
              }
          }
      }
  
      return [ar, ai];
  }
  </code></pre>
  
  <p>This code is good however this Oscillator's gain is standardized automatically. I want to set gain as loud as BufferSource (buffer -> AudioBuffer -> BufferSource), but it doesn't work I have tried using AudioGainNode, see <a href="http://jsdo.it/Moriken/sfDX" rel="nofollow">this test code</a>.</p>