home *** CD-ROM | disk | FTP | other *** search
/ Peanuts NeXT Software Archives / Peanuts-2.iso / Developer / hardware / dsp / drbub / vfreq.asm < prev   
Encoding:
Assembly Source File  |  1991-09-07  |  3.8 KB  |  181 lines

  1. ;**********************************************************
  2. ;
  3. ; Frequency Scaler
  4. ; This program implements a frequency scaler.  It will attempt
  5. ; to take the input and provide and output which has its
  6. ; frequency scaled by the factor alpha.  It does this by
  7. ; reading the input in sections and outputting the samples
  8. ; at a rate of alpha times the input rate.  If alpha is < 1,
  9. ; the output frequencies are slowed, and some of the signal
  10. ; is lost.  If alpha > 1, the output frequencies are sped up,
  11. ; and some of the signal is repeated.
  12. ;
  13. ; Daniel Howell
  14. ; 3 Jun 1988
  15. ; ECE 148
  16. ;
  17. ; Modified to run in stereo by Todd Day
  18. ;
  19. ;**********************************************************
  20.     page    79,66,1,1
  21.  
  22.     include    'defs.inc'
  23.     include    'ioequ.inc'
  24.     include    'intequ.inc'
  25.  
  26. buffer    equ    $0000            ; beginning of buffer
  27. L    equ    2048            ; buffer length (multiple of 2!)
  28. savea0    equ    buffer+L        ; place to save a register
  29. savea1    equ    savea0+1
  30. savea2    equ    savea1+1
  31. pointer    equ    savea2+1        ; pointer to buffer
  32.  
  33. ; ****************************************
  34. ; SSI receive data vector
  35. ; do long interrupt (save stack and ccr)
  36.     org    p:i_ssird
  37.     jsr    dofreq
  38.  
  39. ; ****************************************
  40. ; begin program
  41. ;
  42.     org    p:pgmram
  43.  
  44. ; setup SSI and others
  45.     include    'setup.asm'
  46.  
  47.     move    #buffer,r6        ; r6 points to input of buffer
  48.     move    #L-1,m6            ; mod L addressing
  49.  
  50.     move    #>1.0/2048,x0        ; alpha (scaling factor)
  51.  
  52.     move    #buffer,r4        ; r4 points to output of buffer
  53.     move    #L-1,m4            ; mod L addressing
  54.     clr      a    #0,n4        ; initialize pointer
  55.     move    a,l:pointer
  56.  
  57.     move    #L-1,y0            ; mask for mod L update of pointer
  58.  
  59. ; start interrupts
  60.     movep    #$b200,x:m_crb
  61.     andi    #$00,mr
  62.  
  63. ; ****************************************
  64. ; monitor the keyboard for changes in alpha
  65. ; uses b
  66.     include    'monitor.asm'
  67.  
  68. ; compare key hit to 'i', get incr, get ready for 'd'
  69.     move    #'i',x1
  70.     move    #>(1.0/16)/2048,y1
  71.     cmp    x1,b        #'d',x1
  72.     jne    d
  73.  
  74. ; increment alpha by 1/16
  75.     move    x0,b
  76.     add    y1,b
  77.     move    b,x0
  78.  
  79. ; print b in decimal
  80. pdec    do    #12,pdec1    ;get ones place
  81.     asl    b
  82. pdec1    jsr    pnum        ;print number in b2 as ASCII
  83.     move    #'.',a        ;print decimal place
  84.     jsr    pwait
  85.     tfr    b,a        ;get tenths place
  86.     do    #4,pdec2    ; * 5
  87.     add    a,b
  88. pdec2    asl    b        ; * 2
  89.     jsr    pnum
  90.     tfr    b,a        ;get hundredths place
  91.     do    #4,pdec3    ; * 5
  92.     add    a,b
  93. pdec3    asl    b        ; * 2
  94.     jsr    pnum
  95.     tfr    b,a        ;get thousandths place
  96.     do    #4,pdec4    ; * 5
  97.     add    a,b
  98. pdec4    asl    b        ; * 2
  99.     jsr    pnum
  100. crlf    move    #13,a        ;CR
  101.     jsr    pwait
  102.     move    #10,a        ;LF
  103.     jsr    pwait
  104.     jmp    getch
  105.  
  106. ; print number in b2 to serial port as ASCII
  107. pnum    move    b2,a
  108.     move    #>'0',x1
  109.     add    x1,a    #0,b2
  110.     do    #16,pwait
  111.     lsl    a
  112. pwait    jclr    #m_tdre,x:m_ssr,pwait
  113.     movep    a,x:m_srxh
  114.     rts
  115.  
  116. ; compare key hit to 'd'
  117. d    cmp    x1,b
  118.     jne    crlf
  119.  
  120. ; decrement alpha by 1/16
  121.     move    x0,b
  122.     sub    y1,b
  123.     move    b,x0
  124.     jmp    pdec
  125.  
  126. ; ****************************************
  127. ; do frequency shifting
  128.  
  129. ; which channel input?
  130. ; when SCO is low, we get left channel data
  131. dofreq    jclr    #m_if0,x:m_sr,left
  132.  
  133. ; ****************************************
  134. ; right channel
  135. ;
  136. right    move    a2,x:savea2        ; save a register
  137.     move    a1,x:savea1
  138.     move    a0,x:savea0
  139.  
  140.     movep    x:m_rx,a        ; get an input sample
  141.     move        a,y:(r6)+    ; store input sample (update pointer)
  142.  
  143.     move        y:(r4+n4),a    ; get output sample
  144.     movep    a,x:m_tx        ; output a sample
  145. ;
  146. ; pointer update - get ready for left channel (it is first in data stream)
  147. ;
  148.     move    l:pointer,a        ; grab pointer
  149.     add    x0,a            ; add alpha to pointer
  150.     rep    #12            ; shift so a1 contains integer part
  151.     asr    a
  152.     and    y0,a            ; modulo L
  153.     move    a1,n4            ; update pointer
  154.     rep    #12            ; shift back
  155.     asl    a
  156.     move    a,l:pointer        ; save pointer
  157.     nop
  158.  
  159. resta    move    x:savea2,a2        ; restore a register
  160.     move    x:savea1,a1
  161.     move    x:savea0,a0
  162.     rti
  163.  
  164. ; ****************************************
  165. ; left channel
  166. ;
  167. left    move    a2,x:savea2        ; save a register
  168.     move    a1,x:savea1
  169.     move    a0,x:savea0
  170.  
  171.     movep    x:m_rx,a        ; get an input sample
  172.     move    a,x:(r6)        ; store input sample
  173.  
  174.     move    x:(r4+n4),a        ; get output sample
  175.     movep    a,x:m_tx        ; output a sample
  176.  
  177.     jmp    resta            ; restore a register
  178.  
  179.  
  180.     end    pgmram
  181.