Skip to content

Instantly share code, notes, and snippets.

@encryptio
Created July 27, 2010 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save encryptio/491728 to your computer and use it in GitHub Desktop.
Save encryptio/491728 to your computer and use it in GitHub Desktop.
int pti = 0;
for (int i = 0; i < len; i++) {
float f = (float)i/len*sr;
if ( f < curve->pts[0].freq ) {
// before the first point
in[i].r = curve->pts[0].power;
} else if ( curve->pts[curve->ct-1].freq < f ) {
// after last point
in[i].r = curve->pts[curve->ct-1].freq;
} else {
// in-between points
while ( !(curve->pts[pti].freq <= f && f < curve->pts[pti+1].freq) ) pti++;
// pts[pti ] is the point immediately to the left of f
// likewise, pts[pti+1] is the point immediately to the right of f
wantpoint *low = &(curve->pts[pti ]);
wantpoint *hi = &(curve->pts[pti+1]);
float p0 = (f-low->freq)/(hi->freq-low->freq);
in[i].r = p0*hi->power + (1-p0)*low->power;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment