aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorAurelien Jacobs <aurel@gnuage.org>2018-01-06 01:31:02 +0100
committerAurelien Jacobs <aurel@gnuage.org>2018-02-09 22:10:55 +0100
commit96b217f5e878fabc142fc198b1e297b624f5c17e (patch)
treeabf33afbfcc4f5ca6e0b94d7ecac75cf3f5e110e /libavcodec
parentfea8e119a2bc103b64faba6b5e1f3defe0c344c2 (diff)
downloadffmpeg-96b217f5e878fabc142fc198b1e297b624f5c17e.tar.gz
aptx: do some clipping to match original codec in extreme cases
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/aptx.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/libavcodec/aptx.c b/libavcodec/aptx.c
index 64a63a7d5b..4173402d03 100644
--- a/libavcodec/aptx.c
+++ b/libavcodec/aptx.c
@@ -466,6 +466,7 @@ static void aptx_quantize_difference(Quantize *quantize,
int64_t error;
sample_difference_abs = FFABS(sample_difference);
+ sample_difference_abs = FFMIN(sample_difference_abs, (1 << 23) - 1);
quantized_sample = aptx_bin_search(sample_difference_abs >> 4,
quantization_factor,
@@ -478,7 +479,7 @@ static void aptx_quantize_difference(Quantize *quantize,
mean = (intervals[1] + intervals[0]) / 2;
interval = (intervals[1] - intervals[0]) * (-(sample_difference < 0) | 1);
- dithered_sample = rshift64_clip24(MUL64(dither, interval) + ((int64_t)(mean + d) << 32), 32);
+ dithered_sample = rshift64_clip24(MUL64(dither, interval) + ((int64_t)av_clip_intp2(mean + d, 23) << 32), 32);
error = ((int64_t)sample_difference_abs << 20) - MUL64(dithered_sample, quantization_factor);
quantize->error = FFABS(rshift64(error, 23));