FreeCalypso > hg > gsm-codec-lib
comparison dev/s2a-regen.c @ 222:842136bbd0da
dev: new program s2a-regen
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 23 Apr 2023 04:09:24 +0000 |
| parents | |
| children | 3afbc6c64172 |
comparison
equal
deleted
inserted
replaced
| 221:6555dae764b3 | 222:842136bbd0da |
|---|---|
| 1 /* | |
| 2 * This program regenerates a G.711 A-law encoding table equivalent to the | |
| 3 * s2a[] table in the toast_alaw.c module in libgsm/toast; the intent is | |
| 4 * to check that table for correctness. The "engine" function that does | |
| 5 * the computation is based on alaw_compress() from ITU-T G.191 STL. | |
| 6 */ | |
| 7 | |
| 8 #include <stdio.h> | |
| 9 #include <stdlib.h> | |
| 10 | |
| 11 static unsigned | |
| 12 alaw_compress (input) | |
| 13 unsigned input; | |
| 14 { | |
| 15 short ix, iexp; | |
| 16 | |
| 17 ix = input >= 2048 /* 0 <= ix < 2048 */ | |
| 18 ? ~input & 2047 /* 1's complement for negative values */ | |
| 19 : input; | |
| 20 | |
| 21 /* Do more, if exponent > 0 */ | |
| 22 if (ix > 15) { /* exponent=0 for ix <= 15 */ | |
| 23 iexp = 1; /* first step: */ | |
| 24 while (ix > 16 + 15) { /* find mantissa and exponent */ | |
| 25 ix >>= 1; | |
| 26 iexp++; | |
| 27 } | |
| 28 ix -= 16; /* second step: remove leading '1' */ | |
| 29 | |
| 30 ix += iexp << 4; /* now compute encoded value */ | |
| 31 } | |
| 32 if (input < 2048) | |
| 33 ix |= (0x0080); /* add sign bit */ | |
| 34 | |
| 35 return ix ^ (0x0055); /* toggle even bits */ | |
| 36 } | |
| 37 | |
| 38 main(argc, argv) | |
| 39 char **argv; | |
| 40 { | |
| 41 unsigned input, output; | |
| 42 | |
| 43 for (input = 0; input < 4096; input++) { | |
| 44 if ((input & 15) == 0) | |
| 45 putchar('\t'); | |
| 46 output = alaw_compress(input); | |
| 47 printf("%03u,", output); | |
| 48 if ((input & 15) == 15) | |
| 49 putchar('\n'); | |
| 50 } | |
| 51 exit(0); | |
| 52 } |
