History

avfilter/avf_showfreqs: implement phase display

Paul B Mahol committed 5 years ago

Commit 38648961 parent 659e6e92 files · +34 −5Browse files

Unified · Split

2 files
  1. doc/filters.texi +9 −0
  2. libavfilter/avf_showfreqs.c +25 −5
doc/filters.texi+9−0
@@ -25187,6 +25187,15 @@ Default is @code{combined}. · 25186 unmodified lines
25187@item minamp25187@item minamp
25188Set minimum amplitude used in @code{log} amplitude scaler.25188Set minimum amplitude used in @code{log} amplitude scaler.
25189 25189
25190@item data
25191Set data display mode.
25192
25193It accepts the following values:
25194@table @samp
25195@item magnitude
25196@item phase
25197@end table
25198Default is @code{magnitude}.
25190@end table25199@end table
25191 25200
25192@section showspatial25201@section showspatial
libavfilter/avf_showfreqs.c+25−5
@@ -36,6 +36,7 @@ · 35 unmodified lines
36#include "internal.h"36#include "internal.h"
37#include "window_func.h"37#include "window_func.h"
38 38
39enum DataMode { MAGNITUDE, PHASE, NB_DATA };
39enum DisplayMode { LINE, BAR, DOT, NB_MODES };40enum DisplayMode { LINE, BAR, DOT, NB_MODES };
40enum ChannelMode { COMBINED, SEPARATE, NB_CMODES };41enum ChannelMode { COMBINED, SEPARATE, NB_CMODES };
41enum FrequencyScale { FS_LINEAR, FS_LOG, FS_RLOG, NB_FSCALES };42enum FrequencyScale { FS_LINEAR, FS_LOG, FS_RLOG, NB_FSCALES };
@@ -45,6 +46,7 @@ typedef struct ShowFreqsContext { · 3 unmodified lines
45 const AVClass *class;46 const AVClass *class;
46 int w, h;47 int w, h;
47 int mode;48 int mode;
49 int data_mode;
48 int cmode;50 int cmode;
49 int fft_size;51 int fft_size;
50 int fft_bits;52 int fft_bits;
@@ -115,6 +117,9 @@ static const AVOption showfreqs_options[] = { · 64 unmodified lines
115 { "combined", "show all channels in same window", 0, AV_OPT_TYPE_CONST, {.i64=COMBINED}, 0, 0, FLAGS, "cmode" },117 { "combined", "show all channels in same window", 0, AV_OPT_TYPE_CONST, {.i64=COMBINED}, 0, 0, FLAGS, "cmode" },
116 { "separate", "show each channel in own window", 0, AV_OPT_TYPE_CONST, {.i64=SEPARATE}, 0, 0, FLAGS, "cmode" },118 { "separate", "show each channel in own window", 0, AV_OPT_TYPE_CONST, {.i64=SEPARATE}, 0, 0, FLAGS, "cmode" },
117 { "minamp", "set minimum amplitude", OFFSET(minamp), AV_OPT_TYPE_FLOAT, {.dbl=1e-6}, FLT_MIN, 1e-6, FLAGS },119 { "minamp", "set minimum amplitude", OFFSET(minamp), AV_OPT_TYPE_FLOAT, {.dbl=1e-6}, FLT_MIN, 1e-6, FLAGS },
120 { "data", "set data mode", OFFSET(data_mode), AV_OPT_TYPE_INT, {.i64=MAGNITUDE}, 0, NB_DATA-1, FLAGS, "data" },
121 { "magnitude", "show magnitude", 0, AV_OPT_TYPE_CONST, {.i64=MAGNITUDE}, 0, 0, FLAGS, "data" },
122 { "phase", "show phase", 0, AV_OPT_TYPE_CONST, {.i64=PHASE}, 0, 0, FLAGS, "data" },
118 { NULL }123 { NULL }
119};124};
120 125
@@ -397,6 +402,7 @@ static int plot_freqs(AVFilterLink *inlink, AVFrame *in) · 276 unmodified lines
397#define RE(x, ch) s->fft_data[ch][x].re402#define RE(x, ch) s->fft_data[ch][x].re
398#define IM(x, ch) s->fft_data[ch][x].im403#define IM(x, ch) s->fft_data[ch][x].im
399#define M(a, b) (sqrt((a) * (a) + (b) * (b)))404#define M(a, b) (sqrt((a) * (a) + (b) * (b)))
405#define P(a, b) (atan2((b), (a)))
400 406
401 colors = av_strdup(s->colors);407 colors = av_strdup(s->colors);
402 if (!colors) {408 if (!colors) {
@@ -413,13 +419,27 @@ static int plot_freqs(AVFilterLink *inlink, AVFrame *in) · 10 unmodified lines
413 if (color)419 if (color)
414 av_parse_color(fg, color, -1, ctx);420 av_parse_color(fg, color, -1, ctx);
415 421
416 a = av_clipd(M(RE(0, ch), 0) / s->scale, 0, 1);422 switch (s->data_mode) {
417 plot_freq(s, ch, a, 0, fg, &prev_y, out, outlink);423 case MAGNITUDE:
424 a = av_clipd(M(RE(0, ch), 0) / s->scale, 0, 1);
425 plot_freq(s, ch, a, 0, fg, &prev_y, out, outlink);
418 426
419 for (f = 1; f < s->nb_freq; f++) {427 for (f = 1; f < s->nb_freq; f++) {
420 a = av_clipd(M(RE(f, ch), IM(f, ch)) / s->scale, 0, 1);428 a = av_clipd(M(RE(f, ch), IM(f, ch)) / s->scale, 0, 1);
421 429
422 plot_freq(s, ch, a, f, fg, &prev_y, out, outlink);430 plot_freq(s, ch, a, f, fg, &prev_y, out, outlink);
431 }
432 break;
433 case PHASE:
434 a = av_clipd((M_PI + P(RE(0, ch), 0)) / (2. * M_PI), 0, 1);
435 plot_freq(s, ch, a, 0, fg, &prev_y, out, outlink);
436
437 for (f = 1; f < s->nb_freq; f++) {
438 a = av_clipd((M_PI + P(RE(f, ch), IM(f, ch))) / (2. * M_PI), 0, 1);
439
440 plot_freq(s, ch, a, f, fg, &prev_y, out, outlink);
441 }
442 break;
423 }443 }
424 }444 }
425 445

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t