From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 4862A47A36 for ; Thu, 28 Dec 2023 18:49:28 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 604E368CCAF; Thu, 28 Dec 2023 20:49:27 +0200 (EET) Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 846E968BF73 for ; Thu, 28 Dec 2023 20:49:21 +0200 (EET) Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a2772011f8dso64606266b.2 for ; Thu, 28 Dec 2023 10:49:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703789360; x=1704394160; darn=ffmpeg.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=fRBbRGTGAVx2Qu2pZL5iACM8V2e/GKl1Fi44vYaz7HU=; b=b1h5eBu1VqpcGwpA1tQLILkWunWEWflCGfsll5kPkDcXE7LavInv45nSn7jZwe/y+W jj7jqrweDglkFW9K4tT/NuJDORVlwiPSBTLNpMOBrOZqW7ZattE1il4/jaqbUwQKDcZM Ao6X52TRjQ2hWk4lIIm4zEPbgeLRhzwuTk5P/peaBHj/PymFEkAKev8wngiVWmRhu7Wu Zuf/YDvFxRC2FyhporKyzokys2Epgd5NoAscLaYScCgkM9IKyYLuWFErbxBi1HWpt0rC VGi/pVmQ1zmBfHCT1ICG6st6j5SkTVVxf5rjAd6cjl5uROcLMkHs2NF+u/t/KZqPuKt3 EH9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703789360; x=1704394160; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=fRBbRGTGAVx2Qu2pZL5iACM8V2e/GKl1Fi44vYaz7HU=; b=FUcyGu4JfTSsj7Oi/cxGE4jJ0UCWfqazP8bFvkbCm1mb4i+DI0eCuPFtfwr8Gf2wPi sYtZe6kRJZB9TFB+20IER7/rLhXMs+wMdNUxr1SMc/1byPO8hOSt4BBbk7Yn+G2iUYut qmQwHc/hP6hZUV8/ZHYoG74juVIzAPSOmXJ7ZCfg27zotvgsOwkxiNMjzWvYojFWuHT6 ZzL8u27hy3gqykHiH/mppkVlIA96W/fea+HaicAX4QUn1riv7ZwqAmYsGfe5bO9dQrKh 3C2Uf1xAisqgjGTYWWKpZHz7RoRcNhwcrdezl3hfjOURUHjIhk8u3nZ/1b1w4T/M4Rid RD2g== X-Gm-Message-State: AOJu0YyGTh/x3E7jazk32hfi4Ua+Td61V7Z/anhL4aR+81NRm2kTeEN9 uWDoF2X+WbL1uxjbPMawj3BZdwHXlIg= X-Google-Smtp-Source: AGHT+IHcGrL6ebHpq9uz6UF22YutF1gYMaNAbppM7ymS6vp3IBTvBh2ufQ3vIizqxP0t3BApkRxk3g== X-Received: by 2002:a17:906:f744:b0:a26:9534:92f9 with SMTP id jp4-20020a170906f74400b00a26953492f9mr3874233ejb.106.1703789359900; Thu, 28 Dec 2023 10:49:19 -0800 (PST) Received: from mariano (dynamic-adsl-84-220-189-10.clienti.tiscali.it. [84.220.189.10]) by smtp.gmail.com with ESMTPSA id p10-20020a170907910a00b00a26aaa47cc0sm7119800ejq.129.2023.12.28.10.49.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 10:49:19 -0800 (PST) Received: by mariano (Postfix, from userid 1000) id 2D900BFCDC; Thu, 28 Dec 2023 19:49:18 +0100 (CET) Date: Thu, 28 Dec 2023 19:49:18 +0100 From: Stefano Sabatini To: FFmpeg development discussions and patches Message-ID: Mail-Followup-To: FFmpeg development discussions and patches References: <20231228003839.860894-1-stefasab@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="dNJjSiYsHF26nLah" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.1.4 (2021-12-11) Subject: Re: [FFmpeg-devel] [PATCH 2/2] lavfi/setpts: introduce rand() function in expression X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --dNJjSiYsHF26nLah Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On date Thursday 2023-12-28 16:00:57 +0100, Stefano Sabatini wrote: > On date Thursday 2023-12-28 12:02:59 +0100, Andreas Rheinhardt wrote: > > Stefano Sabatini: > > > This is useful to simulate random jitter. > > > --- > > > Changelog | 1 + > > > doc/filters.texi | 10 +++++++++- > > > libavfilter/setpts.c | 39 +++++++++++++++++++++++++++++++++------ > > > 3 files changed, 43 insertions(+), 7 deletions(-) [...] > > Why is this added here and not in lavu/eval so that it is available with > > all expressions? > > There is no specific reason. Sometimes you need to have a control over > the seed, in this case you need to provide the PRNG context. > > For the general case, probably we can place a global LFG in the eval > module and fetch its generated values. Another possible solution in attachment, leveraging the same affine PRNG used in random(). For other use cases you might need to use a high-quality PRNG and this might not be good enough. --dNJjSiYsHF26nLah Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-lavu-eval-add-randomi-function-to-compute-random-val.patch" >From 4dc5213b0913a2585f75dfd03b497ca2efc093de Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 28 Dec 2023 19:09:22 +0100 Subject: [PATCH] lavu/eval: add randomi function to compute random value in interval --- libavutil/eval.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libavutil/eval.c b/libavutil/eval.c index 344bebbf69..e94597ccf4 100644 --- a/libavutil/eval.c +++ b/libavutil/eval.c @@ -164,7 +164,7 @@ struct AVExpr { e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc, e_round, e_sqrt, e_not, e_random, e_hypot, e_gcd, e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between, e_clip, e_atan2, e_lerp, - e_sgn, + e_sgn, e_randomi } type; double value; // is sign in other types int const_index; @@ -230,13 +230,23 @@ static double eval_expr(Parser *p, AVExpr *e) av_log(p, level, "%f\n", x); return x; } - case e_random:{ +#define COMPUTE_RANDOM(seed_) (seed_)*1664525+1013904223 + case e_random:{ int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1); uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx]; - r= r*1664525+1013904223; + r = COMPUTE_RANDOM(r); p->var[idx]= r; return e->value * (r * (1.0/UINT64_MAX)); } + case e_randomi: { + int idx = av_clip(eval_expr(p, e->param[0]), 0, VARS-1); + uint64_t r = isnan(p->var[idx]) ? 0 : p->var[idx]; + r = COMPUTE_RANDOM(r); + p->var[idx] = r; + double min = eval_expr(p, e->param[1]); + double max = eval_expr(p, e->param[2]); + return min + (max - min) * r / UINT64_MAX; + } case e_while: { double d = NAN; while (eval_expr(p, e->param[0])) @@ -463,6 +473,7 @@ static int parse_primary(AVExpr **e, Parser *p) else if (strmatch(next, "pow" )) d->type = e_pow; else if (strmatch(next, "print" )) d->type = e_print; else if (strmatch(next, "random")) d->type = e_random; + else if (strmatch(next, "randomi")) d->type = e_randomi; else if (strmatch(next, "hypot" )) d->type = e_hypot; else if (strmatch(next, "gcd" )) d->type = e_gcd; else if (strmatch(next, "if" )) d->type = e_if; @@ -676,6 +687,7 @@ static int verify_expr(AVExpr *e) case e_between: case e_clip: case e_lerp: + case e_randomi: return verify_expr(e->param[0]) && verify_expr(e->param[1]) && verify_expr(e->param[2]); -- 2.34.1 --dNJjSiYsHF26nLah Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". --dNJjSiYsHF26nLah--