33 uint64_t histogram[0x10001];
65 for (plane = 0; plane < nb_planes; plane++) {
67 for (i = 0; i < nb_samples; i++)
76 static inline double logdb(uint64_t v)
78 double d = v / (double)(0x8000 * 0x8000);
81 return -log10(d) * 10;
87 int i, max_volume,
shift;
88 uint64_t nb_samples = 0, power = 0, nb_samples_shift = 0, sum = 0;
89 uint64_t histdb[
MAX_DB + 1] = { 0 };
91 for (i = 0; i < 0x10000; i++)
101 shift =
av_log2(nb_samples >> 33);
102 for (i = 0; i < 0x10000; i++) {
104 power += (i - 0x8000) * (i - 0x8000) * (vd->
histogram[i] >>
shift);
106 if (!nb_samples_shift)
108 power = (power + nb_samples_shift / 2) / nb_samples_shift;
113 while (max_volume > 0 && !vd->
histogram[0x8000 + max_volume] &&
118 for (i = 0; i < 0x10000; i++)
119 histdb[(
int)
logdb((i - 0x8000) * (i - 0x8000))] += vd->
histogram[i];
120 for (i = 0; i <=
MAX_DB && !histdb[i]; i++);
121 for (; i <=
MAX_DB && sum < nb_samples / 1000; i++) {
150 .
name =
"volumedetect",
155 .
inputs = volumedetect_inputs,
156 .
outputs = volumedetect_outputs,
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data.
Main libavfilter public API header.
static enum AVSampleFormat formats[]
static double logdb(uint64_t v)
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
static int query_formats(AVFilterContext *ctx)
const char * name
Pad name.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
uint64_t histogram[0x10001]
Number of samples at each PCM value.
static int filter_frame(AVFilterLink *inlink, AVFrame *samples)
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
A filter pad used for either input or output.
A link between two filters.
static const AVFilterPad volumedetect_outputs[]
static av_cold void uninit(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
simple assert() macros that are a bit more flexible than ISO C assert().
uint64_t channel_layout
Channel layout of the audio data.
static void print_stats(AVFilterContext *ctx)
audio channel layout utility functions
static const AVFilterPad outputs[]
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
#define AV_LOG_INFO
Standard information.
static const AVFilterPad inputs[]
AVSampleFormat
Audio sample formats.
static const AVFilterPad volumedetect_inputs[]
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
AVFilter ff_af_volumedetect
AVFilterContext * dst
dest filter
static enum AVSampleFormat sample_fmts[]
uint8_t ** extended_data
pointers to the data planes/channels.
int nb_samples
number of audio samples (per channel) described by this frame