86 #define OFFSET(x) offsetof(ShowSpectrumContext, x)
87 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
153 { 0.13, .03587126228984074, .1573300977624594, -.02548747583751842 },
154 { 0.30, .18572281794568020, .1772436246393981, .17475554840414750 },
155 { 0.60, .28184980583656130, -.1593064119945782, .47132074554608920 },
156 { 0.73, .65830621175547810, -.3716070802232764, .24352759331252930 },
157 { 0.78, .76318535758242900, -.4307467689263783, .16866496622310430 },
158 { 0.91, .95336363636363640, -.2045454545454546, .03313636363636363 },
162 { 0.13, 44/256., (189-128)/256., (138-128)/256. },
163 { 0.25, 29/256., (186-128)/256., (119-128)/256. },
164 { 0.38, 119/256., (194-128)/256., (53-128)/256. },
165 { 0.60, 111/256., (73-128)/256., (59-128)/256. },
166 { 0.73, 205/256., (19-128)/256., (149-128)/256. },
167 { 0.86, 135/256., (83-128)/256., (200-128)/256. },
168 { 1, 73/256., (95-128)/256., (225-128)/256. }},
170 { 0, 44/256., (181-128)/256., (112-128)/256. },
171 { 0.13, 126/256., (177-128)/256., (106-128)/256. },
172 { 0.25, 164/256., (163-128)/256., (109-128)/256. },
173 { 0.38, 200/256., (140-128)/256., (120-128)/256. },
174 { 0.60, 201/256., (117-128)/256., (141-128)/256. },
175 { 0.73, 177/256., (103-128)/256., (165-128)/256. },
176 { 0.86, 136/256., (100-128)/256., (183-128)/256. },
177 { 1, 68/256., (117-128)/256., (203-128)/256. }},
179 { 0, 10/256., (134-128)/256., (132-128)/256. },
180 { 0.23, 21/256., (137-128)/256., (130-128)/256. },
181 { 0.45, 35/256., (134-128)/256., (134-128)/256. },
182 { 0.57, 51/256., (130-128)/256., (139-128)/256. },
183 { 0.67, 104/256., (116-128)/256., (162-128)/256. },
184 { 0.77, 120/256., (105-128)/256., (188-128)/256. },
185 { 0.87, 140/256., (105-128)/256., (188-128)/256. },
189 { 0.23, 44/256., (132-128)/256., (127-128)/256. },
190 { 0.45, 62/256., (116-128)/256., (140-128)/256. },
191 { 0.57, 75/256., (105-128)/256., (152-128)/256. },
192 { 0.67, 95/256., (91-128)/256., (166-128)/256. },
193 { 0.77, 126/256., (74-128)/256., (172-128)/256. },
194 { 0.87, 164/256., (73-128)/256., (162-128)/256. },
198 { 0.23, 36/256., (116-128)/256., (163-128)/256. },
199 { 0.45, 52/256., (102-128)/256., (200-128)/256. },
200 { 0.57, 116/256., (84-128)/256., (196-128)/256. },
201 { 0.67, 157/256., (67-128)/256., (181-128)/256. },
202 { 0.77, 193/256., (40-128)/256., (155-128)/256. },
203 { 0.87, 221/256., (101-128)/256., (134-128)/256. },
207 { 0.20, 29/256., (136-128)/256., (119-128)/256. },
208 { 0.30, 60/256., (119-128)/256., (90-128)/256. },
209 { 0.40, 85/256., (91-128)/256., (85-128)/256. },
210 { 0.50, 116/256., (70-128)/256., (105-128)/256. },
211 { 0.60, 151/256., (50-128)/256., (146-128)/256. },
212 { 0.70, 191/256., (63-128)/256., (178-128)/256. },
213 { 1, 98/256., (80-128)/256., (221-128)/256. }},
283 int i, fft_bits,
h, w;
286 if (!strcmp(ctx->
filter->
name,
"showspectrumpic"))
306 for (fft_bits = 1; 1 << fft_bits < 2 *
h; fft_bits++);
309 for (fft_bits = 1; 1 << fft_bits < 2 * w; fft_bits++);
321 "The window size might be too high.\n");
376 for (s->
win_scale = 0, i = 0; i < s->win_size; i++) {
388 for (i = 0; i < outlink->
h; i++) {
389 memset(outpicref->
data[0] + i * outpicref->
linesize[0], 0, outlink->
w);
390 memset(outpicref->
data[1] + i * outpicref->
linesize[1], 128, outlink->
w);
391 memset(outpicref->
data[2] + i * outpicref->
linesize[2], 128, outlink->
w);
447 #define RE(y, ch) s->fft_data[ch][y].re
448 #define IM(y, ch) s->fft_data[ch][y].im
449 #define MAGNITUDE(y, ch) hypot(RE(y, ch), IM(y, ch))
450 #define PHASE(y, ch) atan2(IM(y, ch), RE(y, ch))
456 const float f = s->
gain * w;
461 for (y = 0; y <
h; y++)
471 float *phases = s->
phases[ch];
473 for (y = 0; y <
h; y++)
474 phases[y] = (
PHASE(y, ch) /
M_PI + 1) / 2;
482 const float f = s->
gain * w;
487 for (y = 0; y <
h; y++)
499 for (y = 0; y <
h; y++)
500 magnitudes[y] *= scale;
505 float *yf,
float *uf,
float *vf)
557 float yf,
float uf,
float vf,
581 float lerpfrac = (a -
start) / (end - start);
604 for (y = 0; y <
size; y++) {
628 float *phases = s->
phases[ch];
635 for (y = 0; y <
h; y++) {
656 a = av_clipf(a, 0, 1);
659 a = av_clipf(sqrt(a), 0, 1);
662 a = av_clipf(
cbrt(a), 0, 1);
665 a = av_clipf(sqrt(sqrt(a)), 0, 1);
668 a = av_clipf(pow(a, 0.20), 0, 1);
671 a = 1 + log10(av_clipd(a, 1e-6, 1)) / 6;
685 for (plane = 0; plane < 3; plane++) {
686 for (y = 0; y < s->
h; y++) {
689 memmove(p, p + 1, s->
w - 1);
694 for (plane = 0; plane < 3; plane++) {
695 for (y = 0; y < s->
h; y++) {
698 memmove(p + 1, p, s->
w - 1);
703 for (plane = 0; plane < 3; plane++) {
707 for (y = 0; y < s->
h; y++) {
714 for (plane = 0; plane < 3; plane++) {
715 for (y = 1; y < s->
h; y++) {
716 memmove(outpicref->
data[plane] + (y-1) * outpicref->
linesize[plane],
717 outpicref->
data[plane] + (y ) * outpicref->
linesize[plane],
723 for (plane = 0; plane < 3; plane++) {
724 for (y = s->
h - 1; y >= 1; y--) {
725 memmove(outpicref->
data[plane] + (y ) * outpicref->
linesize[plane],
726 outpicref->
data[plane] + (y-1) * outpicref->
linesize[plane],
732 for (plane = 0; plane < 3; plane++) {
735 for (x = 0; x < s->
w; x++) {
743 outpicref->
pts = insamples->
pts;
759 #if CONFIG_SHOWSPECTRUM_FILTER
772 for (i = 0; i < outlink->
h; i++) {
778 for (i = s->
xpos; i < outlink->
h; i++) {
796 int ret = 0, consumed = 0;
810 fin->
pts = s->
pts + consumed;
846 static const AVFilterPad showspectrum_outputs[] = {
857 .
name =
"showspectrum",
862 .
inputs = showspectrum_inputs,
863 .
outputs = showspectrum_outputs,
864 .priv_class = &showspectrum_class,
866 #endif // CONFIG_SHOWSPECTRUM_FILTER
868 #if CONFIG_SHOWSPECTRUMPIC_FILTER
870 static const AVOption showspectrumpic_options[] = {
921 static void drawtext(
AVFrame *pic,
int x,
int y,
const char *txt,
int o)
929 for (i = 0; txt[i]; i++) {
933 for (char_y = font_height - 1; char_y >= 0; char_y--) {
935 for (mask = 0x80;
mask; mask >>= 1) {
936 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
937 p[char_y] = ~p[char_y];
943 for (char_y = 0; char_y < font_height; char_y++) {
944 for (mask = 0x80;
mask; mask >>= 1) {
945 if (font[txt[i] * font_height + char_y] & mask)
955 static int showspectrumpic_request_frame(
AVFilterLink *outlink)
970 spb = (samples / (spf * sz)) * spf;
985 if (ret < s->win_size) {
988 (s->
win_size - ret) *
sizeof(
float));
996 if (consumed >= spb) {
1004 memset(s->
magnitudes[ch], 0, h *
sizeof(
float));
1013 float spp = samples / (float)sz;
1019 for (x = 0; x < s->
w + 1; x++)
1022 for (x = 0; x < s->
w + 1; x++)
1024 for (y = 0; y < s->
h + 2; y++) {
1032 for (y = 0; y <
h; y += 20) {
1037 for (y = 0; y <
h; y += 40) {
1043 for (x = 0; x < s->
w; x+=40)
1046 for (x = 0; x < s->
w; x+=80)
1049 for (x = 0; x < s->
w; x+=40) {
1053 for (x = 0; x < s->
w; x+=80) {
1056 for (y = 0; y <
h; y += 40) {
1057 float hz = y * (inlink->
sample_rate / 2) / (
float)(1 << (int)ceil(
log2(h)));
1072 for (x = 0; x < s->
w; x+=80) {
1078 else if (log10(seconds) > 6)
1079 units =
av_asprintf(
"%.2fh", seconds / (60 * 60));
1080 else if (log10(seconds) > 3)
1096 for (y = 0; y < s->
h; y += 20) {
1101 for (y = 0; y < s->
h; y += 40) {
1108 for (x = 0; x < w; x+=40)
1111 for (x = 0; x < w; x+=80)
1114 for (x = 0; x < w; x+=40) {
1118 for (x = 0; x < w; x+=80) {
1121 for (x = 0; x < w; x += 80) {
1122 float hz = x * (inlink->
sample_rate / 2) / (
float)(1 << (int)ceil(
log2(w)));
1137 for (y = 0; y < s->
h; y+=40) {
1143 else if (log10(seconds) > 6)
1144 units =
av_asprintf(
"%.2fh", seconds / (60 * 60));
1145 else if (log10(seconds) > 3)
1162 for (y = 0; y <
h; y++) {
1163 float out[3] = { 0., 127.5, 127.5};
1171 pick_color(s, yf, uf, vf, y / (
float)h, out);
1198 static const AVFilterPad showspectrumpic_inputs[] = {
1202 .filter_frame = showspectrumpic_filter_frame,
1207 static const AVFilterPad showspectrumpic_outputs[] = {
1212 .request_frame = showspectrumpic_request_frame,
1217 AVFilter ff_avf_showspectrumpic = {
1218 .
name =
"showspectrumpic",
1219 .description =
NULL_IF_CONFIG_SMALL(
"Convert input audio to a spectrum video output single picture."),
1223 .
inputs = showspectrumpic_inputs,
1224 .
outputs = showspectrumpic_outputs,
1225 .priv_class = &showspectrumpic_class,
1228 #endif // CONFIG_SHOWSPECTRUMPIC_FILTER
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
#define av_realloc_f(p, o, n)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
av_cold void av_fft_end(FFTContext *s)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Main libavfilter public API header.
FFTComplex ** fft_data
bins holder for each (displayed) channels
int h
agreed upon image height
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
static void calc_phases(ShowSpectrumContext *s)
static void run_fft(ShowSpectrumContext *s, AVFrame *fin)
float * window_func_lut
Window function LUT.
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
static enum AVSampleFormat formats[]
int fft_bits
number of bits (FFT window size = 1<<fft_bits)
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
static AVRational av_make_q(int num, int den)
Create a rational.
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).
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
void av_frame_set_color_range(AVFrame *frame, enum AVColorRange val)
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.
const uint8_t avpriv_cga_font[2048]
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0, will be automatically copied from the first input of the source filter if it exists.
int sample_rate
samples per second
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
static const uint16_t mask[17]
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
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
Context for an Audio FIFO Buffer.
int w
agreed upon image width
char * av_asprintf(const char *fmt,...)
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
audio channel layout utility functions
static int request_frame(AVFilterLink *outlink)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static void acalc_magnitudes(ShowSpectrumContext *s)
AVFilterContext * src
source filter
static const AVFilterPad outputs[]
AVFilterFormats * out_samplerates
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
int format
agreed upon media format
#define FF_ARRAY_ELEMS(a)
the normal 2^n-1 "JPEG" YUV ranges
A list of supported channel layouts.
static const AVFilterPad inputs[]
static int config_output(AVFilterLink *outlink)
static void color_range(ShowSpectrumContext *s, int ch, float *yf, float *uf, float *vf)
AVSampleFormat
Audio sample formats.
static const struct ColorTable color_table[][8]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Describe the class of an AVClass context structure.
void ff_generate_window_func(float *lut, int N, int win_func, float *overlap)
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...
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
static av_cold void uninit(AVFilterContext *ctx)
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
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.
FFTContext * fft
Fast Fourier Transform context.
AVFilterContext * dst
dest filter
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
static enum AVSampleFormat sample_fmts[]
static void scale_magnitudes(ShowSpectrumContext *s, float scale)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
static void pick_color(ShowSpectrumContext *s, float yf, float uf, float vf, float a, float *out)
uint8_t ** extended_data
pointers to the data planes/channels.
static void drawtext(AVFrame *pic, int x, int y, const char *txt)
int xpos
x position (current column)
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
AVPixelFormat
Pixel format.
static void clear_combine_buffer(ShowSpectrumContext *s, int size)
int nb_samples
number of audio samples (per channel) described by this frame
const AVFilter * filter
the AVFilter of which this is an instance
static void calc_magnitudes(ShowSpectrumContext *s)
#define AV_NOPTS_VALUE
Undefined timestamp value.
CGA/EGA/VGA ROM font data.
AVFilterFormats * out_formats
int color_mode
display color scheme