FreeCalypso > hg > gsm-codec-lib
view libgsmefr/e_homing.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 | 035424a6ca83 |
children |
line wrap: on
line source
/************************************************************************** * * File Name: e_homing.c * * Purpose: * This file contains the following functions: * * encoder_homing_frame_test() checks if a frame of input samples * matches the Encoder Homing Frame pattern. * * encoder_reset() called by reset_enc() to reset all * the state variables for the encoder. * * reset_enc() calls functions to reset the state * variables for the encoder and VAD, and * for the transmit DTX and Comfort Noise. * **************************************************************************/ #include "gsm_efr.h" #include "typedef.h" #include "namespace.h" #include "cnst.h" #include "vad.h" #include "dtx.h" #include "codec.h" #include "sig_proc.h" #include "memops.h" #include "enc_state.h" #include "e_homing.h" /*************************************************************************** * * FUNCTION NAME: encoder_homing_frame_test * * PURPOSE: * Checks if a frame of input samples matches the Encoder Homing Frame * pattern, which is 0x0008 for all 160 samples in the frame. * * INPUT: * input_frame[] one frame of speech samples * * OUTPUT: * None * * RETURN: * 0 input frame does not match the Encoder Homing Frame pattern. * 1 input frame matches the Encoder Homing Frame pattern. * **************************************************************************/ Word16 encoder_homing_frame_test (const Word16 input_frame[]) { Word16 i, j; for (i = 0; i < L_FRAME; i++) { j = input_frame[i] ^ EHF_MASK; if (j) break; } return !j; } /*************************************************************************** * * FUNCTION NAME: encoder_reset * * PURPOSE: * resets all of the state variables for the encoder * * INPUT: * None * * OUTPUT: * None * * RETURN: * None * **************************************************************************/ void encoder_reset (struct EFR_encoder_state *st) { Word16 i; /* reset all the encoder state variables */ /* ------------------------------------- */ /* Variables in cod_12k2.c: */ Init_Coder_12k2 (st); /* Variables in levinson.c: */ st->old_A[0] = 4096; /* Last A(z) for case of unstable filter */ for (i = 1; i < M + 1; i++) { st->old_A[i] = 0; } /* Variables in pre_proc.c: */ Init_Pre_Process (st); /* Variables in q_gains.c: */ for (i = 0; i < 4; i++) { st->past_qua_en[i] = -2381; /* past quantized energies */ } st->pred[0] = 44; /* MA prediction coeff */ st->pred[1] = 37; /* MA prediction coeff */ st->pred[2] = 22; /* MA prediction coeff */ st->pred[3] = 12; /* MA prediction coeff */ /* Variables in q_plsf_5.c: */ for (i = 0; i < M; i++) { st->past_r2_q[i] = 0; /* Past quantized prediction error */ } return; } /*************************************************************************** * * FUNCTION NAME: reset_enc * * PURPOSE: * resets all of the state variables for the encoder and VAD, and for * the transmit DTX and Comfort Noise. * * INPUT: * None * * OUTPUT: * None * * RETURN: * None * **************************************************************************/ void EFR_encoder_reset (struct EFR_encoder_state *st, int dtx) { st->dtx_mode = dtx; encoder_reset (st); /* reset all the state variables in the speech encoder*/ vad_reset (st); /* reset all the VAD state variables */ reset_tx_dtx (st); /* reset all the transmit DTX and CN variables */ return; }