History

avfilter/af_afftdn: refactor noise sampling

Paul B Mahol committed 4 years ago

Commit bd5da8a1 parent a2eb13c1 file · +31 −31Browse files

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

Unified · Split

libavfilter/af_afftdn.c+31−31
@@ -35,6 +35,13 @@ · 34 unmodified lines
3535 #define SFM_FLAGS_SIZE (512)
3636 #define SFM_FLAGS_MASK (SFM_FLAGS_SIZE - 1)
3737
38+enum SampleNoiseModes {
39+ SAMPLE_NONE,
40+ SAMPLE_START,
41+ SAMPLE_STOP,
42+ NB_SAMPLEMODES
43+};
44+
3845 enum OutModes {
3946 IN_MODE,
4047 OUT_MODE,
@@ -124,8 +131,7 @@ typedef struct AudioFFTDeNoiseContext { · 83 unmodified lines
124131
125132 int channels;
126133 int sample_noise;
127− int sample_noise_start;
128− int sample_noise_end;
134+ int sample_noise_mode;
129135 float sample_rate;
130136 int buffer_length;
131137 int fft_length;
@@ -204,6 +210,13 @@ static const AVOption afftdn_options[] = { · 72 unmodified lines
204210 { "average", "average", 0, AV_OPT_TYPE_CONST, {.i64 = AVERAGE_LINK}, 0, 0, AFR, "link" },
205211 { "band_multiplier", "set band multiplier",OFFSET(band_multiplier), AV_OPT_TYPE_FLOAT,{.dbl = 1.25}, 0.2,5, AF },
206212 { "bm", "set band multiplier", OFFSET(band_multiplier), AV_OPT_TYPE_FLOAT,{.dbl = 1.25}, 0.2,5, AF },
213+ { "sample_noise", "set sample noise mode",OFFSET(sample_noise_mode),AV_OPT_TYPE_INT,{.i64 = SAMPLE_NONE}, 0, NB_SAMPLEMODES-1, AFR, "sample" },
214+ { "sn", "set sample noise mode",OFFSET(sample_noise_mode),AV_OPT_TYPE_INT,{.i64 = SAMPLE_NONE}, 0, NB_SAMPLEMODES-1, AFR, "sample" },
215+ { "none", "none", 0, AV_OPT_TYPE_CONST, {.i64 = SAMPLE_NONE}, 0, 0, AFR, "sample" },
216+ { "start", "start", 0, AV_OPT_TYPE_CONST, {.i64 = SAMPLE_START}, 0, 0, AFR, "sample" },
217+ { "begin", "start", 0, AV_OPT_TYPE_CONST, {.i64 = SAMPLE_START}, 0, 0, AFR, "sample" },
218+ { "stop", "stop", 0, AV_OPT_TYPE_CONST, {.i64 = SAMPLE_STOP}, 0, 0, AFR, "sample" },
219+ { "end", "stop", 0, AV_OPT_TYPE_CONST, {.i64 = SAMPLE_STOP}, 0, 0, AFR, "sample" },
207220 { NULL }
208221 };
209222
@@ -1155,13 +1168,13 @@ static int output_frame(AVFilterLink *inlink, AVFrame *in) · 945 unmodified lines
11551168 }
11561169 }
11571170
1158− if (s->sample_noise_start) {
1171+ if (s->sample_noise_mode == SAMPLE_START) {
11591172 for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
11601173 DeNoiseChannel *dnch = &s->dnch[ch];
11611174
11621175 init_sample_noise(dnch);
11631176 }
1164− s->sample_noise_start = 0;
1177+ s->sample_noise_mode = SAMPLE_NONE;
11651178 s->sample_noise = 1;
11661179 }
11671180
@@ -1173,7 +1186,7 @@ static int output_frame(AVFilterLink *inlink, AVFrame *in) · 5 unmodified lines
11731186 }
11741187 }
11751188
1176− if (s->sample_noise_end) {
1189+ if (s->sample_noise_mode == SAMPLE_STOP) {
11771190 for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
11781191 DeNoiseChannel *dnch = &s->dnch[ch];
11791192 double sample_noise[NB_PROFILE_BANDS];
@@ -1183,7 +1196,7 @@ static int output_frame(AVFilterLink *inlink, AVFrame *in) · 3 unmodified lines
11831196 set_parameters(s, dnch, 1, 1);
11841197 }
11851198 s->sample_noise = 0;
1186− s->sample_noise_end = 0;
1199+ s->sample_noise_mode = SAMPLE_NONE;
11871200 }
11881201
11891202 s->block_count++;
@@ -1297,36 +1310,23 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar · 107 unmodified lines
12971310 char *res, int res_len, int flags)
12981311 {
12991312 AudioFFTDeNoiseContext *s = ctx->priv;
1300− int need_reset = 0;
13011313 int ret = 0;
13021314
1303− if (!strcmp(cmd, "sample_noise") ||
1304− !strcmp(cmd, "sn")) {
1305− if (!strcmp(args, "start")) {
1306− s->sample_noise_start = 1;
1307− s->sample_noise_end = 0;
1308− } else if (!strcmp(args, "end") ||
1309− !strcmp(args, "stop")) {
1310− s->sample_noise_start = 0;
1311− s->sample_noise_end = 1;
1312− }
1313− } else {
1314− ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
1315− if (ret < 0)
1316− return ret;
1317− need_reset = 1;
1318− }
1315+ ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
1316+ if (ret < 0)
1317+ return ret;
13191318
1320− if (need_reset) {
1321− for (int ch = 0; ch < s->channels; ch++) {
1322− DeNoiseChannel *dnch = &s->dnch[ch];
1319+ if (!strcmp(cmd, "sample_noise") || !strcmp(cmd, "sn"))
1320+ return 0;
13231321
1324− dnch->noise_reduction = s->noise_reduction;
1325− dnch->noise_floor = s->noise_floor;
1326− dnch->residual_floor = s->residual_floor;
1322+ for (int ch = 0; ch < s->channels; ch++) {
1323+ DeNoiseChannel *dnch = &s->dnch[ch];
13271324
1328− set_parameters(s, dnch, 1, 1);
1329− }
1325+ dnch->noise_reduction = s->noise_reduction;
1326+ dnch->noise_floor = s->noise_floor;
1327+ dnch->residual_floor = s->residual_floor;
1328+
1329+ set_parameters(s, dnch, 1, 1);
13301330 }
13311331
13321332 return 0;

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