annotate libtwamr/dtx_dec.c @ 471:b5f8ea41362b

gsmrec-dump: report DHF matches
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 14 May 2024 07:25:06 +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_dec.c
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : Decode comfort noise when in DTX
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 * MODULE INCLUDE FILE AND VERSION ID
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 *****************************************************************************
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 #include "namespace.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "dtx_dec.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
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 * INCLUDE FILES
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 *****************************************************************************
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 #include "tw_amr.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "typedef.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "basic_op.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "oper_32b.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "memops.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "log2.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #include "lsp_az.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #include "pow2.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 #include "a_refl.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 #include "b_cn_cod.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 #include "syn_filt.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 #include "lsp_lsf.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 #include "reorder.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 #include "no_count.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 #include "q_plsf5_tab.h"
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 #include "lsp_tab.h"
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 * LOCAL VARIABLES AND TABLES
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 #define PN_INITIAL_SEED 0x70816958L /* Pseudo noise generator seed value */
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 * Scaling factors for the lsp variability operation *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 ***************************************************/
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 static const Word16 lsf_hist_mean_scale[M] = {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 20000,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 20000,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 20000,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 20000,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 20000,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 18000,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 16384,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 8192,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 0,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 0
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 };
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 /*************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 * level adjustment for different modes Q11 *
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 static const Word16 dtx_log_en_adjust[9] =
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 -1023, /* MR475 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 -878, /* MR515 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 -732, /* MR59 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 -586, /* MR67 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 -440, /* MR74 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 -294, /* MR795 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 -148, /* MR102 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 0, /* MR122 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 0, /* MRDTX */
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 *****************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 * PUBLIC PROGRAM CODE
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 *****************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89
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 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 * Function : dtx_dec_reset
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 **************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 void dtx_dec_reset (dtx_decState *st)
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 int i;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 st->since_last_sid = 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 st->true_sid_period_inv = (1 << 13);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 st->log_en = 3500;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 st->old_log_en = 3500;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 /* low level noise for better performance in DTX handover cases*/
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 st->L_pn_seed_rx = PN_INITIAL_SEED;
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 /* Initialize state->lsp [] and state->lsp_old [] */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 Copy(lsp_init_data, &st->lsp[0], M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 Copy(lsp_init_data, &st->lsp_old[0], M);
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 st->lsf_hist_ptr = 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 st->log_pg_mean = 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 st->log_en_hist_ptr = 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 /* initialize decoder lsf history */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 Copy(mean_lsf, &st->lsf_hist[0], M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 for (i = 1; i < DTX_HIST_SIZE; i++)
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 Copy(&st->lsf_hist[0], &st->lsf_hist[M*i], M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 Set_zero(st->lsf_hist_mean, M*DTX_HIST_SIZE);
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 /* initialize decoder log frame energy */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 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
129 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 st->log_en_hist[i] = st->log_en;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 st->log_en_adjust = 0;
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 st->dtxHangoverCount = DTX_HANG_CONST;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 st->decAnaElapsedCount = 32767;
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->sid_frame = 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 st->valid_data = 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 st->dtxHangoverAdded = 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 st->dtxGlobalState = DTX;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 st->data_updated = 0;
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 /*
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 **************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 * Function : dtx_dec
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 **************************************************************************
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 int dtx_dec(
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 dtx_decState *st, /* i/o : State struct */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 Word16 mem_syn[], /* i/o : AMR decoder state */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 D_plsfState* lsfState, /* i/o : decoder lsf states */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 gc_predState* predState, /* i/o : prediction states */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 Cb_gain_averageState* averState, /* i/o : CB gain average states */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 enum DTXStateType new_state, /* i : new DTX state */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 enum Mode mode, /* i : AMR mode */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 Word16 parm[], /* i : Vector of synthesis parameters */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 Word16 synth[], /* o : synthesised speech */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 Word16 A_t[] /* o : decoded LP filter in 4 subframes*/
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 )
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 Word16 log_en_index;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 Word16 i, j;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 Word16 int_fac;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 Word32 L_log_en_int;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 Word16 lsp_int[M];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 Word16 log_en_int_e;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 Word16 log_en_int_m;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 Word16 level;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 Word16 acoeff[M + 1];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 Word16 refl[M];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 Word16 pred_err;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 Word16 ex[L_SUBFR];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 Word16 ma_pred_init;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 Word16 log_pg_e, log_pg_m;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 Word16 log_pg;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 Flag negative;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 Word16 lsf_mean;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 Word32 L_lsf_mean;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 Word16 lsf_variab_index;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 Word16 lsf_variab_factor;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 Word16 lsf_int[M];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 Word16 lsf_int_variab[M];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 Word16 lsp_int_variab[M];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 Word16 acoeff_variab[M + 1];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 Word16 lsf[M];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 Word32 L_lsf[M];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 Word16 ptr;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 Word16 tmp_int_length;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195
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 /* This function is called if synthesis state is not SPEECH
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 * the globally passed inputs to this function are
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 * st->sid_frame
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 * st->valid_data
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 * st->dtxHangoverAdded
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 * new_state (SPEECH, DTX, DTX_MUTE)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 test(); test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 if ((st->dtxHangoverAdded != 0) &&
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 (st->sid_frame != 0))
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 /* sid_first after dtx hangover period */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 /* or sid_upd after dtxhangover */
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 /* set log_en_adjust to correct value */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 st->log_en_adjust = dtx_log_en_adjust[mode];
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 ptr = add(st->lsf_hist_ptr, M); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 if (sub(ptr, 80) == 0)
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 ptr = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 Copy( &st->lsf_hist[st->lsf_hist_ptr],&st->lsf_hist[ptr],M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 ptr = add(st->log_en_hist_ptr,1); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 if (sub(ptr, DTX_HIST_SIZE) == 0)
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 ptr = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 st->log_en_hist[ptr] = st->log_en_hist[st->log_en_hist_ptr]; /* Q11 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 /* compute mean log energy and lsp *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 * from decoded signal (SID_FIRST) */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 st->log_en = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 for (i = 0; i < M; i++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 L_lsf[i] = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 /* average energy and lsp */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 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
242 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 st->log_en = add(st->log_en,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 shr(st->log_en_hist[i],3));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 for (j = 0; j < M; j++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 L_lsf[j] = L_add(L_lsf[j],
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 L_deposit_l(st->lsf_hist[i * M + j]));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 }
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 for (j = 0; j < M; j++)
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 lsf[j] = extract_l(L_shr(L_lsf[j],3)); /* divide by 8 */ move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 Lsf_lsp(lsf, st->lsp, M);
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 /* make log_en speech coder mode independent */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 /* added again later before synthesis */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 st->log_en = sub(st->log_en, st->log_en_adjust);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 /* compute lsf variability vector */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 Copy(st->lsf_hist, st->lsf_hist_mean, 80);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 for (i = 0; i < M; i++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 L_lsf_mean = 0; move32();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 /* compute mean lsf */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 for (j = 0; j < 8; j++)
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 L_lsf_mean = L_add(L_lsf_mean,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 L_deposit_l(st->lsf_hist_mean[i+j*M]));
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
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 lsf_mean = extract_l(L_shr(L_lsf_mean, 3)); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 /* subtract mean and limit to within reasonable limits *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 * moreover the upper lsf's are attenuated */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 for (j = 0; j < 8; j++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 /* subtract mean */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 st->lsf_hist_mean[i+j*M] =
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 sub(st->lsf_hist_mean[i+j*M], lsf_mean);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 /* attenuate deviation from mean, especially for upper lsf's */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 st->lsf_hist_mean[i+j*M] =
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 mult(st->lsf_hist_mean[i+j*M], lsf_hist_mean_scale[i]);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 /* limit the deviation */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 if (st->lsf_hist_mean[i+j*M] < 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 negative = 1; move16();
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 else
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 negative = 0; move16();
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 st->lsf_hist_mean[i+j*M] = abs_s(st->lsf_hist_mean[i+j*M]);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 /* apply soft limit */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 if (sub(st->lsf_hist_mean[i+j*M], 655) > 0)
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 st->lsf_hist_mean[i+j*M] =
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 add(655, shr(sub(st->lsf_hist_mean[i+j*M], 655), 2));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309 /* apply hard limit */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311 if (sub(st->lsf_hist_mean[i+j*M], 1310) > 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 st->lsf_hist_mean[i+j*M] = 1310; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 if (negative != 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 st->lsf_hist_mean[i+j*M] = -st->lsf_hist_mean[i+j*M];move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 if (st->sid_frame != 0 )
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328 /* Set old SID parameters, always shift */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 /* even if there is no new valid_data */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 Copy(st->lsp, st->lsp_old, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 st->old_log_en = st->log_en; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 if (st->valid_data != 0 ) /* new data available (no CRC) */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336 /* Compute interpolation factor, since the division only works *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337 * for values of since_last_sid < 32 we have to limit the *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 * interpolation to 32 frames */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
339 tmp_int_length = st->since_last_sid; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340 st->since_last_sid = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
342 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343 if (sub(tmp_int_length, 32) > 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
345 tmp_int_length = 32; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
348 if (sub(tmp_int_length, 2) >= 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
349 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
350 move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
351 st->true_sid_period_inv = div_s(1 << 10, shl(tmp_int_length, 10));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
352 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353 else
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
354 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355 st->true_sid_period_inv = 1 << 14; /* 0.5 it Q15 */ move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
358 Init_D_plsf_3(lsfState, parm[0]); /* temporay initialization */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359 D_plsf_3(lsfState, MRDTX, 0, &parm[1], st->lsp);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
360 Set_zero(lsfState->past_r_q, M); /* reset for next speech frame */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
361
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
362 log_en_index = parm[4]; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
363 /* Q11 and divide by 4 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
364 st->log_en = shl(log_en_index, (11 - 2)); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
365
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
366 /* Subtract 2.5 in Q11 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
367 st->log_en = sub(st->log_en, (2560 * 2));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
368
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
369 /* Index 0 is reserved for silence */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
370 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
371 if (log_en_index == 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
372 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
373 st->log_en = MIN_16; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
374 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
375
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
376 /* no interpolation at startup after coder reset */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
377 /* or when SID_UPD has been received right after SPEECH */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
378 test(); test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
379 if ((st->data_updated == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
380 (sub(st->dtxGlobalState, SPEECH) == 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
381 )
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
382 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
383 Copy(st->lsp, st->lsp_old, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
384 st->old_log_en = st->log_en; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
385 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
386 } /* endif valid_data */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
387
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
388 /* initialize gain predictor memory of other modes */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
389 ma_pred_init = sub(shr(st->log_en,1), 9000); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
390 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
391 if (ma_pred_init > 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
392 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
393 ma_pred_init = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
394 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
395 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
396 if (sub(ma_pred_init, -14436) < 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
397 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
398 ma_pred_init = -14436; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
399 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
400
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
401 predState->past_qua_en[0] = ma_pred_init; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
402 predState->past_qua_en[1] = ma_pred_init; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
403 predState->past_qua_en[2] = ma_pred_init; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
404 predState->past_qua_en[3] = ma_pred_init; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
405
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
406 /* 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
407 ma_pred_init = mult(5443, ma_pred_init);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
408 /* 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
409 predState->past_qua_en_MR122[0] = ma_pred_init; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
410 predState->past_qua_en_MR122[1] = ma_pred_init; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
411 predState->past_qua_en_MR122[2] = ma_pred_init; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
412 predState->past_qua_en_MR122[3] = ma_pred_init; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
413 } /* endif sid_frame */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
414
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
415 /* CN generation */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
416 /* recompute level adjustment factor Q11 *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
417 * st->log_en_adjust = 0.9*st->log_en_adjust + *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
418 * 0.1*dtx_log_en_adjust[mode]); */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
419 move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
420 st->log_en_adjust = add(mult(st->log_en_adjust, 29491),
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
421 shr(mult(shl(dtx_log_en_adjust[mode],5),3277),5));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
422
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
423 /* Interpolate SID info */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
424 int_fac = shl(add(1,st->since_last_sid), 10); /* Q10 */ move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
425 int_fac = mult(int_fac, st->true_sid_period_inv); /* Q10 * Q15 -> Q10 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
426
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
427 /* Maximize to 1.0 in Q10 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
428 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
429 if (sub(int_fac, 1024) > 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
430 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
431 int_fac = 1024; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
432 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
433 int_fac = shl(int_fac, 4); /* Q10 -> Q14 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
434
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
435 L_log_en_int = L_mult(int_fac, st->log_en); /* Q14 * Q11->Q26 */ move32();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
436 for(i = 0; i < M; i++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
437 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
438 lsp_int[i] = mult(int_fac, st->lsp[i]);/* Q14 * Q15 -> Q14 */ move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
439 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
440
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
441 int_fac = sub(16384, int_fac); /* 1-k in Q14 */ move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
442
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
443 /* (Q14 * Q11 -> Q26) + Q26 -> Q26 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
444 L_log_en_int = L_mac(L_log_en_int, int_fac, st->old_log_en);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
445 for(i = 0; i < M; i++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
446 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
447 /* Q14 + (Q14 * Q15 -> Q14) -> Q14 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
448 lsp_int[i] = add(lsp_int[i], mult(int_fac, st->lsp_old[i])); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
449 lsp_int[i] = shl(lsp_int[i], 1); /* Q14 -> Q15 */ move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
450 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
451
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
452 /* compute the amount of lsf variability */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
453 lsf_variab_factor = sub(st->log_pg_mean,2457); /* -0.6 in Q12 */ move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
454 /* *0.3 Q12*Q15 -> Q12 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
455 lsf_variab_factor = sub(4096, mult(lsf_variab_factor, 9830));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
456
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
457 /* limit to values between 0..1 in Q12 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
458 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
459 if (sub(lsf_variab_factor, 4096) > 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
460 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
461 lsf_variab_factor = 4096; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
462 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
463 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
464 if (lsf_variab_factor < 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
465 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
466 lsf_variab_factor = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
467 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
468 lsf_variab_factor = shl(lsf_variab_factor, 3); /* -> Q15 */ move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
469
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
470 /* get index of vector to do variability with */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
471 lsf_variab_index = pseudonoise(&st->L_pn_seed_rx, 3); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
472
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
473 /* convert to lsf */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
474 Lsp_lsf(lsp_int, lsf_int, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
475
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
476 /* apply lsf variability */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
477 Copy(lsf_int, lsf_int_variab, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
478 for(i = 0; i < M; i++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
479 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
480 move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
481 lsf_int_variab[i] = add(lsf_int_variab[i],
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
482 mult(lsf_variab_factor,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
483 st->lsf_hist_mean[i+lsf_variab_index*M]));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
484 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
485
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
486 /* 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
487 Reorder_lsf(lsf_int, LSF_GAP, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
488 Reorder_lsf(lsf_int_variab, LSF_GAP, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
489
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
490 /* copy lsf to speech decoders lsf state */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
491 Copy(lsf_int, lsfState->past_lsf_q, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
492
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
493 /* convert to lsp */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
494 Lsf_lsp(lsf_int, lsp_int, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
495 Lsf_lsp(lsf_int_variab, lsp_int_variab, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
496
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
497 /* Compute acoeffs Q12 acoeff is used for level *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
498 * normalization and postfilter, acoeff_variab is *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
499 * used for synthesis filter *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
500 * by doing this we make sure that the level *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
501 * in high frequenncies does not jump up and down */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
502
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
503 Lsp_Az(lsp_int, acoeff);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
504 Lsp_Az(lsp_int_variab, acoeff_variab);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
505
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
506 /* For use in postfilter */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
507 Copy(acoeff, &A_t[0], M + 1);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
508 Copy(acoeff, &A_t[M + 1], M + 1);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
509 Copy(acoeff, &A_t[2 * (M + 1)], M + 1);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
510 Copy(acoeff, &A_t[3 * (M + 1)], M + 1);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
511
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
512 /* Compute reflection coefficients Q15 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
513 A_Refl(&acoeff[1], refl);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
514
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
515 /* Compute prediction error in Q15 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
516 pred_err = MAX_16; /* 0.99997 in Q15 */ move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
517 for (i = 0; i < M; i++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
518 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
519 pred_err = mult(pred_err, sub(MAX_16, mult(refl[i], refl[i])));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
520 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
521
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
522 /* compute logarithm of prediction gain */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
523 Log2(L_deposit_l(pred_err), &log_pg_e, &log_pg_m);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
524
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
525 /* convert exponent and mantissa to Word16 Q12 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
526 log_pg = shl(sub(log_pg_e,15), 12); /* Q12 */ move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
527 log_pg = shr(sub(0,add(log_pg, shr(log_pg_m, 15-12))), 1); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
528 st->log_pg_mean = add(mult(29491,st->log_pg_mean),
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
529 mult(3277, log_pg)); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
530
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
531 /* Compute interpolated log energy */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
532 L_log_en_int = L_shr(L_log_en_int, 10); /* Q26 -> Q16 */ move32();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
533
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
534 /* Add 4 in Q16 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
535 L_log_en_int = L_add(L_log_en_int, 4 * 65536L); move32();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
536
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
537 /* subtract prediction gain */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
538 L_log_en_int = L_sub(L_log_en_int, L_shl(L_deposit_l(log_pg), 4));move32();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
539
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
540 /* adjust level to speech coder mode */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
541 L_log_en_int = L_add(L_log_en_int,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
542 L_shl(L_deposit_l(st->log_en_adjust), 5)); move32();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
543
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
544 log_en_int_e = extract_h(L_log_en_int); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
545 move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
546 log_en_int_m = extract_l(L_shr(L_sub(L_log_en_int,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
547 L_deposit_h(log_en_int_e)), 1));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
548 level = extract_l(Pow2(log_en_int_e, log_en_int_m)); /* Q4 */ move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
549
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
550 for (i = 0; i < 4; i++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
551 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
552 /* Compute innovation vector */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
553 build_CN_code(&st->L_pn_seed_rx, ex);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
554 for (j = 0; j < L_SUBFR; j++)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
555 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
556 ex[j] = mult(level, ex[j]); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
557 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
558 /* Synthesize */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
559 Syn_filt(acoeff_variab, ex, &synth[i * L_SUBFR], L_SUBFR,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
560 mem_syn, 1);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
561
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
562 } /* next i */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
563
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
564 /* reset codebook averaging variables */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
565 averState->hangVar = 20; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
566 averState->hangCount = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
567
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
568 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
569 if (sub(new_state, DTX_MUTE) == 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
570 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
571 /* mute comfort noise as it has been quite a long time since
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
572 * last SID update was performed */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
573
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
574 tmp_int_length = st->since_last_sid; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
575 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
576 if (sub(tmp_int_length, 32) > 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
577 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
578 tmp_int_length = 32; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
579 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
580
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
581 /* safety guard against division by zero */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
582 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
583 if(tmp_int_length <= 0) {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
584 tmp_int_length = 8; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
585 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
586
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
587 move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
588 st->true_sid_period_inv = div_s(1 << 10, shl(tmp_int_length, 10));
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
589
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
590 st->since_last_sid = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
591 Copy(st->lsp, st->lsp_old, M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
592 st->old_log_en = st->log_en; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
593 /* subtract 1/8 in Q11 i.e -6/8 dB */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
594 st->log_en = sub(st->log_en, 256); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
595 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
596
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
597 /* reset interpolation length timer
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
598 * if data has been updated. */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
599 test(); test(); test(); test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
600 if ((st->sid_frame != 0) &&
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
601 ((st->valid_data != 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
602 ((st->valid_data == 0) && (st->dtxHangoverAdded) != 0)))
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
603 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
604 st->since_last_sid = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
605 st->data_updated = 1; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
606 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
607
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
608 return 0;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
609 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
610
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
611 void dtx_dec_activity_update(dtx_decState *st,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
612 Word16 lsf[],
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
613 Word16 frame[])
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
614 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
615 Word16 i;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
616
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
617 Word32 L_frame_en;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
618 Word16 log_en_e, log_en_m, log_en;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
619
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
620 /* update lsp history */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
621 st->lsf_hist_ptr = add(st->lsf_hist_ptr,M); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
622 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
623 if (sub(st->lsf_hist_ptr, 80) == 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
624 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
625 st->lsf_hist_ptr = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
626 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
627 Copy(lsf, &st->lsf_hist[st->lsf_hist_ptr], M);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
628
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
629 /* 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
630 L_frame_en = 0; /* Q0 */ move32();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
631 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
632 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
633 L_frame_en = L_mac(L_frame_en, frame[i], frame[i]);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
634 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
635 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
636
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
637 /* 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
638 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
639 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
640
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
641 /* 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
642 log_en = sub(log_en, 7497+1024);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
643
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
644 /* insert into log energy buffer, no division by two as *
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
645 * log_en in decoder is Q11 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
646 st->log_en_hist_ptr = add(st->log_en_hist_ptr, 1);
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
647 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
648 if (sub(st->log_en_hist_ptr, DTX_HIST_SIZE) == 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
649 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
650 st->log_en_hist_ptr = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
651 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
652 st->log_en_hist[st->log_en_hist_ptr] = log_en; /* Q11 */ move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
653 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
654
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
655 /*
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
656 Table of new SPD synthesis states
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
657
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
658 | previous SPD_synthesis_state
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
659 Incoming |
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
660 frame_type | SPEECH | DTX | DTX_MUTE
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
661 ---------------------------------------------------------------
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
662 RX_SPEECH_GOOD , | | |
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
663 RX_SPEECH_PR_DEGRADED | SPEECH | SPEECH | SPEECH
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
664 ----------------------------------------------------------------
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
665 RX_SPEECH_BAD, | SPEECH | DTX | DTX_MUTE
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
666 ----------------------------------------------------------------
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
667 RX_SID_FIRST, | DTX | DTX/(DTX_MUTE)| DTX_MUTE
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
668 ----------------------------------------------------------------
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
669 RX_SID_UPDATE, | DTX | DTX | DTX
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
670 ----------------------------------------------------------------
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
671 RX_SID_BAD, | DTX | DTX/(DTX_MUTE)| DTX_MUTE
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
672 ----------------------------------------------------------------
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
673 RX_NO_DATA | SPEECH | DTX/(DTX_MUTE)| DTX_MUTE
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
674 |(class2 garb.)| |
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
675 ----------------------------------------------------------------
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
676 RX_ONSET | SPEECH | DTX/(DTX_MUTE)| DTX_MUTE
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
677 |(class2 garb.)| |
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
678 ----------------------------------------------------------------
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
679 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
680
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
681 enum DTXStateType rx_dtx_handler(
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
682 dtx_decState *st, /* i/o : State struct */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
683 enum RXFrameType frame_type /* i : Frame type */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
684 )
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
685 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
686 enum DTXStateType newState;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
687 enum DTXStateType encState;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
688
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
689 /* DTX if SID frame or previously in DTX{_MUTE} and (NO_RX OR BAD_SPEECH) */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
690 test(); test(); test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
691 test(); test(); test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
692 test(); test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
693 if ((sub(frame_type, RX_SID_FIRST) == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
694 (sub(frame_type, RX_SID_UPDATE) == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
695 (sub(frame_type, RX_SID_BAD) == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
696 (((sub(st->dtxGlobalState, DTX) == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
697 (sub(st->dtxGlobalState, DTX_MUTE) == 0)) &&
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
698 ((sub(frame_type, RX_NO_DATA) == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
699 (sub(frame_type, RX_SPEECH_BAD) == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
700 (sub(frame_type, RX_ONSET) == 0))))
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
701 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
702 newState = DTX; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
703
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
704 /* stay in mute for these input types */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
705 test(); test(); test(); test(); test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
706 if ((sub(st->dtxGlobalState, DTX_MUTE) == 0) &&
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
707 ((sub(frame_type, RX_SID_BAD) == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
708 (sub(frame_type, RX_SID_FIRST) == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
709 (sub(frame_type, RX_ONSET) == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
710 (sub(frame_type, RX_NO_DATA) == 0)))
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
711 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
712 newState = DTX_MUTE; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
713 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
714
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
715 /* evaluate if noise parameters are too old */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
716 /* since_last_sid is reset when CN parameters have been updated */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
717 st->since_last_sid = add(st->since_last_sid, 1); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
718
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
719 /* no update of sid parameters in DTX for a long while */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
720 /* Due to the delayed update of st->since_last_sid counter
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
721 SID_UPDATE frames need to be handled separately to avoid
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
722 entering DTX_MUTE for late SID_UPDATE frames
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
723 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
724 test(); test(); logic16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
725 if((sub(frame_type, RX_SID_UPDATE) != 0) &&
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
726 (sub(st->since_last_sid, DTX_MAX_EMPTY_THRESH) > 0))
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
727 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
728 newState = DTX_MUTE; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
729 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
730 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
731 else
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
732 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
733 newState = SPEECH; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
734 st->since_last_sid = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
735 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
736
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
737 /*
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
738 reset the decAnaElapsed Counter when receiving CNI data the first
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
739 time, to robustify counter missmatch after handover
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
740 this might delay the bwd CNI analysis in the new decoder slightly.
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
741 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
742 test(); test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
743 if ((st->data_updated == 0) &&
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
744 (sub(frame_type, RX_SID_UPDATE) == 0))
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
745 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
746 st->decAnaElapsedCount = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
747 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
748
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
749 /* update the SPE-SPD DTX hangover synchronization */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
750 /* to know when SPE has added dtx hangover */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
751 st->decAnaElapsedCount = add(st->decAnaElapsedCount, 1); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
752 st->dtxHangoverAdded = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
753
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
754 test(); test(); test(); test(); test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
755 if ((sub(frame_type, RX_SID_FIRST) == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
756 (sub(frame_type, RX_SID_UPDATE) == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
757 (sub(frame_type, RX_SID_BAD) == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
758 (sub(frame_type, RX_ONSET) == 0) ||
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
759 (sub(frame_type, RX_NO_DATA) == 0))
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
760 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
761 encState = DTX; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
762
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
763 /*
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
764 In frame errors simulations RX_NO_DATA may occasionally mean that
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
765 a speech packet was probably sent by the encoder,
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
766 the assumed _encoder_ state should be SPEECH in such cases.
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
767 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
768
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
769 test(); logic16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
770 if((sub(frame_type, RX_NO_DATA) == 0) &&
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
771 (sub(newState, SPEECH) == 0))
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
772 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
773 encState = SPEECH; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
774 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
775
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
776
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
777 /* Note on RX_ONSET operation differing from RX_NO_DATA operation:
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
778 If a RX_ONSET is received in the decoder (by "accident")
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
779 it is still most likely that the encoder state
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
780 for the "ONSET frame" was DTX.
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
781 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
782 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
783 else
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
784 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
785 encState = SPEECH; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
786 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
787
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
788 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
789 if (sub(encState, SPEECH) == 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
790 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
791 st->dtxHangoverCount = DTX_HANG_CONST; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
792 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
793 else
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
794 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
795 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
796 if (sub(st->decAnaElapsedCount, DTX_ELAPSED_FRAMES_THRESH) > 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
797 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
798 st->dtxHangoverAdded = 1; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
799 st->decAnaElapsedCount = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
800 st->dtxHangoverCount = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
801 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
802 else if (test(), st->dtxHangoverCount == 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
803 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
804 st->decAnaElapsedCount = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
805 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
806 else
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
807 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
808 st->dtxHangoverCount = sub(st->dtxHangoverCount, 1); move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
809 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
810 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
811
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
812 if (sub(newState, SPEECH) != 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
813 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
814 /* DTX or DTX_MUTE
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
815 * CN data is not in a first SID, first SIDs are marked as SID_BAD
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
816 * but will do backwards analysis if a hangover period has been added
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
817 * according to the state machine above
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
818 */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
819
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
820 st->sid_frame = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
821 st->valid_data = 0; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
822
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
823 test();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
824 if (sub(frame_type, RX_SID_FIRST) == 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
825 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
826 st->sid_frame = 1; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
827 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
828 else if (test(), sub(frame_type, RX_SID_UPDATE) == 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
829 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
830 st->sid_frame = 1; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
831 st->valid_data = 1; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
832 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
833 else if (test(), sub(frame_type, RX_SID_BAD) == 0)
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
834 {
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
835 st->sid_frame = 1; move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
836 st->dtxHangoverAdded = 0; /* use old data */ move16();
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
837 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
838 }
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
839
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
840 return newState;
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
841 /* newState is used by both SPEECH AND DTX synthesis routines */
5a1d18542f8a libtwamr: integrate dtx_dec.c and dtx_enc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
842 }