34 #define SAMPLE_FORMAT float
37 #define ctype AVComplexFloat
39 #define TX_TYPE AV_TX_FLOAT_RDFT
41 #define SAMPLE_FORMAT double
44 #define ctype AVComplexDouble
46 #define TX_TYPE AV_TX_DOUBLE_RDFT
49 #define fn3(a,b) a##_##b
50 #define fn2(a,b) fn3(a,b)
51 #define fn(a) fn2(a, SAMPLE_FORMAT)
56 ftype *mag, *phase, *delay,
min = FLT_MAX,
max = FLT_MIN;
57 ftype min_delay = FLT_MAX, max_delay = FLT_MIN;
58 int prev_ymag = -1, prev_yphase = -1, prev_ydelay = -1;
62 for (
int y = 0; y <
s->h; y++)
63 memset(
out->data[0] + y *
out->linesize[0], 0,
s->w * 4);
68 if (!mag || !phase || !delay)
72 for (
i = 0;
i <
s->w;
i++) {
74 double w =
i *
M_PI / (
s->w - 1);
75 double div, real_num = 0., imag_num = 0., real = 0., imag = 0.;
77 for (x = 0; x <
s->nb_taps[
s->selir]; x++) {
78 real += cos(-x *
w) *
src[x];
79 imag += sin(-x *
w) *
src[x];
80 real_num += cos(-x *
w) *
src[x] * x;
81 imag_num += sin(-x *
w) *
src[x] * x;
84 mag[
i] =
hypot(real, imag);
85 phase[
i] = atan2(imag, real);
86 div = real * real + imag * imag;
87 delay[
i] = (real_num * real + imag_num * imag) / div;
90 min_delay =
fminf(min_delay, delay[
i]);
91 max_delay =
fmaxf(max_delay, delay[
i]);
94 for (
i = 0;
i <
s->w;
i++) {
95 int ymag = mag[
i] /
max * (
s->h - 1);
96 int ydelay = (delay[
i] - min_delay) / (max_delay - min_delay) * (
s->h - 1);
97 int yphase = (0.5 * (1. + phase[
i] /
M_PI)) * (
s->h - 1);
99 ymag =
s->h - 1 -
av_clip(ymag, 0,
s->h - 1);
100 yphase =
s->h - 1 -
av_clip(yphase, 0,
s->h - 1);
101 ydelay =
s->h - 1 -
av_clip(ydelay, 0,
s->h - 1);
106 prev_yphase = yphase;
108 prev_ydelay = ydelay;
115 prev_yphase = yphase;
116 prev_ydelay = ydelay;
119 if (
s->w > 400 &&
s->h > 100) {
124 drawtext(
out, 2, 12,
"Min Magnitude:", 0xDDDDDDDD);
129 snprintf(text,
sizeof(text),
"%.2f", max_delay);
133 snprintf(text,
sizeof(text),
"%.2f", min_delay);
144 int cur_nb_taps,
int ch,
157 for (
int i = 0;
i < cur_nb_taps;
i++)
166 for (
int i = 0;
i < cur_nb_taps;
i++)
175 for (
int i = 0;
i < cur_nb_taps;
i++)
176 sum += time[
i] * time[
i];
177 ch_gain = 1. /
SQRT(sum);
211 for (
int i = 0;
i <
size / 2 + 1;
i++)
215 for (
int i = 0;
i <
size / 2 + 1;
i++)
216 sum +=
HYPOT(outc[
i * 2], outc[
i * 2 + 1]);
220 ch_gain = 1. /
power;
232 if (ch_gain != 1. ||
s->ir_gain != 1.) {
233 ftype gain = ch_gain *
s->ir_gain;
237 s->fdsp->vector_fmul_scalar(time, time, gain,
FFALIGN(cur_nb_taps, 4));
239 s->fdsp->vector_dmul_scalar(time, time, gain,
FFALIGN(cur_nb_taps, 8));
249 const int coffset = coeff_partition * seg->coeff_size;
250 const int nb_taps =
s->nb_taps[selir];
251 ftype *time = (
ftype *)
s->norm_ir[selir]->extended_data[ch];
252 ftype *tempin = (
ftype *)seg->tempin->extended_data[ch];
253 ftype *tempout = (
ftype *)seg->tempout->extended_data[ch];
255 const int remaining = nb_taps - (seg->input_offset + coeff_partition * seg->part_size);
256 const int size = remaining >= seg->part_size ? seg->part_size : remaining;
258 memset(tempin +
size, 0,
sizeof(*tempin) * (seg->block_size -
size));
259 memcpy(tempin, time + seg->input_offset + coeff_partition * seg->part_size,
260 size *
sizeof(*tempin));
261 seg->ctx_fn(seg->ctx[ch], tempout, tempin,
sizeof(*tempin));
262 memcpy(
coeff + coffset, tempout, seg->coeff_size *
sizeof(*
coeff));
276 if ((nb_samples & 15) == 0 && nb_samples >= 8) {
278 s->fdsp->vector_fmac_scalar(dst,
src, 1.
f, nb_samples);
280 s->fdsp->vector_dmac_scalar(dst,
src, 1.0, nb_samples);
283 for (
int n = 0; n < nb_samples; n++)
293 const int min_part_size =
s->min_part_size;
294 const int nb_samples =
FFMIN(min_part_size,
out->nb_samples -
offset);
295 const int nb_segments =
s->nb_segments;
296 const float dry_gain =
s->dry_gain;
297 const int selir =
s->selir;
314 if (min_part_size >= 8) {
316 s->fdsp->vector_fmul_scalar(
src + input_offset, in, dry_gain,
FFALIGN(nb_samples, 4));
318 s->fdsp->vector_dmul_scalar(
src + input_offset, in, dry_gain,
FFALIGN(nb_samples, 8));
323 for (
int n = 0; n < nb_samples; n++)
324 src2[n] = in[n] * dry_gain;
327 output_offset[0] += min_part_size;
328 if (output_offset[0] >= part_size) {
329 output_offset[0] = 0;
333 dst += output_offset[0];
338 memset(sumin, 0,
sizeof(*sumin) * seg->
fft_length);
340 if (seg->
loading[ch] < nb_partitions) {
342 for (
int i = 0;
i < nb_partitions;
i++) {
343 const int input_partition = j;
344 const int coeff_partition =
i;
345 const int coffset = coeff_partition * seg->
coeff_size;
354 s->afirdsp.fcmul_add(sumin, blockout, (
const ftype *)
coeff, part_size);
356 s->afirdsp.dcmul_add(sumin, blockout, (
const ftype *)
coeff, part_size);
361 memcpy(dst + part_size, sumout + part_size, part_size *
sizeof(*buf));
362 memset(sumin, 0,
sizeof(*sumin) * seg->
fft_length);
366 memset(tempin + part_size, 0,
sizeof(*tempin) * (seg->
block_size - part_size));
367 memcpy(tempin,
src,
sizeof(*
src) * part_size);
368 seg->
tx_fn(seg->
tx[ch], blockout, tempin,
sizeof(
ftype));
370 if (seg->
loading[ch] < nb_partitions) {
371 const int selir =
s->prev_selir;
374 for (
int i = 0;
i < nb_partitions;
i++) {
375 const int input_partition = j;
376 const int coeff_partition =
i;
377 const int coffset = coeff_partition * seg->
coeff_size;
386 s->afirdsp.fcmul_add(sumin, blockout, (
const ftype *)
coeff, part_size);
388 s->afirdsp.dcmul_add(sumin, blockout, (
const ftype *)
coeff, part_size);
393 memcpy(dst + 2 * part_size, sumout, 2 * part_size *
sizeof(*dst));
394 memset(sumin, 0,
sizeof(*sumin) * seg->
fft_length);
398 for (
int i = 0;
i < nb_partitions;
i++) {
399 const int input_partition = j;
400 const int coeff_partition =
i;
401 const int coffset = coeff_partition * seg->
coeff_size;
410 s->afirdsp.fcmul_add(sumin, blockout, (
const ftype *)
coeff, part_size);
412 s->afirdsp.dcmul_add(sumin, blockout, (
const ftype *)
coeff, part_size);
418 if (seg->
loading[ch] < nb_partitions) {
419 ftype *ptr1 = dst + part_size;
420 ftype *ptr2 = dst + part_size * 2;
421 ftype *ptr3 = dst + part_size * 3;
422 ftype *ptr4 = dst + part_size * 4;
424 memcpy(ptr4, buf,
sizeof(*ptr4) * part_size);
425 for (
int n = 0; n < part_size; n++)
428 if (seg->
loading[ch] < nb_partitions - 1)
429 memcpy(ptr4, ptr3, part_size *
sizeof(*dst));
430 for (
int n = 0; n < part_size; n++)
431 ptr1[n] += sumout[n];
433 if (seg->
loading[ch] == nb_partitions - 1)
434 memcpy(buf, sumout + part_size, part_size *
sizeof(*buf));
436 for (
int i = 0;
i < part_size;
i++) {
439 dst[
i] = ptr1[
i] *
factor + ptr2[
i] * ifactor;
443 memcpy(dst, buf, part_size *
sizeof(*dst));
444 memcpy(buf, sumout + part_size, part_size *
sizeof(*buf));
449 if (part_size != min_part_size)
453 if (seg->
loading[ch] < nb_partitions)
457 if (
s->wet_gain == 1.f)
460 if (min_part_size >= 8) {
462 s->fdsp->vector_fmul_scalar(ptr, ptr,
s->wet_gain,
FFALIGN(nb_samples, 4));
464 s->fdsp->vector_dmul_scalar(ptr, ptr,
s->wet_gain,
FFALIGN(nb_samples, 8));
468 for (
int n = 0; n < nb_samples; n++)
469 ptr[n] *=
s->wet_gain;