# HG changeset patch # User Mychaela Falconia # Date 1669407570 0 # Node ID a18782a7d270877c221c23e7e1a173ac0bb6e13b # Parent d273a77d5523f853146621d086d370b8e602a3fe libgsmefr: d_gains.c compiles diff -r d273a77d5523 -r a18782a7d270 libgsmefr/Makefile --- a/libgsmefr/Makefile Fri Nov 25 19:22:05 2022 +0000 +++ b/libgsmefr/Makefile Fri Nov 25 20:19:30 2022 +0000 @@ -1,8 +1,8 @@ CC= gcc CFLAGS= -O2 OBJS= agc.o autocorr.o az_lsp.o basicop2.o c1035pf.o cod_12k2.o convolve.o \ - d1035pf.o dec_create.o enc_create.o frame2params.o params2frame.o \ - sid_class.o sid_insert.o tls_flags.o + d1035pf.o d_gains.o dec_create.o enc_create.o frame2params.o \ + params2frame.o sid_class.o sid_insert.o tls_flags.o HDRS= basic_op.h cnst.h codec.h d_homing.h dec_state.h dtx.h e_homing.h \ enc_state.h gains_tb.h gsm_efr.h memops.h namespace.h no_count.h \ oper_32b.h sig_proc.h typedef.h vad.h diff -r d273a77d5523 -r a18782a7d270 libgsmefr/d_gains.c --- a/libgsmefr/d_gains.c Fri Nov 25 19:22:05 2022 +0000 +++ b/libgsmefr/d_gains.c Fri Nov 25 20:19:30 2022 +0000 @@ -10,41 +10,22 @@ * ( in dB/(20*log10(2)) ) with mean removed. *************************************************************************/ +#include "gsm_efr.h" #include "typedef.h" +#include "namespace.h" #include "basic_op.h" #include "oper_32b.h" -#include "count.h" +#include "no_count.h" #include "sig_proc.h" +#include "memops.h" +#include "codec.h" #include "gains_tb.h" #include "cnst.h" +#include "dec_state.h" #include "dtx.h" -extern Word16 gain_code_old_rx[4 * DTX_HANGOVER]; - -/* Static variables for bad frame handling */ - -/* Variables used by d_gain_pitch: */ -Word16 pbuf[5], past_gain_pit, prev_gp; - -/* Variables used by d_gain_code: */ -Word16 gbuf[5], past_gain_code, prev_gc; - -/* Static variables for CNI (used by d_gain_code) */ - -Word16 gcode0_CN, gain_code_old_CN, gain_code_new_CN, gain_code_muting_CN; - -/* Memories of gain dequantization: */ - -/* past quantized energies. */ -/* initialized to -14.0/constant, constant = 20*Log10(2) */ - -Word16 past_qua_en[4]; - -/* MA prediction coeff */ -Word16 pred[4]; - /************************************************************************* * * FUNCTION: gmed5 @@ -55,25 +36,21 @@ * *************************************************************************/ -Word16 gmed5 ( /* out : index of the median value (0...4) */ +static Word16 gmed5 ( /* out : index of the median value (0...4) */ Word16 ind[] /* in : Past gain values */ ) { Word16 i, j, ix = 0, tmp[5]; Word16 max, tmp2[5]; - for (i = 0; i < 5; i++) - { - tmp2[i] = ind[i]; move16 (); - } + Copy (ind, tmp2, 5); for (i = 0; i < 5; i++) { max = -8192; move16 (); for (j = 0; j < 5; j++) { - test (); - if (sub (tmp2[j], max) >= 0) + if (tmp2[j] >= max) { max = tmp2[j]; move16 (); ix = j; move16 (); @@ -100,6 +77,7 @@ *************************************************************************/ Word16 d_gain_pitch ( /* out : quantized pitch gain */ + struct EFR_decoder_state *st, Word16 index, /* in : index of quantization */ Word16 bfi, /* in : bad frame indicator (good = 0) */ Word16 state, @@ -115,63 +93,56 @@ Word16 gain, tmp, i; - test (); if (bfi == 0) { - test (); logic16 (); if ((rxdtx_ctrl & RX_SP_FLAG) != 0) { - gain = shr (qua_gain_pitch[index], 2); move16 (); + gain = shr (qua_gain_pitch[index], 2); - test (); if (prev_bf != 0) { - test (); - if (sub (gain, prev_gp) > 0) + if (gain > st->prev_gp) { - gain = prev_gp; + gain = st->prev_gp; } } } else { - gain = 0; move16 (); + gain = 0; } - prev_gp = gain; move16 (); + st->prev_gp = gain; } else { - test (); logic16 (); if ((rxdtx_ctrl & RX_SP_FLAG) != 0) { - tmp = gmed5 (pbuf); move16 (); + tmp = gmed5 (st->pbuf); - test (); - if (sub (tmp, past_gain_pit) < 0) + if (tmp < st->past_gain_pit) { - past_gain_pit = tmp; move16 (); + st->past_gain_pit = tmp; } - gain = mult (pdown[state], past_gain_pit); + gain = mult (pdown[state], st->past_gain_pit); } else { - gain = 0; move16 (); + gain = 0; } } - past_gain_pit = gain; move16 (); + st->past_gain_pit = gain; - test (); - if (sub (past_gain_pit, 4096) > 0) /* if (past_gain_pit > 1.0) */ + if (sub (st->past_gain_pit, 4096) > 0) /* if (past_gain_pit > 1.0) */ { - past_gain_pit = 4096; move16 (); + st->past_gain_pit = 4096; } for (i = 1; i < 5; i++) { - pbuf[i - 1] = pbuf[i]; move16 (); + st->pbuf[i - 1] = st->pbuf[i]; } - pbuf[4] = past_gain_pit; move16 (); + st->pbuf[4] = st->past_gain_pit; return gain; } @@ -197,6 +168,7 @@ #define MEAN_ENER 783741L /* 36/(20*log10(2)) */ void d_gain_code ( + struct EFR_decoder_state *st, Word16 index, /* input : received quantization index */ Word16 code[], /* input : innovation codevector */ Word16 lcode, /* input : codevector length */ @@ -219,142 +191,130 @@ Word16 gcode0, exp, frac, av_pred_en; Word32 ener, ener_code; - test (); test (); logic16 (); if (((rxdtx_ctrl & RX_UPD_SID_QUANT_MEM) != 0) && (i_subfr == 0)) { - gcode0_CN = update_gcode0_CN (gain_code_old_rx); move16 (); - gcode0_CN = shl (gcode0_CN, 4); + st->gcode0_CN = update_gcode0_CN (st->gain_code_old_rx); + st->gcode0_CN = shl (st->gcode0_CN, 4); } /* Handle cases of comfort noise fixed codebook gain decoding in which past valid SID frames are repeated */ - test (); test (); test (); logic16 (); logic16 (); logic16 (); if (((rxdtx_ctrl & RX_NO_TRANSMISSION) != 0) || ((rxdtx_ctrl & RX_INVALID_SID_FRAME) != 0) || ((rxdtx_ctrl & RX_LOST_SID_FRAME) != 0)) { - test (); logic16 (); if ((rxdtx_ctrl & RX_NO_TRANSMISSION) != 0) { /* DTX active: no transmission. Interpolate gain values in memory */ - test (); if (i_subfr == 0) { - *gain_code = interpolate_CN_param (gain_code_old_CN, - gain_code_new_CN, rx_dtx_state); - move16 (); + *gain_code = interpolate_CN_param (st->gain_code_old_CN, + st->gain_code_new_CN, rx_dtx_state); } else { - *gain_code = prev_gc; move16 (); + *gain_code = st->prev_gc; } } else { /* Invalid or lost SID frame: use gain values from last good SID frame */ - gain_code_old_CN = gain_code_new_CN; move16 (); - *gain_code = gain_code_new_CN; move16 (); + st->gain_code_old_CN = st->gain_code_new_CN; + *gain_code = st->gain_code_new_CN; /* reset table of past quantized energies */ for (i = 0; i < 4; i++) { - past_qua_en[i] = -2381; move16 (); + st->past_qua_en[i] = -2381; } } - test (); logic16 (); if ((rxdtx_ctrl & RX_DTX_MUTING) != 0) { /* attenuate the gain value by 0.75 dB in each subframe */ /* (total of 3 dB per frame) */ - gain_code_muting_CN = mult (gain_code_muting_CN, 30057); - *gain_code = gain_code_muting_CN; move16 (); + st->gain_code_muting_CN = mult (st->gain_code_muting_CN, 30057); + *gain_code = st->gain_code_muting_CN; } else { /* Prepare for DTX muting by storing last good gain value */ - gain_code_muting_CN = gain_code_new_CN; move16 (); + st->gain_code_muting_CN = st->gain_code_new_CN; } - past_gain_code = *gain_code; move16 (); + st->past_gain_code = *gain_code; for (i = 1; i < 5; i++) { - gbuf[i - 1] = gbuf[i]; move16 (); + st->gbuf[i - 1] = st->gbuf[i]; } - gbuf[4] = past_gain_code; move16 (); - prev_gc = past_gain_code; move16 (); + st->gbuf[4] = st->past_gain_code; + st->prev_gc = st->past_gain_code; return; } /*----------------- Test erasure ---------------*/ - test (); if (bfi != 0) { - tmp = gmed5 (gbuf); move16 (); - test (); - if (sub (tmp, past_gain_code) < 0) + tmp = gmed5 (st->gbuf); + if (sub (tmp, st->past_gain_code) < 0) { - past_gain_code = tmp; move16 (); + st->past_gain_code = tmp; } - past_gain_code = mult (past_gain_code, cdown[state]); - *gain_code = past_gain_code; move16 (); + st->past_gain_code = mult (st->past_gain_code, cdown[state]); + *gain_code = st->past_gain_code; - av_pred_en = 0; move16 (); + av_pred_en = 0; for (i = 0; i < 4; i++) { - av_pred_en = add (av_pred_en, past_qua_en[i]); + av_pred_en = add (av_pred_en, st->past_qua_en[i]); } /* av_pred_en = 0.25*av_pred_en - 4/(20Log10(2)) */ av_pred_en = mult (av_pred_en, 8192); /* *= 0.25 */ /* if (av_pred_en < -14/(20Log10(2))) av_pred_en = .. */ - test (); if (sub (av_pred_en, -2381) < 0) { - av_pred_en = -2381; move16 (); + av_pred_en = -2381; } for (i = 3; i > 0; i--) { - past_qua_en[i] = past_qua_en[i - 1]; move16 (); + st->past_qua_en[i] = st->past_qua_en[i - 1]; } - past_qua_en[0] = av_pred_en; move16 (); + st->past_qua_en[0] = av_pred_en; for (i = 1; i < 5; i++) { - gbuf[i - 1] = gbuf[i]; move16 (); + st->gbuf[i - 1] = st->gbuf[i]; } - gbuf[4] = past_gain_code; move16 (); + st->gbuf[4] = st->past_gain_code; /* Use the most recent comfort noise fixed codebook gain value for updating the fixed codebook gain history */ - test (); - if (gain_code_new_CN == 0) + if (st->gain_code_new_CN == 0) { - tmp = prev_gc; move16 (); + tmp = st->prev_gc; } else { - tmp = gain_code_new_CN; + tmp = st->gain_code_new_CN; } - update_gain_code_history_rx (tmp, gain_code_old_rx); + update_gain_code_history_rx (st, tmp); - test (); if (sub (i_subfr, (3 * L_SUBFR)) == 0) { - gain_code_old_CN = *gain_code; move16 (); + st->gain_code_old_CN = *gain_code; } return; } - test (); logic16 (); if ((rxdtx_ctrl & RX_SP_FLAG) != 0) { @@ -386,7 +346,7 @@ ener = MEAN_ENER; move32 (); for (i = 0; i < 4; i++) { - ener = L_mac (ener, past_qua_en[i], pred[i]); + ener = L_mac (ener, st->past_qua_en[i], st->pred[i]); } /*-------------------------------------------------------------------* @@ -406,13 +366,11 @@ *gain_code = mult (qua_gain_code[index], gcode0); move16 (); - test (); if (prev_bf != 0) { - test (); - if (sub (*gain_code, prev_gc) > 0) + if (sub (*gain_code, st->prev_gc) > 0) { - *gain_code = prev_gc; move16 (); + *gain_code = st->prev_gc; } } /*-------------------------------------------------------------------* @@ -425,27 +383,25 @@ for (i = 3; i > 0; i--) { - past_qua_en[i] = past_qua_en[i - 1]; move16 (); + st->past_qua_en[i] = st->past_qua_en[i - 1]; } Log2 (L_deposit_l (qua_gain_code[index]), &exp, &frac); - past_qua_en[0] = shr (frac, 5); move16 (); - past_qua_en[0] = add (past_qua_en[0], shl (sub (exp, 11), 10)); - move16 (); + st->past_qua_en[0] = shr (frac, 5); + st->past_qua_en[0] = add (st->past_qua_en[0], shl (sub (exp, 11), 10)); - update_gain_code_history_rx (*gain_code, gain_code_old_rx); + update_gain_code_history_rx (st, *gain_code); if (sub (i_subfr, (3 * L_SUBFR)) == 0) { - gain_code_old_CN = *gain_code; move16 (); + st->gain_code_old_CN = *gain_code; } } else { - test (); test (); logic16 (); if (((rxdtx_ctrl & RX_FIRST_SID_UPDATE) != 0) && (i_subfr == 0)) { - gain_code_new_CN = mult (gcode0_CN, qua_gain_code[index]); + st->gain_code_new_CN = mult (st->gcode0_CN, qua_gain_code[index]); /*---------------------------------------------------------------* * reset table of past quantized energies * @@ -454,37 +410,34 @@ for (i = 0; i < 4; i++) { - past_qua_en[i] = -2381; move16 (); + st->past_qua_en[i] = -2381; } } - test (); test (); logic16 (); if (((rxdtx_ctrl & RX_CONT_SID_UPDATE) != 0) && (i_subfr == 0)) { - gain_code_old_CN = gain_code_new_CN; move16 (); - gain_code_new_CN = mult (gcode0_CN, qua_gain_code[index]); - move16 (); + st->gain_code_old_CN = st->gain_code_new_CN; + st->gain_code_new_CN = mult (st->gcode0_CN, qua_gain_code[index]); } - test (); if (i_subfr == 0) { - *gain_code = interpolate_CN_param (gain_code_old_CN, - gain_code_new_CN, - rx_dtx_state); move16 (); + *gain_code = interpolate_CN_param (st->gain_code_old_CN, + st->gain_code_new_CN, + rx_dtx_state); } else { - *gain_code = prev_gc; move16 (); + *gain_code = st->prev_gc; } } - past_gain_code = *gain_code; move16 (); + st->past_gain_code = *gain_code; for (i = 1; i < 5; i++) { - gbuf[i - 1] = gbuf[i]; move16 (); + st->gbuf[i - 1] = st->gbuf[i]; } - gbuf[4] = past_gain_code; move16 (); - prev_gc = past_gain_code; move16 (); + st->gbuf[4] = st->past_gain_code; + st->prev_gc = st->past_gain_code; return; } diff -r d273a77d5523 -r a18782a7d270 libgsmefr/dtx.h --- a/libgsmefr/dtx.h Fri Nov 25 19:22:05 2022 +0000 +++ b/libgsmefr/dtx.h Fri Nov 25 20:19:30 2022 +0000 @@ -88,14 +88,12 @@ void update_gain_code_history_tx ( struct EFR_encoder_state *st, - Word16 new_gain_code, - Word16 gain_code_old_tx[4 * DTX_HANGOVER] + Word16 new_gain_code ); void update_gain_code_history_rx ( struct EFR_decoder_state *st, - Word16 new_gain_code, - Word16 gain_code_old_rx[4 * DTX_HANGOVER] + Word16 new_gain_code ); Word16 compute_CN_excitation_gain (