FreeCalypso > hg > gsm-codec-lib
view amrconv/param_asm.c @ 242:f081a6850fb5
libgsmfrp: new refined implementation
The previous implementation exhibited the following defects,
which are now fixed:
1) The last received valid SID was cached forever for the purpose of
handling future invalid SIDs - we could have received some valid
SID ages ago, then lots of speech or NO_DATA, and if we then get
an invalid SID, we would resurrect the last valid SID from ancient
history - a bad design. In our new design, we handle invalid SID
based on the current state, much like BFI.
2) GSM 06.11 spec says clearly that after the second lost SID
(received BFI=1 && TAF=1 in CN state) we need to gradually decrease
the output level, rather than jump directly to emitting silence
frames - we previously failed to implement such logic.
3) Per GSM 06.12 section 5.2, Xmaxc should be the same in all 4 subframes
in a SID frame. What should we do if we receive an otherwise valid
SID frame with different Xmaxc? Our previous approach would
replicate this Xmaxc oddity in every subsequent generated CN frame,
which is rather bad. In our new design, the very first CN frame
(which can be seen as a transformation of the SID frame itself)
retains the original 4 distinct Xmaxc, but all subsequent CN frames
are based on the Xmaxc from the last subframe of the most recent SID.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 09 May 2023 05:16:31 +0000 |
parents | 78d1a6513393 |
children |
line wrap: on
line source
/* * This C module is common between amr-cod-parse and amr-ietf-parse * utilities. It contains the function that takes an array of bits * in the codec's natural order and reassembles these bits into * an array of codec parameters. */ #include <stdint.h> #include "amr_defs.h" /* parameter sizes (# of bits), one table per mode */ static const uint8_t bitno_MR475[PRMNO_MR475] = { 8, 8, 7, /* LSP VQ */ 8, 7, 2, 8, /* first subframe */ 4, 7, 2, /* second subframe */ 4, 7, 2, 8, /* third subframe */ 4, 7, 2, /* fourth subframe */ }; static const uint8_t bitno_MR515[PRMNO_MR515] = { 8, 8, 7, /* LSP VQ */ 8, 7, 2, 6, /* first subframe */ 4, 7, 2, 6, /* second subframe */ 4, 7, 2, 6, /* third subframe */ 4, 7, 2, 6, /* fourth subframe */ }; static const uint8_t bitno_MR59[PRMNO_MR59] = { 8, 9, 9, /* LSP VQ */ 8, 9, 2, 6, /* first subframe */ 4, 9, 2, 6, /* second subframe */ 8, 9, 2, 6, /* third subframe */ 4, 9, 2, 6, /* fourth subframe */ }; static const uint8_t bitno_MR67[PRMNO_MR67] = { 8, 9, 9, /* LSP VQ */ 8, 11, 3, 7, /* first subframe */ 4, 11, 3, 7, /* second subframe */ 8, 11, 3, 7, /* third subframe */ 4, 11, 3, 7, /* fourth subframe */ }; static const uint8_t bitno_MR74[PRMNO_MR74] = { 8, 9, 9, /* LSP VQ */ 8, 13, 4, 7, /* first subframe */ 5, 13, 4, 7, /* second subframe */ 8, 13, 4, 7, /* third subframe */ 5, 13, 4, 7, /* fourth subframe */ }; static const uint8_t bitno_MR795[PRMNO_MR795] = { 9, 9, 9, /* LSP VQ */ 8, 13, 4, 4, 5, /* first subframe */ 6, 13, 4, 4, 5, /* second subframe */ 8, 13, 4, 4, 5, /* third subframe */ 6, 13, 4, 4, 5, /* fourth subframe */ }; static const uint8_t bitno_MR102[PRMNO_MR102] = { 8, 9, 9, /* LSP VQ */ 8, 1, 1, 1, 1, 10, 10, 7, 7, /* first subframe */ 5, 1, 1, 1, 1, 10, 10, 7, 7, /* second subframe */ 8, 1, 1, 1, 1, 10, 10, 7, 7, /* third subframe */ 5, 1, 1, 1, 1, 10, 10, 7, 7, /* fourth subframe */ }; static const uint8_t bitno_MR122[PRMNO_MR122] = { 7, 8, 9, 8, 6, /* LSP VQ */ 9, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* first subframe */ 6, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* second subframe */ 9, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* third subframe */ 6, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5 /* fourth subframe */ }; static const uint8_t bitno_MRDTX[PRMNO_MRDTX] = { 3, 8, 9, 9, 6 }; static void bits_to_params(bits, params, table, nparam) const uint8_t *bits; uint16_t *params; const uint8_t *table; unsigned nparam; { const uint8_t *p = bits; const uint8_t *t = table; unsigned n, m, acc; for (n = 0; n < nparam; n++) { acc = 0; for (m = 0; m < *t; m++) { acc <<= 1; if (*p) acc |= 1; p++; } params[n] = acc; t++; } } reassemble_amr_params(bits, params, mode) const uint8_t *bits; uint16_t *params; unsigned mode; { switch (mode) { case MR475: bits_to_params(bits, params, bitno_MR475, PRMNO_MR475); return(0); case MR515: bits_to_params(bits, params, bitno_MR515, PRMNO_MR515); return(0); case MR59: bits_to_params(bits, params, bitno_MR59, PRMNO_MR59); return(0); case MR67: bits_to_params(bits, params, bitno_MR67, PRMNO_MR67); return(0); case MR74: bits_to_params(bits, params, bitno_MR74, PRMNO_MR74); return(0); case MR795: bits_to_params(bits, params, bitno_MR795, PRMNO_MR795); return(0); case MR102: bits_to_params(bits, params, bitno_MR102, PRMNO_MR102); return(0); case MR122: bits_to_params(bits, params, bitno_MR122, PRMNO_MR122); return(0); case MRDTX: bits_to_params(bits, params, bitno_MRDTX, PRMNO_MRDTX); return(0); default: return(-1); } }