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;
74 for (out = 0; out < nb_out; out++) {
75 for (in = 0; in < nb_in; in++)
85 if(layout&(layout-1))
return 1;
118 double center_mix_level,
double surround_mix_level,
119 double lfe_mix_level,
double maxval,
120 double rematrix_volume,
double *matrix_param,
125 int64_t unaccounted, in_ch_layout, out_ch_layout;
129 in_ch_layout =
clean_layout(log_context, in_ch_layout_param);
130 out_ch_layout =
clean_layout(log_context, out_ch_layout_param);
137 if( in_ch_layout == AV_CH_LAYOUT_STEREO_DOWNMIX
138 && (out_ch_layout & AV_CH_LAYOUT_STEREO_DOWNMIX) == 0
144 av_log(log_context,
AV_LOG_ERROR,
"Input channel layout '%s' is not supported\n", buf);
150 av_log(log_context,
AV_LOG_ERROR,
"Output channel layout '%s' is not supported\n", buf);
155 if(in_ch_layout & out_ch_layout & (1ULL<<i))
159 unaccounted= in_ch_layout & ~out_ch_layout;
167 if(in_ch_layout & AV_CH_LAYOUT_STEREO) {
178 if(out_ch_layout & AV_CH_FRONT_CENTER){
181 if(in_ch_layout & AV_CH_FRONT_CENTER)
197 if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
208 }
else if(out_ch_layout & AV_CH_FRONT_CENTER){
214 if(out_ch_layout & AV_CH_BACK_CENTER){
218 if(in_ch_layout & AV_CH_SIDE_LEFT){
240 }
else if(out_ch_layout & AV_CH_FRONT_CENTER){
248 if(out_ch_layout & AV_CH_BACK_LEFT){
251 if (in_ch_layout & AV_CH_BACK_LEFT) {
258 }
else if(out_ch_layout & AV_CH_BACK_CENTER){
276 }
else if(out_ch_layout & AV_CH_FRONT_CENTER){
287 }
else if(out_ch_layout & AV_CH_FRONT_CENTER){
295 if (out_ch_layout & AV_CH_FRONT_CENTER) {
304 for(out_i=i=0; i<64; i++){
307 if((out_ch_layout & (1ULL<<i)) == 0)
310 if((in_ch_layout & (1ULL<<j)) == 0)
313 matrix_param[stride*out_i + in_i] = matrix[i][j];
315 matrix_param[stride*out_i + in_i] = i == j && (in_ch_layout & out_ch_layout & (1ULL<<i));
316 sum += fabs(matrix_param[stride*out_i + in_i]);
319 maxcoef=
FFMAX(maxcoef, sum);
322 if(rematrix_volume < 0)
323 maxcoef = -rematrix_volume;
325 if(maxcoef > maxval || rematrix_volume < 0){
329 matrix_param[stride*i + j] /= maxcoef;
333 if(rematrix_volume > 0){
336 matrix_param[stride*i + j] *= rematrix_volume;
400 for (i = 0; i < nb_out; i++) {
404 for (j = 0; j < nb_in; j++) {
405 double target = s->
matrix[i][j] * 32768 + rem;
410 maxsum =
FFMAX(maxsum, sum);
413 if (maxsum <= 32768) {
427 for (i = 0; i < nb_out; i++)
428 for (j = 0; j < nb_in; j++)
439 for (i = 0; i < nb_out; i++)
440 for (j = 0; j < nb_in; j++)
472 if(HAVE_YASM && HAVE_MMX)
486 int out_i, in_i, i, j;
497 off = len1 * out->
bps;
503 for(out_i=0; out_i<out->
ch_count; out_i++){
511 if(s->
matrix[out_i][in_i]!=1.0){
517 memcpy(out->
ch[out_i], in->
ch[in_i], len*out->
bps);
519 out->
ch[out_i]= in->
ch[in_i];
534 for(i=0; i<
len; i++){
538 v+= ((
float*)in->
ch[in_i])[i] * s->
matrix_flt[out_i][in_i];
540 ((
float*)out->
ch[out_i])[i]= v;
543 for(i=0; i<
len; i++){
547 v+= ((
double*)in->
ch[in_i])[i] * s->
matrix[out_i][in_i];
549 ((
double*)out->
ch[out_i])[i]= v;
552 for(i=0; i<
len; i++){
556 v+= ((int16_t*)in->
ch[in_i])[i] * s->
matrix32[out_i][in_i];
558 ((int16_t*)out->
ch[out_i])[i]= (v + 16384)>>15;
struct AudioConvert * in_convert
input conversion context
enum AVSampleFormat int_sample_fmt
internal sample format (AV_SAMPLE_FMT_FLTP or AV_SAMPLE_FMT_S16P)
Audio buffer used for intermediate storage between conversion phases.
#define FRONT_RIGHT_OF_CENTER
#define AV_CH_LAYOUT_SURROUND
int ch_count
number of channels
void( mix_2_1_func_type)(void *out, const void *in1, const void *in2, void *coeffp, integer index1, integer index2, integer len)
int rematrix_custom
flag to indicate that a custom matrix has been defined
int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy)
void( mix_1_1_func_type)(void *out, const void *in, void *coeffp, integer index, integer len)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define AV_CH_LAYOUT_STEREO
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 clean_layout(void *s, int64_t layout)
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
av_cold int swri_rematrix_init(SwrContext *s)
enum AVSampleFormat fmt
sample format
#define AV_CH_LOW_FREQUENCY
uint8_t * native_simd_one
#define AV_LOG_VERBOSE
Detailed information.
enum AVSampleFormat out_sample_fmt
output sample format
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int matrix_encoding
matrixed stereo encoding
float slev
surround mixing level
int64_t user_in_ch_layout
User set input channel layout.
The libswresample context.
int swri_rematrix_init_x86(struct SwrContext *s)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
float clev
center mixing level
simple assert() macros that are a bit more flexible than ISO C assert().
mix_2_1_func_type * mix_2_1_simd
#define NUM_NAMED_CHANNELS
int32_t matrix32[SWR_CH_MAX][SWR_CH_MAX]
17.15 fixed point rematrixing coefficients
AudioData midbuf
intermediate audio data (postin/preout)
audio channel layout utility functions
#define AV_CH_LAYOUT_STEREO_DOWNMIX
#define FRONT_LEFT_OF_CENTER
int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
Set a customized remix matrix.
mix_1_1_func_type * mix_1_1_f
mix_1_1_func_type * mix_1_1_simd
int64_t out_ch_layout
output channel layout
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AV_CH_FRONT_LEFT_OF_CENTER
mix_any_func_type * mix_any_f
#define AV_CH_FRONT_CENTER
#define FF_ARRAY_ELEMS(a)
#define AV_CH_FRONT_RIGHT_OF_CENTER
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.
static av_cold int auto_matrix(SwrContext *s)
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
float matrix_flt[SWR_CH_MAX][SWR_CH_MAX]
single precision floating point rematrixing coefficients
static int sane_layout(int64_t layout)
#define AV_CH_BACK_CENTER
double matrix[SWR_CH_MAX][SWR_CH_MAX]
floating point rematrixing coefficients
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
int64_t in_ch_layout
input channel layout
GLint GLenum GLboolean GLsizei stride
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
uint8_t * native_simd_matrix
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
Get the channel with the given index in channel_layout.
float lfe_mix_level
LFE mixing level.
void( mix_any_func_type)(uint8_t **out, const uint8_t **in1, void *coeffp, integer len)
const char * av_get_channel_name(uint64_t channel)
Get the name of a given channel.
av_cold void swri_rematrix_free(SwrContext *s)
float rematrix_maxval
maximum value for rematrixing output
float rematrix_volume
rematrixing volume coefficient
mix_2_1_func_type * mix_2_1_f
#define AV_CH_FRONT_RIGHT
static int even(int64_t layout)
uint8_t matrix_ch[SWR_CH_MAX][SWR_CH_MAX+1]
Lists of input channels per output channel that have non zero rematrixing coefficients.
uint8_t * ch[SWR_CH_MAX]
samples buffer per channel
int64_t user_out_ch_layout
User set output channel layout.