From patchwork Sat Feb 1 06:59:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 17641 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 560D244BE11 for ; Sat, 1 Feb 2020 09:00:16 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 384A368A0E5; Sat, 1 Feb 2020 09:00:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail2.protonmail.ch (mail2.protonmail.ch [185.70.40.22]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42C26689DAF for ; Sat, 1 Feb 2020 09:00:09 +0200 (EET) Date: Sat, 01 Feb 2020 06:59:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=protonmail; t=1580540407; bh=W/yWu+mODiIl2rgCerdxsHXMJ2glgXjTErY4+4N9HaM=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=Vl8b818rltV3NHivX1NXyw0o0FUiFcbUATAyosekwwswtdPyg5zC5Ui243ammPqFi nBainqhd5hObj0wUb3EmTvzwdOPAxeMIj8r1bN//A5nILPCr9FuWHT81Q3K8V/rOvi fAgxirQESWMneDAXDDBBLN+OZBtUNZLafiKt/yDw= To: ffmpeg-devel@ffmpeg.org From: Zane van Iperen Message-ID: <20200201065954.27106-1-zane@zanevaniperen.com> Feedback-ID: xylLYHwBzJW7F28tHN-oL9EBm6h5yqtCqG6YwPpJ2oMwBYJT6-HxTnFTF6p18axLiSywX61iUfj4CElBGg8-GA==:Ext:ProtonMail MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.protonmail.ch Subject: [FFmpeg-devel] [PATCH] avcodec/adpcm_argo: simplify and move duplicated logic into a function 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: Zane van Iperen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Zane van Iperen --- libavcodec/adpcm.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index dad3da28d3..9a42353351 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -552,9 +552,21 @@ static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_ } } -static inline int16_t adpcm_argo_expand_nibble(int nibble, int shift, int16_t prev0, int16_t prev1) +static inline int16_t adpcm_argo_expand_nibble(ADPCMChannelStatus *cs, int nibble, int control, int shift) { - return ((8 * prev0) - (4 * prev1) + (nibble * (1 << shift))) >> 2; + int sample = nibble * (1 << shift); + + if (control & 0x04) + sample += (8 * cs->sample1) - (4 * cs->sample2); + else + sample += 4 * cs->sample1; + + sample = av_clip_int16(sample >> 2); + + cs->sample2 = cs->sample1; + cs->sample1 = sample; + + return sample; } /** @@ -1805,7 +1817,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, * They should be 0 initially. */ for (channel = 0; channel < avctx->channels; channel++) { - int control, shift, sample, nibble; + int control, shift; samples = samples_p[channel]; cs = c->status + channel; @@ -1815,25 +1827,9 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, shift = (control >> 4) + 2; for (n = 0; n < nb_samples / 2; n++) { - sample = bytestream2_get_byteu(&gb); - - nibble = sign_extend(sample >> 4, 4); - if (control & 0x04) - *samples = adpcm_argo_expand_nibble(nibble, shift, cs->sample1, cs->sample2); - else - *samples = adpcm_argo_expand_nibble(nibble, shift, cs->sample1, cs->sample1); - - cs->sample2 = cs->sample1; - cs->sample1 = *samples++; - - nibble = sign_extend(sample >> 0, 4); - if (control & 0x04) - *samples = adpcm_argo_expand_nibble(nibble, shift, cs->sample1, cs->sample2); - else - *samples = adpcm_argo_expand_nibble(nibble, shift, cs->sample1, cs->sample1); - - cs->sample2 = cs->sample1; - cs->sample1 = *samples++; + int sample = bytestream2_get_byteu(&gb); + *samples++ = adpcm_argo_expand_nibble(cs, sign_extend(sample >> 4, 4), control, shift); + *samples++ = adpcm_argo_expand_nibble(cs, sign_extend(sample >> 0, 4), control, shift); } } break;