42 #define FREQUENCY_DOMAIN 1
116 nc_close(sofa->
ncid);
126 int ncid, n_dims, n_vars, n_gatts, n_unlim_dim_id, status;
127 char data_delay_dim_name[NC_MAX_NAME];
128 float *sp_a, *sp_e, *sp_r, *
data_ir;
129 char *sofa_conventions;
130 char dim_name[NC_MAX_NAME];
134 int data_delay_dim_id[2];
148 status = nc_open(filename, NC_NOWRITE, &ncid);
149 if (status != NC_NOERR) {
155 nc_inq(ncid, &n_dims, &n_vars, &n_gatts, &n_unlim_dim_id);
164 for (i = 0; i < n_dims; i++) {
165 nc_inq_dim(ncid, i, (
char *)&dim_name, &dim_length[i]);
166 if (!strncmp(
"M", (
const char *)&dim_name, 1))
168 if (!strncmp(
"N", (
const char *)&dim_name, 1))
172 if ((m_dim_id == -1) || (n_dim_id == -1)) {
179 n_samples = dim_length[n_dim_id];
180 m_dim = dim_length[m_dim_id];
186 status = nc_inq_attlen(ncid, NC_GLOBAL,
"Conventions", &att_len);
187 if (status != NC_NOERR) {
200 nc_get_att_text(ncid, NC_GLOBAL,
"Conventions", text);
201 *(text + att_len) = 0;
202 if (strncmp(
"SOFA", text, 4)) {
210 status = nc_inq_attlen(ncid, NC_GLOBAL,
"License", &att_len);
211 if (status == NC_NOERR) {
214 nc_get_att_text(ncid, NC_GLOBAL,
"License", text);
215 *(text + att_len) = 0;
221 status = nc_inq_attlen(ncid, NC_GLOBAL,
"SourceDescription", &att_len);
222 if (status == NC_NOERR) {
225 nc_get_att_text(ncid, NC_GLOBAL,
"SourceDescription", text);
226 *(text + att_len) = 0;
232 status = nc_inq_attlen(ncid, NC_GLOBAL,
"Comment", &att_len);
233 if (status == NC_NOERR) {
236 nc_get_att_text(ncid, NC_GLOBAL,
"Comment", text);
237 *(text + att_len) = 0;
243 status = nc_inq_attlen(ncid, NC_GLOBAL,
"SOFAConventions", &att_len);
244 if (status != NC_NOERR) {
250 sofa_conventions =
av_malloc(att_len + 1);
251 if (!sofa_conventions) {
256 nc_get_att_text(ncid, NC_GLOBAL,
"SOFAConventions", sofa_conventions);
257 *(sofa_conventions + att_len) = 0;
258 if (strncmp(
"SimpleFreeFieldHRIR", sofa_conventions, att_len)) {
268 status = nc_inq_varid(ncid,
"Data.SamplingRate", &samplingrate_id);
269 status += nc_get_var_uint(ncid, samplingrate_id, &sample_rate);
270 if (status != NC_NOERR) {
285 if (!data_delay || !sp_a || !sp_e || !sp_r || !data_ir) {
293 status = nc_inq_varid(ncid,
"Data.IR", &data_ir_id);
294 status += nc_get_var_float(ncid, data_ir_id, data_ir);
295 if (status != NC_NOERR) {
302 status = nc_inq_varid(ncid,
"SourcePosition", &sp_id);
303 status += nc_get_vara_float(ncid, sp_id, (
size_t[2]){ 0, 0 } ,
304 (
size_t[2]){ m_dim, 1}, sp_a);
305 status += nc_get_vara_float(ncid, sp_id, (
size_t[2]){ 0, 1 } ,
306 (
size_t[2]){ m_dim, 1}, sp_e);
307 status += nc_get_vara_float(ncid, sp_id, (
size_t[2]){ 0, 2 } ,
308 (
size_t[2]){ m_dim, 1}, sp_r);
309 if (status != NC_NOERR) {
316 status = nc_inq_varid(ncid,
"Data.Delay", &data_delay_id);
317 status += nc_inq_vardimid(ncid, data_delay_id, &data_delay_dim_id[0]);
318 status += nc_inq_dimname(ncid, data_delay_dim_id[0], data_delay_dim_name);
319 if (status != NC_NOERR) {
327 if (!strncmp(data_delay_dim_name,
"I", 2)) {
333 status = nc_get_var_int(ncid, data_delay_id, &delay[0]);
334 if (status != NC_NOERR) {
339 data_delay_r = data_delay + m_dim;
340 for (i = 0; i < m_dim; i++) {
342 data_delay[i] = delay[0];
343 data_delay_r[i] = delay[1];
346 }
else if (!strncmp(data_delay_dim_name,
"M", 2)) {
349 status = nc_get_var_int(ncid, data_delay_id, data_delay);
350 if (status != NC_NOERR) {
356 av_log(ctx,
AV_LOG_ERROR,
"Data.Delay does not have the required dimensions [I R] or [M R].\n");
378 int len, i, channel_id = 0;
382 if (sscanf(*arg,
"%7[A-Z]%n", buf, &len)) {
385 for (i = 32; i > 0; i >>= 1) {
386 if (layout >= (int64_t)1 << i) {
392 if (channel_id >= 64 || layout0 != (int64_t)1 << channel_id)
394 *rchannel = channel_id;
410 while ((arg =
av_strtok(p,
"|", &tokenizer))) {
420 if (sscanf(arg,
"%f %f", &azim, &elev) == 2) {
424 }
else if (sscanf(arg,
"%f", &azim) == 1) {
439 float azim[16] = { 0 };
440 float elev[16] = { 0 };
452 for (m = 0, ch = 0; ch < n_conv && m < 64; m++) {
453 uint64_t
mask = channels_layout & (1ULL << m);
469 elev[
ch] = 90;
break;
471 elev[
ch] = 45;
break;
473 elev[
ch] = 45;
break;
475 elev[
ch] = 45;
break;
477 elev[
ch] = 45;
break;
479 elev[
ch] = 45;
break;
481 elev[
ch] = 45;
break;
502 memcpy(speaker_azim, azim, n_conv *
sizeof(
float));
503 memcpy(speaker_elev, elev, n_conv *
sizeof(
float));
513 for (i = 0; i < sofa->
m_dim * 2; i++) {
533 for (i = 0; i < m_dim; i++) {
536 current = fabs(sp_a[i] - azim) +
537 fabs(sp_e[i] - elev) +
538 fabs(sp_r[i] - radius);
539 if (current <= delta) {
568 compensate = 256 / (sofa->
n_samples * sqrt(energy));
575 ir[i] = ir[i] * compensate;
603 int *write = &td->
write[jobnr];
604 const int *
const delay = td->
delay[jobnr];
605 const float *
const ir = td->
ir[jobnr];
608 float *temp_src = td->
temp_src[jobnr];
610 const float *
src = (
const float *)in->
data[0];
611 float *dst = (
float *)
out->data[0];
612 const int in_channels = s->
n_conv;
616 const uint32_t modulo = (uint32_t)buffer_length - 1;
623 for (l = 0; l < in_channels; l++) {
625 buffer[l] = ringbuffer + l * buffer_length;
629 const float *temp_ir = ir;
632 for (l = 0; l < in_channels; l++) {
634 *(buffer[l] + wr) = src[l];
638 for (l = 0; l < in_channels; l++) {
639 const float *
const bptr = buffer[l];
645 temp_ir +=
FFALIGN(n_samples, 16);
652 read = (wr - *(delay + l) - (n_samples - 1) + buffer_length) & modulo;
654 if (read + n_samples < buffer_length) {
655 memcpy(temp_src, bptr + read, n_samples *
sizeof(*temp_src));
657 int len =
FFMIN(n_samples - (read % n_samples), buffer_length - read);
659 memcpy(temp_src, bptr + read, len *
sizeof(*temp_src));
660 memcpy(temp_src + len, bptr, (n_samples - len) *
sizeof(*temp_src));
665 temp_ir +=
FFALIGN(n_samples, 16);
675 wr = (wr + 1) & modulo;
689 int *write = &td->
write[jobnr];
694 const float *
src = (
const float *)in->
data[0];
695 float *dst = (
float *)
out->data[0];
696 const int in_channels = s->
n_conv;
700 const uint32_t modulo = (uint32_t)buffer_length - 1;
704 const int n_conv = s->
n_conv;
705 const int n_fft = s->
n_fft;
706 const float fft_scale = 1.0f / s->
n_fft;
717 for (j = 0; j < n_read; j++) {
719 dst[2 * j] = ringbuffer[wr];
720 ringbuffer[wr] = 0.0;
722 wr = (wr + 1) & modulo;
730 for (i = 0; i < n_conv; i++) {
734 dst[2 * j] += src[i + j * in_channels] * s->
gain_lfe;
741 hrtf_offset = hrtf +
offset;
744 memset(fft_in, 0,
sizeof(
FFTComplex) * n_fft);
749 fft_in[j].
re = src[j * in_channels + i];
755 for (j = 0; j < n_fft; j++) {
757 const float re = fft_in[j].
re;
758 const float im = fft_in[j].
im;
762 fft_in[j].
re = re * hcomplex->
re - im * hcomplex->
im;
764 fft_in[j].
im = re * hcomplex->
im + im * hcomplex->
re;
773 dst[2 * j] += fft_in[j].
re * fft_scale;
776 for (j = 0; j < n_samples - 1; j++) {
778 int write_pos = (wr + j) & modulo;
780 *(ringbuffer + write_pos) += fft_in[in->
nb_samples + j].
re * fft_scale;
785 for (i = 0; i <
out->nb_samples; i++) {
787 if (fabs(*dst) > 1) {
806 int n_clippings[2] = { 0 };
830 if (n_clippings[0] + n_clippings[1] > 0) {
832 n_clippings[0] + n_clippings[1], out->
nb_samples * 2);
886 float gain_lin =
expf((s->
gain - 3 * nb_input_channels) / 20 *
M_LN10);
891 float *data_ir_l =
NULL;
892 float *data_ir_r =
NULL;
895 int i, j, azim_orig = azim, elev_orig = elev;
898 av_log(ctx,
AV_LOG_ERROR,
"Selected SOFA file is invalid. Please select valid SOFA file.\n");
918 if (!data_hrtf_r || !data_hrtf_l) {
925 for (i = 0; i < s->
n_conv; i++) {
930 m[i] =
find_m(s, azim, elev, radius);
937 offset = i *
FFALIGN(n_samples, 16);
938 for (j = 0; j < n_samples; j++) {
941 *(data_ir_l + offset + j) =
942 *(s->
sofa.
data_ir + 2 * m[i] * n_samples + n_samples - 1 - j) * gain_lin;
943 *(data_ir_r + offset + j) =
944 *(s->
sofa.
data_ir + 2 * m[i] * n_samples + n_samples - 1 - j + n_samples) * gain_lin;
947 fft_in_l =
av_calloc(n_fft,
sizeof(*fft_in_l));
948 fft_in_r =
av_calloc(n_fft,
sizeof(*fft_in_r));
949 if (!fft_in_l || !fft_in_r) {
958 for (j = 0; j < n_samples; j++) {
963 fft_in_l[delay_l[i] + j].
re =
964 *(s->
sofa.
data_ir + 2 * m[i] * n_samples + j) * gain_lin;
965 fft_in_r[delay_r[i] + j].
re =
966 *(s->
sofa.
data_ir + (2 * m[i] + 1) * n_samples + j) * gain_lin;
972 memcpy(data_hrtf_l + offset, fft_in_l, n_fft *
sizeof(*fft_in_l));
975 memcpy(data_hrtf_r + offset, fft_in_r, n_fft *
sizeof(*fft_in_r));
978 av_log(ctx,
AV_LOG_DEBUG,
"Index: %d, Azimuth: %f, Elevation: %f, Radius: %f of SOFA file.\n",
984 memcpy(s->
data_ir[0], data_ir_l,
sizeof(
float) * n_conv *
FFALIGN(n_samples, 16));
985 memcpy(s->
data_ir[1], data_ir_r,
sizeof(
float) * n_conv *
FFALIGN(n_samples, 16));
1012 memcpy(s->
delay[0], &delay_l[0],
sizeof(
int) * s->
n_conv);
1013 memcpy(s->
delay[1], &delay_r[0],
sizeof(
int) * s->
n_conv);
1042 av_log(ctx,
AV_LOG_ERROR,
"No valid SOFA file could be loaded. Please specify valid SOFA file.\n");
1057 int nb_input_channels = inlink->
channels;
1072 s->
n_conv = nb_input_channels;
1077 if (n_current > n_max) {
1141 av_log(ctx,
AV_LOG_ERROR,
"Couldn't get speaker positions. Input channel configuration not supported.\n");
1149 av_log(ctx,
AV_LOG_DEBUG,
"Samplerate: %d Channels to convolute: %d, Length of ringbuffer: %d x %d\n",
1187 #define OFFSET(x) offsetof(SOFAlizerContext, x)
1188 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1224 .
name =
"sofalizer",
1227 .priv_class = &sofalizer_class,
static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
FFTComplex * data_hrtf[2]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
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)
int max_samples
Maximum number of samples to filter at once.
#define AV_CH_TOP_FRONT_LEFT
#define AV_CH_TOP_FRONT_CENTER
#define AV_CH_LOW_FREQUENCY_2
float(* scalarproduct_float)(const float *v1, const float *v2, int len)
Calculate the scalar product of two vectors of floats.
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().
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
float avpriv_scalarproduct_float_c(const float *v1, const float *v2, int len)
Return the scalar product of two vectors.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define AV_CH_TOP_BACK_LEFT
#define AV_CH_TOP_BACK_CENTER
#define AV_CH_LOW_FREQUENCY
static int find_m(SOFAlizerContext *s, int azim, int elev, float radius)
A filter pad used for either input or output.
A link between two filters.
static int load_data(AVFilterContext *ctx, int azim, int elev, float radius)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int min_samples
Minimum number of samples to filter at once.
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)
static int close_sofa(struct NCSofa *sofa)
#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]
static int max_delay(struct NCSofa *sofa)
#define AV_CH_STEREO_RIGHT
See AV_CH_STEREO_LEFT.
audio channel layout utility functions
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
#define AV_CH_FRONT_LEFT_OF_CENTER
int partial_buf_size
Size of the partial buffer to allocate.
#define AV_CH_FRONT_CENTER
static int load_sofa(AVFilterContext *ctx, char *filename, int *samplingrate)
static const AVFilterPad outputs[]
static void error(const char *err)
#define AV_CH_FRONT_RIGHT_OF_CENTER
A list of supported channel layouts.
static const AVOption sofalizer_options[]
#define AV_LOG_INFO
Standard information.
char * av_strdup(const char *s)
Duplicate a string.
static int config_input(AVFilterLink *inlink)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
#define AV_CH_TOP_BACK_RIGHT
Describe the class of an AVClass context structure.
const char * name
Filter name.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
static const AVFilterPad inputs[]
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
#define AV_CH_BACK_CENTER
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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)
static void fft(const int32_t in[2 *256], cplx32 out[256])
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_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),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){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) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;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)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&1) 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);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
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
VirtualSpeaker vspkrpos[64]
static int compensate_volume(AVFilterContext *ctx)
#define av_malloc_array(a, b)
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().
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.
#define AV_CH_STEREO_LEFT
Stereo downmix.