changeset 9597:b60289b3e29a libavcodec

Factorize out integer sample value decoding for WavPack. This is slightly modified patch by Laurent Aimar.
author kostya
date Tue, 05 May 2009 06:10:59 +0000
parents 182f35c8eaed
children 407470044819
files wavpack.c
diffstat 1 files changed, 26 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/wavpack.c	Mon May 04 17:31:15 2009 +0000
+++ b/wavpack.c	Tue May 05 06:10:59 2009 +0000
@@ -341,11 +341,27 @@
     return sign ? ~ret : ret;
 }
 
+static inline int wv_get_value_integer(WavpackContext *s, uint32_t *crc, int S)
+{
+    int bit;
+
+    if(s->extra_bits){
+        S <<= s->extra_bits;
+
+        if(s->got_extra_bits){
+            S |= get_bits(&s->gb_extra_bits, s->extra_bits);
+            *crc = *crc * 9 + (S&0xffff) * 3 + ((unsigned)S>>16);
+        }
+    }
+    bit = (S & s->and) | s->or;
+    return (((S + bit) << s->shift) - bit) << s->post_shift;
+}
+
 static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *dst, const int hires)
 {
     int i, j, count = 0;
     int last, t;
-    int A, B, L, L2, R, R2, bit;
+    int A, B, L, L2, R, R2;
     int pos = 0;
     uint32_t crc = 0xFFFFFFFF;
     uint32_t crc_extra_bits = 0xFFFFFFFF;
@@ -428,28 +444,14 @@
         if(s->joint)
             L += (R -= (L >> 1));
         crc = (crc * 3 + L) * 3 + R;
-        if(s->extra_bits){
-            L <<= s->extra_bits;
-            R <<= s->extra_bits;
 
-            if(s->got_extra_bits){
-                L |= get_bits(&s->gb_extra_bits, s->extra_bits);
-                crc_extra_bits = crc_extra_bits * 9 + (L&0xffff) * 3 + ((unsigned)L>>16);
-
-                R |= get_bits(&s->gb_extra_bits, s->extra_bits);
-                crc_extra_bits = crc_extra_bits * 9 + (R&0xffff) * 3 + ((unsigned)R>>16);
-            }
+        if(hires){
+            *dst32++ = wv_get_value_integer(s, &crc_extra_bits, L);
+            *dst32++ = wv_get_value_integer(s, &crc_extra_bits, R);
+        } else {
+            *dst16++ = wv_get_value_integer(s, &crc_extra_bits, L);
+            *dst16++ = wv_get_value_integer(s, &crc_extra_bits, R);
         }
-        bit = (L & s->and) | s->or;
-        if(hires)
-            *dst32++ = (((L + bit) << s->shift) - bit) << s->post_shift;
-        else
-            *dst16++ = (((L + bit) << s->shift) - bit) << s->post_shift;
-        bit = (R & s->and) | s->or;
-        if(hires)
-            *dst32++ = (((R + bit) << s->shift) - bit) << s->post_shift;
-        else
-            *dst16++ = (((R + bit) << s->shift) - bit) << s->post_shift;
         count++;
     }while(!last && count < s->samples);
 
@@ -468,7 +470,7 @@
 {
     int i, j, count = 0;
     int last, t;
-    int A, S, T, bit;
+    int A, S, T;
     int pos = 0;
     uint32_t crc = 0xFFFFFFFF;
     uint32_t crc_extra_bits = 0xFFFFFFFF;
@@ -502,20 +504,11 @@
         }
         pos = (pos + 1) & 7;
         crc = crc * 3 + S;
-        if(s->extra_bits){
-            S <<= s->extra_bits;
 
-            if(s->got_extra_bits){
-                S |= get_bits(&s->gb_extra_bits, s->extra_bits);
-                crc_extra_bits = crc_extra_bits * 9 + (S&0xffff) * 3 + ((unsigned)S>>16);
-            }
-        }
-
-        bit = (S & s->and) | s->or;
         if(hires)
-            *dst32++ = (((S + bit) << s->shift) - bit) << s->post_shift;
+            *dst32++ = wv_get_value_integer(s, &crc_extra_bits, S);
         else
-            *dst16++ = (((S + bit) << s->shift) - bit) << s->post_shift;
+            *dst16++ = wv_get_value_integer(s, &crc_extra_bits, S);
         count++;
     }while(!last && count < s->samples);