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