Hello guys, I'm currently trying to implement a Biquad filter into my code but this involves creating a dynamic array that is constantly updated so that I can recall the current digital sample and the previous 2 digital samples at any point for many many samples.
I figured malloc() and free() were the only way to go with this and if anyone has a better suggestion then I'm all ears as I'm still very new to this whole C coding thing.
Anyway, the problem I encounter arises when I try to point to the previous samples stored in the dynamic array and get a "Floating Point Error: Domain" error.
Here is a overview of what ive got:
Code:
main()
{
int current_sample = 1;
float *p1;
float *p2;
p1 = malloc(3);
p2 = malloc(3);
wave[p1] = sine_osc * amplitude;
filtered_wave[p2] = a0 * wave[p1] + a1 * wave[p1-1] + a2 * wave[p1-2] - b1 * filtered_wave[p2-1] - b2 * filtered_wave[p2-2]
if (current_sample > 3)
{
current_sample = 1;
free(p1);
free(p2);
}
}
Unfortunately p1-1 doesnt seem to address the previous sample stored in the array like I hoped and using p1++ just causes errors.
What am I doing wrong?
Thanks
Rhys
PS Is there a trick to using tab when writing a message, I cant get it to work on this forum?!