[PATCH] Change wavpack sample_fmt handling for future float support.

Laurent Aimar fenrir
Mon May 4 21:18:12 CEST 2009


There is no functionnality changes.
---
 libavcodec/wavpack.c |   50 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index 544ed96..8f5b0de 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -341,7 +341,7 @@ static int wv_get_value(WavpackContext *ctx, GetBitContext *gb, int channel, int
     return sign ? ~ret : ret;
 }
 
-static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *dst, const int hires)
+static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *dst, const int type)
 {
     int i, j, count = 0;
     int last, t;
@@ -377,7 +377,7 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
                     B = s->decorr[i].samplesB[pos];
                     j = (pos + t) & 7;
                 }
-                if(hires){
+                if(type != SAMPLE_FMT_S16){
                     L2 = L + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
                     R2 = R + ((s->decorr[i].weightB * (int64_t)B + 512) >> 10);
                 }else{
@@ -389,13 +389,13 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
                 s->decorr[i].samplesA[j] = L = L2;
                 s->decorr[i].samplesB[j] = R = R2;
             }else if(t == -1){
-                if(hires)
+                if(type != SAMPLE_FMT_S16)
                     L2 = L + ((s->decorr[i].weightA * (int64_t)s->decorr[i].samplesA[0] + 512) >> 10);
                 else
                     L2 = L + ((s->decorr[i].weightA * s->decorr[i].samplesA[0] + 512) >> 10);
                 UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, s->decorr[i].samplesA[0], L);
                 L = L2;
-                if(hires)
+                if(type != SAMPLE_FMT_S16)
                     R2 = R + ((s->decorr[i].weightB * (int64_t)L2 + 512) >> 10);
                 else
                     R2 = R + ((s->decorr[i].weightB * L2 + 512) >> 10);
@@ -403,7 +403,7 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
                 R = R2;
                 s->decorr[i].samplesA[0] = R;
             }else{
-                if(hires)
+                if(type != SAMPLE_FMT_S16)
                     R2 = R + ((s->decorr[i].weightB * (int64_t)s->decorr[i].samplesB[0] + 512) >> 10);
                 else
                     R2 = R + ((s->decorr[i].weightB * s->decorr[i].samplesB[0] + 512) >> 10);
@@ -415,7 +415,7 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
                     s->decorr[i].samplesA[0] = R;
                 }
 
-                if(hires)
+                if(type != SAMPLE_FMT_S16)
                     L2 = L + ((s->decorr[i].weightA * (int64_t)R2 + 512) >> 10);
                 else
                     L2 = L + ((s->decorr[i].weightA * R2 + 512) >> 10);
@@ -441,12 +441,12 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
             }
         }
         bit = (L & s->and) | s->or;
-        if(hires)
+        if(type == SAMPLE_FMT_S32)
             *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)
+        if(type == SAMPLE_FMT_S32)
             *dst32++ = (((R + bit) << s->shift) - bit) << s->post_shift;
         else
             *dst16++ = (((R + bit) << s->shift) - bit) << s->post_shift;
@@ -464,7 +464,7 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
     return count * 2;
 }
 
-static inline int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, void *dst, const int hires)
+static inline int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, void *dst, const int type)
 {
     int i, j, count = 0;
     int last, t;
@@ -493,7 +493,7 @@ static inline int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, void *dst
                 A = s->decorr[i].samplesA[pos];
                 j = (pos + t) & 7;
             }
-            if(hires)
+            if(type != SAMPLE_FMT_S16)
                 S = T + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
             else
                 S = T + ((s->decorr[i].weightA * A + 512) >> 10);
@@ -512,7 +512,7 @@ static inline int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, void *dst
         }
 
         bit = (S & s->and) | s->or;
-        if(hires)
+        if(type == SAMPLE_FMT_S16)
             *dst32++ = (((S + bit) << s->shift) - bit) << s->post_shift;
         else
             *dst16++ = (((S + bit) << s->shift) - bit) << s->post_shift;
@@ -805,15 +805,27 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
     }
 
     if(s->stereo_in){
-        if(bpp == 2)
-            samplecount = wv_unpack_stereo(s, &s->gb, samples, 0);
-        else
-            samplecount = wv_unpack_stereo(s, &s->gb, samples, 1);
+        switch(avctx->sample_fmt){
+        case SAMPLE_FMT_S16:
+            samplecount = wv_unpack_stereo(s, &s->gb, samples, SAMPLE_FMT_S16);
+            break;
+        default:
+            assert(0);
+        case SAMPLE_FMT_S32:
+            samplecount = wv_unpack_stereo(s, &s->gb, samples, SAMPLE_FMT_S32);
+            break;
+        }
     }else{
-        if(bpp == 2)
-            samplecount = wv_unpack_mono(s, &s->gb, samples, 0);
-        else
-            samplecount = wv_unpack_mono(s, &s->gb, samples, 1);
+        switch(avctx->sample_fmt){
+        case SAMPLE_FMT_S16:
+            samplecount = wv_unpack_mono(s, &s->gb, samples, SAMPLE_FMT_S16);
+            break;
+        default:
+            assert(0);
+        case SAMPLE_FMT_S32:
+            samplecount = wv_unpack_mono(s, &s->gb, samples, SAMPLE_FMT_S32);
+            break;
+        }
         if(s->stereo && bpp == 2){
             int16_t *dst = (int16_t*)samples + samplecount * 2;
             int16_t *src = (int16_t*)samples + samplecount;
-- 
1.5.6.5


--k1lZvvs/B4yU6o8G
Content-Type: text/x-diff; charset=iso-8859-1
Content-Disposition: attachment; filename="0002-Factorize-wavpack-integer-decoding.patch"




More information about the ffmpeg-devel mailing list