1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
23 Available from http://www.3gpp.org
25 (C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26 Permission to distribute, modify and use this file under the standard license
27 terms listed above has been obtained from the copyright holder.
28 ****************************************************************************************/
30 ------------------------------------------------------------------------------
34 Filename: phase_dispersion.cpp
36 ------------------------------------------------------------------------------
37 INPUT AND OUTPUT DEFINITIONS
39 int16 gain_code, (i) Q0 : gain of code
40 int16 gain_pit, (i) Q14 : gain of pitch
41 int16 code[], (i/o) : code vector
42 int16 mode, (i) : level, 0=hi, 1=lo, 2=off
43 int16 disp_mem[], (i/o) : static memory (size = 8)
46 ------------------------------------------------------------------------------
49 post-processing to enhance noise in low bit rate.
51 ------------------------------------------------------------------------------
55 ------------------------------------------------------------------------------
58 ------------------------------------------------------------------------------
61 ------------------------------------------------------------------------------
65 /*----------------------------------------------------------------------------
67 ----------------------------------------------------------------------------*/
69 #include "pv_amr_wb_type_defs.h"
70 #include "pvamrwbdecoder_basic_op.h"
71 #include "pvamrwbdecoder_cnst.h"
72 #include "pvamrwbdecoder_mem_funcs.h"
73 #include "pvamrwbdecoder_acelp.h"
74 #include "pvamrwb_math_op.h"
77 /*----------------------------------------------------------------------------
79 ; Define module specific macros here
80 ----------------------------------------------------------------------------*/
83 /*----------------------------------------------------------------------------
85 ; Include all pre-processor statements here. Include conditional
86 ; compile variables also.
87 ----------------------------------------------------------------------------*/
88 #define pitch_0_9 14746 /* 0.9 in Q14 */
89 #define pitch_0_6 9830 /* 0.6 in Q14 */
92 /*----------------------------------------------------------------------------
93 ; LOCAL FUNCTION DEFINITIONS
94 ; Function Prototype declaration
95 ----------------------------------------------------------------------------*/
97 /*----------------------------------------------------------------------------
98 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
99 ; Variable declaration - defined here and used outside this module
100 ----------------------------------------------------------------------------*/
101 /* impulse response with phase dispersion */
103 /* 2.0 - 6.4 kHz phase dispersion */
104 static const int16 ph_imp_low[L_SUBFR] =
106 20182, 9693, 3270, -3437, 2864, -5240, 1589, -1357,
107 600, 3893, -1497, -698, 1203, -5249, 1199, 5371,
108 -1488, -705, -2887, 1976, 898, 721, -3876, 4227,
109 -5112, 6400, -1032, -4725, 4093, -4352, 3205, 2130,
110 -1996, -1835, 2648, -1786, -406, 573, 2484, -3608,
111 3139, -1363, -2566, 3808, -639, -2051, -541, 2376,
112 3932, -6262, 1432, -3601, 4889, 370, 567, -1163,
113 -2854, 1914, 39, -2418, 3454, 2975, -4021, 3431
116 /* 3.2 - 6.4 kHz phase dispersion */
117 static const int16 ph_imp_mid[L_SUBFR] =
119 24098, 10460, -5263, -763, 2048, -927, 1753, -3323,
120 2212, 652, -2146, 2487, -3539, 4109, -2107, -374,
121 -626, 4270, -5485, 2235, 1858, -2769, 744, 1140,
122 -763, -1615, 4060, -4574, 2982, -1163, 731, -1098,
123 803, 167, -714, 606, -560, 639, 43, -1766,
124 3228, -2782, 665, 763, 233, -2002, 1291, 1871,
125 -3470, 1032, 2710, -4040, 3624, -4214, 5292, -4270,
126 1563, 108, -580, 1642, -2458, 957, 544, 2540
129 /*----------------------------------------------------------------------------
130 ; EXTERNAL FUNCTION REFERENCES
131 ; Declare functions defined elsewhere and referenced in this module
132 ----------------------------------------------------------------------------*/
134 /*----------------------------------------------------------------------------
135 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
136 ; Declare variables used in this module but defined elsewhere
137 ----------------------------------------------------------------------------*/
139 /*----------------------------------------------------------------------------
141 ----------------------------------------------------------------------------*/
143 void phase_dispersion(
144 int16 gain_code, /* (i) Q0 : gain of code */
145 int16 gain_pit, /* (i) Q14 : gain of pitch */
146 int16 code[], /* (i/o) : code vector */
147 int16 mode, /* (i) : level, 0=hi, 1=lo, 2=off */
148 int16 disp_mem[], /* (i/o) : static memory (size = 8) */
153 int16 *prev_gain_pit, *prev_gain_code, *prev_state;
154 int16 *code2 = ScratchMem;
156 prev_state = disp_mem;
157 prev_gain_code = disp_mem + 1;
158 prev_gain_pit = disp_mem + 2;
160 pv_memset((void *)code2, 0, (2*L_SUBFR)*sizeof(*code2));
163 if (gain_pit < pitch_0_6)
167 else if (gain_pit < pitch_0_9)
176 for (i = 5; i > 0; i--)
178 prev_gain_pit[i] = prev_gain_pit[i - 1];
180 prev_gain_pit[0] = gain_pit;
182 if (sub_int16(gain_code, *prev_gain_code) > shl_int16(*prev_gain_code, 1))
193 for (i = 0; i < 6; i++)
195 if (prev_gain_pit[i] < pitch_0_6)
205 if (state > *prev_state + 1)
211 *prev_gain_code = gain_code;
214 /* circular convolution */
216 state += mode; /* level of dispersion */
220 for (i = 0; i < L_SUBFR; i++)
224 for (j = 0; j < L_SUBFR; j++)
226 code2[i + j] = add_int16(code2[i + j], mult_int16_r(code[i], ph_imp_low[j]));
233 for (i = 0; i < L_SUBFR; i++)
237 for (j = 0; j < L_SUBFR; j++)
239 code2[i + j] = add_int16(code2[i + j], mult_int16_r(code[i], ph_imp_mid[j]));
246 for (i = 0; i < L_SUBFR; i++)
248 code[i] = add_int16(code2[i], code2[i + L_SUBFR]);