Unified · Split
| @@ -35,6 +35,13 @@ · 34 unmodified lines | ||
| 35 | 35 | #define SFM_FLAGS_SIZE (512) |
| 36 | 36 | #define SFM_FLAGS_MASK (SFM_FLAGS_SIZE - 1) |
| 37 | 37 | |
| 38 | +enum SampleNoiseModes { | |
| 39 | + SAMPLE_NONE, | |
| 40 | + SAMPLE_START, | |
| 41 | + SAMPLE_STOP, | |
| 42 | + NB_SAMPLEMODES | |
| 43 | +}; | |
| 44 | + | |
| 38 | 45 | enum OutModes { |
| 39 | 46 | IN_MODE, |
| 40 | 47 | OUT_MODE, |
| @@ -124,8 +131,7 @@ typedef struct AudioFFTDeNoiseContext { · 83 unmodified lines | ||
| 124 | 131 | |
| 125 | 132 | int channels; |
| 126 | 133 | int sample_noise; |
| 127 | − int sample_noise_start; | |
| 128 | − int sample_noise_end; | |
| 134 | + int sample_noise_mode; | |
| 129 | 135 | float sample_rate; |
| 130 | 136 | int buffer_length; |
| 131 | 137 | int fft_length; |
| @@ -204,6 +210,13 @@ static const AVOption afftdn_options[] = { · 72 unmodified lines | ||
| 204 | 210 | { "average", "average", 0, AV_OPT_TYPE_CONST, {.i64 = AVERAGE_LINK}, 0, 0, AFR, "link" }, |
| 205 | 211 | { "band_multiplier", "set band multiplier",OFFSET(band_multiplier), AV_OPT_TYPE_FLOAT,{.dbl = 1.25}, 0.2,5, AF }, |
| 206 | 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 | 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 | 1172 | for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) { |
| 1160 | 1173 | DeNoiseChannel *dnch = &s->dnch[ch]; |
| 1161 | 1174 | |
| 1162 | 1175 | init_sample_noise(dnch); |
| 1163 | 1176 | } |
| 1164 | − s->sample_noise_start = 0; | |
| 1177 | + s->sample_noise_mode = SAMPLE_NONE; | |
| 1165 | 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 | 1190 | for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) { |
| 1178 | 1191 | DeNoiseChannel *dnch = &s->dnch[ch]; |
| 1179 | 1192 | double sample_noise[NB_PROFILE_BANDS]; |
| @@ -1183,7 +1196,7 @@ static int output_frame(AVFilterLink *inlink, AVFrame *in) · 3 unmodified lines | ||
| 1183 | 1196 | set_parameters(s, dnch, 1, 1); |
| 1184 | 1197 | } |
| 1185 | 1198 | s->sample_noise = 0; |
| 1186 | − s->sample_noise_end = 0; | |
| 1199 | + s->sample_noise_mode = SAMPLE_NONE; | |
| 1187 | 1200 | } |
| 1188 | 1201 | |
| 1189 | 1202 | s->block_count++; |
| @@ -1297,36 +1310,23 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar · 107 unmodified lines | ||
| 1297 | 1310 | char *res, int res_len, int flags) |
| 1298 | 1311 | { |
| 1299 | 1312 | AudioFFTDeNoiseContext *s = ctx->priv; |
| 1300 | − int need_reset = 0; | |
| 1301 | 1313 | int ret = 0; |
| 1302 | 1314 | |
| 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; | |
| 1319 | 1318 | |
| 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; | |
| 1323 | 1321 | |
| 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]; | |
| 1327 | 1324 | |
| 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); | |
| 1330 | 1330 | } |
| 1331 | 1331 | |
| 1332 | 1332 | return 0; |