home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Programming / Source / Guitar / fir3.asm < prev    next >
Encoding:
Assembly Source File  |  1992-07-28  |  5.0 KB  |  125 lines

  1. ;;  Author - Rick Vander Kam
  2. ;;  Copyright (c) 1992 - All rights reserved
  3. ;;  Modification history
  4. ;;  --------------------
  5. ;;  2/29/92/rvk - initial file created from /usr/lib/dsp/ugsrc/onezero.asm
  6. ;;
  7. ;;------------------------------ DOCUMENTATION ---------------------------
  8. ;;  NAME
  9. ;;      fir3 (UG macro) - three-point FIR filter section
  10. ;;
  11. ;;  SYNOPSIS
  12. ;;      fir3 pf,ic,sout,aout0,sinp,ainp0,s10,s20,bb00,bb10,bb20
  13. ;;
  14. ;;  MACRO ARGUMENTS
  15. ;;      pf        = global label prefix (any text unique to invoking macro)
  16. ;;      ic        = instance count (s.t. pf\_fir3_\ic\_ is globally unique)
  17. ;;      sout      = output vector memory space ('x' or 'y')
  18. ;;      aout0     = initial output vector memory address
  19. ;;      sinp      = input vector memory space ('x' or 'y')
  20. ;;      ainp0     = initial input vector memory address
  21. ;;      bb00      = initial coefficient of undelayed input
  22. ;;      bb10      = initial coefficient of once delayed input
  23. ;;      bb20      = initial coefficient of twice delayed input
  24. ;;      s10        = initial once delayed state variable
  25. ;;      s20        = initial twice delayed state variable
  26. ;;
  27. ;;  DSP MEMORY ARGUMENTS
  28. ;;      Access         Description              Initialization
  29. ;;      ------         -----------              --------------
  30. ;;      x:(R_X)+       Current output address   aout0
  31. ;;      x:(R_X)+       Current input address    ainp0
  32. ;;      x:(R_X)+       bb2 coefficient         bb20
  33. ;;      x:(R_X)+       s1 state variable         s10
  34. ;;      y:(R_Y)+       bb0 coefficient          bb00
  35. ;;      y:(R_Y)+       bb1 coefficient          bb10
  36. ;;      y:(R_Y)+       s2 state variable          s20
  37. ;;
  38. ;;  DESCRIPTION
  39. ;;      The fir3 unit-generator implements a three-point
  40. ;;      FIR filter section in direct form.  For best performance,
  41. ;;      output memory space should be y.
  42. ;;
  43. ;;      In pseudo-C notation:
  44. ;;
  45. ;;      ainp = x:(R_X)+;
  46. ;;      aout = x:(R_X)+;
  47. ;;      bb2 = x:(R_X)+;
  48. ;;      s1 = x:(R_X)+;
  49. ;;      bb0 = y:(R_Y)+;
  50. ;;      bb1 = y:(R_Y)+;
  51. ;;      s2 = y:(R_Y)+;
  52. ;;
  53. ;;      for (n=0;n<I_NTICK;n++) {
  54. ;;           in = sinp:ainp[n];
  55. ;;           sout:aout[n] = bb0*in + bb1*s1 + bb2*s2;
  56. ;;           s1 = in;
  57. ;;           s2 = s1;
  58. ;;      }
  59. ;;        
  60. ;;  DSPWRAP ARGUMENT INFO
  61. ;;      fir3 (prefix)pf,(instance)ic,(dspace)sout,(output)aout,
  62. ;;         (dspace)sinp,(input)ainp,s1,s2,bb0,bb1,bb2
  63. ;;
  64. ;;  MAXIMUM EXECUTION TIME
  65. ;;      ???
  66. ;;
  67. ;;  MINIMUM EXECUTION TIME
  68. ;;       ???
  69. ;;
  70. ;;  SOURCE
  71. ;;      /user/rvk/ee265/test/fir3UG/fir3.asm
  72. ;;
  73. ;;  SEE ALSO
  74. ;;      /usr/lib/dsp/ugsrc/biquad.asm  - two-pole, two-zero filter section
  75. ;;      /usr/lib/dsp/ugsrc/onepole.asm - one-pole filter section
  76. ;;      /usr/lib/dsp/ugsrc/twopole.asm - two-pole filter section
  77. ;;
  78. ;;  ALU REGISTER USE
  79. ;;      X0 = x(n) and x(n-1) , input and s1 = once delayed input
  80. ;;      X1 = x(n-2) = s2 = twice delayed input
  81. ;;      Y0 = bb0,bb2 = undelayed and twice-delayed signal coefficients
  82. ;;      Y1 = bb1 = once-delayed signal coefficient
  83. ;;       A = multiply-add accumulator
  84. ;;       B = holder for bb0
  85. ;;
  86. fir3   macro pf,ic,sout,aout0,sinp,ainp0,s10,s20,bb00,bb10,bb20
  87.                new_xarg pf\_fir3_\ic\_,aout,aout0   ; output address arg
  88.                new_xarg pf\_fir3_\ic\_,ainp,ainp0   ; input address arg
  89.                new_xarg pf\_fir3_\ic\_,bb2,bb20    ; twice delayed input coeff
  90.                new_xarg pf\_fir3_\ic\_,s2,s20    ; once delayed input sample
  91.                new_yarg pf\_fir3_\ic\_,bb0,bb00     ; undelayed input coeff
  92.                new_yarg pf\_fir3_\ic\_,bb1,bb10     ; once-delayed input coeff
  93.                new_yarg pf\_fir3_\ic\_,s1,s10     ; twice-delayed input
  94.  
  95.                move x:(R_X)+,R_O                  ; output address to R_O
  96.                move x:(R_X)+,R_I1                 ; input address to R_I1
  97.  
  98.                move x:(R_X)+,Y1        ;bb2 to Y1
  99.           move x:(R_X),X1 y:(R_Y)+,B        ; s2 to X1, bb0 to B
  100.                move y:(R_Y)+,Y0                   ; bb1 to Y0
  101.                move y:(R_Y),X0                ; s1 to X0
  102.                mpy  X1,Y1,A   X0,X1     ; s2*bb2, update s2=x(n-1)
  103.                macr X0,Y0,A   sinp:(R_I1)+,X0      ; A += s1*bb1,   update s1=x(n)
  104.           tfr Y0,B  B,Y0            ;bb0 to Y0, bb1 to B (swap)
  105.           macr X0,Y0,A            ;A += bb0*x(n) (= first output)
  106.                do #I_NTICK-1,pf\_fir3_\ic\_tickloop
  107.                     tfr Y0,B B,Y0                          ;bb0 to B, bb1 to Y0
  108.                     move  A,sout:(R_O)+                      ;ship output
  109.                     mpy  X1,Y1,A   X0,X1                      ;A=bb2*x(n-2), s2=x(n-1)
  110.                     macr X0,Y0,A   sinp:(R_I1)+,X0    ;A+=bb1*x(n-1),  s1=x(n)
  111.             tfr Y0,B  B,Y0                      ;bb0 to Y0, bb1 to B (swap)
  112.             macr X0,Y0,A                      ;A += bb0*x(n)
  113. pf\_fir3_\ic\_tickloop    
  114.                if "sout"!='x'
  115.                     move X1,x:(R_X)+    A,sout:(R_O)+
  116.             move X0,y:(R_Y)+
  117.                else
  118.                     move A,sout:(R_O)+       ; ship last output
  119.                     move X1,x:(R_X)+         ; save s2 in mem arg
  120.             move X0,y:(R_Y)+       ; save s1 in mem arg
  121.                endif
  122.      endm
  123.  
  124.  
  125.