⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basic_op40.c

📁 EVRC是用于高通公司的语音编码
💻 C
📖 第 1 页 / 共 3 页
字号:
 |    L_var1   40 bit long signed integer (Word40) whose value falls in the  |
 |             range : MIN_40 <= L_var3 <= MAX_40.                           |
 |                                                                           |
 |    var2     16 bit short signed integer (Word16) whose value falls in  |
 |             therange : MIN_16 <= var1 <= MAX_16.                          |
 |                                                                           |
 |   Return Value :                                                          |
 |                                                                           |
 |    L_var_out                                                              |
 |             40 bit long signed integer (Word40) whose value falls in the  |
 |             range : MIN_40 <= L_var_out <= MAX_40.                        |
 |___________________________________________________________________________|
*/

Word40 L_shr40(Word40 L_var1, Word16 var2)
{
  Word40 L_var_out;

  Word40 L_shl40(Word40 L_var1, Word16 var2);

  if (var2 < 0)
  {
    L_var_out = L_shl40(L_var1,(Word16)(-var2));
#ifdef WMOPS_FX
    counter_fx.L_shl40--;
#endif
  }
  else
  {
    L_var_out = L_shift_left40(L_var1, (Word16)(-var2));
  }

#ifdef WMOPS_FX
  counter_fx.L_shr40++;
#endif

  return(L_var_out);
}

/*___________________________________________________________________________
 |                                                                           |
 |   Function Name : L_shl40                                                 |
 |                                                                           |
 |   Purpose :                                                               |
 |                                                                           |
 |   Arithmetically shift the 40 bit input L_var1 left var2 positions. Zero  |
 |   fill the var2 LSB of the result. If var2 is negative, L_var1 right by   |
 |   -var2 arithmetically shift with sign extension. Saturate the result in  |
 |   case of underflows or overflows.                                        |
 |                                                                           |
 |   Complexity weight : 2                                                   |
 |                                                                           |
 |   Inputs :                                                                |
 |                                                                           |
 |    L_var1   40 bit long signed integer (Word40) whose value falls in the  |
 |             range : MIN_40 <= L_var3 <= MAX_40.                           |
 |                                                                           |
 |    var2     16 bit short signed integer (Word16) whose value falls in  |
 |             therange : MIN_16 <= var1 <= MAX_16.                          |
 |                                                                           |
 |   Return Value :                                                          |
 |                                                                           |
 |    L_var_out                                                              |
 |             40 bit long signed integer (Word40) whose value falls in the  |
 |             range : MIN_40 <= L_var_out <= MAX_40.                        |
 |___________________________________________________________________________|
*/

Word40 L_shl40(Word40 L_var1, Word16 var2)
{
  Word40 L_var_out;

  if (var2 <= 0)
  {
    L_var_out = L_shr40(L_var1,(Word16)(-var2));
#ifdef WMOPS_FX
    counter_fx.L_shr40--;
#endif
  }
  else
  {
    L_var_out = L_shift_left40(L_var1, var2);

    L_var_out = L_saturate40(L_var_out);
  }

#ifdef WMOPS_FX
  counter_fx.L_shl40++;
#endif

  return(L_var_out);
}


/*___________________________________________________________________________
 |                                                                           |
 |   Function Name : L_sat32_40                                              |
 |                                                                           |
 |   Purpose :                                                               |
 |                                                                           |
 |    40 bit L_var1 is limited to the range MAX_32..MIN_32.  L_var1 is set   |
 |    to MAX_32 on overflow or MIN_32 on underflow.                          |
 |                                                                           |
 |   Complexity weight : 1                                                   |
 |                                                                           |
 |   Inputs :                                                                |
 |                                                                           |
 |    L_var1   40 bit long signed integer (Word40) whose value falls in the  |
 |             range : MIN_40 <= var1 <= MAX_40.                             |
 |                                                                           |
 |   Return Value :                                                          |
 |                                                                           |
 |    L_var_out                                                              |
 |             40 bit long signed integer (Word40) whose value falls in the  |
 |             range : MIN_32 <= var_out <= MAX_32.                          |
 |___________________________________________________________________________|
*/

Word40 L_sat32_40(Word40 L_var1)
{
  Word40 L_var_out;

  if (L_var1 > MAX_32)
  {
    L_var_out = MAX_32;
    giOverflow = 1;
  }
  else if (L_var1 < MIN_32)
  {
    L_var_out = MIN_32;
    giOverflow = 1;
  }
  else L_var_out = L_var1;

#ifdef WMOPS_FX
  counter_fx.L_sat32_40++;
#endif

  return (L_var_out);
}


/*___________________________________________________________________________
 |                                                                           |
 |   Function Name : norm32_l_40                                             |
 |                                                                           |
 |   Purpose :                                                               |
 |                                                                           |
 |   Produces the number of left shift needed to normalize in 32 bits format |
 |   the 40 bit variable l_var1 for positive values on the interval with     |
 |   minimum of (MAX_32+1)/2 and maximum of MAX_32, and for negative values  |
 |   on the interval with minimum of MIN_32 and maximum of (MIN_32/2)+1;     |
 |   in order to normalize the result, the following operation must be done: |
 |                                                                           |
 |                   norm_L_var1 = L_shl40(L_var1,norm32_l(L_var1)).         |
 |                                                                           |
 |   Complexity weight : 3                                                   |
 |                                                                           |
 |   Inputs :                                                                |
 |                                                                           |
 |    L_var1   40 bit long signed integer (Word40) whose value falls in the  |
 |             range : MIN_40 <= var1 <= MAX_40.                             |
 |                                                                           |
 |   Return Value :                                                          |
 |                                                                           |
 |    var_out  16 bit short signed integer (Word16) whose value falls in  |
 |             therange : -8 <= var_out <= 31.                               |
 |___________________________________________________________________________|
*/

Word16 norm32_l40(Word40 L_var1)
{
  Word16 var_out;

  L_var1 = floor(L_var1);
  var_out = 0;

  if (L_var1 != 0)
  {
    while ((L_var1 > MIN_32) && (L_var1 < MAX_32))
    {
      L_var1 = L_shift_left40(L_var1, 1);
      var_out++;
    }

    while ((L_var1 < MIN_32) || (L_var1 > MAX_32))
    {
      L_var1 = L_shift_left40(L_var1, -1);
      var_out--;
    }
  }

#ifdef WMOPS_FX
  counter_fx.norm32_l40++;
#endif

  return(var_out);
 }


/*___________________________________________________________________________
 |                                                                           |
 |   Function Name : extract_l40                                             |
 |                                                                           |
 |   Purpose :                                                               |
 |                                                                           |
 |   Get the lower 16 bits of a 40-bit variable into a 16-bit variable       |
 |                                                                           |
 |   Complexity weight : 1                                                   |
 |                                                                           |
 |   Inputs :                                                                |
 |                                                                           |
 |    L_var1   40 bit long signed integer (Word40) whose value falls in the  |
 |             range : MIN_40 <= var1 <= MAX_40.                             |
 |                                                                           |
 |   Return Value :                                                          |
 |                                                                           |
 |    var_out  16 bit short signed integer (Word16) which may take any value |
 |___________________________________________________________________________|
*/

Word16 extract_l40(Word40 L_var1)
{
  Word16 out;
  
  out = (Word16)(L_var1 - floor(L_var1/65536.)*65536.);

#ifdef WMOPS_FX
  counter_fx.extract_l40++;
#endif

  return (out);
}



/*___________________________________________________________________________
 |                                                                           |
 |   Function Name : L_deposit_l40                                           |
 |                                                                           |
 |   Purpose :                                                               |
 |                                                                           |
 |   Replace lower 16 bits of a 40-bit variable by those of 16-bit input     |
 |   variable var_in                                                         |
 |                                                                           |
 |   Complexity weight : 1                                                   |
 |                                                                           |
 |   Inputs :                                                                |
 |                                                                           |
 |    L_var1   40 bit long signed integer (Word40) whose value falls in the  |
 |             range : MIN_40 <= var1 <= MAX_40.                             |
 |    var_in   16 bit short signed integer (Word16) which may take any value |
 |                                                                           |
 |   Return Value :                                                          |
 |                                                                           |
 |             40 bit long signed integer (Word40) whose value falls in the  |
 |             range : MIN_40 <= var1 <= MAX_40.                             |
 |___________________________________________________________________________|
*/

Word40 L_deposit_l40(Word40 L_var1, Word16 var_in)
{
  Word40 out;
  Word32 tmp32;
    
  tmp32 = 0x0000ffff & (Word32)var_in;  /* no sign extend  */
  out = L_add40(floor(L_var1/65536.)*65536., tmp32);

#ifdef WMOPS_FX
  counter_fx.L_add40--;
  counter_fx.L_deposit_l40++;
#endif

  return (out);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -