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 EB73F4A53B for ; Wed, 1 May 2024 11:19:50 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5773A68D6B0; Wed, 1 May 2024 14:19:47 +0300 (EEST) Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0982768D697 for ; Wed, 1 May 2024 14:19:41 +0300 (EEST) Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2db101c11beso78546441fa.0 for ; Wed, 01 May 2024 04:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714562380; x=1715167180; darn=ffmpeg.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=GbDJqx0a3mGUAZe/k0hPiERxKcVLdg6tA/G4+DArZcY=; b=Ym8VmFwgHK5BwNOLy01P8DB3/u5E8pYNHCOgy2vCMIQIA9YDCTAyeVsjltIh+rxCUf 2eBybEl7rBbwgQL8WWJyuuhjipaSaq1c/iBXW3AM27HGFs10tYP2IzrBr3zVDtkWRBOC ICRfjUShEYFpSGS+om02vWRo90jPQOyc2RDuU/WhMgGYB1M0Pv/kx3SYYf3P7/zZZieM 6BGOmw9jxxbLkCwN3LjmxZ8S7juTz6NOM6LE6IF3EGwdJZr5v+FnJblr3cwN4BbYc5et 2aZdo+PzVVpSH9xy6AbHjOOhmi5Sr5Pp5RjOVOAUJ55ZfslAYv6Hsmm8Gx3lh0SSRqB0 HNIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714562380; x=1715167180; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GbDJqx0a3mGUAZe/k0hPiERxKcVLdg6tA/G4+DArZcY=; b=EgiwjlGkeFqfJ13R10arYMgT4j319Lgg/A++/ztQumNoA10j4+PddUmvRJW3FdBt+r WvGfh8Rn7BWY25b9dOqL1dlUvx4z7Xm+O6WtZG2QijhuBx4TJZHiAhTeLIwxIaUafpCZ wMEKSCyVbjx6q9uIfb/lolid9uQxawCI7BnlXkQx0Sm683GCWiEXLkKwW+HmFvsSYwmJ u0wyhySyOE8xE5kAxVx3Ikh7vieg6dBuhoNfyyghwFPT+orfZDG3PXJyyFE3Iu0hNYTB 6PyFfkII5/A+serMhGSMb7oi739ELsWUiz8vxlXVgBoz1CaPoj9hDO/yxuRY54+X0CKH 4KiQ== X-Gm-Message-State: AOJu0YygJJ6HP72GrFdm0Et0Z0pGeei5RAIgdMA1kbcHn9QQMIDGy4LX 3h5B/w1ZlgZg4uhWNCIkDgLVjmXOZtfM6uCeuR7BZLiFMokvJVHQrTR3aV+2yKc= X-Google-Smtp-Source: AGHT+IEhKFnwl2bZlXS0KWceSKwg7xp+aW7Vx+d66nT3jt6Y7yfyvFBRyTRFjrGi+eQ4m8WC4HSxlg== X-Received: by 2002:a05:651c:1022:b0:2df:820a:8f06 with SMTP id w2-20020a05651c102200b002df820a8f06mr1519094ljm.34.1714562379683; Wed, 01 May 2024 04:19:39 -0700 (PDT) Received: from smtpclient.apple ([2a02:e0:8bd6:600:c848:e80e:b784:83f3]) by smtp.gmail.com with ESMTPSA id g10-20020a7bc4ca000000b0041bf28aa11dsm1855286wmk.42.2024.05.01.04.19.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 May 2024 04:19:39 -0700 (PDT) From: Yigithan Yigit Message-Id: <111960FB-46DE-49F9-93E9-75AED1355BFD@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_6A758791-9D8A-4B3C-A6AE-DF2C5A7733F9" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.100.2.1.4\)) Date: Wed, 1 May 2024 14:19:28 +0300 In-Reply-To: To: FFmpeg development discussions and patches References: <4401208C-BB2A-4DA4-A2FD-1CB92DAF2FE9@gmail.com> <9D07803F-F9FC-4B97-934B-521E6680F0D4@gmail.com> <2860DBAC-6B04-468C-AD2E-24C31C64E2AC@gmail.com> X-Mailer: Apple Mail (2.3774.100.2.1.4) Subject: Re: [FFmpeg-devel] [PATCH] avfilter/af_volumedetect.c: Add 32bit float audio support 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 Cc: Thilo Borgmann Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --Apple-Mail=_6A758791-9D8A-4B3C-A6AE-DF2C5A7733F9 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Included mem.h and made some changes about readability. --Apple-Mail=_6A758791-9D8A-4B3C-A6AE-DF2C5A7733F9 Content-Disposition: attachment; filename=v8-avfilter-af_volumedetect.c-Add-32bit-float-audio-sup.patch Content-Type: application/octet-stream; x-unix-mode=0600; name="v8-avfilter-af_volumedetect.c-Add-32bit-float-audio-sup.patch" Content-Transfer-Encoding: quoted-printable =46rom=202e923b8d7aef283fce92609514436e7377744afc=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20yigithanyigit=20= =0ADate:=20Wed,=201=20May=202024=20= 13:46:25=20+0300=0ASubject:=20[PATCH]=20avfilter/af_volumedetect.c:=20= Add=2032bit=20float=20audio=20support=0A=0A---=0A=20= libavfilter/af_volumedetect.c=20|=20229=20= +++++++++++++++++++++++++---------=0A=201=20file=20changed,=20167=20= insertions(+),=2062=20deletions(-)=0A=0Adiff=20--git=20= a/libavfilter/af_volumedetect.c=20b/libavfilter/af_volumedetect.c=0A= index=208b001d1cf2..f6295e8da2=20100644=0A---=20= a/libavfilter/af_volumedetect.c=0A+++=20b/libavfilter/af_volumedetect.c=0A= @@=20-20,98=20+20,192=20@@=0A=20=0A=20#include=20= "libavutil/channel_layout.h"=0A=20#include=20"libavutil/avassert.h"=0A= +#include=20"libavutil/mem.h"=0A=20#include=20"audio.h"=0A=20#include=20= "avfilter.h"=0A=20#include=20"internal.h"=0A=20=0A+#define=20MAX_DB_FLT=20= 1024=0A+#define=20MAX_DB=2091=0A+#define=20HISTOGRAM_SIZE=200x10000=0A= +#define=20HISTOGRAM_SIZE_FLT=20(MAX_DB_FLT*2)=0A+=0A=20typedef=20struct=20= VolDetectContext=20{=0A-=20=20=20=20/**=0A-=20=20=20=20=20*=20Number=20= of=20samples=20at=20each=20PCM=20value.=0A-=20=20=20=20=20*=20= histogram[0x8000=20+=20i]=20is=20the=20number=20of=20samples=20at=20= value=20i.=0A-=20=20=20=20=20*=20The=20extra=20element=20is=20there=20= for=20symmetry.=0A-=20=20=20=20=20*/=0A-=20=20=20=20uint64_t=20= histogram[0x10001];=0A+=20=20=20=20uint64_t*=20histogram;=20///<=20for=20= integer=20number=20of=20samples=20at=20each=20PCM=20value,=20for=20float=20= number=20of=20samples=20at=20each=20dB=0A+=20=20=20=20uint64_t=20= nb_samples;=20///<=20number=20of=20samples=0A+=20=20=20=20double=20sum2;=20= =20=20=20=20=20=20=20=20///<=20sum=20of=20the=20squares=20of=20the=20= samples=0A+=20=20=20=20double=20max;=20=20=20=20=20=20=20=20=20=20///<=20= maximum=20sample=20value=0A+=20=20=20=20int=20is_float;=20=20=20=20=20=20= =20=20///<=20true=20if=20the=20input=20is=20in=20floating=20point=0A=20}=20= VolDetectContext;=0A=20=0A+static=20inline=20double=20logdb(double=20v,=20= enum=20AVSampleFormat=20sample_fmt)=0A+{=0A+=20=20=20=20if=20(sample_fmt=20= =3D=3D=20AV_SAMPLE_FMT_FLT)=20{=0A+=20=20=20=20=20=20=20=20if=20(!v)=0A+=20= =20=20=20=20=20=20=20=20=20=20=20return=20MAX_DB_FLT;=0A+=20=20=20=20=20=20= =20=20return=20-log10(v)=20*=2010;=0A+=20=20=20=20}=20else=20{=0A+=20=20=20= =20=20=20=20=20double=20d=20=3D=20v=20/=20(double)(0x8000=20*=200x8000);=0A= +=20=20=20=20=20=20=20=20if=20(!v)=0A+=20=20=20=20=20=20=20=20=20=20=20=20= return=20MAX_DB;=0A+=20=20=20=20=20=20=20=20return=20-log10(d)=20*=2010;=0A= +=20=20=20=20}=0A+}=0A+=0A+static=20void=20= update_float_stats(VolDetectContext=20*vd,=20float=20*audio_data)=0A+{=0A= +=20=20=20=20double=20sample;=0A+=20=20=20=20int=20idx;=0A+=20=20=20=20= if(!isnormal(*audio_data))=0A+=20=20=20=20=20=20=20=20return;=0A+=20=20=20= =20sample=20=3D=20fabsf(*audio_data);=0A+=20=20=20=20if=20(sample=20>=20= vd->max)=0A+=20=20=20=20=20=20=20=20vd->max=20=3D=20sample;=0A+=20=20=20=20= vd->sum2=20+=3D=20sample=20*=20sample;=0A+=20=20=20=20idx=20=3D=20= lrintf(floorf(logdb(sample=20*=20sample,=20AV_SAMPLE_FMT_FLT)))=20+=20= MAX_DB_FLT;=0A+=20=20=20=20vd->histogram[idx]++;=0A+=20=20=20=20= vd->nb_samples++;=0A+}=0A+=0A=20static=20int=20filter_frame(AVFilterLink=20= *inlink,=20AVFrame=20*samples)=0A=20{=0A=20=20=20=20=20AVFilterContext=20= *ctx=20=3D=20inlink->dst;=0A=20=20=20=20=20VolDetectContext=20*vd=20=3D=20= ctx->priv;=0A-=20=20=20=20int=20nb_samples=20=20=3D=20= samples->nb_samples;=0A=20=20=20=20=20int=20nb_channels=20=3D=20= samples->ch_layout.nb_channels;=0A=20=20=20=20=20int=20nb_planes=20=20=20= =3D=20nb_channels;=0A+=20=20=20=20int=20nb_samples=20=20=3D=20= samples->nb_samples;=0A=20=20=20=20=20int=20plane,=20i;=0A-=20=20=20=20= int16_t=20*pcm;=0A+=20=20=20=20int=20planar=20=3D=200;=0A=20=0A-=20=20=20= =20if=20(!av_sample_fmt_is_planar(samples->format))=20{=0A-=20=20=20=20=20= =20=20=20nb_samples=20*=3D=20nb_channels;=0A+=20=20=20=20planar=20=3D=20= av_sample_fmt_is_planar(samples->format);=0A+=20=20=20=20if=20(!planar)=0A= =20=20=20=20=20=20=20=20=20nb_planes=20=3D=201;=0A+=20=20=20=20if=20= (vd->is_float)=20{=0A+=20=20=20=20=20=20=20=20float=20*audio_data;=0A+=20= =20=20=20=20=20=20=20for=20(plane=20=3D=200;=20plane=20<=20nb_planes;=20= plane++)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20audio_data=20=3D=20= (float=20*)samples->extended_data[plane];=0A+=20=20=20=20=20=20=20=20=20=20= =20=20for=20(i=20=3D=200;=20i=20<=20nb_samples;=20i++)=20{=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20if=20(planar)=20{=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20update_float_stats(vd,=20= &audio_data[i]);=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20}=20= else=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= for=20(int=20j=20=3D=200;=20j=20<=20nb_channels;=20j++)=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= update_float_stats(vd,=20&audio_data[i=20*=20nb_channels=20+=20j]);=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20}=0A+=20=20=20=20=20=20=20=20= =20=20=20=20}=0A+=20=20=20=20=20=20=20=20}=0A+=20=20=20=20}=20else=20{=0A= +=20=20=20=20=20=20=20=20int16_t=20*pcm;=0A+=20=20=20=20=20=20=20=20for=20= (plane=20=3D=200;=20plane=20<=20nb_planes;=20plane++)=20{=0A+=20=20=20=20= =20=20=20=20=20=20=20=20pcm=20=3D=20(int16_t=20= *)samples->extended_data[plane];=0A+=20=20=20=20=20=20=20=20=20=20=20=20= for=20(i=20=3D=200;=20i=20<=20nb_samples;=20i++)=20{=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20if=20(planar)=20{=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20vd->histogram[pcm[i]=20+=20= 0x8000]++;=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= vd->nb_samples++;=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20}=20= else=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= for=20(int=20j=20=3D=200;=20j=20<=20nb_channels;=20j++)=20{=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= vd->histogram[pcm[i=20*=20nb_channels=20+=20j]=20+=200x8000]++;=0A+=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= vd->nb_samples++;=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20}=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20}=0A+=20=20=20= =20=20=20=20=20=20=20=20=20}=0A+=20=20=20=20=20=20=20=20}=0A=20=20=20=20=20= }=0A-=20=20=20=20for=20(plane=20=3D=200;=20plane=20<=20nb_planes;=20= plane++)=20{=0A-=20=20=20=20=20=20=20=20pcm=20=3D=20(int16_t=20= *)samples->extended_data[plane];=0A-=20=20=20=20=20=20=20=20for=20(i=20=3D= =200;=20i=20<=20nb_samples;=20i++)=0A-=20=20=20=20=20=20=20=20=20=20=20=20= vd->histogram[pcm[i]=20+=200x8000]++;=0A-=20=20=20=20}=0A-=0A=20=20=20=20= =20return=20ff_filter_frame(inlink->dst->outputs[0],=20samples);=0A=20}=0A= =20=0A-#define=20MAX_DB=2091=0A-=0A-static=20inline=20double=20= logdb(uint64_t=20v)=0A+static=20void=20print_stats(AVFilterContext=20= *ctx)=0A=20{=0A-=20=20=20=20double=20d=20=3D=20v=20/=20(double)(0x8000=20= *=200x8000);=0A-=20=20=20=20if=20(!v)=0A-=20=20=20=20=20=20=20=20return=20= MAX_DB;=0A-=20=20=20=20return=20-log10(d)=20*=2010;=0A+=20=20=20=20= VolDetectContext=20*vd=20=3D=20ctx->priv;=0A+=0A+=20=20=20=20if=20= (!vd->nb_samples)=0A+=20=20=20=20=20=20=20=20return;=0A+=20=20=20=20if=20= (vd->is_float)=20{=0A+=20=20=20=20=20=20=20=20int=20i,=20sum=20=3D=200;=0A= +=20=20=20=20=20=20=20=20av_log(ctx,=20AV_LOG_INFO,=20"n_samples:=20%"=20= PRId64=20"\n",=20vd->nb_samples);=0A+=20=20=20=20=20=20=20=20av_log(ctx,=20= AV_LOG_INFO,=20"mean_volume:=20%.1f=20dB\n",=20-logdb(vd->sum2=20/=20= vd->nb_samples,=20AV_SAMPLE_FMT_FLT));=0A+=20=20=20=20=20=20=20=20= av_log(ctx,=20AV_LOG_INFO,=20"max_volume:=20%.1f=20dB\n",=20= -2.0*logdb(vd->max,=20AV_SAMPLE_FMT_FLT));=0A+=20=20=20=20=20=20=20=20= for=20(i=20=3D=200;=20i=20<=20HISTOGRAM_SIZE_FLT=20&&=20= !vd->histogram[i];=20i++);=0A+=20=20=20=20=20=20=20=20for=20(;=20i=20>=3D=20= 0=20&&=20sum=20<=20vd->nb_samples=20/=201000;=20i++)=20{=0A+=20=20=20=20=20= =20=20=20=20=20=20=20if=20(!vd->histogram[i])=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20continue;=0A+=20=20=20=20=20=20=20=20=20=20=20=20= av_log(ctx,=20AV_LOG_INFO,=20"histogram_%ddb:=20%"=20PRId64=20"\n",=20= MAX_DB_FLT=20-=20i,=20vd->histogram[i]);=0A+=20=20=20=20=20=20=20=20=20=20= =20=20sum=20+=3D=20vd->histogram[i];=0A+=20=20=20=20=20=20=20=20}=0A+=20=20= =20=20}=20else=20{=0A+=20=20=20=20=20=20=20=20int=20i,=20max_volume,=20= shift;=0A+=20=20=20=20=20=20=20=20uint64_t=20nb_samples=20=3D=200,=20= power=20=3D=200,=20nb_samples_shift=20=3D=200,=20sum=20=3D=200;=0A+=20=20= =20=20=20=20=20=20uint64_t=20histdb[MAX_DB=20+=201]=20=3D=20{0};=0A+=20=20= =20=20=20=20=20=20for=20(i=20=3D=200;=20i=20<=200x10000;=20i++)=0A+=20=20= =20=20=20=20=20=20=20=20=20=20nb_samples=20+=3D=20vd->histogram[i];=0A+=20= =20=20=20=20=20=20=20av_log(ctx,=20AV_LOG_INFO,=20"n_samples:=20%"=20= PRId64=20"\n",=20nb_samples);=0A+=20=20=20=20=20=20=20=20/*=0A+=20=20=20=20= =20=20=20=20=20=20=20=20*=20If=20nb_samples=20>=201<<34,=20there=20is=20= a=20risk=20of=20overflow=20in=20the=0A+=20=20=20=20=20=20=20=20=20=20=20=20= *=20multiplication=20or=20the=20sum:=20shift=20all=20histogram=20values=20= to=20avoid=20that.=0A+=20=20=20=20=20=20=20=20=20=20=20=20*=20The=20= total=20number=20of=20samples=20must=20be=20recomputed=20to=20avoid=20= rounding=0A+=20=20=20=20=20=20=20=20=20=20=20=20*=20errors.=0A+=20=20=20=20= =20=20=20=20*/=0A+=20=20=20=20=20=20=20=20shift=20=3D=20= av_log2(nb_samples=20>>=2033);=0A+=20=20=20=20=20=20=20=20for=20(i=20=3D=20= 0;=20i=20<=200x10000;=20i++)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20= nb_samples_shift=20+=3D=20vd->histogram[i]=20>>=20shift;=0A+=20=20=20=20=20= =20=20=20=20=20=20=20power=20+=3D=20(i=20-=200x8000)=20*=20(i=20-=20= 0x8000)=20*=20(vd->histogram[i]=20>>=20shift);=0A+=20=20=20=20=20=20=20=20= }=0A+=20=20=20=20=20=20=20=20if=20(!nb_samples_shift)=0A+=20=20=20=20=20=20= =20=20=20=20=20=20return;=0A+=20=20=20=20=20=20=20=20power=20=3D=20= (power=20+=20nb_samples_shift=20/=202)=20/=20nb_samples_shift;=0A+=20=20=20= =20=20=20=20=20av_assert0(power=20<=3D=200x8000=20*=200x8000);=0A+=20=20=20= =20=20=20=20=20av_log(ctx,=20AV_LOG_INFO,=20"mean_volume:=20%.1f=20= dB\n",=20-logdb((double)power,=20AV_SAMPLE_FMT_S16));=0A+=20=20=20=20=20=20= =20=20max_volume=20=3D=200x8000;=0A+=20=20=20=20=20=20=20=20while=20= (max_volume=20>=200=20&&=20!vd->histogram[0x8000=20+=20max_volume]=20&&=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20!vd->histogram[0x8000=20= -=20max_volume])=0A+=20=20=20=20=20=20=20=20=20=20=20=20max_volume--;=0A= +=20=20=20=20=20=20=20=20av_log(ctx,=20AV_LOG_INFO,=20"max_volume:=20= %.1f=20dB\n",=20-logdb((double)(max_volume=20*=20max_volume),=20= AV_SAMPLE_FMT_S16));=0A+=20=20=20=20=20=20=20=20for=20(i=20=3D=200;=20i=20= <=200x10000;=20i++)=0A+=20=20=20=20=20=20=20=20=20=20=20=20= histdb[(int)logdb((double)(i=20-=200x8000)=20*=20(i=20-=200x8000),=20= AV_SAMPLE_FMT_S16)]=20+=3D=20vd->histogram[i];=0A+=20=20=20=20=20=20=20=20= for=20(i=20=3D=200;=20i=20<=3D=20MAX_DB=20&&=20!histdb[i];=20i++);=0A+=20= =20=20=20=20=20=20=20for=20(;=20i=20<=3D=20MAX_DB=20&&=20sum=20<=20= nb_samples=20/=201000;=20i++)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20= av_log(ctx,=20AV_LOG_INFO,=20"histogram_%ddb:=20%"=20PRId64=20"\n",=20= -i,=20histdb[i]);=0A+=20=20=20=20=20=20=20=20=20=20=20=20sum=20+=3D=20= histdb[i];=0A+=20=20=20=20=20=20=20=20}=0A+=20=20=20=20}=0A=20}=0A=20=0A= -static=20void=20print_stats(AVFilterContext=20*ctx)=0A+static=20int=20= config_output(AVFilterLink=20*outlink)=0A=20{=0A+=20=20=20=20= AVFilterContext=20*ctx=20=3D=20outlink->src;=0A=20=20=20=20=20= VolDetectContext=20*vd=20=3D=20ctx->priv;=0A-=20=20=20=20int=20i,=20= max_volume,=20shift;=0A-=20=20=20=20uint64_t=20nb_samples=20=3D=200,=20= power=20=3D=200,=20nb_samples_shift=20=3D=200,=20sum=20=3D=200;=0A-=20=20= =20=20uint64_t=20histdb[MAX_DB=20+=201]=20=3D=20{=200=20};=0A-=0A-=20=20=20= =20for=20(i=20=3D=200;=20i=20<=200x10000;=20i++)=0A-=20=20=20=20=20=20=20= =20nb_samples=20+=3D=20vd->histogram[i];=0A-=20=20=20=20av_log(ctx,=20= AV_LOG_INFO,=20"n_samples:=20%"PRId64"\n",=20nb_samples);=0A-=20=20=20=20= if=20(!nb_samples)=0A-=20=20=20=20=20=20=20=20return;=0A+=20=20=20=20= size_t=20histogram_size;=0A=20=0A-=20=20=20=20/*=20If=20nb_samples=20>=20= 1<<34,=20there=20is=20a=20risk=20of=20overflow=20in=20the=0A-=20=20=20=20= =20=20=20multiplication=20or=20the=20sum:=20shift=20all=20histogram=20= values=20to=20avoid=20that.=0A-=20=20=20=20=20=20=20The=20total=20number=20= of=20samples=20must=20be=20recomputed=20to=20avoid=20rounding=0A-=20=20=20= =20=20=20=20errors.=20*/=0A-=20=20=20=20shift=20=3D=20av_log2(nb_samples=20= >>=2033);=0A-=20=20=20=20for=20(i=20=3D=200;=20i=20<=200x10000;=20i++)=20= {=0A-=20=20=20=20=20=20=20=20nb_samples_shift=20+=3D=20vd->histogram[i]=20= >>=20shift;=0A-=20=20=20=20=20=20=20=20power=20+=3D=20(i=20-=200x8000)=20= *=20(i=20-=200x8000)=20*=20(vd->histogram[i]=20>>=20shift);=0A-=20=20=20=20= }=0A-=20=20=20=20if=20(!nb_samples_shift)=0A-=20=20=20=20=20=20=20=20= return;=0A-=20=20=20=20power=20=3D=20(power=20+=20nb_samples_shift=20/=20= 2)=20/=20nb_samples_shift;=0A-=20=20=20=20av_assert0(power=20<=3D=20= 0x8000=20*=200x8000);=0A-=20=20=20=20av_log(ctx,=20AV_LOG_INFO,=20= "mean_volume:=20%.1f=20dB\n",=20-logdb(power));=0A-=0A-=20=20=20=20= max_volume=20=3D=200x8000;=0A-=20=20=20=20while=20(max_volume=20>=200=20= &&=20!vd->histogram[0x8000=20+=20max_volume]=20&&=0A-=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= !vd->histogram[0x8000=20-=20max_volume])=0A-=20=20=20=20=20=20=20=20= max_volume--;=0A-=20=20=20=20av_log(ctx,=20AV_LOG_INFO,=20"max_volume:=20= %.1f=20dB\n",=20-logdb(max_volume=20*=20max_volume));=0A-=0A-=20=20=20=20= for=20(i=20=3D=200;=20i=20<=200x10000;=20i++)=0A-=20=20=20=20=20=20=20=20= histdb[(int)logdb((i=20-=200x8000)=20*=20(i=20-=200x8000))]=20+=3D=20= vd->histogram[i];=0A-=20=20=20=20for=20(i=20=3D=200;=20i=20<=3D=20MAX_DB=20= &&=20!histdb[i];=20i++);=0A-=20=20=20=20for=20(;=20i=20<=3D=20MAX_DB=20= &&=20sum=20<=20nb_samples=20/=201000;=20i++)=20{=0A-=20=20=20=20=20=20=20= =20av_log(ctx,=20AV_LOG_INFO,=20"histogram_%ddb:=20%"PRId64"\n",=20i,=20= histdb[i]);=0A-=20=20=20=20=20=20=20=20sum=20+=3D=20histdb[i];=0A+=20=20=20= =20vd->is_float=20=3D=20outlink->format=20=3D=3D=20AV_SAMPLE_FMT_FLT=20= ||=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= outlink->format=20=3D=3D=20AV_SAMPLE_FMT_FLTP;=0A+=0A+=20=20=20=20if=20= (!vd->is_float)=20{=0A+=20=20=20=20=20=20=20=20/*=0A+=20=20=20=20=20=20=20= =20*=20Number=20of=20samples=20at=20each=20PCM=20value.=0A+=20=20=20=20=20= =20=20=20*=20Only=20used=20for=20integer=20formats.=0A+=20=20=20=20=20=20= =20=20*=20For=2016=20bit=20signed=20PCM=20there=20are=2065536.=0A+=20=20=20= =20=20=20=20=20*=20histogram[0x8000=20+=20i]=20is=20the=20number=20of=20= samples=20at=20value=20i.=0A+=20=20=20=20=20=20=20=20*=20The=20extra=20= element=20is=20there=20for=20symmetry.=0A+=20=20=20=20=20=20=20=20*/=0A+=20= =20=20=20=20=20=20=20histogram_size=20=3D=20HISTOGRAM_SIZE=20+=201;=0A+=20= =20=20=20}=20else=20{=0A+=20=20=20=20=20=20=20=20/*=0A+=20=20=20=20=20=20= =20=20*=20The=20histogram=20is=20used=20to=20store=20the=20number=20of=20= samples=20at=20each=20dB=0A+=20=20=20=20=20=20=20=20*=20instead=20of=20= the=20number=20of=20samples=20at=20each=20PCM=20value.=0A+=20=20=20=20=20= =20=20=20*/=0A+=20=20=20=20=20=20=20=20histogram_size=20=3D=20= HISTOGRAM_SIZE_FLT=20+=201;=0A=20=20=20=20=20}=0A+=20=20=20=20= vd->histogram=20=3D=20av_calloc(histogram_size,=20sizeof(uint64_t));=0A+=20= =20=20=20if=20(!vd->histogram)=0A+=20=20=20=20=20=20=20=20return=20= AVERROR(ENOMEM);=0A+=20=20=20=20return=200;=0A=20}=0A=20=0A=20static=20= av_cold=20void=20uninit(AVFilterContext=20*ctx)=0A=20{=0A+=20=20=20=20= VolDetectContext=20*vd=20=3D=20ctx->priv;=0A=20=20=20=20=20= print_stats(ctx);=0A+=20=20=20=20if=20(vd->histogram)=0A+=20=20=20=20=20=20= =20=20av_freep(&vd->histogram);=0A=20}=0A=20=0A=20static=20const=20= AVFilterPad=20volumedetect_inputs[]=20=3D=20{=0A@@=20-122,6=20+216,14=20= @@=20static=20const=20AVFilterPad=20volumedetect_inputs[]=20=3D=20{=0A=20= =20=20=20=20},=0A=20};=0A=20=0A+static=20const=20AVFilterPad=20= volumedetect_outputs[]=20=3D=20{=0A+=20=20=20=20{=0A+=20=20=20=20=20=20=20= =20.name=20=20=20=20=20=20=20=20=20=3D=20"default",=0A+=20=20=20=20=20=20= =20=20.type=20=20=20=20=20=20=20=20=20=3D=20AVMEDIA_TYPE_AUDIO,=0A+=20=20= =20=20=20=20=20=20.config_props=20=3D=20config_output,=0A+=20=20=20=20},=0A= +};=0A+=0A=20const=20AVFilter=20ff_af_volumedetect=20=3D=20{=0A=20=20=20=20= =20.name=20=20=20=20=20=20=20=20=20=20=3D=20"volumedetect",=0A=20=20=20=20= =20.description=20=20=20=3D=20NULL_IF_CONFIG_SMALL("Detect=20audio=20= volume."),=0A@@=20-129,6=20+231,9=20@@=20const=20AVFilter=20= ff_af_volumedetect=20=3D=20{=0A=20=20=20=20=20.uninit=20=20=20=20=20=20=20= =20=3D=20uninit,=0A=20=20=20=20=20.flags=20=20=20=20=20=20=20=20=20=3D=20= AVFILTER_FLAG_METADATA_ONLY,=0A=20=20=20=20=20= FILTER_INPUTS(volumedetect_inputs),=0A-=20=20=20=20= FILTER_OUTPUTS(ff_audio_default_filterpad),=0A-=20=20=20=20= FILTER_SAMPLEFMTS(AV_SAMPLE_FMT_S16,=20AV_SAMPLE_FMT_S16P),=0A+=20=20=20=20= FILTER_OUTPUTS(volumedetect_outputs),=0A+=20=20=20=20= FILTER_SAMPLEFMTS(AV_SAMPLE_FMT_S16,=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20AV_SAMPLE_FMT_S16P,=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20AV_SAMPLE_FMT_FLT,=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= AV_SAMPLE_FMT_FLTP),=0A=20};=0A--=20=0A2.44.0=0A=0A= --Apple-Mail=_6A758791-9D8A-4B3C-A6AE-DF2C5A7733F9 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". --Apple-Mail=_6A758791-9D8A-4B3C-A6AE-DF2C5A7733F9--