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: isp_isf.c                                                *
19*                                                                      *
20*       Description:                                                   *
21*   Isp_isf   Transformation isp to isf                            *
22*   Isf_isp   Transformation isf to isp                            *
23*                                                                      *
24*   The transformation from isp[i] to isf[i] and isf[i] to isp[i]  *
25*   are approximated by a look-up table and interpolation          *
26*                                                                      *
27************************************************************************/
28
29#include "typedef.h"
30#include "basic_op.h"
31#include "isp_isf.tab"                     /* Look-up table for transformations */
32
33void Isp_isf(
34        Word16 isp[],                         /* (i) Q15 : isp[m] (range: -1<=val<1)                */
35        Word16 isf[],                         /* (o) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */
36        Word16 m                              /* (i)     : LPC order                                */
37        )
38{
39    Word32 i, ind;
40    Word32 L_tmp;
41    ind = 127;                               /* beging at end of table -1 */
42    for (i = (m - 1); i >= 0; i--)
43    {
44        if (i >= (m - 2))
45        {                                  /* m-2 is a constant */
46            ind = 127;                       /* beging at end of table -1 */
47        }
48        /* find value in table that is just greater than isp[i] */
49        while (table[ind] < isp[i])
50            ind--;
51        /* acos(isp[i])= ind*128 + ( ( isp[i]-table[ind] ) * slope[ind] )/2048 */
52        L_tmp = vo_L_mult(vo_sub(isp[i], table[ind]), slope[ind]);
53        isf[i] = vo_round((L_tmp << 4));   /* (isp[i]-table[ind])*slope[ind])>>11 */
54        isf[i] = add1(isf[i], (ind << 7));
55    }
56    isf[m - 1] = (isf[m - 1] >> 1);
57    return;
58}
59
60
61void Isf_isp(
62        Word16 isf[],                         /* (i) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */
63        Word16 isp[],                         /* (o) Q15 : isp[m] (range: -1<=val<1)                */
64        Word16 m                              /* (i)     : LPC order                                */
65        )
66{
67    Word16 offset;
68    Word32 i, ind, L_tmp;
69
70    for (i = 0; i < m - 1; i++)
71    {
72        isp[i] = isf[i];
73    }
74    isp[m - 1] = (isf[m - 1] << 1);
75
76    for (i = 0; i < m; i++)
77    {
78        ind = (isp[i] >> 7);                      /* ind    = b7-b15 of isf[i] */
79        offset = (Word16) (isp[i] & 0x007f);      /* offset = b0-b6  of isf[i] */
80
81        /* isp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 128 */
82        L_tmp = vo_L_mult(vo_sub(table[ind + 1], table[ind]), offset);
83        isp[i] = add1(table[ind], (Word16)((L_tmp >> 8)));
84    }
85
86    return;
87}
88
89
90
91
92