From patchwork Tue Aug 25 14:09:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21913 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 6189544B6CA for ; Tue, 25 Aug 2020 17:10:24 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 475E768AD22; Tue, 25 Aug 2020 17:10:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E478768A8F3 for ; Tue, 25 Aug 2020 17:10:19 +0300 (EEST) Received: by mail-ej1-f67.google.com with SMTP id a21so757604ejp.0 for ; Tue, 25 Aug 2020 07:10:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T5iEoUxqtE+RKgLCppji99ooivkYtyeHosdCGWVccyM=; b=JO+JRMWj4lYxi9sUxI0PN6bs4MBa23ifxYIELNu9674C1L2J98qnACAMxaM0/5R0G4 BcjfAjDQ392cCcDIvMBLHacJQDINwLMY2OTCbEW73RTrkDjYhZkXFURdOAC6DLPHXwOK YYOLDIyMCcagA5Driyco4TOpxkMyMBrDJlbYZBkuZMhzYmJO+yTKpC0wjzx9RbgOa0A5 qZ8o3Jedbczrmz3Ts0AKep6HIhvqX9IpdGThBR4xtUdm9sTHM6cLl/kJYazikl/v0ItO t/pZac6dt6+NviagrwQkd99saMfjW6J41S1FbhGRFyeki3uwUQgrCN+eKYEtNmVZqDR8 CZxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T5iEoUxqtE+RKgLCppji99ooivkYtyeHosdCGWVccyM=; b=GHd/lt9o41O7yKedXHjjx8oQmwzcn/RgGRk9xUs6QuxZh/RD+Y0LL+3zg4nLdj5ti4 zLxqSwSnbEybXA4tm64qs7UAMe4Xo652SgqPZqang3ulYHstsZox+BLQiwZz3O5kTGzA oaEeNeto4HxPwTClCBqqVG1bLI9O3TOa3ivN+sR9qZ20l96/cNyy7CrJ1q4aPeNa3n7e +oeYaSwLdgv+7OzcaVbhyVLMjf3UF3zpuHOX+pmuoj3EijnE9QZDLQGkhWXEJbFvmS13 m6Us2ymGG05lpl/ICQwoQSHCwMb/voF4EIgSO0i1XGk4M0HF/dtlC5rPSkrdSesKHBa+ 4AbA== X-Gm-Message-State: AOAM53185rY1/1uxtrOqEcneXypfYjlaoVo22EYg3QCJYuzu1eqFylBD 7ebsOAKOu3MZmuKotR+eBQXCPiiUxX8= X-Google-Smtp-Source: ABdhPJyGN66IxyXZ1e+t33IKroodWbJi+ZsK6q9Jcm4+Kag+n+RblseaXKqtUhYR0GXNMx6ObvCR8w== X-Received: by 2002:a17:906:71c4:: with SMTP id i4mr11222608ejk.347.1598364618980; Tue, 25 Aug 2020 07:10:18 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id k25sm10169806edx.96.2020.08.25.07.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2020 07:10:18 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 25 Aug 2020 16:09:21 +0200 Message-Id: <20200825140927.16433-13-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200825140927.16433-1-andreas.rheinhardt@gmail.com> References: <20200825140927.16433-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/19] avfilter/af_aiir: Avoid temporary buffer when drawing image 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" When creating the output video, a temporary buffer is used whose elments are only used three times: Once to store a value in it, once more to add the value of the preceding element of the temporary buffer to the current element and once more to add the current i. element to the i. element of another bufffer; the two latter operations were performed in one loop, whereas the first was performed in a loop of its own. Yet these loops can be combined and the temporary buffer avoided. All one needs to do is store the running total of the elements that currently are in the temporary buffer and keep the preceding value of the destination buffer (it is needed to calculate the next element of the current temporary buffer, i.e. it is needed to know by how much to increment the running total). Signed-off-by: Andreas Rheinhardt --- One could combine various allocations here and in many other places. But for now I'll leave this to a future patchset. libavfilter/af_aiir.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/libavfilter/af_aiir.c b/libavfilter/af_aiir.c index 3df25b4d9b..75bb79eb06 100644 --- a/libavfilter/af_aiir.c +++ b/libavfilter/af_aiir.c @@ -866,8 +866,9 @@ static void get_response(int channel, int format, double w, static void draw_response(AVFilterContext *ctx, AVFrame *out, int sample_rate) { AudioIIRContext *s = ctx->priv; - double *mag, *phase, *temp, *delay, min = DBL_MAX, max = -DBL_MAX; + double *mag, *phase, *delay, min = DBL_MAX, max = -DBL_MAX; double min_delay = DBL_MAX, max_delay = -DBL_MAX, min_phase, max_phase; + double tmp, oldphase; int prev_ymag = -1, prev_yphase = -1, prev_ydelay = -1; char text[32]; int ch, i; @@ -875,10 +876,9 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out, int sample_rate) memset(out->data[0], 0, s->h * out->linesize[0]); phase = av_malloc_array(s->w, sizeof(*phase)); - temp = av_malloc_array(s->w, sizeof(*temp)); mag = av_malloc_array(s->w, sizeof(*mag)); delay = av_malloc_array(s->w, sizeof(*delay)); - if (!mag || !phase || !delay || !temp) + if (!mag || !phase || !delay) goto end; ch = av_clip(s->ir_channel, 0, s->channels - 1); @@ -898,17 +898,15 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out, int sample_rate) max = fmax(max, mag[i]); } - temp[0] = 0.; - for (i = 0; i < s->w - 1; i++) { - double d = phase[i] - phase[i + 1]; - temp[i + 1] = ceil(fabs(d) / (2. * M_PI)) * 2. * M_PI * ((d > M_PI) - (d < -M_PI)); - } - + tmp = 0.; + oldphase = phase[0]; min_phase = phase[0]; max_phase = phase[0]; for (i = 1; i < s->w; i++) { - temp[i] += temp[i - 1]; - phase[i] += temp[i]; + double d = oldphase - phase[i]; + oldphase = phase[i]; + tmp += ceil(fabs(d) / (2. * M_PI)) * 2. * M_PI * ((d > M_PI) - (d < -M_PI)); + phase[i] += tmp; min_phase = fmin(min_phase, phase[i]); max_phase = fmax(max_phase, phase[i]); } @@ -975,7 +973,6 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out, int sample_rate) end: av_free(delay); - av_free(temp); av_free(phase); av_free(mag); }