You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avfilter/avf_showcwt: improve caching of some arrays
This commit is contained in:
@@ -402,6 +402,7 @@ static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
|||||||
const int count = s->frequency_band_count;
|
const int count = s->frequency_band_count;
|
||||||
const int start = (count * jobnr) / nb_jobs;
|
const int start = (count * jobnr) / nb_jobs;
|
||||||
const int end = (count * (jobnr+1)) / nb_jobs;
|
const int end = (count * (jobnr+1)) / nb_jobs;
|
||||||
|
const int nb_channels = s->nb_channels;
|
||||||
const int ihop_index = s->ihop_index;
|
const int ihop_index = s->ihop_index;
|
||||||
const int ihop_size = s->ihop_size;
|
const int ihop_size = s->ihop_size;
|
||||||
const float rotation = s->rotation;
|
const float rotation = s->rotation;
|
||||||
@@ -414,8 +415,8 @@ static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
|||||||
float Y, U, V;
|
float Y, U, V;
|
||||||
|
|
||||||
for (int y = start; y < end; y++) {
|
for (int y = start; y < end; y++) {
|
||||||
const AVComplexFloat *src = ((const AVComplexFloat *)s->ch_out->extended_data[0]) +
|
const AVComplexFloat *src = ((const AVComplexFloat *)s->ch_out->extended_data[y]) +
|
||||||
y * ihop_size + ihop_index;
|
0 * ihop_size + ihop_index;
|
||||||
|
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case DIRECTION_LR:
|
case DIRECTION_LR:
|
||||||
@@ -471,8 +472,7 @@ static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
|||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
const AVComplexFloat *src2 = ((const AVComplexFloat *)s->ch_out->extended_data[FFMIN(1, s->nb_channels - 1)]) +
|
const AVComplexFloat *src2 = (nb_channels > 1) ? src + ihop_size: src;
|
||||||
y * ihop_size + ihop_index;
|
|
||||||
float z, u, v;
|
float z, u, v;
|
||||||
|
|
||||||
z = hypotf(src[0].re + src2[0].re, src[0].im + src2[0].im);
|
z = hypotf(src[0].re + src2[0].re, src[0].im + src2[0].im);
|
||||||
@@ -511,11 +511,10 @@ static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
|||||||
Y = 0.f;
|
Y = 0.f;
|
||||||
U = V = 0.5f;
|
U = V = 0.5f;
|
||||||
for (int ch = 0; ch < nb_channels; ch++) {
|
for (int ch = 0; ch < nb_channels; ch++) {
|
||||||
const AVComplexFloat *src = ((const AVComplexFloat *)s->ch_out->extended_data[ch]) +
|
const AVComplexFloat *srcn = src + ihop_size * ch;
|
||||||
y * ihop_size + ihop_index;
|
|
||||||
float z;
|
float z;
|
||||||
|
|
||||||
z = hypotf(src[0].re, src[0].im);
|
z = hypotf(srcn[0].re, srcn[0].im);
|
||||||
z = remap_log(z, log_factor);
|
z = remap_log(z, log_factor);
|
||||||
|
|
||||||
Y += z * yf;
|
Y += z * yf;
|
||||||
@@ -591,7 +590,7 @@ static int run_channel_cwt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo
|
|||||||
const int end = (count * (jobnr+1)) / nb_jobs;
|
const int end = (count * (jobnr+1)) / nb_jobs;
|
||||||
|
|
||||||
for (int y = start; y < end; y++) {
|
for (int y = start; y < end; y++) {
|
||||||
AVComplexFloat *chout = ((AVComplexFloat *)s->ch_out->extended_data[ch]) + y * ihop_size;
|
AVComplexFloat *chout = ((AVComplexFloat *)s->ch_out->extended_data[y]) + ch * ihop_size;
|
||||||
AVComplexFloat *over = ((AVComplexFloat *)s->over->extended_data[ch]) + y * ihop_size;
|
AVComplexFloat *over = ((AVComplexFloat *)s->over->extended_data[ch]) + y * ihop_size;
|
||||||
AVComplexFloat *dstx = (AVComplexFloat *)s->dst_x->extended_data[jobnr];
|
AVComplexFloat *dstx = (AVComplexFloat *)s->dst_x->extended_data[jobnr];
|
||||||
AVComplexFloat *srcx = (AVComplexFloat *)s->src_x->extended_data[jobnr];
|
AVComplexFloat *srcx = (AVComplexFloat *)s->src_x->extended_data[jobnr];
|
||||||
@@ -720,7 +719,7 @@ static int compute_kernel(AVFilterContext *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int n = 0; n < size; n++)
|
for (int n = 0; n < size; n++)
|
||||||
index[n] = n % s->output_padding_size;
|
index[n] = n & (s->output_padding_size - 1);
|
||||||
|
|
||||||
av_log(ctx, AV_LOG_DEBUG, "range_min: %d\n", range_min);
|
av_log(ctx, AV_LOG_DEBUG, "range_min: %d\n", range_min);
|
||||||
av_log(ctx, AV_LOG_DEBUG, "range_max: %d\n", range_max);
|
av_log(ctx, AV_LOG_DEBUG, "range_max: %d\n", range_max);
|
||||||
@@ -818,11 +817,11 @@ static int config_output(AVFilterLink *outlink)
|
|||||||
s->src_x = av_frame_alloc();
|
s->src_x = av_frame_alloc();
|
||||||
s->kernel = av_calloc(s->frequency_band_count, sizeof(*s->kernel));
|
s->kernel = av_calloc(s->frequency_band_count, sizeof(*s->kernel));
|
||||||
s->cache = ff_get_audio_buffer(inlink, s->hop_size);
|
s->cache = ff_get_audio_buffer(inlink, s->hop_size);
|
||||||
s->ch_out = ff_get_audio_buffer(inlink, s->frequency_band_count * 2 * s->ihop_size);
|
|
||||||
s->over = ff_get_audio_buffer(inlink, s->frequency_band_count * 2 * s->ihop_size);
|
s->over = ff_get_audio_buffer(inlink, s->frequency_band_count * 2 * s->ihop_size);
|
||||||
s->bh_out = ff_get_audio_buffer(inlink, s->frequency_band_count);
|
s->bh_out = ff_get_audio_buffer(inlink, s->frequency_band_count);
|
||||||
s->ifft_in = av_frame_alloc();
|
s->ifft_in = av_frame_alloc();
|
||||||
s->ifft_out = av_frame_alloc();
|
s->ifft_out = av_frame_alloc();
|
||||||
|
s->ch_out = av_frame_alloc();
|
||||||
s->index = av_calloc(s->input_padding_size, sizeof(*s->index));
|
s->index = av_calloc(s->input_padding_size, sizeof(*s->index));
|
||||||
s->kernel_start = av_calloc(s->frequency_band_count, sizeof(*s->kernel_start));
|
s->kernel_start = av_calloc(s->frequency_band_count, sizeof(*s->kernel_start));
|
||||||
s->kernel_stop = av_calloc(s->frequency_band_count, sizeof(*s->kernel_stop));
|
s->kernel_stop = av_calloc(s->frequency_band_count, sizeof(*s->kernel_stop));
|
||||||
@@ -831,6 +830,13 @@ static int config_output(AVFilterLink *outlink)
|
|||||||
!s->frequency_band || !s->cache || !s->index || !s->bh_out || !s->kernel)
|
!s->frequency_band || !s->cache || !s->index || !s->bh_out || !s->kernel)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
s->ch_out->format = inlink->format;
|
||||||
|
s->ch_out->nb_samples = 2 * s->ihop_size * inlink->ch_layout.nb_channels;
|
||||||
|
s->ch_out->ch_layout.nb_channels = s->frequency_band_count;
|
||||||
|
ret = av_frame_get_buffer(s->ch_out, 0);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
s->ifft_in->format = inlink->format;
|
s->ifft_in->format = inlink->format;
|
||||||
s->ifft_in->nb_samples = s->ifft_in_size * 2;
|
s->ifft_in->nb_samples = s->ifft_in_size * 2;
|
||||||
s->ifft_in->ch_layout.nb_channels = s->nb_threads;
|
s->ifft_in->ch_layout.nb_channels = s->nb_threads;
|
||||||
|
Reference in New Issue
Block a user