-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplc.c
142 lines (118 loc) · 6.18 KB
/
plc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*****************************************************************************/
/* BroadVoice(R)16 (BV16) Floating-Point ANSI-C Source Code */
/* Revision Date: October 5, 2012 */
/* Version 1.2 */
/*****************************************************************************/
/*****************************************************************************/
/* Copyright 2000-2012 Broadcom Corporation */
/* */
/* This software is provided under the GNU Lesser General Public License, */
/* version 2.1, as published by the Free Software Foundation ("LGPL"). */
/* This program is distributed in the hope that it will be useful, but */
/* WITHOUT ANY SUPPORT OR WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the LGPL for */
/* more details. A copy of the LGPL is available at */
/* http://www.broadcom.com/licenses/LGPLv2.1.php, */
/* or by writing to the Free Software Foundation, Inc., */
/* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*****************************************************************************/
/*****************************************************************************
plc.c : Packet Loss Concealment
$Log$
******************************************************************************/
#include <math.h>
#include "typedef.h"
#include "bv16cnst.h"
#include "bvcommon.h"
#include "bv16strct.h"
#include "bv16externs.h"
#include "utility.h"
#include "postfilt.h"
extern void BV16_PLC(
struct BV16_Decoder_State *ds,
short *out){
int n;
Float r[FRSZ]; /* random excitation */
Float E, gain, scplcg;
Float xq[LXQ];
Float s[FRSZ]; /* enhanced short-term excitation */
Float d[LTMOFF+FRSZ]; /* long-term synthesis filter memory */
Float *sq;
/************************************************************/
/* Copy decoder state memory */
/************************************************************/
Fcopy(d, ds->ltsym, LTMOFF); /* excitation */
Fcopy(xq, ds->xq, XQOFF);
sq = xq+XQOFF;
/************************************************************/
/* Update counter of consecutive list frames */
/************************************************************/
if(ds->cfecount < HoldPLCG+AttnPLCG-1)
ds->cfecount++;
ds->ngfae = 0;
/************************************************************/
/* Generate Unscaled Excitation */
/************************************************************/
E = 0.0;
for(n=0; n<FRSZ; n++){
ds->idum = 1664525L*ds->idum + 1013904223L;
r[n] = (Float)(ds->idum >> 16) - 32767.0;
E += r[n] * r[n];
}
/************************************************************/
/* Calculate Scaling */
/************************************************************/
scplcg = ScPLCG_a + ScPLCG_b * ds->per;
if(scplcg > ScPLCGmax)
scplcg = ScPLCGmax;
else if(scplcg < ScPLCGmin)
scplcg = ScPLCGmin;
gain = scplcg * sqrt(ds->E/E);
/************************************************************/
/* Long-term synthesis filter */
/************************************************************/
for(n=0; n<FRSZ; n++){
d[LTMOFF+n] = gain * r[n];
d[LTMOFF+n] += ds->bq_last[0] * d[LTMOFF+n-ds->pp_last+1];
d[LTMOFF+n] += ds->bq_last[1] * d[LTMOFF+n-ds->pp_last];
d[LTMOFF+n] += ds->bq_last[2] * d[LTMOFF+n-ds->pp_last-1];
}
/************************************************************/
/* Short-term synthesis filter */
/************************************************************/
apfilter(ds->atplc, LPCO, d+LTMOFF, sq, FRSZ, ds->stsym, 1);
/************************************************************/
/* Save decoder state memory */
/************************************************************/
Fcopy(ds->ltsym, d+FRSZ, LTMOFF); /* excitation */
/************************************************************/
/* Update memory of predictive LSP quantizer */
/************************************************************/
lspplc(ds->lsplast,ds->lsppm);
/************************************************************/
/* Update memory of predictive gain quantizer */
/************************************************************/
gainplc(ds->E, ds->lgpm, ds->prevlg);
/************************************************************/
/* Signal level estimation */
/************************************************************/
estlevel(ds->prevlg[0],&ds->level,&ds->lmax,&ds->lmin,&ds->lmean,
&ds->x1,ds->ngfae,ds->nggalgc,&ds->estl_alpha_min);
/************************************************************/
/* Attenuation during long packet losses */
/************************************************************/
if(ds->cfecount >= HoldPLCG){
gain = 1.0 - AttnFacPLCG * (Float)(ds->cfecount - (HoldPLCG-1));
ds->bq_last[0] = gain * ds->bq_last[0];
ds->bq_last[1] = gain * ds->bq_last[1];
ds->bq_last[2] = gain * ds->bq_last[2];
ds->E = (gain * gain) * ds->E;
}
/************************************************************/
/* Adaptive Postfiltering */
/************************************************************/
postfilter(xq, ds->pp_last, &(ds->ma_a), ds->b_prv, &(ds->pp_prv), s);
F2s(out, s, FRSZ);
Fcopy(ds->xq, xq+FRSZ, XQOFF);
return;
}