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 6D58848D19 for ; Sun, 24 Mar 2024 21:12:49 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DF18868D3F4; Sun, 24 Mar 2024 23:12:46 +0200 (EET) Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5DD7468D231 for ; Sun, 24 Mar 2024 23:12:40 +0200 (EET) Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-56c12c73ed8so331285a12.2 for ; Sun, 24 Mar 2024 14:12:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711314758; x=1711919558; 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=ZxFD/5F1eSyFUkmoG9UmLk3tUT9MKp+KRORDVJulgYQ=; b=UtDw0rWLm0+K3lCwNItOxiR/RMfujeo1HPcWIgkqUdcGKTfG/2k2srZguSkFvwjbRO mwktNbmuebTd7eSsZnIBxyIQO/OUTos9NrATLdWVbGZK5oxsZ5YdW494hj0nMaE1paNw YHw3V7U1TVV/S9zQC2SlqwNYVF+2Le9rsAdNc8RTFdfKyqpMeoLQy/M61vSk4D464EiS 8F9V0XYWf3g3PI0dammJfVddtnK0rsN/66UxTRjDsopHBT3F1AuVaTEF34dW3SaK9MSR FbWoKT3vzPgmox+tuOjvb+xeLzrZT+TtLYsxsFtzK76rZ2KMI8EqpCFxNWXA4Wgqg+5A uwPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711314758; x=1711919558; 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=ZxFD/5F1eSyFUkmoG9UmLk3tUT9MKp+KRORDVJulgYQ=; b=s6l2tXTlB0NskuRBBXy9ePAjNd7M6nWVbeyfEABHvGKP5MWyvQVm+0vpP+FO1RZux1 guTzL5PFJjHhotTzcDIE1DLYBD9u7D9PLZZRFSnpHYro0oH92nfbqdmROGNnf9+HsGLl +Bnq7kOjeFQ+WCcXESfRLR9IqVHoMAUv36YyblwZB9WIO8H83uQKZP7kzrgC1mSWYRoM 8hzpEW91Bsuc2uBP6YO4EukJxwBATo9Ll2z7O+34DEfMZ4XrvhKf8XDqLgK+xd3JD6HA 4EBJaBiQR8cei0uW7vupPodQSQx+nparkEgFBZyIYZ+sUAitTZ/PHPqeTwCc47zD3s9F 24nQ== X-Gm-Message-State: AOJu0Yzrm5/wgLIG61dCfwfociWj1Ok9gMKec0UTukfztrUDJ4E99fzm jv5TzX8W4TIswIsxG4WsCNsAR48EtAXmCw651HrUWdZCcBxrHCjD1NkzO0o= X-Google-Smtp-Source: AGHT+IF95GwYXM6uWXE7pDrF+6ium0UVkWtOfWXud5D0SYst65icyAXcor/PwesxRR6YWm0ZTFbiww== X-Received: by 2002:a50:8703:0:b0:567:737f:e910 with SMTP id i3-20020a508703000000b00567737fe910mr4226712edb.3.1711314758336; Sun, 24 Mar 2024 14:12:38 -0700 (PDT) Received: from smtpclient.apple ([2a02:e0:8bc4:3100:78ed:c65f:f07c:5284]) by smtp.gmail.com with ESMTPSA id r10-20020a508d8a000000b0056ba017ca7fsm2196635edh.87.2024.03.24.14.12.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2024 14:12:38 -0700 (PDT) From: =?utf-8?Q?Yi=C4=9Fithan_Yi=C4=9Fit?= Message-Id: <2860DBAC-6B04-468C-AD2E-24C31C64E2AC@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_788C8A07-0C35-4B7A-AF90-86D3A764B777" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.100.2.1.4\)) Date: Mon, 25 Mar 2024 00:12:26 +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> 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=_788C8A07-0C35-4B7A-AF90-86D3A764B777 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Fixed some bugs that I not realized on previous commits. --Apple-Mail=_788C8A07-0C35-4B7A-AF90-86D3A764B777 Content-Disposition: attachment; filename*0=v2-0001-avfilter-af_volumedetect.c-Add-32bit-float-audio-sup.pat; filename*1=ch Content-Type: application/octet-stream; x-unix-mode=0644; name="v2-0001-avfilter-af_volumedetect.c-Add-32bit-float-audio-sup.patch" Content-Transfer-Encoding: quoted-printable =46rom=2098c6360c5e258311e6d1d4e6e9eeba9a86eab6a8=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20yigithanyigit=20=0A= Date:=20Tue,=2012=20Mar=202024=2001:27:59=20+0300=0ASubject:=20[PATCH]=20= avfilter/af_volumedetect.c:=20Add=2032bit=20float=20audio=20support=0A=0A= Fixes=20#9613=0A=0Aa=0A---=0A=20libavfilter/af_volumedetect.c=20|=20225=20= ++++++++++++++++++++++++----------=0A=201=20file=20changed,=20163=20= insertions(+),=2062=20deletions(-)=0A=0Adiff=20--git=20= a/libavfilter/af_volumedetect.c=20b/libavfilter/af_volumedetect.c=0A= index=208b001d1cf2..ee2228ccca=20100644=0A---=20= a/libavfilter/af_volumedetect.c=0A+++=20b/libavfilter/af_volumedetect.c=0A= @@=20-24,94=20+24,184=20@@=0A=20#include=20"avfilter.h"=0A=20#include=20= "internal.h"=0A=20=0A+#define=20NOISE_FLOOR_DB_FLT=20-758=0A+#define=20= MAX_DB_FLT=20770=0A+#define=20MAX_DB=2091=0A+#define=20HISTOGRAM_SIZE=20= 0x10000=0A+=0A=20typedef=20struct=20VolDetectContext=20{=0A-=20=20=20=20= /**=0A-=20=20=20=20=20*=20Number=20of=20samples=20at=20each=20PCM=20= value.=0A-=20=20=20=20=20*=20histogram[0x8000=20+=20i]=20is=20the=20= number=20of=20samples=20at=20value=20i.=0A-=20=20=20=20=20*=20The=20= extra=20element=20is=20there=20for=20symmetry.=0A-=20=20=20=20=20*/=0A-=20= =20=20=20uint64_t=20histogram[0x10001];=0A+=20=20=20=20uint64_t*=20= histogram;=20///<=20for=20integer=20number=20of=20samples=20at=20each=20= PCM=20value,=20for=20float=20number=20of=20samples=20at=20each=20dB=0A+=20= =20=20=20uint64_t=20nb_samples;=20///<=20number=20of=20samples=0A+=20=20=20= =20double=20sum2;=20=20=20=20=20=20=20=20=20///<=20sum=20of=20the=20= squares=20of=20the=20samples=0A+=20=20=20=20double=20max;=20=20=20=20=20=20= =20=20=20=20///<=20maximum=20sample=20value=0A+=20=20=20=20int=20= is_float;=20=20=20=20=20=20=20=20///<=20true=20if=20the=20input=20is=20= in=20floating=20point=0A=20}=20VolDetectContext;=0A=20=0A+static=20= inline=20double=20logdb(double=20v,=20enum=20AVSampleFormat=20= sample_fmt)=0A+{=0A+=20=20=20=20if=20(sample_fmt=20=3D=3D=20= AV_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=20= return=2010.0=20*=20log10(v);=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=20max_sample;=0A+=20=20=20=20max_sample=20=3D=20= fabsf(*audio_data);=0A+=20=20=20=20if=20(max_sample=20>=20vd->max)=0A+=20= =20=20=20=20=20=20=20vd->max=20=3D=20max_sample;=0A+=20=20=20=20vd->sum2=20= +=3D=20*audio_data=20*=20*audio_data;=0A+=20=20=20=20= vd->histogram[(int)logdb(*audio_data=20*=20*audio_data,=20= AV_SAMPLE_FMT_FLT)=20+=20MAX_DB_FLT]++;=0A+=20=20=20=20vd->nb_samples++;=0A= +}=0A+=0A=20static=20int=20filter_frame(AVFilterLink=20*inlink,=20= AVFrame=20*samples)=0A=20{=0A=20=20=20=20=20AVFilterContext=20*ctx=20=3D=20= inlink->dst;=0A=20=20=20=20=20VolDetectContext=20*vd=20=3D=20ctx->priv;=0A= -=20=20=20=20int=20nb_samples=20=20=3D=20samples->nb_samples;=0A=20=20=20= =20=20int=20nb_channels=20=3D=20samples->ch_layout.nb_channels;=0A=20=20=20= =20=20int=20nb_planes=20=20=20=3D=20nb_channels;=0A+=20=20=20=20int=20= planar=20=20=20=20=20=20=3D=200;=0A=20=20=20=20=20int=20plane,=20i;=0A-=20= =20=20=20int16_t=20*pcm;=0A=20=0A-=20=20=20=20if=20= (!av_sample_fmt_is_planar(samples->format))=20{=0A-=20=20=20=20=20=20=20=20= nb_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<=20samples->nb_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=20= update_float_stats(vd,=20&audio_data[i]);=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20}=20else=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20for=20(int=20j=20=3D=200;=20j=20<=20nb_channels;=20= j++)=0A+=20=20=20=20=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=20*=20nb_channels=20+=20= j]);=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= else=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<=20samples->nb_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=20double=20rms;=0A+=20=20=20=20= =20=20=20=20int=20i,=20sum=20=3D=200;=0A+=20=20=20=20=20=20=20=20= av_log(ctx,=20AV_LOG_INFO,=20"n_samples:=20%"=20PRId64=20"\n",=20= vd->nb_samples);=0A+=20=20=20=20=20=20=20=20av_log(ctx,=20AV_LOG_INFO,=20= "mean_volume:=20%.1f=20dB\n",=20logdb(vd->sum2=20/=20vd->nb_samples,=20= AV_SAMPLE_FMT_FLT));=0A+=20=20=20=20=20=20=20=20av_log(ctx,=20= AV_LOG_INFO,=20"max_volume:=20%.1f=20dB\n",=20logdb(vd->max=20*=20= vd->max,=20AV_SAMPLE_FMT_FLT));=0A+=20=20=20=20=20=20=20=20for=20(i=20=3D=20= MAX_DB_FLT=20-=20NOISE_FLOOR_DB_FLT;=20i=20>=3D=200=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",=20i,=20= histdb[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=0A-=20=20=20=20= /*=20If=20nb_samples=20>=201<<34,=20there=20is=20a=20risk=20of=20= overflow=20in=20the=0A-=20=20=20=20=20=20=20multiplication=20or=20the=20= sum:=20shift=20all=20histogram=20values=20to=20avoid=20that.=0A-=20=20=20= =20=20=20=20The=20total=20number=20of=20samples=20must=20be=20recomputed=20= to=20avoid=20rounding=0A-=20=20=20=20=20=20=20errors.=20*/=0A-=20=20=20=20= shift=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=20= nb_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=20return;=0A-=20=20=20=20= power=20=3D=20(power=20+=20nb_samples_shift=20/=202)=20/=20= nb_samples_shift;=0A-=20=20=20=20av_assert0(power=20<=3D=200x8000=20*=20= 0x8000);=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=20max_volume=20=3D=20= 0x8000;=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=20vd->histogram=20=3D=20av_calloc(HISTOGRAM_SIZE=20+=20= 1,=20sizeof(uint64_t));=0A+=20=20=20=20=20=20=20=20if=20(!vd->histogram)=0A= +=20=20=20=20=20=20=20=20=20=20=20=20return=20AVERROR(ENOMEM);=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*=20The=20range=20of=20dB=20is=20from=20-758=20to=20770.=0A+=20=20= =20=20=20=20=20=20*/=0A+=20=20=20=20=20=20=20=20vd->histogram=20=3D=20= av_calloc(MAX_DB_FLT=20-=20NOISE_FLOOR_DB_FLT=20+=201,=20= sizeof(uint64_t));=0A+=20=20=20=20=20=20=20=20if=20(!vd->histogram)=0A+=20= =20=20=20=20=20=20=20=20=20=20=20return=20AVERROR(ENOMEM);=0A=20=20=20=20= =20}=0A+=20=20=20=20return=200;=0A=20}=0A=20=0A=20static=20av_cold=20= void=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+212,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+227,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=_788C8A07-0C35-4B7A-AF90-86D3A764B777 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_788C8A07-0C35-4B7A-AF90-86D3A764B777 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=_788C8A07-0C35-4B7A-AF90-86D3A764B777--