FFmpeg  4.4.9
af_sofalizer.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * sofalizer.c : SOFAlizer filter for virtual binaural acoustics
3  *****************************************************************************
4  * Copyright (C) 2013-2015 Andreas Fuchs, Wolfgang Hrauda,
5  * Acoustics Research Institute (ARI), Vienna, Austria
6  *
7  * Authors: Andreas Fuchs <andi.fuchs.mail@gmail.com>
8  * Wolfgang Hrauda <wolfgang.hrauda@gmx.at>
9  *
10  * SOFAlizer project coordinator at ARI, main developer of SOFA:
11  * Piotr Majdak <piotr@majdak.at>
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation; either version 2.1 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26  *****************************************************************************/
27 
28 #include <math.h>
29 #include <mysofa.h>
30 
31 #include "libavcodec/avfft.h"
32 #include "libavutil/avstring.h"
34 #include "libavutil/float_dsp.h"
35 #include "libavutil/intmath.h"
36 #include "libavutil/opt.h"
37 #include "avfilter.h"
38 #include "filters.h"
39 #include "internal.h"
40 #include "audio.h"
41 
42 #define TIME_DOMAIN 0
43 #define FREQUENCY_DOMAIN 1
44 
45 typedef struct MySofa { /* contains data of one SOFA file */
46  struct MYSOFA_HRTF *hrtf;
47  struct MYSOFA_LOOKUP *lookup;
48  struct MYSOFA_NEIGHBORHOOD *neighborhood;
49  int ir_samples; /* length of one impulse response (IR) */
50  int n_samples; /* ir_samples to next power of 2 */
51  float *lir, *rir; /* IRs (time-domain) */
52  float *fir;
53  int max_delay;
54 } MySofa;
55 
56 typedef struct VirtualSpeaker {
58  float azim;
59  float elev;
61 
62 typedef struct SOFAlizerContext {
63  const AVClass *class;
64 
65  char *filename; /* name of SOFA file */
66  MySofa sofa; /* contains data of the SOFA file */
67 
68  int sample_rate; /* sample rate from SOFA file */
69  float *speaker_azim; /* azimuth of the virtual loudspeakers */
70  float *speaker_elev; /* elevation of the virtual loudspeakers */
71  char *speakers_pos; /* custom positions of the virtual loudspeakers */
72  float lfe_gain; /* initial gain for the LFE channel */
73  float gain_lfe; /* gain applied to LFE channel */
74  int lfe_channel; /* LFE channel position in channel layout */
75 
76  int n_conv; /* number of channels to convolute */
77 
78  /* buffer variables (for convolution) */
79  float *ringbuffer[2]; /* buffers input samples, length of one buffer: */
80  /* no. input ch. (incl. LFE) x buffer_length */
81  int write[2]; /* current write position to ringbuffer */
82  int buffer_length; /* is: longest IR plus max. delay in all SOFA files */
83  /* then choose next power of 2 */
84  int n_fft; /* number of samples in one FFT block */
86 
87  /* netCDF variables */
88  int *delay[2]; /* broadband delay for each channel/IR to be convolved */
89 
90  float *data_ir[2]; /* IRs for all channels to be convolved */
91  /* (this excludes the LFE) */
92  float *temp_src[2];
93  FFTComplex *temp_fft[2]; /* Array to hold FFT values */
94  FFTComplex *temp_afft[2]; /* Array to accumulate FFT values prior to IFFT */
95 
96  /* control variables */
97  float gain; /* filter gain (in dB) */
98  float rotation; /* rotation of virtual loudspeakers (in degrees) */
99  float elevation; /* elevation of virtual loudspeakers (in deg.) */
100  float radius; /* distance virtual loudspeakers to listener (in metres) */
101  int type; /* processing type */
102  int framesize; /* size of buffer */
103  int normalize; /* should all IRs be normalized upon import ? */
104  int interpolate; /* should wanted IRs be interpolated from neighbors ? */
105  int minphase; /* should all IRs be minphased upon import ? */
106  float anglestep; /* neighbor search angle step, in agles */
107  float radstep; /* neighbor search radius step, in meters */
108 
110 
111  FFTContext *fft[2], *ifft[2];
113 
116 
117 static int close_sofa(struct MySofa *sofa)
118 {
119  if (sofa->neighborhood)
120  mysofa_neighborhood_free(sofa->neighborhood);
121  sofa->neighborhood = NULL;
122  if (sofa->lookup)
123  mysofa_lookup_free(sofa->lookup);
124  sofa->lookup = NULL;
125  if (sofa->hrtf)
126  mysofa_free(sofa->hrtf);
127  sofa->hrtf = NULL;
128  av_freep(&sofa->fir);
129 
130  return 0;
131 }
132 
133 static int preload_sofa(AVFilterContext *ctx, char *filename, int *samplingrate)
134 {
135  struct SOFAlizerContext *s = ctx->priv;
136  struct MYSOFA_HRTF *mysofa;
137  char *license;
138  int ret;
139 
140  mysofa = mysofa_load(filename, &ret);
141  s->sofa.hrtf = mysofa;
142  if (ret || !mysofa) {
143  av_log(ctx, AV_LOG_ERROR, "Can't find SOFA-file '%s'\n", filename);
144  return AVERROR(EINVAL);
145  }
146 
147  ret = mysofa_check(mysofa);
148  if (ret != MYSOFA_OK) {
149  av_log(ctx, AV_LOG_ERROR, "Selected SOFA file is invalid. Please select valid SOFA file.\n");
150  return ret;
151  }
152 
153  if (!mysofa->N || !mysofa->M || mysofa->DataIR.elements / mysofa->M / mysofa->R < mysofa->N ||
154  (mysofa->DataDelay.elements != mysofa->R && mysofa->DataDelay.elements / mysofa->R < mysofa->M)) {
155  av_log(ctx, AV_LOG_ERROR, "Selected SOFA file has inconsistent dimensions.\n");
156  return AVERROR_INVALIDDATA;
157  }
158 
159  if (s->normalize)
160  mysofa_loudness(s->sofa.hrtf);
161 
162  if (s->minphase)
163  mysofa_minphase(s->sofa.hrtf, 0.01f);
164 
165  mysofa_tocartesian(s->sofa.hrtf);
166 
167  s->sofa.lookup = mysofa_lookup_init(s->sofa.hrtf);
168  if (s->sofa.lookup == NULL)
169  return AVERROR(EINVAL);
170 
171  if (s->interpolate)
172  s->sofa.neighborhood = mysofa_neighborhood_init_withstepdefine(s->sofa.hrtf,
173  s->sofa.lookup,
174  s->anglestep,
175  s->radstep);
176 
177  s->sofa.fir = av_calloc(s->sofa.hrtf->N * s->sofa.hrtf->R, sizeof(*s->sofa.fir));
178  if (!s->sofa.fir)
179  return AVERROR(ENOMEM);
180 
181  if (mysofa->DataSamplingRate.elements != 1)
182  return AVERROR(EINVAL);
183  av_log(ctx, AV_LOG_DEBUG, "Original IR length: %d.\n", mysofa->N);
184  *samplingrate = mysofa->DataSamplingRate.values[0];
185  license = mysofa_getAttribute(mysofa->attributes, (char *)"License");
186  if (license)
187  av_log(ctx, AV_LOG_INFO, "SOFA license: %s\n", license);
188 
189  return 0;
190 }
191 
192 static int parse_channel_name(AVFilterContext *ctx, char **arg, int *rchannel)
193 {
194  int len, i, channel_id = 0;
195  int64_t layout, layout0;
196  char buf[8] = {0};
197 
198  /* try to parse a channel name, e.g. "FL" */
199  if (av_sscanf(*arg, "%7[A-Z]%n", buf, &len)) {
200  layout0 = layout = av_get_channel_layout(buf);
201  /* channel_id <- first set bit in layout */
202  for (i = 32; i > 0; i >>= 1) {
203  if (layout >= 1LL << i) {
204  channel_id += i;
205  layout >>= i;
206  }
207  }
208  /* reject layouts that are not a single channel */
209  if (channel_id >= 64 || layout0 != 1LL << channel_id) {
210  av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", buf);
211  return AVERROR(EINVAL);
212  }
213  *rchannel = channel_id;
214  *arg += len;
215  return 0;
216  } else if (av_sscanf(*arg, "%d%n", &channel_id, &len) == 1) {
217  if (channel_id < 0 || channel_id >= 64) {
218  av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%d\' as channel number.\n", channel_id);
219  return AVERROR(EINVAL);
220  }
221  *rchannel = channel_id;
222  *arg += len;
223  return 0;
224  }
225  return AVERROR(EINVAL);
226 }
227 
228 static void parse_speaker_pos(AVFilterContext *ctx, int64_t in_channel_layout)
229 {
230  SOFAlizerContext *s = ctx->priv;
231  char *arg, *tokenizer, *p, *args = av_strdup(s->speakers_pos);
232 
233  if (!args)
234  return;
235  p = args;
236 
237  while ((arg = av_strtok(p, "|", &tokenizer))) {
238  float azim, elev;
239  int out_ch_id;
240 
241  p = NULL;
242  if (parse_channel_name(ctx, &arg, &out_ch_id)) {
243  continue;
244  }
245  if (av_sscanf(arg, "%f %f", &azim, &elev) == 2) {
246  s->vspkrpos[out_ch_id].set = 1;
247  s->vspkrpos[out_ch_id].azim = azim;
248  s->vspkrpos[out_ch_id].elev = elev;
249  } else if (av_sscanf(arg, "%f", &azim) == 1) {
250  s->vspkrpos[out_ch_id].set = 1;
251  s->vspkrpos[out_ch_id].azim = azim;
252  s->vspkrpos[out_ch_id].elev = 0;
253  }
254  }
255 
256  av_free(args);
257 }
258 
260  float *speaker_azim, float *speaker_elev)
261 {
262  struct SOFAlizerContext *s = ctx->priv;
263  uint64_t channels_layout = ctx->inputs[0]->channel_layout;
264  float azim[64] = { 0 };
265  float elev[64] = { 0 };
266  int m, ch, n_conv = ctx->inputs[0]->channels; /* get no. input channels */
267 
268  if (n_conv < 0 || n_conv > 64)
269  return AVERROR(EINVAL);
270 
271  s->lfe_channel = -1;
272 
273  if (s->speakers_pos)
274  parse_speaker_pos(ctx, channels_layout);
275 
276  /* set speaker positions according to input channel configuration: */
277  for (m = 0, ch = 0; ch < n_conv && m < 64; m++) {
278  uint64_t mask = channels_layout & (1ULL << m);
279 
280  switch (mask) {
281  case AV_CH_FRONT_LEFT: azim[ch] = 30; break;
282  case AV_CH_FRONT_RIGHT: azim[ch] = 330; break;
283  case AV_CH_FRONT_CENTER: azim[ch] = 0; break;
284  case AV_CH_LOW_FREQUENCY:
285  case AV_CH_LOW_FREQUENCY_2: s->lfe_channel = ch; break;
286  case AV_CH_BACK_LEFT: azim[ch] = 150; break;
287  case AV_CH_BACK_RIGHT: azim[ch] = 210; break;
288  case AV_CH_BACK_CENTER: azim[ch] = 180; break;
289  case AV_CH_SIDE_LEFT: azim[ch] = 90; break;
290  case AV_CH_SIDE_RIGHT: azim[ch] = 270; break;
291  case AV_CH_FRONT_LEFT_OF_CENTER: azim[ch] = 15; break;
292  case AV_CH_FRONT_RIGHT_OF_CENTER: azim[ch] = 345; break;
293  case AV_CH_TOP_CENTER: azim[ch] = 0;
294  elev[ch] = 90; break;
295  case AV_CH_TOP_FRONT_LEFT: azim[ch] = 30;
296  elev[ch] = 45; break;
297  case AV_CH_TOP_FRONT_CENTER: azim[ch] = 0;
298  elev[ch] = 45; break;
299  case AV_CH_TOP_FRONT_RIGHT: azim[ch] = 330;
300  elev[ch] = 45; break;
301  case AV_CH_TOP_BACK_LEFT: azim[ch] = 150;
302  elev[ch] = 45; break;
303  case AV_CH_TOP_BACK_RIGHT: azim[ch] = 210;
304  elev[ch] = 45; break;
305  case AV_CH_TOP_BACK_CENTER: azim[ch] = 180;
306  elev[ch] = 45; break;
307  case AV_CH_WIDE_LEFT: azim[ch] = 90; break;
308  case AV_CH_WIDE_RIGHT: azim[ch] = 270; break;
309  case AV_CH_SURROUND_DIRECT_LEFT: azim[ch] = 90; break;
310  case AV_CH_SURROUND_DIRECT_RIGHT: azim[ch] = 270; break;
311  case AV_CH_STEREO_LEFT: azim[ch] = 90; break;
312  case AV_CH_STEREO_RIGHT: azim[ch] = 270; break;
313  case 0: break;
314  default:
315  return AVERROR(EINVAL);
316  }
317 
318  if (s->vspkrpos[m].set) {
319  azim[ch] = s->vspkrpos[m].azim;
320  elev[ch] = s->vspkrpos[m].elev;
321  }
322 
323  if (mask)
324  ch++;
325  }
326 
327  memcpy(speaker_azim, azim, n_conv * sizeof(float));
328  memcpy(speaker_elev, elev, n_conv * sizeof(float));
329 
330  return 0;
331 
332 }
333 
334 typedef struct ThreadData {
335  AVFrame *in, *out;
336  int *write;
337  int **delay;
338  float **ir;
339  int *n_clippings;
340  float **ringbuffer;
341  float **temp_src;
344 } ThreadData;
345 
346 static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
347 {
348  SOFAlizerContext *s = ctx->priv;
349  ThreadData *td = arg;
350  AVFrame *in = td->in, *out = td->out;
351  int offset = jobnr;
352  int *write = &td->write[jobnr];
353  const int *const delay = td->delay[jobnr];
354  const float *const ir = td->ir[jobnr];
355  int *n_clippings = &td->n_clippings[jobnr];
356  float *ringbuffer = td->ringbuffer[jobnr];
357  float *temp_src = td->temp_src[jobnr];
358  const int ir_samples = s->sofa.ir_samples; /* length of one IR */
359  const int n_samples = s->sofa.n_samples;
360  const int planar = in->format == AV_SAMPLE_FMT_FLTP;
361  const int mult = 1 + !planar;
362  const float *src = (const float *)in->extended_data[0]; /* get pointer to audio input buffer */
363  float *dst = (float *)out->extended_data[jobnr * planar]; /* get pointer to audio output buffer */
364  const int in_channels = s->n_conv; /* number of input channels */
365  /* ring buffer length is: longest IR plus max. delay -> next power of 2 */
366  const int buffer_length = s->buffer_length;
367  /* -1 for AND instead of MODULO (applied to powers of 2): */
368  const uint32_t modulo = (uint32_t)buffer_length - 1;
369  float *buffer[64]; /* holds ringbuffer for each input channel */
370  int wr = *write;
371  int read;
372  int i, l;
373 
374  if (!planar)
375  dst += offset;
376 
377  for (l = 0; l < in_channels; l++) {
378  /* get starting address of ringbuffer for each input channel */
379  buffer[l] = ringbuffer + l * buffer_length;
380  }
381 
382  for (i = 0; i < in->nb_samples; i++) {
383  const float *temp_ir = ir; /* using same set of IRs for each sample */
384 
385  dst[0] = 0;
386  if (planar) {
387  for (l = 0; l < in_channels; l++) {
388  const float *srcp = (const float *)in->extended_data[l];
389 
390  /* write current input sample to ringbuffer (for each channel) */
391  buffer[l][wr] = srcp[i];
392  }
393  } else {
394  for (l = 0; l < in_channels; l++) {
395  /* write current input sample to ringbuffer (for each channel) */
396  buffer[l][wr] = src[l];
397  }
398  }
399 
400  /* loop goes through all channels to be convolved */
401  for (l = 0; l < in_channels; l++) {
402  const float *const bptr = buffer[l];
403 
404  if (l == s->lfe_channel) {
405  /* LFE is an input channel but requires no convolution */
406  /* apply gain to LFE signal and add to output buffer */
407  dst[0] += *(buffer[s->lfe_channel] + wr) * s->gain_lfe;
408  temp_ir += n_samples;
409  continue;
410  }
411 
412  /* current read position in ringbuffer: input sample write position
413  * - delay for l-th ch. + diff. betw. IR length and buffer length
414  * (mod buffer length) */
415  read = (wr - delay[l] - (ir_samples - 1) + buffer_length) & modulo;
416 
417  if (read + ir_samples < buffer_length) {
418  memmove(temp_src, bptr + read, ir_samples * sizeof(*temp_src));
419  } else {
420  int len = FFMIN(n_samples - (read % ir_samples), buffer_length - read);
421 
422  memmove(temp_src, bptr + read, len * sizeof(*temp_src));
423  memmove(temp_src + len, bptr, (n_samples - len) * sizeof(*temp_src));
424  }
425 
426  /* multiply signal and IR, and add up the results */
427  dst[0] += s->fdsp->scalarproduct_float(temp_ir, temp_src, FFALIGN(ir_samples, 32));
428  temp_ir += n_samples;
429  }
430 
431  /* clippings counter */
432  if (fabsf(dst[0]) > 1)
433  n_clippings[0]++;
434 
435  /* move output buffer pointer by +2 to get to next sample of processed channel: */
436  dst += mult;
437  src += in_channels;
438  wr = (wr + 1) & modulo; /* update ringbuffer write position */
439  }
440 
441  *write = wr; /* remember write position in ringbuffer for next call */
442 
443  return 0;
444 }
445 
446 static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
447 {
448  SOFAlizerContext *s = ctx->priv;
449  ThreadData *td = arg;
450  AVFrame *in = td->in, *out = td->out;
451  int offset = jobnr;
452  int *write = &td->write[jobnr];
453  FFTComplex *hrtf = s->data_hrtf[jobnr]; /* get pointers to current HRTF data */
454  int *n_clippings = &td->n_clippings[jobnr];
455  float *ringbuffer = td->ringbuffer[jobnr];
456  const int ir_samples = s->sofa.ir_samples; /* length of one IR */
457  const int planar = in->format == AV_SAMPLE_FMT_FLTP;
458  const int mult = 1 + !planar;
459  float *dst = (float *)out->extended_data[jobnr * planar]; /* get pointer to audio output buffer */
460  const int in_channels = s->n_conv; /* number of input channels */
461  /* ring buffer length is: longest IR plus max. delay -> next power of 2 */
462  const int buffer_length = s->buffer_length;
463  /* -1 for AND instead of MODULO (applied to powers of 2): */
464  const uint32_t modulo = (uint32_t)buffer_length - 1;
465  FFTComplex *fft_in = s->temp_fft[jobnr]; /* temporary array for FFT input/output data */
466  FFTComplex *fft_acc = s->temp_afft[jobnr];
467  FFTContext *ifft = s->ifft[jobnr];
468  FFTContext *fft = s->fft[jobnr];
469  const int n_conv = s->n_conv;
470  const int n_fft = s->n_fft;
471  const float fft_scale = 1.0f / s->n_fft;
472  FFTComplex *hrtf_offset;
473  int wr = *write;
474  int n_read;
475  int i, j;
476 
477  if (!planar)
478  dst += offset;
479 
480  /* find minimum between number of samples and output buffer length:
481  * (important, if one IR is longer than the output buffer) */
482  n_read = FFMIN(ir_samples, in->nb_samples);
483  for (j = 0; j < n_read; j++) {
484  /* initialize output buf with saved signal from overflow buf */
485  dst[mult * j] = ringbuffer[wr];
486  ringbuffer[wr] = 0.0f; /* re-set read samples to zero */
487  /* update ringbuffer read/write position */
488  wr = (wr + 1) & modulo;
489  }
490 
491  /* initialize rest of output buffer with 0 */
492  for (j = n_read; j < in->nb_samples; j++) {
493  dst[mult * j] = 0;
494  }
495 
496  /* fill FFT accumulation with 0 */
497  memset(fft_acc, 0, sizeof(FFTComplex) * n_fft);
498 
499  for (i = 0; i < n_conv; i++) {
500  const float *src = (const float *)in->extended_data[i * planar]; /* get pointer to audio input buffer */
501 
502  if (i == s->lfe_channel) { /* LFE */
503  if (in->format == AV_SAMPLE_FMT_FLT) {
504  for (j = 0; j < in->nb_samples; j++) {
505  /* apply gain to LFE signal and add to output buffer */
506  dst[2 * j] += src[i + j * in_channels] * s->gain_lfe;
507  }
508  } else {
509  for (j = 0; j < in->nb_samples; j++) {
510  /* apply gain to LFE signal and add to output buffer */
511  dst[j] += src[j] * s->gain_lfe;
512  }
513  }
514  continue;
515  }
516 
517  /* outer loop: go through all input channels to be convolved */
518  offset = i * n_fft; /* no. samples already processed */
519  hrtf_offset = hrtf + offset;
520 
521  /* fill FFT input with 0 (we want to zero-pad) */
522  memset(fft_in, 0, sizeof(FFTComplex) * n_fft);
523 
524  if (in->format == AV_SAMPLE_FMT_FLT) {
525  for (j = 0; j < in->nb_samples; j++) {
526  /* prepare input for FFT */
527  /* write all samples of current input channel to FFT input array */
528  fft_in[j].re = src[j * in_channels + i];
529  }
530  } else {
531  for (j = 0; j < in->nb_samples; j++) {
532  /* prepare input for FFT */
533  /* write all samples of current input channel to FFT input array */
534  fft_in[j].re = src[j];
535  }
536  }
537 
538  /* transform input signal of current channel to frequency domain */
539  av_fft_permute(fft, fft_in);
540  av_fft_calc(fft, fft_in);
541  for (j = 0; j < n_fft; j++) {
542  const FFTComplex *hcomplex = hrtf_offset + j;
543  const float re = fft_in[j].re;
544  const float im = fft_in[j].im;
545 
546  /* complex multiplication of input signal and HRTFs */
547  /* output channel (real): */
548  fft_acc[j].re += re * hcomplex->re - im * hcomplex->im;
549  /* output channel (imag): */
550  fft_acc[j].im += re * hcomplex->im + im * hcomplex->re;
551  }
552  }
553 
554  /* transform output signal of current channel back to time domain */
555  av_fft_permute(ifft, fft_acc);
556  av_fft_calc(ifft, fft_acc);
557 
558  for (j = 0; j < in->nb_samples; j++) {
559  /* write output signal of current channel to output buffer */
560  dst[mult * j] += fft_acc[j].re * fft_scale;
561  }
562 
563  for (j = 0; j < ir_samples - 1; j++) { /* overflow length is IR length - 1 */
564  /* write the rest of output signal to overflow buffer */
565  int write_pos = (wr + j) & modulo;
566 
567  *(ringbuffer + write_pos) += fft_acc[in->nb_samples + j].re * fft_scale;
568  }
569 
570  /* go through all samples of current output buffer: count clippings */
571  for (i = 0; i < out->nb_samples; i++) {
572  /* clippings counter */
573  if (fabsf(dst[i * mult]) > 1) { /* if current output sample > 1 */
574  n_clippings[0]++;
575  }
576  }
577 
578  /* remember read/write position in ringbuffer for next call */
579  *write = wr;
580 
581  return 0;
582 }
583 
584 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
585 {
586  AVFilterContext *ctx = inlink->dst;
587  SOFAlizerContext *s = ctx->priv;
588  AVFilterLink *outlink = ctx->outputs[0];
589  int n_clippings[2] = { 0 };
590  ThreadData td;
591  AVFrame *out;
592 
593  out = ff_get_audio_buffer(outlink, in->nb_samples);
594  if (!out) {
595  av_frame_free(&in);
596  return AVERROR(ENOMEM);
597  }
599 
600  td.in = in; td.out = out; td.write = s->write;
601  td.delay = s->delay; td.ir = s->data_ir; td.n_clippings = n_clippings;
602  td.ringbuffer = s->ringbuffer; td.temp_src = s->temp_src;
603  td.temp_fft = s->temp_fft;
604  td.temp_afft = s->temp_afft;
605 
606  if (s->type == TIME_DOMAIN) {
607  ctx->internal->execute(ctx, sofalizer_convolute, &td, NULL, 2);
608  } else if (s->type == FREQUENCY_DOMAIN) {
609  ctx->internal->execute(ctx, sofalizer_fast_convolute, &td, NULL, 2);
610  }
611  emms_c();
612 
613  /* display error message if clipping occurred */
614  if (n_clippings[0] + n_clippings[1] > 0) {
615  av_log(ctx, AV_LOG_WARNING, "%d of %d samples clipped. Please reduce gain.\n",
616  n_clippings[0] + n_clippings[1], out->nb_samples * 2);
617  }
618 
619  av_frame_free(&in);
620  return ff_filter_frame(outlink, out);
621 }
622 
624 {
625  AVFilterLink *inlink = ctx->inputs[0];
626  AVFilterLink *outlink = ctx->outputs[0];
627  SOFAlizerContext *s = ctx->priv;
628  AVFrame *in;
629  int ret;
630 
631  FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
632 
633  if (s->nb_samples)
634  ret = ff_inlink_consume_samples(inlink, s->nb_samples, s->nb_samples, &in);
635  else
636  ret = ff_inlink_consume_frame(inlink, &in);
637  if (ret < 0)
638  return ret;
639  if (ret > 0)
640  return filter_frame(inlink, in);
641 
642  FF_FILTER_FORWARD_STATUS(inlink, outlink);
643  FF_FILTER_FORWARD_WANTED(outlink, inlink);
644 
645  return FFERROR_NOT_READY;
646 }
647 
649 {
650  struct SOFAlizerContext *s = ctx->priv;
653  int ret, sample_rates[] = { 48000, -1 };
654  static const enum AVSampleFormat sample_fmts[] = {
657  };
658 
660  if (!formats)
661  return AVERROR(ENOMEM);
663  if (ret)
664  return ret;
665 
667  if (!layouts)
668  return AVERROR(ENOMEM);
669 
670  ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->outcfg.channel_layouts);
671  if (ret)
672  return ret;
673 
674  layouts = NULL;
676  if (ret)
677  return ret;
678 
679  ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts);
680  if (ret)
681  return ret;
682 
683  sample_rates[0] = s->sample_rate;
685  if (!formats)
686  return AVERROR(ENOMEM);
688 }
689 
690 static int getfilter_float(AVFilterContext *ctx, float x, float y, float z,
691  float *left, float *right,
692  float *delay_left, float *delay_right)
693 {
694  struct SOFAlizerContext *s = ctx->priv;
695  float c[3], delays[2];
696  float *fl, *fr;
697  int nearest;
698  int *neighbors;
699  float *res;
700 
701  c[0] = x, c[1] = y, c[2] = z;
702  nearest = mysofa_lookup(s->sofa.lookup, c);
703  if (nearest < 0)
704  return AVERROR(EINVAL);
705 
706  if (s->interpolate) {
707  neighbors = mysofa_neighborhood(s->sofa.neighborhood, nearest);
708  res = mysofa_interpolate(s->sofa.hrtf, c,
709  nearest, neighbors,
710  s->sofa.fir, delays);
711  } else {
712  if (s->sofa.hrtf->DataDelay.elements > s->sofa.hrtf->R) {
713  delays[0] = s->sofa.hrtf->DataDelay.values[nearest * s->sofa.hrtf->R];
714  delays[1] = s->sofa.hrtf->DataDelay.values[nearest * s->sofa.hrtf->R + 1];
715  } else {
716  delays[0] = s->sofa.hrtf->DataDelay.values[0];
717  delays[1] = s->sofa.hrtf->DataDelay.values[1];
718  }
719  res = s->sofa.hrtf->DataIR.values + nearest * s->sofa.hrtf->N * s->sofa.hrtf->R;
720  }
721 
722  *delay_left = delays[0];
723  *delay_right = delays[1];
724 
725  fl = res;
726  fr = res + s->sofa.hrtf->N;
727 
728  memcpy(left, fl, sizeof(float) * s->sofa.hrtf->N);
729  memcpy(right, fr, sizeof(float) * s->sofa.hrtf->N);
730 
731  return 0;
732 }
733 
734 static int load_data(AVFilterContext *ctx, int azim, int elev, float radius, int sample_rate)
735 {
736  struct SOFAlizerContext *s = ctx->priv;
737  int n_samples;
738  int ir_samples;
739  int n_conv = s->n_conv; /* no. channels to convolve */
740  int n_fft;
741  float delay_l; /* broadband delay for each IR */
742  float delay_r;
743  int nb_input_channels = ctx->inputs[0]->channels; /* no. input channels */
744  float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10); /* gain - 3dB/channel */
745  FFTComplex *data_hrtf_l = NULL;
746  FFTComplex *data_hrtf_r = NULL;
747  FFTComplex *fft_in_l = NULL;
748  FFTComplex *fft_in_r = NULL;
749  float *data_ir_l = NULL;
750  float *data_ir_r = NULL;
751  int offset = 0; /* used for faster pointer arithmetics in for-loop */
752  int i, j, azim_orig = azim, elev_orig = elev;
753  int ret = 0;
754  int n_current;
755  int n_max = 0;
756 
757  av_log(ctx, AV_LOG_DEBUG, "IR length: %d.\n", s->sofa.hrtf->N);
758  s->sofa.ir_samples = s->sofa.hrtf->N;
759  s->sofa.n_samples = FFMAX(32, 1 << (32 - ff_clz(s->sofa.ir_samples)));
760 
761  n_samples = s->sofa.n_samples;
762  ir_samples = s->sofa.ir_samples;
763 
764  if (s->type == TIME_DOMAIN) {
765  s->data_ir[0] = av_calloc(n_samples, sizeof(float) * s->n_conv);
766  s->data_ir[1] = av_calloc(n_samples, sizeof(float) * s->n_conv);
767 
768  if (!s->data_ir[0] || !s->data_ir[1]) {
769  ret = AVERROR(ENOMEM);
770  goto fail;
771  }
772  }
773 
774  s->delay[0] = av_calloc(s->n_conv, sizeof(int));
775  s->delay[1] = av_calloc(s->n_conv, sizeof(int));
776 
777  if (!s->delay[0] || !s->delay[1]) {
778  ret = AVERROR(ENOMEM);
779  goto fail;
780  }
781 
782  /* get temporary IR for L and R channel */
783  data_ir_l = av_calloc(n_conv * n_samples, sizeof(*data_ir_l));
784  data_ir_r = av_calloc(n_conv * n_samples, sizeof(*data_ir_r));
785  if (!data_ir_r || !data_ir_l) {
786  ret = AVERROR(ENOMEM);
787  goto fail;
788  }
789 
790  if (s->type == TIME_DOMAIN) {
791  s->temp_src[0] = av_calloc(n_samples, sizeof(float));
792  s->temp_src[1] = av_calloc(n_samples, sizeof(float));
793  if (!s->temp_src[0] || !s->temp_src[1]) {
794  ret = AVERROR(ENOMEM);
795  goto fail;
796  }
797  }
798 
799  s->speaker_azim = av_calloc(s->n_conv, sizeof(*s->speaker_azim));
800  s->speaker_elev = av_calloc(s->n_conv, sizeof(*s->speaker_elev));
801  if (!s->speaker_azim || !s->speaker_elev) {
802  ret = AVERROR(ENOMEM);
803  goto fail;
804  }
805 
806  /* get speaker positions */
807  if ((ret = get_speaker_pos(ctx, s->speaker_azim, s->speaker_elev)) < 0) {
808  av_log(ctx, AV_LOG_ERROR, "Couldn't get speaker positions. Input channel configuration not supported.\n");
809  goto fail;
810  }
811 
812  for (i = 0; i < s->n_conv; i++) {
813  float coordinates[3];
814 
815  /* load and store IRs and corresponding delays */
816  azim = (int)(s->speaker_azim[i] + azim_orig) % 360;
817  elev = (int)(s->speaker_elev[i] + elev_orig) % 90;
818 
819  coordinates[0] = azim;
820  coordinates[1] = elev;
821  coordinates[2] = radius;
822 
823  mysofa_s2c(coordinates);
824 
825  /* get id of IR closest to desired position */
826  ret = getfilter_float(ctx, coordinates[0], coordinates[1], coordinates[2],
827  data_ir_l + n_samples * i,
828  data_ir_r + n_samples * i,
829  &delay_l, &delay_r);
830  if (ret < 0)
831  goto fail;
832 
833  s->delay[0][i] = delay_l * sample_rate;
834  s->delay[1][i] = delay_r * sample_rate;
835 
836  s->sofa.max_delay = FFMAX3(s->sofa.max_delay, s->delay[0][i], s->delay[1][i]);
837  }
838 
839  /* get size of ringbuffer (longest IR plus max. delay) */
840  /* then choose next power of 2 for performance optimization */
841  n_current = n_samples + s->sofa.max_delay;
842  /* length of longest IR plus max. delay */
843  n_max = FFMAX(n_max, n_current);
844 
845  /* buffer length is longest IR plus max. delay -> next power of 2
846  (32 - count leading zeros gives required exponent) */
847  s->buffer_length = 1 << (32 - ff_clz(n_max));
848  s->n_fft = n_fft = 1 << (32 - ff_clz(n_max + s->framesize));
849 
850  if (s->type == FREQUENCY_DOMAIN) {
851  av_fft_end(s->fft[0]);
852  av_fft_end(s->fft[1]);
853  s->fft[0] = av_fft_init(av_log2(s->n_fft), 0);
854  s->fft[1] = av_fft_init(av_log2(s->n_fft), 0);
855  av_fft_end(s->ifft[0]);
856  av_fft_end(s->ifft[1]);
857  s->ifft[0] = av_fft_init(av_log2(s->n_fft), 1);
858  s->ifft[1] = av_fft_init(av_log2(s->n_fft), 1);
859 
860  if (!s->fft[0] || !s->fft[1] || !s->ifft[0] || !s->ifft[1]) {
861  av_log(ctx, AV_LOG_ERROR, "Unable to create FFT contexts of size %d.\n", s->n_fft);
862  ret = AVERROR(ENOMEM);
863  goto fail;
864  }
865  }
866 
867  if (s->type == TIME_DOMAIN) {
868  s->ringbuffer[0] = av_calloc(s->buffer_length, sizeof(float) * nb_input_channels);
869  s->ringbuffer[1] = av_calloc(s->buffer_length, sizeof(float) * nb_input_channels);
870  } else if (s->type == FREQUENCY_DOMAIN) {
871  /* get temporary HRTF memory for L and R channel */
872  data_hrtf_l = av_malloc_array(n_fft, sizeof(*data_hrtf_l) * n_conv);
873  data_hrtf_r = av_malloc_array(n_fft, sizeof(*data_hrtf_r) * n_conv);
874  if (!data_hrtf_r || !data_hrtf_l) {
875  ret = AVERROR(ENOMEM);
876  goto fail;
877  }
878 
879  s->ringbuffer[0] = av_calloc(s->buffer_length, sizeof(float));
880  s->ringbuffer[1] = av_calloc(s->buffer_length, sizeof(float));
881  s->temp_fft[0] = av_malloc_array(s->n_fft, sizeof(FFTComplex));
882  s->temp_fft[1] = av_malloc_array(s->n_fft, sizeof(FFTComplex));
883  s->temp_afft[0] = av_malloc_array(s->n_fft, sizeof(FFTComplex));
884  s->temp_afft[1] = av_malloc_array(s->n_fft, sizeof(FFTComplex));
885  if (!s->temp_fft[0] || !s->temp_fft[1] ||
886  !s->temp_afft[0] || !s->temp_afft[1]) {
887  ret = AVERROR(ENOMEM);
888  goto fail;
889  }
890  }
891 
892  if (!s->ringbuffer[0] || !s->ringbuffer[1]) {
893  ret = AVERROR(ENOMEM);
894  goto fail;
895  }
896 
897  if (s->type == FREQUENCY_DOMAIN) {
898  fft_in_l = av_calloc(n_fft, sizeof(*fft_in_l));
899  fft_in_r = av_calloc(n_fft, sizeof(*fft_in_r));
900  if (!fft_in_l || !fft_in_r) {
901  ret = AVERROR(ENOMEM);
902  goto fail;
903  }
904  }
905 
906  for (i = 0; i < s->n_conv; i++) {
907  float *lir, *rir;
908 
909  offset = i * n_samples; /* no. samples already written */
910 
911  lir = data_ir_l + offset;
912  rir = data_ir_r + offset;
913 
914  if (s->type == TIME_DOMAIN) {
915  for (j = 0; j < ir_samples; j++) {
916  /* load reversed IRs of the specified source position
917  * sample-by-sample for left and right ear; and apply gain */
918  s->data_ir[0][offset + j] = lir[ir_samples - 1 - j] * gain_lin;
919  s->data_ir[1][offset + j] = rir[ir_samples - 1 - j] * gain_lin;
920  }
921  } else if (s->type == FREQUENCY_DOMAIN) {
922  memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l));
923  memset(fft_in_r, 0, n_fft * sizeof(*fft_in_r));
924 
925  offset = i * n_fft; /* no. samples already written */
926  for (j = 0; j < ir_samples; j++) {
927  /* load non-reversed IRs of the specified source position
928  * sample-by-sample and apply gain,
929  * L channel is loaded to real part, R channel to imag part,
930  * IRs are shifted by L and R delay */
931  fft_in_l[s->delay[0][i] + j].re = lir[j] * gain_lin;
932  fft_in_r[s->delay[1][i] + j].re = rir[j] * gain_lin;
933  }
934 
935  /* actually transform to frequency domain (IRs -> HRTFs) */
936  av_fft_permute(s->fft[0], fft_in_l);
937  av_fft_calc(s->fft[0], fft_in_l);
938  memcpy(data_hrtf_l + offset, fft_in_l, n_fft * sizeof(*fft_in_l));
939  av_fft_permute(s->fft[0], fft_in_r);
940  av_fft_calc(s->fft[0], fft_in_r);
941  memcpy(data_hrtf_r + offset, fft_in_r, n_fft * sizeof(*fft_in_r));
942  }
943  }
944 
945  if (s->type == FREQUENCY_DOMAIN) {
946  s->data_hrtf[0] = av_malloc_array(n_fft * s->n_conv, sizeof(FFTComplex));
947  s->data_hrtf[1] = av_malloc_array(n_fft * s->n_conv, sizeof(FFTComplex));
948  if (!s->data_hrtf[0] || !s->data_hrtf[1]) {
949  ret = AVERROR(ENOMEM);
950  goto fail;
951  }
952 
953  memcpy(s->data_hrtf[0], data_hrtf_l, /* copy HRTF data to */
954  sizeof(FFTComplex) * n_conv * n_fft); /* filter struct */
955  memcpy(s->data_hrtf[1], data_hrtf_r,
956  sizeof(FFTComplex) * n_conv * n_fft);
957  }
958 
959 fail:
960  av_freep(&data_hrtf_l); /* free temporary HRTF memory */
961  av_freep(&data_hrtf_r);
962 
963  av_freep(&data_ir_l); /* free temprary IR memory */
964  av_freep(&data_ir_r);
965 
966  av_freep(&fft_in_l); /* free temporary FFT memory */
967  av_freep(&fft_in_r);
968 
969  return ret;
970 }
971 
973 {
974  SOFAlizerContext *s = ctx->priv;
975  int ret;
976 
977  if (!s->filename) {
978  av_log(ctx, AV_LOG_ERROR, "Valid SOFA filename must be set.\n");
979  return AVERROR(EINVAL);
980  }
981 
982  /* preload SOFA file, */
983  ret = preload_sofa(ctx, s->filename, &s->sample_rate);
984  if (ret) {
985  /* file loading error */
986  av_log(ctx, AV_LOG_ERROR, "Error while loading SOFA file: '%s'\n", s->filename);
987  } else { /* no file loading error, resampling not required */
988  av_log(ctx, AV_LOG_DEBUG, "File '%s' loaded.\n", s->filename);
989  }
990 
991  if (ret) {
992  av_log(ctx, AV_LOG_ERROR, "No valid SOFA file could be loaded. Please specify valid SOFA file.\n");
993  return ret;
994  }
995 
996  s->fdsp = avpriv_float_dsp_alloc(0);
997  if (!s->fdsp)
998  return AVERROR(ENOMEM);
999 
1000  return 0;
1001 }
1002 
1003 static int config_input(AVFilterLink *inlink)
1004 {
1005  AVFilterContext *ctx = inlink->dst;
1006  SOFAlizerContext *s = ctx->priv;
1007  int ret;
1008 
1009  if (s->type == FREQUENCY_DOMAIN)
1010  s->nb_samples = s->framesize;
1011 
1012  /* gain -3 dB per channel */
1013  s->gain_lfe = expf((s->gain - 3 * inlink->channels + s->lfe_gain) / 20 * M_LN10);
1014 
1015  s->n_conv = inlink->channels;
1016 
1017  /* load IRs to data_ir[0] and data_ir[1] for required directions */
1018  if ((ret = load_data(ctx, s->rotation, s->elevation, s->radius, inlink->sample_rate)) < 0)
1019  return ret;
1020 
1021  av_log(ctx, AV_LOG_DEBUG, "Samplerate: %d Channels to convolute: %d, Length of ringbuffer: %d x %d\n",
1022  inlink->sample_rate, s->n_conv, inlink->channels, s->buffer_length);
1023 
1024  return 0;
1025 }
1026 
1028 {
1029  SOFAlizerContext *s = ctx->priv;
1030 
1031  close_sofa(&s->sofa);
1032  av_fft_end(s->ifft[0]);
1033  av_fft_end(s->ifft[1]);
1034  av_fft_end(s->fft[0]);
1035  av_fft_end(s->fft[1]);
1036  s->ifft[0] = NULL;
1037  s->ifft[1] = NULL;
1038  s->fft[0] = NULL;
1039  s->fft[1] = NULL;
1040  av_freep(&s->delay[0]);
1041  av_freep(&s->delay[1]);
1042  av_freep(&s->data_ir[0]);
1043  av_freep(&s->data_ir[1]);
1044  av_freep(&s->ringbuffer[0]);
1045  av_freep(&s->ringbuffer[1]);
1046  av_freep(&s->speaker_azim);
1047  av_freep(&s->speaker_elev);
1048  av_freep(&s->temp_src[0]);
1049  av_freep(&s->temp_src[1]);
1050  av_freep(&s->temp_afft[0]);
1051  av_freep(&s->temp_afft[1]);
1052  av_freep(&s->temp_fft[0]);
1053  av_freep(&s->temp_fft[1]);
1054  av_freep(&s->data_hrtf[0]);
1055  av_freep(&s->data_hrtf[1]);
1056  av_freep(&s->fdsp);
1057 }
1058 
1059 #define OFFSET(x) offsetof(SOFAlizerContext, x)
1060 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1061 
1062 static const AVOption sofalizer_options[] = {
1063  { "sofa", "sofa filename", OFFSET(filename), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
1064  { "gain", "set gain in dB", OFFSET(gain), AV_OPT_TYPE_FLOAT, {.dbl=0}, -20, 40, .flags = FLAGS },
1065  { "rotation", "set rotation" , OFFSET(rotation), AV_OPT_TYPE_FLOAT, {.dbl=0}, -360, 360, .flags = FLAGS },
1066  { "elevation", "set elevation", OFFSET(elevation), AV_OPT_TYPE_FLOAT, {.dbl=0}, -90, 90, .flags = FLAGS },
1067  { "radius", "set radius", OFFSET(radius), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 5, .flags = FLAGS },
1068  { "type", "set processing", OFFSET(type), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, .flags = FLAGS, "type" },
1069  { "time", "time domain", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, .flags = FLAGS, "type" },
1070  { "freq", "frequency domain", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, .flags = FLAGS, "type" },
1071  { "speakers", "set speaker custom positions", OFFSET(speakers_pos), AV_OPT_TYPE_STRING, {.str=0}, 0, 0, .flags = FLAGS },
1072  { "lfegain", "set lfe gain", OFFSET(lfe_gain), AV_OPT_TYPE_FLOAT, {.dbl=0}, -20,40, .flags = FLAGS },
1073  { "framesize", "set frame size", OFFSET(framesize), AV_OPT_TYPE_INT, {.i64=1024},1024,96000, .flags = FLAGS },
1074  { "normalize", "normalize IRs", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, .flags = FLAGS },
1075  { "interpolate","interpolate IRs from neighbors", OFFSET(interpolate),AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags = FLAGS },
1076  { "minphase", "minphase IRs", OFFSET(minphase), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags = FLAGS },
1077  { "anglestep", "set neighbor search angle step", OFFSET(anglestep), AV_OPT_TYPE_FLOAT, {.dbl=.5}, 0.01, 10, .flags = FLAGS },
1078  { "radstep", "set neighbor search radius step", OFFSET(radstep), AV_OPT_TYPE_FLOAT, {.dbl=.01}, 0.01, 1, .flags = FLAGS },
1079  { NULL }
1080 };
1081 
1083 
1084 static const AVFilterPad inputs[] = {
1085  {
1086  .name = "default",
1087  .type = AVMEDIA_TYPE_AUDIO,
1088  .config_props = config_input,
1089  },
1090  { NULL }
1091 };
1092 
1093 static const AVFilterPad outputs[] = {
1094  {
1095  .name = "default",
1096  .type = AVMEDIA_TYPE_AUDIO,
1097  },
1098  { NULL }
1099 };
1100 
1102  .name = "sofalizer",
1103  .description = NULL_IF_CONFIG_SMALL("SOFAlizer (Spatially Oriented Format for Acoustics)."),
1104  .priv_size = sizeof(SOFAlizerContext),
1105  .priv_class = &sofalizer_class,
1106  .init = init,
1107  .activate = activate,
1108  .uninit = uninit,
1110  .inputs = inputs,
1111  .outputs = outputs,
1113 };
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:925
static int preload_sofa(AVFilterContext *ctx, char *filename, int *samplingrate)
Definition: af_sofalizer.c:133
static int close_sofa(struct MySofa *sofa)
Definition: af_sofalizer.c:117
static int load_data(AVFilterContext *ctx, int azim, int elev, float radius, int sample_rate)
Definition: af_sofalizer.c:734
static int query_formats(AVFilterContext *ctx)
Definition: af_sofalizer.c:648
static int config_input(AVFilterLink *inlink)
static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: af_sofalizer.c:346
AVFilter ff_af_sofalizer
#define FLAGS
#define TIME_DOMAIN
Definition: af_sofalizer.c:42
static const AVFilterPad inputs[]
static const AVOption sofalizer_options[]
static const AVFilterPad outputs[]
static void parse_speaker_pos(AVFilterContext *ctx, int64_t in_channel_layout)
Definition: af_sofalizer.c:228
static int get_speaker_pos(AVFilterContext *ctx, float *speaker_azim, float *speaker_elev)
Definition: af_sofalizer.c:259
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_sofalizer.c:584
static int activate(AVFilterContext *ctx)
Definition: af_sofalizer.c:623
static av_cold int init(AVFilterContext *ctx)
Definition: af_sofalizer.c:972
static av_cold void uninit(AVFilterContext *ctx)
static int getfilter_float(AVFilterContext *ctx, float x, float y, float z, float *left, float *right, float *delay_left, float *delay_right)
Definition: af_sofalizer.c:690
#define FREQUENCY_DOMAIN
Definition: af_sofalizer.c:43
#define OFFSET(x)
AVFILTER_DEFINE_CLASS(sofalizer)
static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: af_sofalizer.c:446
static int parse_channel_name(AVFilterContext *ctx, char **arg, int *rchannel)
Definition: af_sofalizer.c:192
#define av_cold
Definition: attributes.h:88
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:86
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
uint8_t
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1<< 16)) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(UINT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&HAVE_MMX) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out->ch+ch,(const uint8_t **) in->ch+ch, off *(out-> planar
Definition: audioconvert.c:56
FFT functions.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1099
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
Definition: avfilter.c:1513
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1494
Main libavfilter public API header.
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
uint64_t layout
audio channel layout utility functions
#define fail()
Definition: checkasm.h:133
#define FFMAX3(a, b, c)
Definition: common.h:104
#define FFMIN(a, b)
Definition: common.h:105
#define FFMAX(a, b)
Definition: common.h:103
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
sample_rates
int
sample_rate
float im
Definition: fft.c:82
float re
Definition: fft.c:82
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
Definition: filters.h:265
#define FF_FILTER_FORWARD_STATUS(inlink, outlink)
Acknowledge the status on an input link and forward it to an output link.
Definition: filters.h:237
#define FFERROR_NOT_READY
Filters implementation helper functions.
Definition: filters.h:34
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition: filters.h:210
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:338
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:587
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:427
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:575
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:461
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
#define AV_CH_LAYOUT_STEREO
#define AV_CH_SIDE_LEFT
#define AV_CH_SURROUND_DIRECT_RIGHT
#define AV_CH_WIDE_LEFT
#define AV_CH_WIDE_RIGHT
#define AV_CH_TOP_FRONT_LEFT
#define AV_CH_FRONT_RIGHT
#define AV_CH_TOP_BACK_CENTER
#define AV_CH_FRONT_RIGHT_OF_CENTER
#define AV_CH_BACK_CENTER
#define AV_CH_TOP_FRONT_CENTER
#define AV_CH_FRONT_LEFT_OF_CENTER
#define AV_CH_LOW_FREQUENCY_2
#define AV_CH_BACK_RIGHT
#define AV_CH_FRONT_CENTER
#define AV_CH_TOP_BACK_RIGHT
#define AV_CH_TOP_CENTER
#define AV_CH_SIDE_RIGHT
#define AV_CH_BACK_LEFT
#define AV_CH_TOP_BACK_LEFT
#define AV_CH_LOW_FREQUENCY
#define AV_CH_STEREO_RIGHT
See AV_CH_STEREO_LEFT.
#define AV_CH_TOP_FRONT_RIGHT
#define AV_CH_STEREO_LEFT
Stereo downmix.
#define AV_CH_FRONT_LEFT
#define AV_CH_SURROUND_DIRECT_LEFT
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
Definition: avfft.c:38
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
Definition: avfft.c:43
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
Definition: avfft.c:28
av_cold void av_fft_end(FFTContext *s)
Definition: avfft.c:48
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
#define ff_clz
Definition: intmath.h:142
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:253
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:63
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
Definition: avstring.c:186
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
Definition: avsscanf.c:962
cl_device_type type
int i
Definition: input.c:407
#define av_log2
Definition: intmath.h:83
static int16_t mult(Float11 *f1, Float11 *f2)
Definition: g726.c:55
const char * arg
Definition: jacosubdec.c:67
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
#define emms_c()
Definition: internal.h:54
#define expf(x)
Definition: libm.h:283
static const uint16_t mask[17]
Definition: lzw.c:38
#define FFALIGN(x, a)
Definition: macros.h:48
#define M_LN10
Definition: mathematics.h:43
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVOptions.
#define td
Definition: regdef.h:70
static char buffer[20]
Definition: seek.c:32
formats
Definition: signature.h:48
Describe the class of an AVClass context structure.
Definition: log.h:67
A list of supported channel layouts.
Definition: formats.h:86
An instance of a filter.
Definition: avfilter.h:341
A list of supported formats for one end of a filter link.
Definition: formats.h:65
A filter pad used for either input or output.
Definition: internal.h:54
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1699
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
AVOption.
Definition: opt.h:248
FFTSample re
Definition: avfft.h:38
FFTSample im
Definition: avfft.h:38
Definition: fft.h:83
int n_samples
Definition: af_sofalizer.c:50
float * lir
Definition: af_sofalizer.c:51
struct MYSOFA_NEIGHBORHOOD * neighborhood
Definition: af_sofalizer.c:48
int max_delay
Definition: af_sofalizer.c:53
struct MYSOFA_HRTF * hrtf
Definition: af_sofalizer.c:46
int ir_samples
Definition: af_sofalizer.c:49
struct MYSOFA_LOOKUP * lookup
Definition: af_sofalizer.c:47
float * rir
Definition: af_sofalizer.c:51
float * fir
Definition: af_sofalizer.c:52
float * ringbuffer[2]
Definition: af_sofalizer.c:79
FFTComplex * temp_afft[2]
Definition: af_sofalizer.c:94
float * temp_src[2]
Definition: af_sofalizer.c:92
float * speaker_elev
Definition: af_sofalizer.c:70
FFTContext * ifft[2]
Definition: af_sofalizer.c:111
FFTContext * fft[2]
Definition: af_sofalizer.c:111
VirtualSpeaker vspkrpos[64]
Definition: af_sofalizer.c:109
float * speaker_azim
Definition: af_sofalizer.c:69
FFTComplex * temp_fft[2]
Definition: af_sofalizer.c:93
float * data_ir[2]
Definition: af_sofalizer.c:90
FFTComplex * data_hrtf[2]
Definition: af_sofalizer.c:112
AVFloatDSPContext * fdsp
Definition: af_sofalizer.c:114
Used for passing data between threads.
Definition: dsddec.c:67
FFTComplex ** temp_fft
Definition: af_headphone.c:133
int * n_clippings
Definition: af_headphone.c:130
int ** delay
Definition: af_sofalizer.c:337
AVFrame * out
Definition: af_adeclick.c:505
float ** ir
Definition: af_headphone.c:129
AVFrame * in
Definition: af_adenorm.c:223
float ** temp_src
Definition: af_headphone.c:132
FFTComplex ** temp_afft
Definition: af_headphone.c:134
float ** ringbuffer
Definition: af_headphone.c:131
#define av_free(p)
#define av_malloc_array(a, b)
#define av_freep(p)
#define av_log(a,...)
#define src
Definition: vp8dsp.c:255
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
static void interpolate(float *out, float v1, float v2, int size)
Definition: twinvq.c:84
if(ret< 0)
Definition: vf_mcdeint.c:282
static const uint8_t offset[127][2]
Definition: vf_spp.c:107
int len
static double c[64]