Advertisement
henke37

linear interpolation

May 1st, 2015
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. counter_t increment=42;
  2. counter_t threshold=9001;
  3. counter_t counter=0;
  4. sample_t curSample=0,nextSample=0;
  5.  
  6. sample_t linearInterpolateNextSample() {
  7.     counter+=increment;
  8.     while(counter>threshold) {
  9.         counter-=threshold;
  10.         curSample=nextSample;
  11.         nextSample=readNextSample();
  12.     }
  13.  
  14.     //can be optimized using fixed point math
  15.     //and fast division by shifting
  16.     float t=counter/threshold;
  17.  
  18.     //lerp between the two samples
  19.     return curSample*(1-t)+nextSample*(t);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement