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

  1.  
  2.     ***  ADPCM3 sample decompression routines   ****
  3.     *** Copyright (C) 1993 by Christian Buchner ****
  4.  
  5.  
  6.         SECTION    Code
  7.  
  8.  
  9.     *** DecompressADPCM3 ***
  10.  
  11.     ; JoinCode = DecompressADPCM3(Source, Length, Destination, JoinCode)
  12.     ; d0                          a0      d0      a1           d1
  13.     ;
  14.     ; Length _MUST_ be a multiple of 3!
  15.     ;
  16.     ; This function decompresses 3bit ADPCM data to a given memory. The
  17.     ; result is an 8 bit raw sample which can be played by the Amiga
  18.     ; audio DMA. The destination buffer must be at least 8/3 times as
  19.     ; large as the source buffer.
  20.     ;
  21.         ; The JoinCode is used to decompress a sample in parts. Just hand in
  22.     ; the return value of the last decompressed chunk and continue at the
  23.     ; position you stopped. The JoinCode should be set to 0 when starting
  24.     ; a new decompression.
  25.     ; 
  26.     ; Bits 31-16      Bits 15-0
  27.     ; Current Delta | Current EstMax
  28.     ;
  29.  
  30.         XDEF _DecompressADPCM3
  31. _DecompressADPCM3
  32.         movem.l    d2-d4,-(sp)
  33.  
  34.         move.w    d1,d3            ; d3=EstMax
  35.         swap    d1
  36.         move.w    d1,d2            ; d2=Delta
  37.         bne.s    d3_loop
  38.         moveq    #5,d2
  39.  
  40. d3_loop        move.b    (a0)+,d1        ; d1=Shifter
  41.         rol.b    #3,d1
  42.         bsr.s    d3_byte
  43.         rol.b    #3,d1
  44.         bsr.s    d3_byte
  45.         lsl.w    #2,d1
  46.         move.b    (a0)+,d1
  47.         ror.w    #7,d1
  48.         bsr.s    d3_byte
  49.         rol.w    #3,d1
  50.         bsr.s    d3_byte
  51.         rol.w    #3,d1
  52.         bsr.s    d3_byte
  53.         lsr.w    #7,d1
  54.         move.b    (a0)+,d1
  55.         ror.w    #6,d1
  56.         bsr.s    d3_byte
  57.         rol.w    #3,d1
  58.         bsr.s    d3_byte
  59.         rol.w    #3,d1
  60.         bsr.s    d3_byte
  61.  
  62. d3_entry    subq.l    #3,d0            ; d0=Counter
  63.         bhi.s    d3_loop
  64.  
  65.         move.w    d2,d0            ; -> d0=JoinCode
  66.         swap    d0
  67.         move.w    d3,d0
  68.  
  69.         movem.l    (sp)+,d2-d4
  70.         rts
  71.  
  72. d3_byte        bsr    adaptive
  73.         move.w    d3,d4
  74.         asr.w    #6,d4
  75.         cmp.w    #127,d4
  76.         bgt.s    d3_high
  77.         cmp.w    #-128,d4
  78.         blt.s    d3_low
  79.         move.b    d4,(a1)+
  80.         rts
  81. d3_high        move.b    #127,(a1)+
  82.         rts
  83. d3_low        move.b    #-128,(a1)+
  84.         rts
  85.  
  86.  
  87.  
  88.         *** Adaptions-Routine ***
  89.  
  90. adaptive    ; d1 = SignBit + DataBit
  91.  
  92.         move.w    d2,d4
  93.         lsr.w    #1,d4
  94.         btst    #1,d1
  95.         beq.s    d3_0
  96. d3_1        btst    #0,d1
  97.         beq.s    d3_10
  98. d3_11        add.w    d2,d4
  99.         add.w    d2,d4
  100.         add.w    d2,d4
  101.         mulu    #$6607,d2
  102.         bra.s    d3_sign
  103. d3_10        add.w    d2,d4
  104.         add.w    d2,d4
  105.         mulu    #$4D14,d2
  106.         bra.s    d3_sign
  107. d3_0        btst    #0,d1
  108.         beq.s    d3_00
  109. d3_01        add.w    d2,d4
  110.         mulu    #$3A9F,d2
  111.         bra.s    d3_sign
  112. d3_00        mulu    #$399A,d2
  113. d3_sign        btst    #2,d1
  114.         beq.s    d3_add
  115.         neg.w    d4
  116. d3_add        add.w    d4,d3
  117.         add.l    #8192,d2
  118.         moveq    #14,d4
  119.         asr.l    d4,d2
  120.         rts
  121.  
  122.  
  123.         END
  124.