History

avfilter/avf_showcwt: improve range detection for morlet scales

Paul B Mahol committed 3 years ago

Commit 8bbaecb1 parent 48cd5561 file · +13 −8Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/avf_showcwt.c+13−8
@@ -152,7 +152,7 @@ static const AVOption showcwt_options[] = { · 151 unmodified lines
152 { "min", "set minimum frequency", OFFSET(minimum_frequency), AV_OPT_TYPE_FLOAT, {.dbl = 20.}, 1, 192000, FLAGS },152 { "min", "set minimum frequency", OFFSET(minimum_frequency), AV_OPT_TYPE_FLOAT, {.dbl = 20.}, 1, 192000, FLAGS },
153 { "max", "set maximum frequency", OFFSET(maximum_frequency), AV_OPT_TYPE_FLOAT, {.dbl = 20000.}, 1, 192000, FLAGS },153 { "max", "set maximum frequency", OFFSET(maximum_frequency), AV_OPT_TYPE_FLOAT, {.dbl = 20000.}, 1, 192000, FLAGS },
154 { "logb", "set logarithmic basis", OFFSET(logarithmic_basis), AV_OPT_TYPE_FLOAT, {.dbl = 0.0001}, 0, 1, FLAGS },154 { "logb", "set logarithmic basis", OFFSET(logarithmic_basis), AV_OPT_TYPE_FLOAT, {.dbl = 0.0001}, 0, 1, FLAGS },
155 { "deviation", "set frequency deviation", OFFSET(deviation), AV_OPT_TYPE_FLOAT, {.dbl = 1.}, 0, 10, FLAGS },155 { "deviation", "set frequency deviation", OFFSET(deviation), AV_OPT_TYPE_FLOAT, {.dbl = 1.}, 0, 100, FLAGS },
156 { "pps", "set pixels per second", OFFSET(pps), AV_OPT_TYPE_INT, {.i64 = 64}, 1, 1024, FLAGS },156 { "pps", "set pixels per second", OFFSET(pps), AV_OPT_TYPE_INT, {.i64 = 64}, 1, 1024, FLAGS },
157 { "mode", "set output mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 4, FLAGS, "mode" },157 { "mode", "set output mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 4, FLAGS, "mode" },
158 { "magnitude", "magnitude", 0, AV_OPT_TYPE_CONST,{.i64=0}, 0, 0, FLAGS, "mode" },158 { "magnitude", "magnitude", 0, AV_OPT_TYPE_CONST,{.i64=0}, 0, 0, FLAGS, "mode" },
@@ -701,13 +701,13 @@ static int compute_kernel(AVFilterContext *ctx) · 542 unmodified lines
701 701
702 for (int y = 0; y < fsize; y++) {702 for (int y = 0; y < fsize; y++) {
703 AVComplexFloat *kernel = s->kernel[y];703 AVComplexFloat *kernel = s->kernel[y];
704 int start = 0, stop = 0;704 int start = INT_MIN, stop = INT_MAX;
705 const float frequency = s->frequency_band[y*2] * correction;705 const float frequency = s->frequency_band[y*2] * correction;
706 const float deviation = 1.f / (s->frequency_band[y*2+1] *706 const float deviation = 1.f / (s->frequency_band[y*2+1] *
707 output_sample_count * correction);707 output_sample_count * correction);
708 const int range = 8.f*M_PI*sqrtf(1.f/deviation);708 const int a = FFMAX(frequency-12.f*sqrtf(1.f/deviation)-0.5f, -size);
709 const int a = floorf(frequency-range);709 const int b = FFMIN(frequency+12.f*sqrtf(1.f/deviation)-0.5f, size+a);
710 const int b = ceilf(frequency+range);710 const int range = -a;
711 711
712 memset(tkernel, 0, size * sizeof(*tkernel));712 memset(tkernel, 0, size * sizeof(*tkernel));
713 for (int n = a; n < b; n++) {713 for (int n = a; n < b; n++) {
@@ -720,7 +720,7 @@ static int compute_kernel(AVFilterContext *ctx) · 6 unmodified lines
720 for (int n = a; n < b; n++) {720 for (int n = a; n < b; n++) {
721 if (tkernel[n+range] != 0.f) {721 if (tkernel[n+range] != 0.f) {
722 if (tkernel[n+range] > FLT_MIN)722 if (tkernel[n+range] > FLT_MIN)
723 av_log(ctx, AV_LOG_DEBUG, "out of range kernel\n");723 av_log(ctx, AV_LOG_DEBUG, "out of range kernel %g\n", tkernel[n+range]);
724 start = n;724 start = n;
725 break;725 break;
726 }726 }
@@ -729,16 +729,21 @@ static int compute_kernel(AVFilterContext *ctx) · 2 unmodified lines
729 for (int n = b; n >= a; n--) {729 for (int n = b; n >= a; n--) {
730 if (tkernel[n+range] != 0.f) {730 if (tkernel[n+range] != 0.f) {
731 if (tkernel[n+range] > FLT_MIN)731 if (tkernel[n+range] > FLT_MIN)
732 av_log(ctx, AV_LOG_DEBUG, "out of range kernel\n");732 av_log(ctx, AV_LOG_DEBUG, "out of range kernel %g\n", tkernel[n+range]);
733 stop = n;733 stop = n;
734 break;734 break;
735 }735 }
736 }736 }
737 737
738 if (start == INT_MIN || stop == INT_MAX) {
739 ret = AVERROR(EINVAL);
740 break;
741 }
742
738 kernel_start[y] = start;743 kernel_start[y] = start;
739 kernel_stop[y] = stop;744 kernel_stop[y] = stop;
740 745
741 kernel = av_calloc(FFALIGN(stop - start + 1+range, 16), sizeof(*kernel));746 kernel = av_calloc(FFALIGN(stop-start+1, 16), sizeof(*kernel));
742 if (!kernel) {747 if (!kernel) {
743 ret = AVERROR(ENOMEM);748 ret = AVERROR(ENOMEM);
744 break;749 break;

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