Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int32_t SIGMASTUDIOTYPE_FIXPOINT_CONVERT(double value) {
- return (int32_t)(value * (double)((int32_t)(0x01 << 24)));
- }
- #define PI 3.141592653589793
- int maun(void)
- {
- double dBgain = 0.0;
- double dBoost = 1.0;
- float frequency = 16.0;
- float sampleRate = 48000.0;
- float Q = 0.71;
- double bandwidth = frequency / Q;
- double Ax = pow(10, dBoost / 40.0);
- double omega = 2 * PI * frequency / sampleRate;
- double sn = sin(omega);
- double cs = cos(omega);
- double alpha = sn / (2 * Q);
- double a0 = 1 + (alpha / Ax);
- double a1 = -( 2 * cs) / a0;
- double a2 = (1 - (alpha / Ax)) / a0;
- double gainlinear = pow(10, dBgain / 20.0) / a0;
- double b0 = (1 + (alpha * Ax)) * gainlinear;
- double b1 = -( 2 * cs) * gainlinear;
- double b2 = (1 - (alpha * Ax)) * gainlinear;
- a1 *= -1;
- a2 *= -1;
- int32_t B0 = SIGMASTUDIOTYPE_FIXPOINT_CONVERT(b0);
- int32_t B1 = SIGMASTUDIOTYPE_FIXPOINT_CONVERT(b1);
- int32_t B2 = SIGMASTUDIOTYPE_FIXPOINT_CONVERT(b2);
- int32_t A1 = SIGMASTUDIOTYPE_FIXPOINT_CONVERT(a1);
- int32_t A2 = SIGMASTUDIOTYPE_FIXPOINT_CONVERT(a2);
- printf("Gain=%.1f, Boost=%.1f, freq=%.1f\n", dBgain, dBoost, frequency);
- printf(" B2 = %08X \n B1 = %08X \n B0 = %08X \n A2 = %08X \n A1 = %08X \n", B2, B1, B0, A2, A1);
- printf(" B2 = %.14f\n B1 = %.14f\n B0 = %.14f\n A2 = %.14f\n A1 = %.14f\n", b2, b1, b0, a2, a1);
- printf(" BW=%0.14f\n", bandwidth);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement