# HG changeset patch # User Mychaela Falconia # Date 1683863299 0 # Node ID 6ac547f0b90384bd4df8e64e9799b978dcabf253 # Parent 56d3fbacd115310c6be1975d0c9f97ade1bd6881 libgsmfrp: yet another invalid SID logic change, for 1.0.2 diff -r 56d3fbacd115 -r 6ac547f0b903 libgsmfrp/Makefile --- a/libgsmfrp/Makefile Fri May 12 02:04:42 2023 +0000 +++ b/libgsmfrp/Makefile Fri May 12 03:48:19 2023 +0000 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 OBJS= bad_frame.o comfort_noise.o good_frame.o prng.o sidclass.o \ - silence_frame.o state.o + silence_frame.o state.o xmaxc_mean.o HDRS= gsm_fr_preproc.h internal.h LIB= libgsmfrp.a diff -r 56d3fbacd115 -r 6ac547f0b903 libgsmfrp/bad_frame.c --- a/libgsmfrp/bad_frame.c Fri May 12 02:04:42 2023 +0000 +++ b/libgsmfrp/bad_frame.c Fri May 12 03:48:19 2023 +0000 @@ -94,6 +94,8 @@ void gsmfr_preproc_invalid_sid(struct gsmfr_preproc_state *st, gsm_byte *frame) { + int mute; + switch (st->rx_state) { case NO_DATA: memcpy(frame, &gsmfr_preproc_silence_frame, sizeof(gsm_frame)); @@ -105,17 +107,16 @@ */ st->rx_state = COMFORT_NOISE; memcpy(st->sid_prefix, &st->speech_frame, 5); - st->sid_xmaxc = ((st->speech_frame[27] & 0x1F) << 1) | - (st->speech_frame[28] >> 7); + st->sid_xmaxc = gsmfr_preproc_xmaxc_mean(st->speech_frame); gsmfr_preproc_gen_cn(st, frame); return; case SPEECH_MUTING: - /* same as above, but set the state to CN_MUTING */ - st->rx_state = CN_MUTING; - memcpy(st->sid_prefix, &st->speech_frame, 5); - st->sid_xmaxc = ((st->speech_frame[27] & 0x1F) << 1) | - (st->speech_frame[28] >> 7); - gsmfr_preproc_gen_cn(st, frame); + /* ignore invalid SID in this state and act as if we got BFI */ + mute = reduce_xmaxc(st->speech_frame); + memcpy(frame, &st->speech_frame, sizeof(gsm_frame)); + random_grid_pos(st, frame); + if (mute) + st->rx_state = NO_DATA; return; case COMFORT_NOISE: case LOST_SID: diff -r 56d3fbacd115 -r 6ac547f0b903 libgsmfrp/internal.h --- a/libgsmfrp/internal.h Fri May 12 02:04:42 2023 +0000 +++ b/libgsmfrp/internal.h Fri May 12 03:48:19 2023 +0000 @@ -33,3 +33,4 @@ gsm_byte *frame); extern uint16_t gsmfr_preproc_prng(struct gsmfr_preproc_state *state, uint16_t no_bits); +extern uint8_t gsmfr_preproc_xmaxc_mean(const gsm_byte *frame); diff -r 56d3fbacd115 -r 6ac547f0b903 libgsmfrp/xmaxc_mean.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgsmfrp/xmaxc_mean.c Fri May 12 03:48:19 2023 +0000 @@ -0,0 +1,100 @@ +/* + * The function implemented in this module computes a mean Xmaxc + * for comfort noise generation from the 4 subframe Xmaxc parameters + * extracted from an input frame. + */ + +#include +#include "gsm_fr_preproc.h" +#include "internal.h" + +static const uint16_t dequant_table[64] = { + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 18, 20, 22, 24, 26, 28, 30, + 32, 36, 40, 44, 48, 52, 56, 60, + 64, 72, 80, 88, 96, 104, 112, 120, + 128, 144, 160, 176, 192, 208, 224, 240, + 256, 288, 320, 352, 384, 416, 448, 480, + 512, 576, 640, 704, 768, 832, 896, 960, +}; + +static const uint8_t requant_table[1024] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, + 24, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 27, + 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, + 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 33, + 34, 34, 34, 34, 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 35, 35, + 36, 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 37, 37, 37, + 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, + 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, + 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, + 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, + 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, + 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, + 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, + 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, + 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, + 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, + 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, + 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, + 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, + 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, + 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, + 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, + 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, + 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, + 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, + 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, + 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, + 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, + 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, + 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, + 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, + 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, + 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, + 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, + 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, + 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, + 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, + 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, + 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, + 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, +}; + +uint8_t gsmfr_preproc_xmaxc_mean(const gsm_byte *frame) +{ + unsigned sub, xmaxc, sum; + + sum = 0; + for (sub = 0; sub < 4; sub++) { + xmaxc = ((frame[sub*7+6] & 0x1F) << 1) | (frame[sub*7+7] >> 7); + sum += dequant_table[xmaxc]; + } + xmaxc = requant_table[sum >> 2]; + return xmaxc; +}