History

avfilter/af_afftdn: simplify changing commands

Paul B Mahol committed 6 years ago

Commit 84e9a551 parent 8e2a8321 file · +23 −41Browse files

Unified · Split

libavfilter/af_afftdn.c+23−41
@@ -141,24 +141,25 @@ typedef struct AudioFFTDeNoiseContext { · 140 unmodified lines
141141 } AudioFFTDeNoiseContext;
142142
143143 #define OFFSET(x) offsetof(AudioFFTDeNoiseContext, x)
144−#define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
144+#define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
145+#define AFR AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
145146
146147 static const AVOption afftdn_options[] = {
147− { "nr", "set the noise reduction", OFFSET(noise_reduction), AV_OPT_TYPE_FLOAT, {.dbl = 12}, .01, 97, A },
148− { "nf", "set the noise floor", OFFSET(noise_floor), AV_OPT_TYPE_FLOAT, {.dbl =-50}, -80,-20, A },
149− { "nt", "set the noise type", OFFSET(noise_type), AV_OPT_TYPE_INT, {.i64 = WHITE_NOISE}, WHITE_NOISE, NB_NOISE-1, A, "type" },
150− { "w", "white noise", 0, AV_OPT_TYPE_CONST, {.i64 = WHITE_NOISE}, 0, 0, A, "type" },
151− { "v", "vinyl noise", 0, AV_OPT_TYPE_CONST, {.i64 = VINYL_NOISE}, 0, 0, A, "type" },
152− { "s", "shellac noise", 0, AV_OPT_TYPE_CONST, {.i64 = SHELLAC_NOISE}, 0, 0, A, "type" },
153− { "c", "custom noise", 0, AV_OPT_TYPE_CONST, {.i64 = CUSTOM_NOISE}, 0, 0, A, "type" },
154− { "bn", "set the custom bands noise", OFFSET(band_noise_str), AV_OPT_TYPE_STRING, {.str = 0}, 0, 0, A },
155− { "rf", "set the residual floor", OFFSET(residual_floor), AV_OPT_TYPE_FLOAT, {.dbl =-38}, -80,-20, A },
156− { "tn", "track noise", OFFSET(track_noise), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, A },
157− { "tr", "track residual", OFFSET(track_residual), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, A },
158− { "om", "set output mode", OFFSET(output_mode), AV_OPT_TYPE_INT, {.i64 = OUT_MODE}, 0, NB_MODES-1, A, "mode" },
159− { "i", "input", 0, AV_OPT_TYPE_CONST, {.i64 = IN_MODE}, 0, 0, A, "mode" },
160− { "o", "output", 0, AV_OPT_TYPE_CONST, {.i64 = OUT_MODE}, 0, 0, A, "mode" },
161− { "n", "noise", 0, AV_OPT_TYPE_CONST, {.i64 = NOISE_MODE}, 0, 0, A, "mode" },
148+ { "nr", "set the noise reduction", OFFSET(noise_reduction), AV_OPT_TYPE_FLOAT, {.dbl = 12}, .01, 97, AFR },
149+ { "nf", "set the noise floor", OFFSET(noise_floor), AV_OPT_TYPE_FLOAT, {.dbl =-50}, -80,-20, AFR },
150+ { "nt", "set the noise type", OFFSET(noise_type), AV_OPT_TYPE_INT, {.i64 = WHITE_NOISE}, WHITE_NOISE, NB_NOISE-1, AF, "type" },
151+ { "w", "white noise", 0, AV_OPT_TYPE_CONST, {.i64 = WHITE_NOISE}, 0, 0, AF, "type" },
152+ { "v", "vinyl noise", 0, AV_OPT_TYPE_CONST, {.i64 = VINYL_NOISE}, 0, 0, AF, "type" },
153+ { "s", "shellac noise", 0, AV_OPT_TYPE_CONST, {.i64 = SHELLAC_NOISE}, 0, 0, AF, "type" },
154+ { "c", "custom noise", 0, AV_OPT_TYPE_CONST, {.i64 = CUSTOM_NOISE}, 0, 0, AF, "type" },
155+ { "bn", "set the custom bands noise", OFFSET(band_noise_str), AV_OPT_TYPE_STRING, {.str = 0}, 0, 0, AF },
156+ { "rf", "set the residual floor", OFFSET(residual_floor), AV_OPT_TYPE_FLOAT, {.dbl =-38}, -80,-20, AFR },
157+ { "tn", "track noise", OFFSET(track_noise), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AFR },
158+ { "tr", "track residual", OFFSET(track_residual), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AFR },
159+ { "om", "set output mode", OFFSET(output_mode), AV_OPT_TYPE_INT, {.i64 = OUT_MODE}, 0, NB_MODES-1, AFR, "mode" },
160+ { "i", "input", 0, AV_OPT_TYPE_CONST, {.i64 = IN_MODE}, 0, 0, AFR, "mode" },
161+ { "o", "output", 0, AV_OPT_TYPE_CONST, {.i64 = OUT_MODE}, 0, 0, AFR, "mode" },
162+ { "n", "noise", 0, AV_OPT_TYPE_CONST, {.i64 = NOISE_MODE}, 0, 0, AFR, "mode" },
162163 { NULL }
163164 };
164165
@@ -1375,6 +1376,7 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar · 1210 unmodified lines
13751376 {
13761377 AudioFFTDeNoiseContext *s = ctx->priv;
13771378 int need_reset = 0;
1379+ int ret = 0;
13781380
13791381 if (!strcmp(cmd, "sample_noise") ||
13801382 !strcmp(cmd, "sn")) {
@@ -1386,31 +1388,11 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar · 5 unmodified lines
13861388 s->sample_noise_start = 0;
13871389 s->sample_noise_end = 1;
13881390 }
1389− } else if (!strcmp(cmd, "nr") ||
1390− !strcmp(cmd, "noise_reduction")) {
1391− float nr;
1392−
1393− if (av_sscanf(args, "%f", &nr) == 1) {
1394− s->noise_reduction = av_clipf(nr, 0.01, 97);
1395− need_reset = 1;
1396− }
1397− } else if (!strcmp(cmd, "nf") ||
1398− !strcmp(cmd, "noise_floor")) {
1399− float nf;
1400−
1401− if (av_sscanf(args, "%f", &nf) == 1) {
1402− s->noise_floor = av_clipf(nf, -80, -20);
1403− need_reset = 1;
1404− }
1405− } else if (!strcmp(cmd, "output_mode") ||
1406− !strcmp(cmd, "om")) {
1407− if (!strcmp(args, "i")) {
1408− s->output_mode = IN_MODE;
1409− } else if (!strcmp(args, "o")) {
1410− s->output_mode = OUT_MODE;
1411− } else if (!strcmp(args, "n")) {
1412− s->output_mode = NOISE_MODE;
1413− }
1391+ } else {
1392+ ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
1393+ if (ret < 0)
1394+ return ret;
1395+ need_reset = 1;
14141396 }
14151397
14161398 if (need_reset)

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