-struct stereo_sample {
- short left, right;
-};
-
-inline short clip(int x)
-{
- if (x < -32768) {
- return x;
- } else if (x > 32767) {
- return 32767;
- } else {
- return short(x);
- }
-}
-
-static float a1, a2, b0, b1, b2;
-static float d0, d1;
-
-static void filter_init(float cutoff_radians)
-{
- float resonance = 1.0f / sqrt(2.0f);
- float sn = sin(cutoff_radians), cs = cos(cutoff_radians);
- float alpha = float(sn / (2 * resonance));
-
- // coefficients for lowpass filter
- float a0 = 1 + alpha;
- b0 = (1 - cs) * 0.5f;
- b1 = 1 - cs;
- b2 = b0;
- a1 = -2 * cs;
- a2 = 1 - alpha;
-
- b0 /= a0;
- b1 /= a0;
- b2 /= a0;
- a1 /= a0;
- a2 /= a0;
-
- // reset filter delays
- d0 = d1 = 0.0f;
-}
-
-static float filter_update(float in)
-{
- float out = b0*in + d0;
- d0 = b1 * in - a1 * out + d1;
- d1 = b2 * in - a2 * out;
- return out;
-}
-
-int main(int argc, char **argv)