diff --git a/libavfilter/avf_showcwt.c b/libavfilter/avf_showcwt.c index 505c66e3ab..3ef8433b61 100644 --- a/libavfilter/avf_showcwt.c +++ b/libavfilter/avf_showcwt.c @@ -85,7 +85,7 @@ typedef struct ShowCWTContext { unsigned *index; int *kernel_start; int *kernel_stop; - AVFrame *cache[2]; + AVFrame *cache; AVFrame *outpicref; AVFrame *fft_in; AVFrame *fft_out; @@ -168,8 +168,7 @@ static av_cold void uninit(AVFilterContext *ctx) av_freep(&s->index); av_frame_free(&s->kernel); - av_frame_free(&s->cache[0]); - av_frame_free(&s->cache[1]); + av_frame_free(&s->cache); av_frame_free(&s->outpicref); av_frame_free(&s->fft_in); av_frame_free(&s->fft_out); @@ -280,32 +279,25 @@ static int run_channel_cwt_prepare(AVFilterContext *ctx, void *arg, int jobnr, i ShowCWTContext *s = ctx->priv; const int hop_size = s->hop_size; AVFrame *fin = arg; - float *cache0 = (float *)s->cache[0]->extended_data[ch]; - float *cache = (float *)s->cache[1]->extended_data[ch]; + AVComplexFloat *cache = (AVComplexFloat *)s->cache->extended_data[ch]; AVComplexFloat *src = (AVComplexFloat *)s->fft_in->extended_data[ch]; AVComplexFloat *dst = (AVComplexFloat *)s->fft_out->extended_data[ch]; if (fin) { - const int offset = s->hop_index; const float *input = (const float *)fin->extended_data[ch]; + const int offset = s->input_padding_size - fin->nb_samples; - memcpy(&cache[offset], input, - fin->nb_samples * sizeof(float)); + memmove(cache, cache + fin->nb_samples, sizeof(*cache) * offset); + for (int n = 0; n < fin->nb_samples; n++) { + cache[offset + n].re = input[n]; + cache[offset + n].im = 0.f; + } } - if (fin == NULL) { - memset(&cache[s->hop_index], 0, - (hop_size - s->hop_index) * sizeof(float)); - } else if (s->hop_index + fin->nb_samples < hop_size) { + if (fin && s->hop_index + fin->nb_samples < hop_size) return 0; - } - for (int n = 0; n < hop_size; n++) { - src[n].re = cache0[n]; - src[n].im = 0.f; - src[n + hop_size].re = cache[n]; - src[n + hop_size].im = 0.f; - } + memcpy(src, cache, sizeof(*src) * s->input_padding_size); s->tx_fn(s->fft[jobnr], dst, src, sizeof(*src)); @@ -630,8 +622,7 @@ static int config_output(AVFilterLink *outlink) s->outpicref = ff_get_video_buffer(outlink, outlink->w, outlink->h); s->fft_in = ff_get_audio_buffer(inlink, s->fft_in_size * 2); s->fft_out = ff_get_audio_buffer(inlink, s->fft_out_size * 2); - s->cache[0] = ff_get_audio_buffer(inlink, s->hop_size); - s->cache[1] = ff_get_audio_buffer(inlink, s->hop_size); + s->cache = ff_get_audio_buffer(inlink, s->fft_in_size * 2); s->ch_out = ff_get_audio_buffer(inlink, s->frequency_band_count * 2 * s->ihop_size); s->ifft_in = av_frame_alloc(); s->ifft_out = av_frame_alloc(); @@ -641,7 +632,7 @@ static int config_output(AVFilterLink *outlink) s->kernel_stop = av_calloc(s->frequency_band_count, sizeof(*s->kernel_stop)); if (!s->outpicref || !s->fft_in || !s->fft_out || !s->ifft_in || !s->ifft_out || !s->kernel_start || !s->kernel_stop || - !s->frequency_band || !s->kernel || !s->cache[0] || !s->cache[1] || !s->index) + !s->frequency_band || !s->kernel || !s->cache || !s->index) return AVERROR(ENOMEM); s->ifft_in->format = inlink->format; @@ -983,10 +974,8 @@ static int activate(AVFilterContext *ctx) } if (s->hop_index >= s->hop_size || s->ihop_index > 0) { - if (s->hop_index) { - FFSWAP(AVFrame *, s->cache[0], s->cache[1]); + if (s->hop_index) s->hop_index = 0; - } for (int ch = 0; ch < s->nb_channels && s->ihop_index == 0; ch++) { ff_filter_execute(ctx, run_channel_cwt, (void *)&ch, NULL,