74 for (plane = 0; plane < nb_planes; plane++) {
76 for (i = 0; i < nb_samples; i++)
85 static inline double logdb(uint64_t v)
87 double d = v / (double)(0x8000 * 0x8000);
90 return -log10(d) * 10;
96 int i, max_volume,
shift;
97 uint64_t nb_samples = 0, power = 0, nb_samples_shift = 0, sum = 0;
98 uint64_t histdb[
MAX_DB + 1] = { 0 };
100 for (i = 0; i < 0x10000; i++)
110 shift =
av_log2(nb_samples >> 33);
111 for (i = 0; i < 0x10000; i++) {
113 power += (i - 0x8000) * (i - 0x8000) * (vd->
histogram[i] >>
shift);
115 if (!nb_samples_shift)
117 power = (power + nb_samples_shift / 2) / nb_samples_shift;
122 while (max_volume > 0 && !vd->
histogram[0x8000 + max_volume] &&
127 for (i = 0; i < 0x10000; i++)
128 histdb[(
int)
logdb((i - 0x8000) * (i - 0x8000))] += vd->
histogram[i];
129 for (i = 0; i <=
MAX_DB && !histdb[i]; i++);
130 for (; i <=
MAX_DB && sum < nb_samples / 1000; i++) {
159 .
name =
"volumedetect",
164 .
inputs = volumedetect_inputs,
165 .
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 double logdb(uint64_t v)
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().
static void print_stats(AVFilterContext *ctx)
int channels
number of audio channels, only used for audio.
audio channel layout utility functions
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
A list of supported channel layouts.
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.
AVSampleFormat
Audio sample formats.
static const AVFilterPad volumedetect_inputs[]
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
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