Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -81,7 +81,7 @@ typedef struct ShowCWTContext { · 80 unmodified lines | ||
| 81 | 81 | unsigned *index; |
| 82 | 82 | int *kernel_start; |
| 83 | 83 | int *kernel_stop; |
| 84 | − AVFrame *overlap; | |
| 84 | + AVFrame *cache[2]; | |
| 85 | 85 | AVFrame *outpicref; |
| 86 | 86 | AVFrame *fft_in; |
| 87 | 87 | AVFrame *fft_out; |
| @@ -158,7 +158,8 @@ static av_cold void uninit(AVFilterContext *ctx) · 70 unmodified lines | ||
| 158 | 158 | av_freep(&s->index); |
| 159 | 159 | |
| 160 | 160 | av_frame_free(&s->kernel); |
| 161 | − av_frame_free(&s->overlap); | |
| 161 | + av_frame_free(&s->cache[0]); | |
| 162 | + av_frame_free(&s->cache[1]); | |
| 162 | 163 | av_frame_free(&s->outpicref); |
| 163 | 164 | av_frame_free(&s->fft_in); |
| 164 | 165 | av_frame_free(&s->fft_out); |
| @@ -243,12 +244,6 @@ static void frequency_band(float *frequency_band, · 78 unmodified lines | ||
| 243 | 244 | } |
| 244 | 245 | } |
| 245 | 246 | |
| 246 | −#define cmul(operator, index) { \ | |
| 247 | − const float ff = kernel[index]; \ | |
| 248 | − isrc[n].re operator ff*dst[index].re; \ | |
| 249 | − isrc[n].im operator ff*dst[index].im; \ | |
| 250 | −} | |
| 251 | − | |
| 252 | 247 | static float remap_log(float value, float log_factor) |
| 253 | 248 | { |
| 254 | 249 | float sign = (0 < value) - (value < 0); |
| @@ -261,36 +256,33 @@ static float remap_log(float value, float log_factor) · 6 unmodified lines | ||
| 261 | 256 | static int run_channel_cwt_prepare(AVFilterContext *ctx, void *arg, int jobnr, int ch) |
| 262 | 257 | { |
| 263 | 258 | ShowCWTContext *s = ctx->priv; |
| 259 | + const int hop_size = s->hop_size; | |
| 264 | 260 | AVFrame *fin = arg; |
| 265 | − float *overlap = (float *)s->overlap->extended_data[ch]; | |
| 261 | + float *cache0 = (float *)s->cache[0]->extended_data[ch]; | |
| 262 | + float *cache = (float *)s->cache[1]->extended_data[ch]; | |
| 266 | 263 | AVComplexFloat *src = (AVComplexFloat *)s->fft_in->extended_data[ch]; |
| 267 | 264 | AVComplexFloat *dst = (AVComplexFloat *)s->fft_out->extended_data[ch]; |
| 268 | − const int nb_consumed_samples = s->nb_consumed_samples; | |
| 269 | − const int input_padding_size = s->input_padding_size; | |
| 270 | 265 | |
| 271 | 266 | if (fin) { |
| 272 | − const int hop_size = fin->nb_samples; | |
| 273 | − const int offset = input_padding_size - hop_size; | |
| 267 | + const int offset = s->hop_index; | |
| 274 | 268 | const float *input = (const float *)fin->extended_data[ch]; |
| 275 | 269 | |
| 276 | − memmove(overlap, &overlap[hop_size], offset * sizeof(float)); | |
| 277 | − memcpy(&overlap[offset], input, | |
| 270 | + memcpy(&cache[offset], input, | |
| 278 | 271 | fin->nb_samples * sizeof(float)); |
| 279 | 272 | } |
| 280 | 273 | |
| 281 | 274 | if (fin == NULL) { |
| 282 | − const int hop_size = s->hop_size; | |
| 283 | − | |
| 284 | − memmove(overlap, &overlap[hop_size], hop_size * sizeof(float)); | |
| 285 | − memset(&overlap[s->hop_index], 0, | |
| 275 | + memset(&cache[s->hop_index], 0, | |
| 286 | 276 | (hop_size - s->hop_index) * sizeof(float)); |
| 287 | − } else if (s->hop_index + fin->nb_samples < s->hop_size) { | |
| 277 | + } else if (s->hop_index + fin->nb_samples < hop_size) { | |
| 288 | 278 | return 0; |
| 289 | 279 | } |
| 290 | 280 | |
| 291 | − for (int n = 0; n < nb_consumed_samples; n++) { | |
| 292 | − src[n].re = overlap[n]; | |
| 281 | + for (int n = 0; n < hop_size; n++) { | |
| 282 | + src[n].re = cache0[n]; | |
| 293 | 283 | src[n].im = 0.f; |
| 284 | + src[n + hop_size].re = cache[n]; | |
| 285 | + src[n + hop_size].im = 0.f; | |
| 294 | 286 | } |
| 295 | 287 | |
| 296 | 288 | s->tx_fn(s->fft[jobnr], dst, src, sizeof(*src)); |
| @@ -442,15 +434,15 @@ static int run_channel_cwt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 145 unmodified lines | ||
| 442 | 434 | memset(isrc, 0, sizeof(*isrc) * output_sample_count); |
| 443 | 435 | for (int i = kernel_start; i < kernel_stop; i++) { |
| 444 | 436 | const unsigned n = index[i]; |
| 445 | − cmul(+=, i); | |
| 437 | + const float ff = kernel[i]; | |
| 438 | + | |
| 439 | + isrc[n].re += ff * dst[i].re; | |
| 440 | + isrc[n].im += ff * dst[i].im; | |
| 446 | 441 | } |
| 447 | 442 | |
| 448 | 443 | s->itx_fn(s->ifft[jobnr], idst, isrc, sizeof(*isrc)); |
| 449 | 444 | |
| 450 | − for (int i = 0; i < ihop_size; i++) { | |
| 451 | − chout[i].re = idst[ioffset + i].re; | |
| 452 | − chout[i].im = idst[ioffset + i].im; | |
| 453 | − } | |
| 445 | + memcpy(chout, idst + ioffset, sizeof(*chout) * ihop_size); | |
| 454 | 446 | } |
| 455 | 447 | |
| 456 | 448 | return 0; |
| @@ -572,7 +564,8 @@ static int config_output(AVFilterLink *outlink) · 115 unmodified lines | ||
| 572 | 564 | s->outpicref = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
| 573 | 565 | s->fft_in = ff_get_audio_buffer(inlink, s->fft_in_size * 2); |
| 574 | 566 | s->fft_out = ff_get_audio_buffer(inlink, s->fft_out_size * 2); |
| 575 | − s->overlap = ff_get_audio_buffer(inlink, s->input_padding_size); | |
| 567 | + s->cache[0] = ff_get_audio_buffer(inlink, s->hop_size); | |
| 568 | + s->cache[1] = ff_get_audio_buffer(inlink, s->hop_size); | |
| 576 | 569 | s->ch_out = ff_get_audio_buffer(inlink, s->frequency_band_count * 2 * s->ihop_size); |
| 577 | 570 | s->ifft_in = av_frame_alloc(); |
| 578 | 571 | s->ifft_out = av_frame_alloc(); |
| @@ -582,7 +575,7 @@ static int config_output(AVFilterLink *outlink) · 3 unmodified lines | ||
| 582 | 575 | s->kernel_stop = av_calloc(s->frequency_band_count, sizeof(*s->kernel_stop)); |
| 583 | 576 | if (!s->outpicref || !s->fft_in || !s->fft_out || |
| 584 | 577 | !s->ifft_in || !s->ifft_out || !s->kernel_start || !s->kernel_stop || |
| 585 | − !s->frequency_band || !s->kernel || !s->overlap || !s->index) | |
| 578 | + !s->frequency_band || !s->kernel || !s->cache[0] || !s->cache[1] || !s->index) | |
| 586 | 579 | return AVERROR(ENOMEM); |
| 587 | 580 | |
| 588 | 581 | s->ifft_in->format = inlink->format; |
| @@ -834,7 +827,10 @@ static int activate(AVFilterContext *ctx) · 245 unmodified lines | ||
| 834 | 827 | } |
| 835 | 828 | |
| 836 | 829 | if (s->hop_index >= s->hop_size || s->ihop_index > 0) { |
| 837 | − s->hop_index = 0; | |
| 830 | + if (s->hop_index) { | |
| 831 | + FFSWAP(AVFrame *, s->cache[0], s->cache[1]); | |
| 832 | + s->hop_index = 0; | |
| 833 | + } | |
| 838 | 834 | |
| 839 | 835 | for (int ch = 0; ch < s->nb_channels && s->ihop_index == 0; ch++) { |
| 840 | 836 | ff_filter_execute(ctx, run_channel_cwt, (void *)&ch, NULL, |