title: AccessViolationException with sound buffer conversion
body: <p>I'm using <strong>Naudio AsioOut</strong> object to pass data from input buffer to my <code>delayProc()</code> function and then to output buffer.</p>
  
  <p>The <code>delayProc()</code> needs <code>float[]</code> buffer type, and this is possible using <code>e.GetAsInterleavedSamples()</code>. The problem is I need to re-convert it to a multidimensional <code>IntPtr</code>, to do this I'm using <code>AsioSampleConvertor</code> class.</p>
  
  <p>When I try to apply the effect it shows me an error: <strong>AccessViolationException</strong> on the code of <code>AsioSampleConvertor</code> class. </p>
  
  <p>So I think the problem is due to the conversion from <code>float[]</code> to <code>IntPtr[]</code>..</p>
  
  <p>I give you some code:</p>
  
  <p><strong>OnAudioAvailable()</strong></p>
  
  <pre><code>floatIn = new float[e.SamplesPerBuffer * e.InputBuffers.Length];//*2
  
  e.GetAsInterleavedSamples(floatIn);
  
  floatOut = delayProc(floatIn, e.SamplesPerBuffer * e.InputBuffers.Length, 1.5f);
  //conversione da float[] a IntPtr[L][R]
  Outp = Marshal.AllocHGlobal(sizeof(float)*floatOut.Length);
  
  Marshal.Copy(floatOut, 0, Outp, floatOut.Length);
  NAudio.Wave.Asio.ASIOSampleConvertor.ConvertorFloatToInt2Channels(Outp, e.OutputBuffers, e.InputBuffers.Length, floatOut.Length);
  </code></pre>
  
  <p><strong>delayProc()</strong></p>
  
  <pre><code>private float[] delayProc(float[] sourceBuffer, int sampleCount, float delay)
  {
      if (OldBuf == null)
      {
          OldBuf = new float[sampleCount];
      }
      float[] BufDly = new float[(int)(sampleCount * delay)];
      int delayLength = (int)(BufDly.Length - (BufDly.Length / delay));
      for (int j = sampleCount - delayLength; j &lt; sampleCount; j++)
          for (int i = 0; i &lt; delayLength; i++)
              BufDly[i] = OldBuf[j];
      for (int j = 0; j &lt; sampleCount; j++)
          for (int i = delayLength; i &lt; BufDly.Length; i++)
              BufDly[i] = sourceBuffer[j];
      for (int i = 0; i &lt; sampleCount; i++)
          OldBuf[i] = sourceBuffer[i];
      return BufDly;
  }
  </code></pre>
  
  <p><strong>AsioSampleConvertor</strong></p>
  
  <pre><code>public static void ConvertorFloatToInt2Channels(IntPtr inputInterleavedBuffer, IntPtr[] asioOutputBuffers, int nbChannels, int nbSamples)
  {
      unsafe
      {
          float* inputSamples = (float*)inputInterleavedBuffer;
          int* leftSamples = (int*)asioOutputBuffers[0];
          int* rightSamples = (int*)asioOutputBuffers[1];
  
          for (int i = 0; i &lt; nbSamples; i++)
          {
              *leftSamples++ = clampToInt(inputSamples[0]);
              *rightSamples++ = clampToInt(inputSamples[1]);
              inputSamples += 2;
          }
      }
  }
  </code></pre>
  
  <p><strong>ClampToInt()</strong></p>
  
  <pre><code>private static int clampToInt(double sampleValue)
  {
      sampleValue = (sampleValue &lt; -1.0) ? -1.0 : (sampleValue &gt; 1.0) ? 1.0 : sampleValue;
      return (int)(sampleValue * 2147483647.0);
  }
  </code></pre>
  
  <p>If you need some other code, just ask me.</p>