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;
68 if (!
s ||
s->in_convert)
70 memset(
s->matrix, 0,
sizeof(
s->matrix));
71 memset(
s->matrix_flt, 0,
sizeof(
s->matrix_flt));
72 nb_in = (
s->user_in_ch_count > 0) ?
s->user_in_ch_count :
74 nb_out = (
s->user_out_ch_count > 0) ?
s->user_out_ch_count :
77 for (in = 0; in < nb_in; in++)
78 s->matrix_flt[
out][in] =
s->matrix[
out][in] = matrix[in];
81 s->rematrix_custom = 1;
120 double center_mix_level,
double surround_mix_level,
121 double lfe_mix_level,
double maxval,
122 double rematrix_volume,
double *matrix_param,
127 int64_t unaccounted, in_ch_layout, out_ch_layout;
131 in_ch_layout =
clean_layout(log_context, in_ch_layout_param);
132 out_ch_layout =
clean_layout(log_context, out_ch_layout_param);
149 "Full-on remixing from 22.2 has not yet been implemented! "
150 "Processing the input as '%s'\n",
156 av_log(log_context,
AV_LOG_ERROR,
"Input channel layout '%s' is not supported\n", buf);
162 av_log(log_context,
AV_LOG_ERROR,
"Output channel layout '%s' is not supported\n", buf);
167 if(in_ch_layout & out_ch_layout & (1ULL<<
i))
171 unaccounted= in_ch_layout & ~out_ch_layout;
316 for(out_i=
i=0;
i<64;
i++){
319 if((out_ch_layout & (1ULL<<
i)) == 0)
322 if((in_ch_layout & (1ULL<<j)) == 0)
325 matrix_param[
stride*out_i + in_i] = matrix[
i][j];
327 matrix_param[
stride*out_i + in_i] =
i == j && (in_ch_layout & out_ch_layout & (1ULL<<
i));
328 sum +=
fabs(matrix_param[
stride*out_i + in_i]);
331 maxcoef=
FFMAX(maxcoef, sum);
334 if(rematrix_volume < 0)
335 maxcoef = -rematrix_volume;
337 if(maxcoef > maxval || rematrix_volume < 0){
341 matrix_param[
stride*
i + j] /= maxcoef;
345 if(rematrix_volume > 0){
348 matrix_param[
stride*
i + j] *= rematrix_volume;
371 if (
s->rematrix_maxval > 0) {
372 maxval =
s->rematrix_maxval;
379 memset(
s->matrix, 0,
sizeof(
s->matrix));
381 s->clev,
s->slev,
s->lfe_mix_level,
382 maxval,
s->rematrix_volume, (
double*)
s->matrix,
383 s->matrix[1] -
s->matrix[0],
s->matrix_encoding,
s);
389 s->matrix_flt[
i][j] =
s->matrix[
i][j];
397 int nb_in =
s->used_ch_count;
398 int nb_out =
s->out.ch_count;
402 if (!
s->rematrix_custom) {
409 s->native_matrix =
av_calloc(nb_in * nb_out,
sizeof(
int));
411 if (!
s->native_matrix || !
s->native_one)
413 for (
i = 0;
i < nb_out;
i++) {
417 for (j = 0; j < nb_in; j++) {
418 double target =
s->matrix[
i][j] * 32768 + rem;
419 ((
int*)
s->native_matrix)[
i * nb_in + j] =
lrintf(target);
420 rem += target - ((
int*)
s->native_matrix)[
i * nb_in + j];
421 sum +=
FFABS(((
int*)
s->native_matrix)[
i * nb_in + j]);
423 maxsum =
FFMAX(maxsum, sum);
425 *((
int*)
s->native_one) = 32768;
426 if (maxsum <= 32768) {
436 s->native_matrix =
av_calloc(nb_in * nb_out,
sizeof(
float));
438 if (!
s->native_matrix || !
s->native_one)
440 for (
i = 0;
i < nb_out;
i++)
441 for (j = 0; j < nb_in; j++)
442 ((
float*)
s->native_matrix)[
i * nb_in + j] =
s->matrix[
i][j];
443 *((
float*)
s->native_one) = 1.0;
448 s->native_matrix =
av_calloc(nb_in * nb_out,
sizeof(
double));
450 if (!
s->native_matrix || !
s->native_one)
452 for (
i = 0;
i < nb_out;
i++)
453 for (j = 0; j < nb_in; j++)
454 ((
double*)
s->native_matrix)[
i * nb_in + j] =
s->matrix[
i][j];
455 *((
double*)
s->native_one) = 1.0;
463 s->native_matrix =
av_calloc(nb_in * nb_out,
sizeof(
int));
464 if (!
s->native_matrix) {
468 for (
i = 0;
i < nb_out;
i++) {
471 for (j = 0; j < nb_in; j++) {
472 double target =
s->matrix[
i][j] * 32768 + rem;
473 ((
int*)
s->native_matrix)[
i * nb_in + j] =
lrintf(target);
474 rem += target - ((
int*)
s->native_matrix)[
i * nb_in + j];
477 *((
int*)
s->native_one) = 32768;
487 s->matrix32[
i][j]=
lrintf(
s->matrix[
i][j] * 32768);
489 s->matrix_ch[
i][++ch_in]= j;
491 s->matrix_ch[
i][0]= ch_in;
494 if(HAVE_X86ASM && HAVE_MMX)
508 int out_i, in_i,
i, j;
513 s->mix_any_f(
out->ch, (
const uint8_t **)in->
ch,
s->native_matrix,
len);
517 if(
s->mix_2_1_simd ||
s->mix_1_1_simd){
519 off = len1 *
out->bps;
525 for(out_i=0; out_i<
out->ch_count; out_i++){
526 switch(
s->matrix_ch[out_i][0]){
532 in_i=
s->matrix_ch[out_i][1];
533 if(
s->matrix[out_i][in_i]!=1.0){
534 if(
s->mix_1_1_simd && len1)
535 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);
537 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);
539 memcpy(
out->ch[out_i], in->
ch[in_i],
len*
out->bps);
541 out->ch[out_i]= in->
ch[in_i];
545 int in_i1 =
s->matrix_ch[out_i][1];
546 int in_i2 =
s->matrix_ch[out_i][2];
547 if(
s->mix_2_1_simd && len1)
548 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);
550 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);
552 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);
558 for(j=0; j<
s->matrix_ch[out_i][0]; j++){
559 in_i=
s->matrix_ch[out_i][1+j];
560 v+= ((
float*)in->
ch[in_i])[
i] *
s->matrix_flt[out_i][in_i];
562 ((
float*)
out->ch[out_i])[
i]= v;
567 for(j=0; j<
s->matrix_ch[out_i][0]; j++){
568 in_i=
s->matrix_ch[out_i][1+j];
569 v+= ((
double*)in->
ch[in_i])[
i] *
s->matrix[out_i][in_i];
571 ((
double*)
out->ch[out_i])[
i]= v;
576 for(j=0; j<
s->matrix_ch[out_i][0]; j++){
577 in_i=
s->matrix_ch[out_i][1+j];
578 v+= ((int16_t*)in->
ch[in_i])[
i] *
s->matrix32[out_i][in_i];
580 ((int16_t*)
out->ch[out_i])[
i]= (v + 16384)>>15;
static int64_t clean_layout(void *s, int64_t layout)
void() mix_any_func_type(uint8_t **out, const uint8_t **in1, void *coeffp, integer len)
@ AV_SAMPLE_FMT_FLTP
float, planar
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_CH_LAYOUT_7POINT1_WIDE_BACK
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 NUM_NAMED_CHANNELS
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of 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.
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
#define AV_CH_LAYOUT_22POINT2
#define AV_CH_LAYOUT_STEREO_DOWNMIX
#define av_assert0(cond)
assert() equivalent, that is always enabled.
const char * av_get_channel_name(uint64_t channel)
Get the name of a given channel.
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 ...
static __device__ float fabs(float a)
#define AV_CH_FRONT_CENTER
#define AV_CH_FRONT_LEFT_OF_CENTER
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
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)
av_cold void swri_rematrix_free(SwrContext *s)
#define AV_CH_FRONT_RIGHT_OF_CENTER
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
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.
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
Get the channel with the given index in channel_layout.
#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
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
static void copy_float(SilenceRemoveContext *s, AVFrame *out, AVFrame *in, int ch, int out_offset, int in_offset)
av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout_param, double center_mix_level, double surround_mix_level, double lfe_mix_level, double maxval, double rematrix_volume, double *matrix_param, int stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
Generate a channel mixing matrix.
static int sane_layout(int64_t layout)
@ AV_MATRIX_ENCODING_DPLII