[FFmpeg-cvslog] wavpack: Properly clip samples during lossy decode

Derek Buitenhuis git at videolan.org
Mon Dec 5 00:43:08 CET 2011


ffmpeg | branch: master | Derek Buitenhuis <derek.buitenhuis at gmail.com> | Sat Dec  3 14:35:23 2011 -0500| [a548b6cbfcf6d872bed473c1981931db36eda690] | committer: Ronald S. Bultje

wavpack: Properly clip samples during lossy decode

When decoding lossy WavPack samples, they are supposed
to be clipped, in order to be decoded correctly.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
Signed-off-by: Ronald S. Bultje <rsbultje at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a548b6cbfcf6d872bed473c1981931db36eda690
---

 libavcodec/wavpack.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index e4b7ebe..11e9904 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -110,7 +110,7 @@ typedef struct WavpackFrameContext {
     int extra_bits;
     int and, or, shift;
     int post_shift;
-    int hybrid, hybrid_bitrate;
+    int hybrid, hybrid_bitrate, hybrid_maxclip;
     int float_flag;
     int float_shift;
     int float_max_exp;
@@ -403,8 +403,14 @@ static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc, in
             *crc = *crc * 9 + (S&0xffff) * 3 + ((unsigned)S>>16);
         }
     }
+
     bit = (S & s->and) | s->or;
-    return (((S + bit) << s->shift) - bit) << s->post_shift;
+    bit = (((S + bit) << s->shift) - bit);
+
+    if(s->hybrid)
+        bit = av_clip(bit, -s->hybrid_maxclip, s->hybrid_maxclip - 1);
+
+    return bit << s->post_shift;
 }
 
 static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
@@ -792,6 +798,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
     s->joint = s->frame_flags & WV_JOINT_STEREO;
     s->hybrid = s->frame_flags & WV_HYBRID_MODE;
     s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE;
+    s->hybrid_maxclip = 1 << ((((s->frame_flags & 0x03) + 1) << 3) - 1);
     s->post_shift = 8 * (bpp-1-(s->frame_flags&0x03)) + ((s->frame_flags >> 13) & 0x1f);
     s->CRC = AV_RL32(buf); buf += 4;
     if(wc->mkv_mode)



More information about the ffmpeg-cvslog mailing list