home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Sound / SoX / Source / resampl.h < prev    next >
Text File  |  1999-07-18  |  3KB  |  76 lines

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