resample.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * The configuration constants below govern
  3. * the number of bits in the input sample and filter coefficients, the
  4. * number of bits to the right of the binary-point for fixed-point math, etc.
  5. *
  6. */
  7. /* Conversion constants */
  8. #define Nhc 8
  9. #define Na 7
  10. #define Np (Nhc+Na)
  11. #define Npc (1<<Nhc)
  12. #define Amask ((1<<Na)-1)
  13. #define Pmask ((1<<Np)-1)
  14. #define Nh 16
  15. #define Nb 16
  16. #define Nhxn 14
  17. #define Nhg (Nh-Nhxn)
  18. #define NLpScl 13
  19. /* Description of constants:
  20. *
  21. * Npc - is the number of look-up values available for the lowpass filter
  22. * between the beginning of its impulse response and the "cutoff time"
  23. * of the filter. The cutoff time is defined as the reciprocal of the
  24. * lowpass-filter cut off frequence in Hz. For example, if the
  25. * lowpass filter were a sinc function, Npc would be the index of the
  26. * impulse-response lookup-table corresponding to the first zero-
  27. * crossing of the sinc function. (The inverse first zero-crossing
  28. * time of a sinc function equals its nominal cutoff frequency in Hz.)
  29. * Npc must be a power of 2 due to the details of the current
  30. * implementation. The default value of 512 is sufficiently high that
  31. * using linear interpolation to fill in between the table entries
  32. * gives approximately 16-bit accuracy in filter coefficients.
  33. *
  34. * Nhc - is log base 2 of Npc.
  35. *
  36. * Na - is the number of bits devoted to linear interpolation of the
  37. * filter coefficients.
  38. *
  39. * Np - is Na + Nhc, the number of bits to the right of the binary point
  40. * in the integer "time" variable. To the left of the point, it indexes
  41. * the input array (X), and to the right, it is interpreted as a number
  42. * between 0 and 1 sample of the input X. Np must be less than 16 in
  43. * this implementation.
  44. *
  45. * Nh - is the number of bits in the filter coefficients. The sum of Nh and
  46. * the number of bits in the input data (typically 16) cannot exceed 32.
  47. * Thus Nh should be 16. The largest filter coefficient should nearly
  48. * fill 16 bits (32767).
  49. *
  50. * Nb - is the number of bits in the input data. The sum of Nb and Nh cannot
  51. * exceed 32.
  52. *
  53. * Nhxn - is the number of bits to right shift after multiplying each input
  54. * sample times a filter coefficient. It can be as great as Nh and as
  55. * small as 0. Nhxn = Nh-2 gives 2 guard bits in the multiply-add
  56. * accumulation. If Nhxn=0, the accumulation will soon overflow 32 bits.
  57. *
  58. * Nhg - is the number of guard bits in mpy-add accumulation (equal to Nh-Nhxn)
  59. *
  60. * NLpScl - is the number of bits allocated to the unity-gain normalization
  61. * factor. The output of the lowpass filter is multiplied by LpScl and
  62. * then right-shifted NLpScl bits. To avoid overflow, we must have
  63. * Nb+Nhg+NLpScl < 32.
  64. */