# HG changeset patch # User Mychaela Falconia # Date 1682268812 0 # Node ID a5200ad12d586b5ab06e3378b678aaebf5851759 # Parent 84d22eb72196419fbaec1fef06b854b23fa6ffdc dev/s2u-regen.c: new approach diff -r 84d22eb72196 -r a5200ad12d58 dev/s2u-regen.c --- a/dev/s2u-regen.c Sun Apr 23 05:17:06 2023 +0000 +++ b/dev/s2u-regen.c Sun Apr 23 16:53:32 2023 +0000 @@ -1,8 +1,15 @@ /* - * 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. + * This program generates a G.711 mu-law encoding table of the same form + * as the s2u[] table in the toast_ulaw.c module in libgsm/toast, i.e., + * an encoding table that takes only the upper 13 bits of the linear PCM + * sample to be encoded, even though canonical mu-law encoding requires + * 14-bit input. The 13-bit table constructed by this program is computed + * as if the lsb of the "proper" 14-bit input is always zero, like it is + * expected to be when the linear PCM samples came from the output of a + * GSM speech decoder. + * + * The "engine" function that does the computation is based on ulaw_compress() + * from ITU-T G.191 STL. */ #include @@ -20,12 +27,12 @@ unsigned output; /* -------------------------------------------------------------------- */ - /* Change from 14 bit left justified to 14 bit right justified */ + /* Input is 14-bit right-justified in this version */ /* 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 */ + absno = input >= 0x2000 /* compute 1's complement in case of */ + ? (~input & 0x1FFF) + 33 /* negative samples */ + : input + 33; /* NB: 33 is the difference value */ /* between the thresholds for */ /* A-law and u-law. */ if (absno > (0x1FFF)) /* limitation to "absno" < 8192 */ @@ -51,7 +58,7 @@ output = (high_nibble << 4) | low_nibble; /* Add sign bit */ - if (input < 4096) + if (input < 0x2000) output = output | (0x0080); return output; @@ -63,7 +70,7 @@ unsigned input, output; for (input = 0; input < 8192; input++) { - output = ulaw_compress(input); + output = ulaw_compress(input << 1); printf("%04o,", output); if ((input % 15) == 14 || input == 8191) putchar('\n');