title: How to wrap last/first element making building interpolation?
body: <p>I've this code that iterate some samples and build a simple linear interpolation between the points:</p>
  
  <pre><code>foreach sample:
     base = floor(index_pointer)
     frac = index_pointer - base
     out = in[base] * (1 - frac) + in[base + 1] * frac
     index_pointer += speed
  
     // restart
     if(index_pointer &gt;= sample_length) 
     {
        index_pointer = 0
     }
  </code></pre>
  
  <p>using "speed" equal to 1, the game is done. But if the <code>index_pointer</code> is different than 1 (i.e. got fractional part) I need to wrap last/first element keeping the translation consistent.</p>
  
  <p>How would you do this? Double indexes?</p>
  
  <p>Here's an example of values I have. Let say <code>in</code> array of 4 values:  [8, 12, 16, 20].</p>
  
  <p>It will be:</p>
  
  <pre><code>1.0*in[0] + 0.0*in[1]=8
  0.28*in[0] + 0.72*in[1]=10.88
  0.56*in[1] + 0.44*in[2]=13.76
  0.84*in[2] + 0.14*in[3]=16.64
  0.12*in[2] + 0.88*in[3]=19.52
  0.4*in[3] + 0.6*in[4]=8 // wrong; here I need to wrapper
  </code></pre>
  
  <p>the last point is wrong. [4] will be 0 because I don't have [4], but the first part need to take care of 0.4 and the weight of first sample (I think?).</p>