# HG changeset patch # User Mychaela Falconia # Date 1721799591 0 # Node ID ee54b9748c0952d2ee7dbd3c4d9cae399384b8b4 # Parent d5f1b7aa76c4621ac45b71dbc311bf9999cb0232 hr-sid: add conversion of misordered SID field diff -r d5f1b7aa76c4 -r ee54b9748c09 .hgignore --- a/.hgignore Sun Jun 09 08:58:44 2024 +0000 +++ b/.hgignore Wed Jul 24 05:39:51 2024 +0000 @@ -26,6 +26,7 @@ ^dmw/dmw-[au]law\. ^efr-sid/mk-sid-test$ +^hr-sid/misorder$ ^hr-sid/sidgen$ ^pcma2efr/all-outputs\. diff -r d5f1b7aa76c4 -r ee54b9748c09 hr-sid/Makefile --- a/hr-sid/Makefile Sun Jun 09 08:58:44 2024 +0000 +++ b/hr-sid/Makefile Wed Jul 24 05:39:51 2024 +0000 @@ -1,15 +1,23 @@ CC= gcc CFLAGS= -O2 -PROG= sidgen -OUTPUT= hr-sid-test.hrpf +PROGS= misorder sidgen +MISORD= sid-field-misorder.inc +SIDTEST=hr-sid-test.hrpf +OUTPUT= ${MISORD} ${SIDTEST} -all: ${PROG} ${OUTPUT} +all: ${PROGS} ${OUTPUT} -${PROG}: ${PROG}.o +sidgen: sidgen.c ${CC} ${CFLAGS} -o $@ $^ -${OUTPUT}: ${PROG} - ./${PROG} ${OUTPUT} +${SIDTEST}: sidgen + ./sidgen $@ + +misorder: misorder.c + ${CC} ${CFLAGS} -o $@ $^ + +${MISORD}: misorder + ./misorder > $@ clean: - rm -f ${PROG} *.o *.hrpf + rm -f ${PROGS} *.o *.hrpf *.inc diff -r d5f1b7aa76c4 -r ee54b9748c09 hr-sid/misorder.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hr-sid/misorder.c Wed Jul 24 05:39:51 2024 +0000 @@ -0,0 +1,89 @@ +/* + * swSidDetection() in reid.c in GSM 06.06 source contains a table + * that identifies the 79 bits of the SID field when they got misordered + * as a result of decoding in unvoiced mode. That table is given + * in the form of an array of 18 codec params. We need the same mask + * of misordered SID field bits in the packed format of TS 101 318. + * This program performs the conversion. + */ + +#include +#include +#include + +static const int16_t misordered_sid_params[18] = { + 0x0001, /* R0 */ /* unvoiced */ + 0x00ef, /* LPC1 */ + 0x003e, /* LPC2 */ + 0x007f, /* LPC3 */ + 0x0001, /* INT LPC */ + 0x0003, /* Mode */ + 0x001f, /* Code1_1 */ + 0x0072, /* Code2_1 */ + 0x0012, /* GSP0_1 */ + 0x003f, /* Code1_2 */ + 0x007f, /* Code2_2 */ + 0x0008, /* GSP0_2 */ + 0x007f, /* Code1_3 */ + 0x007f, /* Code2_3 */ + 0x0008, /* GSP0_3 */ + 0x007f, /* Code1_4 */ + 0x007f, /* Code2_4 */ + 0x000c, /* GSP0_4 */ +}; + +void +pack_ts101318_unvoiced(params, payload) + const int16_t *params; + uint8_t *payload; +{ + uint8_t *c = payload; + + /* unvoiced mode */ + *c++ = ((params[0] & 0x1F) << 3) + | ((params[1] >> 8) & 0x7); + *c++ = params[1] & 0xFF; + *c++ = ((params[2] >> 1) & 0xFF); + *c++ = ((params[2] & 0x1) << 7) + | ((params[3] >> 1) & 0x7F); + *c++ = ((params[3] & 0x1) << 7) + | ((params[4] & 0x1) << 6) + | ((params[5] & 0x3) << 4) + | ((params[6] >> 3) & 0xF); + *c++ = ((params[6] & 0x7) << 5) + | ((params[7] >> 2) & 0x1F); + *c++ = ((params[7] & 0x3) << 6) + | ((params[8] & 0x1F) << 1) + | ((params[9] >> 6) & 0x1); + *c++ = ((params[9] & 0x3F) << 2) + | ((params[10] >> 5) & 0x3); + *c++ = ((params[10] & 0x1F) << 3) + | ((params[11] >> 2) & 0x7); + *c++ = ((params[11] & 0x3) << 6) + | ((params[12] >> 1) & 0x3F); + *c++ = ((params[12] & 0x1) << 7) + | (params[13] & 0x7F); + *c++ = ((params[14] & 0x1F) << 3) + | ((params[15] >> 4) & 0x7); + *c++ = ((params[15] & 0xF) << 4) + | ((params[16] >> 3) & 0xF); + *c++ = ((params[16] & 0x7) << 5) + | (params[17] & 0x1F); +} + +main(argc, argv) + char **argv; +{ + uint8_t packed_frame[14]; + int i; + + pack_ts101318_unvoiced(misordered_sid_params, packed_frame); + for (i = 0; i < 14; i++) { + printf("0x%02X,", packed_frame[i]); + if (i == 6 || i == 13) + putchar('\n'); + else + putchar(' '); + } + exit(0); +}