64 #define OFFSET(x) offsetof(ShowSpectrumContext, x)
65 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
99 { 0.13, .03587126228984074, .1573300977624594, -.02548747583751842 },
100 { 0.30, .18572281794568020, .1772436246393981, .17475554840414750 },
101 { 0.60, .28184980583656130, -.1593064119945782, .47132074554608920 },
102 { 0.73, .65830621175547810, -.3716070802232764, .24352759331252930 },
103 { 0.78, .76318535758242900, -.4307467689263783, .16866496622310430 },
104 { 0.91, .95336363636363640, -.2045454545454546, .03313636363636363 },
161 int i, rdft_bits, win_size,
h;
170 for (rdft_bits = 1; 1 << rdft_bits < 2 *
h; rdft_bits++);
171 win_size = 1 << rdft_bits;
181 "The window size might be too high.\n");
211 for (i = 0; i < win_size; i++)
215 for (i = 0; i < win_size; i++)
219 for (i = 0; i < win_size; i++)
223 for (i = 0; i < win_size; i++)
238 for (i = 0; i < outlink->
h; i++) {
239 memset(outpicref->
data[0] + i * outpicref->
linesize[0], 0, outlink->
w);
240 memset(outpicref->
data[1] + i * outpicref->
linesize[1], 128, outlink->
w);
241 memset(outpicref->
data[2] + i * outpicref->
linesize[2], 128, outlink->
w);
245 if (s->
xpos >= outlink->
w)
260 s->
w, s->
h, win_size);
276 for (i = 0; i < outlink->
h; i++) {
300 const int nb_freq = 1 << (s->
rdft_bits - 1);
301 const int win_size = nb_freq << 1;
302 const double w = 1. / (sqrt(nb_freq) * 32768.);
313 for (n = 0; n < win_size; n++)
322 #define RE(y, ch) s->rdft_data[ch][2 * (y) + 0]
323 #define IM(y, ch) s->rdft_data[ch][2 * (y) + 1]
324 #define MAGNITUDE(y, ch) hypot(RE(y, ch), IM(y, ch))
327 for (y = 0; y < outlink->
h; y++) {
379 for (y = 0; y <
h; y++) {
397 a = 1 - log(
FFMAX(
FFMIN(1, a), 1e-6)) / log(1e-6);
423 float lerpfrac = (a -
start) / (end - start);
445 for (plane = 0; plane < 3; plane++) {
446 for (y = 0; y < outlink->
h; y++) {
449 memmove(p, p + 1, outlink->
w - 1);
452 s->
xpos = outlink->
w - 1;
454 for (plane = 0; plane < 3; plane++) {
456 (outlink->
h - 1) * outpicref->
linesize[plane] +
458 for (y = 0; y < outlink->
h; y++) {
465 outpicref->
pts = insamples->
pts;
468 if (s->
xpos >= outlink->
w)
515 .
name =
"showspectrum",
520 .
inputs = showspectrum_inputs,
521 .
outputs = showspectrum_outputs,
522 .priv_class = &showspectrum_class,
#define av_realloc_f(p, o, n)
This structure describes decoded (raw) audio or video data.
static double rint(double x)
static const AVFilterPad outputs[]
Main libavfilter public API header.
int max_samples
Maximum number of samples to filter at once.
int h
agreed upon image height
float * window_func_lut
Window function LUT.
static enum AVSampleFormat formats[]
static int query_formats(AVFilterContext *ctx)
static const struct @124 intensity_color_table[]
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
static AVRational av_make_q(int num, int den)
Create a rational.
RDFTContext * rdft
Real Discrete Fourier Transform context.
static const AVFilterPad showspectrum_outputs[]
int mode
channel display mode
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
#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.
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 AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
A filter pad used for either input or output.
A link between two filters.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline double cbrt(double x)
int min_samples
Minimum number of samples to filter at once.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown; if left to 0/0, will be automatically be cop...
int sample_rate
samples per second
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#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
float saturation
color saturation multiplier
float * combine_buffer
color combining buffer (3 * h items)
simple assert() macros that are a bit more flexible than ISO C assert().
struct AVFilterChannelLayouts * out_channel_layouts
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
void av_rdft_calc(RDFTContext *s, FFTSample *data)
int w
agreed upon image width
audio channel layout utility functions
static const AVFilterPad showspectrum_inputs[]
void av_rdft_end(RDFTContext *s)
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
AVFilterContext * src
source filter
int partial_buf_size
Size of the partial buffer to allocate.
AVFilterFormats * out_samplerates
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
A list of supported channel layouts.
static int config_output(AVFilterLink *outlink)
AVSampleFormat
Audio sample formats.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
AVFILTER_DEFINE_CLASS(showspectrum)
rational number numerator/denominator
const char * name
Filter name.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
offset must point to two consecutive integers
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
static enum AVPixelFormat pix_fmts[]
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static av_cold void uninit(AVFilterContext *ctx)
static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
int channels
Number of channels.
int rdft_bits
number of bits (RDFT window size = 1<<rdft_bits)
AVFilterContext * dst
dest filter
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){if(!*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));if(!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=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);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);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) 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_log(ac->avr, AV_LOG_TRACE,"%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
static enum AVSampleFormat sample_fmts[]
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
AVFilter ff_avf_showspectrum
uint8_t ** extended_data
pointers to the data planes/channels.
int xpos
x position (current column)
AVPixelFormat
Pixel format.
int nb_samples
number of audio samples (per channel) described by this frame
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
AVFilterFormats * out_formats
int color_mode
display color scheme