Showing the changes to libavfilter (1 of 2 files). Show all
Unified · Split
| @@ -33,8 +33,6 @@ · 32 unmodified lines | ||
| 33 | 33 | #define WEIGHT_LUT_NBITS 20 |
| 34 | 34 | #define WEIGHT_LUT_SIZE (1<<WEIGHT_LUT_NBITS) |
| 35 | 35 | |
| 36 | −#define SQR(x) ((x) * (x)) | |
| 37 | − | |
| 38 | 36 | typedef struct AudioNLMeansContext { |
| 39 | 37 | const AVClass *class; |
| 40 | 38 | |
| @@ -75,8 +73,8 @@ enum OutModes { · 34 unmodified lines | ||
| 75 | 73 | #define AFT AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM |
| 76 | 74 | |
| 77 | 75 | static const AVOption anlmdn_options[] = { |
| 78 | − { "strength", "set denoising strength", OFFSET(a), AV_OPT_TYPE_FLOAT, {.dbl=0.00001},0.00001, 10, AFT }, | |
| 79 | − { "s", "set denoising strength", OFFSET(a), AV_OPT_TYPE_FLOAT, {.dbl=0.00001},0.00001, 10, AFT }, | |
| 76 | + { "strength", "set denoising strength", OFFSET(a), AV_OPT_TYPE_FLOAT, {.dbl=0.00001},0.00001, 10000, AFT }, | |
| 77 | + { "s", "set denoising strength", OFFSET(a), AV_OPT_TYPE_FLOAT, {.dbl=0.00001},0.00001, 10000, AFT }, | |
| 80 | 78 | { "patch", "set patch duration", OFFSET(pd), AV_OPT_TYPE_DURATION, {.i64=2000}, 1000, 100000, AFT }, |
| 81 | 79 | { "p", "set patch duration", OFFSET(pd), AV_OPT_TYPE_DURATION, {.i64=2000}, 1000, 100000, AFT }, |
| 82 | 80 | { "research", "set research duration", OFFSET(rd), AV_OPT_TYPE_DURATION, {.i64=6000}, 2000, 300000, AFT }, |
| @@ -86,19 +84,26 @@ static const AVOption anlmdn_options[] = { · 3 unmodified lines | ||
| 86 | 84 | { "i", "input", 0, AV_OPT_TYPE_CONST, {.i64=IN_MODE}, 0, 0, AFT, "mode" }, |
| 87 | 85 | { "o", "output", 0, AV_OPT_TYPE_CONST, {.i64=OUT_MODE}, 0, 0, AFT, "mode" }, |
| 88 | 86 | { "n", "noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_MODE},0, 0, AFT, "mode" }, |
| 89 | − { "smooth", "set smooth factor", OFFSET(m), AV_OPT_TYPE_FLOAT, {.dbl=11.}, 1, 15, AFT }, | |
| 90 | − { "m", "set smooth factor", OFFSET(m), AV_OPT_TYPE_FLOAT, {.dbl=11.}, 1, 15, AFT }, | |
| 87 | + { "smooth", "set smooth factor", OFFSET(m), AV_OPT_TYPE_FLOAT, {.dbl=11.}, 1, 1000, AFT }, | |
| 88 | + { "m", "set smooth factor", OFFSET(m), AV_OPT_TYPE_FLOAT, {.dbl=11.}, 1, 1000, AFT }, | |
| 91 | 89 | { NULL } |
| 92 | 90 | }; |
| 93 | 91 | |
| 94 | 92 | AVFILTER_DEFINE_CLASS(anlmdn); |
| 95 | 93 | |
| 94 | +static inline float sqrdiff(float x, float y) | |
| 95 | +{ | |
| 96 | + const float diff = x - y; | |
| 97 | + | |
| 98 | + return diff * diff; | |
| 99 | +} | |
| 100 | + | |
| 96 | 101 | static float compute_distance_ssd_c(const float *f1, const float *f2, ptrdiff_t K) |
| 97 | 102 | { |
| 98 | 103 | float distance = 0.; |
| 99 | 104 | |
| 100 | 105 | for (int k = -K; k <= K; k++) |
| 101 | − distance += SQR(f1[k] - f2[k]); | |
| 106 | + distance += sqrdiff(f1[k], f2[k]); | |
| 102 | 107 | |
| 103 | 108 | return distance; |
| 104 | 109 | } |
| @@ -110,7 +115,7 @@ static void compute_cache_c(float *cache, const float *f, · 5 unmodified lines | ||
| 110 | 115 | int v = 0; |
| 111 | 116 | |
| 112 | 117 | for (int j = jj; j < jj + S; j++, v++) |
| 113 | − cache[v] += -SQR(f[i - K - 1] - f[j - K - 1]) + SQR(f[i + K] - f[j + K]); | |
| 118 | + cache[v] += -sqrdiff(f[i - K - 1], f[j - K - 1]) + sqrdiff(f[i + K], f[j + K]); | |
| 114 | 119 | } |
| 115 | 120 | |
| 116 | 121 | void ff_anlmdn_init(AudioNLMDNDSPContext *dsp) |
| @@ -213,7 +218,9 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) · 96 unmodified lines | ||
| 213 | 218 | float *cache = (float *)s->cache->extended_data[ch]; |
| 214 | 219 | const float sw = (65536.f / (4 * K + 2)) / sqrtf(s->a); |
| 215 | 220 | float *dst = (float *)out->extended_data[ch] + s->offset; |
| 216 | − const float smooth = s->m; | |
| 221 | + const float *const weight_lut = s->weight_lut; | |
| 222 | + const float pdiff_lut_scale = s->pdiff_lut_scale; | |
| 223 | + const float smooth = fminf(s->m, WEIGHT_LUT_SIZE / pdiff_lut_scale); | |
| 217 | 224 | |
| 218 | 225 | for (int i = S; i < s->H + S; i++) { |
| 219 | 226 | float P = 0.f, Q = 0.f; |
| @@ -231,26 +238,24 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) · 11 unmodified lines | ||
| 231 | 238 | } |
| 232 | 239 | |
| 233 | 240 | for (int j = 0; j < 2 * S && !ctx->is_disabled; j++) { |
| 234 | − const float distance = cache[j]; | |
| 241 | + float distance = cache[j]; | |
| 235 | 242 | unsigned weight_lut_idx; |
| 236 | 243 | float w; |
| 237 | 244 | |
| 238 | − if (distance < 0.f) { | |
| 239 | − cache[j] = 0.f; | |
| 240 | − continue; | |
| 241 | − } | |
| 245 | + if (distance < 0.f) | |
| 246 | + cache[j] = distance = 0.f; | |
| 242 | 247 | w = distance * sw; |
| 243 | 248 | if (w >= smooth) |
| 244 | 249 | continue; |
| 245 | − weight_lut_idx = w * s->pdiff_lut_scale; | |
| 250 | + weight_lut_idx = w * pdiff_lut_scale; | |
| 246 | 251 | av_assert2(weight_lut_idx < WEIGHT_LUT_SIZE); |
| 247 | − w = s->weight_lut[weight_lut_idx]; | |
| 252 | + w = weight_lut[weight_lut_idx]; | |
| 248 | 253 | P += w * f[i - S + j + (j >= S)]; |
| 249 | 254 | Q += w; |
| 250 | 255 | } |
| 251 | 256 | |
| 252 | 257 | P += f[i]; |
| 253 | − Q += 1; | |
| 258 | + Q += 1.f; | |
| 254 | 259 | |
| 255 | 260 | switch (om) { |
| 256 | 261 | case IN_MODE: dst[i - S] = f[i]; break; |