Skip to content

Instantly share code, notes, and snippets.

@selenologist
Created April 3, 2016 11:55
Show Gist options
  • Save selenologist/ca2bab6352897f35f1ecc2ff6b2cc5ae to your computer and use it in GitHub Desktop.
Save selenologist/ca2bab6352897f35f1ecc2ff6b2cc5ae to your computer and use it in GitHub Desktop.
/* shoves new samples onto a kernel-sized history buffer */
float convolve(const float input,
const float* kernel, const size_t kernel_length,
float* history){
int index = kernel_length -1;
/* XXX: replace with better data structure without data copying
this is really inefficient! It does work though.
*/
for(; index > 0; index--){
history[index] = history[index - 1];
}
history[0] = input;
float output = 0.0;
for(index = 0; index < kernel_length; index++){
output += history[index] * kernel[index];
}
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment