Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
61641627
Commit
61641627
authored
Jul 13, 2015
by
Paul B Mahol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/af_astats: calculate audio bit-depth
Signed-off-by:
Paul B Mahol
<
onemda@gmail.com
>
parent
30015584
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
2 deletions
+19
-2
af_astats.c
libavfilter/af_astats.c
+19
-2
No files found.
libavfilter/af_astats.c
View file @
61641627
...
@@ -33,6 +33,7 @@ typedef struct ChannelStats {
...
@@ -33,6 +33,7 @@ typedef struct ChannelStats {
double
min
,
max
;
double
min
,
max
;
double
min_run
,
max_run
;
double
min_run
,
max_run
;
double
min_runs
,
max_runs
;
double
min_runs
,
max_runs
;
uint64_t
mask
;
uint64_t
min_count
,
max_count
;
uint64_t
min_count
,
max_count
;
uint64_t
nb_samples
;
uint64_t
nb_samples
;
}
ChannelStats
;
}
ChannelStats
;
...
@@ -121,6 +122,15 @@ static int config_output(AVFilterLink *outlink)
...
@@ -121,6 +122,15 @@ static int config_output(AVFilterLink *outlink)
return
0
;
return
0
;
}
}
static
unsigned
bit_depth
(
uint64_t
mask
)
{
unsigned
result
=
64
;
for
(;
result
&&
!
(
mask
&
1
);
--
result
,
mask
>>=
1
);
return
result
;
}
static
inline
void
update_stat
(
AudioStatsContext
*
s
,
ChannelStats
*
p
,
double
d
)
static
inline
void
update_stat
(
AudioStatsContext
*
s
,
ChannelStats
*
p
,
double
d
)
{
{
if
(
d
<
p
->
min
)
{
if
(
d
<
p
->
min
)
{
...
@@ -151,6 +161,7 @@ static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d)
...
@@ -151,6 +161,7 @@ static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d)
p
->
sigma_x2
+=
d
*
d
;
p
->
sigma_x2
+=
d
*
d
;
p
->
avg_sigma_x2
=
p
->
avg_sigma_x2
*
s
->
mult
+
(
1
.
0
-
s
->
mult
)
*
d
*
d
;
p
->
avg_sigma_x2
=
p
->
avg_sigma_x2
*
s
->
mult
+
(
1
.
0
-
s
->
mult
)
*
d
*
d
;
p
->
last
=
d
;
p
->
last
=
d
;
p
->
mask
|=
llrint
(
d
*
(
1LLU
<<
63
));
if
(
p
->
nb_samples
>=
s
->
tc_samples
)
{
if
(
p
->
nb_samples
>=
s
->
tc_samples
)
{
p
->
max_sigma_x2
=
FFMAX
(
p
->
max_sigma_x2
,
p
->
avg_sigma_x2
);
p
->
max_sigma_x2
=
FFMAX
(
p
->
max_sigma_x2
,
p
->
avg_sigma_x2
);
...
@@ -177,7 +188,7 @@ static void set_meta(AVDictionary **metadata, int chan, const char *key,
...
@@ -177,7 +188,7 @@ static void set_meta(AVDictionary **metadata, int chan, const char *key,
static
void
set_metadata
(
AudioStatsContext
*
s
,
AVDictionary
**
metadata
)
static
void
set_metadata
(
AudioStatsContext
*
s
,
AVDictionary
**
metadata
)
{
{
uint64_t
min_count
=
0
,
max_count
=
0
,
nb_samples
=
0
;
uint64_t
m
ask
=
0
,
m
in_count
=
0
,
max_count
=
0
,
nb_samples
=
0
;
double
min_runs
=
0
,
max_runs
=
0
,
double
min_runs
=
0
,
max_runs
=
0
,
min
=
DBL_MAX
,
max
=
DBL_MIN
,
min
=
DBL_MAX
,
max
=
DBL_MIN
,
max_sigma_x
=
0
,
max_sigma_x
=
0
,
...
@@ -203,6 +214,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
...
@@ -203,6 +214,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
max_count
+=
p
->
max_count
;
max_count
+=
p
->
max_count
;
min_runs
+=
p
->
min_runs
;
min_runs
+=
p
->
min_runs
;
max_runs
+=
p
->
max_runs
;
max_runs
+=
p
->
max_runs
;
mask
|=
p
->
mask
;
nb_samples
+=
p
->
nb_samples
;
nb_samples
+=
p
->
nb_samples
;
if
(
fabs
(
p
->
sigma_x
)
>
fabs
(
max_sigma_x
))
if
(
fabs
(
p
->
sigma_x
)
>
fabs
(
max_sigma_x
))
max_sigma_x
=
p
->
sigma_x
;
max_sigma_x
=
p
->
sigma_x
;
...
@@ -217,6 +229,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
...
@@ -217,6 +229,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
set_meta
(
metadata
,
c
+
1
,
"Crest_factor"
,
"%f"
,
p
->
sigma_x2
?
FFMAX
(
-
p
->
min
,
p
->
max
)
/
sqrt
(
p
->
sigma_x2
/
p
->
nb_samples
)
:
1
);
set_meta
(
metadata
,
c
+
1
,
"Crest_factor"
,
"%f"
,
p
->
sigma_x2
?
FFMAX
(
-
p
->
min
,
p
->
max
)
/
sqrt
(
p
->
sigma_x2
/
p
->
nb_samples
)
:
1
);
set_meta
(
metadata
,
c
+
1
,
"Flat_factor"
,
"%f"
,
LINEAR_TO_DB
((
p
->
min_runs
+
p
->
max_runs
)
/
(
p
->
min_count
+
p
->
max_count
)));
set_meta
(
metadata
,
c
+
1
,
"Flat_factor"
,
"%f"
,
LINEAR_TO_DB
((
p
->
min_runs
+
p
->
max_runs
)
/
(
p
->
min_count
+
p
->
max_count
)));
set_meta
(
metadata
,
c
+
1
,
"Peak_count"
,
"%f"
,
(
float
)(
p
->
min_count
+
p
->
max_count
));
set_meta
(
metadata
,
c
+
1
,
"Peak_count"
,
"%f"
,
(
float
)(
p
->
min_count
+
p
->
max_count
));
set_meta
(
metadata
,
c
+
1
,
"Bit_depth"
,
"%f"
,
bit_depth
(
p
->
mask
));
}
}
set_meta
(
metadata
,
0
,
"Overall.DC_offset"
,
"%f"
,
max_sigma_x
/
(
nb_samples
/
s
->
nb_channels
));
set_meta
(
metadata
,
0
,
"Overall.DC_offset"
,
"%f"
,
max_sigma_x
/
(
nb_samples
/
s
->
nb_channels
));
...
@@ -228,6 +241,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
...
@@ -228,6 +241,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
set_meta
(
metadata
,
0
,
"Overall.RMS_trough"
,
"%f"
,
LINEAR_TO_DB
(
sqrt
(
min_sigma_x2
)));
set_meta
(
metadata
,
0
,
"Overall.RMS_trough"
,
"%f"
,
LINEAR_TO_DB
(
sqrt
(
min_sigma_x2
)));
set_meta
(
metadata
,
0
,
"Overall.Flat_factor"
,
"%f"
,
LINEAR_TO_DB
((
min_runs
+
max_runs
)
/
(
min_count
+
max_count
)));
set_meta
(
metadata
,
0
,
"Overall.Flat_factor"
,
"%f"
,
LINEAR_TO_DB
((
min_runs
+
max_runs
)
/
(
min_count
+
max_count
)));
set_meta
(
metadata
,
0
,
"Overall.Peak_count"
,
"%f"
,
(
float
)(
min_count
+
max_count
)
/
(
double
)
s
->
nb_channels
);
set_meta
(
metadata
,
0
,
"Overall.Peak_count"
,
"%f"
,
(
float
)(
min_count
+
max_count
)
/
(
double
)
s
->
nb_channels
);
set_meta
(
metadata
,
0
,
"Overall.Bit_depth"
,
"%f"
,
bit_depth
(
mask
));
set_meta
(
metadata
,
0
,
"Overall.Number_of_samples"
,
"%f"
,
nb_samples
/
s
->
nb_channels
);
set_meta
(
metadata
,
0
,
"Overall.Number_of_samples"
,
"%f"
,
nb_samples
/
s
->
nb_channels
);
}
}
...
@@ -276,7 +290,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
...
@@ -276,7 +290,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
static
void
print_stats
(
AVFilterContext
*
ctx
)
static
void
print_stats
(
AVFilterContext
*
ctx
)
{
{
AudioStatsContext
*
s
=
ctx
->
priv
;
AudioStatsContext
*
s
=
ctx
->
priv
;
uint64_t
min_count
=
0
,
max_count
=
0
,
nb_samples
=
0
;
uint64_t
m
ask
=
0
,
m
in_count
=
0
,
max_count
=
0
,
nb_samples
=
0
;
double
min_runs
=
0
,
max_runs
=
0
,
double
min_runs
=
0
,
max_runs
=
0
,
min
=
DBL_MAX
,
max
=
DBL_MIN
,
min
=
DBL_MAX
,
max
=
DBL_MIN
,
max_sigma_x
=
0
,
max_sigma_x
=
0
,
...
@@ -302,6 +316,7 @@ static void print_stats(AVFilterContext *ctx)
...
@@ -302,6 +316,7 @@ static void print_stats(AVFilterContext *ctx)
max_count
+=
p
->
max_count
;
max_count
+=
p
->
max_count
;
min_runs
+=
p
->
min_runs
;
min_runs
+=
p
->
min_runs
;
max_runs
+=
p
->
max_runs
;
max_runs
+=
p
->
max_runs
;
mask
|=
p
->
mask
;
nb_samples
+=
p
->
nb_samples
;
nb_samples
+=
p
->
nb_samples
;
if
(
fabs
(
p
->
sigma_x
)
>
fabs
(
max_sigma_x
))
if
(
fabs
(
p
->
sigma_x
)
>
fabs
(
max_sigma_x
))
max_sigma_x
=
p
->
sigma_x
;
max_sigma_x
=
p
->
sigma_x
;
...
@@ -318,6 +333,7 @@ static void print_stats(AVFilterContext *ctx)
...
@@ -318,6 +333,7 @@ static void print_stats(AVFilterContext *ctx)
av_log
(
ctx
,
AV_LOG_INFO
,
"Crest factor: %f
\n
"
,
p
->
sigma_x2
?
FFMAX
(
-
p
->
min
,
p
->
max
)
/
sqrt
(
p
->
sigma_x2
/
p
->
nb_samples
)
:
1
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Crest factor: %f
\n
"
,
p
->
sigma_x2
?
FFMAX
(
-
p
->
min
,
p
->
max
)
/
sqrt
(
p
->
sigma_x2
/
p
->
nb_samples
)
:
1
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Flat factor: %f
\n
"
,
LINEAR_TO_DB
((
p
->
min_runs
+
p
->
max_runs
)
/
(
p
->
min_count
+
p
->
max_count
)));
av_log
(
ctx
,
AV_LOG_INFO
,
"Flat factor: %f
\n
"
,
LINEAR_TO_DB
((
p
->
min_runs
+
p
->
max_runs
)
/
(
p
->
min_count
+
p
->
max_count
)));
av_log
(
ctx
,
AV_LOG_INFO
,
"Peak count: %"
PRId64
"
\n
"
,
p
->
min_count
+
p
->
max_count
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Peak count: %"
PRId64
"
\n
"
,
p
->
min_count
+
p
->
max_count
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Bit depth: %u
\n
"
,
bit_depth
(
p
->
mask
));
}
}
av_log
(
ctx
,
AV_LOG_INFO
,
"Overall
\n
"
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Overall
\n
"
);
...
@@ -331,6 +347,7 @@ static void print_stats(AVFilterContext *ctx)
...
@@ -331,6 +347,7 @@ static void print_stats(AVFilterContext *ctx)
av_log
(
ctx
,
AV_LOG_INFO
,
"RMS trough dB: %f
\n
"
,
LINEAR_TO_DB
(
sqrt
(
min_sigma_x2
)));
av_log
(
ctx
,
AV_LOG_INFO
,
"RMS trough dB: %f
\n
"
,
LINEAR_TO_DB
(
sqrt
(
min_sigma_x2
)));
av_log
(
ctx
,
AV_LOG_INFO
,
"Flat factor: %f
\n
"
,
LINEAR_TO_DB
((
min_runs
+
max_runs
)
/
(
min_count
+
max_count
)));
av_log
(
ctx
,
AV_LOG_INFO
,
"Flat factor: %f
\n
"
,
LINEAR_TO_DB
((
min_runs
+
max_runs
)
/
(
min_count
+
max_count
)));
av_log
(
ctx
,
AV_LOG_INFO
,
"Peak count: %f
\n
"
,
(
min_count
+
max_count
)
/
(
double
)
s
->
nb_channels
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Peak count: %f
\n
"
,
(
min_count
+
max_count
)
/
(
double
)
s
->
nb_channels
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Bit depth: %u
\n
"
,
bit_depth
(
mask
));
av_log
(
ctx
,
AV_LOG_INFO
,
"Number of samples: %"
PRId64
"
\n
"
,
nb_samples
/
s
->
nb_channels
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Number of samples: %"
PRId64
"
\n
"
,
nb_samples
/
s
->
nb_channels
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment