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

  1.  
  2.     ***  ADPCM2 sample decompression routines   ****
  3.     *** Copyright (C) 1993 by Christian Buchner ****
  4.  
  5.  
  6.         SECTION    Code
  7.  
  8.  
  9.     *** DecompressADPCM2 ***
  10.  
  11.     ; JoinCode = DecompressADPCM2(Source, Length, Destination, JoinCode)
  12.     ; d0                          a0      d0      a1           d1
  13.     ;
  14.     ; This function decompresses 2bit ADPCM data to a given memory. The
  15.     ; result is an 8 bit raw sample which can be played by the Amiga
  16.     ; audio DMA. The destination buffer must be at least 4 times as large
  17.     ; as the source buffer.
  18.     ;
  19.         ; The JoinCode is used to decompress a sample in parts. Just hand in
  20.     ; the return value of the last decompressed chunk and continue at the
  21.     ; position you stopped. The JoinCode should be set to 0 when starting
  22.     ; a new decompression.
  23.     ; 
  24.     ; Bits 31-16      Bits 15-0
  25.     ; Current Delta | Current EstMax
  26.     ;
  27.  
  28.         XDEF _DecompressADPCM2
  29. _DecompressADPCM2
  30.         movem.l    d2-d4,-(sp)
  31.  
  32.         move.w    d1,d3            ; d3=EstMax
  33.         swap    d1
  34.         move.w    d1,d2            ; d2=Delta
  35.         bne.s    d2_entry
  36.         moveq    #5,d2
  37.         bra.s    d2_entry
  38.  
  39. d2_loop        move.b    (a0)+,d1        ; d1=Shifter
  40.         rol.b    #2,d1
  41.         bsr.s    d2_byte
  42.         rol.b    #2,d1
  43.         bsr.s    d2_byte
  44.         rol.b    #2,d1
  45.         bsr.s    d2_byte
  46.         rol.b    #2,d1
  47.         bsr.s    d2_byte
  48.  
  49. d2_entry    dbra    d0,d2_loop        ; d0=Counter
  50.         swap    d0
  51.         subq.w    #1,d0
  52.         bcs.s    d2_finished
  53.         swap    d0
  54.         bra.s    d2_loop
  55.  
  56. d2_finished    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. d2_byte        bsr.s    adaptive
  64.         move.w    d3,d4
  65.         asr.w    #6,d4
  66.         cmp.w    #127,d4
  67.         bgt.s    d2_high
  68.         cmp.w    #-128,d4
  69.         blt.s    d2_low
  70.         move.b    d4,(a1)+
  71.         rts
  72. d2_high        move.b    #127,(a1)+
  73.         rts
  74. d2_low        move.b    #-128,(a1)+
  75.         rts
  76.  
  77.  
  78.  
  79.         *** Adaptions-Routine ***
  80.  
  81. adaptive    ; d1 = SignBit + DataBit
  82.  
  83.         move.w    d2,d4
  84.         lsr.w    #1,d4
  85.         btst    #0,d1
  86.         beq.s    d2_skip1
  87.         add.w    d2,d4
  88.         mulu    #$5600,d2
  89.         bra.s    d2_sign
  90. d2_skip1    mulu    #$3800,d2
  91. d2_sign        btst    #1,d1
  92.         beq.s    d2_skip2
  93.         neg.w    d4
  94. d2_skip2    add.w    d4,d3
  95.         add.l    #8192,d2
  96.         moveq    #14,d4
  97.         asr.l    d4,d2
  98.         rts
  99.  
  100.  
  101.         END
  102.