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

Unified · Split

libavfilter/avf_showcwt.c+13−8
@@ -152,7 +152,7 @@ static const AVOption showcwt_options[] = { · 151 unmodified lines
152152 { "min", "set minimum frequency", OFFSET(minimum_frequency), AV_OPT_TYPE_FLOAT, {.dbl = 20.}, 1, 192000, FLAGS },
153153 { "max", "set maximum frequency", OFFSET(maximum_frequency), AV_OPT_TYPE_FLOAT, {.dbl = 20000.}, 1, 192000, FLAGS },
154154 { "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 },
156156 { "pps", "set pixels per second", OFFSET(pps), AV_OPT_TYPE_INT, {.i64 = 64}, 1, 1024, FLAGS },
157157 { "mode", "set output mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 4, FLAGS, "mode" },
158158 { "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
701701
702702 for (int y = 0; y < fsize; y++) {
703703 AVComplexFloat *kernel = s->kernel[y];
704− int start = 0, stop = 0;
704+ int start = INT_MIN, stop = INT_MAX;
705705 const float frequency = s->frequency_band[y*2] * correction;
706706 const float deviation = 1.f / (s->frequency_band[y*2+1] *
707707 output_sample_count * correction);
708− const int range = 8.f*M_PI*sqrtf(1.f/deviation);
709− const int a = floorf(frequency-range);
710− const int b = ceilf(frequency+range);
708+ const int a = FFMAX(frequency-12.f*sqrtf(1.f/deviation)-0.5f, -size);
709+ const int b = FFMIN(frequency+12.f*sqrtf(1.f/deviation)-0.5f, size+a);
710+ const int range = -a;
711711
712712 memset(tkernel, 0, size * sizeof(*tkernel));
713713 for (int n = a; n < b; n++) {
@@ -720,7 +720,7 @@ static int compute_kernel(AVFilterContext *ctx) · 6 unmodified lines
720720 for (int n = a; n < b; n++) {
721721 if (tkernel[n+range] != 0.f) {
722722 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]);
724724 start = n;
725725 break;
726726 }
@@ -729,16 +729,21 @@ static int compute_kernel(AVFilterContext *ctx) · 2 unmodified lines
729729 for (int n = b; n >= a; n--) {
730730 if (tkernel[n+range] != 0.f) {
731731 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]);
733733 stop = n;
734734 break;
735735 }
736736 }
737737
738+ if (start == INT_MIN || stop == INT_MAX) {
739+ ret = AVERROR(EINVAL);
740+ break;
741+ }
742+
738743 kernel_start[y] = start;
739744 kernel_stop[y] = stop;
740745
741− kernel = av_calloc(FFALIGN(stop - start + 1+range, 16), sizeof(*kernel));
746+ kernel = av_calloc(FFALIGN(stop-start+1, 16), sizeof(*kernel));
742747 if (!kernel) {
743748 ret = AVERROR(ENOMEM);
744749 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