120 #define IIR_CH(name, type, min, max, need_clipping) \
121 static int iir_ch_## name(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) \
123 AudioIIRContext *s = ctx->priv; \
124 const double ig = s->dry_gain; \
125 const double og = s->wet_gain; \
126 ThreadData *td = arg; \
127 AVFrame *in = td->in, *out = td->out; \
128 const type *src = (const type *)in->extended_data[ch]; \
129 double *ic = (double *)s->iir[ch].cache[0]; \
130 double *oc = (double *)s->iir[ch].cache[1]; \
131 const int nb_a = s->iir[ch].nb_ab[0]; \
132 const int nb_b = s->iir[ch].nb_ab[1]; \
133 const double *a = s->iir[ch].ab[0]; \
134 const double *b = s->iir[ch].ab[1]; \
135 int *clippings = &s->iir[ch].clippings; \
136 type *dst = (type *)out->extended_data[ch]; \
139 for (n = 0; n < in->nb_samples; n++) { \
140 double sample = 0.; \
143 memmove(&ic[1], &ic[0], (nb_b - 1) * sizeof(*ic)); \
144 memmove(&oc[1], &oc[0], (nb_a - 1) * sizeof(*oc)); \
145 ic[0] = src[n] * ig; \
146 for (x = 0; x < nb_b; x++) \
147 sample += b[x] * ic[x]; \
149 for (x = 1; x < nb_a; x++) \
150 sample -= a[x] * oc[x]; \
154 if (need_clipping && sample < min) { \
157 } else if (need_clipping && sample > max) { \
168 IIR_CH(s16p, int16_t, INT16_MIN, INT16_MAX, 1)
170 IIR_CH(fltp,
float, -1., 1., 0)
171 IIR_CH(dblp,
double, -1., 1., 0)
173 #define SERIAL_IIR_CH(name, type, min, max, need_clipping) \
174 static int iir_ch_serial_## name(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) \
176 AudioIIRContext *s = ctx->priv; \
177 const double ig = s->dry_gain; \
178 const double og = s->wet_gain; \
179 ThreadData *td = arg; \
180 AVFrame *in = td->in, *out = td->out; \
181 const type *src = (const type *)in->extended_data[ch]; \
182 type *dst = (type *)out->extended_data[ch]; \
183 IIRChannel *iir = &s->iir[ch]; \
184 int *clippings = &iir->clippings; \
185 int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2; \
188 for (i = 0; i < nb_biquads; i++) { \
189 const double a1 = -iir->biquads[i].a1; \
190 const double a2 = -iir->biquads[i].a2; \
191 const double b0 = iir->biquads[i].b0; \
192 const double b1 = iir->biquads[i].b1; \
193 const double b2 = iir->biquads[i].b2; \
194 double i1 = iir->biquads[i].i1; \
195 double i2 = iir->biquads[i].i2; \
196 double o1 = iir->biquads[i].o1; \
197 double o2 = iir->biquads[i].o2; \
199 for (n = 0; n < in->nb_samples; n++) { \
200 double sample = ig * (i ? dst[n] : src[n]); \
201 double o0 = sample * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
209 if (need_clipping && o0 < min) { \
212 } else if (need_clipping && o0 > max) { \
219 iir->biquads[i].i1 = i1; \
220 iir->biquads[i].i2 = i2; \
221 iir->biquads[i].o1 = o1; \
222 iir->biquads[i].o2 = o2; \
241 for (p = item_str; *p && *p !=
'|'; p++) {
250 char *p, *
arg, *old_str, *prev_arg =
NULL, *saveptr =
NULL;
256 for (i = 0; i < nb_items; i++) {
257 if (!(arg =
av_strtok(p,
"|", &saveptr)))
266 if (sscanf(arg,
"%lf", &s->
iir[i].
g) != 1) {
282 char *p, *
arg, *old_str, *saveptr =
NULL;
288 for (i = 0; i < nb_items; i++) {
289 if (!(arg =
av_strtok(p,
" ", &saveptr)))
293 if (sscanf(arg,
"%lf", &dst[i]) != 1) {
307 char *p, *
arg, *old_str, *saveptr =
NULL;
313 for (i = 0; i < nb_items; i++) {
314 if (!(arg =
av_strtok(p,
" ", &saveptr)))
318 if (sscanf(arg, format, &dst[i*2], &dst[i*2+1]) != 2) {
330 static const char *
format[] = {
"%lf",
"%lf %lfi",
"%lf %lfr",
"%lf %lfd" };
335 char *p, *
arg, *old_str, *prev_arg =
NULL, *saveptr =
NULL;
344 if (!(arg =
av_strtok(p,
"|", &saveptr)))
357 if (!iir->
ab[ab] || !iir->
cache[ab]) {
379 static void multiply(
double wre,
double wim,
int npz,
double *coeffs)
381 double nwre = -wre, nwim = -wim;
385 for (i = npz; i >= 1; i--) {
386 cre = coeffs[2 * i + 0];
387 cim = coeffs[2 * i + 1];
389 coeffs[2 * i + 0] = (nwre * cre - nwim * cim) + coeffs[2 * (i - 1) + 0];
390 coeffs[2 * i + 1] = (nwre * cim + nwim * cre) + coeffs[2 * (i - 1) + 1];
395 coeffs[0] = nwre * cre - nwim * cim;
396 coeffs[1] = nwre * cim + nwim * cre;
406 for (i = 0; i < nb; i++) {
407 coeffs[2 * (i + 1) ] = 0.0;
408 coeffs[2 * (i + 1) + 1] = 0.0;
411 for (i = 0; i < nb; i++)
412 multiply(pz[2 * i], pz[2 * i + 1], nb, coeffs);
414 for (i = 0; i < nb + 1; i++) {
415 if (fabs(coeffs[2 * i + 1]) > FLT_EPSILON) {
416 av_log(ctx,
AV_LOG_ERROR,
"coeff: %f of z^%d is not real; poles/zeros are not complex conjugates.\n",
417 coeffs[2 * i + 1], i);
428 int ch, i, j, ret = 0;
436 if (!topc || !botc) {
451 for (j = 0, i = iir->
nb_ab[1]; i >= 0; j++, i--) {
452 iir->
ab[1][j] = topc[2 * i];
456 for (j = 0, i = iir->
nb_ab[0]; i >= 0; j++, i--) {
457 iir->
ab[0][j] = botc[2 * i];
479 int current_biquad = 0;
485 while (nb_biquads--) {
486 Pair outmost_pole = { -1, -1 };
487 Pair nearest_zero = { -1, -1 };
488 double zeros[4] = { 0 };
489 double poles[4] = { 0 };
492 double min_distance = DBL_MAX;
496 for (i = 0; i < iir->
nb_ab[0]; i++) {
501 mag =
hypot(iir->
ab[0][2 * i], iir->
ab[0][2 * i + 1]);
509 for (i = 0; i < iir->
nb_ab[1]; i++) {
513 if (iir->
ab[0][2 * i ] == iir->
ab[0][2 * outmost_pole.
a ] &&
514 iir->
ab[0][2 * i + 1] == -iir->
ab[0][2 * outmost_pole.
a + 1]) {
522 if (outmost_pole.
a < 0 || outmost_pole.
b < 0)
525 for (i = 0; i < iir->
nb_ab[1]; i++) {
530 distance =
hypot(iir->
ab[0][2 * outmost_pole.
a ] - iir->
ab[1][2 * i ],
531 iir->
ab[0][2 * outmost_pole.
a + 1] - iir->
ab[1][2 * i + 1]);
533 if (distance < min_distance) {
539 for (i = 0; i < iir->
nb_ab[1]; i++) {
543 if (iir->
ab[1][2 * i ] == iir->
ab[1][2 * nearest_zero.
a ] &&
544 iir->
ab[1][2 * i + 1] == -iir->
ab[1][2 * nearest_zero.
a + 1]) {
552 if (nearest_zero.
a < 0 || nearest_zero.
b < 0)
555 poles[0] = iir->
ab[0][2 * outmost_pole.
a ];
556 poles[1] = iir->
ab[0][2 * outmost_pole.
a + 1];
558 zeros[0] = iir->
ab[1][2 * nearest_zero.
a ];
559 zeros[1] = iir->
ab[1][2 * nearest_zero.
a + 1];
561 if (nearest_zero.
a == nearest_zero.
b && outmost_pole.
a == outmost_pole.
b) {
568 poles[2] = iir->
ab[0][2 * outmost_pole.
b ];
569 poles[3] = iir->
ab[0][2 * outmost_pole.
b + 1];
571 zeros[2] = iir->
ab[1][2 * nearest_zero.
b ];
572 zeros[3] = iir->
ab[1][2 * nearest_zero.
b + 1];
575 ret =
expand(ctx, zeros, 2, b);
579 ret =
expand(ctx, poles, 2, a);
583 iir->
ab[0][2 * outmost_pole.
a] = iir->
ab[0][2 * outmost_pole.
a + 1] =
NAN;
584 iir->
ab[0][2 * outmost_pole.
b] = iir->
ab[0][2 * outmost_pole.
b + 1] =
NAN;
585 iir->
ab[1][2 * nearest_zero.
a] = iir->
ab[1][2 * nearest_zero.
a + 1] =
NAN;
586 iir->
ab[1][2 * nearest_zero.
b] = iir->
ab[1][2 * nearest_zero.
b + 1] =
NAN;
589 iir->
biquads[current_biquad].
a1 = a[2] / a[4];
590 iir->
biquads[current_biquad].
a2 = a[0] / a[4];
591 iir->
biquads[current_biquad].
b0 = b[4] / a[4] * (current_biquad ? 1.0 : iir->
g);
592 iir->
biquads[current_biquad].
b1 = b[2] / a[4] * (current_biquad ? 1.0 : iir->
g);
593 iir->
biquads[current_biquad].
b2 = b[0] / a[4] * (current_biquad ? 1.0 : iir->
g);
619 for (n = 0; n < iir->
nb_ab[0]; n++) {
620 double r = iir->
ab[0][2*
n];
621 double angle = iir->
ab[0][2*n+1];
623 iir->
ab[0][2*
n] = r * cos(angle);
624 iir->
ab[0][2*n+1] = r * sin(angle);
627 for (n = 0; n < iir->
nb_ab[1]; n++) {
628 double r = iir->
ab[1][2*
n];
629 double angle = iir->
ab[1][2*n+1];
631 iir->
ab[1][2*
n] = r * cos(angle);
632 iir->
ab[1][2*n+1] = r * sin(angle);
646 for (n = 0; n < iir->
nb_ab[0]; n++) {
647 double r = iir->
ab[0][2*
n];
648 double angle =
M_PI*iir->
ab[0][2*n+1]/180.;
650 iir->
ab[0][2*
n] = r * cos(angle);
651 iir->
ab[0][2*n+1] = r * sin(angle);
654 for (n = 0; n < iir->
nb_ab[1]; n++) {
655 double r = iir->
ab[1][2*
n];
656 double angle =
M_PI*iir->
ab[1][2*n+1]/180.;
658 iir->
ab[1][2*
n] = r * cos(angle);
659 iir->
ab[1][2*n+1] = r * sin(angle);
672 for (i = 0; txt[i]; i++) {
676 for (char_y = 0; char_y < font_height; char_y++) {
677 for (mask = 0x80;
mask; mask >>= 1) {
678 if (font[txt[i] * font_height + char_y] & mask)
689 int dx =
FFABS(x1-x0);
690 int dy =
FFABS(y1-y0), sy = y0 < y1 ? 1 : -1;
691 int err = (dx>dy ? dx : -dy) / 2, e2;
696 if (x0 == x1 && y0 == y1)
716 float *mag, *phase,
min = FLT_MAX, max = FLT_MIN;
717 int prev_ymag = -1, prev_yphase = -1;
729 for (i = 0; i < s->
w; i++) {
732 double w = i *
M_PI / (s->
w - 1);
735 double real, imag, div;
738 realz = 0., realp = 0.;
739 imagz = 0., imagp = 0.;
741 realz += cos(-x * w) * a[x];
742 imagz += sin(-x * w) * a[x];
746 realp += cos(-x * w) * b[x];
747 imagp += sin(-x * w) * b[x];
750 div = realp * realp + imagp * imagp;
751 real = (realz * realp + imagz * imagp) / div;
752 imag = (imagz * realp - imagp * realz) / div;
757 double ore, oim,
re,
im;
759 re = cos(w) - a[2 * x];
760 im = sin(w) - a[2 * x + 1];
765 real = ore * re - oim *
im;
766 imag = ore * im + oim *
re;
770 double ore, oim,
re,
im;
772 re = cos(w) - b[2 * x];
773 im = sin(w) - b[2 * x + 1];
777 div = re * re + im *
im;
779 real = (ore * re + oim *
im) / div;
780 imag = (oim * re - ore *
im) / div;
785 phase[i] = atan2(imag, real);
786 min = fminf(min, mag[i]);
787 max = fmaxf(max, mag[i]);
790 for (i = 0; i < s->
w; i++) {
791 int ymag = mag[i] / max * (s->
h - 1);
792 int yphase = (0.5 * (1. + phase[i] /
M_PI)) * (s->
h - 1);
794 ymag = s->
h - 1 - av_clip(ymag, 0, s->
h - 1);
795 yphase = s->
h - 1 - av_clip(yphase, 0, s->
h - 1);
800 prev_yphase = yphase;
803 draw_line(out, i, yphase,
FFMAX(i - 1, 0), prev_yphase, 0xFF00FF00);
806 prev_yphase = yphase;
809 if (s->
w > 400 && s->
h > 100) {
810 drawtext(out, 2, 2,
"Max Magnitude:", 0xDDDDDDDD);
811 snprintf(text,
sizeof(text),
"%.2f", max);
812 drawtext(out, 15 * 8 + 2, 2, text, 0xDDDDDDDD);
814 drawtext(out, 2, 12,
"Min Magnitude:", 0xDDDDDDDD);
815 snprintf(text,
sizeof(text),
"%.2f", min);
816 drawtext(out, 15 * 8 + 2, 12, text, 0xDDDDDDDD);
850 }
else if (s->
format == 3) {
864 av_log(ctx,
AV_LOG_WARNING,
"tf coefficients format is not recommended for too high number of zeros/poles.\n");
867 av_log(ctx,
AV_LOG_WARNING,
"Direct processsing is not recommended for zp coefficients format.\n");
873 av_log(ctx,
AV_LOG_ERROR,
"Serial cascading is not implemented for transfer function.\n");
887 for (i = 1; i < iir->
nb_ab[0]; i++) {
888 iir->
ab[0][i] /= iir->
ab[0][0];
891 for (i = 0; i < iir->
nb_ab[1]; i++) {
892 iir->
ab[1][i] *= iir->
g / iir->
ab[0][0];
930 for (ch = 0; ch < outlink->
channels; ch++) {
1021 for (ch = 0; ch < s->
channels; ch++) {
1047 #define OFFSET(x) offsetof(AudioIIRContext, x)
1048 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1049 #define VF AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1060 {
"pr",
"Z-plane zeros/poles (polar radians)", 0,
AV_OPT_TYPE_CONST, {.i64=2}, 0, 0,
AF,
"format" },
1061 {
"pd",
"Z-plane zeros/poles (polar degrees)", 0,
AV_OPT_TYPE_CONST, {.i64=3}, 0, 0,
AF,
"format" },
1066 {
"dbl",
"double-precision floating-point", 0,
AV_OPT_TYPE_CONST, {.i64=0}, 0, 0,
AF,
"precision" },
1067 {
"flt",
"single-precision floating-point", 0,
AV_OPT_TYPE_CONST, {.i64=1}, 0, 0,
AF,
"precision" },
1071 {
"channel",
"set IR channel to display frequency response",
OFFSET(ir_channel),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1024,
VF },
1080 .description =
NULL_IF_CONFIG_SMALL(
"Apply Infinite Impulse Response filter with supplied coefficients."),
1082 .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 int config_video(AVFilterLink *outlink)
int h
agreed upon image height
static void convert_pd2zp(AVFilterContext *ctx, int channels)
static void drawtext(AVFrame *pic, int x, int y, const char *txt, uint32_t color)
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)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
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.
AVFilterPad * output_pads
array of output pads
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
static av_cold int end(AVCodecContext *avctx)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
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)
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
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.
const uint8_t avpriv_cga_font[2048]
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 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().
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
static float distance(float x, float y, int band)
int w
agreed upon image width
static av_const double hypot(double x, double y)
static int convert_zp2tf(AVFilterContext *ctx, int channels)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
AVFilterContext * src
source filter
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
int format
agreed upon media format
A list of supported channel layouts.
static void draw_response(AVFilterContext *ctx, AVFrame *out)
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.
Used for passing data between threads.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
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)
Rational number (pair of numerator and denominator).
const char * name
Filter name.
static int read_zp_coefficients(AVFilterContext *ctx, char *item_str, int nb_items, double *dst, const char *format)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static av_cold void uninit(AVFilterContext *ctx)
offset must point to two consecutive integers
static const AVFilterPad inputs[]
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
static enum AVPixelFormat pix_fmts[]
#define flags(name, subs,...)
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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 void draw_line(AVFrame *out, int x0, int y0, int x1, int y1, uint32_t color)
int channels
Number of channels.
avfilter_execute_func * execute
AVFilterContext * dst
dest filter
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static enum AVSampleFormat sample_fmts[]
AVFILTER_DEFINE_CLASS(aiir)
#define av_malloc_array(a, b)
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
AVPixelFormat
Pixel format.
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[]
CGA/EGA/VGA ROM font data.
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