/* This C language subroutine performs Mu-Law compression/expansion. The Run Time Library for the C Language. Gordon A. Sterling (617) 461 - 3076 DSP Development Tools Engineering Created on 4/28/90 Updated on 5/94 by AS #include
int mu_expand(int x); int mu_compress(int x); */ #include "lib_glob.h" #include "com_glob.h" .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL _mu_expand, _mu_compress; _mu_expand: R2=0xFF; /*Mask unwanted bits*/ R8=R4 AND R2, R0=R4; R8=R2 XOR R8, FETCH_RETURN /*Invert bits*/ R2=0x70; R1=R2 AND R8; /*Isolate segment bits*/ R0=R1 XOR R8; /*Remove segment bits*/ R2=0xFFFFFF80; R8=R0+R2; IF LT JUMP (PC, posval) (DB); /*Determine sign*/ R2=33; R13=LSHIFT R13 BY -4; /*Shift segment bits to LSBs*/ negval: R0=R8+R8; JUMP (PC,7) (DB), R0=R0+R2;/*Add segment offset*/ R0=ASHIFT R0 BY R1; /*Position bits*/ R0=R2-R0; /*Remove segment offset*/ posval: R0=R0+R0; R0=R0+R2; /*Add segment offset*/ R0=ASHIFT R0 BY R1; /*Position bits*/ R0=R0-R2; restore_state: RETURN (DB); RESTORE_STACK RESTORE_FRAME _mu_compress: R1=ABS R4, R0=R4; /*Take absolute value*/ R2=33; /*Add offset of boundries*/ R1=R1+R2, FETCH_RETURN R2=8191; /*Maximum PCM value*/ R1=MIN(R1,R2); /*Cap input*/ R2=EXP R1; /*Find exponent adjustment*/ R2=-R2; R1=ASHIFT R1 BY R2; /*Normalize input*/ R1=BCLR R1 BY 30; /*Remove first significant bit*/ R1=LSHIFT R1 BY -26; /*Shift position bits*/ R0=PASS R0; /*Test sign of input*/ IF LT R1=BSET R1 BY 7; /*Set sign bit if necessary*/ R0=25; R0=R0-R2; /*Compute segment*/ IF LT R0=R0-R0; R1=R1 OR LSHIFT R0 BY 4; /*Position segment bits*/ JUMP (PC, restore_state) (DB); R2=0xFF; R0=R1 XOR R2; /*Invert bits*/ .ENDSEG;