Showing the changes to libavfilter (1 of 2 files). Show all
Unified · Split
| @@ -101,6 +101,8 @@ typedef struct ShowSpectrumContext { · 100 unmodified lines | |||
| 101 | int single_pic; | 101 | int single_pic; |
| 102 | int legend; | 102 | int legend; |
| 103 | int start_x, start_y; | 103 | int start_x, start_y; |
| 104 | float drange; | ||
| 105 | float dmin, dscale; | ||
| 104 | int (*plot_channel)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); | 106 | int (*plot_channel)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); |
| 105 | } ShowSpectrumContext; | 107 | } ShowSpectrumContext; |
| 106 | 108 | ||
| @@ -181,6 +183,7 @@ static const AVOption showspectrum_options[] = { · 74 unmodified lines | |||
| 181 | { "stop", "stop frequency", OFFSET(stop), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT32_MAX, FLAGS }, | 183 | { "stop", "stop frequency", OFFSET(stop), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT32_MAX, FLAGS }, |
| 182 | { "fps", "set video rate", OFFSET(rate_str), AV_OPT_TYPE_STRING, {.str = "auto"}, 0, 0, FLAGS }, | 184 | { "fps", "set video rate", OFFSET(rate_str), AV_OPT_TYPE_STRING, {.str = "auto"}, 0, 0, FLAGS }, |
| 183 | { "legend", "draw legend", OFFSET(legend), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, | 185 | { "legend", "draw legend", OFFSET(legend), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, |
| 186 | { "drange", "set dynamic range in dBFS", OFFSET(drange), AV_OPT_TYPE_FLOAT, {.dbl = 120}, 10, 200, FLAGS }, | ||
| 184 | { NULL } | 187 | { NULL } |
| 185 | }; | 188 | }; |
| 186 | 189 | ||
| @@ -871,10 +874,10 @@ static int draw_legend(AVFilterContext *ctx, int samples) · 684 unmodified lines | |||
| 871 | } | 874 | } |
| 872 | 875 | ||
| 873 | for (y = 0; ch == 0 && y < h; y += h / 10) { | 876 | for (y = 0; ch == 0 && y < h; y += h / 10) { |
| 874 | float value = 120.f * log10f(1.f - y / (float)h); | 877 | float value = s->drange * log10f(1.f - y / (float)h); |
| 875 | char *text; | 878 | char *text; |
| 876 | 879 | ||
| 877 | if (value < -120) | 880 | if (value < -s->drange) |
| 878 | break; | 881 | break; |
| 879 | text = av_asprintf("%.0f dB", value); | 882 | text = av_asprintf("%.0f dB", value); |
| 880 | if (!text) | 883 | if (!text) |
| @@ -925,7 +928,7 @@ static float get_value(AVFilterContext *ctx, int ch, int y) · 44 unmodified lines | |||
| 925 | a = av_clipf(powf(a, 0.20), 0, 1); | 928 | a = av_clipf(powf(a, 0.20), 0, 1); |
| 926 | break; | 929 | break; |
| 927 | case LOG: | 930 | case LOG: |
| 928 | a = 1.f + log10f(av_clipf(a, 1e-6, 1)) / 6.f; // zero = -120dBFS | 931 | a = 1.f + log10f(av_clipf(a, s->dmin, 1.f)) * s->dscale; |
| 929 | break; | 932 | break; |
| 930 | default: | 933 | default: |
| 931 | av_assert0(0); | 934 | av_assert0(0); |
| @@ -999,6 +1002,9 @@ static int config_output(AVFilterLink *outlink) · 67 unmodified lines | |||
| 999 | int i, fft_size, h, w, ret; | 1002 | int i, fft_size, h, w, ret; |
| 1000 | float overlap; | 1003 | float overlap; |
| 1001 | 1004 | ||
| 1005 | s->dmin = expf(-s->drange * M_LN10 / 20.f); | ||
| 1006 | s->dscale = -1.f / log10f(s->dmin); | ||
| 1007 | |||
| 1002 | switch (s->fscale) { | 1008 | switch (s->fscale) { |
| 1003 | case F_LINEAR: s->plot_channel = plot_channel_lin; break; | 1009 | case F_LINEAR: s->plot_channel = plot_channel_lin; break; |
| 1004 | case F_LOG: s->plot_channel = plot_channel_log; break; | 1010 | case F_LOG: s->plot_channel = plot_channel_log; break; |
| @@ -1641,6 +1647,7 @@ static const AVOption showspectrumpic_options[] = { · 636 unmodified lines | |||
| 1641 | { "rotation", "color rotation", OFFSET(rotation), AV_OPT_TYPE_FLOAT, {.dbl = 0}, -1, 1, FLAGS }, | 1647 | { "rotation", "color rotation", OFFSET(rotation), AV_OPT_TYPE_FLOAT, {.dbl = 0}, -1, 1, FLAGS }, |
| 1642 | { "start", "start frequency", OFFSET(start), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT32_MAX, FLAGS }, | 1648 | { "start", "start frequency", OFFSET(start), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT32_MAX, FLAGS }, |
| 1643 | { "stop", "stop frequency", OFFSET(stop), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT32_MAX, FLAGS }, | 1649 | { "stop", "stop frequency", OFFSET(stop), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT32_MAX, FLAGS }, |
| 1650 | { "drange", "set dynamic range in dBFS", OFFSET(drange), AV_OPT_TYPE_FLOAT, {.dbl = 120}, 10, 200, FLAGS }, | ||
| 1644 | { NULL } | 1651 | { NULL } |
| 1645 | }; | 1652 | }; |
| 1646 | 1653 | ||