History

avfilter/af_afftdn: refactor noise sampling

Paul B Mahol committed 4 years ago

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

Unified · Split

libavfilter/af_afftdn.c+31−31
@@ -35,6 +35,13 @@ · 34 unmodified lines
35#define SFM_FLAGS_SIZE (512)35#define SFM_FLAGS_SIZE (512)
36#define SFM_FLAGS_MASK (SFM_FLAGS_SIZE - 1)36#define SFM_FLAGS_MASK (SFM_FLAGS_SIZE - 1)
37 37
38enum SampleNoiseModes {
39 SAMPLE_NONE,
40 SAMPLE_START,
41 SAMPLE_STOP,
42 NB_SAMPLEMODES
43};
44
38enum OutModes {45enum OutModes {
39 IN_MODE,46 IN_MODE,
40 OUT_MODE,47 OUT_MODE,
@@ -124,8 +131,7 @@ typedef struct AudioFFTDeNoiseContext { · 83 unmodified lines
124 131
125 int channels;132 int channels;
126 int sample_noise;133 int sample_noise;
127 int sample_noise_start;134 int sample_noise_mode;
128 int sample_noise_end;
129 float sample_rate;135 float sample_rate;
130 int buffer_length;136 int buffer_length;
131 int fft_length;137 int fft_length;
@@ -204,6 +210,13 @@ static const AVOption afftdn_options[] = { · 72 unmodified lines
204 { "average", "average", 0, AV_OPT_TYPE_CONST, {.i64 = AVERAGE_LINK}, 0, 0, AFR, "link" },210 { "average", "average", 0, AV_OPT_TYPE_CONST, {.i64 = AVERAGE_LINK}, 0, 0, AFR, "link" },
205 { "band_multiplier", "set band multiplier",OFFSET(band_multiplier), AV_OPT_TYPE_FLOAT,{.dbl = 1.25}, 0.2,5, AF },211 { "band_multiplier", "set band multiplier",OFFSET(band_multiplier), AV_OPT_TYPE_FLOAT,{.dbl = 1.25}, 0.2,5, AF },
206 { "bm", "set band multiplier", OFFSET(band_multiplier), AV_OPT_TYPE_FLOAT,{.dbl = 1.25}, 0.2,5, AF },212 { "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" },
207 { NULL }220 { NULL }
208};221};
209 222
@@ -1155,13 +1168,13 @@ static int output_frame(AVFilterLink *inlink, AVFrame *in) · 945 unmodified lines
1155 }1168 }
1156 }1169 }
1157 1170
1158 if (s->sample_noise_start) {1171 if (s->sample_noise_mode == SAMPLE_START) {
1159 for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {1172 for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
1160 DeNoiseChannel *dnch = &s->dnch[ch];1173 DeNoiseChannel *dnch = &s->dnch[ch];
1161 1174
1162 init_sample_noise(dnch);1175 init_sample_noise(dnch);
1163 }1176 }
1164 s->sample_noise_start = 0;1177 s->sample_noise_mode = SAMPLE_NONE;
1165 s->sample_noise = 1;1178 s->sample_noise = 1;
1166 }1179 }
1167 1180
@@ -1173,7 +1186,7 @@ static int output_frame(AVFilterLink *inlink, AVFrame *in) · 5 unmodified lines
1173 }1186 }
1174 }1187 }
1175 1188
1176 if (s->sample_noise_end) {1189 if (s->sample_noise_mode == SAMPLE_STOP) {
1177 for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {1190 for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
1178 DeNoiseChannel *dnch = &s->dnch[ch];1191 DeNoiseChannel *dnch = &s->dnch[ch];
1179 double sample_noise[NB_PROFILE_BANDS];1192 double sample_noise[NB_PROFILE_BANDS];
@@ -1183,7 +1196,7 @@ static int output_frame(AVFilterLink *inlink, AVFrame *in) · 3 unmodified lines
1183 set_parameters(s, dnch, 1, 1);1196 set_parameters(s, dnch, 1, 1);
1184 }1197 }
1185 s->sample_noise = 0;1198 s->sample_noise = 0;
1186 s->sample_noise_end = 0;1199 s->sample_noise_mode = SAMPLE_NONE;
1187 }1200 }
1188 1201
1189 s->block_count++;1202 s->block_count++;
@@ -1297,36 +1310,23 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar · 107 unmodified lines
1297 char *res, int res_len, int flags)1310 char *res, int res_len, int flags)
1298{1311{
1299 AudioFFTDeNoiseContext *s = ctx->priv;1312 AudioFFTDeNoiseContext *s = ctx->priv;
1300 int need_reset = 0;
1301 int ret = 0;1313 int ret = 0;
1302 1314
1303 if (!strcmp(cmd, "sample_noise") ||1315 ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
1304 !strcmp(cmd, "sn")) {1316 if (ret < 0)
1305 if (!strcmp(args, "start")) {1317 return ret;
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 }
1319 1318
1320 if (need_reset) {1319 if (!strcmp(cmd, "sample_noise") || !strcmp(cmd, "sn"))
1321 for (int ch = 0; ch < s->channels; ch++) {1320 return 0;
1322 DeNoiseChannel *dnch = &s->dnch[ch];
1323 1321
1324 dnch->noise_reduction = s->noise_reduction;1322 for (int ch = 0; ch < s->channels; ch++) {
1325 dnch->noise_floor = s->noise_floor;1323 DeNoiseChannel *dnch = &s->dnch[ch];
1326 dnch->residual_floor = s->residual_floor;
1327 1324
1328 set_parameters(s, dnch, 1, 1);1325 dnch->noise_reduction = s->noise_reduction;
1329 }1326 dnch->noise_floor = s->noise_floor;
1327 dnch->residual_floor = s->residual_floor;
1328
1329 set_parameters(s, dnch, 1, 1);
1330 }1330 }
1331 1331
1332 return 0;1332 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