annotate libtwamr/dtx_enc.c @ 468:4104b0390fab

efrtest: new program gsmefr-dlcap-sync
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 13 May 2024 07:21:09 +0000
parents 5a1d18542f8a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 ********************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 ********************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : dtx_enc.c
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : DTX mode computation of SID parameters
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 ********************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 /*
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 ********************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 * MODULE INCLUDE FILE AND VERSION ID
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 ********************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "namespace.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include "dtx_enc.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 /*
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 ********************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * INCLUDE FILES
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 ********************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "tw_amr.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "typedef.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "basic_op.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "oper_32b.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "q_plsf.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #include "memops.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #include "log2.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 #include "lsp_lsf.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 #include "reorder.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 #include "no_count.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 #include "lsp_tab.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 /*
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 ********************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 * PUBLIC PROGRAM CODE
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 ********************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 /*
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 **************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 * Function : dtx_enc_reset
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 **************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 void dtx_enc_reset (dtx_encState *st)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 Word16 i;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 st->hist_ptr = 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 st->log_en_index = 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 st->init_lsf_vq_index = 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 st->lsp_index[0] = 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 st->lsp_index[1] = 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 st->lsp_index[2] = 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 /* Init lsp_hist[] */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 for(i = 0; i < DTX_HIST_SIZE; i++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 Copy(lsp_init_data, &st->lsp_hist[i * M], M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 /* Reset energy history */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 Set_zero(st->log_en_hist, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 st->dtxHangoverCount = DTX_HANG_CONST;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 st->decAnaElapsedCount = 32767;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 /*
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 **************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 * Function : dtx_enc
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 **************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 int dtx_enc(dtx_encState *st, /* i/o : State struct */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 Word16 computeSidFlag, /* i : compute SID */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 Q_plsfState *qSt, /* i/o : Qunatizer state struct */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 gc_predState* predState, /* i/o : State struct */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 Word16 **anap /* o : analysis parameters */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 )
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 Word16 i,j;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 Word16 log_en;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 Word16 lsf[M];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 Word16 lsp[M];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 Word16 lsp_q[M];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 Word32 L_lsp[M];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 /* VOX mode computation of SID parameters */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 test (); test ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 if ((computeSidFlag != 0))
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 /* compute new SID frame if safe i.e don't
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 * compute immediately after a talk spurt */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 log_en = 0; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 for (i = 0; i < M; i++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 L_lsp[i] = 0; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 /* average energy and lsp */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 for (i = 0; i < DTX_HIST_SIZE; i++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 log_en = add(log_en,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 shr(st->log_en_hist[i],2));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 for (j = 0; j < M; j++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 L_lsp[j] = L_add(L_lsp[j],
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 L_deposit_l(st->lsp_hist[i * M + j]));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 log_en = shr(log_en, 1);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 for (j = 0; j < M; j++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 lsp[j] = extract_l(L_shr(L_lsp[j], 3)); /* divide by 8 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 /* quantize logarithmic energy to 6 bits */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 st->log_en_index = add(log_en, 2560); /* +2.5 in Q10 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 st->log_en_index = add(st->log_en_index, 128); /* add 0.5/4 in Q10 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 st->log_en_index = shr(st->log_en_index, 8);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 test ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 if (sub(st->log_en_index, 63) > 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 st->log_en_index = 63; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 test ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 if (st->log_en_index < 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 st->log_en_index = 0; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 /* update gain predictor memory */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 log_en = shl(st->log_en_index, -2+10); /* Q11 and divide by 4 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 log_en = sub(log_en, 2560); /* add 2.5 in Q11 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 log_en = sub(log_en, 9000);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 test ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 if (log_en > 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 log_en = 0; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 test ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 if (sub(log_en, -14436) < 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 log_en = -14436; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 /* past_qua_en for other modes than MR122 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 predState->past_qua_en[0] = log_en; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 predState->past_qua_en[1] = log_en; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 predState->past_qua_en[2] = log_en; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 predState->past_qua_en[3] = log_en; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 /* scale down by factor 20*log10(2) in Q15 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 log_en = mult(5443, log_en);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 /* past_qua_en for mode MR122 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 predState->past_qua_en_MR122[0] = log_en; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 predState->past_qua_en_MR122[1] = log_en; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 predState->past_qua_en_MR122[2] = log_en; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 predState->past_qua_en_MR122[3] = log_en; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 /* make sure that LSP's are ordered */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 Lsp_lsf(lsp, lsf, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 Reorder_lsf(lsf, LSF_GAP, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 Lsf_lsp(lsf, lsp, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 /* Quantize lsp and put on parameter list */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 Q_plsf_3(qSt, MRDTX, lsp, lsp_q, st->lsp_index,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 &st->init_lsf_vq_index);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 *(*anap)++ = st->init_lsf_vq_index; /* 3 bits */ move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 *(*anap)++ = st->lsp_index[0]; /* 8 bits */ move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 *(*anap)++ = st->lsp_index[1]; /* 9 bits */ move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 *(*anap)++ = st->lsp_index[2]; /* 9 bits */ move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 *(*anap)++ = st->log_en_index; /* 6 bits */ move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 /* = 35 bits */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 return 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 /*
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 **************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 * Function : dtx_buffer
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 * Purpose : handles the DTX buffer
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 **************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 int dtx_buffer(dtx_encState *st, /* i/o : State struct */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 Word16 lsp_new[], /* i : LSP vector */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 Word16 speech[] /* i : speech samples */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 )
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 Word16 i;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 Word32 L_frame_en;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 Word16 log_en_e;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 Word16 log_en_m;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 Word16 log_en;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 /* update pointer to circular buffer */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 st->hist_ptr = add(st->hist_ptr, 1);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 test ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 if (sub(st->hist_ptr, DTX_HIST_SIZE) == 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 st->hist_ptr = 0; move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 /* copy lsp vector into buffer */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 Copy(lsp_new, &st->lsp_hist[st->hist_ptr * M], M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 /* compute log energy based on frame energy */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 L_frame_en = 0; /* Q0 */ move32 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 for (i=0; i < L_FRAME; i++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 L_frame_en = L_mac(L_frame_en, speech[i], speech[i]);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 Log2(L_frame_en, &log_en_e, &log_en_m);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 /* convert exponent and mantissa to Word16 Q10 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 log_en = shl(log_en_e, 10); /* Q10 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 log_en = add(log_en, shr(log_en_m, 15-10));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 /* divide with L_FRAME i.e subtract with log2(L_FRAME) = 7.32193 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 log_en = sub(log_en, 8521);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 /* insert into log energy buffer with division by 2 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 log_en = shr(log_en, 1);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 st->log_en_hist[st->hist_ptr] = log_en; /* Q10 */ move16 ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 return 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 /*
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 **************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 * Function : tx_dtx_handler
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 * Purpose : adds extra speech hangover to analyze speech on the decoding side.
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 **************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 Word16 tx_dtx_handler(dtx_encState *st, /* i/o : State struct */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 Word16 vad_flag, /* i : vad decision */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 enum Mode *usedMode /* i/o : mode changed or not */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 )
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 Word16 compute_new_sid_possible;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 /* this state machine is in synch with the GSMEFR txDtx machine */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 st->decAnaElapsedCount = add(st->decAnaElapsedCount, 1);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 compute_new_sid_possible = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 if (vad_flag != 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 st->dtxHangoverCount = DTX_HANG_CONST; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 else
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 { /* non-speech */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 if (st->dtxHangoverCount == 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 { /* out of decoder analysis hangover */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 st->decAnaElapsedCount = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 *usedMode = MRDTX; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 compute_new_sid_possible = 1; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 else
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 { /* in possible analysis hangover */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 st->dtxHangoverCount = sub(st->dtxHangoverCount, 1);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 /* decAnaElapsedCount + dtxHangoverCount < DTX_ELAPSED_FRAMES_THRESH */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 test ();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 if (sub(add(st->decAnaElapsedCount, st->dtxHangoverCount),
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 DTX_ELAPSED_FRAMES_THRESH) < 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 *usedMode = MRDTX; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 /* if short time since decoder update, do not add extra HO */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 /*
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 else
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 override VAD and stay in
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 speech mode *usedMode
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 and add extra hangover
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 return compute_new_sid_possible;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 }