acelp_math.h File Reference

#include <stdint.h>

Go to the source code of this file.

Functions

int16_t ff_cos (uint16_t arg)
 fixed-point implementation of cosine in [0; PI) domain
int ff_exp2 (uint16_t power)
 fixed-point implementation of exp2(x) in [0; 1] domain
int ff_log2 (uint32_t value)
 Calculates log2(x).
static int dot_product (const int16_t *a, const int16_t *b, int length, int shift)
 returns the dot product
static int bidir_sal (int value, int offset)
 Shift value left or right depending on sign of offset parameter.


Function Documentation

static int bidir_sal ( int  value,
int  offset 
) [inline, static]

Shift value left or right depending on sign of offset parameter.

Parameters:
value value to shift
offset shift offset
Returns:
value << offset, if offset>=0; value >> -offset - otherwise

Definition at line 80 of file acelp_math.h.

Referenced by ff_acelp_decode_gain_code().

00081 {
00082     if(offset < 0) return value >> -offset;
00083     else           return value <<  offset;
00084 }

static int dot_product ( const int16_t *  a,
const int16_t *  b,
int  length,
int  shift 
) [static]

returns the dot product

Parameters:
a input data array
b input data array
length number of elements
shift right shift by this value will be done after multiplication
Returns:
dot product = sum of elementwise products

Definition at line 62 of file acelp_math.h.

Referenced by ff_acelp_decode_gain_code().

00063 {
00064     int sum = 0;
00065     int i;
00066 
00067     for(i=0; i<length; i++)
00068         sum += (a[i] * b[i]) >> shift;
00069 
00070     return sum;
00071 }

int16_t ff_cos ( uint16_t  arg  ) 

fixed-point implementation of cosine in [0; PI) domain

Parameters:
arg fixed-point cosine argument, 0 <= arg < 0x4000
Returns:
value of (1<<15) * cos(arg * PI / (1<<14)), -0x8000 <= result <= 0x7fff

Definition at line 137 of file acelp_math.c.

Referenced by ff_acelp_lsf2lsp().

00138 {
00139     uint8_t offset= arg;
00140     uint8_t ind = arg >> 8;
00141 
00142     assert(arg <= 0x3fff);
00143 
00144     return tab_cos[ind] + (offset * (tab_cos[ind+1] - tab_cos[ind]) >> 8);
00145 }

int ff_exp2 ( uint16_t  power  ) 

fixed-point implementation of exp2(x) in [0; 1] domain

Parameters:
power argument to exp2, 0 <= power <= 0x7fff
Returns:
value of (1<<20) * exp2(power / (1<<15)) 0x8000c <= result <= 0xfffea

Definition at line 147 of file acelp_math.c.

Referenced by ff_acelp_decode_gain_code().

00148 {
00149     unsigned int result= exp2a[power>>10] + 0x10000;
00150 
00151     assert(arg <= 0x7fff);
00152 
00153     result= (result<<3) + ((result*exp2b[(power>>5)&31])>>17);
00154     return result + ((result*(power&31)*89)>>22);
00155 }

int ff_log2 ( uint32_t  value  ) 

Calculates log2(x).

Parameters:
value function argument, 0 < value <= 7fff ffff
Returns:
value of (1<<15) * log2(value)

Definition at line 179 of file acelp_math.c.

References av_log2().

Referenced by ff_acelp_decode_gain_code(), and ff_acelp_update_past_gain().

00180 {
00181     uint8_t  power_int;
00182     uint8_t  frac_x0;
00183     uint16_t frac_dx;
00184 
00185     // Stripping zeros from beginning
00186     power_int = av_log2(value);
00187     value <<= (31 - power_int);
00188 
00189     // b31 is always non-zero now
00190     frac_x0 = (value & 0x7c000000) >> 26; // b26-b31 and [32..63] -> [0..31]
00191     frac_dx = (value & 0x03fff800) >> 11;
00192 
00193     value = tab_log2[frac_x0];
00194     value += (frac_dx * (tab_log2[frac_x0+1] - tab_log2[frac_x0])) >> 15;
00195 
00196     return (power_int << 15) + value;
00197 }


Generated on Thu Aug 28 04:44:30 2008 for libextractor by  doxygen 1.5.1