annotate libtwamr/bgnscd.c @ 499:446a4a2955ba

libgsmhr1/typedefs.h: initial port
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 19 Jun 2024 00:50:29 +0000
parents 8dfb7cbe6b59
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
308
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*************************************************************************
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 *
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * R99 Version 3.3.0
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * REL-4 Version 4.1.0
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 *
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 ********************************************************************************
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 *
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 * File : bgnscd.c
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * Purpose : Background noise source charateristic detector (SCD)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 *
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 ********************************************************************************
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 /*
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 ********************************************************************************
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 * MODULE INCLUDE FILE AND VERSION ID
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 ********************************************************************************
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "namespace.h"
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "bgnscd.h"
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 #include "typedef.h"
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 #include "basic_op.h"
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 #include "no_count.h"
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 #include "cnst.h"
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 #include "memops.h"
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 #include "gmed_n.h"
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "sqrt_l.h"
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 /*
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 ********************************************************************************
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 * LOCAL VARIABLES AND TABLES
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 ********************************************************************************
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 /*-----------------------------------------------------------------*
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 * Decoder constant parameters (defined in "cnst.h") *
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 *-----------------------------------------------------------------*
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 * L_FRAME : Frame size. *
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 * L_SUBFR : Sub-frame size. *
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 *-----------------------------------------------------------------*/
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 /*
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 ********************************************************************************
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 * PUBLIC PROGRAM CODE
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 ********************************************************************************
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 /*
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 **************************************************************************
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 *
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 * Function : Bgn_scd_reset
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 * Purpose : Resets state memory
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 *
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 **************************************************************************
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 void Bgn_scd_reset (Bgn_scdState *state)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 /* Static vectors to zero */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 Set_zero (state->frameEnergyHist, L_ENERGYHIST);
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 /* Initialize hangover handling */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 state->bgHangover = 0;
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 /*
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 **************************************************************************
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 *
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 * Function : Bgn_scd
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 * Purpose : Charaterice synthesis speech and detect background noise
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 * Returns : background noise decision; 0 = no bgn, 1 = bgn
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 *
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 **************************************************************************
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 Word16 Bgn_scd (Bgn_scdState *st, /* i : State variables for bgn SCD */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 Word16 ltpGainHist[], /* i : LTP gain history */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 Word16 speech[], /* o : synthesis speech frame */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 Word16 *voicedHangover /* o : # of frames after last
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 voiced frame */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 )
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 Word16 i;
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 Word16 prevVoiced, inbgNoise;
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 Word16 temp;
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 Word16 ltpLimit, frameEnergyMin;
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 Word16 currEnergy, noiseFloor, maxEnergy, maxEnergyLastPart;
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 Word32 s;
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 /* Update the inBackgroundNoise flag (valid for use in next frame if BFI) */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 /* it now works as a energy detector floating on top */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 /* not as good as a VAD. */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 currEnergy = 0; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 s = (Word32) 0; move32 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 for (i = 0; i < L_FRAME; i++)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 s = L_mac (s, speech[i], speech[i]);
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 s = L_shl(s, 2);
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 currEnergy = extract_h (s);
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 frameEnergyMin = 32767; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 for (i = 0; i < L_ENERGYHIST; i++)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 test ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 if (sub(st->frameEnergyHist[i], frameEnergyMin) < 0)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 frameEnergyMin = st->frameEnergyHist[i]; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 noiseFloor = shl (frameEnergyMin, 4); /* Frame Energy Margin of 16 */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 maxEnergy = st->frameEnergyHist[0]; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 for (i = 1; i < L_ENERGYHIST-4; i++)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 test ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 if ( sub (maxEnergy, st->frameEnergyHist[i]) < 0)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 maxEnergy = st->frameEnergyHist[i]; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 maxEnergyLastPart = st->frameEnergyHist[2*L_ENERGYHIST/3]; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 for (i = 2*L_ENERGYHIST/3+1; i < L_ENERGYHIST; i++)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 test ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 if ( sub (maxEnergyLastPart, st->frameEnergyHist[i] ) < 0)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 maxEnergyLastPart = st->frameEnergyHist[i]; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 inbgNoise = 0; /* false */ move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 /* Do not consider silence as noise */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 /* Do not consider continuous high volume as noise */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 /* Or if the current noise level is very low */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 /* Mark as noise if under current noise limit */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 /* OR if the maximum energy is below the upper limit */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 test (); test (); test (); test (); test ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 if ( (sub(maxEnergy, LOWERNOISELIMIT) > 0) &&
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 (sub(currEnergy, FRAMEENERGYLIMIT) < 0) &&
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 (sub(currEnergy, LOWERNOISELIMIT) > 0) &&
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 ( (sub(currEnergy, noiseFloor) < 0) ||
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 (sub(maxEnergyLastPart, UPPERNOISELIMIT) < 0)))
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 test ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 if (sub(add(st->bgHangover, 1), 30) > 0)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 st->bgHangover = 30; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 } else
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 st->bgHangover = add(st->bgHangover, 1);
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 else
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 st->bgHangover = 0; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 /* make final decision about frame state , act somewhat cautiosly */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 test ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 if (sub(st->bgHangover,1) > 0)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 inbgNoise = 1; /* true */ move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 for (i = 0; i < L_ENERGYHIST-1; i++)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 st->frameEnergyHist[i] = st->frameEnergyHist[i+1]; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 st->frameEnergyHist[L_ENERGYHIST-1] = currEnergy; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 /* prepare for voicing decision; tighten the threshold after some
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 time in noise */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 ltpLimit = 13926; /* 0.85 Q14 */ move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 test ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 if (sub(st->bgHangover, 8) > 0)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 ltpLimit = 15565; /* 0.95 Q14 */ move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 test ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 if (sub(st->bgHangover, 15) > 0)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 ltpLimit = 16383; /* 1.00 Q14 */ move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 /* weak sort of voicing indication. */
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 prevVoiced = 0; /* false */ move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 test ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 if (sub(gmed_n(&ltpGainHist[4], 5), ltpLimit) > 0)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 prevVoiced = 1; /* true */ move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 test ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 if (sub(st->bgHangover, 20) > 0) {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 if (sub(gmed_n(ltpGainHist, 9), ltpLimit) > 0)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 prevVoiced = 1; /* true */ move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 else
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 prevVoiced = 0; /* false */ move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 test ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 if (prevVoiced)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 *voicedHangover = 0; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 else
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 temp = add(*voicedHangover, 1);
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 test ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 if (sub(temp, 10) > 0)
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 *voicedHangover = 10; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 else
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 {
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 *voicedHangover = temp; move16 ();
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 }
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 return inbgNoise;
8dfb7cbe6b59 libtwamr: integrated up to bgnscd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 }