[FFmpeg-cvslog] r14056 - in trunk/libavcodec: acelp_math.h acelp_pitch_delay.c

michael subversion
Thu Jul 3 13:50:44 CEST 2008


Author: michael
Date: Thu Jul  3 13:50:44 2008
New Revision: 14056

Log:
make sum_of_squares() more generic


Modified:
   trunk/libavcodec/acelp_math.h
   trunk/libavcodec/acelp_pitch_delay.c

Modified: trunk/libavcodec/acelp_math.h
==============================================================================
--- trunk/libavcodec/acelp_math.h	(original)
+++ trunk/libavcodec/acelp_math.h	Thu Jul  3 13:50:44 2008
@@ -51,23 +51,21 @@ 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 Calculates 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
- *
- * \note array must be at least length+offset long!
  */
-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;
 }

Modified: trunk/libavcodec/acelp_pitch_delay.c
==============================================================================
--- trunk/libavcodec/acelp_pitch_delay.c	(original)
+++ trunk/libavcodec/acelp_pitch_delay.c	Thu Jul  3 13:50:44 2008
@@ -103,7 +103,7 @@ int16_t ff_acelp_decode_gain_code(
         mr_energy += quant_energy[i] * ma_prediction_coeff[i];
 
 #ifdef G729_BITEXACT
-    mr_energy += (((-6165LL * ff_log2(sum_of_squares(fc_v, subframe_size, 0, 0))) >> 3) & ~0x3ff);
+    mr_energy += (((-6165LL * ff_log2(dot_product(fc_v, fc_v, subframe_size, 0))) >> 3) & ~0x3ff);
 
     mr_energy = (5439 * (mr_energy >> 15)) >> 8;           // (0.15) = (0.15) * (7.23)
 
@@ -113,7 +113,7 @@ int16_t ff_acelp_decode_gain_code(
            );
 #else
     mr_energy = gain_corr_factor * exp(M_LN10 / (20 << 23) * mr_energy) /
-                sqrt(sum_of_squares(fc_v, subframe_size, 0, 0));
+                sqrt(dot_product(fc_v, fc_v, subframe_size, 0));
     return mr_energy >> 12;
 #endif
 }




More information about the ffmpeg-cvslog mailing list