home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #6
/
amigamamagazinepolishissue1998.iso
/
packery
/
fp_adpcm
/
x2adpcm
/
source
/
adpcm3_crunch.asm
< prev
next >
Wrap
Assembly Source File
|
1977-12-31
|
2KB
|
122 lines
*** ADPCM3 sample compression routines ****
*** Copyright (C) 1993 by Christian Buchner ****
SECTION Code
*** CompressADPCM3 ***
; JoinCode = CompressADPCM3(Source, Length, Destination, JoinCode)
; d0 a0 d0 a1 d1
;
; This function compresses a RAW sample to a given memory. The
; result is a 3bit ADPCM code. The destination buffer must be
; at least (Length+7)/8*3 bytes in size.
;
; Function of the JoinCode: See above.
XDEF _CompressADPCM3
_CompressADPCM3
movem.l d2-d4,-(sp)
move.w d1,d3 ; d3=EstMax
swap d1
move.w d1,d2 ; d2=Delta
bne.s c3_loop
moveq #5,d2
c3_loop moveq #0,d1 ; d1=Shifter
bsr.s c3_byte
lsl.b #3,d1
bsr.s c3_byte
lsl.w #3,d1
bsr.s c3_byte
lsl.w #3,d1
bsr.s c3_byte
lsl.w #3,d1
bsr.s c3_byte
lsl.l #3,d1
bsr.s c3_byte
lsl.l #3,d1
bsr.s c3_byte
lsl.l #3,d1
bsr.s c3_byte
swap d1
move.b d1,(a1)+
rol.l #8,d1
move.b d1,(a1)+
rol.l #8,d1
move.b d1,(a1)+
subq.l #8,d0 ; d0=Counter
bhi.s c3_loop
move.w d2,d0 ; -> d0=JoinCode
swap d0
move.w d3,d0
movem.l (sp)+,d2-d4
rts
c3_byte move.b (a0)+,d4
ext.w d4
asl.w #6,d4
sub.w d3,d4
bpl.s c3_positive
or.b #%100,d1
neg.w d4
c3_positive sub.w d2,d4
bls.s c3_00
sub.w d2,d4
bls.s c3_01
sub.w d2,d4
bls.s c3_10
c3_11 or.b #%11,d1
bra.s c3_00
c3_10 or.b #%10,d1
bra.s c3_00
c3_01 or.b #%01,d1
c3_00 bsr.s adaptive
rts
*** Adaptions-Routine ***
adaptive ; d1 = SignBit + DataBit
move.w d2,d4
lsr.w #1,d4
btst #1,d1
beq.s d3_0
d3_1 btst #0,d1
beq.s d3_10
d3_11 add.w d2,d4
add.w d2,d4
add.w d2,d4
mulu #$6607,d2
bra.s d3_sign
d3_10 add.w d2,d4
add.w d2,d4
mulu #$4D14,d2
bra.s d3_sign
d3_0 btst #0,d1
beq.s d3_00
d3_01 add.w d2,d4
mulu #$3A9F,d2
bra.s d3_sign
d3_00 mulu #$399A,d2
d3_sign btst #2,d1
beq.s d3_add
neg.w d4
d3_add add.w d4,d3
add.l #8192,d2
moveq #14,d4
asr.l d4,d2
rts
END