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);
142 if (ret || !mysofa) {
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");
157 mysofa_minphase(s->
sofa.
hrtf, 0.01f);
175 if (mysofa->DataSamplingRate.elements != 1)
178 *samplingrate = mysofa->DataSamplingRate.values[0];
179 license = mysofa_getAttribute(mysofa->attributes, (
char *)
"License");
188 int len,
i, channel_id = 0;
192 if (
av_sscanf(*arg,
"%7[A-Z]%n", buf, &len)) {
195 for (i = 32; i > 0; i >>= 1) {
196 if (layout >= 1LL << i) {
202 if (channel_id >= 64 || layout0 != 1LL << channel_id)
204 *rchannel = channel_id;
220 while ((arg =
av_strtok(p,
"|", &tokenizer))) {
230 if (
av_sscanf(arg,
"%f %f", &azim, &elev) == 2) {
234 }
else if (
av_sscanf(arg,
"%f", &azim) == 1) {
245 float *speaker_azim,
float *speaker_elev)
249 float azim[16] = { 0 };
250 float elev[16] = { 0 };
262 for (m = 0, ch = 0; ch < n_conv && m < 64; m++) {
263 uint64_t
mask = channels_layout & (1ULL << m);
279 elev[ch] = 90;
break;
281 elev[ch] = 45;
break;
283 elev[ch] = 45;
break;
285 elev[ch] = 45;
break;
287 elev[ch] = 45;
break;
289 elev[ch] = 45;
break;
291 elev[ch] = 45;
break;
312 memcpy(speaker_azim, azim, n_conv *
sizeof(
float));
313 memcpy(speaker_elev, elev, n_conv *
sizeof(
float));
337 int *write = &td->
write[jobnr];
338 const int *
const delay = td->
delay[jobnr];
339 const float *
const ir = td->
ir[jobnr];
342 float *temp_src = td->
temp_src[jobnr];
348 float *dst = (
float *)
out->extended_data[jobnr *
planar];
349 const int in_channels = s->
n_conv;
353 const uint32_t modulo = (uint32_t)buffer_length - 1;
362 for (l = 0; l < in_channels; l++) {
364 buffer[l] = ringbuffer + l * buffer_length;
368 const float *temp_ir = ir;
372 for (l = 0; l < in_channels; l++) {
376 buffer[l][wr] = srcp[i];
379 for (l = 0; l < in_channels; l++) {
381 buffer[l][wr] = src[l];
386 for (l = 0; l < in_channels; l++) {
387 const float *
const bptr = buffer[l];
393 temp_ir += n_samples;
400 read = (wr - delay[l] - (ir_samples - 1) + buffer_length) & modulo;
402 if (read + ir_samples < buffer_length) {
403 memmove(temp_src, bptr + read, ir_samples *
sizeof(*temp_src));
405 int len =
FFMIN(n_samples - (read % ir_samples), buffer_length - read);
407 memmove(temp_src, bptr + read, len *
sizeof(*temp_src));
408 memmove(temp_src + len, bptr, (n_samples - len) *
sizeof(*temp_src));
417 if (fabsf(dst[0]) > 1)
423 wr = (wr + 1) & modulo;
437 int *write = &td->
write[jobnr];
444 float *dst = (
float *)
out->extended_data[jobnr * planar];
445 const int in_channels = s->
n_conv;
449 const uint32_t modulo = (uint32_t)buffer_length - 1;
454 const int n_conv = s->
n_conv;
455 const int n_fft = s->
n_fft;
456 const float fft_scale = 1.0f / s->
n_fft;
468 for (j = 0; j < n_read; j++) {
470 dst[mult * j] = ringbuffer[wr];
471 ringbuffer[wr] = 0.0f;
473 wr = (wr + 1) & modulo;
482 memset(fft_acc, 0,
sizeof(
FFTComplex) * n_fft);
484 for (i = 0; i < n_conv; i++) {
491 dst[2 * j] += src[i + j * in_channels] * s->
gain_lfe;
504 hrtf_offset = hrtf +
offset;
507 memset(fft_in, 0,
sizeof(
FFTComplex) * n_fft);
513 fft_in[j].
re = src[j * in_channels +
i];
519 fft_in[j].
re = src[j];
526 for (j = 0; j < n_fft; j++) {
528 const float re = fft_in[j].
re;
529 const float im = fft_in[j].
im;
533 fft_acc[j].
re += re * hcomplex->
re - im * hcomplex->
im;
535 fft_acc[j].
im += re * hcomplex->
im + im * hcomplex->
re;
545 dst[mult * j] += fft_acc[j].
re * fft_scale;
548 for (j = 0; j < ir_samples - 1; j++) {
550 int write_pos = (wr + j) & modulo;
552 *(ringbuffer + write_pos) += fft_acc[in->
nb_samples + j].
re * fft_scale;
556 for (i = 0; i <
out->nb_samples; i++) {
558 if (fabsf(dst[i * mult]) > 1) {
574 int n_clippings[2] = { 0 };
599 if (n_clippings[0] + n_clippings[1] > 0) {
601 n_clippings[0] + n_clippings[1], out->
nb_samples * 2);
676 float *left,
float *right,
677 float *delay_left,
float *delay_right)
680 float c[3], delays[2];
686 c[0] = x, c[1] = y, c[2] = z;
693 res = mysofa_interpolate(s->
sofa.
hrtf, c,
701 delays[0] = s->
sofa.
hrtf->DataDelay.values[0];
702 delays[1] = s->
sofa.
hrtf->DataDelay.values[1];
707 *delay_left = delays[0];
708 *delay_right = delays[1];
713 memcpy(left, fl,
sizeof(
float) * s->
sofa.
hrtf->N);
714 memcpy(right, fr,
sizeof(
float) * s->
sofa.
hrtf->N);
729 float gain_lin =
expf((s->
gain - 3 * nb_input_channels) / 20 *
M_LN10);
734 float *data_ir_l =
NULL;
735 float *data_ir_r =
NULL;
737 int i, j, azim_orig = azim, elev_orig = elev;
768 data_ir_l =
av_calloc(n_conv * n_samples,
sizeof(*data_ir_l));
769 data_ir_r =
av_calloc(n_conv * n_samples,
sizeof(*data_ir_r));
770 if (!data_ir_r || !data_ir_l) {
793 av_log(ctx,
AV_LOG_ERROR,
"Couldn't get speaker positions. Input channel configuration not supported.\n");
797 for (i = 0; i < s->
n_conv; i++) {
798 float coordinates[3];
804 coordinates[0] = azim;
805 coordinates[1] = elev;
808 mysofa_s2c(coordinates);
811 ret =
getfilter_float(ctx, coordinates[0], coordinates[1], coordinates[2],
812 data_ir_l + n_samples * i,
813 data_ir_r + n_samples * i,
828 n_max =
FFMAX(n_max, n_current);
859 if (!data_hrtf_r || !data_hrtf_l) {
883 fft_in_l =
av_calloc(n_fft,
sizeof(*fft_in_l));
884 fft_in_r =
av_calloc(n_fft,
sizeof(*fft_in_r));
885 if (!fft_in_l || !fft_in_r) {
891 for (i = 0; i < s->
n_conv; i++) {
903 s->
data_ir[0][offset + j] = lir[ir_samples - 1 - j] * gain_lin;
904 s->
data_ir[1][offset + j] = rir[ir_samples - 1 - j] * gain_lin;
907 memset(fft_in_l, 0, n_fft *
sizeof(*fft_in_l));
908 memset(fft_in_r, 0, n_fft *
sizeof(*fft_in_r));
916 fft_in_l[s->
delay[0][
i] + j].
re = lir[j] * gain_lin;
917 fft_in_r[s->
delay[1][
i] + j].
re = rir[j] * gain_lin;
923 memcpy(data_hrtf_l + offset, fft_in_l, n_fft *
sizeof(*fft_in_l));
926 memcpy(data_hrtf_r + offset, fft_in_r, n_fft *
sizeof(*fft_in_r));
977 av_log(ctx,
AV_LOG_ERROR,
"No valid SOFA file could be loaded. Please specify valid SOFA file.\n");
1006 av_log(ctx,
AV_LOG_DEBUG,
"Samplerate: %d Channels to convolute: %d, Length of ringbuffer: %d x %d\n",
1044 #define OFFSET(x) offsetof(SOFAlizerContext, x) 1045 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM 1087 .
name =
"sofalizer",
1090 .priv_class = &sofalizer_class,
static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
float(* scalarproduct_float)(const float *v1, const float *v2, int len)
Calculate the scalar product of two vectors of floats.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
FFTComplex * data_hrtf[2]
This structure describes decoded (raw) audio or video data.
#define AV_CH_TOP_FRONT_RIGHT
av_cold void av_fft_end(FFTContext *s)
#define AV_LOG_WARNING
Something somehow does not look correct.
Main libavfilter public API header.
AVFILTER_DEFINE_CLASS(sofalizer)
#define AV_CH_TOP_FRONT_LEFT
#define AV_CH_TOP_FRONT_CENTER
#define AV_CH_LOW_FREQUENCY_2
struct MYSOFA_HRTF * hrtf
#define FFERROR_NOT_READY
Filters implementation helper functions.
FFTComplex * temp_afft[2]
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
#define AV_CH_SURROUND_DIRECT_RIGHT
#define AV_CH_LAYOUT_STEREO
struct AVFilterChannelLayouts * in_channel_layouts
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
static int close_sofa(struct MySofa *sofa)
const char * name
Pad name.
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define AV_CH_TOP_BACK_LEFT
struct MYSOFA_LOOKUP * lookup
#define AV_CH_TOP_BACK_CENTER
#define AV_CH_LOW_FREQUENCY
static void interpolate(float *out, float v1, float v2, int size)
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
A filter pad used for either input or output.
A link between two filters.
#define i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
int sample_rate
samples per second
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
static const uint16_t mask[17]
static int get_speaker_pos(AVFilterContext *ctx, float *speaker_azim, float *speaker_elev)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static int query_formats(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
struct AVFilterChannelLayouts * out_channel_layouts
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
static const uint8_t offset[127][2]
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
#define AV_CH_STEREO_RIGHT
See AV_CH_STEREO_LEFT.
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
static int load_data(AVFilterContext *ctx, int azim, int elev, float radius, int sample_rate)
audio channel layout utility functions
static int16_t mult(Float11 *f1, Float11 *f2)
#define AV_CH_FRONT_LEFT_OF_CENTER
#define AV_CH_FRONT_CENTER
static const AVFilterPad outputs[]
#define AV_CH_FRONT_RIGHT_OF_CENTER
A list of supported channel layouts.
static const AVOption sofalizer_options[]
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
#define AV_LOG_INFO
Standard information.
static int preload_sofa(AVFilterContext *ctx, char *filename, int *samplingrate)
char * av_strdup(const char *s)
Duplicate a string.
AVSampleFormat
Audio sample formats.
Used for passing data between threads.
static int activate(AVFilterContext *ctx)
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.
static int config_input(AVFilterLink *inlink)
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)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
#define AV_CH_TOP_BACK_RIGHT
Describe the class of an AVClass context structure.
const char * name
Filter name.
static const AVFilterPad inputs[]
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
#define FF_FILTER_FORWARD_STATUS(inlink, outlink)
Acknowledge the status on an input link and forward it to an output link.
#define flags(name, subs,...)
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
#define AV_CH_BACK_CENTER
static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
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()...
static int parse_channel_name(char **arg, int *rchannel, char *buf)
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
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
int channels
Number of channels.
avfilter_execute_func * execute
static av_cold int init(AVFilterContext *ctx)
static void parse_speaker_pos(AVFilterContext *ctx, int64_t in_channel_layout)
AVFilterContext * dst
dest filter
#define AV_CH_SURROUND_DIRECT_LEFT
#define AV_CH_FRONT_RIGHT
static enum AVSampleFormat sample_fmts[]
VirtualSpeaker vspkrpos[64]
#define av_malloc_array(a, b)
uint8_t ** extended_data
pointers to the data planes/channels.
static av_cold void uninit(AVFilterContext *ctx)
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
struct MYSOFA_NEIGHBORHOOD * neighborhood
int nb_samples
number of audio samples (per channel) described by this frame
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static int getfilter_float(AVFilterContext *ctx, float x, float y, float z, float *left, float *right, float *delay_left, float *delay_right)
#define AV_CH_STEREO_LEFT
Stereo downmix.