home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #6
/
amigamamagazinepolishissue1998.iso
/
packery
/
fp_adpcm
/
x2adpcm
/
source
/
adpcm2_crunch.asm
next >
Wrap
Assembly Source File
|
1977-12-31
|
2KB
|
97 lines
*** ADPCM2 sample compression routines ****
*** Copyright (C) 1993 by Christian Buchner ****
SECTION Code
*** CompressADPCM2 ***
; JoinCode = CompressADPCM2(Source, Length, Destination, JoinCode)
; d0 a0 d0 a1 d1
;
; This function compresses a RAW sample to a given memory. The
; result is a 2bit ADPCM code. The destination buffer must be
; at least (Length+3)/4 bytes in size.
;
; Function of the JoinCode: See above.
XDEF _CompressADPCM2
_CompressADPCM2
movem.l d2-d4,-(sp)
addq.l #3,d0
lsr.l #2,d0
move.w d1,d3 ; d3=EstMax
swap d1
move.w d1,d2 ; d2=Delta
bne.s c2_entry
moveq #5,d2
bra.s c2_entry
c2_loop lsl.b #2,d1 ; d1=Shifter
bsr.s c2_byte
lsl.b #2,d1
bsr.s c2_byte
lsl.b #2,d1
bsr.s c2_byte
lsl.b #2,d1
bsr.s c2_byte
move.b d1,(a1)+
c2_entry dbra d0,c2_loop ; d0=Counter
swap d0
subq.w #1,d0
bcs.s c2_finished
swap d0
bra.s c2_loop
c2_finished move.w d2,d0 ; -> d0=JoinCode
swap d0
move.w d3,d0
movem.l (sp)+,d2-d4
rts
c2_byte move.b (a0)+,d4
ext.w d4
asl.w #6,d4
sub.w d3,d4
bpl.s c2_skip1
bset #1,d1
neg.w d4
c2_skip1 cmp.w d2,d4
bls.s c2_skip2
bset #0,d1
c2_skip2 bsr.s adaptive
rts
*** Adaptions-Routine ***
adaptive ; d1 = SignBit + DataBit
move.w d2,d4
lsr.w #1,d4
btst #0,d1
beq.s d2_skip1
add.w d2,d4
mulu #$5600,d2
bra.s d2_sign
d2_skip1 mulu #$3800,d2
d2_sign btst #1,d1
beq.s d2_skip2
neg.w d4
d2_skip2 add.w d4,d3
add.l #8192,d2
moveq #14,d4
asr.l d4,d2
rts
END