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

  1. ;;  Author - Rick Vander Kam
  2. ;;  Copyright (c) 1992 - All rights reserved
  3. ;;  Modification history
  4. ;;  --------------------
  5. ;;  2/22/92 - rvk - initial file created from /usr/lib/dsp/ugsrc/onepole.asm
  6. ;;               added threshold argument to get variable clipping behavior
  7. ;;
  8. ;;------------------------------ DOCUMENTATION ---------------------------
  9. ;;  NAME
  10. ;;      cubicnl (UG macro) - cubic polynomial filter section
  11. ;;
  12. ;;  SYNOPSIS
  13. ;;      cubicnl pf,ic,sout,aout0,sinp,ainp0,aa10,aa20,aa30,thr0
  14. ;;
  15. ;;  MACRO ARGUMENTS
  16. ;;      pf        = global label prefix (any text unique to invoking macro)
  17. ;;      ic        = instance count (s.t. pf\_cubicnl_\ic\_ is globally unique)
  18. ;;      sout      = output vector memory space ('x' or 'y')
  19. ;;      aout0     = initial output vector memory address
  20. ;;      sinp      = input vector memory space ('x' or 'y')
  21. ;;      ainp0     = initial input vector memory address
  22. ;;      aa10      = initial coefficient of (input^1)
  23. ;;    aa20     = initial coeff of (input^2)
  24. ;;    aa30    = initial coeff of (input^3)
  25. ;;    thr0        = threshold value
  26. ;;
  27. ;;  DSP MEMORY ARGUMENTS
  28. ;;      Access         Description              Initialization
  29. ;;      ------         -----------              --------------
  30. ;;      x:(R_X)+       Current output address   aout0
  31. ;;      y:(R_Y)+       Current input address    ainp0
  32. ;;      x:(R_X)+       aa1 coefficient          aa10
  33. ;;      y:(R_Y)+       aa2 coefficient          aa20
  34. ;;      y:(R_Y)+       aa3 coefficient          aa30
  35. ;;      x:(R_X)+       thr value                  thr0
  36. ;;
  37. ;;  DESCRIPTION
  38. ;;      The cubicnl unit-generator implements a nonlinear,
  39. ;;      cubic polynomial filter section in direct form.  It has
  40. ;;    a variable threshold level, and any sample whose value
  41. ;;    is above the threshold will be hard-limited.  In pseudo-C notation:
  42. ;;
  43. ;;      ainp = y:(R_Y)+;
  44. ;;      aout = x:(R_X)+;
  45. ;;      aa1 = x:(R_X)+;
  46. ;;      aa2 = y:(R_Y)+;
  47. ;;      aa3 = y:(R_Y)+;
  48. ;;      thr = x:(R_X)+;
  49. ;;
  50. ;;      for (n=0;n<I_NTICK;n++) {
  51. ;;         if(sinp:ainp[n]<thr) {
  52. ;;        sout:aout[n]    = aa1*sinp:ainp[n] 
  53. ;;        +aa2*(ainp[n]*ainp[n])
  54. ;;        +aa3*(ainp[n]*ainp[n]*ainp[n]);
  55. ;;       }
  56. ;;       else sout:aout[n] = thr;
  57. ;;      }
  58. ;;        
  59. ;;  DSPWRAP ARGUMENT INFO
  60. ;;      cubicnl (prefix)pf,(instance)ic,
  61. ;;         (dspace)sout,(output)aout,
  62. ;;         (dspace)sinp,(input)ainp,aa1,aa2,aa3,thr
  63. ;;
  64. ;;  MAXIMUM EXECUTION TIME
  65. ;;      ???
  66. ;;
  67. ;;  MINIMUM EXECUTION TIME
  68. ;;      ???
  69. ;;
  70. ;;  SOURCE
  71. ;;      /user/rvk/ee265/test/cubicnlUG
  72. ;;
  73. ;;  SEE ALSO
  74. ;;      /usr/lib/dsp/ugsrc/onezero.asm - one-zero filter section
  75. ;;      /usr/lib/dsp/ugsrc/twopole.asm - two-pole filter section
  76. ;;      /usr/lib/dsp/ugsrc/biquad.asm  - two-pole, two-zero filter section
  77. ;;      /usr/lib/dsp/ugsrc/onezero.asm - one-zero filter section
  78. ;;  
  79. ;;  ALU REGISTER USE
  80. ;;    X0 = input sample raised to powers
  81. ;;    Y0 = aa2
  82. ;;    X1 = aa1 and temp. input holder
  83. ;;    Y1 = aa3 and temp. coeff holder
  84. ;;    A = output value accumulator, threshold comparison
  85. ;;    B = working multiplications accumulator
  86.  
  87. cubicnl macro pf,ic,sout,aout0,sinp,ainp0,aa10,aa20,aa30,thr0
  88.              new_xarg pf\_cubicnl_\ic\_,aout,aout0   ; output address arg
  89.              new_yarg pf\_cubicnl_\ic\_,ainp,ainp0   ; input address arg
  90.              new_xarg pf\_cubicnl_\ic\_,aa1,aa10     ; coeff of x
  91.              new_yarg pf\_cubicnl_\ic\_,aa2,aa20     ; coeff of x^2
  92.              new_yarg pf\_cubicnl_\ic\_,aa3,aa30     ; coeff of x^3
  93.              new_xarg pf\_cubicnl_\ic\_,thr,thr0       ; coeff of x
  94.  
  95.              move x:(R_X)+,R_O                  ; output address to R_O
  96.              move x:(R_Y)+,R_I1                 ; input address to R_I1
  97.     move x:(R_X)+,X1  y:(R_Y)+,Y0    ;aa1->X1, aa2->Y0
  98.  
  99.      do #I_NTICK,pf\_cubicnl_\ic\_tickloop
  100.           move sinp:(R_I1)+,X0        ;input->X0, B cleared for altout
  101.           mpy X0,X1,A    X1,Y1    ;aa1*in->A, aa1 saved
  102.           mpyr X0,X0,B    X0,X1    ;in^2->B, in->X1
  103.           move B,X0            ;in^2->X0
  104.           mpyr X0,X1,B            ;in^3->B
  105.           mac Y0,X0,A    Y1,X1    ;A+=aa2*in^2, restore aa1
  106.           move B,X0    y:(R_Y),Y1    ;in^3->X0, aa3->Y1
  107.           macr Y1,X0,A    x:(R_X),B        ;A+=aa3*in^3, threshold value -> B
  108.           cmpm A,B            ;check output against threshold
  109.           jle    pf\_cubicnl_\ic\_altout
  110.           jmp pf\_cubicnl_\ic\_out
  111. pf\_cubicnl_\ic\_altout
  112.           tfr B,A   A,B                ;get threshold value in A
  113.           jclr  #23,B1,pf\_cubicnl_\ic\_out    ;input is (+), so write A as output
  114.           neg A                    ;input is (-), so negate A first
  115. pf\_cubicnl_\ic\_out
  116.           move A,sout:(R_O)+        ;ship A as output
  117. pf\_cubicnl_\ic\_tickloop   
  118.         move x:(R_X)+,X0  y:(R_Y)+,Y1    ;(dummy) increment R_X and R_Y
  119.      endm
  120.  
  121.