31 #define SAMPLE_FORMAT float
33 #define ctype AVComplexFloat
36 #define SAMPLE_FORMAT double
38 #define ctype AVComplexDouble
42 #define fn3(a,b) a##_##b
43 #define fn2(a,b) fn3(a,b)
44 #define fn(a) fn2(a, SAMPLE_FORMAT)
49 ftype *mag, *phase, *delay,
min = FLT_MAX,
max = FLT_MIN;
50 ftype min_delay = FLT_MAX, max_delay = FLT_MIN;
51 int prev_ymag = -1, prev_yphase = -1, prev_ydelay = -1;
55 memset(
out->data[0], 0,
s->h *
out->linesize[0]);
60 if (!mag || !phase || !delay)
64 for (
i = 0;
i <
s->w;
i++) {
66 double w =
i *
M_PI / (
s->w - 1);
67 double div, real_num = 0., imag_num = 0., real = 0., imag = 0.;
69 for (x = 0; x <
s->nb_taps; x++) {
70 real += cos(-x *
w) *
src[x];
71 imag += sin(-x *
w) *
src[x];
72 real_num += cos(-x *
w) *
src[x] * x;
73 imag_num += sin(-x *
w) *
src[x] * x;
76 mag[
i] =
hypot(real, imag);
77 phase[
i] = atan2(imag, real);
78 div = real * real + imag * imag;
79 delay[
i] = (real_num * real + imag_num * imag) / div;
82 min_delay =
fminf(min_delay, delay[
i]);
83 max_delay =
fmaxf(max_delay, delay[
i]);
86 for (
i = 0;
i <
s->w;
i++) {
87 int ymag = mag[
i] /
max * (
s->h - 1);
88 int ydelay = (delay[
i] - min_delay) / (max_delay - min_delay) * (
s->h - 1);
89 int yphase = (0.5 * (1. + phase[
i] /
M_PI)) * (
s->h - 1);
91 ymag =
s->h - 1 -
av_clip(ymag, 0,
s->h - 1);
92 yphase =
s->h - 1 -
av_clip(yphase, 0,
s->h - 1);
93 ydelay =
s->h - 1 -
av_clip(ydelay, 0,
s->h - 1);
100 prev_ydelay = ydelay;
107 prev_yphase = yphase;
108 prev_ydelay = ydelay;
111 if (
s->w > 400 &&
s->h > 100) {
116 drawtext(
out, 2, 12,
"Min Magnitude:", 0xDDDDDDDD);
121 snprintf(text,
sizeof(text),
"%.2f", max_delay);
125 snprintf(text,
sizeof(text),
"%.2f", min_delay);
137 for (
int ch = 0; ch <
ctx->inputs[1 +
s->selir]->ch_layout.nb_channels; ch++) {
138 ftype *time = (
ftype *)
s->ir[
s->selir]->extended_data[!
s->one2many * ch];
141 for (
int i =
FFMAX(1,
s->length *
s->nb_taps);
i <
s->nb_taps;
i++)
156 const int remaining =
s->nb_taps - toffset;
160 for (
int n = 0; n <
size; n++)
161 coeff[coffset + n].
re = time[toffset + n];
167 memset(blockin, 0,
sizeof(*blockin) * seg->
fft_length);
168 memcpy(blockin, time + toffset,
size *
sizeof(*blockin));
170 seg->
tx_fn(seg->
tx[0], blockout, blockin,
sizeof(
ftype));
172 for (
int n = 0; n < seg->
part_size + 1; n++) {
173 coeff[coffset + n].re = blockout[2 * n];
174 coeff[coffset + n].im = blockout[2 * n + 1];
201 for (ch = 0; ch <
ctx->inputs[1 +
s->selir]->ch_layout.nb_channels; ch++) {
202 ftype *time = (
ftype *)
s->ir[
s->selir]->extended_data[!
s->one2many * ch];
204 for (
int i = 0;
i < cur_nb_taps;
i++)
207 s->gain =
ctx->inputs[1 +
s->selir]->ch_layout.nb_channels /
power;
210 for (ch = 0; ch <
ctx->inputs[1 +
s->selir]->ch_layout.nb_channels; ch++) {
211 ftype *time = (
ftype *)
s->ir[
s->selir]->extended_data[!
s->one2many * ch];
213 for (
int i = 0;
i < cur_nb_taps;
i++)
216 s->gain =
ctx->inputs[1 +
s->selir]->ch_layout.nb_channels /
power;
219 for (ch = 0; ch <
ctx->inputs[1 +
s->selir]->ch_layout.nb_channels; ch++) {
220 ftype *time = (
ftype *)
s->ir[
s->selir]->extended_data[!
s->one2many * ch];
222 for (
int i = 0;
i < cur_nb_taps;
i++)
231 s->gain =
FFMIN(
s->gain *
s->ir_gain, 1.);
235 for (
int ch = 0; ch <
ctx->inputs[1 +
s->selir]->ch_layout.nb_channels; ch++) {
236 ftype *time = (
ftype *)
s->ir[
s->selir]->extended_data[!
s->one2many * ch];
239 s->fdsp->vector_fmul_scalar(time, time,
s->gain,
FFALIGN(cur_nb_taps, 4));
241 s->fdsp->vector_dmul_scalar(time, time,
s->gain,
FFALIGN(cur_nb_taps, 8));
250 for (
int n = 0; n <
len; n++)
251 for (
int m = 0; m <= n; m++)
252 out[n] += ir[m].
re * in[n - m];
257 if ((nb_samples & 15) == 0 && nb_samples >= 16) {
259 s->fdsp->vector_fmac_scalar(dst,
src, 1.
f, nb_samples);
261 s->fdsp->vector_dmac_scalar(dst,
src, 1.0, nb_samples);
264 for (
int n = 0; n < nb_samples; n++)
274 const int nb_samples =
FFMIN(
s->min_part_size,
out->nb_samples -
offset);
284 if (
s->min_part_size >= 8) {
292 for (n = 0; n < nb_samples; n++)
325 memmove(
src,
src +
s->min_part_size, (seg->
input_size -
s->min_part_size) *
sizeof(*src));
327 for (n = 0; n < nb_samples; n++) {
333 memset(sumin, 0,
sizeof(*sumin) * seg->
fft_length);
340 seg->
tx_fn(seg->
tx[ch], blockout, blockin,
sizeof(
ftype));
365 memcpy(dst, buf, seg->
part_size *
sizeof(*dst));
372 memmove(
src,
src +
s->min_part_size, (seg->
input_size -
s->min_part_size) *
sizeof(*src));
377 if (
s->min_part_size >= 8) {
379 s->fdsp->vector_fmul_scalar(ptr, ptr,
s->wet_gain,
FFALIGN(nb_samples, 4));
381 s->fdsp->vector_dmul_scalar(ptr, ptr,
s->wet_gain,
FFALIGN(nb_samples, 8));
385 for (n = 0; n < nb_samples; n++)
386 ptr[n] *=
s->wet_gain;