Unified · Split
| @@ -20,7 +20,6 @@ · 19 unmodified lines | ||
| 20 | 20 | |
| 21 | 21 | #include <float.h> |
| 22 | 22 | |
| 23 | −#include "libavutil/audio_fifo.h" | |
| 24 | 23 | #include "libavutil/avstring.h" |
| 25 | 24 | #include "libavutil/channel_layout.h" |
| 26 | 25 | #include "libavutil/opt.h" |
| @@ -101,7 +100,6 @@ typedef struct AudioFFTDeNoiseContext { · 74 unmodified lines | ||
| 101 | 100 | float last_noise_balance; |
| 102 | 101 | int64_t block_count; |
| 103 | 102 | |
| 104 | − int64_t pts; | |
| 105 | 103 | int channels; |
| 106 | 104 | int sample_noise; |
| 107 | 105 | int sample_noise_start; |
| @@ -124,6 +122,8 @@ typedef struct AudioFFTDeNoiseContext { · 16 unmodified lines | ||
| 124 | 122 | |
| 125 | 123 | DeNoiseChannel *dnch; |
| 126 | 124 | |
| 125 | + AVFrame *winframe; | |
| 126 | + | |
| 127 | 127 | double max_gain; |
| 128 | 128 | double max_var; |
| 129 | 129 | double gain_scale; |
| @@ -138,8 +138,6 @@ typedef struct AudioFFTDeNoiseContext { · 8 unmodified lines | ||
| 138 | 138 | double vector_b[5]; |
| 139 | 139 | double matrix_b[75]; |
| 140 | 140 | double matrix_c[75]; |
| 141 | − | |
| 142 | − AVAudioFifo *fifo; | |
| 143 | 141 | } AudioFFTDeNoiseContext; |
| 144 | 142 | |
| 145 | 143 | #define OFFSET(x) offsetof(AudioFFTDeNoiseContext, x) |
| @@ -620,7 +618,6 @@ static int config_input(AVFilterLink *inlink) · 474 unmodified lines | ||
| 620 | 618 | if (!s->dnch) |
| 621 | 619 | return AVERROR(ENOMEM); |
| 622 | 620 | |
| 623 | − s->pts = AV_NOPTS_VALUE; | |
| 624 | 621 | s->channels = inlink->channels; |
| 625 | 622 | s->sample_rate = inlink->sample_rate; |
| 626 | 623 | s->sample_advance = s->sample_rate / 80; |
| @@ -831,6 +828,10 @@ static int config_input(AVFilterLink *inlink) · 204 unmodified lines | ||
| 831 | 828 | } |
| 832 | 829 | } |
| 833 | 830 | |
| 831 | + s->winframe = ff_get_audio_buffer(inlink, s->window_length); | |
| 832 | + if (!s->winframe) | |
| 833 | + return AVERROR(ENOMEM); | |
| 834 | + | |
| 834 | 835 | wscale = sqrt(16.0 / (9.0 * s->fft_length)); |
| 835 | 836 | sum = 0.0; |
| 836 | 837 | for (int i = 0; i < s->window_length; i++) { |
| @@ -857,10 +858,6 @@ static int config_input(AVFilterLink *inlink) · 20 unmodified lines | ||
| 857 | 858 | } |
| 858 | 859 | s->noise_band_count = s->noise_band_edge[16]; |
| 859 | 860 | |
| 860 | − s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->fft_length); | |
| 861 | − if (!s->fifo) | |
| 862 | − return AVERROR(ENOMEM); | |
| 863 | − | |
| 864 | 861 | return 0; |
| 865 | 862 | } |
| 866 | 863 | |
| @@ -1160,23 +1157,24 @@ static void get_auto_noise_levels(AudioFFTDeNoiseContext *s, · 293 unmodified lines | ||
| 1160 | 1157 | } |
| 1161 | 1158 | } |
| 1162 | 1159 | |
| 1163 | −static int output_frame(AVFilterLink *inlink) | |
| 1160 | +static int output_frame(AVFilterLink *inlink, AVFrame *in) | |
| 1164 | 1161 | { |
| 1165 | 1162 | AVFilterContext *ctx = inlink->dst; |
| 1166 | 1163 | AVFilterLink *outlink = ctx->outputs[0]; |
| 1167 | 1164 | AudioFFTDeNoiseContext *s = ctx->priv; |
| 1168 | 1165 | const int output_mode = ctx->is_disabled ? IN_MODE : s->output_mode; |
| 1169 | − AVFrame *out = NULL, *in = NULL; | |
| 1166 | + const int offset = s->window_length - s->sample_advance; | |
| 1167 | + AVFrame *out = NULL; | |
| 1170 | 1168 | ThreadData td; |
| 1171 | 1169 | int ret = 0; |
| 1172 | 1170 | |
| 1173 | − in = ff_get_audio_buffer(outlink, s->window_length); | |
| 1174 | − if (!in) | |
| 1175 | − return AVERROR(ENOMEM); | |
| 1171 | + for (int ch = 0; ch < s->channels; ch++) { | |
| 1172 | + float *src = (float *)s->winframe->extended_data[ch]; | |
| 1176 | 1173 | |
| 1177 | − ret = av_audio_fifo_peek(s->fifo, (void **)in->extended_data, s->window_length); | |
| 1178 | − if (ret < 0) | |
| 1179 | − goto end; | |
| 1174 | + memmove(src, &src[s->sample_advance], offset * sizeof(float)); | |
| 1175 | + memcpy(&src[offset], in->extended_data[ch], in->nb_samples * sizeof(float)); | |
| 1176 | + memset(&src[offset + in->nb_samples], 0, (s->sample_advance - in->nb_samples) * sizeof(float)); | |
| 1177 | + } | |
| 1180 | 1178 | |
| 1181 | 1179 | if (s->track_noise) { |
| 1182 | 1180 | for (int ch = 0; ch < inlink->channels; ch++) { |
| @@ -1205,7 +1203,7 @@ static int output_frame(AVFilterLink *inlink) · 22 unmodified lines | ||
| 1205 | 1203 | for (int ch = 0; ch < inlink->channels; ch++) { |
| 1206 | 1204 | DeNoiseChannel *dnch = &s->dnch[ch]; |
| 1207 | 1205 | |
| 1208 | − sample_noise_block(s, dnch, in, ch); | |
| 1206 | + sample_noise_block(s, dnch, s->winframe, ch); | |
| 1209 | 1207 | } |
| 1210 | 1208 | } |
| 1211 | 1209 | |
| @@ -1223,11 +1221,11 @@ static int output_frame(AVFilterLink *inlink) · 11 unmodified lines | ||
| 1223 | 1221 | } |
| 1224 | 1222 | |
| 1225 | 1223 | s->block_count++; |
| 1226 | − td.in = in; | |
| 1224 | + td.in = s->winframe; | |
| 1227 | 1225 | ff_filter_execute(ctx, filter_channel, &td, NULL, |
| 1228 | 1226 | FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx))); |
| 1229 | 1227 | |
| 1230 | − out = ff_get_audio_buffer(outlink, s->sample_advance); | |
| 1228 | + out = ff_get_audio_buffer(outlink, in->nb_samples); | |
| 1231 | 1229 | if (!out) { |
| 1232 | 1230 | ret = AVERROR(ENOMEM); |
| 1233 | 1231 | goto end; |
| @@ -1236,20 +1234,20 @@ static int output_frame(AVFilterLink *inlink) · 2 unmodified lines | ||
| 1236 | 1234 | for (int ch = 0; ch < inlink->channels; ch++) { |
| 1237 | 1235 | DeNoiseChannel *dnch = &s->dnch[ch]; |
| 1238 | 1236 | double *src = dnch->out_samples; |
| 1239 | − float *orig = (float *)in->extended_data[ch]; | |
| 1237 | + const float *orig = (const float *)s->winframe->extended_data[ch]; | |
| 1240 | 1238 | float *dst = (float *)out->extended_data[ch]; |
| 1241 | 1239 | |
| 1242 | 1240 | switch (output_mode) { |
| 1243 | 1241 | case IN_MODE: |
| 1244 | − for (int m = 0; m < s->sample_advance; m++) | |
| 1242 | + for (int m = 0; m < out->nb_samples; m++) | |
| 1245 | 1243 | dst[m] = orig[m]; |
| 1246 | 1244 | break; |
| 1247 | 1245 | case OUT_MODE: |
| 1248 | − for (int m = 0; m < s->sample_advance; m++) | |
| 1246 | + for (int m = 0; m < out->nb_samples; m++) | |
| 1249 | 1247 | dst[m] = src[m]; |
| 1250 | 1248 | break; |
| 1251 | 1249 | case NOISE_MODE: |
| 1252 | − for (int m = 0; m < s->sample_advance; m++) | |
| 1250 | + for (int m = 0; m < out->nb_samples; m++) | |
| 1253 | 1251 | dst[m] = orig[m] - src[m]; |
| 1254 | 1252 | break; |
| 1255 | 1253 | default: |
| @@ -1261,13 +1259,11 @@ static int output_frame(AVFilterLink *inlink) · 5 unmodified lines | ||
| 1261 | 1259 | memset(src + (s->window_length - s->sample_advance), 0, s->sample_advance * sizeof(*src)); |
| 1262 | 1260 | } |
| 1263 | 1261 | |
| 1264 | − av_audio_fifo_drain(s->fifo, s->sample_advance); | |
| 1262 | + out->pts = in->pts; | |
| 1265 | 1263 | |
| 1266 | − out->pts = s->pts; | |
| 1267 | 1264 | ret = ff_filter_frame(outlink, out); |
| 1268 | 1265 | if (ret < 0) |
| 1269 | 1266 | goto end; |
| 1270 | − s->pts += av_rescale_q(s->sample_advance, (AVRational){1, outlink->sample_rate}, outlink->time_base); | |
| 1271 | 1267 | end: |
| 1272 | 1268 | av_frame_free(&in); |
| 1273 | 1269 | |
| @@ -1279,34 +1275,19 @@ static int activate(AVFilterContext *ctx) · 5 unmodified lines | ||
| 1279 | 1275 | AVFilterLink *inlink = ctx->inputs[0]; |
| 1280 | 1276 | AVFilterLink *outlink = ctx->outputs[0]; |
| 1281 | 1277 | AudioFFTDeNoiseContext *s = ctx->priv; |
| 1282 | − AVFrame *frame = NULL; | |
| 1278 | + AVFrame *in = NULL; | |
| 1283 | 1279 | int ret; |
| 1284 | 1280 | |
| 1285 | 1281 | FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); |
| 1286 | 1282 | |
| 1287 | − ret = ff_inlink_consume_frame(inlink, &frame); | |
| 1283 | + ret = ff_inlink_consume_samples(inlink, s->sample_advance, s->sample_advance, &in); | |
| 1288 | 1284 | if (ret < 0) |
| 1289 | 1285 | return ret; |
| 1290 | − | |
| 1291 | − if (ret > 0) { | |
| 1292 | − if (s->pts == AV_NOPTS_VALUE) | |
| 1293 | − s->pts = frame->pts; | |
| 1294 | − | |
| 1295 | − ret = av_audio_fifo_write(s->fifo, (void **)frame->extended_data, frame->nb_samples); | |
| 1296 | − av_frame_free(&frame); | |
| 1297 | − if (ret < 0) | |
| 1298 | − return ret; | |
| 1299 | − } | |
| 1300 | − | |
| 1301 | − if (av_audio_fifo_size(s->fifo) >= s->window_length) | |
| 1302 | − return output_frame(inlink); | |
| 1286 | + if (ret > 0) | |
| 1287 | + return output_frame(inlink, in); | |
| 1303 | 1288 | |
| 1304 | 1289 | FF_FILTER_FORWARD_STATUS(inlink, outlink); |
| 1305 | − if (ff_outlink_frame_wanted(outlink) && | |
| 1306 | − av_audio_fifo_size(s->fifo) < s->window_length) { | |
| 1307 | − ff_inlink_request_frame(inlink); | |
| 1308 | − return 0; | |
| 1309 | − } | |
| 1290 | + FF_FILTER_FORWARD_WANTED(outlink, inlink); | |
| 1310 | 1291 | |
| 1311 | 1292 | return FFERROR_NOT_READY; |
| 1312 | 1293 | } |
| @@ -1319,6 +1300,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 6 unmodified lines | ||
| 1319 | 1300 | av_freep(&s->bin2band); |
| 1320 | 1301 | av_freep(&s->band_alpha); |
| 1321 | 1302 | av_freep(&s->band_beta); |
| 1303 | + av_frame_free(&s->winframe); | |
| 1322 | 1304 | |
| 1323 | 1305 | if (s->dnch) { |
| 1324 | 1306 | for (int ch = 0; ch < s->channels; ch++) { |
| @@ -1343,8 +1325,6 @@ static av_cold void uninit(AVFilterContext *ctx) · 18 unmodified lines | ||
| 1343 | 1325 | } |
| 1344 | 1326 | av_freep(&s->dnch); |
| 1345 | 1327 | } |
| 1346 | − | |
| 1347 | − av_audio_fifo_free(s->fifo); | |
| 1348 | 1328 | } |
| 1349 | 1329 | |
| 1350 | 1330 | static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, |