00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <inttypes.h>
00024 #include <limits.h>
00025
00026 #include "libavutil/avassert.h"
00027 #include "avcodec.h"
00028 #include "mathops.h"
00029 #include "celp_math.h"
00030 #include "libavutil/common.h"
00031
00032 static const uint16_t exp2a[]=
00033 {
00034 0, 1435, 2901, 4400, 5931, 7496, 9096, 10730,
00035 12400, 14106, 15850, 17632, 19454, 21315, 23216, 25160,
00036 27146, 29175, 31249, 33368, 35534, 37747, 40009, 42320,
00037 44682, 47095, 49562, 52082, 54657, 57289, 59979, 62727,
00038 };
00039
00040 static const uint16_t exp2b[]=
00041 {
00042 3, 712, 1424, 2134, 2845, 3557, 4270, 4982,
00043 5696, 6409, 7124, 7839, 8554, 9270, 9986, 10704,
00044 11421, 12138, 12857, 13576, 14295, 15014, 15734, 16455,
00045 17176, 17898, 18620, 19343, 20066, 20790, 21514, 22238,
00046 };
00047
00048 int ff_exp2(uint16_t power)
00049 {
00050 unsigned int result= exp2a[power>>10] + 0x10000;
00051
00052 av_assert2(power <= 0x7fff);
00053
00054 result= (result<<3) + ((result*exp2b[(power>>5)&31])>>17);
00055 return result + ((result*(power&31)*89)>>22);
00056 }
00057
00063 static const uint16_t tab_log2[33] =
00064 {
00065 #ifdef G729_BITEXACT
00066 0, 1455, 2866, 4236, 5568, 6863, 8124, 9352,
00067 10549, 11716, 12855, 13967, 15054, 16117, 17156, 18172,
00068 19167, 20142, 21097, 22033, 22951, 23852, 24735, 25603,
00069 26455, 27291, 28113, 28922, 29716, 30497, 31266, 32023, 32767,
00070 #else
00071 4, 1459, 2870, 4240, 5572, 6867, 8127, 9355,
00072 10552, 11719, 12858, 13971, 15057, 16120, 17158, 18175,
00073 19170, 20145, 21100, 22036, 22954, 23854, 24738, 25605,
00074 26457, 27294, 28116, 28924, 29719, 30500, 31269, 32025, 32769,
00075 #endif
00076 };
00077
00078 int ff_log2(uint32_t value)
00079 {
00080 uint8_t power_int;
00081 uint8_t frac_x0;
00082 uint16_t frac_dx;
00083
00084
00085 power_int = av_log2(value);
00086 value <<= (31 - power_int);
00087
00088
00089 frac_x0 = (value & 0x7c000000) >> 26;
00090 frac_dx = (value & 0x03fff800) >> 11;
00091
00092 value = tab_log2[frac_x0];
00093 value += (frac_dx * (tab_log2[frac_x0+1] - tab_log2[frac_x0])) >> 15;
00094
00095 return (power_int << 15) + value;
00096 }
00097
00098 int64_t ff_dot_product(const int16_t *a, const int16_t *b, int length)
00099 {
00100 int i;
00101 int64_t sum = 0;
00102
00103 for (i = 0; i < length; i++)
00104 sum += MUL16(a[i], b[i]);
00105
00106 return sum;
00107 }
00108
00109 float ff_dot_productf(const float* a, const float* b, int length)
00110 {
00111 float sum = 0;
00112 int i;
00113
00114 for(i=0; i<length; i++)
00115 sum += a[i] * b[i];
00116
00117 return sum;
00118 }
00119
00120 void ff_celp_math_init(CELPMContext *c)
00121 {
00122 c->dot_productf = ff_dot_productf;
00123
00124 if(HAVE_MIPSFPU)
00125 ff_celp_math_init_mips(c);
00126 }