From 49719d3cb58c03bc0a976f47d2c82e8ca48d1b3d Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sat, 11 Nov 2023 00:44:36 +0100 Subject: [PATCH] avfilter/avf_showcwt: add fm frequency scaler --- doc/filters.texi | 1 + libavfilter/avf_showcwt.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/filters.texi b/doc/filters.texi index 12113d7802..13c18a2574 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -30842,6 +30842,7 @@ Set the frequency scale used. Allowed values are: @item sqrt @item cbrt @item qdrt +@item fm @end table Default value is @code{linear}. diff --git a/libavfilter/avf_showcwt.c b/libavfilter/avf_showcwt.c index d5bc920a4b..e7164ebb25 100644 --- a/libavfilter/avf_showcwt.c +++ b/libavfilter/avf_showcwt.c @@ -45,6 +45,7 @@ enum FrequencyScale { FSCALE_SQRT, FSCALE_CBRT, FSCALE_QDRT, + FSCALE_FM, NB_FSCALE }; @@ -144,6 +145,7 @@ static const AVOption showcwt_options[] = { { "sqrt", "sqrt", 0, AV_OPT_TYPE_CONST,{.i64=FSCALE_SQRT}, 0, 0, FLAGS, "scale" }, { "cbrt", "cbrt", 0, AV_OPT_TYPE_CONST,{.i64=FSCALE_CBRT}, 0, 0, FLAGS, "scale" }, { "qdrt", "qdrt", 0, AV_OPT_TYPE_CONST,{.i64=FSCALE_QDRT}, 0, 0, FLAGS, "scale" }, + { "fm", "fm", 0, AV_OPT_TYPE_CONST,{.i64=FSCALE_FM}, 0, 0, FLAGS, "scale" }, { "iscale", "set intensity scale", OFFSET(intensity_scale),AV_OPT_TYPE_INT, {.i64=0}, 0, NB_ISCALE-1, FLAGS, "iscale" }, { "linear", "linear", 0, AV_OPT_TYPE_CONST,{.i64=ISCALE_LINEAR}, 0, 0, FLAGS, "iscale" }, { "log", "logarithmic", 0, AV_OPT_TYPE_CONST,{.i64=ISCALE_LOG}, 0, 0, FLAGS, "iscale" }, @@ -292,6 +294,10 @@ static float frequency_band(float *frequency_band, frequency = frequency * frequency * frequency * frequency; frequency_derivative *= 4.f * powf(frequency, 3.f / 4.f); break; + case FSCALE_FM: + frequency = 2.f * powf(frequency, 3.f / 2.f) / 3.f; + frequency_derivative *= sqrtf(frequency); + break; } frequency_band[y*2 ] = frequency; @@ -788,7 +794,8 @@ static int config_output(AVFilterLink *outlink) AVFilterContext *ctx = outlink->src; AVFilterLink *inlink = ctx->inputs[0]; ShowCWTContext *s = ctx->priv; - float maximum_frequency = fminf(s->maximum_frequency, inlink->sample_rate * 0.5f); + const float limit_frequency = inlink->sample_rate * 0.5f; + float maximum_frequency = fminf(s->maximum_frequency, limit_frequency); float minimum_frequency = s->minimum_frequency; float scale = 1.f, factor; int ret; @@ -847,6 +854,10 @@ static int config_output(AVFilterLink *outlink) minimum_frequency = powf(minimum_frequency, 0.25f); maximum_frequency = powf(maximum_frequency, 0.25f); break; + case FSCALE_FM: + minimum_frequency = powf(9.f * (minimum_frequency * minimum_frequency) / 4.f, 1.f / 3.f); + maximum_frequency = powf(9.f * (maximum_frequency * maximum_frequency) / 4.f, 1.f / 3.f); + break; } s->frequency_band = av_calloc(s->frequency_band_count,