aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/ac3dsp.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2015-10-28 15:38:22 +0100
committerDiego Biurrun <diego@biurrun.de>2016-10-01 00:46:25 +0200
commitb57e38f52cc3f31a27105c28887d57cd6812c3eb (patch)
treee37260a47617bb608972ae3169b90feb43c270e6 /libavcodec/ac3dsp.c
parenta9ba59591ed509fb7e6decfde8da4cbfd4ddf4b8 (diff)
downloadffmpeg-b57e38f52cc3f31a27105c28887d57cd6812c3eb.tar.gz
ac3dsp: x86: Replace inline asm for in-decoder downmixing with standalone asm
Adds a wrapper function for downmixing which detects channel count changes and updates the selected downmix function accordingly. Simplification and porting to current x86inc infrastructure by Diego Biurrun. Signed-off-by: Diego Biurrun <diego@biurrun.de>
Diffstat (limited to 'libavcodec/ac3dsp.c')
-rw-r--r--libavcodec/ac3dsp.c112
1 files changed, 75 insertions, 37 deletions
diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c
index 8eae5ad866..440bd1a991 100644
--- a/libavcodec/ac3dsp.c
+++ b/libavcodec/ac3dsp.c
@@ -171,49 +171,53 @@ static void ac3_extract_exponents_c(uint8_t *exp, int32_t *coef, int nb_coefs)
}
}
-static void ac3_downmix_c(float **samples, float **matrix,
- int out_ch, int in_ch, int len)
+static void ac3_downmix_5_to_2_symmetric_c(float **samples, float **matrix,
+ int len)
{
- int **matrix_cmp = (int **)matrix;
- int i, j;
+ int i;
float v0, v1;
+ float front_mix = matrix[0][0];
+ float center_mix = matrix[0][1];
+ float surround_mix = matrix[0][3];
- if (in_ch == 5 && out_ch == 2 &&
- !(matrix_cmp[1][0] | matrix_cmp[0][2] |
- matrix_cmp[1][3] | matrix_cmp[0][4] |
- (matrix_cmp[0][1] ^ matrix_cmp[1][1]) |
- (matrix_cmp[0][0] ^ matrix_cmp[1][2]))) {
- float front_mix = matrix[0][0];
- float center_mix = matrix[0][1];
- float surround_mix = matrix[0][3];
+ for (i = 0; i < len; i++) {
+ v0 = samples[0][i] * front_mix +
+ samples[1][i] * center_mix +
+ samples[3][i] * surround_mix;
- for (i = 0; i < len; i++) {
- v0 = samples[0][i] * front_mix +
- samples[1][i] * center_mix +
- samples[3][i] * surround_mix;
+ v1 = samples[1][i] * center_mix +
+ samples[2][i] * front_mix +
+ samples[4][i] * surround_mix;
- v1 = samples[1][i] * center_mix +
- samples[2][i] * front_mix +
- samples[4][i] * surround_mix;
+ samples[0][i] = v0;
+ samples[1][i] = v1;
+ }
+}
- samples[0][i] = v0;
- samples[1][i] = v1;
- }
- } else if (in_ch == 5 && out_ch == 1 &&
- matrix_cmp[0][0] == matrix_cmp[0][2] &&
- matrix_cmp[0][3] == matrix_cmp[0][4]) {
- float front_mix = matrix[0][0];
- float center_mix = matrix[0][1];
- float surround_mix = matrix[0][3];
+static void ac3_downmix_5_to_1_symmetric_c(float **samples, float **matrix,
+ int len)
+{
+ int i;
+ float front_mix = matrix[0][0];
+ float center_mix = matrix[0][1];
+ float surround_mix = matrix[0][3];
- for (i = 0; i < len; i++) {
- samples[0][i] = samples[0][i] * front_mix +
- samples[1][i] * center_mix +
- samples[2][i] * front_mix +
- samples[3][i] * surround_mix +
- samples[4][i] * surround_mix;
- }
- } else if (out_ch == 2) {
+ for (i = 0; i < len; i++) {
+ samples[0][i] = samples[0][i] * front_mix +
+ samples[1][i] * center_mix +
+ samples[2][i] * front_mix +
+ samples[3][i] * surround_mix +
+ samples[4][i] * surround_mix;
+ }
+}
+
+static void ac3_downmix_c(float **samples, float **matrix,
+ int out_ch, int in_ch, int len)
+{
+ int i, j;
+ float v0, v1;
+
+ if (out_ch == 2) {
for (i = 0; i < len; i++) {
v0 = v1 = 0.0f;
for (j = 0; j < in_ch; j++) {
@@ -246,6 +250,38 @@ static void apply_window_int16_c(int16_t *output, const int16_t *input,
}
}
+void ff_ac3dsp_downmix(AC3DSPContext *c, float **samples, float **matrix,
+ int out_ch, int in_ch, int len)
+{
+ if (c->in_channels != in_ch || c->out_channels != out_ch) {
+ int **matrix_cmp = (int **)matrix;
+
+ c->in_channels = in_ch;
+ c->out_channels = out_ch;
+ c->downmix = NULL;
+
+ if (in_ch == 5 && out_ch == 2 &&
+ !(matrix_cmp[1][0] | matrix_cmp[0][2] |
+ matrix_cmp[1][3] | matrix_cmp[0][4] |
+ (matrix_cmp[0][1] ^ matrix_cmp[1][1]) |
+ (matrix_cmp[0][0] ^ matrix_cmp[1][2]))) {
+ c->downmix = ac3_downmix_5_to_2_symmetric_c;
+ } else if (in_ch == 5 && out_ch == 1 &&
+ matrix_cmp[0][0] == matrix_cmp[0][2] &&
+ matrix_cmp[0][3] == matrix_cmp[0][4]) {
+ c->downmix = ac3_downmix_5_to_1_symmetric_c;
+ }
+
+ if (ARCH_X86)
+ ff_ac3dsp_set_downmix_x86(c);
+ }
+
+ if (c->downmix)
+ c->downmix(samples, matrix, len);
+ else
+ ac3_downmix_c(samples, matrix, out_ch, in_ch, len);
+}
+
av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
{
c->ac3_exponent_min = ac3_exponent_min_c;
@@ -257,7 +293,9 @@ av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
c->update_bap_counts = ac3_update_bap_counts_c;
c->compute_mantissa_size = ac3_compute_mantissa_size_c;
c->extract_exponents = ac3_extract_exponents_c;
- c->downmix = ac3_downmix_c;
+ c->in_channels = 0;
+ c->out_channels = 0;
+ c->downmix = NULL;
c->apply_window_int16 = apply_window_int16_c;
if (ARCH_ARM)