summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/amrwbenc/src/g_pitch.c
blob: 98ee87e0b946b509038aa99a7316b032c675049c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 ** Copyright 2003-2010, VisualOn, Inc.
 **
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
 ** You may obtain a copy of the License at
 **
 **     http://www.apache.org/licenses/LICENSE-2.0
 **
 ** Unless required by applicable law or agreed to in writing, software
 ** distributed under the License is distributed on an "AS IS" BASIS,
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ** See the License for the specific language governing permissions and
 ** limitations under the License.
 */

/***********************************************************************
*      File: g_pitch.c                                                 *
*                                                                      *
*      Description:Compute the gain of pitch. Result in Q12        *
*                  if(gain < 0) gain = 0                           *
*                  if(gain > 1.2) gain = 1.2           *
************************************************************************/

#include "typedef.h"
#include "basic_op.h"
#include "math_op.h"

Word16 G_pitch(                            /* (o) Q14 : Gain of pitch lag saturated to 1.2   */
        Word16 xn[],                          /* (i)     : Pitch target.                        */
        Word16 y1[],                          /* (i)     : filtered adaptive codebook.          */
        Word16 g_coeff[],                     /* : Correlations need for gain quantization.     */
        Word16 L_subfr                        /* : Length of subframe.                          */
          )
{
    Word32 i;
    Word16 xy, yy, exp_xy, exp_yy, gain;
    /* Compute scalar product <y1[],y1[]> */
#ifdef ASM_OPT                  /* asm optimization branch */
    /* Compute scalar product <xn[],y1[]> */
    xy = extract_h(Dot_product12_asm(xn, y1, L_subfr, &exp_xy));
    yy = extract_h(Dot_product12_asm(y1, y1, L_subfr, &exp_yy));

#else
    /* Compute scalar product <xn[],y1[]> */
    xy = extract_h(Dot_product12(xn, y1, L_subfr, &exp_xy));
    yy = extract_h(Dot_product12(y1, y1, L_subfr, &exp_yy));

#endif

    g_coeff[0] = yy;
    g_coeff[1] = exp_yy;
    g_coeff[2] = xy;
    g_coeff[3] = exp_xy;

    /* If (xy < 0) gain = 0 */
    if (xy < 0)
        return ((Word16) 0);

    /* compute gain = xy/yy */

    xy >>= 1;                       /* Be sure xy < yy */
    gain = div_s(xy, yy);

    i = exp_xy;
    i -= exp_yy;

    gain = shl(gain, i);

    /* if (gain > 1.2) gain = 1.2  in Q14 */
    if(gain > 19661)
    {
        gain = 19661;
    }
    return (gain);
}