Go to the documentation of this file.
25 #define TEMPLATE_REMATRIX_FLT
27 #undef TEMPLATE_REMATRIX_FLT
29 #define TEMPLATE_REMATRIX_DBL
31 #undef TEMPLATE_REMATRIX_DBL
33 #define TEMPLATE_REMATRIX_S16
38 #undef TEMPLATE_REMATRIX_S16
40 #define TEMPLATE_REMATRIX_S32
42 #undef TEMPLATE_REMATRIX_S32
46 #define FRONT_CENTER 2
47 #define LOW_FREQUENCY 3
50 #define FRONT_LEFT_OF_CENTER 6
51 #define FRONT_RIGHT_OF_CENTER 7
56 #define TOP_FRONT_LEFT 12
57 #define TOP_FRONT_CENTER 13
58 #define TOP_FRONT_RIGHT 14
59 #define TOP_BACK_LEFT 15
60 #define TOP_BACK_CENTER 16
61 #define TOP_BACK_RIGHT 17
62 #define NUM_NAMED_CHANNELS 18
66 int nb_in, nb_out, in,
out;
67 int user_in_chlayout_nb_channels, user_out_chlayout_nb_channels;
69 if (!
s ||
s->in_convert)
71 memset(
s->matrix, 0,
sizeof(
s->matrix));
72 memset(
s->matrix_flt, 0,
sizeof(
s->matrix_flt));
74 #if FF_API_OLD_CHANNEL_LAYOUT
78 if (!user_in_chlayout_nb_channels)
80 user_in_chlayout_nb_channels =
s->user_in_chlayout.nb_channels;
82 #if FF_API_OLD_CHANNEL_LAYOUT
83 (
s->user_in_ch_count > 0) ?
s->user_in_ch_count :
85 user_in_chlayout_nb_channels;
90 if (!user_out_chlayout_nb_channels)
92 user_out_chlayout_nb_channels =
s->user_out_chlayout.nb_channels;
94 #if FF_API_OLD_CHANNEL_LAYOUT
95 (
s->user_out_ch_count > 0) ?
s->user_out_ch_count :
97 user_out_chlayout_nb_channels;
99 for (in = 0; in < nb_in; in++)
103 s->rematrix_custom = 1;
149 #if FF_API_OLD_CHANNEL_LAYOUT
150 av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout_param,
151 double center_mix_level,
double surround_mix_level,
152 double lfe_mix_level,
double maxval,
153 double rematrix_volume,
double *matrix_param,
164 return swr_build_matrix2(&in_ch_layout, &out_ch_layout, center_mix_level, surround_mix_level,
165 lfe_mix_level, maxval, rematrix_volume, matrix_param,
166 stride, matrix_encoding, log_context);
171 double center_mix_level,
double surround_mix_level,
172 double lfe_mix_level,
double maxval,
173 double rematrix_volume,
double *matrix_param,
176 int i, j, out_i,
ret;
205 "Full-on remixing from 22.2 has not yet been implemented! "
206 "Processing the input as '%s'\n",
217 av_log(log_context,
AV_LOG_ERROR,
"Input channel layout '%s' is not supported\n", buf);
229 av_log(log_context,
AV_LOG_ERROR,
"Output channel layout '%s' is not supported\n", buf);
240 unaccounted = in_ch_layout.
u.
mask & ~out_ch_layout.u.mask;
407 for(out_i=
i=0;
i<64;
i++){
418 matrix_param[
stride*out_i + in_i] =
i == j &&
421 sum +=
fabs(matrix_param[
stride*out_i + in_i]);
424 maxcoef=
FFMAX(maxcoef, sum);
427 if(rematrix_volume < 0)
428 maxcoef = -rematrix_volume;
430 if(maxcoef > maxval || rematrix_volume < 0){
434 matrix_param[
stride*
i + j] /= maxcoef;
438 if(rematrix_volume > 0){
441 matrix_param[
stride*
i + j] *= rematrix_volume;
446 for (
i = 0;
i < out_ch_layout.nb_channels;
i++){
469 if (
s->rematrix_maxval > 0) {
470 maxval =
s->rematrix_maxval;
477 memset(
s->matrix, 0,
sizeof(
s->matrix));
479 s->clev,
s->slev,
s->lfe_mix_level,
480 maxval,
s->rematrix_volume, (
double*)
s->matrix,
481 s->matrix[1] -
s->matrix[0],
s->matrix_encoding,
s);
487 s->matrix_flt[
i][j] =
s->matrix[
i][j];
495 int nb_in =
s->used_ch_layout.nb_channels;
496 int nb_out =
s->out.ch_count;
500 if (!
s->rematrix_custom) {
507 s->native_matrix =
av_calloc(nb_in * nb_out,
sizeof(
int));
509 if (!
s->native_matrix || !
s->native_one)
511 for (
i = 0;
i < nb_out;
i++) {
515 for (j = 0; j < nb_in; j++) {
516 double target =
s->matrix[
i][j] * 32768 + rem;
517 ((
int*)
s->native_matrix)[
i * nb_in + j] =
lrintf(target);
518 rem += target - ((
int*)
s->native_matrix)[
i * nb_in + j];
519 sum +=
FFABS(((
int*)
s->native_matrix)[
i * nb_in + j]);
521 maxsum =
FFMAX(maxsum, sum);
523 *((
int*)
s->native_one) = 32768;
524 if (maxsum <= 32768) {
534 s->native_matrix =
av_calloc(nb_in * nb_out,
sizeof(
float));
536 if (!
s->native_matrix || !
s->native_one)
538 for (
i = 0;
i < nb_out;
i++)
539 for (j = 0; j < nb_in; j++)
540 ((
float*)
s->native_matrix)[
i * nb_in + j] =
s->matrix[
i][j];
541 *((
float*)
s->native_one) = 1.0;
546 s->native_matrix =
av_calloc(nb_in * nb_out,
sizeof(
double));
548 if (!
s->native_matrix || !
s->native_one)
550 for (
i = 0;
i < nb_out;
i++)
551 for (j = 0; j < nb_in; j++)
552 ((
double*)
s->native_matrix)[
i * nb_in + j] =
s->matrix[
i][j];
553 *((
double*)
s->native_one) = 1.0;
561 s->native_matrix =
av_calloc(nb_in * nb_out,
sizeof(
int));
562 if (!
s->native_matrix) {
566 for (
i = 0;
i < nb_out;
i++) {
569 for (j = 0; j < nb_in; j++) {
570 double target =
s->matrix[
i][j] * 32768 + rem;
571 ((
int*)
s->native_matrix)[
i * nb_in + j] =
lrintf(target);
572 rem += target - ((
int*)
s->native_matrix)[
i * nb_in + j];
575 *((
int*)
s->native_one) = 32768;
585 s->matrix32[
i][j]=
lrintf(
s->matrix[
i][j] * 32768);
587 s->matrix_ch[
i][++ch_in]= j;
589 s->matrix_ch[
i][0]= ch_in;
592 #if ARCH_X86 && HAVE_X86ASM && HAVE_MMX
607 int out_i, in_i,
i, j;
612 s->mix_any_f(
out->ch, (
const uint8_t **)in->
ch,
s->native_matrix,
len);
616 if(
s->mix_2_1_simd ||
s->mix_1_1_simd){
618 off = len1 *
out->bps;
624 for(out_i=0; out_i<
out->ch_count; out_i++){
625 switch(
s->matrix_ch[out_i][0]){
631 in_i=
s->matrix_ch[out_i][1];
632 if(
s->matrix[out_i][in_i]!=1.0){
633 if(
s->mix_1_1_simd && len1)
634 s->mix_1_1_simd(
out->ch[out_i] , in->
ch[in_i] ,
s->native_simd_matrix, in->
ch_count*out_i + in_i, len1);
636 s->mix_1_1_f (
out->ch[out_i]+off, in->
ch[in_i]+off,
s->native_matrix, in->
ch_count*out_i + in_i,
len-len1);
638 memcpy(
out->ch[out_i], in->
ch[in_i],
len*
out->bps);
640 out->ch[out_i]= in->
ch[in_i];
644 int in_i1 =
s->matrix_ch[out_i][1];
645 int in_i2 =
s->matrix_ch[out_i][2];
646 if(
s->mix_2_1_simd && len1)
647 s->mix_2_1_simd(
out->ch[out_i] , in->
ch[in_i1] , in->
ch[in_i2] ,
s->native_simd_matrix, in->
ch_count*out_i + in_i1, in->
ch_count*out_i + in_i2, len1);
649 s->mix_2_1_f (
out->ch[out_i] , in->
ch[in_i1] , in->
ch[in_i2] ,
s->native_matrix, in->
ch_count*out_i + in_i1, in->
ch_count*out_i + in_i2, len1);
651 s->mix_2_1_f (
out->ch[out_i]+off, in->
ch[in_i1]+off, in->
ch[in_i2]+off,
s->native_matrix, in->
ch_count*out_i + in_i1, in->
ch_count*out_i + in_i2,
len-len1);
657 for(j=0; j<
s->matrix_ch[out_i][0]; j++){
658 in_i=
s->matrix_ch[out_i][1+j];
659 v+= ((
float*)in->
ch[in_i])[
i] *
s->matrix_flt[out_i][in_i];
661 ((
float*)
out->ch[out_i])[
i]= v;
666 for(j=0; j<
s->matrix_ch[out_i][0]; j++){
667 in_i=
s->matrix_ch[out_i][1+j];
668 v+= ((
double*)in->
ch[in_i])[
i] *
s->matrix[out_i][in_i];
670 ((
double*)
out->ch[out_i])[
i]= v;
675 for(j=0; j<
s->matrix_ch[out_i][0]; j++){
676 in_i=
s->matrix_ch[out_i][1+j];
677 v+= ((int16_t*)in->
ch[in_i])[
i] *
s->matrix32[out_i][in_i];
679 ((int16_t*)
out->ch[out_i])[
i]= (v + 16384)>>15;
void() mix_any_func_type(uint8_t **out, const uint8_t **in1, void *coeffp, integer len)
#define FF_ENABLE_DEPRECATION_WARNINGS
@ AV_SAMPLE_FMT_FLTP
float, planar
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_CH_LAYOUT_7POINT1_WIDE_BACK
#define AV_CHANNEL_LAYOUT_STEREO_DOWNMIX
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define AV_CHANNEL_LAYOUT_STEREO
#define NUM_NAMED_CHANNELS
#define AV_CH_TOP_FRONT_RIGHT
enum AVChannel av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx)
Get the channel with the given index in a channel layout.
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
int swri_rematrix_init_x86(struct SwrContext *s)
#define AV_LOG_VERBOSE
Detailed information.
static int sane_layout(AVChannelLayout *ch_layout)
#define AV_CH_TOP_FRONT_LEFT
enum AVChannelOrder order
Channel order used in this layout.
uint64_t mask
This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used for AV_CHANNEL_ORDER_AMBISONIC ...
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
int nb_channels
Number of channels in this layout.
int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
Set a customized remix matrix.
#define FRONT_LEFT_OF_CENTER
#define AV_CH_LAYOUT_STEREO
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int even(int64_t layout)
#define FF_ARRAY_ELEMS(a)
@ AV_MATRIX_ENCODING_DOLBY
#define AV_CH_LOW_FREQUENCY
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
FF_ENABLE_DEPRECATION_WARNINGS int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
#define AV_CH_LAYOUT_STEREO_DOWNMIX
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_cold int auto_matrix(SwrContext *s)
The libswresample context.
uint8_t * ch[SWR_CH_MAX]
samples buffer per channel
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout, double center_mix_level, double surround_mix_level, double lfe_mix_level, double maxval, double rematrix_volume, double *matrix_param, ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
Generate a channel mixing matrix.
static __device__ float fabs(float a)
#define AV_CH_FRONT_CENTER
#define AV_CH_FRONT_LEFT_OF_CENTER
#define AV_CHANNEL_LAYOUT_22POINT2
int ch_count
number of channels
static void copy_double(SilenceRemoveContext *s, AVFrame *out, AVFrame *in, int ch, int out_offset, int in_offset)
void() mix_2_1_func_type(void *out, const void *in1, const void *in2, void *coeffp, integer index1, integer index2, integer len)
An AVChannelLayout holds information about the channel layout of audio data.
#define FF_API_OLD_CHANNEL_LAYOUT
av_cold void swri_rematrix_free(SwrContext *s)
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
#define AV_CH_FRONT_RIGHT_OF_CENTER
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel layout
void() mix_1_1_func_type(void *out, const void *in, void *coeffp, integer index, integer len)
#define FRONT_RIGHT_OF_CENTER
#define i(width, name, range_min, range_max)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
int av_channel_name(char *buf, size_t buf_size, enum AVChannel channel_id)
Get a human readable string in an abbreviated form describing a given channel.
#define AV_CH_BACK_CENTER
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_calloc(size_t nmemb, size_t size)
#define AV_CH_LAYOUT_SURROUND
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout, uint64_t mask)
Find out what channels from a given set are present in a channel layout, without regard for their pos...
int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, enum AVChannel channel)
Get the index of a given channel in a channel layout.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
@ AV_SAMPLE_FMT_DBLP
double, planar
av_cold int swri_rematrix_init(SwrContext *s)
#define AV_CH_FRONT_RIGHT
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
#define FF_DISABLE_DEPRECATION_WARNINGS
@ AV_CHAN_TOP_FRONT_CENTER
#define AV_CHANNEL_LAYOUT_MONO
union AVChannelLayout::@314 u
Details about which channels are present in this layout.
static void copy_float(SilenceRemoveContext *s, AVFrame *out, AVFrame *in, int ch, int out_offset, int in_offset)
@ AV_MATRIX_ENCODING_DPLII
static int clean_layout(AVChannelLayout *out, const AVChannelLayout *in, void *s)