1 /*
2 ** Copyright 2003-2010, VisualOn, Inc.
3 **
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
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
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 express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 /*******************************************************************************
17 File: pre_echo_control.c
18
19 Content: Pre echo control functions
20
21 *******************************************************************************/
22
23 #include "basic_op.h"
24 #include "oper_32b.h"
25
26 #include "oper_32b.h"
27 #include "pre_echo_control.h"
28
29
30 /*****************************************************************************
31 *
32 * function name:InitPreEchoControl
33 * description: init pre echo control parameter
34 *
35 *****************************************************************************/
InitPreEchoControl(Word32 * pbThresholdNm1,Word16 numPb,Word32 * pbThresholdQuiet)36 void InitPreEchoControl(Word32 *pbThresholdNm1,
37 Word16 numPb,
38 Word32 *pbThresholdQuiet)
39 {
40 Word16 pb;
41
42 for(pb=0; pb<numPb; pb++) {
43 pbThresholdNm1[pb] = pbThresholdQuiet[pb];
44 }
45 }
46
47 /*****************************************************************************
48 *
49 * function name:PreEchoControl
50 * description: update shreshold to avoid pre echo
51 * thr(n) = max(rpmin*thrq(n), min(thrq(n), rpelev*thrq1(n)))
52 *
53 *
54 *****************************************************************************/
PreEchoControl(Word32 * pbThresholdNm1,Word16 numPb,Word32 maxAllowedIncreaseFactor,Word16 minRemainingThresholdFactor,Word32 * pbThreshold,Word16 mdctScale,Word16 mdctScalenm1)55 void PreEchoControl(Word32 *pbThresholdNm1,
56 Word16 numPb,
57 Word32 maxAllowedIncreaseFactor,
58 Word16 minRemainingThresholdFactor,
59 Word32 *pbThreshold,
60 Word16 mdctScale,
61 Word16 mdctScalenm1)
62 {
63 Word32 i;
64 Word32 tmpThreshold1, tmpThreshold2;
65 Word32 scaling;
66
67 /* maxAllowedIncreaseFactor is hard coded to 2 */
68 (void)maxAllowedIncreaseFactor;
69
70 scaling = ((mdctScale - mdctScalenm1) << 1);
71
72 if ( scaling > 0 ) {
73 for(i = 0; i < numPb; i++) {
74 tmpThreshold1 = pbThresholdNm1[i] >> (scaling-1);
75 tmpThreshold2 = L_mpy_ls(pbThreshold[i], minRemainingThresholdFactor);
76
77 /* copy thresholds to internal memory */
78 pbThresholdNm1[i] = pbThreshold[i];
79
80
81 if(pbThreshold[i] > tmpThreshold1) {
82 pbThreshold[i] = tmpThreshold1;
83 }
84
85 if(tmpThreshold2 > pbThreshold[i]) {
86 pbThreshold[i] = tmpThreshold2;
87 }
88
89 }
90 }
91 else {
92 scaling = -scaling;
93 for(i = 0; i < numPb; i++) {
94
95 tmpThreshold1 = pbThresholdNm1[i] << 1;
96 tmpThreshold2 = L_mpy_ls(pbThreshold[i], minRemainingThresholdFactor);
97
98 /* copy thresholds to internal memory */
99 pbThresholdNm1[i] = pbThreshold[i];
100
101
102 if(((pbThreshold[i] >> scaling) > tmpThreshold1)) {
103 pbThreshold[i] = tmpThreshold1 << scaling;
104 }
105
106 if(tmpThreshold2 > pbThreshold[i]) {
107 pbThreshold[i] = tmpThreshold2;
108 }
109
110 }
111 }
112 }
113
114