30 #include "libavcodec/avfft.h"
31 #include "libavutil/avassert.h"
32 #include "libavutil/channel_layout.h"
33 #include "libavutil/opt.h"
63 #define OFFSET(x) offsetof(ShowSpectrumContext, x)
64 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
91 { 0.13, .03587126228984074, .1573300977624594, -.02548747583751842 },
92 { 0.30, .18572281794568020, .1772436246393981, .17475554840414750 },
93 { 0.60, .28184980583656130, -.1593064119945782, .47132074554608920 },
94 { 0.73, .65830621175547810, -.3716070802232764, .24352759331252930 },
95 { 0.78, .76318535758242900, -.4307467689263783, .16866496622310430 },
96 { 0.91, .95336363636363640, -.2045454545454546, .03313636363636363 },
153 int i, rdft_bits, win_size, h;
162 for (rdft_bits = 1; 1 << rdft_bits < 2 * h; rdft_bits++);
163 win_size = 1 << rdft_bits;
167 size_t rdft_size, rdft_listsize;
186 win_size, &rdft_size) < 0)
204 for (i = 0; i < win_size; i++)
214 for (i = 0; i < outlink->
h; i++) {
215 memset(outpicref->
data[0] + i * outpicref->
linesize[0], 0, outlink->
w);
216 memset(outpicref->
data[1] + i * outpicref->
linesize[1], 128, outlink->
w);
217 memset(outpicref->
data[2] + i * outpicref->
linesize[2], 128, outlink->
w);
221 if (s->
xpos >= outlink->
w)
229 s->
w, s->
h, win_size);
238 if (s->
xpos >= outlink->
w)
272 const int nb_freq = 1 << (s->
rdft_bits - 1);
273 const int win_size = nb_freq << 1;
274 const double w = 1. / (sqrt(nb_freq) * 32768.);
278 const int add_samples =
FFMIN(win_size - start, nb_samples);
285 for (n = 0; n < add_samples; n++)
291 if (s->
filled == win_size) {
301 #define RE(y, ch) s->rdft_data[ch][2 * y + 0]
302 #define IM(y, ch) s->rdft_data[ch][2 * y + 1]
303 #define MAGNITUDE(y, ch) hypot(RE(y, ch), IM(y, ch))
306 for (y = 0; y < outlink->
h; y++) {
358 for (y = 0; y < h; y++) {
376 a = 1 - log(
FFMAX(
FFMIN(1, a), 1e-6)) / log(1e-6);
402 float lerpfrac = (a -
start) / (end - start);
424 for (plane = 0; plane < 3; plane++) {
425 for (y = 0; y < outlink->
h; y++) {
428 memmove(p, p + 1, outlink->
w - 1);
431 s->
xpos = outlink->
w - 1;
433 for (plane = 0; plane < 3; plane++) {
435 (outlink->
h - 1) * outpicref->
linesize[plane] +
437 for (y = 0; y < outlink->
h; y++) {
443 outpicref->
pts = insamples->
pts +
462 while (left_samples) {
494 .
name =
"showspectrum",
499 .
inputs = showspectrum_inputs,
500 .
outputs = showspectrum_outputs,
501 .priv_class = &showspectrum_class,
This structure describes decoded (raw) audio or video data.
static double rint(double x)
const char * name
Filter name.
void * priv
private data for use by the filter
static const AVFilterPad outputs[]
int h
agreed upon image height
uint8_t ** extended_data
pointers to the data planes/channels.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
float * window_func_lut
Window function LUT.
static enum AVSampleFormat formats[]
static int query_formats(AVFilterContext *ctx)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
int sliding
1 if sliding mode, 0 otherwise
RDFTContext * rdft
Real Discrete Fourier Transform context.
static const AVFilterPad showspectrum_outputs[]
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static const AVOption showspectrum_options[]
static av_cold int end(AVCodecContext *avctx)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static int request_frame(AVFilterLink *outlink)
FFTSample ** rdft_data
bins holder for each (displayed) channels
#define AV_LOG_VERBOSE
Detailed information.
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
static av_always_inline double cbrt(double x)
int sample_rate
samples per second
static struct @113 intensity_color_table[]
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
float saturation
color saturation multiplier
float * combine_buffer
color combining buffer (3 * h items)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
AVFilterContext * src
source filter
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVPixelFormat
Pixel format.
void av_rdft_calc(RDFTContext *s, FFTSample *data)
int w
agreed upon image width
static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples, int nb_samples)
static const AVFilterPad showspectrum_inputs[]
static int push_frame(AVFilterLink *outlink)
static int av_size_mult(size_t a, size_t b, size_t *r)
Multiply two size_t values checking for overflow.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int filled
number of samples (per channel) filled in current rdft_buffer
void av_rdft_end(RDFTContext *s)
A list of supported channel layouts.
AVFilterFormats * out_samplerates
Main libavfilter public API header.
AVFilterLink ** outputs
array of pointers to output links
AVSampleFormat
Audio Sample Formats.
enum DisplayMode mode
channel display mode
static int config_output(AVFilterLink *outlink)
AVFilterFormats * out_formats
void * av_realloc_f(void *ptr, size_t nelem, size_t elsize)
Allocate or reallocate a block of memory.
AVFilter avfilter_avf_showspectrum
Describe the class of an AVClass context structure.
int consumed
number of samples (per channel) consumed from the input frame
static const AVFilterPad inputs[]
AVFilterLink ** inputs
array of pointers to input links
rational number numerator/denominator
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
offset must point to two consecutive integers
enum MovChannelLayoutTag * layouts
static const uint16_t scale[4]
static av_cold void uninit(AVFilterContext *ctx)
AVFrame * av_frame_clone(AVFrame *src)
Create a new frame that references the same data as src.
int channels
Number of channels.
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
int rdft_bits
number of bits (RDFT window size = 1<<rdft_bits)
#define AVFILTER_DEFINE_CLASS(fname)
static enum AVSampleFormat sample_fmts[]
struct AVFilterChannelLayouts * out_channel_layouts
#define av_assert0(cond)
assert() equivalent, that is always enabled.
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
int xpos
x position (current column)
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
enum ColorMode color_mode
display color scheme
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)