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

  1.  
  2.     ***   ADPCM2 sample compression routines    ****
  3.     *** Copyright (C) 1993 by Christian Buchner ****
  4.  
  5.  
  6.         SECTION Code
  7.  
  8.  
  9.     *** CompressADPCM2 ***
  10.  
  11.     ; JoinCode = CompressADPCM2(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 2bit ADPCM code. The destination buffer must be
  16.     ; at least (Length+3)/4 bytes in size.
  17.     ;
  18.     ; Function of the JoinCode: See above.
  19.  
  20.  
  21.         XDEF _CompressADPCM2
  22. _CompressADPCM2
  23.         movem.l    d2-d4,-(sp)
  24.  
  25.         addq.l    #3,d0
  26.         lsr.l    #2,d0
  27.  
  28.         move.w    d1,d3            ; d3=EstMax
  29.         swap    d1
  30.         move.w    d1,d2            ; d2=Delta
  31.         bne.s    c2_entry
  32.         moveq    #5,d2
  33.         bra.s    c2_entry
  34.  
  35. c2_loop        lsl.b    #2,d1            ; d1=Shifter
  36.         bsr.s    c2_byte
  37.         lsl.b    #2,d1
  38.         bsr.s    c2_byte
  39.         lsl.b    #2,d1
  40.         bsr.s    c2_byte
  41.         lsl.b    #2,d1
  42.         bsr.s    c2_byte
  43.         move.b    d1,(a1)+
  44.  
  45. c2_entry    dbra    d0,c2_loop        ; d0=Counter
  46.         swap    d0
  47.         subq.w    #1,d0
  48.         bcs.s    c2_finished
  49.         swap    d0
  50.         bra.s    c2_loop
  51.  
  52. c2_finished    move.w    d2,d0            ; -> d0=JoinCode
  53.         swap    d0
  54.         move.w    d3,d0
  55.  
  56.         movem.l    (sp)+,d2-d4
  57.         rts
  58.  
  59. c2_byte        move.b    (a0)+,d4
  60.         ext.w    d4
  61.         asl.w    #6,d4
  62.         sub.w    d3,d4
  63.         bpl.s    c2_skip1
  64.         bset    #1,d1
  65.         neg.w    d4
  66. c2_skip1    cmp.w    d2,d4
  67.         bls.s    c2_skip2
  68.         bset    #0,d1
  69. c2_skip2    bsr.s    adaptive
  70.         rts
  71.  
  72.  
  73.  
  74.         *** Adaptions-Routine ***
  75.  
  76. adaptive    ; d1 = SignBit + DataBit
  77.  
  78.         move.w    d2,d4
  79.         lsr.w    #1,d4
  80.         btst    #0,d1
  81.         beq.s    d2_skip1
  82.         add.w    d2,d4
  83.         mulu    #$5600,d2
  84.         bra.s    d2_sign
  85. d2_skip1    mulu    #$3800,d2
  86. d2_sign        btst    #1,d1
  87.         beq.s    d2_skip2
  88.         neg.w    d4
  89. d2_skip2    add.w    d4,d3
  90.         add.l    #8192,d2
  91.         moveq    #14,d4
  92.         asr.l    d4,d2
  93.         rts
  94.  
  95.  
  96.         END
  97.