00001 /* 00002 * Various fixed-point math operations 00003 * 00004 * Copyright (c) 2008 Vladimir Voroshilov 00005 * 00006 * This file is part of FFmpeg. 00007 * 00008 * FFmpeg is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * FFmpeg is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with FFmpeg; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #ifndef FFMPEG_ACELP_MATH_H 00024 #define FFMPEG_ACELP_MATH_H 00025 00026 #include <stdint.h> 00027 00028 /** 00029 * \brief fixed-point implementation of cosine in [0; PI) domain 00030 * \param arg fixed-point cosine argument, 0 <= arg < 0x4000 00031 * 00032 * \return value of (1<<15) * cos(arg * PI / (1<<14)), -0x8000 <= result <= 0x7fff 00033 */ 00034 int16_t ff_cos(uint16_t arg); 00035 00036 /** 00037 * \brief fixed-point implementation of exp2(x) in [0; 1] domain 00038 * \param power argument to exp2, 0 <= power <= 0x7fff 00039 * 00040 * \return value of (1<<20) * exp2(power / (1<<15)) 00041 * 0x8000c <= result <= 0xfffea 00042 */ 00043 int ff_exp2(uint16_t power); 00044 00045 /** 00046 * \brief Calculates log2(x) 00047 * \param value function argument, 0 < value <= 7fff ffff 00048 * 00049 * \return value of (1<<15) * log2(value) 00050 */ 00051 int ff_log2(uint32_t value); 00052 00053 /** 00054 * \brief returns the dot product 00055 * \param a input data array 00056 * \param b input data array 00057 * \param length number of elements 00058 * \param shift right shift by this value will be done after multiplication 00059 * 00060 * \return dot product = sum of elementwise products 00061 */ 00062 static int dot_product(const int16_t* a, const int16_t* b, int length, int shift) 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 } 00072 00073 /** 00074 * \brief Shift value left or right depending on sign of offset parameter. 00075 * \param value value to shift 00076 * \param offset shift offset 00077 * 00078 * \return value << offset, if offset>=0; value >> -offset - otherwise 00079 */ 00080 static inline int bidir_sal(int value, int offset) 00081 { 00082 if(offset < 0) return value >> -offset; 00083 else return value << offset; 00084 } 00085 00086 #endif /* FFMPEG_ACELP_MATH_H */
1.5.1