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