Home | History | Annotate | Download | only in src
      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: voicefac.c                                                   *
     19 *                                                                      *
     20 *   Description: Find the voicing factors (1 = voice to -1 = unvoiced) *
     21 *                                                                      *
     22 ************************************************************************/
     23 
     24 #include "typedef.h"
     25 #include "basic_op.h"
     26 #include "math_op.h"
     27 
     28 Word16 voice_factor(                                  /* (o) Q15   : factor (-1=unvoiced to 1=voiced) */
     29         Word16 exc[],                         /* (i) Q_exc : pitch excitation                 */
     30         Word16 Q_exc,                         /* (i)       : exc format                       */
     31         Word16 gain_pit,                      /* (i) Q14   : gain of pitch                    */
     32         Word16 code[],                        /* (i) Q9    : Fixed codebook excitation        */
     33         Word16 gain_code,                     /* (i) Q0    : gain of code                     */
     34         Word16 L_subfr                        /* (i)       : subframe length                  */
     35         )
     36 {
     37     Word16 tmp, exp, ener1, exp1, ener2, exp2;
     38     Word32 i, L_tmp;
     39 
     40 #ifdef ASM_OPT               /* asm optimization branch */
     41     ener1 = extract_h(Dot_product12_asm(exc, exc, L_subfr, &exp1));
     42 #else
     43     ener1 = extract_h(Dot_product12(exc, exc, L_subfr, &exp1));
     44 #endif
     45     exp1 = exp1 - (Q_exc + Q_exc);
     46     L_tmp = vo_L_mult(gain_pit, gain_pit);
     47     exp = norm_l(L_tmp);
     48     tmp = extract_h(L_tmp << exp);
     49     ener1 = vo_mult(ener1, tmp);
     50     exp1 = exp1 - exp - 10;        /* 10 -> gain_pit Q14 to Q9 */
     51 
     52 #ifdef ASM_OPT                /* asm optimization branch */
     53     ener2 = extract_h(Dot_product12_asm(code, code, L_subfr, &exp2));
     54 #else
     55     ener2 = extract_h(Dot_product12(code, code, L_subfr, &exp2));
     56 #endif
     57 
     58     exp = norm_s(gain_code);
     59     tmp = gain_code << exp;
     60     tmp = vo_mult(tmp, tmp);
     61     ener2 = vo_mult(ener2, tmp);
     62     exp2 = exp2 - (exp + exp);
     63 
     64     i = exp1 - exp2;
     65 
     66     if (i >= 0)
     67     {
     68         ener1 = ener1 >> 1;
     69         ener2 = ener2 >> (i + 1);
     70     } else
     71     {
     72         ener1 = ener1 >> (1 - i);
     73         ener2 = ener2 >> 1;
     74     }
     75 
     76     tmp = vo_sub(ener1, ener2);
     77     ener1 = add1(add1(ener1, ener2), 1);
     78 
     79     if (tmp >= 0)
     80     {
     81         tmp = div_s(tmp, ener1);
     82     } else
     83     {
     84         tmp = vo_negate(div_s(vo_negate(tmp), ener1));
     85     }
     86 
     87     return (tmp);
     88 }
     89 
     90 
     91 
     92 
     93