From patchwork Sat Jan 6 16:48:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jacobs X-Patchwork-Id: 7162 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.78.2 with SMTP id r2csp726391jaa; Sat, 6 Jan 2018 08:49:02 -0800 (PST) X-Google-Smtp-Source: ACJfBovEHm+IdLS5EVV3/lBEDA3Gv5bA7pLEu4xDpaQ9/BImJsWMiLPlt8j1Yd3siHqsRXS9qyJO X-Received: by 10.28.21.66 with SMTP id 63mr5325845wmv.44.1515257342640; Sat, 06 Jan 2018 08:49:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515257342; cv=none; d=google.com; s=arc-20160816; b=CMCKdSYPuy8/xMEZlfDUUuago3SKRZMO+bE7aA67W7hvB31axT6arFxAHxW1rOZsw0 BKinl94x4FAdUPsIsF8HUHcwZnO+cwc7dqJbmsfu/vDuigzVRr+u3e3AzotpyVvA7MoV rKtknbxmRQqvmTIJ4xycBaVfy6b/A9EzBE2TIhTTw9Q0ioe/mddybOCERWcuw3jh79QW ENaaKfVftKg9jFlXAz4xJTTgHvOiTmaOT7BgpsVEdoraw87tpavHlC3fr0SLl3Ls1Ap5 nf/74AYzqapKQ7M6Q/BctlqkRcYwZIHjvjE3asF9HiGhLMo7h+FKLTPP/LiILdFx8ZEX LUuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=Xt97EeHgSetSsqne64IeCKwnUC4NaJCsLNrpN/GcGHI=; b=uCtQnh2vIWAUBEtesWH2ZkGxf4htQNKhuf9Xt88Ciqgoi0/N2lyc4N2uuhbOspXWMf 2wOsQ+vul6UEQDZLYlVn2AcUMbZMij0WlivBCb2chdGan0oXaiGHI0wxWszSMU7niNhJ aR+4fh8qsR9x2aPFKj1irwGxbtosA1l4fVht/ilLqnrILRyVpa2myWhJY53LEKYGOeZY PIwH8vy1nAUUTyVxn6jxPnWafUXJa7QUPnEUtMRZKrrir/s+py6bwUajRwkykMS5JmN8 dDx276+x9ElZY8lBOs3xd19YwE5rMze8imfFOWw71k82APW7y6IKyeeSI66+JJ4wFrke Usvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e9si5197901wmi.141.2018.01.06.08.49.02; Sat, 06 Jan 2018 08:49:02 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AE5A4689E18; Sat, 6 Jan 2018 18:48:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp6-g21.free.fr (smtp6-g21.free.fr [212.27.42.6]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 72354689E13 for ; Sat, 6 Jan 2018 18:48:52 +0200 (EET) Received: from marge.gnuage.org (unknown [IPv6:2a01:e35:2e26:9790::10]) by smtp6-g21.free.fr (Postfix) with ESMTPS id 8B9847803BB for ; Sat, 6 Jan 2018 17:48:52 +0100 (CET) Received: from [2a01:e35:2e26:9790:bc8a:b994:5b68:84cc] (helo=xps) by marge.gnuage.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1eXreN-0001sF-O1; Sat, 06 Jan 2018 17:48:52 +0100 Received: from aurel by xps with local (Exim 4.90) (envelope-from ) id 1eXreN-0006sO-J2; Sat, 06 Jan 2018 17:48:51 +0100 From: Aurelien Jacobs To: FFmpeg development discussions and patches Date: Sat, 6 Jan 2018 17:48:06 +0100 Message-Id: <20180106164808.26162-4-aurel@gnuage.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180106164808.26162-1-aurel@gnuage.org> References: <20180106164808.26162-1-aurel@gnuage.org> X-SA-Exim-Connect-IP: 2a01:e35:2e26:9790:bc8a:b994:5b68:84cc X-SA-Exim-Mail-From: aurel@gnuage.org X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on marge.gnuage.org X-Spam-Level: X-Spam-Status: No, score=-0.2 required=3.0 tests=BAYES_00, FSL_HELO_NON_FQDN_1, RDNS_NONE autolearn=no autolearn_force=no version=3.4.1 X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on marge.gnuage.org) Subject: [FFmpeg-devel] [PATCH 3/5] aptx: do some clipping to match original codec in extreme cases X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Aurelien Jacobs MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavcodec/aptx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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));