Skip to content

Commit 740f510

Browse files
committed
swresample: Use double and float for matrixes for best quality and speed
Signed-off-by: Michael Niedermayer <[email protected]>
1 parent dcc506a commit 740f510

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

libswresample/rematrix.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
7373
for (out = 0; out < nb_out; out++) {
7474
for (in = 0; in < nb_in; in++)
7575
s->matrix[out][in] = matrix[in];
76+
if (s->int_sample_fmt == AV_SAMPLE_FMT_FLTP)
77+
for (in = 0; in < nb_in; in++)
78+
s->matrix_flt[out][in] = matrix[in];
7679
matrix += stride;
7780
}
7881
s->rematrix_custom = 1;
@@ -354,6 +357,12 @@ av_cold static int auto_matrix(SwrContext *s)
354357
}
355358
av_log(s, AV_LOG_DEBUG, "\n");
356359
}
360+
if (s->int_sample_fmt == AV_SAMPLE_FMT_FLTP) {
361+
int i;
362+
for (i = 0; i < FF_ARRAY_ELEMS(s->matrix[0])*FF_ARRAY_ELEMS(s->matrix[0]); i++)
363+
s->matrix_flt[0][i] = s->matrix[0][i];
364+
}
365+
357366
return 0;
358367
}
359368

@@ -513,7 +522,7 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
513522
float v=0;
514523
for(j=0; j<s->matrix_ch[out_i][0]; j++){
515524
in_i= s->matrix_ch[out_i][1+j];
516-
v+= ((float*)in->ch[in_i])[i] * s->matrix[out_i][in_i];
525+
v+= ((float*)in->ch[in_i])[i] * s->matrix_flt[out_i][in_i];
517526
}
518527
((float*)out->ch[out_i])[i]= v;
519528
}

libswresample/swresample_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ struct SwrContext {
168168
struct ResampleContext *resample; ///< resampling context
169169
struct Resampler const *resampler; ///< resampler virtual function table
170170

171-
float matrix[SWR_CH_MAX][SWR_CH_MAX]; ///< floating point rematrixing coefficients
171+
double matrix[SWR_CH_MAX][SWR_CH_MAX]; ///< floating point rematrixing coefficients
172+
float matrix_flt[SWR_CH_MAX][SWR_CH_MAX]; ///< single precision floating point rematrixing coefficients
172173
uint8_t *native_matrix;
173174
uint8_t *native_one;
174175
uint8_t *native_simd_one;

0 commit comments

Comments
 (0)