52 enum ColorMode    { 
CHANNEL, 
INTENSITY, 
RAINBOW, 
MORELAND, 
NEBULAE, 
FIRE, 
FIERY, 
FRUIT, 
COOL, 
MAGMA, 
GREEN, 
VIRIDIS, 
PLASMA, 
CIVIDIS, 
TERRAIN, 
NB_CLMODES };
 
  110 #define OFFSET(x) offsetof(ShowSpectrumContext, x) 
  111 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM 
  179     { 0.13, .03587126228984074,  .1573300977624594, -.02548747583751842 },
 
  180     { 0.30, .18572281794568020,  .1772436246393981,  .17475554840414750 },
 
  181     { 0.60, .28184980583656130, -.1593064119945782,  .47132074554608920 },
 
  182     { 0.73, .65830621175547810, -.3716070802232764,  .24352759331252930 },
 
  183     { 0.78, .76318535758242900, -.4307467689263783,  .16866496622310430 },
 
  184     { 0.91, .95336363636363640, -.2045454545454546,  .03313636363636363 },
 
  188     { 0.13,            44/256.,     (189-128)/256.,      (138-128)/256. },
 
  189     { 0.25,            29/256.,     (186-128)/256.,      (119-128)/256. },
 
  190     { 0.38,           119/256.,     (194-128)/256.,       (53-128)/256. },
 
  191     { 0.60,           111/256.,      (73-128)/256.,       (59-128)/256. },
 
  192     { 0.73,           205/256.,      (19-128)/256.,      (149-128)/256. },
 
  193     { 0.86,           135/256.,      (83-128)/256.,      (200-128)/256. },
 
  194     {    1,            73/256.,      (95-128)/256.,      (225-128)/256. }},
 
  196     {    0,            44/256.,     (181-128)/256.,      (112-128)/256. },
 
  197     { 0.13,           126/256.,     (177-128)/256.,      (106-128)/256. },
 
  198     { 0.25,           164/256.,     (163-128)/256.,      (109-128)/256. },
 
  199     { 0.38,           200/256.,     (140-128)/256.,      (120-128)/256. },
 
  200     { 0.60,           201/256.,     (117-128)/256.,      (141-128)/256. },
 
  201     { 0.73,           177/256.,     (103-128)/256.,      (165-128)/256. },
 
  202     { 0.86,           136/256.,     (100-128)/256.,      (183-128)/256. },
 
  203     {    1,            68/256.,     (117-128)/256.,      (203-128)/256. }},
 
  205     {    0,            10/256.,     (134-128)/256.,      (132-128)/256. },
 
  206     { 0.23,            21/256.,     (137-128)/256.,      (130-128)/256. },
 
  207     { 0.45,            35/256.,     (134-128)/256.,      (134-128)/256. },
 
  208     { 0.57,            51/256.,     (130-128)/256.,      (139-128)/256. },
 
  209     { 0.67,           104/256.,     (116-128)/256.,      (162-128)/256. },
 
  210     { 0.77,           120/256.,     (105-128)/256.,      (188-128)/256. },
 
  211     { 0.87,           140/256.,     (105-128)/256.,      (188-128)/256. },
 
  215     { 0.23,            44/256.,     (132-128)/256.,      (127-128)/256. },
 
  216     { 0.45,            62/256.,     (116-128)/256.,      (140-128)/256. },
 
  217     { 0.57,            75/256.,     (105-128)/256.,      (152-128)/256. },
 
  218     { 0.67,            95/256.,      (91-128)/256.,      (166-128)/256. },
 
  219     { 0.77,           126/256.,      (74-128)/256.,      (172-128)/256. },
 
  220     { 0.87,           164/256.,      (73-128)/256.,      (162-128)/256. },
 
  224     { 0.23,            36/256.,     (116-128)/256.,      (163-128)/256. },
 
  225     { 0.45,            52/256.,     (102-128)/256.,      (200-128)/256. },
 
  226     { 0.57,           116/256.,      (84-128)/256.,      (196-128)/256. },
 
  227     { 0.67,           157/256.,      (67-128)/256.,      (181-128)/256. },
 
  228     { 0.77,           193/256.,      (40-128)/256.,      (155-128)/256. },
 
  229     { 0.87,           221/256.,     (101-128)/256.,      (134-128)/256. },
 
  233     { 0.20,            29/256.,     (136-128)/256.,      (119-128)/256. },
 
  234     { 0.30,            60/256.,     (119-128)/256.,       (90-128)/256. },
 
  235     { 0.40,            85/256.,      (91-128)/256.,       (85-128)/256. },
 
  236     { 0.50,           116/256.,      (70-128)/256.,      (105-128)/256. },
 
  237     { 0.60,           151/256.,      (50-128)/256.,      (146-128)/256. },
 
  238     { 0.70,           191/256.,      (63-128)/256.,      (178-128)/256. },
 
  239     {    1,            98/256.,      (80-128)/256.,      (221-128)/256. }},
 
  246     { 0.10,            23/256.,     (175-128)/256.,      (120-128)/256. },
 
  247     { 0.23,            43/256.,     (158-128)/256.,      (144-128)/256. },
 
  248     { 0.35,            85/256.,     (138-128)/256.,      (179-128)/256. },
 
  249     { 0.48,            96/256.,     (128-128)/256.,      (189-128)/256. },
 
  250     { 0.64,           128/256.,     (103-128)/256.,      (214-128)/256. },
 
  251     { 0.92,           205/256.,      (80-128)/256.,      (152-128)/256. },
 
  259     { 0.10,          0x39/255.,   (0x9D -128)/255.,    (0x8F -128)/255. },
 
  260     { 0.23,          0x5C/255.,   (0x9A -128)/255.,    (0x68 -128)/255. },
 
  261     { 0.35,          0x69/255.,   (0x93 -128)/255.,    (0x57 -128)/255. },
 
  262     { 0.48,          0x76/255.,   (0x88 -128)/255.,    (0x4B -128)/255. },
 
  263     { 0.64,          0x8A/255.,   (0x72 -128)/255.,    (0x4F -128)/255. },
 
  264     { 0.80,          0xA3/255.,   (0x50 -128)/255.,    (0x66 -128)/255. },
 
  265     {    1,          0xCC/255.,   (0x2F -128)/255.,    (0x87 -128)/255. }},
 
  268     { 0.10,          0x27/255.,   (0xC2 -128)/255.,    (0x82 -128)/255. },
 
  269     { 0.58,          0x5B/255.,   (0x9A -128)/255.,    (0xAE -128)/255. },
 
  270     { 0.70,          0x89/255.,   (0x44 -128)/255.,    (0xAB -128)/255. },
 
  271     { 0.80,          0xB4/255.,   (0x2B -128)/255.,    (0x9E -128)/255. },
 
  272     { 0.91,          0xD2/255.,   (0x38 -128)/255.,    (0x92 -128)/255. },
 
  276     { 0.20,          0x28/255.,   (0x98 -128)/255.,    (0x6F -128)/255. },
 
  277     { 0.50,          0x48/255.,   (0x95 -128)/255.,    (0x74 -128)/255. },
 
  278     { 0.63,          0x69/255.,   (0x84 -128)/255.,    (0x7F -128)/255. },
 
  279     { 0.76,          0x89/255.,   (0x75 -128)/255.,    (0x84 -128)/255. },
 
  280     { 0.90,          0xCE/255.,   (0x35 -128)/255.,    (0x95 -128)/255. },
 
  285     { 0.60,                  1,                -.5,                 -.5 },
 
  286     { 0.85,                  1,                -.5,                  .5 },
 
  297         for (
i = 0; 
i < 
s->nb_display_channels; 
i++)
 
  302         for (
i = 0; 
i < 
s->nb_display_channels; 
i++)
 
  307         for (
i = 0; 
i < 
s->nb_display_channels; 
i++)
 
  312         for (
i = 0; 
i < 
s->nb_display_channels; 
i++)
 
  316     if (
s->fft_scratch) {
 
  317         for (
i = 0; 
i < 
s->nb_display_channels; 
i++)
 
  321     if (
s->color_buffer) {
 
  322         for (
i = 0; 
i < 
s->nb_display_channels; 
i++)
 
  328         for (
i = 0; 
i < 
s->nb_display_channels; 
i++)
 
  335         for (
i = 0; 
i < 
s->nb_display_channels; 
i++)
 
  376     const float *window_func_lut = 
s->window_func_lut;
 
  378     const int ch = jobnr;
 
  385         float theta, phi, psi, 
a, 
b, 
S, 
c;
 
  391         int M = 
s->win_size / 2;
 
  393         for (n = 0; n < 
s->win_size; n++) {
 
  394             s->fft_data[ch][n].re = p[n] * window_func_lut[n];
 
  395             s->fft_data[ch][n].im = 0;
 
  398         phi = 2.f * 
M_PI * (
s->stop - 
s->start) / (
float)
inlink->sample_rate / (
M - 1);
 
  399         theta = 2.f * 
M_PI * 
s->start / (float)
inlink->sample_rate;
 
  401         for (
int n = 0; n < 
M; n++) {
 
  402             h[n].re = 
cosf(n * n / 2.
f * phi);
 
  403             h[n].im = 
sinf(n * n / 2.
f * phi);
 
  406         for (
int n = 
M; n < 
L; n++) {
 
  411         for (
int n = 
L - 
N; n < 
L; n++) {
 
  412             h[n].re = 
cosf((
L - n) * (
L - n) / 2.
f * phi);
 
  413             h[n].im = 
sinf((
L - n) * (
L - n) / 2.
f * phi);
 
  416         for (
int n = 
N; n < 
L; n++) {
 
  421         for (
int n = 0; n < 
N; n++) {
 
  422             psi = n * theta + n * n / 2.f * phi;
 
  425             a = 
c * 
g[n].re - 
S * 
g[n].im;
 
  426             b = 
S * 
g[n].re + 
c * 
g[n].im;
 
  431         memcpy(
f, 
h, 
s->buf_size * 
sizeof(*
f));
 
  432         s->tx_fn(
s->fft[ch], 
h, 
f, 
sizeof(
float));
 
  434         memcpy(
f, 
g, 
s->buf_size * 
sizeof(*
f));
 
  435         s->tx_fn(
s->fft[ch], 
g, 
f, 
sizeof(
float));
 
  437         for (
int n = 0; n < 
L; n++) {
 
  440             a = 
c * 
h[n].re - 
S * 
h[n].im;
 
  441             b = 
S * 
h[n].re + 
c * 
h[n].im;
 
  447         memcpy(
f, 
g, 
s->buf_size * 
sizeof(*
f));
 
  448         s->itx_fn(
s->ifft[ch], 
g, 
f, 
sizeof(
float));
 
  450         for (
int k = 0; k < 
M; k++) {
 
  451             psi = k * k / 2.f * phi;
 
  454             a = 
c * 
g[k].re - 
S * 
g[k].im;
 
  455             b = 
S * 
g[k].re + 
c * 
g[k].im;
 
  456             s->fft_data[ch][k].re = 
a;
 
  457             s->fft_data[ch][k].im = 
b;
 
  460         for (n = 0; n < 
s->win_size; n++) {
 
  461             s->fft_in[ch][n].re = p[n] * window_func_lut[n];
 
  462             s->fft_in[ch][n].im = 0;
 
  466         s->tx_fn(
s->fft[ch], 
s->fft_data[ch], 
s->fft_in[ch], 
sizeof(
float));
 
  480     for (
i = 0; txt[
i]; 
i++) {
 
  484             for (char_y = font_height - 1; char_y >= 0; char_y--) {
 
  485                 uint8_t *p = pic->
data[0] + (y + 
i * 10) * pic->
linesize[0] + x;
 
  487                     if (font[txt[
i] * font_height + font_height - 1 - char_y] & 
mask)
 
  488                         p[char_y] = ~p[char_y];
 
  494             for (char_y = 0; char_y < font_height; char_y++) {
 
  496                     if (font[txt[
i] * font_height + char_y] & 
mask)
 
  507                         float *yf, 
float *uf, 
float *vf)
 
  512         *yf = 256.0f / 
s->nb_display_channels;
 
  513         switch (
s->color_mode) {
 
  552         if (
s->nb_display_channels > 1) {
 
  553             *uf *= 0.5f * 
sinf((2 * 
M_PI * ch) / 
s->nb_display_channels + 
M_PI * 
s->rotation);
 
  554             *vf *= 0.5f * 
cosf((2 * 
M_PI * ch) / 
s->nb_display_channels + 
M_PI * 
s->rotation);
 
  564     *uf *= 
s->saturation;
 
  565     *vf *= 
s->saturation;
 
  569                        float yf, 
float uf, 
float vf,
 
  573         const int cm = 
s->color_mode;
 
  593             float lerpfrac = (
a - start) / (end - start);
 
  618     else if (log10(seconds) > 6)
 
  620     else if (log10(seconds) > 3)
 
  628                        const float bmin, 
const float bmax,
 
  629                        const float min, 
const float max)
 
  634 static float get_hz(
const float bin, 
const float bmax,
 
  635                     const float min, 
const float max,
 
  649                            float bmin, 
float bmax,
 
  655 static float bin_pos(
const int bin, 
const int num_bins, 
const float min, 
const float max)
 
  663     const float dmin = 
s->dmin;
 
  664     const float dmax = 
s->dmax;
 
  668         a = (
a - dmin) / (dmax - dmin);
 
  686         a = (
s->drange - 
s->limit + 
log10f(
a) * 20.f) / 
s->drange;
 
  698     const float dmin = 
s->dmin;
 
  699     const float dmax = 
s->dmax;
 
  724         a = 
a * (dmax - dmin) + dmin;
 
  734     int ch, y, x = 0, sz = 
s->orientation == 
VERTICAL ? 
s->w : 
s->h;
 
  736     float spp = 
samples / (float)sz;
 
  739     char chlayout_str[128];
 
  748     drawtext(
s->outpicref, 2, outlink->
h - 10, 
"CREATED BY LIBAVFILTER", 0);
 
  749     drawtext(
s->outpicref, outlink->
w - 2 - strlen(text) * 10, outlink->
h - 10, text, 0);
 
  752         text = 
av_asprintf(
"Zoom: %d Hz - %d Hz", 
s->start, 
s->stop);
 
  755         drawtext(
s->outpicref, outlink->
w - 2 - strlen(text) * 10, 3, text, 0);
 
  759     dst = 
s->outpicref->data[0] + (
s->start_y - 1) * 
s->outpicref->linesize[0] + 
s->start_x - 1;
 
  760     for (x = 0; x < 
s->w + 1; x++)
 
  762     dst = 
s->outpicref->data[0] + (
s->start_y + 
s->h) * 
s->outpicref->linesize[0] + 
s->start_x - 1;
 
  763     for (x = 0; x < 
s->w + 1; x++)
 
  765     for (y = 0; y < 
s->h + 2; y++) {
 
  766         dst = 
s->outpicref->data[0] + (y + 
s->start_y - 1) * 
s->outpicref->linesize[0];
 
  767         dst[
s->start_x - 1] = 200;
 
  768         dst[
s->start_x + 
s->w] = 200;
 
  771         int h = 
s->mode == 
SEPARATE ? 
s->h / 
s->nb_display_channels : 
s->h;
 
  772         int hh = 
s->mode == 
SEPARATE ? -(
s->h % 
s->nb_display_channels) + 1 : 1;
 
  773         for (ch = 0; ch < (
s->mode == 
SEPARATE ? 
s->nb_display_channels : 1); ch++) {
 
  774             for (y = 0; y < 
h; y += 20) {
 
  775                 dst = 
s->outpicref->data[0] + (
s->start_y + 
h * (ch + 1) - y - hh) * 
s->outpicref->linesize[0];
 
  776                 dst[
s->start_x - 2] = 200;
 
  777                 dst[
s->start_x + 
s->w + 1] = 200;
 
  779             for (y = 0; y < 
h; y += 40) {
 
  780                 dst = 
s->outpicref->data[0] + (
s->start_y + 
h * (ch + 1) - y - hh) * 
s->outpicref->linesize[0];
 
  781                 dst[
s->start_x - 3] = 200;
 
  782                 dst[
s->start_x + 
s->w + 2] = 200;
 
  784             dst = 
s->outpicref->data[0] + (
s->start_y - 2) * 
s->outpicref->linesize[0] + 
s->start_x;
 
  785             for (x = 0; x < 
s->w; x+=40)
 
  787             dst = 
s->outpicref->data[0] + (
s->start_y - 3) * 
s->outpicref->linesize[0] + 
s->start_x;
 
  788             for (x = 0; x < 
s->w; x+=80)
 
  790             dst = 
s->outpicref->data[0] + (
s->h + 
s->start_y + 1) * 
s->outpicref->linesize[0] + 
s->start_x;
 
  791             for (x = 0; x < 
s->w; x+=40) {
 
  794             dst = 
s->outpicref->data[0] + (
s->h + 
s->start_y + 2) * 
s->outpicref->linesize[0] + 
s->start_x;
 
  795             for (x = 0; x < 
s->w; x+=80) {
 
  798             for (y = 0; y < 
h; y += 40) {
 
  799                 float range = 
s->stop ? 
s->stop - 
s->start : 
inlink->sample_rate / 2;
 
  800                 float hertz = 
get_hz(y, 
h, 
s->start, 
s->start + range, 
s->fscale);
 
  810                 drawtext(
s->outpicref, 
s->start_x - 8 * strlen(units) - 4, 
h * (ch + 1) + 
s->start_y - y - 4 - hh, units, 0);
 
  815         for (x = 0; x < 
s->w && 
s->single_pic; x+=80) {
 
  816             float seconds = x * spp / 
inlink->sample_rate;
 
  821             drawtext(
s->outpicref, 
s->start_x + x - 4 * strlen(units), 
s->h + 
s->start_y + 6, units, 0);
 
  822             drawtext(
s->outpicref, 
s->start_x + x - 4 * strlen(units), 
s->start_y - 12, units, 0);
 
  826         drawtext(
s->outpicref, outlink->
w / 2 - 4 * 4, outlink->
h - 
s->start_y / 2, 
"TIME", 0);
 
  827         drawtext(
s->outpicref, 
s->start_x / 7, outlink->
h / 2 - 14 * 4, 
"FREQUENCY (Hz)", 1);
 
  829         int w = 
s->mode == 
SEPARATE ? 
s->w / 
s->nb_display_channels : 
s->w;
 
  830         for (y = 0; y < 
s->h; y += 20) {
 
  831             dst = 
s->outpicref->data[0] + (
s->start_y + y) * 
s->outpicref->linesize[0];
 
  832             dst[
s->start_x - 2] = 200;
 
  833             dst[
s->start_x + 
s->w + 1] = 200;
 
  835         for (y = 0; y < 
s->h; y += 40) {
 
  836             dst = 
s->outpicref->data[0] + (
s->start_y + y) * 
s->outpicref->linesize[0];
 
  837             dst[
s->start_x - 3] = 200;
 
  838             dst[
s->start_x + 
s->w + 2] = 200;
 
  840         for (ch = 0; ch < (
s->mode == 
SEPARATE ? 
s->nb_display_channels : 1); ch++) {
 
  841             dst = 
s->outpicref->data[0] + (
s->start_y - 2) * 
s->outpicref->linesize[0] + 
s->start_x + 
w * ch;
 
  842             for (x = 0; x < 
w; x+=40)
 
  844             dst = 
s->outpicref->data[0] + (
s->start_y - 3) * 
s->outpicref->linesize[0] + 
s->start_x + 
w * ch;
 
  845             for (x = 0; x < 
w; x+=80)
 
  847             dst = 
s->outpicref->data[0] + (
s->h + 
s->start_y + 1) * 
s->outpicref->linesize[0] + 
s->start_x + 
w * ch;
 
  848             for (x = 0; x < 
w; x+=40) {
 
  851             dst = 
s->outpicref->data[0] + (
s->h + 
s->start_y + 2) * 
s->outpicref->linesize[0] + 
s->start_x + 
w * ch;
 
  852             for (x = 0; x < 
w; x+=80) {
 
  855             for (x = 0; x < 
w - 79; x += 80) {
 
  856                 float range = 
s->stop ? 
s->stop - 
s->start : 
inlink->sample_rate / 2;
 
  857                 float hertz = 
get_hz(x, 
w, 
s->start, 
s->start + range, 
s->fscale);
 
  867                 drawtext(
s->outpicref, 
s->start_x - 4 * strlen(units) + x + 
w * ch, 
s->start_y - 12, units, 0);
 
  868                 drawtext(
s->outpicref, 
s->start_x - 4 * strlen(units) + x + 
w * ch, 
s->h + 
s->start_y + 6, units, 0);
 
  872         for (y = 0; y < 
s->h && 
s->single_pic; y+=40) {
 
  873             float seconds = y * spp / 
inlink->sample_rate;
 
  878             drawtext(
s->outpicref, 
s->start_x - 8 * strlen(units) - 4, 
s->start_y + y - 4, units, 0);
 
  881         drawtext(
s->outpicref, 
s->start_x / 7, outlink->
h / 2 - 4 * 4, 
"TIME", 1);
 
  882         drawtext(
s->outpicref, outlink->
w / 2 - 14 * 4, outlink->
h - 
s->start_y / 2, 
"FREQUENCY (Hz)", 0);
 
  885     for (ch = 0; ch < (multi ? 
s->nb_display_channels : 1); ch++) {
 
  886         int h = multi ? 
s->h / 
s->nb_display_channels : 
s->h;
 
  888         for (y = 0; y < 
h; y++) {
 
  889             float out[3] = { 0., 127.5, 127.5};
 
  892             for (chn = 0; chn < (
s->mode == 
SEPARATE ? 1 : 
s->nb_display_channels); chn++) {
 
  894                 int channel = (multi) ? 
s->nb_display_channels - ch - 1 : chn;
 
  903             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);
 
  904             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);
 
  905             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);
 
  908         for (y = 0; ch == 0 && y < 
h + 5; y += 25) {
 
  909             static const char *log_fmt = 
"%.0f";
 
  910             static const char *lin_fmt = 
"%.3f";
 
  911             const float a = 
av_clipf(1.
f - y / (
float)(
h - 1), 0.
f, 1.
f);
 
  918             drawtext(
s->outpicref, 
s->w + 
s->start_x + 35, 
s->start_y + y - 3, text, 0);
 
  924         drawtext(
s->outpicref, 
s->w + 
s->start_x + 22, 
s->start_y + 
s->h + 20, 
"dBFS", 0);
 
  932     float *magnitudes = 
s->magnitudes[ch];
 
  933     float *phases = 
s->phases[ch];
 
  956     const int h = 
s->orientation == 
VERTICAL ? 
s->channel_height : 
s->channel_width;
 
  957     const int ch = jobnr;
 
  965     for (y = 0; y < 
h; y++) {
 
  966         int row = (
s->mode == 
COMBINED) ? y : ch * 
h + y;
 
  967         float *
out = &
s->color_buffer[ch][3 * row];
 
  980     const int h = 
s->orientation == 
VERTICAL ? 
s->channel_height : 
s->channel_width;
 
  981     const int ch = jobnr;
 
  988     for (
int yy = 0; yy < 
h; yy++) {
 
  989         float range = 
s->stop ? 
s->stop - 
s->start : 
inlink->sample_rate / 2;
 
  997             int row = (
s->mode == 
COMBINED) ? yy : ch * 
h + yy;
 
  998             float *
out = &
s->color_buffer[ch][3 * row];
 
 1012     int i, fft_size, 
h, 
w, 
ret;
 
 1018     switch (
s->fscale) {
 
 1025     if ((
s->stop || 
s->start) && 
s->stop <= 
s->start) {
 
 1030     if (!strcmp(
ctx->filter->name, 
"showspectrumpic"))
 
 1038         s->start_x = (log10(
inlink->sample_rate) + 1) * 25;
 
 1040         outlink->
w += 
s->start_x * 2;
 
 1041         outlink->
h += 
s->start_y * 2;
 
 1046     s->channel_height = 
h;
 
 1047     s->channel_width  = 
w;
 
 1057     s->win_size = fft_size;
 
 1075     if (fft_size != 
s->fft_size) {
 
 1078         s->fft_size = fft_size;
 
 1083         for (
i = 0; 
i < 
s->nb_display_channels; 
i++) {
 
 1094         s->nb_display_channels = 
inlink->channels;
 
 1095         for (
i = 0; 
i < 
s->nb_display_channels; 
i++) {
 
 1103                            "The window size might be too high.\n");
 
 1109                        "The window size might be too high.\n");
 
 1114         s->magnitudes = 
av_calloc(
s->nb_display_channels, 
sizeof(*
s->magnitudes));
 
 1117         for (
i = 0; 
i < 
s->nb_display_channels; 
i++) {
 
 1119             if (!
s->magnitudes[
i])
 
 1123         s->phases = 
av_calloc(
s->nb_display_channels, 
sizeof(*
s->phases));
 
 1126         for (
i = 0; 
i < 
s->nb_display_channels; 
i++) {
 
 1133         s->color_buffer = 
av_calloc(
s->nb_display_channels, 
sizeof(*
s->color_buffer));
 
 1134         if (!
s->color_buffer)
 
 1136         for (
i = 0; 
i < 
s->nb_display_channels; 
i++) {
 
 1138             if (!
s->color_buffer[
i])
 
 1142         s->fft_in = 
av_calloc(
s->nb_display_channels, 
sizeof(*
s->fft_in));
 
 1145         s->fft_data = 
av_calloc(
s->nb_display_channels, 
sizeof(*
s->fft_data));
 
 1148         s->fft_scratch = 
av_calloc(
s->nb_display_channels, 
sizeof(*
s->fft_scratch));
 
 1149         if (!
s->fft_scratch)
 
 1151         for (
i = 0; 
i < 
s->nb_display_channels; 
i++) {
 
 1156             s->fft_data[
i] = 
av_calloc(
s->buf_size, 
sizeof(**
s->fft_data));
 
 1157             if (!
s->fft_data[
i])
 
 1160             s->fft_scratch[
i] = 
av_calloc(
s->buf_size, 
sizeof(**
s->fft_scratch));
 
 1161             if (!
s->fft_scratch[
i])
 
 1166         s->window_func_lut =
 
 1168                          sizeof(*
s->window_func_lut));
 
 1169         if (!
s->window_func_lut)
 
 1172         if (
s->overlap == 1)
 
 1173             s->overlap = overlap;
 
 1174         s->hop_size = (1.f - 
s->overlap) * 
s->win_size;
 
 1175         if (
s->hop_size < 1) {
 
 1180         for (
s->win_scale = 0, 
i = 0; i < s->win_size; 
i++) {
 
 1181             s->win_scale += 
s->window_func_lut[
i] * 
s->window_func_lut[
i];
 
 1183         s->win_scale = 1.f / sqrtf(
s->win_scale);
 
 1187         s->outpicref = outpicref =
 
 1192         for (
i = 0; 
i < outlink->
h; 
i++) {
 
 1193             memset(outpicref->
data[0] + 
i * outpicref->
linesize[0],   0, outlink->
w);
 
 1194             memset(outpicref->
data[1] + 
i * outpicref->
linesize[1], 128, outlink->
w);
 
 1195             memset(outpicref->
data[2] + 
i * outpicref->
linesize[2], 128, outlink->
w);
 
 1199         if (!
s->single_pic && 
s->legend)
 
 1203     if ((
s->orientation == 
VERTICAL   && 
s->xpos >= 
s->w) ||
 
 1219     if (!
s->single_pic && strcmp(
s->rate_str, 
"auto")) {
 
 1224         s->frame_rate = 
s->auto_frame_rate;
 
 1232                          sizeof(*
s->combine_buffer));
 
 1236                          sizeof(*
s->combine_buffer));
 
 1240            s->w, 
s->h, 
s->win_size);
 
 1249 #define RE(y, ch) s->fft_data[ch][y].re 
 1250 #define IM(y, ch) s->fft_data[ch][y].im 
 1251 #define MAGNITUDE(y, ch) hypotf(RE(y, ch), IM(y, ch)) 
 1252 #define PHASE(y, ch) atan2f(IM(y, ch), RE(y, ch)) 
 1257     const double w = 
s->win_scale * (
s->scale == 
LOG ? 
s->win_scale : 1);
 
 1259     const float f = 
s->gain * 
w;
 
 1260     const int ch = jobnr;
 
 1261     float *magnitudes = 
s->magnitudes[ch];
 
 1263     for (y = 0; y < 
h; y++)
 
 1272     const int h = 
s->orientation == 
VERTICAL ? 
s->h : 
s->w;
 
 1273     const int ch = jobnr;
 
 1274     float *phases = 
s->phases[ch];
 
 1277     for (y = 0; y < 
h; y++)
 
 1278         phases[y] = (
PHASE(y, ch) / 
M_PI + 1) / 2;
 
 1285     const float rng = 2.f * 
M_PI;
 
 1287     float max = -FLT_MAX;
 
 1288     float min = FLT_MAX;
 
 1290     for (
int i = 0; 
i < 
N; 
i++) {
 
 1291         const float d = x[
FFMIN(
i + 1, 
N)] - x[
i];
 
 1292         const float p = 
ceilf(
fabsf(
d) / rng) * rng * (((d < tol) > 0.f) - ((
d > -tol) > 0.f));
 
 1307     const int h = 
s->orientation == 
VERTICAL ? 
s->h : 
s->w;
 
 1308     const int ch = jobnr;
 
 1309     float *phases = 
s->phases[ch];
 
 1313     for (y = 0; y < 
h; y++)
 
 1314         phases[y] = 
PHASE(y, ch);
 
 1317     for (y = 0; y < 
h; y++)
 
 1325     const double w = 
s->win_scale * (
s->scale == 
LOG ? 
s->win_scale : 1);
 
 1326     int ch, y, 
h = 
s->orientation == 
VERTICAL ? 
s->h : 
s->w;
 
 1327     const float f = 
s->gain * 
w;
 
 1329     for (ch = 0; ch < 
s->nb_display_channels; ch++) {
 
 1330         float *magnitudes = 
s->magnitudes[ch];
 
 1332         for (y = 0; y < 
h; y++)
 
 1339     int ch, y, 
h = 
s->orientation == 
VERTICAL ? 
s->h : 
s->w;
 
 1341     for (ch = 0; ch < 
s->nb_display_channels; ch++) {
 
 1342         float *magnitudes = 
s->magnitudes[ch];
 
 1344         for (y = 0; y < 
h; y++)
 
 1345             magnitudes[y] *= 
scale;
 
 1353     for (y = 0; y < 
size; y++) {
 
 1354         s->combine_buffer[3 * y    ] = 0;
 
 1355         s->combine_buffer[3 * y + 1] = 127.5;
 
 1356         s->combine_buffer[3 * y + 2] = 127.5;
 
 1366     int ret, plane, x, y, z = 
s->orientation == 
VERTICAL ? 
s->h : 
s->w;
 
 1374     for (y = 0; y < z * 3; y++) {
 
 1375         for (x = 0; x < 
s->nb_display_channels; x++) {
 
 1376             s->combine_buffer[y] += 
s->color_buffer[x][y];
 
 1384             for (plane = 0; plane < 3; plane++) {
 
 1385                 for (y = 0; y < 
s->h; y++) {
 
 1386                     uint8_t *p = outpicref->
data[plane] + 
s->start_x +
 
 1387                                  (y + 
s->start_y) * outpicref->
linesize[plane];
 
 1388                     memmove(p, p + 1, 
s->w - 1);
 
 1392         } 
else if (
s->sliding == 
RSCROLL) {
 
 1393             for (plane = 0; plane < 3; plane++) {
 
 1394                 for (y = 0; y < 
s->h; y++) {
 
 1395                     uint8_t *p = outpicref->
data[plane] + 
s->start_x +
 
 1396                                  (y + 
s->start_y) * outpicref->
linesize[plane];
 
 1397                     memmove(p + 1, p, 
s->w - 1);
 
 1402         for (plane = 0; plane < 3; plane++) {
 
 1403             uint8_t *p = outpicref->
data[plane] + 
s->start_x +
 
 1404                          (outlink->
h - 1 - 
s->start_y) * outpicref->
linesize[plane] +
 
 1406             for (y = 0; y < 
s->h; y++) {
 
 1413             for (plane = 0; plane < 3; plane++) {
 
 1414                 for (y = 1; y < 
s->h; y++) {
 
 1415                     memmove(outpicref->
data[plane] + (y-1 + 
s->start_y) * outpicref->
linesize[plane] + 
s->start_x,
 
 1416                             outpicref->
data[plane] + (y   + 
s->start_y) * outpicref->
linesize[plane] + 
s->start_x,
 
 1421         } 
else if (
s->sliding == 
RSCROLL) {
 
 1422             for (plane = 0; plane < 3; plane++) {
 
 1423                 for (y = 
s->h - 1; y >= 1; y--) {
 
 1424                     memmove(outpicref->
data[plane] + (y   + 
s->start_y) * outpicref->
linesize[plane] + 
s->start_x,
 
 1425                             outpicref->
data[plane] + (y-1 + 
s->start_y) * outpicref->
linesize[plane] + 
s->start_x,
 
 1431         for (plane = 0; plane < 3; plane++) {
 
 1432             uint8_t *p = outpicref->
data[plane] + 
s->start_x +
 
 1433                          (
s->xpos + 
s->start_y) * outpicref->
linesize[plane];
 
 1434             for (x = 0; x < 
s->w; x++) {
 
 1446         if (
s->orientation == 
VERTICAL && 
s->xpos < 0)
 
 1452         if (
s->orientation == 
VERTICAL && 
s->xpos >= 
s->w)
 
 1458     if (!
s->single_pic && (
s->sliding != 
FULLFRAME || 
s->xpos == 0)) {
 
 1459         if (
s->old_pts < outpicref->
pts) {
 
 1468                     for (y = 0; y < 10; y++) {
 
 1469                         memset(
s->outpicref->data[0] + outlink->
w / 2 - 4 * 
s->old_len +
 
 1470                                (outlink->
h - 
s->start_y / 2 - 20 + y) * 
s->outpicref->linesize[0], 0, 10 * 
s->old_len);
 
 1473                              outlink->
w / 2 - 4 * strlen(units),
 
 1474                              outlink->
h - 
s->start_y / 2 - 20,
 
 1477                     for (y = 0; y < 10 * 
s->old_len; y++) {
 
 1478                         memset(
s->outpicref->data[0] + 
s->start_x / 7 + 20 +
 
 1479                                (outlink->
h / 2 - 4 * 
s->old_len + y) * 
s->outpicref->linesize[0], 0, 10);
 
 1482                              s->start_x / 7 + 20,
 
 1483                              outlink->
h / 2 - 4 * strlen(units),
 
 1486                 s->old_len = strlen(units);
 
 1489             s->old_pts = outpicref->
pts;
 
 1503 #if CONFIG_SHOWSPECTRUM_FILTER 
 1535         fin->
pts = 
s->pts + 
s->consumed;
 
 1536         s->consumed += 
s->hop_size;
 
 1567         s->xpos > 0 && 
s->outpicref) {
 
 1571             for (
int i = 0; 
i < outlink->
h; 
i++) {
 
 1572                 memset(
s->outpicref->data[0] + 
i * 
s->outpicref->linesize[0] + 
s->xpos,   0, outlink->
w - 
s->xpos);
 
 1573                 memset(
s->outpicref->data[1] + 
i * 
s->outpicref->linesize[1] + 
s->xpos, 128, outlink->
w - 
s->xpos);
 
 1574                 memset(
s->outpicref->data[2] + 
i * 
s->outpicref->linesize[2] + 
s->xpos, 128, outlink->
w - 
s->xpos);
 
 1577             for (
int i = 
s->xpos; i < outlink->
h; 
i++) {
 
 1578                 memset(
s->outpicref->data[0] + 
i * 
s->outpicref->linesize[0],   0, outlink->
w);
 
 1579                 memset(
s->outpicref->data[1] + 
i * 
s->outpicref->linesize[1], 128, outlink->
w);
 
 1580                 memset(
s->outpicref->data[2] + 
i * 
s->outpicref->linesize[2], 128, outlink->
w);
 
 1584         pts = 
s->outpicref->pts;
 
 1586         s->outpicref = 
NULL;
 
 1609 static const AVFilterPad showspectrum_inputs[] = {
 
 1616 static const AVFilterPad showspectrum_outputs[] = {
 
 1625     .
name          = 
"showspectrum",
 
 1633     .priv_class    = &showspectrum_class,
 
 1636 #endif // CONFIG_SHOWSPECTRUM_FILTER 
 1638 #if CONFIG_SHOWSPECTRUMPIC_FILTER 
 1640 static const AVOption showspectrumpic_options[] = {
 
 1689 static int showspectrumpic_request_frame(
AVFilterLink *outlink)
 
 1700         int x = 0, sz = 
s->orientation == 
VERTICAL ? 
s->w : 
s->h;
 
 1705         spf = 
FFMAX(1, spf);
 
 1707         spb = (
samples / (spf * sz)) * spf;
 
 1722             if (ret < s->win_size) {
 
 1723                 for (ch = 0; ch < 
s->nb_display_channels; ch++) {
 
 1725                            (
s->win_size - 
ret) * 
sizeof(
float));
 
 1733             if (consumed >= spb) {
 
 1740                 for (ch = 0; ch < 
s->nb_display_channels; ch++)
 
 1741                     memset(
s->magnitudes[ch], 0, 
h * 
sizeof(
float));
 
 1746         s->outpicref->pts = 0;
 
 1752         s->outpicref = 
NULL;
 
 1769 static const AVFilterPad showspectrumpic_inputs[] = {
 
 1773         .filter_frame = showspectrumpic_filter_frame,
 
 1777 static const AVFilterPad showspectrumpic_outputs[] = {
 
 1782         .request_frame = showspectrumpic_request_frame,
 
 1787     .
name          = 
"showspectrumpic",
 
 1788     .description   = 
NULL_IF_CONFIG_SMALL(
"Convert input audio to a spectrum video output single picture."),
 
 1794     .priv_class    = &showspectrumpic_class,
 
 1798 #endif // CONFIG_SHOWSPECTRUMPIC_FILTER