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: deemph.c                                                 *
19*                                                                      *
20*      Description:filtering through 1/(1-mu z^ -1)                    *
21*                  Deemph2 --> signal is divided by 2                  *
22*                  Deemph_32 --> for 32 bits signal.                   *
23*                                                                      *
24************************************************************************/
25
26#include "typedef.h"
27#include "basic_op.h"
28#include "math_op.h"
29
30void Deemph(
31        Word16 x[],                           /* (i/o)   : input signal overwritten by the output */
32        Word16 mu,                            /* (i) Q15 : deemphasis factor                      */
33        Word16 L,                             /* (i)     : vector size                            */
34        Word16 * mem                          /* (i/o)   : memory (y[-1])                         */
35       )
36{
37    Word32 i;
38    Word32 L_tmp;
39
40    L_tmp = L_deposit_h(x[0]);
41    L_tmp = L_mac(L_tmp, *mem, mu);
42    x[0] = vo_round(L_tmp);
43
44    for (i = 1; i < L; i++)
45    {
46        L_tmp = L_deposit_h(x[i]);
47        L_tmp = L_mac(L_tmp, x[i - 1], mu);
48        x[i] = voround(L_tmp);
49    }
50
51    *mem = x[L - 1];
52
53    return;
54}
55
56
57void Deemph2(
58        Word16 x[],                           /* (i/o)   : input signal overwritten by the output */
59        Word16 mu,                            /* (i) Q15 : deemphasis factor                      */
60        Word16 L,                             /* (i)     : vector size                            */
61        Word16 * mem                          /* (i/o)   : memory (y[-1])                         */
62        )
63{
64    Word32 i;
65    Word32 L_tmp;
66    L_tmp = x[0] << 15;
67    i = L_mult(*mem, mu);
68    L_tmp = L_add(L_tmp, i);
69    x[0] = voround(L_tmp);
70    for (i = 1; i < L; i++)
71    {
72        Word32 tmp;
73        L_tmp = x[i] << 15;
74        tmp = (x[i - 1] * mu)<<1;
75        L_tmp = L_add(L_tmp, tmp);
76        x[i] = voround(L_tmp);
77    }
78    *mem = x[L - 1];
79    return;
80}
81
82
83void Deemph_32(
84        Word16 x_hi[],                        /* (i)     : input signal (bit31..16) */
85        Word16 x_lo[],                        /* (i)     : input signal (bit15..4)  */
86        Word16 y[],                           /* (o)     : output signal (x16)      */
87        Word16 mu,                            /* (i) Q15 : deemphasis factor        */
88        Word16 L,                             /* (i)     : vector size              */
89        Word16 * mem                          /* (i/o)   : memory (y[-1])           */
90          )
91{
92    Word16 fac;
93    Word32 i, L_tmp;
94
95    fac = mu >> 1;                                /* Q15 --> Q14 */
96
97    L_tmp = L_deposit_h(x_hi[0]);
98    L_tmp += (x_lo[0] * 8)<<1;
99    L_tmp = (L_tmp << 3);
100    L_tmp += ((*mem) * fac)<<1;
101    L_tmp = (L_tmp << 1);
102    y[0] = (L_tmp + 0x8000)>>16;
103
104    for (i = 1; i < L; i++)
105    {
106        L_tmp = L_deposit_h(x_hi[i]);
107        L_tmp += (x_lo[i] * 8)<<1;
108        L_tmp = (L_tmp << 3);
109        L_tmp += (y[i - 1] * fac)<<1;
110        L_tmp = (L_tmp << 1);
111        y[i] = (L_tmp + 0x8000)>>16;
112    }
113
114    *mem = y[L - 1];
115
116    return;
117}
118
119
120
121