101 #define IIR_CH(name, type, min, max, need_clipping) \
102 static int iir_ch_## name(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) \
104 AudioIIRContext *s = ctx->priv; \
105 const double ig = s->dry_gain; \
106 const double og = s->wet_gain; \
107 ThreadData *td = arg; \
108 AVFrame *in = td->in, *out = td->out; \
109 const type *src = (const type *)in->extended_data[ch]; \
110 double *ic = (double *)s->iir[ch].cache[0]; \
111 double *oc = (double *)s->iir[ch].cache[1]; \
112 const int nb_a = s->iir[ch].nb_ab[0]; \
113 const int nb_b = s->iir[ch].nb_ab[1]; \
114 const double *a = s->iir[ch].ab[0]; \
115 const double *b = s->iir[ch].ab[1]; \
116 int *clippings = &s->iir[ch].clippings; \
117 type *dst = (type *)out->extended_data[ch]; \
120 for (n = 0; n < in->nb_samples; n++) { \
121 double sample = 0.; \
124 memmove(&ic[1], &ic[0], (nb_b - 1) * sizeof(*ic)); \
125 memmove(&oc[1], &oc[0], (nb_a - 1) * sizeof(*oc)); \
126 ic[0] = src[n] * ig; \
127 for (x = 0; x < nb_b; x++) \
128 sample += b[x] * ic[x]; \
130 for (x = 1; x < nb_a; x++) \
131 sample -= a[x] * oc[x]; \
135 if (need_clipping && sample < min) { \
138 } else if (need_clipping && sample > max) { \
149 IIR_CH(s16p, int16_t, INT16_MIN, INT16_MAX, 1)
151 IIR_CH(fltp,
float, -1., 1., 0)
152 IIR_CH(dblp,
double, -1., 1., 0)
154 #define SERIAL_IIR_CH(name, type, min, max, need_clipping) \
155 static int iir_ch_serial_## name(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) \
157 AudioIIRContext *s = ctx->priv; \
158 const double ig = s->dry_gain; \
159 const double og = s->wet_gain; \
160 ThreadData *td = arg; \
161 AVFrame *in = td->in, *out = td->out; \
162 const type *src = (const type *)in->extended_data[ch]; \
163 type *dst = (type *)out->extended_data[ch]; \
164 IIRChannel *iir = &s->iir[ch]; \
165 int *clippings = &iir->clippings; \
166 int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2; \
169 for (i = 0; i < nb_biquads; i++) { \
170 const double a1 = -iir->biquads[i].a1; \
171 const double a2 = -iir->biquads[i].a2; \
172 const double b0 = iir->biquads[i].b0; \
173 const double b1 = iir->biquads[i].b1; \
174 const double b2 = iir->biquads[i].b2; \
175 double i1 = iir->biquads[i].i1; \
176 double i2 = iir->biquads[i].i2; \
177 double o1 = iir->biquads[i].o1; \
178 double o2 = iir->biquads[i].o2; \
180 for (n = 0; n < in->nb_samples; n++) { \
181 double sample = ig * (i ? dst[n] : src[n]); \
182 double o0 = sample * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
190 if (need_clipping && o0 < min) { \
193 } else if (need_clipping && o0 > max) { \
200 iir->biquads[i].i1 = i1; \
201 iir->biquads[i].i2 = i2; \
202 iir->biquads[i].o1 = o1; \
203 iir->biquads[i].o2 = o2; \
222 for (p = item_str; *p && *p !=
'|'; p++) {
231 char *p, *
arg, *old_str, *prev_arg =
NULL, *saveptr =
NULL;
237 for (i = 0; i < nb_items; i++) {
238 if (!(arg =
av_strtok(p,
"|", &saveptr)))
247 if (sscanf(arg,
"%lf", &s->
iir[i].
g) != 1) {
263 char *p, *
arg, *old_str, *saveptr =
NULL;
269 for (i = 0; i < nb_items; i++) {
270 if (!(arg =
av_strtok(p,
" ", &saveptr)))
274 if (sscanf(arg,
"%lf", &dst[i]) != 1) {
288 char *p, *
arg, *old_str, *saveptr =
NULL;
294 for (i = 0; i < nb_items; i++) {
295 if (!(arg =
av_strtok(p,
" ", &saveptr)))
299 if (sscanf(arg, format, &dst[i*2], &dst[i*2+1]) != 2) {
311 static const char *
format[] = {
"%lf",
"%lf %lfi",
"%lf %lfr",
"%lf %lfd" };
316 char *p, *
arg, *old_str, *prev_arg =
NULL, *saveptr =
NULL;
325 if (!(arg =
av_strtok(p,
"|", &saveptr)))
338 if (!iir->
ab[ab] || !iir->
cache[ab]) {
362 double nwre = -wre, nwim = -wim;
366 for (i = npz; i >= 1; i--) {
367 cre = coeffs[2 * i + 0];
368 cim = coeffs[2 * i + 1];
370 coeffs[2 * i + 0] = (nwre * cre - nwim * cim) + coeffs[2 * (i - 1) + 0];
371 coeffs[2 * i + 1] = (nwre * cim + nwim * cre) + coeffs[2 * (i - 1) + 1];
376 coeffs[0] = nwre * cre - nwim * cim;
377 coeffs[1] = nwre * cim + nwim * cre;
387 for (i = 0; i < nb; i++) {
388 coeffs[2 * (i + 1) ] = 0.0;
389 coeffs[2 * (i + 1) + 1] = 0.0;
392 for (i = 0; i < nb; i++)
393 multiply(pz[2 * i], pz[2 * i + 1], nb, coeffs);
395 for (i = 0; i < nb + 1; i++) {
396 if (fabs(coeffs[2 * i + 1]) > FLT_EPSILON) {
397 av_log(ctx,
AV_LOG_ERROR,
"coeff: %lf of z^%d is not real; poles/zeros are not complex conjugates.\n",
398 coeffs[2 * i + 1], i);
409 int ch, i, j, ret = 0;
417 if (!topc || !botc) {
432 for (j = 0, i = iir->
nb_ab[1]; i >= 0; j++, i--) {
433 iir->
ab[1][j] = topc[2 * i];
437 for (j = 0, i = iir->
nb_ab[0]; i >= 0; j++, i--) {
438 iir->
ab[0][j] = botc[2 * i];
460 int current_biquad = 0;
466 while (nb_biquads--) {
467 Pair outmost_pole = { -1, -1 };
468 Pair nearest_zero = { -1, -1 };
469 double zeros[4] = { 0 };
470 double poles[4] = { 0 };
473 double min_distance = DBL_MAX;
477 for (i = 0; i < iir->
nb_ab[0]; i++) {
482 mag =
hypot(iir->
ab[0][2 * i], iir->
ab[0][2 * i + 1]);
490 for (i = 0; i < iir->
nb_ab[1]; i++) {
494 if (iir->
ab[0][2 * i ] == iir->
ab[0][2 * outmost_pole.
a ] &&
495 iir->
ab[0][2 * i + 1] == -iir->
ab[0][2 * outmost_pole.
a + 1]) {
503 if (outmost_pole.
a < 0 || outmost_pole.
b < 0)
506 for (i = 0; i < iir->
nb_ab[1]; i++) {
511 distance =
hypot(iir->
ab[0][2 * outmost_pole.
a ] - iir->
ab[1][2 * i ],
512 iir->
ab[0][2 * outmost_pole.
a + 1] - iir->
ab[1][2 * i + 1]);
514 if (distance < min_distance) {
520 for (i = 0; i < iir->
nb_ab[1]; i++) {
524 if (iir->
ab[1][2 * i ] == iir->
ab[1][2 * nearest_zero.
a ] &&
525 iir->
ab[1][2 * i + 1] == -iir->
ab[1][2 * nearest_zero.
a + 1]) {
533 if (nearest_zero.
a < 0 || nearest_zero.
b < 0)
536 poles[0] = iir->
ab[0][2 * outmost_pole.
a ];
537 poles[1] = iir->
ab[0][2 * outmost_pole.
a + 1];
539 zeros[0] = iir->
ab[1][2 * nearest_zero.
a ];
540 zeros[1] = iir->
ab[1][2 * nearest_zero.
a + 1];
542 if (nearest_zero.
a == nearest_zero.
b && outmost_pole.
a == outmost_pole.
b) {
549 poles[2] = iir->
ab[0][2 * outmost_pole.
b ];
550 poles[3] = iir->
ab[0][2 * outmost_pole.
b + 1];
552 zeros[2] = iir->
ab[1][2 * nearest_zero.
b ];
553 zeros[3] = iir->
ab[1][2 * nearest_zero.
b + 1];
556 ret =
expand(ctx, zeros, 2, b);
560 ret =
expand(ctx, poles, 2, a);
564 iir->
ab[0][2 * outmost_pole.
a] = iir->
ab[0][2 * outmost_pole.
a + 1] =
NAN;
565 iir->
ab[0][2 * outmost_pole.
b] = iir->
ab[0][2 * outmost_pole.
b + 1] =
NAN;
566 iir->
ab[1][2 * nearest_zero.
a] = iir->
ab[1][2 * nearest_zero.
a + 1] =
NAN;
567 iir->
ab[1][2 * nearest_zero.
b] = iir->
ab[1][2 * nearest_zero.
b + 1] =
NAN;
570 iir->
biquads[current_biquad].
a1 = a[2] / a[4];
571 iir->
biquads[current_biquad].
a2 = a[0] / a[4];
572 iir->
biquads[current_biquad].
b0 = b[4] / a[4] * (current_biquad ? 1.0 : iir->
g);
573 iir->
biquads[current_biquad].
b1 = b[2] / a[4] * (current_biquad ? 1.0 : iir->
g);
574 iir->
biquads[current_biquad].
b2 = b[0] / a[4] * (current_biquad ? 1.0 : iir->
g);
600 for (n = 0; n < iir->
nb_ab[0]; n++) {
601 double r = iir->
ab[0][2*
n];
602 double angle = iir->
ab[0][2*n+1];
604 iir->
ab[0][2*
n] = r * cos(angle);
605 iir->
ab[0][2*n+1] = r * sin(angle);
608 for (n = 0; n < iir->
nb_ab[1]; n++) {
609 double r = iir->
ab[1][2*
n];
610 double angle = iir->
ab[1][2*n+1];
612 iir->
ab[1][2*
n] = r * cos(angle);
613 iir->
ab[1][2*n+1] = r * sin(angle);
627 for (n = 0; n < iir->
nb_ab[0]; n++) {
628 double r = iir->
ab[0][2*
n];
629 double angle =
M_PI*iir->
ab[0][2*n+1]/180.;
631 iir->
ab[0][2*
n] = r * cos(angle);
632 iir->
ab[0][2*n+1] = r * sin(angle);
635 for (n = 0; n < iir->
nb_ab[1]; n++) {
636 double r = iir->
ab[1][2*
n];
637 double angle =
M_PI*iir->
ab[1][2*n+1]/180.;
639 iir->
ab[1][2*
n] = r * cos(angle);
640 iir->
ab[1][2*n+1] = r * sin(angle);
671 }
else if (s->
format == 3) {
676 av_log(ctx,
AV_LOG_WARNING,
"tf coefficients format is not recommended for too high number of zeros/poles.\n");
679 av_log(ctx,
AV_LOG_WARNING,
"Direct processsing is not recommended for zp coefficients format.\n");
685 av_log(ctx,
AV_LOG_ERROR,
"Serial cascading is not implemented for transfer function.\n");
696 for (ch = 0; ch < inlink->
channels; ch++) {
699 for (i = 1; i < iir->
nb_ab[0]; i++) {
700 iir->
ab[0][i] /= iir->
ab[0][0];
703 for (i = 0; i < iir->
nb_ab[1]; i++) {
704 iir->
ab[1][i] *= iir->
g / iir->
ab[0][0];
742 for (ch = 0; ch < outlink->
channels; ch++) {
781 for (ch = 0; ch < s->
channels; ch++) {
811 #define OFFSET(x) offsetof(AudioIIRContext, x)
812 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
823 {
"pr",
"Z-plane zeros/poles (polar radians)", 0,
AV_OPT_TYPE_CONST, {.i64=2}, 0, 0,
AF,
"format" },
824 {
"pd",
"Z-plane zeros/poles (polar degrees)", 0,
AV_OPT_TYPE_CONST, {.i64=3}, 0, 0,
AF,
"format" },
829 {
"dbl",
"double-precision floating-point", 0,
AV_OPT_TYPE_CONST, {.i64=0}, 0, 0,
AF,
"precision" },
830 {
"flt",
"single-precision floating-point", 0,
AV_OPT_TYPE_CONST, {.i64=1}, 0, 0,
AF,
"precision" },
840 .description =
NULL_IF_CONFIG_SMALL(
"Apply Infinite Impulse Response filter with supplied coefficients."),
842 .priv_class = &aiir_class,
static const char * format[]
This structure describes decoded (raw) audio or video data.
enum AVSampleFormat sample_format
#define AV_LOG_WARNING
Something somehow does not look correct.
Main libavfilter public API header.
static void convert_pd2zp(AVFilterContext *ctx, int channels)
static int decompose_zp2biquads(AVFilterContext *ctx, int channels)
#define SERIAL_IIR_CH(name, type, min, max, need_clipping)
static void count_coefficients(char *item_str, int *nb_items)
static int config_output(AVFilterLink *outlink)
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
static int process(struct ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed)
const char * name
Pad name.
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.
static av_cold int init(AVFilterContext *ctx)
static int expand(AVFilterContext *ctx, double *pz, int nb, double *coeffs)
#define IIR_CH(name, type, min, max, need_clipping)
#define AV_LOG_VERBOSE
Detailed information.
static int read_tf_coefficients(AVFilterContext *ctx, char *item_str, int nb_items, double *dst)
static int query_formats(AVFilterContext *ctx)
A filter pad used for either input or output.
A link between two filters.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
static int read_channels(AVFilterContext *ctx, int channels, uint8_t *item_str, int ab)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#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...
simple assert() macros that are a bit more flexible than ISO C assert().
static float distance(float x, float y, int band)
static av_const double hypot(double x, double y)
static int convert_zp2tf(AVFilterContext *ctx, int channels)
AVFilterContext * src
source filter
int format
agreed upon media format
A list of supported channel layouts.
int(* iir_channel)(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
char * av_strdup(const char *s)
Duplicate a string.
AVSampleFormat
Audio sample formats.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
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 AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Describe the class of an AVClass context structure.
static int read_gains(AVFilterContext *ctx, char *item_str, int nb_items)
static void convert_pr2zp(AVFilterContext *ctx, int channels)
const char * name
Filter name.
static int read_zp_coefficients(AVFilterContext *ctx, char *item_str, int nb_items, double *dst, const char *format)
static av_cold void uninit(AVFilterContext *ctx)
static const AVFilterPad inputs[]
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
static const AVFilterPad outputs[]
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 channels
Number of channels.
avfilter_execute_func * execute
static const int16_t coeffs[]
AVFilterContext * dst
dest filter
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static enum AVSampleFormat sample_fmts[]
AVFILTER_DEFINE_CLASS(aiir)
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 const AVOption aiir_options[]
static void multiply(double wre, double wim, int npz, double *coeffs)
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_X86ASM &&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