43 #define FREQUENCY_DOMAIN 1
123 mysofa_lookup_free(sofa->
lookup);
126 mysofa_free(sofa->
hrtf);
136 struct MYSOFA_HRTF *mysofa;
140 mysofa = mysofa_load(filename, &ret);
141 s->sofa.hrtf = mysofa;
142 if (ret || !mysofa) {
147 ret = mysofa_check(mysofa);
148 if (ret != MYSOFA_OK) {
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)) {
160 mysofa_loudness(
s->sofa.hrtf);
163 mysofa_minphase(
s->sofa.hrtf, 0.01f);
165 mysofa_tocartesian(
s->sofa.hrtf);
167 s->sofa.lookup = mysofa_lookup_init(
s->sofa.hrtf);
168 if (
s->sofa.lookup ==
NULL)
172 s->sofa.neighborhood = mysofa_neighborhood_init_withstepdefine(
s->sofa.hrtf,
177 s->sofa.fir =
av_calloc(
s->sofa.hrtf->N *
s->sofa.hrtf->R,
sizeof(*
s->sofa.fir));
181 if (mysofa->DataSamplingRate.elements != 1)
184 *samplingrate = mysofa->DataSamplingRate.values[0];
185 license = mysofa_getAttribute(mysofa->attributes, (
char *)
"License");
194 int len,
i, channel_id = 0;
202 for (
i = 32;
i > 0;
i >>= 1) {
209 if (channel_id >= 64 || layout0 != 1LL << channel_id) {
213 *rchannel = channel_id;
217 if (channel_id < 0 || channel_id >= 64) {
221 *rchannel = channel_id;
231 char *
arg, *tokenizer, *p, *args =
av_strdup(
s->speakers_pos);
246 s->vspkrpos[out_ch_id].set = 1;
247 s->vspkrpos[out_ch_id].azim = azim;
248 s->vspkrpos[out_ch_id].elev = elev;
250 s->vspkrpos[out_ch_id].set = 1;
251 s->vspkrpos[out_ch_id].azim = azim;
252 s->vspkrpos[out_ch_id].elev = 0;
260 float *speaker_azim,
float *speaker_elev)
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;
268 if (n_conv < 0 || n_conv > 64)
277 for (m = 0, ch = 0; ch <
n_conv && m < 64; m++) {
278 uint64_t
mask = channels_layout & (1ULL << m);
294 elev[ch] = 90;
break;
296 elev[ch] = 45;
break;
298 elev[ch] = 45;
break;
300 elev[ch] = 45;
break;
302 elev[ch] = 45;
break;
304 elev[ch] = 45;
break;
306 elev[ch] = 45;
break;
318 if (
s->vspkrpos[m].set) {
319 azim[ch] =
s->vspkrpos[m].azim;
320 elev[ch] =
s->vspkrpos[m].elev;
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;
359 const int n_samples =
s->sofa.n_samples;
362 const float *
src = (
const float *)
in->extended_data[0];
363 float *dst = (
float *)
out->extended_data[jobnr *
planar];
364 const int in_channels =
s->n_conv;
366 const int buffer_length =
s->buffer_length;
368 const uint32_t modulo = (uint32_t)buffer_length - 1;
377 for (l = 0; l < in_channels; l++) {
379 buffer[l] = ringbuffer + l * buffer_length;
382 for (
i = 0;
i <
in->nb_samples;
i++) {
383 const float *temp_ir = ir;
387 for (l = 0; l < in_channels; l++) {
388 const float *srcp = (
const float *)
in->extended_data[l];
394 for (l = 0; l < in_channels; l++) {
401 for (l = 0; l < in_channels; l++) {
402 const float *
const bptr =
buffer[l];
404 if (l ==
s->lfe_channel) {
407 dst[0] += *(
buffer[
s->lfe_channel] + wr) *
s->gain_lfe;
408 temp_ir += n_samples;
415 read = (wr - delay[l] - (ir_samples - 1) + buffer_length) & modulo;
417 if (read + ir_samples < buffer_length) {
418 memmove(temp_src, bptr + read, ir_samples *
sizeof(*temp_src));
420 int len =
FFMIN(n_samples - (read % ir_samples), buffer_length - read);
422 memmove(temp_src, bptr + read,
len *
sizeof(*temp_src));
423 memmove(temp_src +
len, bptr, (n_samples -
len) *
sizeof(*temp_src));
427 dst[0] +=
s->fdsp->scalarproduct_float(temp_ir, temp_src,
FFALIGN(ir_samples, 32));
428 temp_ir += n_samples;
432 if (
fabsf(dst[0]) > 1)
438 wr = (wr + 1) & modulo;
452 int *write = &
td->write[jobnr];
454 int *n_clippings = &
td->n_clippings[jobnr];
455 float *ringbuffer =
td->ringbuffer[jobnr];
456 const int ir_samples =
s->sofa.ir_samples;
459 float *dst = (
float *)
out->extended_data[jobnr *
planar];
460 const int in_channels =
s->n_conv;
462 const int buffer_length =
s->buffer_length;
464 const uint32_t modulo = (uint32_t)buffer_length - 1;
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;
482 n_read =
FFMIN(ir_samples,
in->nb_samples);
483 for (j = 0; j < n_read; j++) {
485 dst[
mult * j] = ringbuffer[wr];
486 ringbuffer[wr] = 0.0f;
488 wr = (wr + 1) & modulo;
492 for (j = n_read; j <
in->nb_samples; j++) {
497 memset(fft_acc, 0,
sizeof(
FFTComplex) * n_fft);
499 for (
i = 0;
i < n_conv;
i++) {
500 const float *
src = (
const float *)
in->extended_data[
i *
planar];
502 if (
i ==
s->lfe_channel) {
504 for (j = 0; j <
in->nb_samples; j++) {
506 dst[2 * j] +=
src[
i + j * in_channels] *
s->gain_lfe;
509 for (j = 0; j <
in->nb_samples; j++) {
511 dst[j] +=
src[j] *
s->gain_lfe;
519 hrtf_offset = hrtf +
offset;
522 memset(fft_in, 0,
sizeof(
FFTComplex) * n_fft);
525 for (j = 0; j <
in->nb_samples; j++) {
528 fft_in[j].
re =
src[j * in_channels +
i];
531 for (j = 0; j <
in->nb_samples; j++) {
534 fft_in[j].
re =
src[j];
541 for (j = 0; j < n_fft; j++) {
543 const float re = fft_in[j].
re;
544 const float im = fft_in[j].
im;
548 fft_acc[j].
re +=
re * hcomplex->
re -
im * hcomplex->
im;
550 fft_acc[j].
im +=
re * hcomplex->
im +
im * hcomplex->
re;
558 for (j = 0; j <
in->nb_samples; j++) {
560 dst[
mult * j] += fft_acc[j].
re * fft_scale;
563 for (j = 0; j < ir_samples - 1; j++) {
565 int write_pos = (wr + j) & modulo;
567 *(ringbuffer + write_pos) += fft_acc[
in->nb_samples + j].
re * fft_scale;
571 for (
i = 0;
i <
out->nb_samples;
i++) {
589 int n_clippings[2] = { 0 };
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;
614 if (n_clippings[0] + n_clippings[1] > 0) {
616 n_clippings[0] + n_clippings[1],
out->nb_samples * 2);
691 float *left,
float *right,
692 float *delay_left,
float *delay_right)
695 float c[3], delays[2];
701 c[0] = x,
c[1] = y,
c[2] = z;
702 nearest = mysofa_lookup(
s->sofa.lookup,
c);
706 if (
s->interpolate) {
707 neighbors = mysofa_neighborhood(
s->sofa.neighborhood, nearest);
708 res = mysofa_interpolate(
s->sofa.hrtf,
c,
710 s->sofa.fir, delays);
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];
716 delays[0] =
s->sofa.hrtf->DataDelay.values[0];
717 delays[1] =
s->sofa.hrtf->DataDelay.values[1];
719 res =
s->sofa.hrtf->DataIR.values + nearest *
s->sofa.hrtf->N *
s->sofa.hrtf->R;
722 *delay_left = delays[0];
723 *delay_right = delays[1];
726 fr = res +
s->sofa.hrtf->N;
728 memcpy(left, fl,
sizeof(
float) *
s->sofa.hrtf->N);
729 memcpy(right, fr,
sizeof(
float) *
s->sofa.hrtf->N);
743 int nb_input_channels =
ctx->inputs[0]->channels;
744 float gain_lin =
expf((
s->gain - 3 * nb_input_channels) / 20 *
M_LN10);
749 float *data_ir_l =
NULL;
750 float *data_ir_r =
NULL;
752 int i, j, azim_orig = azim, elev_orig = elev;
758 s->sofa.ir_samples =
s->sofa.hrtf->N;
759 s->sofa.n_samples =
FFMAX(32, 1 << (32 -
ff_clz(
s->sofa.ir_samples)));
761 n_samples =
s->sofa.n_samples;
762 ir_samples =
s->sofa.ir_samples;
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);
768 if (!
s->data_ir[0] || !
s->data_ir[1]) {
777 if (!
s->delay[0] || !
s->delay[1]) {
785 if (!data_ir_r || !data_ir_l) {
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]) {
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) {
808 av_log(
ctx,
AV_LOG_ERROR,
"Couldn't get speaker positions. Input channel configuration not supported.\n");
812 for (
i = 0;
i <
s->n_conv;
i++) {
813 float coordinates[3];
816 azim = (
int)(
s->speaker_azim[
i] + azim_orig) % 360;
817 elev = (
int)(
s->speaker_elev[
i] + elev_orig) % 90;
819 coordinates[0] = azim;
820 coordinates[1] = elev;
823 mysofa_s2c(coordinates);
827 data_ir_l + n_samples *
i,
828 data_ir_r + n_samples *
i,
836 s->sofa.max_delay =
FFMAX3(
s->sofa.max_delay,
s->delay[0][
i],
s->delay[1][
i]);
841 n_current = n_samples +
s->sofa.max_delay;
843 n_max =
FFMAX(n_max, n_current);
847 s->buffer_length = 1 << (32 -
ff_clz(n_max));
860 if (!
s->fft[0] || !
s->fft[1] || !
s->ifft[0] || !
s->ifft[1]) {
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);
874 if (!data_hrtf_r || !data_hrtf_l) {
879 s->ringbuffer[0] =
av_calloc(
s->buffer_length,
sizeof(
float));
880 s->ringbuffer[1] =
av_calloc(
s->buffer_length,
sizeof(
float));
885 if (!
s->temp_fft[0] || !
s->temp_fft[1] ||
886 !
s->temp_afft[0] || !
s->temp_afft[1]) {
892 if (!
s->ringbuffer[0] || !
s->ringbuffer[1]) {
900 if (!fft_in_l || !fft_in_r) {
906 for (
i = 0;
i <
s->n_conv;
i++) {
915 for (j = 0; j < ir_samples; j++) {
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;
922 memset(fft_in_l, 0,
n_fft *
sizeof(*fft_in_l));
923 memset(fft_in_r, 0,
n_fft *
sizeof(*fft_in_r));
926 for (j = 0; j < ir_samples; j++) {
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;
938 memcpy(data_hrtf_l +
offset, fft_in_l,
n_fft *
sizeof(*fft_in_l));
941 memcpy(data_hrtf_r +
offset, fft_in_r,
n_fft *
sizeof(*fft_in_r));
948 if (!
s->data_hrtf[0] || !
s->data_hrtf[1]) {
953 memcpy(
s->data_hrtf[0], data_hrtf_l,
955 memcpy(
s->data_hrtf[1], data_hrtf_r,
1010 s->nb_samples =
s->framesize;
1021 av_log(
ctx,
AV_LOG_DEBUG,
"Samplerate: %d Channels to convolute: %d, Length of ringbuffer: %d x %d\n",
1059 #define OFFSET(x) offsetof(SOFAlizerContext, x)
1060 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1102 .
name =
"sofalizer",
1105 .priv_class = &sofalizer_class,
static enum AVSampleFormat sample_fmts[]
static int preload_sofa(AVFilterContext *ctx, char *filename, int *samplingrate)
static int close_sofa(struct MySofa *sofa)
static int load_data(AVFilterContext *ctx, int azim, int elev, float radius, int sample_rate)
static int query_formats(AVFilterContext *ctx)
static int config_input(AVFilterLink *inlink)
static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
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)
static int get_speaker_pos(AVFilterContext *ctx, float *speaker_azim, float *speaker_elev)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int activate(AVFilterContext *ctx)
static av_cold int init(AVFilterContext *ctx)
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)
AVFILTER_DEFINE_CLASS(sofalizer)
static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int parse_channel_name(AVFilterContext *ctx, char **arg, int *rchannel)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
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 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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
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.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Main libavfilter public API header.
#define flags(name, subs,...)
audio channel layout utility functions
static __device__ float fabsf(float a)
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
#define FF_FILTER_FORWARD_STATUS(inlink, outlink)
Acknowledge the status on an input link and forward it to an output link.
#define FFERROR_NOT_READY
Filters implementation helper functions.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
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_SURROUND_DIRECT_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_FRONT_CENTER
#define AV_CH_TOP_BACK_RIGHT
#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_SURROUND_DIRECT_LEFT
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
av_cold void av_fft_end(FFTContext *s)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
char * av_strdup(const char *s)
Duplicate a string.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_FLTP
float, planar
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().
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
static int16_t mult(Float11 *f1, Float11 *f2)
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const uint16_t mask[17]
enum MovChannelLayoutTag * layouts
Describe the class of an AVClass context structure.
A list of supported channel layouts.
A link between two filters.
int channels
Number of channels.
int sample_rate
samples per second
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
This structure describes decoded (raw) audio or video data.
struct MYSOFA_NEIGHBORHOOD * neighborhood
struct MYSOFA_HRTF * hrtf
struct MYSOFA_LOOKUP * lookup
FFTComplex * temp_afft[2]
VirtualSpeaker vspkrpos[64]
FFTComplex * data_hrtf[2]
Used for passing data between threads.
#define av_malloc_array(a, b)
static void interpolate(float *out, float v1, float v2, int size)
static const uint8_t offset[127][2]