29 #include "config_components.h"
54 enum ColorMode {
CHANNEL,
INTENSITY,
RAINBOW,
MORELAND,
NEBULAE,
FIRE,
FIERY,
FRUIT,
COOL,
MAGMA,
GREEN,
VIRIDIS,
PLASMA,
CIVIDIS,
TERRAIN,
NB_CLMODES };
58 #define DEFAULT_LENGTH 300
122 #define OFFSET(x) offsetof(ShowSpectrumContext, x)
123 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
192 { 0.13, .03587126228984074, .1573300977624594, -.02548747583751842 },
193 { 0.30, .18572281794568020, .1772436246393981, .17475554840414750 },
194 { 0.60, .28184980583656130, -.1593064119945782, .47132074554608920 },
195 { 0.73, .65830621175547810, -.3716070802232764, .24352759331252930 },
196 { 0.78, .76318535758242900, -.4307467689263783, .16866496622310430 },
197 { 0.91, .95336363636363640, -.2045454545454546, .03313636363636363 },
201 { 0.13, 44/256., (189-128)/256., (138-128)/256. },
202 { 0.25, 29/256., (186-128)/256., (119-128)/256. },
203 { 0.38, 119/256., (194-128)/256., (53-128)/256. },
204 { 0.60, 111/256., (73-128)/256., (59-128)/256. },
205 { 0.73, 205/256., (19-128)/256., (149-128)/256. },
206 { 0.86, 135/256., (83-128)/256., (200-128)/256. },
207 { 1, 73/256., (95-128)/256., (225-128)/256. }},
209 { 0, 44/256., (181-128)/256., (112-128)/256. },
210 { 0.13, 126/256., (177-128)/256., (106-128)/256. },
211 { 0.25, 164/256., (163-128)/256., (109-128)/256. },
212 { 0.38, 200/256., (140-128)/256., (120-128)/256. },
213 { 0.60, 201/256., (117-128)/256., (141-128)/256. },
214 { 0.73, 177/256., (103-128)/256., (165-128)/256. },
215 { 0.86, 136/256., (100-128)/256., (183-128)/256. },
216 { 1, 68/256., (117-128)/256., (203-128)/256. }},
218 { 0, 10/256., (134-128)/256., (132-128)/256. },
219 { 0.23, 21/256., (137-128)/256., (130-128)/256. },
220 { 0.45, 35/256., (134-128)/256., (134-128)/256. },
221 { 0.57, 51/256., (130-128)/256., (139-128)/256. },
222 { 0.67, 104/256., (116-128)/256., (162-128)/256. },
223 { 0.77, 120/256., (105-128)/256., (188-128)/256. },
224 { 0.87, 140/256., (105-128)/256., (188-128)/256. },
228 { 0.23, 44/256., (132-128)/256., (127-128)/256. },
229 { 0.45, 62/256., (116-128)/256., (140-128)/256. },
230 { 0.57, 75/256., (105-128)/256., (152-128)/256. },
231 { 0.67, 95/256., (91-128)/256., (166-128)/256. },
232 { 0.77, 126/256., (74-128)/256., (172-128)/256. },
233 { 0.87, 164/256., (73-128)/256., (162-128)/256. },
237 { 0.23, 36/256., (116-128)/256., (163-128)/256. },
238 { 0.45, 52/256., (102-128)/256., (200-128)/256. },
239 { 0.57, 116/256., (84-128)/256., (196-128)/256. },
240 { 0.67, 157/256., (67-128)/256., (181-128)/256. },
241 { 0.77, 193/256., (40-128)/256., (155-128)/256. },
242 { 0.87, 221/256., (101-128)/256., (134-128)/256. },
246 { 0.20, 29/256., (136-128)/256., (119-128)/256. },
247 { 0.30, 60/256., (119-128)/256., (90-128)/256. },
248 { 0.40, 85/256., (91-128)/256., (85-128)/256. },
249 { 0.50, 116/256., (70-128)/256., (105-128)/256. },
250 { 0.60, 151/256., (50-128)/256., (146-128)/256. },
251 { 0.70, 191/256., (63-128)/256., (178-128)/256. },
252 { 1, 98/256., (80-128)/256., (221-128)/256. }},
259 { 0.10, 23/256., (175-128)/256., (120-128)/256. },
260 { 0.23, 43/256., (158-128)/256., (144-128)/256. },
261 { 0.35, 85/256., (138-128)/256., (179-128)/256. },
262 { 0.48, 96/256., (128-128)/256., (189-128)/256. },
263 { 0.64, 128/256., (103-128)/256., (214-128)/256. },
264 { 0.92, 205/256., (80-128)/256., (152-128)/256. },
272 { 0.10, 0x39/255., (0x9D -128)/255., (0x8F -128)/255. },
273 { 0.23, 0x5C/255., (0x9A -128)/255., (0x68 -128)/255. },
274 { 0.35, 0x69/255., (0x93 -128)/255., (0x57 -128)/255. },
275 { 0.48, 0x76/255., (0x88 -128)/255., (0x4B -128)/255. },
276 { 0.64, 0x8A/255., (0x72 -128)/255., (0x4F -128)/255. },
277 { 0.80, 0xA3/255., (0x50 -128)/255., (0x66 -128)/255. },
278 { 1, 0xCC/255., (0x2F -128)/255., (0x87 -128)/255. }},
281 { 0.10, 0x27/255., (0xC2 -128)/255., (0x82 -128)/255. },
282 { 0.58, 0x5B/255., (0x9A -128)/255., (0xAE -128)/255. },
283 { 0.70, 0x89/255., (0x44 -128)/255., (0xAB -128)/255. },
284 { 0.80, 0xB4/255., (0x2B -128)/255., (0x9E -128)/255. },
285 { 0.91, 0xD2/255., (0x38 -128)/255., (0x92 -128)/255. },
289 { 0.20, 0x28/255., (0x98 -128)/255., (0x6F -128)/255. },
290 { 0.50, 0x48/255., (0x95 -128)/255., (0x74 -128)/255. },
291 { 0.63, 0x69/255., (0x84 -128)/255., (0x7F -128)/255. },
292 { 0.76, 0x89/255., (0x75 -128)/255., (0x84 -128)/255. },
293 { 0.90, 0xCE/255., (0x35 -128)/255., (0x95 -128)/255. },
298 { 0.60, 1, -.5, -.5 },
299 { 0.85, 1, -.5, .5 },
310 for (
i = 0;
i <
s->nb_display_channels;
i++)
315 for (
i = 0;
i <
s->nb_display_channels;
i++)
320 for (
i = 0;
i <
s->nb_display_channels;
i++)
325 for (
i = 0;
i <
s->nb_display_channels;
i++)
329 if (
s->fft_scratch) {
330 for (
i = 0;
i <
s->nb_display_channels;
i++)
334 if (
s->color_buffer) {
335 for (
i = 0;
i <
s->nb_display_channels;
i++)
341 for (
i = 0;
i <
s->nb_display_channels;
i++)
348 for (
i = 0;
i <
s->nb_display_channels;
i++)
353 while (
s->nb_frames > 0) {
387 const float *window_func_lut =
s->window_func_lut;
389 const int ch = jobnr;
394 float *in_frame = (
float *)
s->in_frame->extended_data[ch];
396 memmove(in_frame, in_frame +
s->hop_size, (
s->fft_size -
s->hop_size) *
sizeof(
float));
397 memcpy(in_frame +
s->fft_size -
s->hop_size, p, fin->
nb_samples *
sizeof(
float));
400 in_frame[
i +
s->fft_size -
s->hop_size] = 0.f;
403 float theta, phi, psi,
a,
b,
S,
c;
409 int M =
s->win_size / 2;
411 for (n = 0; n <
s->win_size; n++) {
412 s->fft_data[ch][n].re = in_frame[n] * window_func_lut[n];
413 s->fft_data[ch][n].im = 0;
416 phi = 2.f *
M_PI * (
s->stop -
s->start) / (
float)
inlink->sample_rate / (
M - 1);
419 for (
int n = 0; n <
M; n++) {
420 h[n].re =
cosf(n * n / 2.
f * phi);
421 h[n].im =
sinf(n * n / 2.
f * phi);
424 for (
int n =
M; n <
L; n++) {
429 for (
int n =
L -
N; n <
L; n++) {
430 h[n].re =
cosf((
L - n) * (
L - n) / 2.
f * phi);
431 h[n].im =
sinf((
L - n) * (
L - n) / 2.
f * phi);
434 for (
int n =
N; n <
L; n++) {
439 for (
int n = 0; n <
N; n++) {
440 psi = n * theta + n * n / 2.f * phi;
443 a =
c *
g[n].re -
S *
g[n].im;
444 b =
S *
g[n].re +
c *
g[n].im;
449 memcpy(
f,
h,
s->buf_size *
sizeof(*
f));
452 memcpy(
f,
g,
s->buf_size *
sizeof(*
f));
455 for (
int n = 0; n <
L; n++) {
458 a =
c *
h[n].re -
S *
h[n].im;
459 b =
S *
h[n].re +
c *
h[n].im;
465 memcpy(
f,
g,
s->buf_size *
sizeof(*
f));
468 for (
int k = 0; k <
M; k++) {
469 psi = k * k / 2.f * phi;
472 a =
c *
g[k].re -
S *
g[k].im;
473 b =
S *
g[k].re +
c *
g[k].im;
474 s->fft_data[ch][k].re =
a;
475 s->fft_data[ch][k].im =
b;
478 for (n = 0; n <
s->win_size; n++) {
479 s->fft_in[ch][n].re = in_frame[n] * window_func_lut[n];
480 s->fft_in[ch][n].im = 0;
497 for (
int i = 0; txt[
i];
i++) {
501 for (char_y = font_height - 1; char_y >= 0; char_y--) {
502 uint8_t *p = pic->
data[0] + (y +
i * 10) * pic->
linesize[0] + x;
504 if (font[txt[
i] * font_height + font_height - 1 - char_y] &
mask)
505 p[char_y] = ~p[char_y];
511 for (char_y = 0; char_y < font_height; char_y++) {
513 if (font[txt[
i] * font_height + char_y] &
mask)
522 for (
int i = 0; txt[
i] && pic->
data[3];
i++) {
526 for (char_y = font_height - 1; char_y >= 0; char_y--) {
527 uint8_t *p = pic->
data[3] + (y +
i * 10) * pic->
linesize[3] + x;
529 for (
int k = 0; k < 8; k++)
536 for (char_y = 0; char_y < font_height; char_y++) {
546 float *yf,
float *uf,
float *
vf)
551 *yf = 256.0f /
s->nb_display_channels;
552 switch (
s->color_mode) {
591 if (
s->nb_display_channels > 1) {
592 *uf *= 0.5f *
sinf((2 *
M_PI * ch) /
s->nb_display_channels +
M_PI *
s->rotation);
593 *
vf *= 0.5f *
cosf((2 *
M_PI * ch) /
s->nb_display_channels +
M_PI *
s->rotation);
603 *uf *=
s->saturation;
604 *
vf *=
s->saturation;
608 float yf,
float uf,
float vf,
611 const float af =
s->opacity_factor * 255.f;
614 const int cm =
s->color_mode;
634 float lerpfrac = (
a - start) / (end - start);
661 else if (log10(seconds) > 6)
663 else if (log10(seconds) > 3)
671 const float bmin,
const float bmax,
672 const float min,
const float max)
677 static float get_hz(
const float bin,
const float bmax,
678 const float min,
const float max,
692 float bmin,
float bmax,
698 static float bin_pos(
const int bin,
const int num_bins,
const float min,
const float max)
706 const float dmin =
s->dmin;
707 const float dmax =
s->dmax;
711 a = (
a - dmin) / (dmax - dmin);
729 a = (
s->drange -
s->limit +
log10f(
a) * 20.f) /
s->drange;
741 const float dmin =
s->dmin;
742 const float dmax =
s->dmax;
767 a =
a * (dmax - dmin) + dmin;
777 int ch, y, x = 0, sz =
s->orientation ==
VERTICAL ?
s->w :
s->h;
782 char chlayout_str[128];
790 drawtext(
s->outpicref, 2, outlink->
h - 10,
"CREATED BY LIBAVFILTER", 0);
791 drawtext(
s->outpicref, outlink->
w - 2 - strlen(text) * 10, outlink->
h - 10, text, 0);
794 text =
av_asprintf(
"Zoom: %d Hz - %d Hz",
s->start,
s->stop);
797 drawtext(
s->outpicref, outlink->
w - 2 - strlen(text) * 10, 3, text, 0);
801 dst =
s->outpicref->data[0] + (
s->start_y - 1) *
s->outpicref->linesize[0] +
s->start_x - 1;
802 for (x = 0; x <
s->w + 1; x++)
804 dst =
s->outpicref->data[0] + (
s->start_y +
s->h) *
s->outpicref->linesize[0] +
s->start_x - 1;
805 for (x = 0; x <
s->w + 1; x++)
807 for (y = 0; y <
s->h + 2; y++) {
808 dst =
s->outpicref->data[0] + (y +
s->start_y - 1) *
s->outpicref->linesize[0];
809 dst[
s->start_x - 1] = 200;
810 dst[
s->start_x +
s->w] = 200;
813 int h =
s->mode ==
SEPARATE ?
s->h /
s->nb_display_channels :
s->h;
814 int hh =
s->mode ==
SEPARATE ? -(
s->h %
s->nb_display_channels) + 1 : 1;
815 for (ch = 0; ch < (
s->mode ==
SEPARATE ?
s->nb_display_channels : 1); ch++) {
816 for (y = 0; y <
h; y += 20) {
817 dst =
s->outpicref->data[0] + (
s->start_y +
h * (ch + 1) - y - hh) *
s->outpicref->linesize[0];
818 dst[
s->start_x - 2] = 200;
819 dst[
s->start_x +
s->w + 1] = 200;
821 for (y = 0; y <
h; y += 40) {
822 dst =
s->outpicref->data[0] + (
s->start_y +
h * (ch + 1) - y - hh) *
s->outpicref->linesize[0];
823 dst[
s->start_x - 3] = 200;
824 dst[
s->start_x +
s->w + 2] = 200;
826 dst =
s->outpicref->data[0] + (
s->start_y - 2) *
s->outpicref->linesize[0] +
s->start_x;
827 for (x = 0; x <
s->w; x+=40)
829 dst =
s->outpicref->data[0] + (
s->start_y - 3) *
s->outpicref->linesize[0] +
s->start_x;
830 for (x = 0; x <
s->w; x+=80)
832 dst =
s->outpicref->data[0] + (
s->h +
s->start_y + 1) *
s->outpicref->linesize[0] +
s->start_x;
833 for (x = 0; x <
s->w; x+=40) {
836 dst =
s->outpicref->data[0] + (
s->h +
s->start_y + 2) *
s->outpicref->linesize[0] +
s->start_x;
837 for (x = 0; x <
s->w; x+=80) {
840 for (y = 0; y <
h; y += 40) {
841 float range =
s->stop ?
s->stop -
s->start :
inlink->sample_rate / 2;
852 drawtext(
s->outpicref,
s->start_x - 8 * strlen(units) - 4,
h * (ch + 1) +
s->start_y - y - 4 - hh, units, 0);
857 for (x = 0; x <
s->w &&
s->single_pic; x+=80) {
858 float seconds = x * spp /
inlink->sample_rate;
863 drawtext(
s->outpicref,
s->start_x + x - 4 * strlen(units),
s->h +
s->start_y + 6, units, 0);
864 drawtext(
s->outpicref,
s->start_x + x - 4 * strlen(units),
s->start_y - 12, units, 0);
868 drawtext(
s->outpicref, outlink->
w / 2 - 4 * 4, outlink->
h -
s->start_y / 2,
"TIME", 0);
869 drawtext(
s->outpicref,
s->start_x / 7, outlink->
h / 2 - 14 * 4,
"FREQUENCY (Hz)", 1);
871 int w =
s->mode ==
SEPARATE ?
s->w /
s->nb_display_channels :
s->w;
872 for (y = 0; y <
s->h; y += 20) {
873 dst =
s->outpicref->data[0] + (
s->start_y + y) *
s->outpicref->linesize[0];
874 dst[
s->start_x - 2] = 200;
875 dst[
s->start_x +
s->w + 1] = 200;
877 for (y = 0; y <
s->h; y += 40) {
878 dst =
s->outpicref->data[0] + (
s->start_y + y) *
s->outpicref->linesize[0];
879 dst[
s->start_x - 3] = 200;
880 dst[
s->start_x +
s->w + 2] = 200;
882 for (ch = 0; ch < (
s->mode ==
SEPARATE ?
s->nb_display_channels : 1); ch++) {
883 dst =
s->outpicref->data[0] + (
s->start_y - 2) *
s->outpicref->linesize[0] +
s->start_x +
w * ch;
884 for (x = 0; x <
w; x+=40)
886 dst =
s->outpicref->data[0] + (
s->start_y - 3) *
s->outpicref->linesize[0] +
s->start_x +
w * ch;
887 for (x = 0; x <
w; x+=80)
889 dst =
s->outpicref->data[0] + (
s->h +
s->start_y + 1) *
s->outpicref->linesize[0] +
s->start_x +
w * ch;
890 for (x = 0; x <
w; x+=40) {
893 dst =
s->outpicref->data[0] + (
s->h +
s->start_y + 2) *
s->outpicref->linesize[0] +
s->start_x +
w * ch;
894 for (x = 0; x <
w; x+=80) {
897 for (x = 0; x <
w - 79; x += 80) {
898 float range =
s->stop ?
s->stop -
s->start :
inlink->sample_rate / 2;
909 drawtext(
s->outpicref,
s->start_x - 4 * strlen(units) + x +
w * ch,
s->start_y - 12, units, 0);
910 drawtext(
s->outpicref,
s->start_x - 4 * strlen(units) + x +
w * ch,
s->h +
s->start_y + 6, units, 0);
914 for (y = 0; y <
s->h &&
s->single_pic; y+=40) {
915 float seconds = y * spp /
inlink->sample_rate;
920 drawtext(
s->outpicref,
s->start_x - 8 * strlen(units) - 4,
s->start_y + y - 4, units, 0);
923 drawtext(
s->outpicref,
s->start_x / 7, outlink->
h / 2 - 4 * 4,
"TIME", 1);
924 drawtext(
s->outpicref, outlink->
w / 2 - 14 * 4, outlink->
h -
s->start_y / 2,
"FREQUENCY (Hz)", 0);
927 for (ch = 0; ch < (multi ?
s->nb_display_channels : 1); ch++) {
928 int h = multi ?
s->h /
s->nb_display_channels :
s->h;
930 for (y = 0; y <
h; y++) {
931 float out[4] = { 0., 127.5, 127.5, 0.f};
934 for (chn = 0; chn < (
s->mode ==
SEPARATE ? 1 :
s->nb_display_channels); chn++) {
936 int channel = (multi) ?
s->nb_display_channels - ch - 1 : chn;
946 memset(
s->outpicref->data[0]+(
s->start_y +
h * (ch + 1) - y - 1) *
s->outpicref->linesize[0] +
s->w +
s->start_x + 20,
av_clip_uint8(
out[0]), 10);
947 memset(
s->outpicref->data[1]+(
s->start_y +
h * (ch + 1) - y - 1) *
s->outpicref->linesize[1] +
s->w +
s->start_x + 20,
av_clip_uint8(
out[1]), 10);
948 memset(
s->outpicref->data[2]+(
s->start_y +
h * (ch + 1) - y - 1) *
s->outpicref->linesize[2] +
s->w +
s->start_x + 20,
av_clip_uint8(
out[2]), 10);
949 if (
s->outpicref->data[3])
950 memset(
s->outpicref->data[3]+(
s->start_y +
h * (ch + 1) - y - 1) *
s->outpicref->linesize[3] +
s->w +
s->start_x + 20,
av_clip_uint8(
out[3]), 10);
953 for (y = 0; ch == 0 && y <
h + 5; y += 25) {
954 static const char *log_fmt =
"%.0f";
955 static const char *lin_fmt =
"%.3f";
956 const float a =
av_clipf(1.
f - y / (
float)(
h - 1), 0.
f, 1.
f);
963 drawtext(
s->outpicref,
s->w +
s->start_x + 35,
s->start_y + y - 3, text, 0);
969 drawtext(
s->outpicref,
s->w +
s->start_x + 22,
s->start_y +
s->h + 20,
"dBFS", 0);
977 float *magnitudes =
s->magnitudes[ch];
978 float *phases =
s->phases[ch];
1001 const int h =
s->orientation ==
VERTICAL ?
s->channel_height :
s->channel_width;
1002 const int ch = jobnr;
1010 for (y = 0; y <
h; y++) {
1011 int row = (
s->mode ==
COMBINED) ? y : ch *
h + y;
1012 float *
out = &
s->color_buffer[ch][4 * row];
1025 const int h =
s->orientation ==
VERTICAL ?
s->channel_height :
s->channel_width;
1026 const int ch = jobnr;
1033 for (
int yy = 0; yy <
h; yy++) {
1034 float range =
s->stop ?
s->stop -
s->start :
inlink->sample_rate / 2;
1042 int row = (
s->mode ==
COMBINED) ? yy : ch *
h + yy;
1043 float *
out = &
s->color_buffer[ch][4 * row];
1058 int i, fft_size,
h,
w,
ret;
1065 switch (
s->fscale) {
1072 if ((
s->stop ||
s->start) &&
s->stop <=
s->start) {
1077 if (!strcmp(
ctx->filter->name,
"showspectrumpic"))
1085 s->start_x = (log10(
inlink->sample_rate) + 1) * 25;
1087 outlink->
w +=
s->start_x * 2;
1088 outlink->
h +=
s->start_y * 2;
1093 s->channel_height =
h;
1094 s->channel_width =
w;
1104 s->win_size = fft_size;
1122 if (fft_size !=
s->fft_size) {
1125 s->fft_size = fft_size;
1130 for (
i = 0;
i <
s->nb_display_channels;
i++) {
1141 s->nb_display_channels =
inlink->ch_layout.nb_channels;
1142 for (
i = 0;
i <
s->nb_display_channels;
i++) {
1150 "The window size might be too high.\n");
1156 "The window size might be too high.\n");
1161 s->magnitudes =
av_calloc(
s->nb_display_channels,
sizeof(*
s->magnitudes));
1164 for (
i = 0;
i <
s->nb_display_channels;
i++) {
1166 if (!
s->magnitudes[
i])
1170 s->phases =
av_calloc(
s->nb_display_channels,
sizeof(*
s->phases));
1173 for (
i = 0;
i <
s->nb_display_channels;
i++) {
1180 s->color_buffer =
av_calloc(
s->nb_display_channels,
sizeof(*
s->color_buffer));
1181 if (!
s->color_buffer)
1183 for (
i = 0;
i <
s->nb_display_channels;
i++) {
1185 if (!
s->color_buffer[
i])
1189 s->fft_in =
av_calloc(
s->nb_display_channels,
sizeof(*
s->fft_in));
1192 s->fft_data =
av_calloc(
s->nb_display_channels,
sizeof(*
s->fft_data));
1195 s->fft_scratch =
av_calloc(
s->nb_display_channels,
sizeof(*
s->fft_scratch));
1196 if (!
s->fft_scratch)
1198 for (
i = 0;
i <
s->nb_display_channels;
i++) {
1203 s->fft_data[
i] =
av_calloc(
s->buf_size,
sizeof(**
s->fft_data));
1204 if (!
s->fft_data[
i])
1207 s->fft_scratch[
i] =
av_calloc(
s->buf_size,
sizeof(**
s->fft_scratch));
1208 if (!
s->fft_scratch[
i])
1213 s->window_func_lut =
1215 sizeof(*
s->window_func_lut));
1216 if (!
s->window_func_lut)
1219 if (
s->overlap == 1)
1220 s->overlap = overlap;
1221 s->hop_size = (1.f -
s->overlap) *
s->win_size;
1222 if (
s->hop_size < 1) {
1227 for (
s->win_scale = 0,
i = 0; i < s->win_size;
i++) {
1228 s->win_scale +=
s->window_func_lut[
i] *
s->window_func_lut[
i];
1230 s->win_scale = 1.f /
sqrtf(
s->win_scale);
1234 s->outpicref = outpicref =
1239 for (
i = 0;
i < outlink->
h;
i++) {
1240 memset(outpicref->
data[0] +
i * outpicref->
linesize[0], 0, outlink->
w);
1241 memset(outpicref->
data[1] +
i * outpicref->
linesize[1], 128, outlink->
w);
1242 memset(outpicref->
data[2] +
i * outpicref->
linesize[2], 128, outlink->
w);
1243 if (outpicref->
data[3])
1244 memset(outpicref->
data[3] +
i * outpicref->
linesize[3], 0, outlink->
w);
1248 if (!
s->single_pic &&
s->legend)
1252 if ((
s->orientation ==
VERTICAL &&
s->xpos >=
s->w) ||
1268 if (!
s->single_pic && strcmp(
s->rate_str,
"auto")) {
1272 }
else if (
s->single_pic) {
1275 s->frame_rate =
s->auto_frame_rate;
1283 sizeof(*
s->combine_buffer));
1287 sizeof(*
s->combine_buffer));
1289 if (!
s->combine_buffer)
1293 s->w,
s->h,
s->win_size);
1307 #define RE(y, ch) s->fft_data[ch][y].re
1308 #define IM(y, ch) s->fft_data[ch][y].im
1309 #define MAGNITUDE(y, ch) hypotf(RE(y, ch), IM(y, ch))
1310 #define PHASE(y, ch) atan2f(IM(y, ch), RE(y, ch))
1315 const double w =
s->win_scale * (
s->scale ==
LOG ?
s->win_scale : 1);
1317 const float f =
s->gain *
w;
1318 const int ch = jobnr;
1319 float *magnitudes =
s->magnitudes[ch];
1321 for (y = 0; y <
h; y++)
1330 const int h =
s->orientation ==
VERTICAL ?
s->h :
s->w;
1331 const int ch = jobnr;
1332 float *phases =
s->phases[ch];
1335 for (y = 0; y <
h; y++)
1336 phases[y] = (
PHASE(y, ch) /
M_PI + 1) / 2;
1343 const float rng = 2.f *
M_PI;
1345 float max = -FLT_MAX;
1346 float min = FLT_MAX;
1348 for (
int i = 0;
i <
N;
i++) {
1349 const float d = x[
FFMIN(
i + 1,
N)] - x[
i];
1350 const float p =
ceilf(
fabsf(d) / rng) * rng * (((d < tol) > 0.f) - ((d > -tol) > 0.f));
1365 const int h =
s->orientation ==
VERTICAL ?
s->h :
s->w;
1366 const int ch = jobnr;
1367 float *phases =
s->phases[ch];
1371 for (y = 0; y <
h; y++)
1372 phases[y] =
PHASE(y, ch);
1375 for (y = 0; y <
h; y++)
1383 const double w =
s->win_scale * (
s->scale ==
LOG ?
s->win_scale : 1);
1384 int ch, y,
h =
s->orientation ==
VERTICAL ?
s->h :
s->w;
1385 const float f =
s->gain *
w;
1387 for (ch = 0; ch <
s->nb_display_channels; ch++) {
1388 float *magnitudes =
s->magnitudes[ch];
1390 for (y = 0; y <
h; y++)
1397 int ch, y,
h =
s->orientation ==
VERTICAL ?
s->h :
s->w;
1399 for (ch = 0; ch <
s->nb_display_channels; ch++) {
1400 float *magnitudes =
s->magnitudes[ch];
1402 for (y = 0; y <
h; y++)
1403 magnitudes[y] *=
scale;
1411 for (y = 0; y <
size; y++) {
1412 s->combine_buffer[4 * y ] = 0;
1413 s->combine_buffer[4 * y + 1] = 127.5;
1414 s->combine_buffer[4 * y + 2] = 127.5;
1415 s->combine_buffer[4 * y + 3] = 0;
1425 int ret, plane, x, y, z =
s->orientation ==
VERTICAL ?
s->h :
s->w;
1434 for (y = 0; y < z * 4; y++) {
1435 for (x = 0; x <
s->nb_display_channels; x++) {
1436 s->combine_buffer[y] +=
s->color_buffer[x][y];
1443 outpicref =
s->outpicref;
1447 for (plane = 0; plane < 3 +
alpha; plane++) {
1448 for (y = 0; y <
s->h; y++) {
1449 uint8_t *p = outpicref->
data[plane] +
s->start_x +
1450 (y +
s->start_y) * outpicref->
linesize[plane];
1451 memmove(p, p + 1,
s->w - 1);
1455 }
else if (
s->sliding ==
RSCROLL) {
1456 for (plane = 0; plane < 3 +
alpha; plane++) {
1457 for (y = 0; y <
s->h; y++) {
1458 uint8_t *p = outpicref->
data[plane] +
s->start_x +
1459 (y +
s->start_y) * outpicref->
linesize[plane];
1460 memmove(p + 1, p,
s->w - 1);
1465 for (plane = 0; plane < 3; plane++) {
1466 uint8_t *p = outpicref->
data[plane] +
s->start_x +
1467 (outlink->
h - 1 -
s->start_y) * outpicref->
linesize[plane] +
1469 for (y = 0; y <
s->h; y++) {
1475 uint8_t *p = outpicref->
data[3] +
s->start_x +
1476 (outlink->
h - 1 -
s->start_y) * outpicref->
linesize[3] +
1478 for (y = 0; y <
s->h; y++) {
1485 for (plane = 0; plane < 3 +
alpha; plane++) {
1486 for (y = 1; y <
s->h; y++) {
1487 memmove(outpicref->
data[plane] + (y-1 +
s->start_y) * outpicref->
linesize[plane] +
s->start_x,
1488 outpicref->
data[plane] + (y +
s->start_y) * outpicref->
linesize[plane] +
s->start_x,
1493 }
else if (
s->sliding ==
RSCROLL) {
1494 for (plane = 0; plane < 3 +
alpha; plane++) {
1495 for (y =
s->h - 1; y >= 1; y--) {
1496 memmove(outpicref->
data[plane] + (y +
s->start_y) * outpicref->
linesize[plane] +
s->start_x,
1497 outpicref->
data[plane] + (y-1 +
s->start_y) * outpicref->
linesize[plane] +
s->start_x,
1503 for (plane = 0; plane < 3; plane++) {
1504 uint8_t *p = outpicref->
data[plane] +
s->start_x +
1505 (
s->xpos +
s->start_y) * outpicref->
linesize[plane];
1506 for (x = 0; x <
s->w; x++) {
1512 uint8_t *p = outpicref->
data[3] +
s->start_x +
1513 (
s->xpos +
s->start_y) * outpicref->
linesize[3];
1514 for (x = 0; x <
s->w; x++) {
1526 if (
s->orientation ==
VERTICAL &&
s->xpos < 0)
1532 if (
s->orientation ==
VERTICAL &&
s->xpos >=
s->w)
1538 if (!
s->single_pic && (
s->sliding !=
FULLFRAME ||
s->xpos == 0)) {
1549 for (y = 0; y < 10; y++) {
1550 memset(
s->outpicref->data[0] + outlink->
w / 2 - 4 *
s->old_len +
1551 (outlink->
h -
s->start_y / 2 - 20 + y) *
s->outpicref->linesize[0], 0, 10 *
s->old_len);
1554 outlink->
w / 2 - 4 * strlen(units),
1555 outlink->
h -
s->start_y / 2 - 20,
1558 for (y = 0; y < 10 *
s->old_len; y++) {
1559 memset(
s->outpicref->data[0] +
s->start_x / 7 + 20 +
1560 (outlink->
h / 2 - 4 *
s->old_len + y) *
s->outpicref->linesize[0], 0, 10);
1563 s->start_x / 7 + 20,
1564 outlink->
h / 2 - 4 * strlen(units),
1567 s->old_len = strlen(units);
1570 s->old_pts = outpicref->
pts;
1584 #if CONFIG_SHOWSPECTRUM_FILTER
1615 s->in_pts = fin->
pts;
1624 s->xpos > 0 &&
s->outpicref) {
1627 for (
int i = 0;
i < outlink->
h;
i++) {
1628 memset(
s->outpicref->data[0] +
i *
s->outpicref->linesize[0] +
s->xpos, 0, outlink->
w -
s->xpos);
1629 memset(
s->outpicref->data[1] +
i *
s->outpicref->linesize[1] +
s->xpos, 128, outlink->
w -
s->xpos);
1630 memset(
s->outpicref->data[2] +
i *
s->outpicref->linesize[2] +
s->xpos, 128, outlink->
w -
s->xpos);
1631 if (
s->outpicref->data[3])
1632 memset(
s->outpicref->data[3] +
i *
s->outpicref->linesize[3] +
s->xpos, 0, outlink->
w -
s->xpos);
1635 for (
int i =
s->xpos; i < outlink->
h;
i++) {
1636 memset(
s->outpicref->data[0] +
i *
s->outpicref->linesize[0], 0, outlink->
w);
1637 memset(
s->outpicref->data[1] +
i *
s->outpicref->linesize[1], 128, outlink->
w);
1638 memset(
s->outpicref->data[2] +
i *
s->outpicref->linesize[2], 128, outlink->
w);
1639 if (
s->outpicref->data[3])
1640 memset(
s->outpicref->data[3] +
i *
s->outpicref->linesize[3], 0, outlink->
w);
1644 pts =
s->outpicref->pts;
1646 s->outpicref =
NULL;
1675 static const AVFilterPad showspectrum_outputs[] = {
1684 .
name =
"showspectrum",
1692 .priv_class = &showspectrum_class,
1695 #endif // CONFIG_SHOWSPECTRUM_FILTER
1697 #if CONFIG_SHOWSPECTRUMPIC_FILTER
1699 static const AVOption showspectrumpic_options[] = {
1749 static int showspectrumpic_request_frame(
AVFilterLink *outlink)
1759 int x = 0, sz =
s->orientation ==
VERTICAL ?
s->w :
s->h;
1760 unsigned int nb_frame = 0;
1765 spf =
s->win_size * (
s->samples / ((
s->win_size * sz) *
ceil(
s->samples / (
float)(
s->win_size * sz))));
1766 spf =
FFMAX(1, spf);
1769 spb = (
s->samples / (spf * sz)) * spf;
1776 int acc_samples = 0;
1779 while (nb_frame < s->nb_frames) {
1780 AVFrame *cur_frame =
s->frames[nb_frame];
1781 int cur_frame_samples = cur_frame->
nb_samples;
1784 if (acc_samples < spf) {
1785 nb_samples =
FFMIN(spf - acc_samples, cur_frame_samples - src_offset);
1786 acc_samples += nb_samples;
1788 dst_offset, src_offset, nb_samples,
1792 src_offset += nb_samples;
1793 dst_offset += nb_samples;
1794 if (cur_frame_samples <= src_offset) {
1800 if (acc_samples == spf)
1808 if (consumed >= spb) {
1815 for (ch = 0; ch <
s->nb_display_channels; ch++)
1816 memset(
s->magnitudes[ch], 0,
h *
sizeof(
float));
1821 s->outpicref->pts = 0;
1827 s->outpicref =
NULL;
1839 if (
s->nb_frames + 1ULL >
s->frames_size /
sizeof(*(
s->frames))) {
1846 s->frames[
s->nb_frames] = insamples;
1853 static const AVFilterPad showspectrumpic_inputs[] = {
1857 .filter_frame = showspectrumpic_filter_frame,
1861 static const AVFilterPad showspectrumpic_outputs[] = {
1866 .request_frame = showspectrumpic_request_frame,
1871 .
name =
"showspectrumpic",
1872 .description =
NULL_IF_CONFIG_SMALL(
"Convert input audio to a spectrum video output single picture."),
1878 .priv_class = &showspectrumpic_class,
1882 #endif // CONFIG_SHOWSPECTRUMPIC_FILTER