62 ( in_channels == am->
in_channels || in_channels == 0) &&
63 (out_channels == am->
out_channels || out_channels == 0)) {
69 if (ptr_align == 1 && samples_align == 1) {
77 snprintf(chan_str,
sizeof(chan_str),
"[%d to %d] ",
78 in_channels, out_channels);
80 snprintf(chan_str,
sizeof(chan_str),
"[%d to any] ",
82 }
else if (out_channels) {
83 snprintf(chan_str,
sizeof(chan_str),
"[any to %d] ",
89 (in_channels || out_channels) ? chan_str :
"", descr);
93 #define MIX_FUNC_NAME(fmt, cfmt) mix_any_ ## fmt ##_## cfmt ##_c
95 #define MIX_FUNC_GENERIC(fmt, cfmt, stype, ctype, sumtype, expr) \
96 static void MIX_FUNC_NAME(fmt, cfmt)(stype **samples, ctype **matrix, \
97 int len, int out_ch, int in_ch) \
100 stype temp[AVRESAMPLE_MAX_CHANNELS]; \
101 for (i = 0; i < len; i++) { \
102 for (out = 0; out < out_ch; out++) { \
104 for (in = 0; in < in_ch; in++) \
105 sum += samples[in][i] * matrix[out][in]; \
108 for (out = 0; out < out_ch; out++) \
109 samples[out][i] = temp[out]; \
116 MIX_FUNC_GENERIC(S16P, Q8, int16_t, int16_t, int32_t, av_clip_int16(sum >> 8))
120 static
void mix_2_to_1_fltp_flt_c(
float **
samples,
float **matrix,
int len,
121 int out_ch,
int in_ch)
123 float *src0 = samples[0];
124 float *src1 = samples[1];
126 float m0 = matrix[0][0];
127 float m1 = matrix[0][1];
130 *dst++ = *src0++ * m0 + *src1++ * m1;
131 *dst++ = *src0++ * m0 + *src1++ * m1;
132 *dst++ = *src0++ * m0 + *src1++ * m1;
133 *dst++ = *src0++ * m0 + *src1++ * m1;
137 *dst++ = *src0++ * m0 + *src1++ * m1;
143 int out_ch,
int in_ch)
145 int16_t *src0 = samples[0];
146 int16_t *src1 = samples[1];
148 float m0 = matrix[0][0];
149 float m1 = matrix[0][1];
152 *dst++ = av_clip_int16(
lrintf(*src0++ * m0 + *src1++ * m1));
153 *dst++ = av_clip_int16(
lrintf(*src0++ * m0 + *src1++ * m1));
154 *dst++ = av_clip_int16(
lrintf(*src0++ * m0 + *src1++ * m1));
155 *dst++ = av_clip_int16(
lrintf(*src0++ * m0 + *src1++ * m1));
159 *dst++ = av_clip_int16(
lrintf(*src0++ * m0 + *src1++ * m1));
165 int out_ch,
int in_ch)
167 int16_t *src0 = samples[0];
168 int16_t *src1 = samples[1];
170 int16_t m0 = matrix[0][0];
171 int16_t m1 = matrix[0][1];
174 *dst++ = (*src0++ * m0 + *src1++ * m1) >> 8;
175 *dst++ = (*src0++ * m0 + *src1++ * m1) >> 8;
176 *dst++ = (*src0++ * m0 + *src1++ * m1) >> 8;
177 *dst++ = (*src0++ * m0 + *src1++ * m1) >> 8;
181 *dst++ = (*src0++ * m0 + *src1++ * m1) >> 8;
187 int out_ch,
int in_ch)
190 float *dst0 = samples[0];
191 float *dst1 = samples[1];
193 float m0 = matrix[0][0];
194 float m1 = matrix[1][0];
220 int out_ch,
int in_ch)
223 float *src0 = samples[0];
224 float *src1 = samples[1];
225 float *src2 = samples[2];
226 float *src3 = samples[3];
227 float *src4 = samples[4];
228 float *src5 = samples[5];
231 float *m0 = matrix[0];
232 float *m1 = matrix[1];
237 *dst0++ = v0 * m0[0] +
243 *dst1++ = v0 * m1[0] +
254 int out_ch,
int in_ch)
257 float *dst0 = samples[0];
258 float *dst1 = samples[1];
259 float *dst2 = samples[2];
260 float *dst3 = samples[3];
261 float *dst4 = samples[4];
262 float *dst5 = samples[5];
269 *dst0++ = v0 * matrix[0][0] + v1 * matrix[0][1];
270 *dst1++ = v0 * matrix[1][0] + v1 * matrix[1][1];
271 *dst2++ = v0 * matrix[2][0] + v1 * matrix[2][1];
272 *dst3++ = v0 * matrix[3][0] + v1 * matrix[3][1];
273 *dst4++ = v0 * matrix[4][0] + v1 * matrix[4][1];
274 *dst5++ = v0 * matrix[5][0] + v1 * matrix[5][1];
298 2, 1, 1, 1,
"C", mix_2_to_1_fltp_flt_c);
361 char in_layout_name[128];
362 char out_layout_name[128];
364 sizeof(*matrix_dbl));
387 in_layout_name, out_layout_name);
445 av_dlog(am->
avr,
"audio_mix: %d samples - %d to %d channels (%s)\n",
470 #define GET_MATRIX_CONVERT(suffix, scale) \
471 if (!am->matrix_ ## suffix[0]) { \
472 av_log(am->avr, AV_LOG_ERROR, "matrix is not set\n"); \
473 return AVERROR(EINVAL); \
475 for (o = 0; o < am->out_channels; o++) \
476 for (i = 0; i < am->in_channels; i++) \
477 matrix[o * stride + i] = am->matrix_ ## suffix[o][i] * (scale);
512 #define CONVERT_MATRIX(type, expr) \
513 am->matrix_## type[0] = av_mallocz(am->out_channels * am->in_channels * \
514 sizeof(*am->matrix_## type[0])); \
515 if (!am->matrix_## type[0]) \
516 return AVERROR(ENOMEM); \
517 for (o = 0; o < am->out_channels; o++) { \
519 am->matrix_## type[o] = am->matrix_## type[o - 1] + \
521 for (i = 0; i < am->in_channels; i++) { \
522 double v = matrix[o * stride + i]; \
523 am->matrix_## type[o][i] = expr; \
526 am->matrix = (void **)am->matrix_## type;