]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/acelp_math.h
gcc chokes on xmm constraints, so pessimize int32_to_float_fmul_scalar_sse a little
[ffmpeg] / libavcodec / acelp_math.h
index 95be5f62e3a8f9e2303019bbec32fe78e9837a78..d2515505e38685f2adaf97e7d3c641e852b3fa03 100644 (file)
@@ -23,6 +23,8 @@
 #ifndef FFMPEG_ACELP_MATH_H
 #define FFMPEG_ACELP_MATH_H
 
+#include <stdint.h>
+
 /**
  * \brief fixed-point implementation of cosine in [0; PI) domain
  * \param arg fixed-point cosine argument, 0 <= arg < 0x4000
@@ -49,25 +51,36 @@ int ff_exp2(uint16_t power);
 int ff_log2(uint32_t value);
 
 /**
- * \brief Calculates sum of array element multiplications
- * \param speech input data array
+ * \brief returns the dot product
+ * \param a input data array
+ * \param b input data array
  * \param length number of elements
- * \param offset offset for calculation of sum of s[i]*s[i+offset]
- * \param shift right shift by this value will be done before multiplication
- *
- * \return sum of multiplications
+ * \param shift right shift by this value will be done after multiplication
  *
- * \note array must be at least length+offset long!
+ * \return dot product = sum of elementwise products
  */
-static int sum_of_squares(const int16_t* speech, int length, int offset, int shift)
+static int dot_product(const int16_t* a, const int16_t* b, int length, int shift)
 {
-    const int16_t* speech_end;
     int sum = 0;
+    int i;
 
-    for(speech_end=speech+length; speech<speech_end; speech++)
-       sum += (speech[0] * speech[offset]) >> shift;
+    for(i=0; i<length; i++)
+        sum += (a[i] * b[i]) >> shift;
 
     return sum;
 }
 
-#endif // FFMPEG_ACELP_MATH_H
+/**
+ * \brief Shift value left or right depending on sign of offset parameter.
+ * \param value value to shift
+ * \param offset shift offset
+ *
+ * \return value << offset, if offset>=0; value >> -offset - otherwise
+ */
+static inline int bidir_sal(int value, int offset)
+{
+    if(offset < 0) return value >> -offset;
+    else           return value <<  offset;
+}
+
+#endif /* FFMPEG_ACELP_MATH_H */