63 int out_channels,
int ptr_align,
int samples_align,
74 if (ptr_align == 1 && samples_align == 1) {
82 snprintf(chan_str,
sizeof(chan_str),
"[%d to %d] ",
83 in_channels, out_channels);
85 snprintf(chan_str,
sizeof(chan_str),
"[%d to any] ",
87 }
else if (out_channels) {
88 snprintf(chan_str,
sizeof(chan_str),
"[any to %d] ",
91 snprintf(chan_str,
sizeof(chan_str),
"[any to any] ");
99 #define MIX_FUNC_NAME(fmt, cfmt) mix_any_ ## fmt ##_## cfmt ##_c
101 #define MIX_FUNC_GENERIC(fmt, cfmt, stype, ctype, sumtype, expr) \
102 static void MIX_FUNC_NAME(fmt, cfmt)(stype **samples, ctype **matrix, \
103 int len, int out_ch, int in_ch) \
106 stype temp[AVRESAMPLE_MAX_CHANNELS]; \
107 for (i = 0; i < len; i++) { \
108 for (out = 0; out < out_ch; out++) { \
110 for (in = 0; in < in_ch; in++) \
111 sum += samples[in][i] * matrix[out][in]; \
114 for (out = 0; out < out_ch; out++) \
115 samples[out][i] = temp[out]; \
122 MIX_FUNC_GENERIC(S16P, Q8, int16_t, int16_t, int32_t, av_clip_int16(sum >> 8))
126 static
void mix_2_to_1_fltp_flt_c(
float **
samples,
float **matrix,
int len,
127 int out_ch,
int in_ch)
129 float *src0 = samples[0];
130 float *src1 = samples[1];
132 float m0 = matrix[0][0];
133 float m1 = matrix[0][1];
136 *dst++ = *src0++ * m0 + *src1++ * m1;
137 *dst++ = *src0++ * m0 + *src1++ * m1;
138 *dst++ = *src0++ * m0 + *src1++ * m1;
139 *dst++ = *src0++ * m0 + *src1++ * m1;
143 *dst++ = *src0++ * m0 + *src1++ * m1;
149 int out_ch,
int in_ch)
151 int16_t *src0 = samples[0];
152 int16_t *src1 = samples[1];
154 float m0 = matrix[0][0];
155 float m1 = matrix[0][1];
158 *dst++ = av_clip_int16(
lrintf(*src0++ * m0 + *src1++ * m1));
159 *dst++ = av_clip_int16(
lrintf(*src0++ * m0 + *src1++ * m1));
160 *dst++ = av_clip_int16(
lrintf(*src0++ * m0 + *src1++ * m1));
161 *dst++ = av_clip_int16(
lrintf(*src0++ * m0 + *src1++ * m1));
165 *dst++ = av_clip_int16(
lrintf(*src0++ * m0 + *src1++ * m1));
171 int out_ch,
int in_ch)
173 int16_t *src0 = samples[0];
174 int16_t *src1 = samples[1];
176 int16_t m0 = matrix[0][0];
177 int16_t m1 = matrix[0][1];
180 *dst++ = (*src0++ * m0 + *src1++ * m1) >> 8;
181 *dst++ = (*src0++ * m0 + *src1++ * m1) >> 8;
182 *dst++ = (*src0++ * m0 + *src1++ * m1) >> 8;
183 *dst++ = (*src0++ * m0 + *src1++ * m1) >> 8;
187 *dst++ = (*src0++ * m0 + *src1++ * m1) >> 8;
193 int out_ch,
int in_ch)
196 float *dst0 = samples[0];
197 float *dst1 = samples[1];
199 float m0 = matrix[0][0];
200 float m1 = matrix[1][0];
226 int out_ch,
int in_ch)
229 float *src0 = samples[0];
230 float *src1 = samples[1];
231 float *src2 = samples[2];
232 float *src3 = samples[3];
233 float *src4 = samples[4];
234 float *src5 = samples[5];
237 float *m0 = matrix[0];
238 float *m1 = matrix[1];
243 *dst0++ = v0 * m0[0] +
249 *dst1++ = v0 * m1[0] +
260 int out_ch,
int in_ch)
263 float *dst0 = samples[0];
264 float *dst1 = samples[1];
265 float *dst2 = samples[2];
266 float *dst3 = samples[3];
267 float *dst4 = samples[4];
268 float *dst5 = samples[5];
275 *dst0++ = v0 * matrix[0][0] + v1 * matrix[0][1];
276 *dst1++ = v0 * matrix[1][0] + v1 * matrix[1][1];
277 *dst2++ = v0 * matrix[2][0] + v1 * matrix[2][1];
278 *dst3++ = v0 * matrix[3][0] + v1 * matrix[3][1];
279 *dst4++ = v0 * matrix[4][0] + v1 * matrix[4][1];
280 *dst5++ = v0 * matrix[5][0] + v1 * matrix[5][1];
311 2, 1, 1, 1,
"C", mix_2_to_1_fltp_flt_c);
374 sizeof(*matrix_dbl));
444 av_dlog(am->
avr,
"audio_mix: %d samples - %d to %d channels (%s)\n",
457 data0[j++] = src->
data[i];
493 #define GET_MATRIX_CONVERT(suffix, scale) \
494 if (!am->matrix_ ## suffix[0]) { \
495 av_log(am->avr, AV_LOG_ERROR, "matrix is not set\n"); \
496 return AVERROR(EINVAL); \
498 for (o = 0, o0 = 0; o < am->out_channels; o++) { \
499 for (i = 0, i0 = 0; i < am->in_channels; i++) { \
500 if (am->input_skip[i] || am->output_zero[o]) \
501 matrix[o * stride + i] = 0.0; \
503 matrix[o * stride + i] = am->matrix_ ## suffix[o0][i0] * \
505 if (!am->input_skip[i]) \
508 if (!am->output_zero[o]) \
544 if (matrix[o * stride + i] != 0.0) {
551 if (o < am->in_channels) {
553 if (matrix[i * stride + o] != 0.0) {
576 if ((o != i && matrix[o * stride + i] != 0.0) ||
577 (o == i && matrix[o * stride + i] != 1.0)) {
585 if (i0 != i && matrix[o * stride + i0] != 0.0) {
602 if (matrix[o * stride + i] != 0.0) {
624 if ((o != i && matrix[o * stride + i] != 0.0) ||
625 (o == i && matrix[o * stride + i] != 1.0)) {
634 if (o0 != i && matrix[o0 * stride + i] != 0.0) {
652 int i, o, i0, o0, ret;
653 char in_layout_name[128];
654 char out_layout_name[128];
672 #define CONVERT_MATRIX(type, expr) \
673 am->matrix_## type[0] = av_mallocz(am->out_matrix_channels * \
674 am->in_matrix_channels * \
675 sizeof(*am->matrix_## type[0])); \
676 if (!am->matrix_## type[0]) \
677 return AVERROR(ENOMEM); \
678 for (o = 0, o0 = 0; o < am->out_channels; o++) { \
679 if (am->output_zero[o] || am->output_skip[o]) \
682 am->matrix_## type[o0] = am->matrix_## type[o0 - 1] + \
683 am->in_matrix_channels; \
684 for (i = 0, i0 = 0; i < am->in_channels; i++) { \
686 if (am->input_skip[i]) \
688 v = matrix[o * stride + i]; \
689 am->matrix_## type[o0][i0] = expr; \
694 am->matrix = (void **)am->matrix_## type;
722 in_layout_name, out_layout_name);