home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / packery / fp_adpcm / cdripper / source / adpcm3_crunch.asm < prev    next >
Assembly Source File  |  1977-12-31  |  2KB  |  122 lines

  1.  
  2.     ***   ADPCM3 sample compression routines    ****
  3.     *** Copyright (C) 1993 by Christian Buchner ****
  4.  
  5.  
  6.         SECTION    Code
  7.  
  8.  
  9.     *** CompressADPCM3 ***
  10.  
  11.     ; JoinCode = CompressADPCM3(Source, Length, Destination, JoinCode)
  12.     ; d0                          a0      d0      a1           d1
  13.     ;
  14.     ; This function compresses a RAW sample to a given memory. The
  15.     ; result is a 3bit ADPCM code. The destination buffer must be
  16.     ; at least (Length+7)/8*3 bytes in size.
  17.     ;
  18.     ; Function of the JoinCode: See above.
  19.  
  20.         XDEF _CompressADPCM3
  21. _CompressADPCM3
  22.         movem.l    d2-d4,-(sp)
  23.  
  24.         move.w    d1,d3            ; d3=EstMax
  25.         swap    d1
  26.         move.w    d1,d2            ; d2=Delta
  27.         bne.s    c3_loop
  28.         moveq    #5,d2
  29.  
  30. c3_loop        moveq    #0,d1            ; d1=Shifter
  31.         bsr.s    c3_byte
  32.         lsl.b    #3,d1
  33.         bsr.s    c3_byte
  34.         lsl.w    #3,d1
  35.         bsr.s    c3_byte
  36.         lsl.w    #3,d1
  37.         bsr.s    c3_byte
  38.         lsl.w    #3,d1
  39.         bsr.s    c3_byte
  40.         lsl.l    #3,d1
  41.         bsr.s    c3_byte
  42.         lsl.l    #3,d1
  43.         bsr.s    c3_byte
  44.         lsl.l    #3,d1
  45.         bsr.s    c3_byte
  46.         swap    d1
  47.         move.b    d1,(a1)+
  48.         rol.l    #8,d1
  49.         move.b    d1,(a1)+
  50.         rol.l    #8,d1
  51.         move.b    d1,(a1)+
  52.     
  53.         subq.l    #8,d0            ; d0=Counter
  54.         bhi.s    c3_loop
  55.  
  56.         move.w    d2,d0            ; -> d0=JoinCode
  57.         swap    d0
  58.         move.w    d3,d0
  59.  
  60.         movem.l    (sp)+,d2-d4
  61.         rts
  62.  
  63. c3_byte        move.b    (a0)+,d4
  64.         ext.w    d4
  65.         asl.w    #6,d4
  66.         sub.w    d3,d4
  67.         bpl.s    c3_positive
  68.         or.b    #%100,d1
  69.         neg.w    d4
  70. c3_positive    sub.w    d2,d4
  71.         bls.s    c3_00
  72.         sub.w    d2,d4
  73.         bls.s    c3_01
  74.         sub.w    d2,d4
  75.         bls.s    c3_10
  76. c3_11        or.b    #%11,d1
  77.         bra.s    c3_00
  78. c3_10        or.b    #%10,d1
  79.         bra.s    c3_00
  80. c3_01        or.b    #%01,d1
  81. c3_00        bsr.s    adaptive
  82.         rts
  83.  
  84.  
  85.  
  86.         *** Adaptions-Routine ***
  87.  
  88. adaptive    ; d1 = SignBit + DataBit
  89.  
  90.         move.w    d2,d4
  91.         lsr.w    #1,d4
  92.         btst    #1,d1
  93.         beq.s    d3_0
  94. d3_1        btst    #0,d1
  95.         beq.s    d3_10
  96. d3_11        add.w    d2,d4
  97.         add.w    d2,d4
  98.         add.w    d2,d4
  99.         mulu    #$6607,d2
  100.         bra.s    d3_sign
  101. d3_10        add.w    d2,d4
  102.         add.w    d2,d4
  103.         mulu    #$4D14,d2
  104.         bra.s    d3_sign
  105. d3_0        btst    #0,d1
  106.         beq.s    d3_00
  107. d3_01        add.w    d2,d4
  108.         mulu    #$3A9F,d2
  109.         bra.s    d3_sign
  110. d3_00        mulu    #$399A,d2
  111. d3_sign        btst    #2,d1
  112.         beq.s    d3_add
  113.         neg.w    d4
  114. d3_add        add.w    d4,d3
  115.         add.l    #8192,d2
  116.         moveq    #14,d4
  117.         asr.l    d4,d2
  118.         rts
  119.  
  120.  
  121.         END
  122.