Advertisement
Guest User

Untitled

a guest
Dec 14th, 2022
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. int32_t SIGMASTUDIOTYPE_FIXPOINT_CONVERT(double value) {
  2.     return (int32_t)(value * (double)((int32_t)(0x01 << 24)));
  3. }
  4.  
  5. #define PI 3.141592653589793
  6.  
  7. int maun(void)
  8. {
  9.     double dBgain = 0.0;
  10.     double dBoost = 1.0;
  11.     float frequency = 16.0;
  12.     float sampleRate = 48000.0;
  13.     float Q = 0.71;
  14.     double bandwidth = frequency / Q;
  15.  
  16.     double Ax = pow(10, dBoost / 40.0);
  17.     double omega = 2 * PI * frequency / sampleRate;
  18.     double sn = sin(omega);
  19.     double cs = cos(omega);
  20.     double alpha = sn / (2 * Q);
  21.     double a0 = 1 + (alpha / Ax);
  22.     double a1 = -( 2 * cs) / a0;
  23.     double a2 = (1 - (alpha / Ax)) / a0;
  24.     double gainlinear = pow(10, dBgain / 20.0) / a0;
  25.     double b0 = (1 + (alpha * Ax)) * gainlinear;
  26.     double b1 = -( 2 * cs) * gainlinear;
  27.     double b2 = (1 - (alpha * Ax)) * gainlinear;
  28.  
  29.     a1 *= -1;
  30.     a2 *= -1;
  31.  
  32.     int32_t B0 = SIGMASTUDIOTYPE_FIXPOINT_CONVERT(b0);
  33.     int32_t B1 = SIGMASTUDIOTYPE_FIXPOINT_CONVERT(b1);
  34.     int32_t B2 = SIGMASTUDIOTYPE_FIXPOINT_CONVERT(b2);
  35.     int32_t A1 = SIGMASTUDIOTYPE_FIXPOINT_CONVERT(a1);
  36.     int32_t A2 = SIGMASTUDIOTYPE_FIXPOINT_CONVERT(a2);
  37.  
  38.     printf("Gain=%.1f, Boost=%.1f, freq=%.1f\n", dBgain, dBoost, frequency);
  39.     printf(" B2 = %08X \n B1 = %08X \n B0 = %08X \n A2 = %08X \n A1 = %08X \n", B2, B1, B0, A2, A1);
  40.     printf(" B2 = %.14f\n B1 = %.14f\n B0 = %.14f\n A2 = %.14f\n A1 = %.14f\n", b2, b1, b0, a2, a1);
  41.     printf(" BW=%0.14f\n", bandwidth);
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement