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
2518725187 @item minamp
2518825188 Set minimum amplitude used in @code{log} amplitude scaler.
2518925189
25190+@item data
25191+Set data display mode.
25192+
25193+It accepts the following values:
25194+@table @samp
25195+@item magnitude
25196+@item phase
25197+@end table
25198+Default is @code{magnitude}.
2519025199 @end table
2519125200
2519225201 @section showspatial
libavfilter/avf_showfreqs.c+25−5
@@ -36,6 +36,7 @@ · 35 unmodified lines
3636 #include "internal.h"
3737 #include "window_func.h"
3838
39+enum DataMode { MAGNITUDE, PHASE, NB_DATA };
3940 enum DisplayMode { LINE, BAR, DOT, NB_MODES };
4041 enum ChannelMode { COMBINED, SEPARATE, NB_CMODES };
4142 enum FrequencyScale { FS_LINEAR, FS_LOG, FS_RLOG, NB_FSCALES };
@@ -45,6 +46,7 @@ typedef struct ShowFreqsContext { · 3 unmodified lines
4546 const AVClass *class;
4647 int w, h;
4748 int mode;
49+ int data_mode;
4850 int cmode;
4951 int fft_size;
5052 int fft_bits;
@@ -115,6 +117,9 @@ static const AVOption showfreqs_options[] = { · 64 unmodified lines
115117 { "combined", "show all channels in same window", 0, AV_OPT_TYPE_CONST, {.i64=COMBINED}, 0, 0, FLAGS, "cmode" },
116118 { "separate", "show each channel in own window", 0, AV_OPT_TYPE_CONST, {.i64=SEPARATE}, 0, 0, FLAGS, "cmode" },
117119 { "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" },
118123 { NULL }
119124 };
120125
@@ -397,6 +402,7 @@ static int plot_freqs(AVFilterLink *inlink, AVFrame *in) · 276 unmodified lines
397402 #define RE(x, ch) s->fft_data[ch][x].re
398403 #define IM(x, ch) s->fft_data[ch][x].im
399404 #define M(a, b) (sqrt((a) * (a) + (b) * (b)))
405+#define P(a, b) (atan2((b), (a)))
400406
401407 colors = av_strdup(s->colors);
402408 if (!colors) {
@@ -413,13 +419,27 @@ static int plot_freqs(AVFilterLink *inlink, AVFrame *in) · 10 unmodified lines
413419 if (color)
414420 av_parse_color(fg, color, -1, ctx);
415421
416− a = av_clipd(M(RE(0, ch), 0) / s->scale, 0, 1);
417− plot_freq(s, ch, a, 0, fg, &prev_y, out, outlink);
422+ switch (s->data_mode) {
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);
418426
419− for (f = 1; f < s->nb_freq; f++) {
420− a = av_clipd(M(RE(f, ch), IM(f, ch)) / s->scale, 0, 1);
427+ for (f = 1; f < s->nb_freq; f++) {
428+ a = av_clipd(M(RE(f, ch), IM(f, ch)) / s->scale, 0, 1);
421429
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;
423443 }
424444 }
425445

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