• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /***********************************************************************
18 *      File: preemph.c                                                *
19 *                                                                     *
20 *      Description: Preemphasis: filtering through 1 - g z^-1         *
21 *              Preemph2 --> signal is multiplied by 2             *
22 *                                                                     *
23 ************************************************************************/
24 
25 #include "typedef.h"
26 #include "basic_op.h"
27 #include <stdint.h>
28 
Preemph(Word16 x[],Word16 mu,Word16 lg,Word16 * mem)29 void Preemph(
30         Word16 x[],                           /* (i/o)   : input signal overwritten by the output */
31         Word16 mu,                            /* (i) Q15 : preemphasis coefficient                */
32         Word16 lg,                            /* (i)     : lenght of filtering                    */
33         Word16 * mem                          /* (i/o)   : memory (x[-1])                         */
34         )
35 {
36     Word16 temp;
37     Word32 i, L_tmp;
38 
39     temp = x[lg - 1];
40 
41     for (i = lg - 1; i > 0; i--)
42     {
43         L_tmp = L_deposit_h(x[i]);
44         L_tmp -= (x[i - 1] * mu)<<1;
45         x[i] = (L_tmp + 0x8000)>>16;
46     }
47 
48     L_tmp = L_deposit_h(x[0]);
49     L_tmp -= ((*mem) * mu)<<1;
50     x[0] = (L_tmp + 0x8000)>>16;
51 
52     *mem = temp;
53 
54     return;
55 }
56 
57 
Preemph2(Word16 x[],Word16 mu,Word16 lg,Word16 * mem)58 void Preemph2(
59         Word16 x[],                           /* (i/o)   : input signal overwritten by the output */
60         Word16 mu,                            /* (i) Q15 : preemphasis coefficient                */
61         Word16 lg,                            /* (i)     : lenght of filtering                    */
62         Word16 * mem                          /* (i/o)   : memory (x[-1])                         */
63          )
64 {
65     Word16 temp;
66     Word32 i, L_tmp;
67 
68     temp = x[lg - 1];
69 
70     for (i = (Word16) (lg - 1); i > 0; i--)
71     {
72         L_tmp = L_deposit_h(x[i]);
73         L_tmp -= (x[i - 1] * mu)<<1; // only called with mu == 22282, so this won't overflow
74         if (L_tmp > INT32_MAX / 2) {
75             L_tmp = INT32_MAX / 2;
76         }
77         L_tmp = (L_tmp << 1);
78         if (L_tmp > INT32_MAX - 0x8000) {
79             L_tmp = INT32_MAX - 0x8000;
80         }
81         x[i] = (L_tmp + 0x8000)>>16;
82     }
83 
84     L_tmp = L_deposit_h(x[0]);
85     L_tmp -= ((*mem) * mu)<<1;
86     if (L_tmp > INT32_MAX / 2) {
87         L_tmp = INT32_MAX / 2;
88     }
89     L_tmp = (L_tmp << 1);
90     if (L_tmp > INT32_MAX - 0x8000) {
91         L_tmp = INT32_MAX - 0x8000;
92     }
93     x[0] = (L_tmp + 0x8000)>>16;
94 
95     *mem = temp;
96 
97     return;
98 }
99 
100 
101 
102