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) {
396 const float *window_func_lut =
s->window_func_lut;
398 const int ch = jobnr;
403 float *in_frame = (
float *)
s->in_frame->extended_data[ch];
405 memmove(in_frame, in_frame +
s->hop_size, (
s->fft_size -
s->hop_size) *
sizeof(
float));
406 memcpy(in_frame +
s->fft_size -
s->hop_size, p, fin->
nb_samples *
sizeof(
float));
409 in_frame[
i +
s->fft_size -
s->hop_size] = 0.f;
412 float theta, phi, psi,
a,
b,
S,
c;
418 int M =
s->win_size / 2;
420 for (n = 0; n <
s->win_size; n++) {
421 s->fft_data[ch][n].re = in_frame[n] * window_func_lut[n];
422 s->fft_data[ch][n].im = 0;
425 phi = 2.f *
M_PI * (
s->stop -
s->start) / (
float)
inlink->sample_rate / (
M - 1);
428 for (
int n = 0; n <
M; n++) {
429 h[n].re =
cosf(n * n / 2.
f * phi);
430 h[n].im =
sinf(n * n / 2.
f * phi);
433 for (
int n =
M; n <
L; n++) {
438 for (
int n =
L -
N; n <
L; n++) {
439 h[n].re =
cosf((
L - n) * (
L - n) / 2.
f * phi);
440 h[n].im =
sinf((
L - n) * (
L - n) / 2.
f * phi);
443 for (
int n =
N; n <
L; n++) {
448 for (
int n = 0; n <
N; n++) {
449 psi = n * theta + n * n / 2.f * phi;
452 a =
c *
g[n].re -
S *
g[n].im;
453 b =
S *
g[n].re +
c *
g[n].im;
458 memcpy(
f,
h,
s->buf_size *
sizeof(*
f));
461 memcpy(
f,
g,
s->buf_size *
sizeof(*
f));
464 for (
int n = 0; n <
L; n++) {
467 a =
c *
h[n].re -
S *
h[n].im;
468 b =
S *
h[n].re +
c *
h[n].im;
474 memcpy(
f,
g,
s->buf_size *
sizeof(*
f));
477 for (
int k = 0; k <
M; k++) {
478 psi = k * k / 2.f * phi;
481 a =
c *
g[k].re -
S *
g[k].im;
482 b =
S *
g[k].re +
c *
g[k].im;
483 s->fft_data[ch][k].re =
a;
484 s->fft_data[ch][k].im =
b;
487 for (n = 0; n <
s->win_size; n++) {
488 s->fft_in[ch][n].re = in_frame[n] * window_func_lut[n];
489 s->fft_in[ch][n].im = 0;
506 for (
int i = 0; txt[
i];
i++) {
510 for (char_y = font_height - 1; char_y >= 0; char_y--) {
511 uint8_t *p = pic->
data[0] + (y +
i * 10) * pic->
linesize[0] + x;
513 if (font[txt[
i] * font_height + font_height - 1 - char_y] &
mask)
514 p[char_y] = ~p[char_y];
520 for (char_y = 0; char_y < font_height; char_y++) {
522 if (font[txt[
i] * font_height + char_y] &
mask)
531 for (
int i = 0; txt[
i] && pic->
data[3];
i++) {
535 for (char_y = font_height - 1; char_y >= 0; char_y--) {
536 uint8_t *p = pic->
data[3] + (y +
i * 10) * pic->
linesize[3] + x;
538 for (
int k = 0; k < 8; k++)
545 for (char_y = 0; char_y < font_height; char_y++) {
555 float *yf,
float *uf,
float *vf)
560 *yf = 256.0f /
s->nb_display_channels;
561 switch (
s->color_mode) {
600 if (
s->nb_display_channels > 1) {
601 *uf *= 0.5f *
sinf((2 *
M_PI * ch) /
s->nb_display_channels +
M_PI *
s->rotation);
602 *vf *= 0.5f *
cosf((2 *
M_PI * ch) /
s->nb_display_channels +
M_PI *
s->rotation);
612 *uf *=
s->saturation;
613 *vf *=
s->saturation;
617 float yf,
float uf,
float vf,
620 const float af =
s->opacity_factor * 255.f;
623 const int cm =
s->color_mode;
643 float lerpfrac = (
a - start) / (end - start);
670 else if (log10(seconds) > 6)
672 else if (log10(seconds) > 3)
680 const float bmin,
const float bmax,
681 const float min,
const float max)
686 static float get_hz(
const float bin,
const float bmax,
687 const float min,
const float max,
701 float bmin,
float bmax,
707 static float bin_pos(
const int bin,
const int num_bins,
const float min,
const float max)
715 const float dmin =
s->dmin;
716 const float dmax =
s->dmax;
720 a = (
a - dmin) / (dmax - dmin);
738 a = (
s->drange -
s->limit +
log10f(
a) * 20.f) /
s->drange;
750 const float dmin =
s->dmin;
751 const float dmax =
s->dmax;
776 a =
a * (dmax - dmin) + dmin;
786 int ch, y, x = 0, sz =
s->orientation ==
VERTICAL ?
s->w :
s->h;
791 char chlayout_str[128];
799 drawtext(
s->outpicref, 2, outlink->
h - 10,
"CREATED BY LIBAVFILTER", 0);
800 drawtext(
s->outpicref, outlink->
w - 2 - strlen(text) * 10, outlink->
h - 10, text, 0);
803 text =
av_asprintf(
"Zoom: %d Hz - %d Hz",
s->start,
s->stop);
806 drawtext(
s->outpicref, outlink->
w - 2 - strlen(text) * 10, 3, text, 0);
810 dst =
s->outpicref->data[0] + (
s->start_y - 1) *
s->outpicref->linesize[0] +
s->start_x - 1;
811 for (x = 0; x <
s->w + 1; x++)
813 dst =
s->outpicref->data[0] + (
s->start_y +
s->h) *
s->outpicref->linesize[0] +
s->start_x - 1;
814 for (x = 0; x <
s->w + 1; x++)
816 for (y = 0; y <
s->h + 2; y++) {
817 dst =
s->outpicref->data[0] + (y +
s->start_y - 1) *
s->outpicref->linesize[0];
818 dst[
s->start_x - 1] = 200;
819 dst[
s->start_x +
s->w] = 200;
822 int h =
s->mode ==
SEPARATE ?
s->h /
s->nb_display_channels :
s->h;
823 int hh =
s->mode ==
SEPARATE ? -(
s->h %
s->nb_display_channels) + 1 : 1;
824 for (ch = 0; ch < (
s->mode ==
SEPARATE ?
s->nb_display_channels : 1); ch++) {
825 for (y = 0; y <
h; y += 20) {
826 dst =
s->outpicref->data[0] + (
s->start_y +
h * (ch + 1) - y - hh) *
s->outpicref->linesize[0];
827 dst[
s->start_x - 2] = 200;
828 dst[
s->start_x +
s->w + 1] = 200;
830 for (y = 0; y <
h; y += 40) {
831 dst =
s->outpicref->data[0] + (
s->start_y +
h * (ch + 1) - y - hh) *
s->outpicref->linesize[0];
832 dst[
s->start_x - 3] = 200;
833 dst[
s->start_x +
s->w + 2] = 200;
835 dst =
s->outpicref->data[0] + (
s->start_y - 2) *
s->outpicref->linesize[0] +
s->start_x;
836 for (x = 0; x <
s->w; x+=40)
838 dst =
s->outpicref->data[0] + (
s->start_y - 3) *
s->outpicref->linesize[0] +
s->start_x;
839 for (x = 0; x <
s->w; x+=80)
841 dst =
s->outpicref->data[0] + (
s->h +
s->start_y + 1) *
s->outpicref->linesize[0] +
s->start_x;
842 for (x = 0; x <
s->w; x+=40) {
845 dst =
s->outpicref->data[0] + (
s->h +
s->start_y + 2) *
s->outpicref->linesize[0] +
s->start_x;
846 for (x = 0; x <
s->w; x+=80) {
849 for (y = 0; y <
h; y += 40) {
850 float range =
s->stop ?
s->stop -
s->start :
inlink->sample_rate / 2;
861 drawtext(
s->outpicref,
s->start_x - 8 * strlen(units) - 4,
h * (ch + 1) +
s->start_y - y - 4 - hh, units, 0);
866 for (x = 0; x <
s->w &&
s->single_pic; x+=80) {
867 float seconds = x * spp /
inlink->sample_rate;
872 drawtext(
s->outpicref,
s->start_x + x - 4 * strlen(units),
s->h +
s->start_y + 6, units, 0);
873 drawtext(
s->outpicref,
s->start_x + x - 4 * strlen(units),
s->start_y - 12, units, 0);
877 drawtext(
s->outpicref, outlink->
w / 2 - 4 * 4, outlink->
h -
s->start_y / 2,
"TIME", 0);
878 drawtext(
s->outpicref,
s->start_x / 7, outlink->
h / 2 - 14 * 4,
"FREQUENCY (Hz)", 1);
880 int w =
s->mode ==
SEPARATE ?
s->w /
s->nb_display_channels :
s->w;
881 for (y = 0; y <
s->h; y += 20) {
882 dst =
s->outpicref->data[0] + (
s->start_y + y) *
s->outpicref->linesize[0];
883 dst[
s->start_x - 2] = 200;
884 dst[
s->start_x +
s->w + 1] = 200;
886 for (y = 0; y <
s->h; y += 40) {
887 dst =
s->outpicref->data[0] + (
s->start_y + y) *
s->outpicref->linesize[0];
888 dst[
s->start_x - 3] = 200;
889 dst[
s->start_x +
s->w + 2] = 200;
891 for (ch = 0; ch < (
s->mode ==
SEPARATE ?
s->nb_display_channels : 1); ch++) {
892 dst =
s->outpicref->data[0] + (
s->start_y - 2) *
s->outpicref->linesize[0] +
s->start_x +
w * ch;
893 for (x = 0; x <
w; x+=40)
895 dst =
s->outpicref->data[0] + (
s->start_y - 3) *
s->outpicref->linesize[0] +
s->start_x +
w * ch;
896 for (x = 0; x <
w; x+=80)
898 dst =
s->outpicref->data[0] + (
s->h +
s->start_y + 1) *
s->outpicref->linesize[0] +
s->start_x +
w * ch;
899 for (x = 0; x <
w; x+=40) {
902 dst =
s->outpicref->data[0] + (
s->h +
s->start_y + 2) *
s->outpicref->linesize[0] +
s->start_x +
w * ch;
903 for (x = 0; x <
w; x+=80) {
906 for (x = 0; x <
w - 79; x += 80) {
907 float range =
s->stop ?
s->stop -
s->start :
inlink->sample_rate / 2;
918 drawtext(
s->outpicref,
s->start_x - 4 * strlen(units) + x +
w * ch,
s->start_y - 12, units, 0);
919 drawtext(
s->outpicref,
s->start_x - 4 * strlen(units) + x +
w * ch,
s->h +
s->start_y + 6, units, 0);
923 for (y = 0; y <
s->h &&
s->single_pic; y+=40) {
924 float seconds = y * spp /
inlink->sample_rate;
929 drawtext(
s->outpicref,
s->start_x - 8 * strlen(units) - 4,
s->start_y + y - 4, units, 0);
932 drawtext(
s->outpicref,
s->start_x / 7, outlink->
h / 2 - 4 * 4,
"TIME", 1);
933 drawtext(
s->outpicref, outlink->
w / 2 - 14 * 4, outlink->
h -
s->start_y / 2,
"FREQUENCY (Hz)", 0);
936 for (ch = 0; ch < (multi ?
s->nb_display_channels : 1); ch++) {
937 int h = multi ?
s->h /
s->nb_display_channels :
s->h;
939 for (y = 0; y <
h; y++) {
940 float out[4] = { 0., 127.5, 127.5, 0.f};
943 for (chn = 0; chn < (
s->mode ==
SEPARATE ? 1 :
s->nb_display_channels); chn++) {
945 int channel = (multi) ?
s->nb_display_channels - ch - 1 : chn;
955 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);
956 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);
957 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);
958 if (
s->outpicref->data[3])
959 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);
962 for (y = 0; ch == 0 && y <
h + 5; y += 25) {
963 static const char *log_fmt =
"%.0f";
964 static const char *lin_fmt =
"%.3f";
965 const float a =
av_clipf(1.
f - y / (
float)(
h - 1), 0.
f, 1.
f);
972 drawtext(
s->outpicref,
s->w +
s->start_x + 35,
s->start_y + y - 3, text, 0);
978 drawtext(
s->outpicref,
s->w +
s->start_x + 22,
s->start_y +
s->h + 20,
"dBFS", 0);
986 float *magnitudes =
s->magnitudes[ch];
987 float *phases =
s->phases[ch];
1010 const int h =
s->orientation ==
VERTICAL ?
s->channel_height :
s->channel_width;
1011 const int ch = jobnr;
1019 for (y = 0; y <
h; y++) {
1020 int row = (
s->mode ==
COMBINED) ? y : ch *
h + y;
1021 float *
out = &
s->color_buffer[ch][4 * row];
1034 const int h =
s->orientation ==
VERTICAL ?
s->channel_height :
s->channel_width;
1035 const int ch = jobnr;
1042 for (
int yy = 0; yy <
h; yy++) {
1043 float range =
s->stop ?
s->stop -
s->start :
inlink->sample_rate / 2;
1051 int row = (
s->mode ==
COMBINED) ? yy : ch *
h + yy;
1052 float *
out = &
s->color_buffer[ch][4 * row];
1066 int i, fft_size,
h,
w,
ret;
1073 switch (
s->fscale) {
1080 if ((
s->stop ||
s->start) &&
s->stop <=
s->start) {
1085 if (!strcmp(
ctx->filter->name,
"showspectrumpic"))
1093 s->start_x = (log10(
inlink->sample_rate) + 1) * 25;
1095 outlink->
w +=
s->start_x * 2;
1096 outlink->
h +=
s->start_y * 2;
1101 s->channel_height =
h;
1102 s->channel_width =
w;
1112 s->win_size = fft_size;
1130 if (fft_size !=
s->fft_size) {
1133 s->fft_size = fft_size;
1138 for (
i = 0;
i <
s->nb_display_channels;
i++) {
1149 s->nb_display_channels =
inlink->ch_layout.nb_channels;
1150 for (
i = 0;
i <
s->nb_display_channels;
i++) {
1158 "The window size might be too high.\n");
1164 "The window size might be too high.\n");
1169 s->magnitudes =
av_calloc(
s->nb_display_channels,
sizeof(*
s->magnitudes));
1172 for (
i = 0;
i <
s->nb_display_channels;
i++) {
1174 if (!
s->magnitudes[
i])
1178 s->phases =
av_calloc(
s->nb_display_channels,
sizeof(*
s->phases));
1181 for (
i = 0;
i <
s->nb_display_channels;
i++) {
1188 s->color_buffer =
av_calloc(
s->nb_display_channels,
sizeof(*
s->color_buffer));
1189 if (!
s->color_buffer)
1191 for (
i = 0;
i <
s->nb_display_channels;
i++) {
1193 if (!
s->color_buffer[
i])
1197 s->fft_in =
av_calloc(
s->nb_display_channels,
sizeof(*
s->fft_in));
1200 s->fft_data =
av_calloc(
s->nb_display_channels,
sizeof(*
s->fft_data));
1203 s->fft_scratch =
av_calloc(
s->nb_display_channels,
sizeof(*
s->fft_scratch));
1204 if (!
s->fft_scratch)
1206 for (
i = 0;
i <
s->nb_display_channels;
i++) {
1211 s->fft_data[
i] =
av_calloc(
s->buf_size,
sizeof(**
s->fft_data));
1212 if (!
s->fft_data[
i])
1215 s->fft_scratch[
i] =
av_calloc(
s->buf_size,
sizeof(**
s->fft_scratch));
1216 if (!
s->fft_scratch[
i])
1221 s->window_func_lut =
1223 sizeof(*
s->window_func_lut));
1224 if (!
s->window_func_lut)
1227 if (
s->overlap == 1)
1228 s->overlap = overlap;
1229 s->hop_size = (1.f -
s->overlap) *
s->win_size;
1230 if (
s->hop_size < 1) {
1235 for (
s->win_scale = 0,
i = 0; i < s->win_size;
i++) {
1236 s->win_scale +=
s->window_func_lut[
i] *
s->window_func_lut[
i];
1238 s->win_scale = 1.f /
sqrtf(
s->win_scale);
1242 s->outpicref = outpicref =
1247 for (
i = 0;
i < outlink->
h;
i++) {
1248 memset(outpicref->
data[0] +
i * outpicref->
linesize[0], 0, outlink->
w);
1249 memset(outpicref->
data[1] +
i * outpicref->
linesize[1], 128, outlink->
w);
1250 memset(outpicref->
data[2] +
i * outpicref->
linesize[2], 128, outlink->
w);
1251 if (outpicref->
data[3])
1252 memset(outpicref->
data[3] +
i * outpicref->
linesize[3], 0, outlink->
w);
1256 if (!
s->single_pic &&
s->legend)
1260 if ((
s->orientation ==
VERTICAL &&
s->xpos >=
s->w) ||
1276 if (!
s->single_pic && strcmp(
s->rate_str,
"auto")) {
1280 }
else if (
s->single_pic) {
1283 s->frame_rate =
s->auto_frame_rate;
1291 sizeof(*
s->combine_buffer));
1295 sizeof(*
s->combine_buffer));
1297 if (!
s->combine_buffer)
1301 s->w,
s->h,
s->win_size);
1315 #define RE(y, ch) s->fft_data[ch][y].re
1316 #define IM(y, ch) s->fft_data[ch][y].im
1317 #define MAGNITUDE(y, ch) hypotf(RE(y, ch), IM(y, ch))
1318 #define PHASE(y, ch) atan2f(IM(y, ch), RE(y, ch))
1323 const double w =
s->win_scale * (
s->scale ==
LOG ?
s->win_scale : 1);
1325 const float f =
s->gain *
w;
1326 const int ch = jobnr;
1327 float *magnitudes =
s->magnitudes[ch];
1329 for (y = 0; y <
h; y++)
1338 const int h =
s->orientation ==
VERTICAL ?
s->h :
s->w;
1339 const int ch = jobnr;
1340 float *phases =
s->phases[ch];
1343 for (y = 0; y <
h; y++)
1344 phases[y] = (
PHASE(y, ch) /
M_PI + 1) / 2;
1351 const float rng = 2.f *
M_PI;
1353 float max = -FLT_MAX;
1354 float min = FLT_MAX;
1356 for (
int i = 0;
i <
N;
i++) {
1357 const float d = x[
FFMIN(
i + 1,
N)] - x[
i];
1358 const float p =
ceilf(
fabsf(
d) / rng) * rng * (((d < tol) > 0.f) - ((
d > -tol) > 0.f));
1373 const int h =
s->orientation ==
VERTICAL ?
s->h :
s->w;
1374 const int ch = jobnr;
1375 float *phases =
s->phases[ch];
1379 for (y = 0; y <
h; y++)
1380 phases[y] =
PHASE(y, ch);
1383 for (y = 0; y <
h; y++)
1391 const double w =
s->win_scale * (
s->scale ==
LOG ?
s->win_scale : 1);
1392 int ch, y,
h =
s->orientation ==
VERTICAL ?
s->h :
s->w;
1393 const float f =
s->gain *
w;
1395 for (ch = 0; ch <
s->nb_display_channels; ch++) {
1396 float *magnitudes =
s->magnitudes[ch];
1398 for (y = 0; y <
h; y++)
1405 int ch, y,
h =
s->orientation ==
VERTICAL ?
s->h :
s->w;
1407 for (ch = 0; ch <
s->nb_display_channels; ch++) {
1408 float *magnitudes =
s->magnitudes[ch];
1410 for (y = 0; y <
h; y++)
1411 magnitudes[y] *=
scale;
1419 for (y = 0; y <
size; y++) {
1420 s->combine_buffer[4 * y ] = 0;
1421 s->combine_buffer[4 * y + 1] = 127.5;
1422 s->combine_buffer[4 * y + 2] = 127.5;
1423 s->combine_buffer[4 * y + 3] = 0;
1433 int ret, plane, x, y, z =
s->orientation ==
VERTICAL ?
s->h :
s->w;
1442 for (y = 0; y < z * 4; y++) {
1443 for (x = 0; x <
s->nb_display_channels; x++) {
1444 s->combine_buffer[y] +=
s->color_buffer[x][y];
1451 outpicref =
s->outpicref;
1455 for (plane = 0; plane < 3 +
alpha; plane++) {
1456 for (y = 0; y <
s->h; y++) {
1457 uint8_t *p = outpicref->
data[plane] +
s->start_x +
1458 (y +
s->start_y) * outpicref->
linesize[plane];
1459 memmove(p, p + 1,
s->w - 1);
1463 }
else if (
s->sliding ==
RSCROLL) {
1464 for (plane = 0; plane < 3 +
alpha; plane++) {
1465 for (y = 0; y <
s->h; y++) {
1466 uint8_t *p = outpicref->
data[plane] +
s->start_x +
1467 (y +
s->start_y) * outpicref->
linesize[plane];
1468 memmove(p + 1, p,
s->w - 1);
1473 for (plane = 0; plane < 3; plane++) {
1474 uint8_t *p = outpicref->
data[plane] +
s->start_x +
1475 (outlink->
h - 1 -
s->start_y) * outpicref->
linesize[plane] +
1477 for (y = 0; y <
s->h; y++) {
1483 uint8_t *p = outpicref->
data[3] +
s->start_x +
1484 (outlink->
h - 1 -
s->start_y) * outpicref->
linesize[3] +
1486 for (y = 0; y <
s->h; y++) {
1493 for (plane = 0; plane < 3 +
alpha; plane++) {
1494 for (y = 1; y <
s->h; y++) {
1495 memmove(outpicref->
data[plane] + (y-1 +
s->start_y) * outpicref->
linesize[plane] +
s->start_x,
1496 outpicref->
data[plane] + (y +
s->start_y) * outpicref->
linesize[plane] +
s->start_x,
1501 }
else if (
s->sliding ==
RSCROLL) {
1502 for (plane = 0; plane < 3 +
alpha; plane++) {
1503 for (y =
s->h - 1; y >= 1; y--) {
1504 memmove(outpicref->
data[plane] + (y +
s->start_y) * outpicref->
linesize[plane] +
s->start_x,
1505 outpicref->
data[plane] + (y-1 +
s->start_y) * outpicref->
linesize[plane] +
s->start_x,
1511 for (plane = 0; plane < 3; plane++) {
1512 uint8_t *p = outpicref->
data[plane] +
s->start_x +
1513 (
s->xpos +
s->start_y) * outpicref->
linesize[plane];
1514 for (x = 0; x <
s->w; x++) {
1520 uint8_t *p = outpicref->
data[3] +
s->start_x +
1521 (
s->xpos +
s->start_y) * outpicref->
linesize[3];
1522 for (x = 0; x <
s->w; x++) {
1534 if (
s->orientation ==
VERTICAL &&
s->xpos < 0)
1540 if (
s->orientation ==
VERTICAL &&
s->xpos >=
s->w)
1546 if (!
s->single_pic && (
s->sliding !=
FULLFRAME ||
s->xpos == 0)) {
1557 for (y = 0; y < 10; y++) {
1558 memset(
s->outpicref->data[0] + outlink->
w / 2 - 4 *
s->old_len +
1559 (outlink->
h -
s->start_y / 2 - 20 + y) *
s->outpicref->linesize[0], 0, 10 *
s->old_len);
1562 outlink->
w / 2 - 4 * strlen(units),
1563 outlink->
h -
s->start_y / 2 - 20,
1566 for (y = 0; y < 10 *
s->old_len; y++) {
1567 memset(
s->outpicref->data[0] +
s->start_x / 7 + 20 +
1568 (outlink->
h / 2 - 4 *
s->old_len + y) *
s->outpicref->linesize[0], 0, 10);
1571 s->start_x / 7 + 20,
1572 outlink->
h / 2 - 4 * strlen(units),
1575 s->old_len = strlen(units);
1578 s->old_pts = outpicref->
pts;
1592 #if CONFIG_SHOWSPECTRUM_FILTER
1623 s->in_pts = fin->
pts;
1632 s->xpos > 0 &&
s->outpicref) {
1635 for (
int i = 0;
i < outlink->
h;
i++) {
1636 memset(
s->outpicref->data[0] +
i *
s->outpicref->linesize[0] +
s->xpos, 0, outlink->
w -
s->xpos);
1637 memset(
s->outpicref->data[1] +
i *
s->outpicref->linesize[1] +
s->xpos, 128, outlink->
w -
s->xpos);
1638 memset(
s->outpicref->data[2] +
i *
s->outpicref->linesize[2] +
s->xpos, 128, outlink->
w -
s->xpos);
1639 if (
s->outpicref->data[3])
1640 memset(
s->outpicref->data[3] +
i *
s->outpicref->linesize[3] +
s->xpos, 0, outlink->
w -
s->xpos);
1643 for (
int i =
s->xpos; i < outlink->
h;
i++) {
1644 memset(
s->outpicref->data[0] +
i *
s->outpicref->linesize[0], 0, outlink->
w);
1645 memset(
s->outpicref->data[1] +
i *
s->outpicref->linesize[1], 128, outlink->
w);
1646 memset(
s->outpicref->data[2] +
i *
s->outpicref->linesize[2], 128, outlink->
w);
1647 if (
s->outpicref->data[3])
1648 memset(
s->outpicref->data[3] +
i *
s->outpicref->linesize[3], 0, outlink->
w);
1652 pts =
s->outpicref->pts;
1654 s->outpicref =
NULL;
1683 static const AVFilterPad showspectrum_outputs[] = {
1692 .
name =
"showspectrum",
1700 .priv_class = &showspectrum_class,
1703 #endif // CONFIG_SHOWSPECTRUM_FILTER
1705 #if CONFIG_SHOWSPECTRUMPIC_FILTER
1707 static const AVOption showspectrumpic_options[] = {
1757 static int showspectrumpic_request_frame(
AVFilterLink *outlink)
1767 int x = 0, sz =
s->orientation ==
VERTICAL ?
s->w :
s->h;
1768 unsigned int nb_frame = 0;
1773 spf =
s->win_size * (
s->samples / ((
s->win_size * sz) *
ceil(
s->samples / (
float)(
s->win_size * sz))));
1774 spf =
FFMAX(1, spf);
1777 spb = (
s->samples / (spf * sz)) * spf;
1784 int acc_samples = 0;
1787 while (nb_frame < s->nb_frames) {
1788 AVFrame *cur_frame =
s->frames[nb_frame];
1789 int cur_frame_samples = cur_frame->
nb_samples;
1792 if (acc_samples < spf) {
1793 nb_samples =
FFMIN(spf - acc_samples, cur_frame_samples - src_offset);
1794 acc_samples += nb_samples;
1796 dst_offset, src_offset, nb_samples,
1800 src_offset += nb_samples;
1801 dst_offset += nb_samples;
1802 if (cur_frame_samples <= src_offset) {
1808 if (acc_samples == spf)
1816 if (consumed >= spb) {
1823 for (ch = 0; ch <
s->nb_display_channels; ch++)
1824 memset(
s->magnitudes[ch], 0,
h *
sizeof(
float));
1829 s->outpicref->pts = 0;
1835 s->outpicref =
NULL;
1847 if (
s->nb_frames + 1ULL >
s->frames_size /
sizeof(*(
s->frames))) {
1854 s->frames[
s->nb_frames] = insamples;
1861 static const AVFilterPad showspectrumpic_inputs[] = {
1865 .filter_frame = showspectrumpic_filter_frame,
1869 static const AVFilterPad showspectrumpic_outputs[] = {
1874 .request_frame = showspectrumpic_request_frame,
1879 .
name =
"showspectrumpic",
1880 .description =
NULL_IF_CONFIG_SMALL(
"Convert input audio to a spectrum video output single picture."),
1886 .priv_class = &showspectrumpic_class,
1890 #endif // CONFIG_SHOWSPECTRUMPIC_FILTER