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 25F224A0E2 for ; Wed, 20 Mar 2024 20:47:12 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0D48B68D4F3; Wed, 20 Mar 2024 22:47:10 +0200 (EET) Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 317D268D4BA for ; Wed, 20 Mar 2024 22:47:03 +0200 (EET) Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a450bedffdfso33475666b.3 for ; Wed, 20 Mar 2024 13:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710967622; x=1711572422; darn=ffmpeg.org; h=to:date:message-id:subject:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=b9bIwFcQ2KQ4Gj1gk0h5fK2nfh8FVimD6AQidkZbrEY=; b=gDLT8u2mqCFKsjEvJFtdgO8qVWI6a0nXJNd9njxWCZXwGY4JlNENysSbqblbUNbX+M 6yST2N/F+aGzYJccGqFssfN4q+wpu2owO6ij6N6/PrHBtWuugzoGriw5qJ1acNN2yZzG E1x3LfPJbrUdX4C07G0Jl9KgTYg3l46FQTuItzdFwtHi0ewfMHgzmEOhIMnbW5s0Ad3w 41KAV1MHyjyB5LaaJMnGYPTOcS/QkQ1Wj843ca2aRpMWw6NrPyxJqWqeR3qmk4p4YD2u 4TckEZVhKE9J4VQEuulgW03sxqs97a3/5gF8FnngZ2O1FQJooAS07fM54MQHM0sVvv4b BDag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710967622; x=1711572422; h=to:date:message-id:subject:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=b9bIwFcQ2KQ4Gj1gk0h5fK2nfh8FVimD6AQidkZbrEY=; b=tuGETC24lLPoTWYPdCx78Q71Q4BZ1cumupKGg6aopK1umG0Y0md68TIBLI++luvYyk F/Soepz3YFGE/3XvhiMXls7aScbpKRhmf6X9eBrX96d7AtQFjMxpmZk2UW/NWUQyItmu 9aLIAXF6ebK7ySd+OE4uQG2Jw7qGpPE15wM4LCbhJ9lLQPTewA/DV4D+wj8qF1mc2s3C aFxnfAzlLvPfDaGsOz6tiZthKZUG5/8R1FvB2Rv0ZvfrWwJIPDLlQ9hHyELG1jSU7PBw UHe+qXLRQ4Lv8sZxwVqrrJyECZxftvry/z5zbFZTcFpRLJas++S28K1yhY3TfXPuiMvl 4IiQ== X-Gm-Message-State: AOJu0Yz2olwbZj4Lgl2HiMe6gdkWOOPiapg1XXp21SC0xM/ohO8CjKI4 C3K6BUZQQVIyP85Wi3CT8OuI6if/5jJ3oyMxsvZ5O5+IJkqvXAEwUxtohYtPsQ== X-Google-Smtp-Source: AGHT+IFAizRyI9/EO6Fq7EKSlLayyDOapkay06IfLP0NPQ3rqW6KCfyi3qCOYqkfPkUkmxxaJK01mA== X-Received: by 2002:a17:907:7284:b0:a46:9e7d:a3e4 with SMTP id dt4-20020a170907728400b00a469e7da3e4mr10996814ejc.46.1710967621494; Wed, 20 Mar 2024 13:47:01 -0700 (PDT) Received: from smtpclient.apple ([2a02:e0:8bc4:3100:54db:e900:9c61:7b91]) by smtp.gmail.com with ESMTPSA id dm18-20020a170907949200b00a45200fe2b5sm7628596ejc.224.2024.03.20.13.47.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Mar 2024 13:47:01 -0700 (PDT) From: =?utf-8?Q?Yi=C4=9Fithan_Yi=C4=9Fit?= Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.100.2.1.4\)) Message-Id: <4401208C-BB2A-4DA4-A2FD-1CB92DAF2FE9@gmail.com> Date: Wed, 20 Mar 2024 23:46:49 +0300 To: ffmpeg-devel@ffmpeg.org X-Mailer: Apple Mail (2.3774.100.2.1.4) X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [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 Content-Type: multipart/mixed; boundary="===============8867135879244322321==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============8867135879244322321== Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-avfilter-af_volumedetect.c-Add-32bit-float-audio-sup.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=0001-avfilter-af_volumedetect.c-Add-32bit-float-audio-sup.patch =46rom=20740de9d733bcc182eb09779b256300af18a8df5d=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---=0A=20libavfilter/af_volumedetect.c=20|=20237=20= ++++++++++++++++++++++++++--------=0A=201=20file=20changed,=20182=20= insertions(+),=2055=20deletions(-)=0A=0Adiff=20--git=20= a/libavfilter/af_volumedetect.c=20b/libavfilter/af_volumedetect.c=0A= index=208b001d1cf2..fe5d7bd08a=20100644=0A---=20= a/libavfilter/af_volumedetect.c=0A+++=20b/libavfilter/af_volumedetect.c=0A= @@=20-24,94=20+24,210=20@@=0A=20#include=20"avfilter.h"=0A=20#include=20= "internal.h"=0A=20=0A-typedef=20struct=20VolDetectContext=20{=0A+typedef=20= struct=20ChannelStats=20{=0A=20=20=20=20=20/**=0A=20=20=20=20=20=20*=20= Number=20of=20samples=20at=20each=20PCM=20value.=0A+=20=20=20=20=20*=20= Only=20used=20for=20integer=20formats.=0A+=20=20=20=20=20*=20For=2016=20= bit=20signed=20PCM=20there=20are=2065536.=0A=20=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=20*=20The=20extra=20element=20is=20there=20= for=20symmetry.=0A=20=20=20=20=20=20*/=0A-=20=20=20=20uint64_t=20= histogram[0x10001];=0A+=20=20=20=20uint64_t*=20histogram;=20///<=20= distribution=20of=20the=20samples,=20only=20used=20for=20integer=20= formats=0A+=20=20=20=20uint64_t=20nb_samples;=20///<=20number=20of=20= samples=0A+=20=20=20=20double=20sum;=20=20=20=20=20=20=20=20=20=20///<=20= sum=20of=20samples=0A+=20=20=20=20double=20sum2;=20=20=20=20=20=20=20=20=20= ///<=20sum=20of=20the=20squares=20of=20the=20samples=0A+=20=20=20=20= double=20max;=20=20=20=20=20=20=20=20=20=20///<=20maximum=20sample=20= value=0A+=20=20=20=20double=20min;=20=20=20=20=20=20=20=20=20=20///<=20= minimum=20sample=20value=0A+}=20ChannelStats;=0A+=0A+typedef=20struct=20= VolDetectContext=20{=0A+=20=20=20=20ChannelStats=20*channel_stats;=20= ///<=20per-channel=20statistics=0A+=20=20=20=20int=20channels;=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20///<=20number=20of=20channels=0A+=20=20= =20=20int=20is_float;=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= ///<=20true=20if=20the=20input=20is=20in=20floating=20point=0A=20}=20= VolDetectContext;=0A=20=0A+static=20void=20= update_float_stats(ChannelStats=20*stats,=20int=20*plane,=20float=20= *audio_data)=0A+{=0A+=20=20=20=20double=20max_sample,=20min_sample;=0A+=20= =20=20=20min_sample=20=3D=20audio_data[*plane];=0A+=20=20=20=20= max_sample=20=3D=20fabsf(audio_data[*plane]);=0A+=20=20=20=20if=20= (max_sample=20>=20stats->max)=0A+=20=20=20=20=20=20=20=20stats->max=20=3D=20= max_sample;=0A+=20=20=20=20if=20(min_sample=20<=20stats->min)=0A+=20=20=20= =20=20=20=20=20stats->min=20=3D=20min_sample;=0A+=20=20=20=20stats->sum=20= +=3D=20audio_data[*plane];=0A+=20=20=20=20stats->sum2=20+=3D=20= audio_data[*plane]=20*=20audio_data[*plane];=0A+=20=20=20=20= stats->nb_samples++;=0A+}=0A+=0A=20static=20int=20= filter_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=20= VolDetectContext=20*vd=20=3D=20ctx->priv;=0A-=20=20=20=20int=20= nb_samples=20=20=3D=20samples->nb_samples;=0A=20=20=20=20=20int=20= nb_channels=20=3D=20samples->ch_layout.nb_channels;=0A=20=20=20=20=20int=20= nb_planes=20=20=20=3D=20nb_channels;=0A+=20=20=20=20int=20planar=20=20=20= =20=20=20=3D=200;=0A=20=20=20=20=20int=20plane,=20i;=0A-=20=20=20=20= int16_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+=0A+=20=20=20=20planar=20=3D=20= av_sample_fmt_is_planar(samples->format);=0A+=20=20=20=20if=20(!planar)=20= {=0A=20=20=20=20=20=20=20=20=20nb_planes=20=3D=201;=0A=20=20=20=20=20}=0A= -=20=20=20=20for=20(plane=20=3D=200;=20plane=20<=20nb_planes;=20plane++)=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=20=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;=20plane++)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20= audio_data=20=3D=20(float=20*)samples->extended_data[plane];=0A+=0A+=20=20= =20=20=20=20=20=20=20=20=20=20for=20(i=20=3D=200;=20i=20<=20= samples->nb_samples;=20i++)=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=20=20=20=20=20*=20If=20= the=20input=20is=20planar,=20the=20samples=20are=20in=20the=20seperated=20= planes.=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20*=20if=20= the=20input=20is=20not=20planar,=20the=20samples=20are=20interleaved.=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20*=20if=20the=20input=20= is=20not=20planar,=20split=20the=20samples=20into=20the=20planes.=0A+=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=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->channel_stats[plane],=20&plane,=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->channel_stats[j],=20&plane,=20&audio_data[i=20*=20= nb_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;=20= plane++)=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=20= vd->channel_stats[plane].histogram[pcm[i]=20+=200x8000]++;=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= vd->channel_stats[plane].nb_samples++;=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++)=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=20vd->channel_stats[j].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=20vd->channel_stats[j].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}=0A=20=20=20=20=20return=20= ff_filter_frame(inlink->dst->outputs[0],=20samples);=0A=20}=0A=20=0A=20= #define=20MAX_DB=2091=0A=20=0A-static=20inline=20double=20logdb(uint64_t=20= v)=0A+static=20inline=20double=20logdb(double=20v,=20enum=20= AVSampleFormat=20sample_fmt)=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=20MAX_DB;=0A-=20=20=20=20return=20-log10(d)=20*=2010;=0A= +=20=20=20=20/*=0A+=20=20=20=20*=20Since=20it=20is=20a=20not=20a=20power=20= value,=20able=20to=20use=2020.0=20*=20log10(v)=0A+=20=20=20=20*/=0A+=20=20= =20=20if=20(sample_fmt=20=3D=3D=20AV_SAMPLE_FMT_FLT)=0A+=20=20=20=20=20=20= =20=20return=2020.0=20*=20log10(v);=0A+=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=20}=0A=20=0A=20static=20void=20= print_stats(AVFilterContext=20*ctx)=0A=20{=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-=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= =20ChannelStats=20*channel_stats=20=3D=20vd->channel_stats;=0A+=0A+=20=20= =20=20if=20(vd->is_float)=20{=0A+=20=20=20=20=20=20=20=20int=20channel;=0A= +=20=20=20=20=20=20=20=20for=20(channel=20=3D=200;=20channel=20<=20= vd->channels;=20channel++)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20= double=20rms;=0A+=20=20=20=20=20=20=20=20=20=20=20=20av_log(ctx,=20= AV_LOG_INFO,=20"Channel:=20%d\n",=20channel=20+=201);=0A+=20=20=20=20=20=20= =20=20=20=20=20=20av_log(ctx,=20AV_LOG_INFO,=20"n_samples:=20%"=20PRId64=20= "\n",=20channel_stats[channel].nb_samples);=0A+=20=20=20=20=20=20=20=20=20= =20=20=20if=20(!channel_stats[channel].nb_samples)=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20return;=0A+=20=20=20=20=20=20=20=20=20=20=20=20= av_log(ctx,=20AV_LOG_INFO,=20"min_volume:=20%.6f=20dB\n",=20= channel_stats[channel].min);=0A+=20=20=20=20=20=20=20=20=20=20=20=20= av_log(ctx,=20AV_LOG_INFO,=20"max_volume:=20%.6f=20dB\n",=20= channel_stats[channel].max);=0A+=20=20=20=20=20=20=20=20=20=20=20=20= av_log(ctx,=20AV_LOG_INFO,=20"peak_level=20dB:=20%.6f=20dB\n",=20= logdb(channel_stats[channel].max,=20AV_SAMPLE_FMT_FLT));=0A+=20=20=20=20=20= =20=20=20=20=20=20=20rms=20=3D=20sqrt(channel_stats[channel].sum2=20/=20= channel_stats[channel].nb_samples);=0A+=20=20=20=20=20=20=20=20=20=20=20=20= av_log(ctx,=20AV_LOG_INFO,=20"RMS=20volume:=20%.6f=20dB\n",=20logdb(rms,=20= AV_SAMPLE_FMT_FLT));=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=20int=20channel;=0A+=20=20=20=20=20=20=20= =20for=20(channel=20=3D=200;=20channel=20<=20vd->channels;=20channel++)=20= {=0A+=20=20=20=20=20=20=20=20=20=20=20=20int=20i,=20max_volume,=20shift;=0A= +=20=20=20=20=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=20=20=20=20=20uint64_t=20histdb[MAX_DB=20+=201]=20=3D=20= {0};=0A+=20=20=20=20=20=20=20=20=20=20=20=20av_log(ctx,=20AV_LOG_INFO,=20= "Channel:=20%d\n",=20channel=20+=201);=0A+=20=20=20=20=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=20=20=20=20nb_samples=20+=3D=20= channel_stats[channel].histogram[i];=0A+=20=20=20=20=20=20=20=20=20=20=20= =20av_log(ctx,=20AV_LOG_INFO,=20"n_samples:=20%"=20PRId64=20"\n",=20= nb_samples);=0A+=20=20=20=20=20=20=20=20=20=20=20=20if=20(!nb_samples)=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20return;=0A+=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*=20If=20= nb_samples=20>=201<<34,=20there=20is=20a=20risk=20of=20overflow=20in=20= the=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20*=20multiplication=20or=20= the=20sum:=20shift=20all=20histogram=20values=20to=20avoid=20that.=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20*=20The=20total=20number=20of=20= samples=20must=20be=20recomputed=20to=20avoid=20rounding=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20*=20errors.=0A+=20=20=20=20=20=20=20=20=20=20=20=20= */=0A+=20=20=20=20=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=20=20=20=20=20= for=20(i=20=3D=200;=20i=20<=200x10000;=20i++)=20{=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20nb_samples_shift=20+=3D=20= channel_stats[channel].histogram[i]=20>>=20shift;=0A+=20=20=20=20=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(channel_stats[channel].histogram[i]=20>>=20shift);=0A+=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= if=20(!nb_samples_shift)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20return;=0A+=20=20=20=20=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=20=20=20=20=20av_assert0(power=20<=3D=200x8000=20*=200x8000);=0A+=20=20= =20=20=20=20=20=20=20=20=20=20av_log(ctx,=20AV_LOG_INFO,=20"mean_volume:=20= %.1f=20dB\n",=20-logdb((double)power,=20AV_SAMPLE_FMT_S16));=0A+=0A+=20=20= =20=20=20=20=20=20=20=20=20=20max_volume=20=3D=200x8000;=0A+=20=20=20=20=20= =20=20=20=20=20=20=20while=20(max_volume=20>=200=20&&=20= !channel_stats[channel].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= !channel_stats[channel].histogram[0x8000=20-=20max_volume])=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20max_volume--;=0A+=20=20=20=20=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),=20AV_SAMPLE_FMT_S16));=0A+=0A= +=20=20=20=20=20=20=20=20=20=20=20=20for=20(i=20=3D=200;=20i=20<=20= 0x10000;=20i++)=0A+=20=20=20=20=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->channel_stats[channel].histogram[i];=0A= +=20=20=20=20=20=20=20=20=20=20=20=20for=20(i=20=3D=200;=20i=20<=3D=20= MAX_DB=20&&=20!histdb[i];=20i++);=0A+=20=20=20=20=20=20=20=20=20=20=20=20= for=20(;=20i=20<=3D=20MAX_DB=20&&=20sum=20<=20nb_samples=20/=201000;=20= i++)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20av_log(ctx,=20= AV_LOG_INFO,=20"histogram_%ddb:=20%"=20PRId64=20"\n",=20i,=20histdb[i]);=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20sum=20+=3D=20histdb[i];=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}=0A=20=0A+static=20int=20config_output(AVFilterLink=20= *outlink)=0A+{=0A+=20=20=20=20AVFilterContext=20*ctx=20=3D=20= outlink->src;=0A+=20=20=20=20VolDetectContext=20*vd=20=3D=20ctx->priv;=0A= +=20=20=20=20int=20i;=0A+=20=20=20=20vd->is_float=20=3D=20= outlink->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=20outlink->format=20=3D=3D=20= AV_SAMPLE_FMT_FLTP;=0A+=0A+=20=20=20=20vd->channels=20=3D=20= outlink->ch_layout.nb_channels;=0A+=20=20=20=20vd->channel_stats=20=3D=20= av_calloc(vd->channels,=20sizeof(ChannelStats));=0A+=0A+=20=20=20=20if=20= (!vd->channel_stats)=0A+=20=20=20=20=20=20=20=20return=20= AVERROR(ENOMEM);=0A+=20=20=20=20=20=20=20=20if=20(!vd->is_float){=0A+=20=20= =20=20=20=20=20=20=20=20=20=20for=20(i=20=3D=200;=20i=20<=20= vd->channels;=20i++)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20vd->channel_stats[i].histogram=20=3D=20av_calloc(0x10000,=20= sizeof(uint64_t));=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20if=20= (!vd->channel_stats[i].histogram)=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20return=20AVERROR(ENOMEM);=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=20return=200;=0A= +}=0A+=0A=20static=20av_cold=20void=20uninit(AVFilterContext=20*ctx)=0A=20= {=0A=20=20=20=20=20print_stats(ctx);=0A+=20=20=20=20if=20(ctx->priv)=20{=0A= +=20=20=20=20=20=20=20=20VolDetectContext=20*vd=20=3D=20ctx->priv;=0A+=20= =20=20=20=20=20=20=20for=20(int=20i=20=3D=200;=20i=20<=20vd->channels;=20= i++)=0A+=20=20=20=20=20=20=20=20=20=20=20=20= av_freep(&vd->channel_stats[i].histogram);=0A+=20=20=20=20=20=20=20=20= av_freep(&vd->channel_stats);=0A+=20=20=20=20}=0A=20}=0A=20=0A=20static=20= const=20AVFilterPad=20volumedetect_inputs[]=20=3D=20{=0A@@=20-122,6=20= +238,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+253,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= --===============8867135879244322321== 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". --===============8867135879244322321==--