# HG changeset patch # User Mychaela Falconia # Date 1682227026 0 # Node ID 84d22eb72196419fbaec1fef06b854b23fa6ffdc # Parent ba737a0203e23c0dbd215c2a9ff66700ee55e00c dev: new program s2u-regen diff -r ba737a0203e2 -r 84d22eb72196 .hgignore --- a/.hgignore Sun Apr 23 04:36:21 2023 +0000 +++ b/.hgignore Sun Apr 23 05:17:06 2023 +0000 @@ -21,6 +21,8 @@ ^dev/gsm0611-silence-fr\.out$ ^dev/s2a-regen$ ^dev/s2a-regen\.out$ +^dev/s2u-regen$ +^dev/s2u-regen\.out$ ^efrtest/gsmefr-cod-parse$ ^efrtest/gsmefr-dec-parse$ diff -r ba737a0203e2 -r 84d22eb72196 dev/Makefile --- a/dev/Makefile Sun Apr 23 04:36:21 2023 +0000 +++ b/dev/Makefile Sun Apr 23 05:17:06 2023 +0000 @@ -1,9 +1,9 @@ CC= gcc CFLAGS= -O2 PROGS= a2s-regen efr-bit-packing efr-sid-insert efr-tidsp gsm0611-silence-fr \ - s2a-regen + s2a-regen s2u-regen DATAOUT=a2s-regen.out efr-bit-packing.out efr-sid-insert.out efr-tidsp.out \ - gsm0611-silence-fr.out s2a-regen.out + gsm0611-silence-fr.out s2a-regen.out s2u-regen.out all: ${PROGS} ${DATAOUT} @@ -43,5 +43,11 @@ s2a-regen.out: s2a-regen ./s2a-regen > $@ +s2u-regen: s2u-regen.c + ${CC} ${CFLAGS} -o $@ $@.c + +s2u-regen.out: s2u-regen + ./s2u-regen > $@ + clean: rm -f *.o *.out ${PROGS} diff -r ba737a0203e2 -r 84d22eb72196 dev/s2u-regen.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dev/s2u-regen.c Sun Apr 23 05:17:06 2023 +0000 @@ -0,0 +1,72 @@ +/* + * This program regenerates a G.711 mu-law encoding table equivalent to the + * s2u[] table in the toast_ulaw.c module in libgsm/toast; the intent is + * to check that table for correctness. The "engine" function that does + * the computation is based on ulaw_compress() from ITU-T G.191 STL. + */ + +#include +#include + +static unsigned +ulaw_compress(input) + unsigned input; +{ + short i; /* aux.var. */ + short absno; /* absolute value of linear (input) sample */ + short segno; /* segment (Table 2/G711, column 1) */ + short low_nibble; /* low nibble of log companded sample */ + short high_nibble; /* high nibble of log companded sample */ + unsigned output; + + /* -------------------------------------------------------------------- */ + /* Change from 14 bit left justified to 14 bit right justified */ + /* Compute absolute value; adjust for easy processing */ + /* -------------------------------------------------------------------- */ + absno = input >= 4096 /* compute 1's complement in case of */ + ? ((~input & 4095) << 1) + 33 /* negative samples */ + : (input << 1) + 33; /* NB: 33 is the difference value */ + /* between the thresholds for */ + /* A-law and u-law. */ + if (absno > (0x1FFF)) /* limitation to "absno" < 8192 */ + absno = (0x1FFF); + + /* Determination of sample's segment */ + i = absno >> 6; + segno = 1; + while (i != 0) { + segno++; + i >>= 1; + } + + /* Mounting the high-nibble of the log-PCM sample */ + high_nibble = (0x0008) - segno; + + /* Mounting the low-nibble of the log PCM sample */ + low_nibble = (absno >> segno) /* right shift of mantissa and */ + &(0x000F); /* masking away leading '1' */ + low_nibble = (0x000F) - low_nibble; + + /* Joining the high-nibble and the low-nibble of the log PCM sample */ + output = (high_nibble << 4) | low_nibble; + + /* Add sign bit */ + if (input < 4096) + output = output | (0x0080); + + return output; +} + +main(argc, argv) + char **argv; +{ + unsigned input, output; + + for (input = 0; input < 8192; input++) { + output = ulaw_compress(input); + printf("%04o,", output); + if ((input % 15) == 14 || input == 8191) + putchar('\n'); + } + exit(0); +}