eq10dsp.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*****************************************
  2. EQ10 library version 1.0
  3. Copyright (C)2002 4Front Technologies
  4. Written by George Yohng
  5. http://www.opensound.com
  6. Proprietary software.
  7. *****************************************/
  8. #ifndef EQ10DSP_H_INCLUDED
  9. #define EQ10DSP_H_INCLUDED
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /* used for volume detectors. for instance, if you want to plot
  14. frequency response, you can use "detect" variable of needed
  15. subband to query level of that frequency band.
  16. release time - is the time in seconds in which detector falls back
  17. to zero, if no peaks detected */
  18. // #define EQ10_DETECTOR_CODE /* uncomment this to */
  19. // #define EQ10_DETECTOR_RELEASE 1.0f /* enable band detector */
  20. /* Dynamic limiter, which prevents EQ from distortion. In no case you
  21. can overflow EQ and cause it to clip */
  22. #define EQ10_TRIM_CODE 0.930 /* trim at -0.6dB */
  23. #define EQ10_TRIM_RELEASE 0.700 /* trim release, in seconds */
  24. #define EQ10_NOFBANDS 10 /* want more bands? not a problem */
  25. #define EQ10_Q 1.41 /* global `Q' factor */
  26. /* if you want separate Q per each band, comment global Q and uncomment
  27. the following array */
  28. //#define EQ10_DQ {1.4,1.4,1.4,1.4,1.4,1.4,1.4,1.4,1.4,1.4}
  29. /* frequency table compatible to Q10 standard */
  30. typedef
  31. struct eq10band_s
  32. {
  33. double gain; /* gain of current band. Do not use this value,
  34. use eq10_setgain instead */
  35. #ifdef EQ10_DETECTOR_CODE
  36. double detect; /* band detector value, do not use.
  37. use eq10_detect to read detector value in dB */
  38. double detectdecay; /* internal - do not use */
  39. #endif
  40. double ua0,ub1,ub2; /* internal - do not use */
  41. double da0,db1,db2; /* internal - do not use */
  42. double x1,x2,y1,y2; /* internal - do not use */
  43. } eq10band_t;
  44. typedef
  45. struct eq10_s
  46. {
  47. double rate; /* sample rate; do not modify */
  48. /* use eq10_setup to change */
  49. eq10band_t band[EQ10_NOFBANDS]; /* bands of equalizer */
  50. double detect; /* global detector value. do not use */
  51. double detectdecay; /* internal - do not use */
  52. } eq10_t;
  53. double eq10_db2gain(double gain_dB); /* converts decibels to internal gain value*/
  54. double eq10_gain2db(double gain); /* converts internal gain value to decibels*/
  55. /* prepare eq array for processing,
  56. eq - pointer to array,
  57. eqs - number of elements in array (number of audio channels)
  58. rate - sample rate
  59. WARNING! this function resets all data in eq and sets all gains to 0dB
  60. */
  61. void eq10_setup(eq10_t *eq, int eqs, double rate);
  62. /* set band gain */
  63. /*
  64. eq - pointer to array,
  65. eqs - number of elements in array (number of audio channels)
  66. bandnr - # of band (0...EQ_NOFBANDS-1)
  67. */
  68. void eq10_setgain(eq10_t *eq,int eqs,int bandnr,double gain_dB);
  69. /* get current band gain */
  70. /* eq - pointer to element, possible to read gain on each channel
  71. separately */
  72. double eq10_getgain(eq10_t *eq,int bandnr);
  73. /* get detector value */
  74. /* eq - pointer to element, possible to read detector value on
  75. each channel separately */
  76. double eq10_detect(eq10_t *eq,int bandnr);
  77. /* process function
  78. eq - pointer to eq structure, corresponding to wanted channel
  79. buf - input buffer (interleaved multichannel)
  80. outbuf - output buffer
  81. sz - number of samples in input buffer
  82. idx - index of processed channel (0...N-1)
  83. step - total number of channels in interleaved stream (N)
  84. */
  85. void eq10_processf(eq10_t *eq,float *buf,float *outbuf,int sz,int idx,int step);
  86. /*
  87. Example:
  88. #define NCHAN 6
  89. ...
  90. eq10_t eq[NCHAN]; // we process 5.1 data, thus 6 channels
  91. int t;
  92. eq10_t *peq;
  93. ...
  94. eq10_setup(eq,NCHAN,44100); // initialize
  95. ...
  96. eq10_setgain(eq,NCHAN, 5, -10.0f ); // set -10dB for gain6 (nr's from zero)
  97. ...
  98. while (bla bla bla) // inner loop
  99. {
  100. for(t=0, peq=eq; t<NCHAN; t++, peq++)
  101. {
  102. eq10_processf(peq, input_buf, output_buf, cSamples, t, NCHAN);
  103. }
  104. }
  105. ...
  106. */
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif //EQ10DSP_H_INCLUDED