History

avcodec/dca: remove old decoder

Remove all files and functions which are not going to be reused, and disable all functions and FATE tests temporarily which will be.

foo86 committed 10 years ago

Commit 46089961 parent b552f3a29 files · +17 −5064Browse files

Unified · Split

29 files
  1. configure +0 −1
  2. libavcodec/Makefile +0 −3
  3. libavcodec/aarch64/Makefile +2 −4
  4. libavcodec/aarch64/dcadsp_init.c +0 −39
  5. libavcodec/aarch64/dcadsp_neon.S +0 −109
  6. libavcodec/allcodecs.c +1 −1
  7. libavcodec/arm/Makefile +3 −6
  8. libavcodec/arm/dca.h +0 −1
  9. libavcodec/arm/dcadsp_init_arm.c +0 −53
  10. libavcodec/arm/dcadsp_neon.S +0 −64
  11. libavcodec/arm/dcadsp_vfp.S +0 −476
  12. libavcodec/dca.h +2 −285
  13. libavcodec/dca_exss.c +0 −373
  14. libavcodec/dca_xll.c +0 −747
  15. libavcodec/dcadata.c +0 −318
  16. libavcodec/dcadata.h +0 −10
  17. libavcodec/dcadec.c +0 −2067
  18. libavcodec/dcadsp.c +0 −134
  19. libavcodec/dcadsp.h +0 −51
  20. libavcodec/dcamath.h +0 −47
  21. libavcodec/x86/Makefile +2 −4
  22. libavcodec/x86/dcadsp.asm +0 −123
  23. libavcodec/x86/dcadsp_init.c +0 −42
  24. tests/checkasm/Makefile +1 −1
  25. tests/checkasm/checkasm.c +2 −3
  26. tests/checkasm/checkasm.h +0 −1
  27. tests/checkasm/dcadsp.c +0 −92
  28. tests/fate/acodec.mak +2 −2
  29. tests/fate/audio.mak +2 −7
configure+0−1
@@ -2271,7 +2271,6 @@ comfortnoise_encoder_select="lpc" · 2270 unmodified lines
2271cook_decoder_select="audiodsp mdct sinewin"2271cook_decoder_select="audiodsp mdct sinewin"
2272cscd_decoder_select="lzo"2272cscd_decoder_select="lzo"
2273cscd_decoder_suggest="zlib"2273cscd_decoder_suggest="zlib"
2274dca_decoder_select="fmtconvert mdct"
2275dds_decoder_select="texturedsp"2274dds_decoder_select="texturedsp"
2276dirac_decoder_select="dirac_parse dwt golomb videodsp mpegvideoenc"2275dirac_decoder_select="dirac_parse dwt golomb videodsp mpegvideoenc"
2277dnxhd_decoder_select="blockdsp idctdsp"2276dnxhd_decoder_select="blockdsp idctdsp"
libavcodec/Makefile+0−3
@@ -222,9 +222,6 @@ OBJS-$(CONFIG_COMFORTNOISE_ENCODER) += cngenc.o · 221 unmodified lines
222OBJS-$(CONFIG_CPIA_DECODER) += cpia.o222OBJS-$(CONFIG_CPIA_DECODER) += cpia.o
223OBJS-$(CONFIG_CSCD_DECODER) += cscd.o223OBJS-$(CONFIG_CSCD_DECODER) += cscd.o
224OBJS-$(CONFIG_CYUV_DECODER) += cyuv.o224OBJS-$(CONFIG_CYUV_DECODER) += cyuv.o
225OBJS-$(CONFIG_DCA_DECODER) += dcadec.o dca.o dcadsp.o \
226 dcadata.o dca_exss.o \
227 dca_xll.o synth_filter.o
228OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o dca.o dcadata.o225OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o dca.o dcadata.o
229OBJS-$(CONFIG_DDS_DECODER) += dds.o226OBJS-$(CONFIG_DDS_DECODER) += dds.o
230OBJS-$(CONFIG_DIRAC_DECODER) += diracdec.o dirac.o diracdsp.o \227OBJS-$(CONFIG_DIRAC_DECODER) += diracdec.o dirac.o diracdsp.o \
libavcodec/aarch64/Makefile+2−4
@@ -1,5 +1,4 @@
1OBJS-$(CONFIG_DCA_DECODER) += aarch64/dcadsp_init.o \1#OBJS-$(CONFIG_DCA_DECODER) += aarch64/synth_filter_init.o
2 aarch64/synth_filter_init.o
3OBJS-$(CONFIG_FFT) += aarch64/fft_init_aarch64.o2OBJS-$(CONFIG_FFT) += aarch64/fft_init_aarch64.o
4OBJS-$(CONFIG_FMTCONVERT) += aarch64/fmtconvert_init.o3OBJS-$(CONFIG_FMTCONVERT) += aarch64/fmtconvert_init.o
5OBJS-$(CONFIG_H264CHROMA) += aarch64/h264chroma_init_aarch64.o4OBJS-$(CONFIG_H264CHROMA) += aarch64/h264chroma_init_aarch64.o
@@ -18,8 +17,7 @@ OBJS-$(CONFIG_VORBIS_DECODER) += aarch64/vorbisdsp_init.o · 12 unmodified lines
18 17
19ARMV8-OBJS-$(CONFIG_VIDEODSP) += aarch64/videodsp.o18ARMV8-OBJS-$(CONFIG_VIDEODSP) += aarch64/videodsp.o
20 19
21NEON-OBJS-$(CONFIG_DCA_DECODER) += aarch64/dcadsp_neon.o \20#NEON-OBJS-$(CONFIG_DCA_DECODER) += aarch64/synth_filter_neon.o
22 aarch64/synth_filter_neon.o
23NEON-OBJS-$(CONFIG_FFT) += aarch64/fft_neon.o21NEON-OBJS-$(CONFIG_FFT) += aarch64/fft_neon.o
24NEON-OBJS-$(CONFIG_FMTCONVERT) += aarch64/fmtconvert_neon.o22NEON-OBJS-$(CONFIG_FMTCONVERT) += aarch64/fmtconvert_neon.o
25NEON-OBJS-$(CONFIG_H264CHROMA) += aarch64/h264cmc_neon.o23NEON-OBJS-$(CONFIG_H264CHROMA) += aarch64/h264cmc_neon.o
libavcodec/aarch64/dcadsp_init.c+0−39
@@ -1,39 +0,0 @@
1/*
2 * Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include "libavutil/aarch64/cpu.h"
24#include "libavutil/attributes.h"
25#include "libavutil/internal.h"
26#include "libavcodec/dcadsp.h"
27
28void ff_dca_lfe_fir0_neon(float *out, const float *in, const float *coefs);
29void ff_dca_lfe_fir1_neon(float *out, const float *in, const float *coefs);
30
31av_cold void ff_dcadsp_init_aarch64(DCADSPContext *s)
32{
33 int cpu_flags = av_get_cpu_flags();
34
35 if (have_neon(cpu_flags)) {
36 s->lfe_fir[0] = ff_dca_lfe_fir0_neon;
37 s->lfe_fir[1] = ff_dca_lfe_fir1_neon;
38 }
39}
libavcodec/aarch64/dcadsp_neon.S+0−109
@@ -1,109 +0,0 @@
1/*
2 * Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
3 * Copyright (c) 2015 Janne Grunau <janne-libav@jannau.net>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "libavutil/aarch64/asm.S"
23
24function ff_dca_lfe_fir0_neon, export=1
25 mov x3, #32 // decifactor
26 sub x1, x1, #7*4
27 add x4, x0, #2*32*4 - 16 // out2
28 mov x7, #-16
29
30 ld1 {v0.4s,v1.4s}, [x1]
31 // reverse [-num_coeffs + 1, 0]
32 ext v3.16b, v0.16b, v0.16b, #8
33 ext v2.16b, v1.16b, v1.16b, #8
34 rev64 v3.4s, v3.4s
35 rev64 v2.4s, v2.4s
361:
37 ld1 {v4.4s,v5.4s}, [x2], #32
38 ld1 {v6.4s,v7.4s}, [x2], #32
39 subs x3, x3, #4
40 fmul v16.4s, v2.4s, v4.4s
41 fmul v23.4s, v0.4s, v4.4s
42 fmul v17.4s, v2.4s, v6.4s
43 fmul v22.4s, v0.4s, v6.4s
44
45 fmla v16.4s, v3.4s, v5.4s
46 fmla v23.4s, v1.4s, v5.4s
47 ld1 {v4.4s,v5.4s}, [x2], #32
48 fmla v17.4s, v3.4s, v7.4s
49 fmla v22.4s, v1.4s, v7.4s
50 ld1 {v6.4s,v7.4s}, [x2], #32
51 fmul v18.4s, v2.4s, v4.4s
52 fmul v21.4s, v0.4s, v4.4s
53 fmul v19.4s, v2.4s, v6.4s
54 fmul v20.4s, v0.4s, v6.4s
55
56 fmla v18.4s, v3.4s, v5.4s
57 fmla v21.4s, v1.4s, v5.4s
58 fmla v19.4s, v3.4s, v7.4s
59 fmla v20.4s, v1.4s, v7.4s
60
61 faddp v16.4s, v16.4s, v17.4s
62 faddp v18.4s, v18.4s, v19.4s
63 faddp v20.4s, v20.4s, v21.4s
64 faddp v22.4s, v22.4s, v23.4s
65 faddp v16.4s, v16.4s, v18.4s
66 faddp v20.4s, v20.4s, v22.4s
67
68 st1 {v16.4s}, [x0], #16
69 st1 {v20.4s}, [x4], x7
70 b.gt 1b
71
72 ret
73endfunc
74
75function ff_dca_lfe_fir1_neon, export=1
76 mov x3, #64 // decifactor
77 sub x1, x1, #3*4
78 add x4, x0, #2*64*4 - 16 // out2
79 mov x7, #-16
80
81 ld1 {v0.4s}, [x1]
82 // reverse [-num_coeffs + 1, 0]
83 ext v1.16b, v0.16b, v0.16b, #8
84 rev64 v1.4s, v1.4s
85
861:
87 ld1 {v4.4s,v5.4s}, [x2], #32
88 ld1 {v6.4s,v7.4s}, [x2], #32
89 subs x3, x3, #4
90 fmul v16.4s, v1.4s, v4.4s
91 fmul v23.4s, v0.4s, v4.4s
92 fmul v17.4s, v1.4s, v5.4s
93 fmul v22.4s, v0.4s, v5.4s
94 fmul v18.4s, v1.4s, v6.4s
95 fmul v21.4s, v0.4s, v6.4s
96 fmul v19.4s, v1.4s, v7.4s
97 fmul v20.4s, v0.4s, v7.4s
98 faddp v16.4s, v16.4s, v17.4s
99 faddp v18.4s, v18.4s, v19.4s
100 faddp v20.4s, v20.4s, v21.4s
101 faddp v22.4s, v22.4s, v23.4s
102 faddp v16.4s, v16.4s, v18.4s
103 faddp v20.4s, v20.4s, v22.4s
104 st1 {v16.4s}, [x0], #16
105 st1 {v20.4s}, [x4], x7
106 b.gt 1b
107
108 ret
109endfunc
libavcodec/allcodecs.c+1−1
@@ -391,7 +391,7 @@ void avcodec_register_all(void) · 390 unmodified lines
391 REGISTER_DECODER(BINKAUDIO_RDFT, binkaudio_rdft);391 REGISTER_DECODER(BINKAUDIO_RDFT, binkaudio_rdft);
392 REGISTER_DECODER(BMV_AUDIO, bmv_audio);392 REGISTER_DECODER(BMV_AUDIO, bmv_audio);
393 REGISTER_DECODER(COOK, cook);393 REGISTER_DECODER(COOK, cook);
394 REGISTER_ENCDEC (DCA, dca);394 REGISTER_ENCODER(DCA, dca);
395 REGISTER_DECODER(DSD_LSBF, dsd_lsbf);395 REGISTER_DECODER(DSD_LSBF, dsd_lsbf);
396 REGISTER_DECODER(DSD_MSBF, dsd_msbf);396 REGISTER_DECODER(DSD_MSBF, dsd_msbf);
397 REGISTER_DECODER(DSD_LSBF_PLANAR, dsd_lsbf_planar);397 REGISTER_DECODER(DSD_LSBF_PLANAR, dsd_lsbf_planar);
libavcodec/arm/Makefile+3−6
@@ -36,8 +36,7 @@ OBJS-$(CONFIG_VP8DSP) += arm/vp8dsp_init_arm.o · 35 unmodified lines
36# decoders/encoders36# decoders/encoders
37OBJS-$(CONFIG_AAC_DECODER) += arm/aacpsdsp_init_arm.o \37OBJS-$(CONFIG_AAC_DECODER) += arm/aacpsdsp_init_arm.o \
38 arm/sbrdsp_init_arm.o38 arm/sbrdsp_init_arm.o
39OBJS-$(CONFIG_DCA_DECODER) += arm/dcadsp_init_arm.o \39#OBJS-$(CONFIG_DCA_DECODER) += arm/synth_filter_init_arm.o
40 arm/synth_filter_init_arm.o
41OBJS-$(CONFIG_HEVC_DECODER) += arm/hevcdsp_init_arm.o40OBJS-$(CONFIG_HEVC_DECODER) += arm/hevcdsp_init_arm.o
42OBJS-$(CONFIG_MLP_DECODER) += arm/mlpdsp_init_arm.o41OBJS-$(CONFIG_MLP_DECODER) += arm/mlpdsp_init_arm.o
43OBJS-$(CONFIG_RV40_DECODER) += arm/rv40dsp_init_arm.o42OBJS-$(CONFIG_RV40_DECODER) += arm/rv40dsp_init_arm.o
@@ -88,8 +87,7 @@ VFP-OBJS-$(CONFIG_FMTCONVERT) += arm/fmtconvert_vfp.o · 44 unmodified lines
88VFP-OBJS-$(CONFIG_MDCT) += arm/mdct_vfp.o87VFP-OBJS-$(CONFIG_MDCT) += arm/mdct_vfp.o
89 88
90# decoders/encoders89# decoders/encoders
91VFP-OBJS-$(CONFIG_DCA_DECODER) += arm/dcadsp_vfp.o \90#VFP-OBJS-$(CONFIG_DCA_DECODER) += arm/synth_filter_vfp.o
92 arm/synth_filter_vfp.o
93 91
94 92
95# NEON optimizations93# NEON optimizations
@@ -128,8 +126,7 @@ NEON-OBJS-$(CONFIG_VP8DSP) += arm/vp8dsp_init_neon.o \ · 32 unmodified lines
128NEON-OBJS-$(CONFIG_AAC_DECODER) += arm/aacpsdsp_neon.o \126NEON-OBJS-$(CONFIG_AAC_DECODER) += arm/aacpsdsp_neon.o \
129 arm/sbrdsp_neon.o127 arm/sbrdsp_neon.o
130NEON-OBJS-$(CONFIG_LLAUDDSP) += arm/lossless_audiodsp_neon.o128NEON-OBJS-$(CONFIG_LLAUDDSP) += arm/lossless_audiodsp_neon.o
131NEON-OBJS-$(CONFIG_DCA_DECODER) += arm/dcadsp_neon.o \129#NEON-OBJS-$(CONFIG_DCA_DECODER) += arm/synth_filter_neon.o
132 arm/synth_filter_neon.o
133NEON-OBJS-$(CONFIG_HEVC_DECODER) += arm/hevcdsp_init_neon.o \130NEON-OBJS-$(CONFIG_HEVC_DECODER) += arm/hevcdsp_init_neon.o \
134 arm/hevcdsp_deblock_neon.o \131 arm/hevcdsp_deblock_neon.o \
135 arm/hevcdsp_idct_neon.o \132 arm/hevcdsp_idct_neon.o \
libavcodec/arm/dca.h+0−1
@@ -24,7 +24,6 @@ · 23 unmodified lines
24#include <stdint.h>24#include <stdint.h>
25 25
26#include "config.h"26#include "config.h"
27#include "libavcodec/dcadsp.h"
28#include "libavcodec/mathops.h"27#include "libavcodec/mathops.h"
29 28
30#if HAVE_ARMV6_INLINE && AV_GCC_VERSION_AT_LEAST(4,4) && !CONFIG_THUMB29#if HAVE_ARMV6_INLINE && AV_GCC_VERSION_AT_LEAST(4,4) && !CONFIG_THUMB
libavcodec/arm/dcadsp_init_arm.c+0−53
@@ -1,53 +0,0 @@
1/*
2 * Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include "libavutil/arm/cpu.h"
24#include "libavutil/attributes.h"
25#include "libavcodec/dcadsp.h"
26
27void ff_dca_lfe_fir0_neon(float *out, const float *in, const float *coefs);
28void ff_dca_lfe_fir1_neon(float *out, const float *in, const float *coefs);
29
30void ff_dca_lfe_fir32_vfp(float *out, const float *in, const float *coefs);
31void ff_dca_lfe_fir64_vfp(float *out, const float *in, const float *coefs);
32
33void ff_dca_qmf_32_subbands_vfp(float samples_in[32][8], int sb_act,
34 SynthFilterContext *synth, FFTContext *imdct,
35 float synth_buf_ptr[512],
36 int *synth_buf_offset, float synth_buf2[32],
37 const float window[512], float *samples_out,
38 float raXin[32], float scale);
39
40av_cold void ff_dcadsp_init_arm(DCADSPContext *s)
41{
42 int cpu_flags = av_get_cpu_flags();
43
44 if (have_vfp_vm(cpu_flags)) {
45 s->lfe_fir[0] = ff_dca_lfe_fir32_vfp;
46 s->lfe_fir[1] = ff_dca_lfe_fir64_vfp;
47 s->qmf_32_subbands = ff_dca_qmf_32_subbands_vfp;
48 }
49 if (have_neon(cpu_flags)) {
50 s->lfe_fir[0] = ff_dca_lfe_fir0_neon;
51 s->lfe_fir[1] = ff_dca_lfe_fir1_neon;
52 }
53}
libavcodec/arm/dcadsp_neon.S+0−64
@@ -1,64 +0,0 @@
1/*
2 * Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "libavutil/arm/asm.S"
22
23function ff_dca_lfe_fir0_neon, export=1
24 push {r4-r6,lr}
25 mov r3, #32 @ decifactor
26 mov r6, #256/32
27 b dca_lfe_fir
28endfunc
29
30function ff_dca_lfe_fir1_neon, export=1
31 push {r4-r6,lr}
32 mov r3, #64 @ decifactor
33 mov r6, #256/64
34dca_lfe_fir:
35 add r4, r0, r3, lsl #2 @ out2
36 add r5, r2, #256*4-16 @ cf1
37 sub r1, r1, #12
38 mov lr, #-16
391:
40 vmov.f32 q2, #0.0 @ v0
41 vmov.f32 q3, #0.0 @ v1
42 mov r12, r6
432:
44 vld1.32 {q8}, [r2,:128]! @ cf0
45 vld1.32 {q9}, [r5,:128], lr @ cf1
46 vld1.32 {q1}, [r1], lr @ in
47 subs r12, r12, #4
48 vrev64.32 q10, q8
49 vmla.f32 q3, q1, q9
50 vmla.f32 d4, d2, d21
51 vmla.f32 d5, d3, d20
52 bne 2b
53
54 add r1, r1, r6, lsl #2
55 subs r3, r3, #1
56 vadd.f32 d4, d4, d5
57 vadd.f32 d6, d6, d7
58 vpadd.f32 d5, d4, d6
59 vst1.32 {d5[0]}, [r0,:32]!
60 vst1.32 {d5[1]}, [r4,:32]!
61 bne 1b
62
63 pop {r4-r6,pc}
64endfunc
libavcodec/arm/dcadsp_vfp.S+0−476
@@ -1,476 +0,0 @@
1/*
2 * Copyright (c) 2013 RISC OS Open Ltd
3 * Author: Ben Avison <bavison@riscosopen.org>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "libavutil/arm/asm.S"
23
24POUT .req a1
25PIN .req a2
26PCOEF .req a3
27OLDFPSCR .req a4
28COUNTER .req ip
29
30IN0 .req s4
31IN1 .req s5
32IN2 .req s6
33IN3 .req s7
34IN4 .req s0
35IN5 .req s1
36IN6 .req s2
37IN7 .req s3
38COEF0 .req s8 @ coefficient elements
39COEF1 .req s9
40COEF2 .req s10
41COEF3 .req s11
42COEF4 .req s12
43COEF5 .req s13
44COEF6 .req s14
45COEF7 .req s15
46ACCUM0 .req s16 @ double-buffered multiply-accumulate results
47ACCUM4 .req s20
48POST0 .req s24 @ do long-latency post-multiply in this vector in parallel
49POST1 .req s25
50POST2 .req s26
51POST3 .req s27
52
53
54.macro inner_loop decifactor, dir, tail, head
55 .ifc "\dir","up"
56 .set X, 0
57 .set Y, 4
58 .else
59 .set X, 4*JMAX*4 - 4
60 .set Y, -4
61 .endif
62 .ifnc "\head",""
63 vldr COEF0, [PCOEF, #X + (0*JMAX + 0) * Y]
64 vldr COEF1, [PCOEF, #X + (1*JMAX + 0) * Y]
65 vldr COEF2, [PCOEF, #X + (2*JMAX + 0) * Y]
66 vldr COEF3, [PCOEF, #X + (3*JMAX + 0) * Y]
67 .endif
68 .ifnc "\tail",""
69 vadd.f POST0, ACCUM0, ACCUM4 @ vector operation
70 .endif
71 .ifnc "\head",""
72 vmul.f ACCUM0, COEF0, IN0 @ vector = vector * scalar
73 vldr COEF4, [PCOEF, #X + (0*JMAX + 1) * Y]
74 vldr COEF5, [PCOEF, #X + (1*JMAX + 1) * Y]
75 vldr COEF6, [PCOEF, #X + (2*JMAX + 1) * Y]
76 .endif
77 .ifnc "\head",""
78 vldr COEF7, [PCOEF, #X + (3*JMAX + 1) * Y]
79 .ifc "\tail",""
80 vmul.f ACCUM4, COEF4, IN1 @ vector operation
81 .endif
82 vldr COEF0, [PCOEF, #X + (0*JMAX + 2) * Y]
83 vldr COEF1, [PCOEF, #X + (1*JMAX + 2) * Y]
84 .ifnc "\tail",""
85 vmul.f ACCUM4, COEF4, IN1 @ vector operation
86 .endif
87 vldr COEF2, [PCOEF, #X + (2*JMAX + 2) * Y]
88 vldr COEF3, [PCOEF, #X + (3*JMAX + 2) * Y]
89 .endif
90 .ifnc "\tail",""
91 vstmia POUT!, {POST0-POST3}
92 .endif
93 .ifnc "\head",""
94 vmla.f ACCUM0, COEF0, IN2 @ vector = vector * scalar
95 vldr COEF4, [PCOEF, #X + (0*JMAX + 3) * Y]
96 vldr COEF5, [PCOEF, #X + (1*JMAX + 3) * Y]
97 vldr COEF6, [PCOEF, #X + (2*JMAX + 3) * Y]
98 vldr COEF7, [PCOEF, #X + (3*JMAX + 3) * Y]
99 vmla.f ACCUM4, COEF4, IN3 @ vector = vector * scalar
100 .if \decifactor == 32
101 vldr COEF0, [PCOEF, #X + (0*JMAX + 4) * Y]
102 vldr COEF1, [PCOEF, #X + (1*JMAX + 4) * Y]
103 vldr COEF2, [PCOEF, #X + (2*JMAX + 4) * Y]
104 vldr COEF3, [PCOEF, #X + (3*JMAX + 4) * Y]
105 vmla.f ACCUM0, COEF0, IN4 @ vector = vector * scalar
106 vldr COEF4, [PCOEF, #X + (0*JMAX + 5) * Y]
107 vldr COEF5, [PCOEF, #X + (1*JMAX + 5) * Y]
108 vldr COEF6, [PCOEF, #X + (2*JMAX + 5) * Y]
109 vldr COEF7, [PCOEF, #X + (3*JMAX + 5) * Y]
110 vmla.f ACCUM4, COEF4, IN5 @ vector = vector * scalar
111 vldr COEF0, [PCOEF, #X + (0*JMAX + 6) * Y]
112 vldr COEF1, [PCOEF, #X + (1*JMAX + 6) * Y]
113 vldr COEF2, [PCOEF, #X + (2*JMAX + 6) * Y]
114 vldr COEF3, [PCOEF, #X + (3*JMAX + 6) * Y]
115 vmla.f ACCUM0, COEF0, IN6 @ vector = vector * scalar
116 vldr COEF4, [PCOEF, #X + (0*JMAX + 7) * Y]
117 vldr COEF5, [PCOEF, #X + (1*JMAX + 7) * Y]
118 vldr COEF6, [PCOEF, #X + (2*JMAX + 7) * Y]
119 vldr COEF7, [PCOEF, #X + (3*JMAX + 7) * Y]
120 vmla.f ACCUM4, COEF4, IN7 @ vector = vector * scalar
121 .endif
122 .endif
123.endm
124
125.macro dca_lfe_fir decifactor
126function ff_dca_lfe_fir\decifactor\()_vfp, export=1
127 fmrx OLDFPSCR, FPSCR
128 ldr ip, =0x03030000 @ RunFast mode, short vectors of length 4, stride 1
129 fmxr FPSCR, ip
130 vldr IN0, [PIN, #-0*4]
131 vldr IN1, [PIN, #-1*4]
132 vldr IN2, [PIN, #-2*4]
133 vldr IN3, [PIN, #-3*4]
134 .if \decifactor == 32
135 .set JMAX, 8
136 vpush {s16-s31}
137 vldr IN4, [PIN, #-4*4]
138 vldr IN5, [PIN, #-5*4]
139 vldr IN6, [PIN, #-6*4]
140 vldr IN7, [PIN, #-7*4]
141 .else
142 .set JMAX, 4
143 vpush {s16-s27}
144 .endif
145
146 mov COUNTER, #\decifactor/4 - 1
147 inner_loop \decifactor, up,, head
1481: add PCOEF, PCOEF, #4*JMAX*4
149 subs COUNTER, COUNTER, #1
150 inner_loop \decifactor, up, tail, head
151 bne 1b
152 inner_loop \decifactor, up, tail
153
154 mov COUNTER, #\decifactor/4 - 1
155 inner_loop \decifactor, down,, head
1561: sub PCOEF, PCOEF, #4*JMAX*4
157 subs COUNTER, COUNTER, #1
158 inner_loop \decifactor, down, tail, head
159 bne 1b
160 inner_loop \decifactor, down, tail
161
162 .if \decifactor == 32
163 vpop {s16-s31}
164 .else
165 vpop {s16-s27}
166 .endif
167 fmxr FPSCR, OLDFPSCR
168 bx lr
169endfunc
170.endm
171
172 dca_lfe_fir 64
173 .ltorg
174 dca_lfe_fir 32
175
176 .unreq POUT
177 .unreq PIN
178 .unreq PCOEF
179 .unreq OLDFPSCR
180 .unreq COUNTER
181
182 .unreq IN0
183 .unreq IN1
184 .unreq IN2
185 .unreq IN3
186 .unreq IN4
187 .unreq IN5
188 .unreq IN6
189 .unreq IN7
190 .unreq COEF0
191 .unreq COEF1
192 .unreq COEF2
193 .unreq COEF3
194 .unreq COEF4
195 .unreq COEF5
196 .unreq COEF6
197 .unreq COEF7
198 .unreq ACCUM0
199 .unreq ACCUM4
200 .unreq POST0
201 .unreq POST1
202 .unreq POST2
203 .unreq POST3
204
205
206IN .req a1
207SBACT .req a2
208OLDFPSCR .req a3
209IMDCT .req a4
210WINDOW .req v1
211OUT .req v2
212BUF .req v3
213SCALEINT .req v4 @ only used in softfp case
214COUNT .req v5
215
216SCALE .req s0
217
218/* Stack layout differs in softfp and hardfp cases:
219 *
220 * hardfp
221 * fp -> 6 arg words saved by caller
222 * a3,a4,v1-v3,v5,fp,lr on entry (a3 just to pad to 8 bytes)
223 * s16-s23 on entry
224 * align 16
225 * buf -> 8*32*4 bytes buffer
226 * s0 on entry
227 * sp -> 3 arg words for callee
228 *
229 * softfp
230 * fp -> 7 arg words saved by caller
231 * a4,v1-v5,fp,lr on entry
232 * s16-s23 on entry
233 * align 16
234 * buf -> 8*32*4 bytes buffer
235 * sp -> 4 arg words for callee
236 */
237
238/* void ff_dca_qmf_32_subbands_vfp(float samples_in[32][8], int sb_act,
239 * SynthFilterContext *synth, FFTContext *imdct,
240 * float (*synth_buf_ptr)[512],
241 * int *synth_buf_offset, float (*synth_buf2)[32],
242 * const float (*window)[512], float *samples_out,
243 * float (*raXin)[32], float scale);
244 */
245function ff_dca_qmf_32_subbands_vfp, export=1
246VFP push {a3-a4,v1-v3,v5,fp,lr}
247NOVFP push {a4,v1-v5,fp,lr}
248 add fp, sp, #8*4
249 vpush {s16-s23}
250 @ The buffer pointed at by raXin isn't big enough for us to do a
251 @ complete matrix transposition as we want to, so allocate an
252 @ alternative buffer from the stack. Align to 4 words for speed.
253 sub BUF, sp, #8*32*4
254 bic BUF, BUF, #15
255 mov sp, BUF
256 ldr lr, =0x03330000 @ RunFast mode, short vectors of length 4, stride 2
257 fmrx OLDFPSCR, FPSCR
258 fmxr FPSCR, lr
259 @ COUNT is used to count down 2 things at once:
260 @ bits 0-4 are the number of word pairs remaining in the output row
261 @ bits 5-31 are the number of words to copy (with possible negation)
262 @ from the source matrix before we start zeroing the remainder
263 mov COUNT, #(-4 << 5) + 16
264 adds COUNT, COUNT, SBACT, lsl #5
265 bmi 2f
2661:
267 vldr s8, [IN, #(0*8+0)*4]
268 vldr s10, [IN, #(0*8+1)*4]
269 vldr s12, [IN, #(0*8+2)*4]
270 vldr s14, [IN, #(0*8+3)*4]
271 vldr s16, [IN, #(0*8+4)*4]
272 vldr s18, [IN, #(0*8+5)*4]
273 vldr s20, [IN, #(0*8+6)*4]
274 vldr s22, [IN, #(0*8+7)*4]
275 vneg.f s8, s8
276 vldr s9, [IN, #(1*8+0)*4]
277 vldr s11, [IN, #(1*8+1)*4]
278 vldr s13, [IN, #(1*8+2)*4]
279 vldr s15, [IN, #(1*8+3)*4]
280 vneg.f s16, s16
281 vldr s17, [IN, #(1*8+4)*4]
282 vldr s19, [IN, #(1*8+5)*4]
283 vldr s21, [IN, #(1*8+6)*4]
284 vldr s23, [IN, #(1*8+7)*4]
285 vstr d4, [BUF, #(0*32+0)*4]
286 vstr d5, [BUF, #(1*32+0)*4]
287 vstr d6, [BUF, #(2*32+0)*4]
288 vstr d7, [BUF, #(3*32+0)*4]
289 vstr d8, [BUF, #(4*32+0)*4]
290 vstr d9, [BUF, #(5*32+0)*4]
291 vstr d10, [BUF, #(6*32+0)*4]
292 vstr d11, [BUF, #(7*32+0)*4]
293 vldr s9, [IN, #(3*8+0)*4]
294 vldr s11, [IN, #(3*8+1)*4]
295 vldr s13, [IN, #(3*8+2)*4]
296 vldr s15, [IN, #(3*8+3)*4]
297 vldr s17, [IN, #(3*8+4)*4]
298 vldr s19, [IN, #(3*8+5)*4]
299 vldr s21, [IN, #(3*8+6)*4]
300 vldr s23, [IN, #(3*8+7)*4]
301 vneg.f s9, s9
302 vldr s8, [IN, #(2*8+0)*4]
303 vldr s10, [IN, #(2*8+1)*4]
304 vldr s12, [IN, #(2*8+2)*4]
305 vldr s14, [IN, #(2*8+3)*4]
306 vneg.f s17, s17
307 vldr s16, [IN, #(2*8+4)*4]
308 vldr s18, [IN, #(2*8+5)*4]
309 vldr s20, [IN, #(2*8+6)*4]
310 vldr s22, [IN, #(2*8+7)*4]
311 vstr d4, [BUF, #(0*32+2)*4]
312 vstr d5, [BUF, #(1*32+2)*4]
313 vstr d6, [BUF, #(2*32+2)*4]
314 vstr d7, [BUF, #(3*32+2)*4]
315 vstr d8, [BUF, #(4*32+2)*4]
316 vstr d9, [BUF, #(5*32+2)*4]
317 vstr d10, [BUF, #(6*32+2)*4]
318 vstr d11, [BUF, #(7*32+2)*4]
319 add IN, IN, #4*8*4
320 add BUF, BUF, #4*4
321 subs COUNT, COUNT, #(4 << 5) + 2
322 bpl 1b
3232: @ Now deal with trailing < 4 samples
324 adds COUNT, COUNT, #3 << 5
325 bmi 4f @ sb_act was a multiple of 4
326 bics lr, COUNT, #0x1F
327 bne 3f
328 @ sb_act was n*4+1
329 vldr s8, [IN, #(0*8+0)*4]
330 vldr s10, [IN, #(0*8+1)*4]
331 vldr s12, [IN, #(0*8+2)*4]
332 vldr s14, [IN, #(0*8+3)*4]
333 vldr s16, [IN, #(0*8+4)*4]
334 vldr s18, [IN, #(0*8+5)*4]
335 vldr s20, [IN, #(0*8+6)*4]
336 vldr s22, [IN, #(0*8+7)*4]
337 vneg.f s8, s8
338 vldr s9, zero
339 vldr s11, zero
340 vldr s13, zero
341 vldr s15, zero
342 vneg.f s16, s16
343 vldr s17, zero
344 vldr s19, zero
345 vldr s21, zero
346 vldr s23, zero
347 vstr d4, [BUF, #(0*32+0)*4]
348 vstr d5, [BUF, #(1*32+0)*4]
349 vstr d6, [BUF, #(2*32+0)*4]
350 vstr d7, [BUF, #(3*32+0)*4]
351 vstr d8, [BUF, #(4*32+0)*4]
352 vstr d9, [BUF, #(5*32+0)*4]
353 vstr d10, [BUF, #(6*32+0)*4]
354 vstr d11, [BUF, #(7*32+0)*4]
355 add BUF, BUF, #2*4
356 sub COUNT, COUNT, #1
357 b 4f
3583: @ sb_act was n*4+2 or n*4+3, so do the first 2
359 vldr s8, [IN, #(0*8+0)*4]
360 vldr s10, [IN, #(0*8+1)*4]
361 vldr s12, [IN, #(0*8+2)*4]
362 vldr s14, [IN, #(0*8+3)*4]
363 vldr s16, [IN, #(0*8+4)*4]
364 vldr s18, [IN, #(0*8+5)*4]
365 vldr s20, [IN, #(0*8+6)*4]
366 vldr s22, [IN, #(0*8+7)*4]
367 vneg.f s8, s8
368 vldr s9, [IN, #(1*8+0)*4]
369 vldr s11, [IN, #(1*8+1)*4]
370 vldr s13, [IN, #(1*8+2)*4]
371 vldr s15, [IN, #(1*8+3)*4]
372 vneg.f s16, s16
373 vldr s17, [IN, #(1*8+4)*4]
374 vldr s19, [IN, #(1*8+5)*4]
375 vldr s21, [IN, #(1*8+6)*4]
376 vldr s23, [IN, #(1*8+7)*4]
377 vstr d4, [BUF, #(0*32+0)*4]
378 vstr d5, [BUF, #(1*32+0)*4]
379 vstr d6, [BUF, #(2*32+0)*4]
380 vstr d7, [BUF, #(3*32+0)*4]
381 vstr d8, [BUF, #(4*32+0)*4]
382 vstr d9, [BUF, #(5*32+0)*4]
383 vstr d10, [BUF, #(6*32+0)*4]
384 vstr d11, [BUF, #(7*32+0)*4]
385 add BUF, BUF, #2*4
386 sub COUNT, COUNT, #(2 << 5) + 1
387 bics lr, COUNT, #0x1F
388 bne 4f
389 @ sb_act was n*4+3
390 vldr s8, [IN, #(2*8+0)*4]
391 vldr s10, [IN, #(2*8+1)*4]
392 vldr s12, [IN, #(2*8+2)*4]
393 vldr s14, [IN, #(2*8+3)*4]
394 vldr s16, [IN, #(2*8+4)*4]
395 vldr s18, [IN, #(2*8+5)*4]
396 vldr s20, [IN, #(2*8+6)*4]
397 vldr s22, [IN, #(2*8+7)*4]
398 vldr s9, zero
399 vldr s11, zero
400 vldr s13, zero
401 vldr s15, zero
402 vldr s17, zero
403 vldr s19, zero
404 vldr s21, zero
405 vldr s23, zero
406 vstr d4, [BUF, #(0*32+0)*4]
407 vstr d5, [BUF, #(1*32+0)*4]
408 vstr d6, [BUF, #(2*32+0)*4]
409 vstr d7, [BUF, #(3*32+0)*4]
410 vstr d8, [BUF, #(4*32+0)*4]
411 vstr d9, [BUF, #(5*32+0)*4]
412 vstr d10, [BUF, #(6*32+0)*4]
413 vstr d11, [BUF, #(7*32+0)*4]
414 add BUF, BUF, #2*4
415 sub COUNT, COUNT, #1
4164: @ Now fill the remainder with 0
417 vldr s8, zero
418 vldr s9, zero
419 ands COUNT, COUNT, #0x1F
420 beq 6f
4215: vstr d4, [BUF, #(0*32+0)*4]
422 vstr d4, [BUF, #(1*32+0)*4]
423 vstr d4, [BUF, #(2*32+0)*4]
424 vstr d4, [BUF, #(3*32+0)*4]
425 vstr d4, [BUF, #(4*32+0)*4]
426 vstr d4, [BUF, #(5*32+0)*4]
427 vstr d4, [BUF, #(6*32+0)*4]
428 vstr d4, [BUF, #(7*32+0)*4]
429 add BUF, BUF, #2*4
430 subs COUNT, COUNT, #1
431 bne 5b
4326:
433 fmxr FPSCR, OLDFPSCR
434 ldr WINDOW, [fp, #3*4]
435 ldr OUT, [fp, #4*4]
436 sub BUF, BUF, #32*4
437NOVFP ldr SCALEINT, [fp, #6*4]
438 mov COUNT, #8
439VFP vpush {SCALE}
440VFP sub sp, sp, #3*4
441NOVFP sub sp, sp, #4*4
4427:
443VFP ldr a1, [fp, #-7*4] @ imdct
444NOVFP ldr a1, [fp, #-8*4]
445 ldmia fp, {a2-a4}
446VFP stmia sp, {WINDOW, OUT, BUF}
447NOVFP stmia sp, {WINDOW, OUT, BUF, SCALEINT}
448VFP vldr SCALE, [sp, #3*4]
449 bl X(ff_synth_filter_float_vfp)
450 add OUT, OUT, #32*4
451 add BUF, BUF, #32*4
452 subs COUNT, COUNT, #1
453 bne 7b
454
455A sub sp, fp, #(8+8)*4
456T sub fp, fp, #(8+8)*4
457T mov sp, fp
458 vpop {s16-s23}
459VFP pop {a3-a4,v1-v3,v5,fp,pc}
460NOVFP pop {a4,v1-v5,fp,pc}
461endfunc
462
463 .unreq IN
464 .unreq SBACT
465 .unreq OLDFPSCR
466 .unreq IMDCT
467 .unreq WINDOW
468 .unreq OUT
469 .unreq BUF
470 .unreq SCALEINT
471 .unreq COUNT
472
473 .unreq SCALE
474
475 .align 2
476zero: .word 0
libavcodec/dca.h+2−285
@@ -27,282 +27,8 @@ · 26 unmodified lines
27 27
28#include <stdint.h>28#include <stdint.h>
29 29
30#include "libavutil/float_dsp.h"
31#include "libavutil/internal.h"30#include "libavutil/internal.h"
32 31#include "libavutil/intreadwrite.h"
33#include "avcodec.h"
34#include "dcadsp.h"
35#include "fmtconvert.h"
36#include "get_bits.h"
37
38#define DCA_PRIM_CHANNELS_MAX (7)
39#define DCA_ABITS_MAX (32) /* Should be 28 */
40#define DCA_SUBSUBFRAMES_MAX (4)
41#define DCA_SUBFRAMES_MAX (16)
42#define DCA_BLOCKS_MAX (16)
43#define DCA_LFE_MAX (3)
44#define DCA_CHSETS_MAX (4)
45#define DCA_CHSET_CHANS_MAX (8)
46
47#define DCA_PRIM_CHANNELS_MAX (7)
48#define DCA_ABITS_MAX (32) /* Should be 28 */
49#define DCA_SUBSUBFRAMES_MAX (4)
50#define DCA_SUBFRAMES_MAX (16)
51#define DCA_BLOCKS_MAX (16)
52#define DCA_LFE_MAX (3)
53#define DCA_XLL_FBANDS_MAX (4)
54#define DCA_XLL_SEGMENTS_MAX (16)
55#define DCA_XLL_CHSETS_MAX (16)
56#define DCA_XLL_CHANNELS_MAX (16)
57#define DCA_XLL_AORDER_MAX (15)
58
59/* Arbitrary limit; not sure what the maximum really is, but much larger. */
60#define DCA_XLL_DMIX_NCOEFFS_MAX (18)
61
62#define DCA_MAX_FRAME_SIZE 16384
63#define DCA_MAX_EXSS_HEADER_SIZE 4096
64
65#define DCA_BUFFER_PADDING_SIZE 1024
66
67enum DCAExtensionMask {
68 DCA_EXT_CORE = 0x001, ///< core in core substream
69 DCA_EXT_XXCH = 0x002, ///< XXCh channels extension in core substream
70 DCA_EXT_X96 = 0x004, ///< 96/24 extension in core substream
71 DCA_EXT_XCH = 0x008, ///< XCh channel extension in core substream
72 DCA_EXT_EXSS_CORE = 0x010, ///< core in ExSS (extension substream)
73 DCA_EXT_EXSS_XBR = 0x020, ///< extended bitrate extension in ExSS
74 DCA_EXT_EXSS_XXCH = 0x040, ///< XXCh channels extension in ExSS
75 DCA_EXT_EXSS_X96 = 0x080, ///< 96/24 extension in ExSS
76 DCA_EXT_EXSS_LBR = 0x100, ///< low bitrate component in ExSS
77 DCA_EXT_EXSS_XLL = 0x200, ///< lossless extension in ExSS
78};
79
80typedef struct XllChSetSubHeader {
81 int channels; ///< number of channels in channel set, at most 16
82 int residual_encode; ///< residual channel encoding
83 int bit_resolution; ///< input sample bit-width
84 int bit_width; ///< original input sample bit-width
85 int sampling_frequency; ///< sampling frequency
86 int samp_freq_interp; ///< sampling frequency interpolation multiplier
87 int replacement_set; ///< replacement channel set group
88 int active_replace_set; ///< current channel set is active channel set
89 int primary_ch_set;
90 int downmix_coeff_code_embedded;
91 int downmix_embedded;
92 int downmix_type;
93 int hier_chset; ///< hierarchical channel set
94 int downmix_ncoeffs;
95 int downmix_coeffs[DCA_XLL_DMIX_NCOEFFS_MAX];
96 int ch_mask_enabled;
97 int ch_mask;
98 int mapping_coeffs_present;
99 int num_freq_bands;
100
101 /* m_nOrigChanOrder */
102 uint8_t orig_chan_order[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
103 uint8_t orig_chan_order_inv[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
104 /* Coefficients for channel pairs (at most 8), m_anPWChPairsCoeffs */
105 int8_t pw_ch_pairs_coeffs[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX/2];
106 /* m_nCurrHighestLPCOrder */
107 uint8_t adapt_order_max[DCA_XLL_FBANDS_MAX];
108 /* m_pnAdaptPredOrder */
109 uint8_t adapt_order[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
110 /* m_pnFixedPredOrder */
111 uint8_t fixed_order[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
112 /* m_pnLPCReflCoeffsQInd, unsigned version */
113 uint8_t lpc_refl_coeffs_q_ind[DCA_XLL_FBANDS_MAX]
114 [DCA_XLL_CHANNELS_MAX][DCA_XLL_AORDER_MAX];
115
116 int lsb_fsize[DCA_XLL_FBANDS_MAX];
117 int8_t scalable_lsbs[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
118 int8_t bit_width_adj_per_ch[DCA_XLL_FBANDS_MAX][DCA_XLL_CHANNELS_MAX];
119} XllChSetSubHeader;
120
121typedef struct XllNavi {
122 GetBitContext gb; // Context for parsing the data segments
123 unsigned band_size[DCA_XLL_FBANDS_MAX];
124 unsigned segment_size[DCA_XLL_FBANDS_MAX][DCA_XLL_SEGMENTS_MAX];
125 unsigned chset_size[DCA_XLL_FBANDS_MAX][DCA_XLL_SEGMENTS_MAX][DCA_XLL_CHSETS_MAX];
126} XllNavi;
127
128typedef struct QMF64_table {
129 float dct4_coeff[32][32];
130 float dct2_coeff[32][32];
131 float rcos[32];
132 float rsin[32];
133} QMF64_table;
134
135/* Primary audio coding header */
136typedef struct DCAAudioHeader {
137 int subband_activity[DCA_PRIM_CHANNELS_MAX]; ///< subband activity count
138 int vq_start_subband[DCA_PRIM_CHANNELS_MAX]; ///< high frequency vq start subband
139 int joint_intensity[DCA_PRIM_CHANNELS_MAX]; ///< joint intensity coding index
140 int transient_huffman[DCA_PRIM_CHANNELS_MAX]; ///< transient mode code book
141 int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]; ///< scale factor code book
142 int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX]; ///< bit allocation quantizer select
143 int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< quantization index codebook select
144 uint32_t scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< scale factor adjustment
145
146 int subframes; ///< number of subframes
147 int total_channels; ///< number of channels including extensions
148 int prim_channels; ///< number of primary audio channels
149} DCAAudioHeader;
150
151typedef struct DCAChan {
152 DECLARE_ALIGNED(32, int32_t, subband_samples)[DCA_BLOCKS_MAX][DCA_SUBBANDS][SAMPLES_PER_SUBBAND];
153
154 /* Subband samples history (for ADPCM) */
155 DECLARE_ALIGNED(32, int32_t, subband_samples_hist)[DCA_SUBBANDS][4];
156 int hist_index;
157
158 /* Half size is sufficient for core decoding, but for 96 kHz data
159 * we need QMF with 64 subbands and 1024 samples. */
160 DECLARE_ALIGNED(32, float, subband_fir_hist)[1024];
161 DECLARE_ALIGNED(32, float, subband_fir_noidea)[64];
162
163 /* Primary audio coding side information */
164 int prediction_mode[DCA_SUBBANDS]; ///< prediction mode (ADPCM used or not)
165 int prediction_vq[DCA_SUBBANDS]; ///< prediction VQ coefs
166 int bitalloc[DCA_SUBBANDS]; ///< bit allocation index
167 int transition_mode[DCA_SUBBANDS]; ///< transition mode (transients)
168 int32_t scale_factor[DCA_SUBBANDS][2];///< scale factors (2 if transient)
169 int joint_huff; ///< joint subband scale factors codebook
170 int joint_scale_factor[DCA_SUBBANDS]; ///< joint subband scale factors
171
172 int32_t high_freq_vq[DCA_SUBBANDS]; ///< VQ encoded high frequency subbands
173} DCAChan;
174
175
176typedef struct DCAContext {
177 const AVClass *class; ///< class for AVOptions
178 AVCodecContext *avctx;
179 /* Frame header */
180 int frame_type; ///< type of the current frame
181 int samples_deficit; ///< deficit sample count
182 int crc_present; ///< crc is present in the bitstream
183 int sample_blocks; ///< number of PCM sample blocks
184 int frame_size; ///< primary frame byte size
185 int amode; ///< audio channels arrangement
186 int sample_rate; ///< audio sampling rate
187 int bit_rate; ///< transmission bit rate
188 int bit_rate_index; ///< transmission bit rate index
189
190 int dynrange; ///< embedded dynamic range flag
191 int timestamp; ///< embedded time stamp flag
192 int aux_data; ///< auxiliary data flag
193 int hdcd; ///< source material is mastered in HDCD
194 int ext_descr; ///< extension audio descriptor flag
195 int ext_coding; ///< extended coding flag
196 int aspf; ///< audio sync word insertion flag
197 int lfe; ///< low frequency effects flag
198 int predictor_history; ///< predictor history flag
199 int header_crc; ///< header crc check bytes
200 int multirate_inter; ///< multirate interpolator switch
201 int version; ///< encoder software revision
202 int copy_history; ///< copy history
203 int source_pcm_res; ///< source pcm resolution
204 int front_sum; ///< front sum/difference flag
205 int surround_sum; ///< surround sum/difference flag
206 int dialog_norm; ///< dialog normalisation parameter
207
208 /* Primary audio coding header */
209 DCAAudioHeader audio_header;
210
211 /* Primary audio coding side information */
212 int subsubframes[DCA_SUBFRAMES_MAX]; ///< number of subsubframes
213 int partial_samples[DCA_SUBFRAMES_MAX]; ///< partial subsubframe samples count
214 float downmix_coef[DCA_PRIM_CHANNELS_MAX + 1][2]; ///< stereo downmix coefficients
215 int dynrange_coef; ///< dynamic range coefficient
216
217 /* Core substream's embedded downmix coefficients (cf. ETSI TS 102 114 V1.4.1)
218 * Input: primary audio channels (incl. LFE if present)
219 * Output: downmix audio channels (up to 4, no LFE) */
220 uint8_t core_downmix; ///< embedded downmix coefficients available
221 uint8_t core_downmix_amode; ///< audio channel arrangement of embedded downmix
222 uint16_t core_downmix_codes[DCA_PRIM_CHANNELS_MAX + 1][4]; ///< embedded downmix coefficients (9-bit codes)
223
224
225 float lfe_data[2 * DCA_LFE_MAX * (DCA_BLOCKS_MAX + 4)]; ///< Low frequency effect data
226 int lfe_scale_factor;
227
228 /* Subband samples history (for ADPCM) */
229 DECLARE_ALIGNED(32, float, raXin)[32];
230
231 DCAChan dca_chan[DCA_PRIM_CHANNELS_MAX];
232
233 int output; ///< type of output
234
235 float *samples_chanptr[DCA_PRIM_CHANNELS_MAX + 1];
236 float *extra_channels[DCA_PRIM_CHANNELS_MAX + 1];
237 uint8_t *extra_channels_buffer;
238 unsigned int extra_channels_buffer_size;
239
240 uint8_t dca_buffer[DCA_MAX_FRAME_SIZE + DCA_MAX_EXSS_HEADER_SIZE + DCA_BUFFER_PADDING_SIZE];
241 int dca_buffer_size; ///< how much data is in the dca_buffer
242
243 const int8_t *channel_order_tab; ///< channel reordering table, lfe and non lfe
244 GetBitContext gb;
245 /* Current position in DCA frame */
246 int current_subframe;
247 int current_subsubframe;
248
249 int core_ext_mask; ///< present extensions in the core substream
250 int exss_ext_mask; ///< Non-core extensions
251
252 /* XCh extension information */
253 int xch_present; ///< XCh extension present and valid
254 int xch_base_channel; ///< index of first (only) channel containing XCH data
255 int xch_disable; ///< whether the XCh extension should be decoded or not
256
257 /* XXCH extension information */
258 int xxch_chset;
259 int xxch_nbits_spk_mask;
260 uint32_t xxch_core_spkmask;
261 uint32_t xxch_spk_masks[4]; /* speaker masks, last element is core mask */
262 int xxch_chset_nch[4];
263 float xxch_dmix_sf[DCA_CHSETS_MAX];
264
265 uint32_t xxch_dmix_embedded; /* lower layer has mix pre-embedded, per chset */
266 float xxch_dmix_coeff[DCA_PRIM_CHANNELS_MAX][32]; /* worst case sizing */
267
268 int8_t xxch_order_tab[32];
269 int8_t lfe_index;
270
271 /* XLL extension information */
272 int xll_disable;
273 int xll_nch_sets; ///< number of channel sets per frame
274 int xll_channels; ///< total number of channels (in all channel sets)
275 int xll_residual_channels; ///< number of residual channels
276 int xll_segments; ///< number of segments per frame
277 int xll_log_smpl_in_seg; ///< supposedly this is "nBits4SamplLoci"
278 int xll_smpl_in_seg; ///< samples in segment per one frequency band for the first channel set
279 int xll_bits4seg_size; ///< number of bits used to read segment size
280 int xll_banddata_crc; ///< presence of CRC16 within each frequency band
281 int xll_scalable_lsb;
282 int xll_bits4ch_mask; ///< channel position mask
283 int xll_fixed_lsb_width;
284 XllChSetSubHeader xll_chsets[DCA_XLL_CHSETS_MAX];
285 XllNavi xll_navi;
286 int *xll_sample_buf;
287 unsigned int xll_sample_buf_size;
288
289 /* ExSS header parser */
290 int static_fields; ///< static fields present
291 int mix_metadata; ///< mixing metadata present
292 int num_mix_configs; ///< number of mix out configurations
293 int mix_config_num_ch[4]; ///< number of channels in each mix out configuration
294
295 int profile;
296 int one2one_map_chtospkr;
297
298 int debug_flag; ///< used for suppressing repeated error messages output
299 AVFloatDSPContext *fdsp;
300 FFTContext imdct;
301 SynthFilterContext synth;
302 DCADSPContext dcadsp;
303 QMF64_table *qmf64_table;
304 FmtConvertContext fmt_conv;
305} DCAContext;
306 32
307extern av_export const uint32_t avpriv_dca_sample_rates[16];33extern av_export const uint32_t avpriv_dca_sample_rates[16];
308 34
@@ -310,15 +36,6 @@ extern av_export const uint32_t avpriv_dca_sample_rates[16]; · 1 unmodified line
310 * Convert bitstream to one representation based on sync marker36 * Convert bitstream to one representation based on sync marker
311 */37 */
312int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,38int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
313 int max_size);39 int max_size);
314
315int ff_dca_xbr_parse_frame(DCAContext *s);
316int ff_dca_xxch_decode_frame(DCAContext *s);
317
318void ff_dca_exss_parse_header(DCAContext *s);
319
320int ff_dca_xll_decode_header(DCAContext *s);
321int ff_dca_xll_decode_navi(DCAContext *s, int asset_end);
322int ff_dca_xll_decode_audio(DCAContext *s, AVFrame *frame);
323 40
324#endif /* AVCODEC_DCA_H */41#endif /* AVCODEC_DCA_H */
libavcodec/dca_exss.c+0−373
@@ -1,373 +0,0 @@
1/*
2 * DCA ExSS extension
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "libavutil/common.h"
22#include "libavutil/log.h"
23
24#include "dca.h"
25#include "dca_syncwords.h"
26#include "get_bits.h"
27
28/* extensions that reside in core substream */
29#define DCA_CORE_EXTS (DCA_EXT_XCH | DCA_EXT_XXCH | DCA_EXT_X96)
30
31/* these are unconfirmed but should be mostly correct */
32enum DCAExSSSpeakerMask {
33 DCA_EXSS_FRONT_CENTER = 0x0001,
34 DCA_EXSS_FRONT_LEFT_RIGHT = 0x0002,
35 DCA_EXSS_SIDE_REAR_LEFT_RIGHT = 0x0004,
36 DCA_EXSS_LFE = 0x0008,
37 DCA_EXSS_REAR_CENTER = 0x0010,
38 DCA_EXSS_FRONT_HIGH_LEFT_RIGHT = 0x0020,
39 DCA_EXSS_REAR_LEFT_RIGHT = 0x0040,
40 DCA_EXSS_FRONT_HIGH_CENTER = 0x0080,
41 DCA_EXSS_OVERHEAD = 0x0100,
42 DCA_EXSS_CENTER_LEFT_RIGHT = 0x0200,
43 DCA_EXSS_WIDE_LEFT_RIGHT = 0x0400,
44 DCA_EXSS_SIDE_LEFT_RIGHT = 0x0800,
45 DCA_EXSS_LFE2 = 0x1000,
46 DCA_EXSS_SIDE_HIGH_LEFT_RIGHT = 0x2000,
47 DCA_EXSS_REAR_HIGH_CENTER = 0x4000,
48 DCA_EXSS_REAR_HIGH_LEFT_RIGHT = 0x8000,
49};
50
51/**
52 * Return the number of channels in an ExSS speaker mask (HD)
53 */
54static int dca_exss_mask2count(int mask)
55{
56 /* count bits that mean speaker pairs twice */
57 return av_popcount(mask) +
58 av_popcount(mask & (DCA_EXSS_CENTER_LEFT_RIGHT |
59 DCA_EXSS_FRONT_LEFT_RIGHT |
60 DCA_EXSS_FRONT_HIGH_LEFT_RIGHT |
61 DCA_EXSS_WIDE_LEFT_RIGHT |
62 DCA_EXSS_SIDE_LEFT_RIGHT |
63 DCA_EXSS_SIDE_HIGH_LEFT_RIGHT |
64 DCA_EXSS_SIDE_REAR_LEFT_RIGHT |
65 DCA_EXSS_REAR_LEFT_RIGHT |
66 DCA_EXSS_REAR_HIGH_LEFT_RIGHT));
67}
68
69/**
70 * Skip mixing coefficients of a single mix out configuration (HD)
71 */
72static void dca_exss_skip_mix_coeffs(GetBitContext *gb, int channels, int out_ch)
73{
74 int i;
75
76 for (i = 0; i < channels; i++) {
77 int mix_map_mask = get_bits(gb, out_ch);
78 int num_coeffs = av_popcount(mix_map_mask);
79 skip_bits_long(gb, num_coeffs * 6);
80 }
81}
82
83/**
84 * Parse extension substream asset header (HD)
85 */
86static int dca_exss_parse_asset_header(DCAContext *s)
87{
88 int header_pos = get_bits_count(&s->gb);
89 int header_size;
90 int channels = 0;
91 int embedded_stereo = 0;
92 int embedded_6ch = 0;
93 int drc_code_present;
94 int extensions_mask = 0;
95 int i, j;
96
97 if (get_bits_left(&s->gb) < 16)
98 return AVERROR_INVALIDDATA;
99
100 /* We will parse just enough to get to the extensions bitmask with which
101 * we can set the profile value. */
102
103 header_size = get_bits(&s->gb, 9) + 1;
104 skip_bits(&s->gb, 3); // asset index
105
106 if (s->static_fields) {
107 if (get_bits1(&s->gb))
108 skip_bits(&s->gb, 4); // asset type descriptor
109 if (get_bits1(&s->gb))
110 skip_bits_long(&s->gb, 24); // language descriptor
111
112 if (get_bits1(&s->gb)) {
113 /* How can one fit 1024 bytes of text here if the maximum value
114 * for the asset header size field above was 512 bytes? */
115 int text_length = get_bits(&s->gb, 10) + 1;
116 if (get_bits_left(&s->gb) < text_length * 8)
117 return AVERROR_INVALIDDATA;
118 skip_bits_long(&s->gb, text_length * 8); // info text
119 }
120
121 skip_bits(&s->gb, 5); // bit resolution - 1
122 skip_bits(&s->gb, 4); // max sample rate code
123 channels = get_bits(&s->gb, 8) + 1;
124
125 s->one2one_map_chtospkr = get_bits1(&s->gb);
126 if (s->one2one_map_chtospkr) {
127 int spkr_remap_sets;
128 int spkr_mask_size = 16;
129 int num_spkrs[7];
130
131 if (channels > 2)
132 embedded_stereo = get_bits1(&s->gb);
133 if (channels > 6)
134 embedded_6ch = get_bits1(&s->gb);
135
136 if (get_bits1(&s->gb)) {
137 spkr_mask_size = (get_bits(&s->gb, 2) + 1) << 2;
138 skip_bits(&s->gb, spkr_mask_size); // spkr activity mask
139 }
140
141 spkr_remap_sets = get_bits(&s->gb, 3);
142
143 for (i = 0; i < spkr_remap_sets; i++) {
144 /* std layout mask for each remap set */
145 num_spkrs[i] = dca_exss_mask2count(get_bits(&s->gb, spkr_mask_size));
146 }
147
148 for (i = 0; i < spkr_remap_sets; i++) {
149 int num_dec_ch_remaps = get_bits(&s->gb, 5) + 1;
150 if (get_bits_left(&s->gb) < 0)
151 return AVERROR_INVALIDDATA;
152
153 for (j = 0; j < num_spkrs[i]; j++) {
154 int remap_dec_ch_mask = get_bits_long(&s->gb, num_dec_ch_remaps);
155 int num_dec_ch = av_popcount(remap_dec_ch_mask);
156 skip_bits_long(&s->gb, num_dec_ch * 5); // remap codes
157 }
158 }
159 } else {
160 skip_bits(&s->gb, 3); // representation type
161 }
162 }
163
164 drc_code_present = get_bits1(&s->gb);
165 if (drc_code_present)
166 get_bits(&s->gb, 8); // drc code
167
168 if (get_bits1(&s->gb))
169 skip_bits(&s->gb, 5); // dialog normalization code
170
171 if (drc_code_present && embedded_stereo)
172 get_bits(&s->gb, 8); // drc stereo code
173
174 if (s->mix_metadata && get_bits1(&s->gb)) {
175 skip_bits(&s->gb, 1); // external mix
176 skip_bits(&s->gb, 6); // post mix gain code
177
178 if (get_bits(&s->gb, 2) != 3) // mixer drc code
179 skip_bits(&s->gb, 3); // drc limit
180 else
181 skip_bits(&s->gb, 8); // custom drc code
182
183 if (get_bits1(&s->gb)) // channel specific scaling
184 for (i = 0; i < s->num_mix_configs; i++)
185 skip_bits_long(&s->gb, s->mix_config_num_ch[i] * 6); // scale codes
186 else
187 skip_bits_long(&s->gb, s->num_mix_configs * 6); // scale codes
188
189 for (i = 0; i < s->num_mix_configs; i++) {
190 if (get_bits_left(&s->gb) < 0)
191 return AVERROR_INVALIDDATA;
192 dca_exss_skip_mix_coeffs(&s->gb, channels, s->mix_config_num_ch[i]);
193 if (embedded_6ch)
194 dca_exss_skip_mix_coeffs(&s->gb, 6, s->mix_config_num_ch[i]);
195 if (embedded_stereo)
196 dca_exss_skip_mix_coeffs(&s->gb, 2, s->mix_config_num_ch[i]);
197 }
198 }
199
200 switch (get_bits(&s->gb, 2)) {
201 case 0:
202 extensions_mask = get_bits(&s->gb, 12);
203 break;
204 case 1:
205 extensions_mask = DCA_EXT_EXSS_XLL;
206 break;
207 case 2:
208 extensions_mask = DCA_EXT_EXSS_LBR;
209 break;
210 case 3:
211 extensions_mask = 0; /* aux coding */
212 break;
213 }
214
215 /* not parsed further, we were only interested in the extensions mask */
216
217 if (get_bits_left(&s->gb) < 0)
218 return AVERROR_INVALIDDATA;
219
220 if (get_bits_count(&s->gb) - header_pos > header_size * 8) {
221 av_log(s->avctx, AV_LOG_WARNING, "Asset header size mismatch.\n");
222 return AVERROR_INVALIDDATA;
223 }
224 skip_bits_long(&s->gb, header_pos + header_size * 8 - get_bits_count(&s->gb));
225
226 if (extensions_mask & DCA_EXT_EXSS_XLL)
227 s->profile = FF_PROFILE_DTS_HD_MA;
228 else if (extensions_mask & (DCA_EXT_EXSS_XBR | DCA_EXT_EXSS_X96 |
229 DCA_EXT_EXSS_XXCH))
230 s->profile = FF_PROFILE_DTS_HD_HRA;
231
232 if (!(extensions_mask & DCA_EXT_CORE))
233 av_log(s->avctx, AV_LOG_WARNING, "DTS core detection mismatch.\n");
234 if ((extensions_mask & DCA_CORE_EXTS) != s->core_ext_mask)
235 av_log(s->avctx, AV_LOG_WARNING,
236 "DTS extensions detection mismatch (%d, %d)\n",
237 extensions_mask & DCA_CORE_EXTS, s->core_ext_mask);
238
239 return 0;
240}
241
242/**
243 * Parse extension substream header (HD)
244 */
245void ff_dca_exss_parse_header(DCAContext *s)
246{
247 int asset_size[8];
248 int ss_index;
249 int blownup;
250 int num_audiop = 1;
251 int num_assets = 1;
252 int active_ss_mask[8];
253 int i, j;
254 int start_pos;
255 int hdrsize;
256 uint32_t mkr;
257
258 if (get_bits_left(&s->gb) < 52)
259 return;
260
261 start_pos = get_bits_count(&s->gb) - 32;
262
263 skip_bits(&s->gb, 8); // user data
264 ss_index = get_bits(&s->gb, 2);
265
266 blownup = get_bits1(&s->gb);
267 hdrsize = get_bits(&s->gb, 8 + 4 * blownup) + 1; // header_size
268 skip_bits(&s->gb, 16 + 4 * blownup); // hd_size
269
270 s->static_fields = get_bits1(&s->gb);
271 if (s->static_fields) {
272 skip_bits(&s->gb, 2); // reference clock code
273 skip_bits(&s->gb, 3); // frame duration code
274
275 if (get_bits1(&s->gb))
276 skip_bits_long(&s->gb, 36); // timestamp
277
278 /* a single stream can contain multiple audio assets that can be
279 * combined to form multiple audio presentations */
280
281 num_audiop = get_bits(&s->gb, 3) + 1;
282 if (num_audiop > 1) {
283 avpriv_request_sample(s->avctx,
284 "Multiple DTS-HD audio presentations");
285 /* ignore such streams for now */
286 return;
287 }
288
289 num_assets = get_bits(&s->gb, 3) + 1;
290 if (num_assets > 1) {
291 avpriv_request_sample(s->avctx, "Multiple DTS-HD audio assets");
292 /* ignore such streams for now */
293 return;
294 }
295
296 for (i = 0; i < num_audiop; i++)
297 active_ss_mask[i] = get_bits(&s->gb, ss_index + 1);
298
299 for (i = 0; i < num_audiop; i++)
300 for (j = 0; j <= ss_index; j++)
301 if (active_ss_mask[i] & (1 << j))
302 skip_bits(&s->gb, 8); // active asset mask
303
304 s->mix_metadata = get_bits1(&s->gb);
305 if (s->mix_metadata) {
306 int mix_out_mask_size;
307
308 skip_bits(&s->gb, 2); // adjustment level
309 mix_out_mask_size = (get_bits(&s->gb, 2) + 1) << 2;
310 s->num_mix_configs = get_bits(&s->gb, 2) + 1;
311
312 for (i = 0; i < s->num_mix_configs; i++) {
313 int mix_out_mask = get_bits(&s->gb, mix_out_mask_size);
314 s->mix_config_num_ch[i] = dca_exss_mask2count(mix_out_mask);
315 }
316 }
317 }
318
319 av_assert0(num_assets > 0); // silence a warning
320
321 for (i = 0; i < num_assets; i++)
322 asset_size[i] = get_bits_long(&s->gb, 16 + 4 * blownup) + 1;
323
324 for (i = 0; i < num_assets; i++) {
325 if (dca_exss_parse_asset_header(s))
326 return;
327 }
328
329 j = get_bits_count(&s->gb);
330 if (start_pos + hdrsize * 8 > j)
331 skip_bits_long(&s->gb, start_pos + hdrsize * 8 - j);
332
333 for (i = 0; i < num_assets; i++) {
334 int end_pos;
335 start_pos = get_bits_count(&s->gb);
336 end_pos = start_pos + asset_size[i] * 8;
337 mkr = get_bits_long(&s->gb, 32);
338
339 /* parse extensions that we know about */
340 switch (mkr) {
341 case DCA_SYNCWORD_XBR:
342 ff_dca_xbr_parse_frame(s);
343 break;
344 case DCA_SYNCWORD_XXCH:
345 ff_dca_xxch_decode_frame(s);
346 s->core_ext_mask |= DCA_EXT_XXCH; /* xxx use for chan reordering */
347 break;
348 case DCA_SYNCWORD_XLL:
349 if (s->xll_disable) {
350 av_log(s->avctx, AV_LOG_DEBUG,
351 "DTS-XLL: ignoring XLL extension\n");
352 break;
353 }
354 av_log(s->avctx, AV_LOG_DEBUG,
355 "DTS-XLL: decoding XLL extension\n");
356 if (ff_dca_xll_decode_header(s) == 0 &&
357 ff_dca_xll_decode_navi(s, end_pos) == 0)
358 s->exss_ext_mask |= DCA_EXT_EXSS_XLL;
359 break;
360 default:
361 av_log(s->avctx, AV_LOG_DEBUG,
362 "DTS-ExSS: unknown marker = 0x%08x\n", mkr);
363 }
364
365 /* skip to end of block */
366 j = get_bits_count(&s->gb);
367 if (j > end_pos)
368 av_log(s->avctx, AV_LOG_ERROR,
369 "DTS-ExSS: Processed asset too long.\n");
370 if (j < end_pos)
371 skip_bits_long(&s->gb, end_pos - j);
372 }
373}
libavcodec/dca_xll.c+0−747
@@ -1,747 +0,0 @@
1/*
2 * DCA XLL extension
3 *
4 * Copyright (C) 2012 Paul B Mahol
5 * Copyright (C) 2014 Niels Möller
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include "libavutil/attributes.h"
25#include "libavutil/common.h"
26#include "libavutil/internal.h"
27
28#include "avcodec.h"
29#include "dca.h"
30#include "dcadata.h"
31#include "get_bits.h"
32#include "unary.h"
33
34/* Sign as bit 0 */
35static inline int get_bits_sm(GetBitContext *s, unsigned n)
36{
37 int x = get_bits(s, n);
38 if (x & 1)
39 return -(x >> 1) - 1;
40 else
41 return x >> 1;
42}
43
44/* Return -1 on error. */
45static int32_t get_dmix_coeff(DCAContext *s, int inverse)
46{
47 unsigned code = get_bits(&s->gb, 9);
48 int32_t sign = (int32_t) (code >> 8) - 1;
49 unsigned idx = code & 0xff;
50 int inv_offset = FF_DCA_DMIXTABLE_SIZE -FF_DCA_INV_DMIXTABLE_SIZE;
51 if (idx >= FF_DCA_DMIXTABLE_SIZE) {
52 av_log(s->avctx, AV_LOG_ERROR,
53 "XLL: Invalid channel set downmix code %x\n", code);
54 return -1;
55 } else if (!inverse) {
56 return (ff_dca_dmixtable[idx] ^ sign) - sign;
57 } else if (idx < inv_offset) {
58 av_log(s->avctx, AV_LOG_ERROR,
59 "XLL: Invalid channel set inverse downmix code %x\n", code);
60 return -1;
61 } else {
62 return (ff_dca_inv_dmixtable[idx - inv_offset] ^ sign) - sign;
63 }
64}
65
66static int32_t dca_get_dmix_coeff(DCAContext *s)
67{
68 return get_dmix_coeff(s, 0);
69}
70
71static int32_t dca_get_inv_dmix_coeff(DCAContext *s)
72{
73 return get_dmix_coeff(s, 1);
74}
75
76/* parse XLL header */
77int ff_dca_xll_decode_header(DCAContext *s)
78{
79 int hdr_pos, hdr_size;
80 av_unused int version, frame_size;
81 int i, chset_index;
82
83 /* get bit position of sync header */
84 hdr_pos = get_bits_count(&s->gb) - 32;
85
86 version = get_bits(&s->gb, 4) + 1;
87 hdr_size = get_bits(&s->gb, 8) + 1;
88
89 frame_size = get_bits_long(&s->gb, get_bits(&s->gb, 5) + 1) + 1;
90
91 s->xll_channels =
92 s->xll_residual_channels = 0;
93 s->xll_nch_sets = get_bits(&s->gb, 4) + 1;
94 s->xll_segments = 1 << get_bits(&s->gb, 4);
95 s->xll_log_smpl_in_seg = get_bits(&s->gb, 4);
96 s->xll_smpl_in_seg = 1 << s->xll_log_smpl_in_seg;
97 s->xll_bits4seg_size = get_bits(&s->gb, 5) + 1;
98 s->xll_banddata_crc = get_bits(&s->gb, 2);
99 s->xll_scalable_lsb = get_bits1(&s->gb);
100 s->xll_bits4ch_mask = get_bits(&s->gb, 5) + 1;
101
102 if (s->xll_scalable_lsb) {
103 s->xll_fixed_lsb_width = get_bits(&s->gb, 4);
104 if (s->xll_fixed_lsb_width)
105 av_log(s->avctx, AV_LOG_WARNING,
106 "XLL: fixed lsb width = %d, non-zero not supported.\n",
107 s->xll_fixed_lsb_width);
108 }
109 /* skip to the end of the common header */
110 i = get_bits_count(&s->gb);
111 if (hdr_pos + hdr_size * 8 > i)
112 skip_bits_long(&s->gb, hdr_pos + hdr_size * 8 - i);
113
114 for (chset_index = 0; chset_index < s->xll_nch_sets; chset_index++) {
115 XllChSetSubHeader *chset = &s->xll_chsets[chset_index];
116 hdr_pos = get_bits_count(&s->gb);
117 hdr_size = get_bits(&s->gb, 10) + 1;
118
119 chset->channels = get_bits(&s->gb, 4) + 1;
120 chset->residual_encode = get_bits(&s->gb, chset->channels);
121 chset->bit_resolution = get_bits(&s->gb, 5) + 1;
122 chset->bit_width = get_bits(&s->gb, 5) + 1;
123 chset->sampling_frequency = ff_dca_sampling_freqs[get_bits(&s->gb, 4)];
124 chset->samp_freq_interp = get_bits(&s->gb, 2);
125 chset->replacement_set = get_bits(&s->gb, 2);
126 if (chset->replacement_set)
127 chset->active_replace_set = get_bits(&s->gb, 1);
128
129 if (s->one2one_map_chtospkr) {
130 chset->primary_ch_set = get_bits(&s->gb, 1);
131 chset->downmix_coeff_code_embedded = get_bits(&s->gb, 1);
132 if (chset->downmix_coeff_code_embedded) {
133 chset->downmix_embedded = get_bits(&s->gb, 1);
134 if (chset->primary_ch_set) {
135 chset->downmix_type = get_bits(&s->gb, 3);
136 if (chset->downmix_type > 6) {
137 av_log(s->avctx, AV_LOG_ERROR,
138 "XLL: Invalid channel set downmix type\n");
139 return AVERROR_INVALIDDATA;
140 }
141 }
142 }
143 chset->hier_chset = get_bits(&s->gb, 1);
144
145 if (chset->downmix_coeff_code_embedded) {
146 /* nDownmixCoeffs is specified as N * M. For a primary
147 * channel set, it appears that N = number of
148 * channels, and M is the number of downmix channels.
149 *
150 * For a non-primary channel set, N is specified as
151 * number of channels + 1, and M is derived from the
152 * channel set hierarchy, and at least in simple cases
153 * M is the number of channels in preceding channel
154 * sets. */
155 if (chset->primary_ch_set) {
156 static const char dmix_table[7] = { 1, 2, 2, 3, 3, 4, 4 };
157 chset->downmix_ncoeffs = chset->channels * dmix_table[chset->downmix_type];
158 } else
159 chset->downmix_ncoeffs = (chset->channels + 1) * s->xll_channels;
160
161 if (chset->downmix_ncoeffs > DCA_XLL_DMIX_NCOEFFS_MAX) {
162 avpriv_request_sample(s->avctx,
163 "XLL: More than %d downmix coefficients",
164 DCA_XLL_DMIX_NCOEFFS_MAX);
165 return AVERROR_PATCHWELCOME;
166 } else if (chset->primary_ch_set) {
167 for (i = 0; i < chset->downmix_ncoeffs; i++)
168 if ((chset->downmix_coeffs[i] = dca_get_dmix_coeff(s)) == -1)
169 return AVERROR_INVALIDDATA;
170 } else {
171 unsigned c, r;
172 for (c = 0, i = 0; c < s->xll_channels; c++, i += chset->channels + 1) {
173 if ((chset->downmix_coeffs[i] = dca_get_inv_dmix_coeff(s)) == -1)
174 return AVERROR_INVALIDDATA;
175 for (r = 1; r <= chset->channels; r++) {
176 int32_t coeff = dca_get_dmix_coeff(s);
177 if (coeff == -1)
178 return AVERROR_INVALIDDATA;
179 chset->downmix_coeffs[i + r] =
180 (chset->downmix_coeffs[i] * (int64_t) coeff + (1 << 15)) >> 16;
181 }
182 }
183 }
184 }
185 chset->ch_mask_enabled = get_bits(&s->gb, 1);
186 if (chset->ch_mask_enabled)
187 chset->ch_mask = get_bits(&s->gb, s->xll_bits4ch_mask);
188 else
189 /* Skip speaker configuration bits */
190 skip_bits_long(&s->gb, 25 * chset->channels);
191 } else {
192 chset->primary_ch_set = 1;
193 chset->downmix_coeff_code_embedded = 0;
194 /* Spec: NumChHierChSet = 0, NumDwnMixCodeCoeffs = 0, whatever that means. */
195 chset->mapping_coeffs_present = get_bits(&s->gb, 1);
196 if (chset->mapping_coeffs_present) {
197 avpriv_report_missing_feature(s->avctx, "XLL: mapping coefficients");
198 return AVERROR_PATCHWELCOME;
199 }
200 }
201 if (chset->sampling_frequency > 96000)
202 chset->num_freq_bands = 2 * (1 + get_bits(&s->gb, 1));
203 else
204 chset->num_freq_bands = 1;
205
206 if (chset->num_freq_bands > 1) {
207 avpriv_report_missing_feature(s->avctx, "XLL: num_freq_bands > 1");
208 return AVERROR_PATCHWELCOME;
209 }
210
211 if (get_bits(&s->gb, 1)) { /* pw_ch_decor_enabled */
212 int bits = av_ceil_log2(chset->channels);
213 for (i = 0; i < chset->channels; i++) {
214 unsigned j = get_bits(&s->gb, bits);
215 if (j >= chset->channels) {
216 av_log(s->avctx, AV_LOG_ERROR,
217 "Original channel order value %u too large, only %d channels.\n",
218 j, chset->channels);
219 return AVERROR_INVALIDDATA;
220 }
221 chset->orig_chan_order[0][i] = j;
222 chset->orig_chan_order_inv[0][j] = i;
223 }
224 for (i = 0; i < chset->channels / 2; i++) {
225 if (get_bits(&s->gb, 1)) /* bChPFlag */
226 chset->pw_ch_pairs_coeffs[0][i] = get_bits_sm(&s->gb, 7);
227 else
228 chset->pw_ch_pairs_coeffs[0][i] = 0;
229 }
230 } else {
231 for (i = 0; i < chset->channels; i++)
232 chset->orig_chan_order[0][i] =
233 chset->orig_chan_order_inv[0][i] = i;
234 for (i = 0; i < chset->channels / 2; i++)
235 chset->pw_ch_pairs_coeffs[0][i] = 0;
236 }
237 /* Adaptive prediction order */
238 chset->adapt_order_max[0] = 0;
239 for (i = 0; i < chset->channels; i++) {
240 chset->adapt_order[0][i] = get_bits(&s->gb, 4);
241 if (chset->adapt_order_max[0] < chset->adapt_order[0][i])
242 chset->adapt_order_max[0] = chset->adapt_order[0][i];
243 }
244 /* Fixed prediction order, used in case the adaptive order
245 * above is zero */
246 for (i = 0; i < chset->channels; i++)
247 chset->fixed_order[0][i] =
248 chset->adapt_order[0][i] ? 0 : get_bits(&s->gb, 2);
249
250 for (i = 0; i < chset->channels; i++) {
251 unsigned j;
252 for (j = 0; j < chset->adapt_order[0][i]; j++)
253 chset->lpc_refl_coeffs_q_ind[0][i][j] = get_bits(&s->gb, 8);
254 }
255
256 if (s->xll_scalable_lsb) {
257 chset->lsb_fsize[0] = get_bits(&s->gb, s->xll_bits4seg_size);
258
259 for (i = 0; i < chset->channels; i++)
260 chset->scalable_lsbs[0][i] = get_bits(&s->gb, 4);
261 for (i = 0; i < chset->channels; i++)
262 chset->bit_width_adj_per_ch[0][i] = get_bits(&s->gb, 4);
263 } else {
264 memset(chset->scalable_lsbs[0], 0,
265 chset->channels * sizeof(chset->scalable_lsbs[0][0]));
266 memset(chset->bit_width_adj_per_ch[0], 0,
267 chset->channels * sizeof(chset->bit_width_adj_per_ch[0][0]));
268 }
269
270 s->xll_channels += chset->channels;
271 s->xll_residual_channels += chset->channels -
272 av_popcount(chset->residual_encode);
273
274 /* FIXME: Parse header data for extra frequency bands. */
275
276 /* Skip to end of channel set sub header. */
277 i = get_bits_count(&s->gb);
278 if (hdr_pos + 8 * hdr_size < i) {
279 av_log(s->avctx, AV_LOG_ERROR,
280 "chset header too large, %d bits, should be <= %d bits\n",
281 i - hdr_pos, 8 * hdr_size);
282 return AVERROR_INVALIDDATA;
283 }
284 if (hdr_pos + 8 * hdr_size > i)
285 skip_bits_long(&s->gb, hdr_pos + 8 * hdr_size - i);
286 }
287 return 0;
288}
289
290/* parse XLL navigation table */
291int ff_dca_xll_decode_navi(DCAContext *s, int asset_end)
292{
293 int nbands, band, chset, seg, data_start;
294
295 /* FIXME: Supports only a single frequency band */
296 nbands = 1;
297
298 for (band = 0; band < nbands; band++) {
299 s->xll_navi.band_size[band] = 0;
300 for (seg = 0; seg < s->xll_segments; seg++) {
301 /* Note: The spec, ETSI TS 102 114 V1.4.1 (2012-09), says
302 * we should read a base value for segment_size from the
303 * stream, before reading the sizes of the channel sets.
304 * But that's apparently incorrect. */
305 s->xll_navi.segment_size[band][seg] = 0;
306
307 for (chset = 0; chset < s->xll_nch_sets; chset++)
308 if (band < s->xll_chsets[chset].num_freq_bands) {
309 s->xll_navi.chset_size[band][seg][chset] =
310 get_bits(&s->gb, s->xll_bits4seg_size) + 1;
311 s->xll_navi.segment_size[band][seg] +=
312 s->xll_navi.chset_size[band][seg][chset];
313 }
314 s->xll_navi.band_size[band] += s->xll_navi.segment_size[band][seg];
315 }
316 }
317 /* Align to 8 bits and skip 16-bit CRC. */
318 skip_bits_long(&s->gb, 16 + ((-get_bits_count(&s->gb)) & 7));
319
320 data_start = get_bits_count(&s->gb);
321 if (data_start + 8 * s->xll_navi.band_size[0] > asset_end) {
322 av_log(s->avctx, AV_LOG_ERROR,
323 "XLL: Data in NAVI table exceeds containing asset\n"
324 "start: %d (bit), size %u (bytes), end %d (bit), error %u\n",
325 data_start, s->xll_navi.band_size[0], asset_end,
326 data_start + 8 * s->xll_navi.band_size[0] - asset_end);
327 return AVERROR_INVALIDDATA;
328 }
329 init_get_bits(&s->xll_navi.gb, s->gb.buffer + data_start / 8,
330 8 * s->xll_navi.band_size[0]);
331 return 0;
332}
333
334static void dca_xll_inv_adapt_pred(int *samples, int nsamples, unsigned order,
335 const int *prev, const uint8_t *q_ind)
336{
337 static const uint16_t table[0x81] = {
338 0, 3070, 5110, 7140, 9156, 11154, 13132, 15085,
339 17010, 18904, 20764, 22588, 24373, 26117, 27818, 29474,
340 31085, 32648, 34164, 35631, 37049, 38418, 39738, 41008,
341 42230, 43404, 44530, 45609, 46642, 47630, 48575, 49477,
342 50337, 51157, 51937, 52681, 53387, 54059, 54697, 55302,
343 55876, 56421, 56937, 57426, 57888, 58326, 58741, 59132,
344 59502, 59852, 60182, 60494, 60789, 61066, 61328, 61576,
345 61809, 62029, 62236, 62431, 62615, 62788, 62951, 63105,
346 63250, 63386, 63514, 63635, 63749, 63855, 63956, 64051,
347 64140, 64224, 64302, 64376, 64446, 64512, 64573, 64631,
348 64686, 64737, 64785, 64830, 64873, 64913, 64950, 64986,
349 65019, 65050, 65079, 65107, 65133, 65157, 65180, 65202,
350 65222, 65241, 65259, 65275, 65291, 65306, 65320, 65333,
351 65345, 65357, 65368, 65378, 65387, 65396, 65405, 65413,
352 65420, 65427, 65434, 65440, 65446, 65451, 65456, 65461,
353 65466, 65470, 65474, 65478, 65481, 65485, 65488, 65491,
354 65535, /* Final value is for the -128 corner case, see below. */
355 };
356 int c[DCA_XLL_AORDER_MAX];
357 int64_t s;
358 unsigned i, j;
359
360 for (i = 0; i < order; i++) {
361 if (q_ind[i] & 1)
362 /* The index value 0xff corresponds to a lookup of entry 0x80 in
363 * the table, and no value is provided in the specification. */
364 c[i] = -table[(q_ind[i] >> 1) + 1];
365 else
366 c[i] = table[q_ind[i] >> 1];
367 }
368 /* The description in the spec is a bit convoluted. We can convert
369 * the reflected values to direct values in place, using a
370 * sequence of reflections operating on two values. */
371 for (i = 1; i < order; i++) {
372 /* i = 1: scale c[0]
373 * i = 2: reflect c[0] <-> c[1]
374 * i = 3: scale c[1], reflect c[0] <-> c[2]
375 * i = 4: reflect c[0] <-> c[3] reflect c[1] <-> c[2]
376 * ... */
377 if (i & 1)
378 c[i / 2] += ((int64_t) c[i] * c[i / 2] + 0x8000) >> 16;
379 for (j = 0; j < i / 2; j++) {
380 int r0 = c[j];
381 int r1 = c[i - j - 1];
382 c[j] += ((int64_t) c[i] * r1 + 0x8000) >> 16;
383 c[i - j - 1] += ((int64_t) c[i] * r0 + 0x8000) >> 16;
384 }
385 }
386 /* Apply predictor. */
387 /* NOTE: Processing samples in this order means that the
388 * predictor is applied to the newly reconstructed samples. */
389 if (prev) {
390 for (i = 0; i < order; i++) {
391 for (j = s = 0; j < i; j++)
392 s += (int64_t) c[j] * samples[i - 1 - j];
393 for (; j < order; j++)
394 s += (int64_t) c[j] * prev[DCA_XLL_AORDER_MAX + i - 1 - j];
395
396 samples[i] -= av_clip_intp2((s + 0x8000) >> 16, 24);
397 }
398 }
399 for (i = order; i < nsamples; i++) {
400 for (j = s = 0; j < order; j++)
401 s += (int64_t) c[j] * samples[i - 1 - j];
402
403 /* NOTE: Equations seem to imply addition, while the
404 * pseudocode seems to use subtraction.*/
405 samples[i] -= av_clip_intp2((s + 0x8000) >> 16, 24);
406 }
407}
408
409int ff_dca_xll_decode_audio(DCAContext *s, AVFrame *frame)
410{
411 /* FIXME: Decodes only the first frequency band. */
412 int seg, chset_i;
413
414 /* Coding parameters for each channel set. */
415 struct coding_params {
416 int seg_type;
417 int rice_code_flag[16];
418 int pancAuxABIT[16];
419 int pancABIT0[16]; /* Not sure what this is */
420 int pancABIT[16]; /* Not sure what this is */
421 int nSamplPart0[16];
422 } param_state[16];
423
424 GetBitContext *gb = &s->xll_navi.gb;
425 int *history;
426
427 /* Layout: First the sample buffer for one segment per channel,
428 * followed by history buffers of DCA_XLL_AORDER_MAX samples for
429 * each channel. */
430 av_fast_malloc(&s->xll_sample_buf, &s->xll_sample_buf_size,
431 (s->xll_smpl_in_seg + DCA_XLL_AORDER_MAX) *
432 s->xll_channels * sizeof(*s->xll_sample_buf));
433 if (!s->xll_sample_buf)
434 return AVERROR(ENOMEM);
435
436 history = s->xll_sample_buf + s->xll_smpl_in_seg * s->xll_channels;
437
438 for (seg = 0; seg < s->xll_segments; seg++) {
439 unsigned in_channel;
440
441 for (chset_i = in_channel = 0; chset_i < s->xll_nch_sets; chset_i++) {
442 /* The spec isn't very explicit, but I think the NAVI sizes are in bytes. */
443 int end_pos = get_bits_count(gb) +
444 8 * s->xll_navi.chset_size[0][seg][chset_i];
445 int i, j;
446 struct coding_params *params = &param_state[chset_i];
447 /* I think this flag means that we should keep seg_type and
448 * other parameters from the previous segment. */
449 int use_seg_state_code_param;
450 XllChSetSubHeader *chset = &s->xll_chsets[chset_i];
451 if (in_channel >= s->avctx->channels)
452 /* FIXME: Could go directly to next segment */
453 goto next_chset;
454
455 if (s->avctx->sample_rate != chset->sampling_frequency) {
456 av_log(s->avctx, AV_LOG_WARNING,
457 "XLL: unexpected chset sample rate %d, expected %d\n",
458 chset->sampling_frequency, s->avctx->sample_rate);
459 goto next_chset;
460 }
461 if (seg != 0)
462 use_seg_state_code_param = get_bits(gb, 1);
463 else
464 use_seg_state_code_param = 0;
465
466 if (!use_seg_state_code_param) {
467 int num_param_sets, i;
468 unsigned bits4ABIT;
469
470 params->seg_type = get_bits(gb, 1);
471 num_param_sets = params->seg_type ? 1 : chset->channels;
472
473 if (chset->bit_width > 16) {
474 bits4ABIT = 5;
475 } else {
476 if (chset->bit_width > 8)
477 bits4ABIT = 4;
478 else
479 bits4ABIT = 3;
480 if (s->xll_nch_sets > 1)
481 bits4ABIT++;
482 }
483
484 for (i = 0; i < num_param_sets; i++) {
485 params->rice_code_flag[i] = get_bits(gb, 1);
486 if (!params->seg_type && params->rice_code_flag[i] && get_bits(gb, 1))
487 params->pancAuxABIT[i] = get_bits(gb, bits4ABIT) + 1;
488 else
489 params->pancAuxABIT[i] = 0;
490 }
491
492 for (i = 0; i < num_param_sets; i++) {
493 if (!seg) {
494 /* Parameters for part 1 */
495 params->pancABIT0[i] = get_bits(gb, bits4ABIT);
496 if (params->rice_code_flag[i] == 0 && params->pancABIT0[i] > 0)
497 /* For linear code */
498 params->pancABIT0[i]++;
499
500 /* NOTE: In the spec, not indexed by band??? */
501 if (params->seg_type == 0)
502 params->nSamplPart0[i] = chset->adapt_order[0][i];
503 else
504 params->nSamplPart0[i] = chset->adapt_order_max[0];
505 } else
506 params->nSamplPart0[i] = 0;
507
508 /* Parameters for part 2 */
509 params->pancABIT[i] = get_bits(gb, bits4ABIT);
510 if (params->rice_code_flag[i] == 0 && params->pancABIT[i] > 0)
511 /* For linear code */
512 params->pancABIT[i]++;
513 }
514 }
515 for (i = 0; i < chset->channels; i++) {
516 int param_index = params->seg_type ? 0 : i;
517 int part0 = params->nSamplPart0[param_index];
518 int bits = part0 ? params->pancABIT0[param_index] : 0;
519 int *sample_buf = s->xll_sample_buf +
520 (in_channel + i) * s->xll_smpl_in_seg;
521
522 if (!params->rice_code_flag[param_index]) {
523 /* Linear code */
524 if (bits)
525 for (j = 0; j < part0; j++)
526 sample_buf[j] = get_bits_sm(gb, bits);
527 else
528 memset(sample_buf, 0, part0 * sizeof(sample_buf[0]));
529
530 /* Second part */
531 bits = params->pancABIT[param_index];
532 if (bits)
533 for (j = part0; j < s->xll_smpl_in_seg; j++)
534 sample_buf[j] = get_bits_sm(gb, bits);
535 else
536 memset(sample_buf + part0, 0,
537 (s->xll_smpl_in_seg - part0) * sizeof(sample_buf[0]));
538 } else {
539 int aux_bits = params->pancAuxABIT[param_index];
540
541 for (j = 0; j < part0; j++) {
542 /* FIXME: Is this identical to Golomb code? */
543 int t = get_unary(gb, 1, 33) << bits;
544 /* FIXME: Could move this test outside of the loop, for efficiency. */
545 if (bits)
546 t |= get_bits(gb, bits);
547 sample_buf[j] = (t & 1) ? -(t >> 1) - 1 : (t >> 1);
548 }
549
550 /* Second part */
551 bits = params->pancABIT[param_index];
552
553 /* Follow the spec's suggestion of using the
554 * buffer also to store the hybrid-rice flags. */
555 memset(sample_buf + part0, 0,
556 (s->xll_smpl_in_seg - part0) * sizeof(sample_buf[0]));
557
558 if (aux_bits > 0) {
559 /* For hybrid rice encoding, some samples are linearly
560 * coded. According to the spec, "nBits4SamplLoci" bits
561 * are used for each index, but this value is not
562 * defined. I guess we should use log2(xll_smpl_in_seg)
563 * bits. */
564 int count = get_bits(gb, s->xll_log_smpl_in_seg);
565 av_log(s->avctx, AV_LOG_DEBUG, "aux count %d (bits %d)\n",
566 count, s->xll_log_smpl_in_seg);
567
568 for (j = 0; j < count; j++)
569 sample_buf[get_bits(gb, s->xll_log_smpl_in_seg)] = 1;
570 }
571 for (j = part0; j < s->xll_smpl_in_seg; j++) {
572 if (!sample_buf[j]) {
573 int t = get_unary(gb, 1, 33);
574 if (bits)
575 t = (t << bits) | get_bits(gb, bits);
576 sample_buf[j] = (t & 1) ? -(t >> 1) - 1 : (t >> 1);
577 } else
578 sample_buf[j] = get_bits_sm(gb, aux_bits);
579 }
580 }
581 }
582
583 for (i = 0; i < chset->channels; i++) {
584 unsigned adapt_order = chset->adapt_order[0][i];
585 int *sample_buf = s->xll_sample_buf +
586 (in_channel + i) * s->xll_smpl_in_seg;
587 int *prev = history + (in_channel + i) * DCA_XLL_AORDER_MAX;
588
589 if (!adapt_order) {
590 unsigned order;
591 for (order = chset->fixed_order[0][i]; order > 0; order--) {
592 unsigned j;
593 for (j = 1; j < s->xll_smpl_in_seg; j++)
594 sample_buf[j] += sample_buf[j - 1];
595 }
596 } else
597 /* Inverse adaptive prediction, in place. */
598 dca_xll_inv_adapt_pred(sample_buf, s->xll_smpl_in_seg,
599 adapt_order, seg ? prev : NULL,
600 chset->lpc_refl_coeffs_q_ind[0][i]);
601 memcpy(prev, sample_buf + s->xll_smpl_in_seg - DCA_XLL_AORDER_MAX,
602 DCA_XLL_AORDER_MAX * sizeof(*prev));
603 }
604 for (i = 1; i < chset->channels; i += 2) {
605 int coeff = chset->pw_ch_pairs_coeffs[0][i / 2];
606 if (coeff != 0) {
607 int *sample_buf = s->xll_sample_buf +
608 (in_channel + i) * s->xll_smpl_in_seg;
609 int *prev = sample_buf - s->xll_smpl_in_seg;
610 unsigned j;
611 for (j = 0; j < s->xll_smpl_in_seg; j++)
612 /* Shift is unspecified, but should apparently be 3. */
613 sample_buf[j] += ((int64_t) coeff * prev[j] + 4) >> 3;
614 }
615 }
616
617 if (s->xll_scalable_lsb) {
618 int lsb_start = end_pos - 8 * chset->lsb_fsize[0] -
619 8 * (s->xll_banddata_crc & 2);
620 int done;
621 i = get_bits_count(gb);
622 if (i > lsb_start) {
623 av_log(s->avctx, AV_LOG_ERROR,
624 "chset data lsb exceeds NAVI size, end_pos %d, lsb_start %d, pos %d\n",
625 end_pos, lsb_start, i);
626 return AVERROR_INVALIDDATA;
627 }
628 if (i < lsb_start)
629 skip_bits_long(gb, lsb_start - i);
630
631 for (i = done = 0; i < chset->channels; i++) {
632 int bits = chset->scalable_lsbs[0][i];
633 if (bits > 0) {
634 /* The channel reordering is conceptually done
635 * before adding the lsb:s, so we need to do
636 * the inverse permutation here. */
637 unsigned pi = chset->orig_chan_order_inv[0][i];
638 int *sample_buf = s->xll_sample_buf +
639 (in_channel + pi) * s->xll_smpl_in_seg;
640 int adj = chset->bit_width_adj_per_ch[0][i];
641 int msb_shift = bits;
642 unsigned j;
643
644 if (adj > 0)
645 msb_shift += adj - 1;
646
647 for (j = 0; j < s->xll_smpl_in_seg; j++)
648 sample_buf[j] = (sample_buf[j] << msb_shift) +
649 (get_bits(gb, bits) << adj);
650
651 done += bits * s->xll_smpl_in_seg;
652 }
653 }
654 if (done > 8 * chset->lsb_fsize[0]) {
655 av_log(s->avctx, AV_LOG_ERROR,
656 "chset lsb exceeds lsb_size\n");
657 return AVERROR_INVALIDDATA;
658 }
659 }
660
661 /* Store output. */
662 for (i = 0; i < chset->channels; i++) {
663 int *sample_buf = s->xll_sample_buf +
664 (in_channel + i) * s->xll_smpl_in_seg;
665 int shift = 1 - chset->bit_resolution;
666 int out_channel = chset->orig_chan_order[0][i];
667 float *out;
668
669 /* XLL uses the channel order C, L, R, and we want L,
670 * R, C. FIXME: Generalize. */
671 if (chset->ch_mask_enabled &&
672 (chset->ch_mask & 7) == 7 && out_channel < 3)
673 out_channel = out_channel ? out_channel - 1 : 2;
674
675 out_channel += in_channel;
676 if (out_channel >= s->avctx->channels)
677 continue;
678
679 out = (float *) frame->extended_data[out_channel];
680 out += seg * s->xll_smpl_in_seg;
681
682 /* NOTE: A one bit means residual encoding is *not* used. */
683 if ((chset->residual_encode >> i) & 1) {
684 /* Replace channel samples.
685 * FIXME: Most likely not the right thing to do. */
686 for (j = 0; j < s->xll_smpl_in_seg; j++)
687 out[j] = ldexpf(sample_buf[j], shift);
688 } else {
689 /* Add residual signal to core channel */
690 for (j = 0; j < s->xll_smpl_in_seg; j++)
691 out[j] += ldexpf(sample_buf[j], shift);
692 }
693 }
694
695 if (chset->downmix_coeff_code_embedded &&
696 !chset->primary_ch_set && chset->hier_chset) {
697 /* Undo hierarchical downmix of earlier channels. */
698 unsigned mix_channel;
699 for (mix_channel = 0; mix_channel < in_channel; mix_channel++) {
700 float *mix_buf;
701 const int *col;
702 float coeff;
703 unsigned row;
704 /* Similar channel reorder C, L, R vs L, R, C reorder. */
705 if (chset->ch_mask_enabled &&
706 (chset->ch_mask & 7) == 7 && mix_channel < 3)
707 mix_buf = (float *) frame->extended_data[mix_channel ? mix_channel - 1 : 2];
708 else
709 mix_buf = (float *) frame->extended_data[mix_channel];
710
711 mix_buf += seg * s->xll_smpl_in_seg;
712 col = &chset->downmix_coeffs[mix_channel * (chset->channels + 1)];
713
714 /* Scale */
715 coeff = ldexpf(col[0], -16);
716 for (j = 0; j < s->xll_smpl_in_seg; j++)
717 mix_buf[j] *= coeff;
718
719 for (row = 0;
720 row < chset->channels && in_channel + row < s->avctx->channels;
721 row++)
722 if (col[row + 1]) {
723 const float *new_channel =
724 (const float *) frame->extended_data[in_channel + row];
725 new_channel += seg * s->xll_smpl_in_seg;
726 coeff = ldexpf(col[row + 1], -15);
727 for (j = 0; j < s->xll_smpl_in_seg; j++)
728 mix_buf[j] -= coeff * new_channel[j];
729 }
730 }
731 }
732
733next_chset:
734 in_channel += chset->channels;
735 /* Skip to next channel set using the NAVI info. */
736 i = get_bits_count(gb);
737 if (i > end_pos) {
738 av_log(s->avctx, AV_LOG_ERROR,
739 "chset data exceeds NAVI size\n");
740 return AVERROR_INVALIDDATA;
741 }
742 if (i < end_pos)
743 skip_bits_long(gb, end_pos - i);
744 }
745 }
746 return 0;
747}
libavcodec/dcadata.c+0−318
@@ -22,7 +22,6 @@ · 21 unmodified lines
22 22
23#include <stdint.h>23#include <stdint.h>
24 24
25#include "libavutil/channel_layout.h"
26#include "libavutil/mem.h"25#include "libavutil/mem.h"
27 26
28#include "dca.h"27#include "dca.h"
@@ -7509,76 +7508,6 @@ DECLARE_ALIGNED(16, const float, ff_dca_lfe_fir_128)[256] = { · 7480 unmodified lines
7509};7508};
7510#undef SCALE7509#undef SCALE
7511 7510
7512
7513#define SCALE(c) ((float)(c) / (256.0f * 32768.0f * 8388608.0f))
7514DECLARE_ALIGNED(16, const float, ff_dca_lfe_xll_fir_64)[256] = {
7515 SCALE( 6103), SCALE( 52170), SCALE(-558064), SCALE(1592440),
7516 SCALE(6290049), SCALE(1502534), SCALE(-546669), SCALE( 53047),
7517 SCALE( 1930), SCALE( 51089), SCALE(-568920), SCALE(1683709),
7518 SCALE(6286575), SCALE(1414057), SCALE(-534782), SCALE( 53729),
7519 SCALE( 2228), SCALE( 49794), SCALE(-579194), SCALE(1776276),
7520 SCALE(6279634), SCALE(1327070), SCALE(-522445), SCALE( 54228),
7521 SCALE( 2552), SCALE( 48275), SCALE(-588839), SCALE(1870070),
7522 SCALE(6269231), SCALE(1241632), SCALE(-509702), SCALE( 54550),
7523 SCALE( 2904), SCALE( 46523), SCALE(-597808), SCALE(1965017),
7524 SCALE(6255380), SCALE(1157798), SCALE(-496595), SCALE( 54708),
7525 SCALE( 3287), SCALE( 44529), SCALE(-606054), SCALE(2061044),
7526 SCALE(6238099), SCALE(1075621), SCALE(-483164), SCALE( 54710),
7527 SCALE( 3704), SCALE( 42282), SCALE(-613529), SCALE(2158071),
7528 SCALE(6217408), SCALE( 995149), SCALE(-469451), SCALE( 54566),
7529 SCALE( 4152), SCALE( 39774), SCALE(-620186), SCALE(2256019),
7530 SCALE(6193332), SCALE( 916430), SCALE(-455494), SCALE( 54285),
7531 SCALE( 4631), SCALE( 36995), SCALE(-625976), SCALE(2354805),
7532 SCALE(6165900), SCALE( 839507), SCALE(-441330), SCALE( 53876),
7533 SCALE( 5139), SCALE( 33937), SCALE(-630850), SCALE(2454343),
7534 SCALE(6135146), SCALE( 764419), SCALE(-426998), SCALE( 53348),
7535 SCALE( 5682), SCALE( 30591), SCALE(-634759), SCALE(2554547),
7536 SCALE(6101107), SCALE( 691203), SCALE(-412531), SCALE( 52711),
7537 SCALE( 6264), SCALE( 26948), SCALE(-637655), SCALE(2655326),
7538 SCALE(6063824), SCALE( 619894), SCALE(-397966), SCALE( 51972),
7539 SCALE( 6886), SCALE( 23001), SCALE(-639488), SCALE(2756591),
7540 SCALE(6023343), SCALE( 550521), SCALE(-383335), SCALE( 51140),
7541 SCALE( 7531), SCALE( 18741), SCALE(-640210), SCALE(2858248),
7542 SCALE(5979711), SCALE( 483113), SCALE(-368671), SCALE( 50224),
7543 SCALE( 8230), SCALE( 14162), SCALE(-639772), SCALE(2960201),
7544 SCALE(5932981), SCALE( 417692), SCALE(-354003), SCALE( 49231),
7545 SCALE( 8959), SCALE( 9257), SCALE(-638125), SCALE(3062355),
7546 SCALE(5883210), SCALE( 354281), SCALE(-339362), SCALE( 48168),
7547 SCALE( 9727), SCALE( 4018), SCALE(-635222), SCALE(3164612),
7548 SCALE(5830457), SCALE( 292897), SCALE(-324777), SCALE( 47044),
7549 SCALE( 10535), SCALE( -1558), SCALE(-631014), SCALE(3266872),
7550 SCALE(5774785), SCALE( 233555), SCALE(-310273), SCALE( 45866),
7551 SCALE( 11381), SCALE( -7480), SCALE(-625455), SCALE(3369035),
7552 SCALE(5716260), SCALE( 176267), SCALE(-295877), SCALE( 44640),
7553 SCALE( 12267), SCALE( -13750), SCALE(-618499), SCALE(3471000),
7554 SCALE(5654952), SCALE( 121042), SCALE(-281613), SCALE( 43373),
7555 SCALE( 13190), SCALE( -20372), SCALE(-610098), SCALE(3572664),
7556 SCALE(5590933), SCALE( 67886), SCALE(-267505), SCALE( 42072),
7557 SCALE( 14152), SCALE( -27352), SCALE(-600209), SCALE(3673924),
7558 SCALE(5524280), SCALE( 16800), SCALE(-253574), SCALE( 40743),
7559 SCALE( 15153), SCALE( -34691), SCALE(-588788), SCALE(3774676),
7560 SCALE(5455069), SCALE( -32214), SCALE(-239840), SCALE( 39391),
7561 SCALE( 16192), SCALE( -42390), SCALE(-575791), SCALE(3874816),
7562 SCALE(5383383), SCALE( -79159), SCALE(-226323), SCALE( 38022),
7563 SCALE( 17267), SCALE( -50453), SCALE(-561178), SCALE(3974239),
7564 SCALE(5309305), SCALE(-124041), SCALE(-213041), SCALE( 36642),
7565 SCALE( 18377), SCALE( -58879), SCALE(-544906), SCALE(4072841),
7566 SCALE(5232922), SCALE(-166869), SCALE(-200010), SCALE( 35256),
7567 SCALE( 19525), SCALE( -67667), SCALE(-526937), SCALE(4170517),
7568 SCALE(5154321), SCALE(-207653), SCALE(-187246), SCALE( 33866),
7569 SCALE( 20704), SCALE( -76817), SCALE(-507233), SCALE(4267162),
7570 SCALE(5073593), SCALE(-246406), SCALE(-174764), SCALE( 32480),
7571 SCALE( 21915), SCALE( -86327), SCALE(-485757), SCALE(4362672),
7572 SCALE(4990831), SCALE(-283146), SCALE(-162575), SCALE( 31101),
7573 SCALE( 23157), SCALE( -96193), SCALE(-462476), SCALE(4456942),
7574 SCALE(4906129), SCALE(-317890), SCALE(-150692), SCALE( 29732),
7575 SCALE( 24426), SCALE(-106412), SCALE(-437356), SCALE(4549871),
7576 SCALE(4819584), SCALE(-350658), SCALE(-139125), SCALE( 28376),
7577 SCALE( 25721), SCALE(-116977), SCALE(-410365), SCALE(4641355),
7578 SCALE(4731293), SCALE(-381475), SCALE(-127884), SCALE( 27038),
7579};
7580#undef SCALE
7581
7582DECLARE_ALIGNED(16, const float, ff_dca_fir_64bands)[1024] = {7511DECLARE_ALIGNED(16, const float, ff_dca_fir_64bands)[1024] = {
7583 /* Bank 0 */7512 /* Bank 0 */
7584 -7.1279389866041690e-8, -7.0950903150874990e-8,7513 -7.1279389866041690e-8, -7.0950903150874990e-8,
@@ -8178,220 +8107,11 @@ const uint32_t ff_dca_inv_dmixtable[FF_DCA_INV_DMIXTABLE_SIZE] = { · 593 unmodified lines
8178 65536,8107 65536,
8179};8108};
8180 8109
8181const float ff_dca_default_coeffs[10][6][2] = {
8182 { { 0.707107, 0.707107 }, { 0.000000, 0.000000 }, }, // A [LFE]
8183 { { 1.000000, 0.000000 }, { 0.000000, 1.000000 }, { 0.000000, 0.000000 }, }, // A + B (dual mono) [LFE]
8184 { { 1.000000, 0.000000 }, { 0.000000, 1.000000 }, { 0.000000, 0.000000 }, }, // L + R (stereo) [LFE]
8185 { { 1.000000, 0.000000 }, { 0.000000, 1.000000 }, { 0.000000, 0.000000 }, }, // (L+R) + (L-R) (sum-difference) [LFE]
8186 { { 1.000000, 0.000000 }, { 0.000000, 1.000000 }, { 0.000000, 0.000000 }, }, // LT + RT (left and right total) [LFE]
8187 { { 0.501187, 0.501187 }, { 0.707107, 0.000000 }, { 0.000000, 0.707107 }, { 0.000000, 0.000000 }, }, // C + L + R [LFE]
8188 { { 0.707107, 0.000000 }, { 0.000000, 0.707107 }, { 0.501187, 0.501187 }, { 0.000000, 0.000000 }, }, // L + R + S [LFE]
8189 { { 0.501187, 0.501187 }, { 0.707107, 0.000000 }, { 0.000000, 0.707107 }, { 0.501187, 0.501187 }, { 0.000000, 0.000000 }, }, // C + L + R + S [LFE]
8190 { { 0.707107, 0.000000 }, { 0.000000, 0.707107 }, { 0.501187, 0.000000 }, { 0.000000, 0.501187 }, { 0.000000, 0.000000 }, }, // L + R + SL + SR [LFE]
8191 { { 0.501187, 0.501187 }, { 0.707107, 0.000000 }, { 0.000000, 0.707107 }, { 0.501187, 0.000000 }, { 0.000000, 0.501187 }, { 0.000000, 0.000000 }, }, // C + L + R + SL + SR [LFE]
8192};
8193
8194const int32_t ff_dca_sampling_freqs[16] = {8110const int32_t ff_dca_sampling_freqs[16] = {
8195 8000, 16000, 32000, 64000, 128000, 22050, 44100, 88200,8111 8000, 16000, 32000, 64000, 128000, 22050, 44100, 88200,
8196 176400, 352800, 12000, 24000, 48000, 96000, 192000, 384000,8112 176400, 352800, 12000, 24000, 48000, 96000, 192000, 384000,
8197};8113};
8198 8114
8199/* downmix coeffs
8200 *
8201 * TABLE 9
8202 * ______________________________________
8203 * Down-mix coefficients for 8-channel source
8204 * audio (5 + 3 format)
8205 * lt
8206 * cen- rt lt ctr rt
8207 * lt ter ctr center
8208 * rt srd srd srd
8209 * ______________________________________
8210 * 1 0.71 0.74 1.0 0.71 0.71 0.58 0.58 0.58
8211 * 2 left 1.0 0.89 0.71 0.46 0.71 0.50
8212 * rt 0.45 0.71 0.89 1.0 0.50 0.71
8213 * 3 lt 1.0 0.89 0.71 0.45
8214 * rt 0.45 0.71 0.89 1.0
8215 * srd 0.71 0.71 0.71
8216 * 4 lt 1.0 0.89 0.71 0.45
8217 * rt 0.45 0.71 0.89 1.0
8218 * lt srd 1.0 0.71
8219 * rt srd 0.71 0.71
8220 * 4 lt 1.0 0.5
8221 * ctr 0.87 1.0 0.87
8222 * rt 0.5 1.0
8223 * srd 0.71 0.71 0.71
8224 * 5 lt 1.0 0.5
8225 * ctr 0.87 1.0 0.87
8226 * rt 0.5 1.0
8227 * lt srd 1.0 0.71
8228 * rt srd 0.71 1.0
8229 * 6 lt 1.0 0.5
8230 * lt ctr 0.87 0.71
8231 * rt ctr 0.71 0.87
8232 * rt 0.5 1.0
8233 * lt srd 1.0 0.71
8234 * rt srd 0.71 1.0
8235 * 6 lt 1.0 0.5
8236 * ctr 0.86 1.0 0.86
8237 * rt 0.5 1.0
8238 * lt srd 1.0
8239 * ctr srd 1.0
8240 * rt srd 1.0
8241 * 7 lt 1.0
8242 * lt ctr 1.0
8243 * ctr 1.0
8244 * rt ctr 1.0
8245 * rt 1.0
8246 * lt srd 1.0 0.71
8247 * rt srd 0.71 1.0
8248 * 7 lt 1.0 0.5
8249 * lt ctr 0.87 0.71
8250 * rt ctr 0.71 0.87
8251 * rt 0.5 1.0
8252 * lt srd 1.0
8253 * ctr srd 1.0
8254 * rt srd 1.0
8255 * 8 lt 1.0 0.5
8256 * lt ctr 0.87 0.71
8257 * rt ctr 0.71 0.87
8258 * rt 0.5 1.0
8259 * lt 1 srd 0.87 0.35
8260 * lt 2 srd 0.5 0.61
8261 * rt 2 srd 0.61 0.50
8262 * rt 2 srd 0.35 0.87
8263 *
8264 * Generation of Lt Rt
8265 *
8266 * In the case when the playback system has analog or digital surround
8267 * multi-channel capability, a down matrix from 5, 4, or 3 channel to
8268 * Lt Rt may be desirable. In the case when the number of decoded audio
8269 * channels exceeds 5, 4 or 3 respectively a first stage down mix to 5,
8270 * 4 or 3 chs should be used as described above.
8271 *
8272 * The down matrixing equations for 5-channel source audio to a
8273 * two-channel Lt Rt playback system are given by:
8274 *
8275 * Left = left + 0.7 * center - 0.7 * (lt surround + rt surround)
8276 *
8277 * Right = right + 0.7 * center + 0.7 * (lt surround + rt surround)
8278 *
8279 * Embedded mixing to 2-channel
8280 *
8281 * One concern arising from the proliferation of multi-channel audio
8282 * systems is that most home systems presently have only two channel
8283 * playback capability. To accommodate this a fixed 2-channel down
8284 * matrix processes is commonly used following the multi-channel
8285 * decoding stage. However, for music only applications the image
8286 * quality etc. of the down matrixed signal may not match that of an
8287 * equivalent stereo recording found on CD.
8288 *
8289 * The concept of embedded mixing is to allow the producer to
8290 * dynamically specify the matrixing coefficients within the audio
8291 * frame itself. In this way the stereo down mix at the decoder may be
8292 * better matched to a 2-channel playback environment.
8293 *
8294 * CHS*2, 7-bit down mix indexes (MCOEFFS) are transmitted along with
8295 * the multi-channel audio once in every frame. The indexes are
8296 * converted to attenuation factors using a 7 bit LUT. The 2-ch down
8297 * mix equations are as follows,
8298 *
8299 * Left Ch = sum (MCOEFF[n] * Ch[n]) for n=1, CHS
8300 *
8301 * Right Ch = sum (MCOEFF[n + CHS] * Ch[n]) for n=1, CHS
8302 *
8303 * where Ch(n) represents the subband samples in the (n)th audio channel.
8304 */
8305
8306const uint32_t ff_dca_map_xxch_to_native[28] = {
8307 AV_CH_FRONT_CENTER,
8308 AV_CH_FRONT_LEFT,
8309 AV_CH_FRONT_RIGHT,
8310 AV_CH_SIDE_LEFT,
8311 AV_CH_SIDE_RIGHT,
8312 AV_CH_LOW_FREQUENCY,
8313 AV_CH_BACK_CENTER,
8314 AV_CH_BACK_LEFT,
8315 AV_CH_BACK_RIGHT,
8316 AV_CH_SIDE_LEFT, /* side surround left -- dup sur side L */
8317 AV_CH_SIDE_RIGHT, /* side surround right -- dup sur side R */
8318 AV_CH_FRONT_LEFT_OF_CENTER,
8319 AV_CH_FRONT_RIGHT_OF_CENTER,
8320 AV_CH_TOP_FRONT_LEFT,
8321 AV_CH_TOP_FRONT_CENTER,
8322 AV_CH_TOP_FRONT_RIGHT,
8323 AV_CH_LOW_FREQUENCY, /* lfe2 -- duplicate lfe1 position */
8324 AV_CH_FRONT_LEFT_OF_CENTER, /* side front left -- dup front cntr L */
8325 AV_CH_FRONT_RIGHT_OF_CENTER,/* side front right -- dup front cntr R */
8326 AV_CH_TOP_CENTER, /* overhead */
8327 AV_CH_TOP_FRONT_LEFT, /* side high left -- dup */
8328 AV_CH_TOP_FRONT_RIGHT, /* side high right -- dup */
8329 AV_CH_TOP_BACK_CENTER,
8330 AV_CH_TOP_BACK_LEFT,
8331 AV_CH_TOP_BACK_RIGHT,
8332 AV_CH_BACK_CENTER, /* rear low center -- dup */
8333 AV_CH_BACK_LEFT, /* rear low left -- dup */
8334 AV_CH_BACK_RIGHT /* read low right -- dup */
8335};
8336
8337/* -1 are reserved or unknown */
8338const int ff_dca_ext_audio_descr_mask[8] = {
8339 DCA_EXT_XCH,
8340 -1,
8341 DCA_EXT_X96,
8342 DCA_EXT_XCH | DCA_EXT_X96,
8343 -1,
8344 -1,
8345 DCA_EXT_XXCH,
8346 -1,
8347};
8348
8349/* Tables for mapping dts channel configurations to libavcodec multichannel api.
8350 * Some compromises have been made for special configurations. Most configurations
8351 * are never used so complete accuracy is not needed.
8352 *
8353 * L = left, R = right, C = center, S = surround, F = front, R = rear, T = total, OV = overhead.
8354 * S -> side, when both rear and back are configured move one of them to the side channel
8355 * OV -> center back
8356 * All 2 channel configurations -> AV_CH_LAYOUT_STEREO
8357 */
8358const uint64_t ff_dca_core_channel_layout[16] = {
8359 AV_CH_FRONT_CENTER, ///< 1, A
8360 AV_CH_LAYOUT_STEREO, ///< 2, A + B (dual mono)
8361 AV_CH_LAYOUT_STEREO, ///< 2, L + R (stereo)
8362 AV_CH_LAYOUT_STEREO, ///< 2, (L + R) + (L - R) (sum-difference)
8363 AV_CH_LAYOUT_STEREO, ///< 2, LT + RT (left and right total)
8364 AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER, ///< 3, C + L + R
8365 AV_CH_LAYOUT_STEREO | AV_CH_BACK_CENTER, ///< 3, L + R + S
8366 AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER | AV_CH_BACK_CENTER, ///< 4, C + L + R + S
8367 AV_CH_LAYOUT_STEREO | AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT, ///< 4, L + R + SL + SR
8368
8369 AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER | AV_CH_SIDE_LEFT |
8370 AV_CH_SIDE_RIGHT, ///< 5, C + L + R + SL + SR
8371
8372 AV_CH_LAYOUT_STEREO | AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT |
8373 AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER, ///< 6, CL + CR + L + R + SL + SR
8374
8375 AV_CH_LAYOUT_STEREO | AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT |
8376 AV_CH_FRONT_CENTER | AV_CH_BACK_CENTER, ///< 6, C + L + R + LR + RR + OV
8377
8378 AV_CH_FRONT_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER |
8379 AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_BACK_CENTER |
8380 AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT, ///< 6, CF + CR + LF + RF + LR + RR
8381
8382 AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_CENTER |
8383 AV_CH_FRONT_RIGHT_OF_CENTER | AV_CH_LAYOUT_STEREO |
8384 AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT, ///< 7, CL + C + CR + L + R + SL + SR
8385
8386 AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER |
8387 AV_CH_LAYOUT_STEREO | AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT |
8388 AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT, ///< 8, CL + CR + L + R + SL1 + SL2 + SR1 + SR2
8389
8390 AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_CENTER |
8391 AV_CH_FRONT_RIGHT_OF_CENTER | AV_CH_LAYOUT_STEREO |
8392 AV_CH_SIDE_LEFT | AV_CH_BACK_CENTER | AV_CH_SIDE_RIGHT, ///< 8, CL + C + CR + L + R + SL + S + SR
8393};
8394
8395const int8_t ff_dca_lfe_index[16] = {8115const int8_t ff_dca_lfe_index[16] = {
8396 1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 1, 3, 2, 38116 1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 1, 3, 2, 3
8397};8117};
@@ -8415,25 +8135,6 @@ const int8_t ff_dca_channel_reorder_lfe[16][9] = { · 17 unmodified lines
8415 { 4, 2, 5, 0, 1, 6, 8, 7, -1 },8135 { 4, 2, 5, 0, 1, 6, 8, 7, -1 },
8416};8136};
8417 8137
8418const int8_t ff_dca_channel_reorder_lfe_xch[16][9] = {
8419 { 0, 2, -1, -1, -1, -1, -1, -1, -1 },
8420 { 0, 1, 3, -1, -1, -1, -1, -1, -1 },
8421 { 0, 1, 3, -1, -1, -1, -1, -1, -1 },
8422 { 0, 1, 3, -1, -1, -1, -1, -1, -1 },
8423 { 0, 1, 3, -1, -1, -1, -1, -1, -1 },
8424 { 2, 0, 1, 4, -1, -1, -1, -1, -1 },
8425 { 0, 1, 3, 4, -1, -1, -1, -1, -1 },
8426 { 2, 0, 1, 4, 5, -1, -1, -1, -1 },
8427 { 0, 1, 4, 5, 3, -1, -1, -1, -1 },
8428 { 2, 0, 1, 5, 6, 4, -1, -1, -1 },
8429 { 3, 4, 0, 1, 6, 7, 5, -1, -1 },
8430 { 2, 0, 1, 4, 5, 6, 7, -1, -1 },
8431 { 0, 6, 4, 5, 2, 3, 7, -1, -1 },
8432 { 4, 2, 5, 0, 1, 7, 8, 6, -1 },
8433 { 5, 6, 0, 1, 8, 3, 9, 4, 7 },
8434 { 4, 2, 5, 0, 1, 6, 9, 8, 7 },
8435};
8436
8437const int8_t ff_dca_channel_reorder_nolfe[16][9] = {8138const int8_t ff_dca_channel_reorder_nolfe[16][9] = {
8438 { 0, -1, -1, -1, -1, -1, -1, -1, -1 },8139 { 0, -1, -1, -1, -1, -1, -1, -1, -1 },
8439 { 0, 1, -1, -1, -1, -1, -1, -1, -1 },8140 { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
@@ -8453,25 +8154,6 @@ const int8_t ff_dca_channel_reorder_nolfe[16][9] = { · 13 unmodified lines
8453 { 3, 2, 4, 0, 1, 5, 7, 6, -1 },8154 { 3, 2, 4, 0, 1, 5, 7, 6, -1 },
8454};8155};
8455 8156
8456const int8_t ff_dca_channel_reorder_nolfe_xch[16][9] = {
8457 { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
8458 { 0, 1, 2, -1, -1, -1, -1, -1, -1 },
8459 { 0, 1, 2, -1, -1, -1, -1, -1, -1 },
8460 { 0, 1, 2, -1, -1, -1, -1, -1, -1 },
8461 { 0, 1, 2, -1, -1, -1, -1, -1, -1 },
8462 { 2, 0, 1, 3, -1, -1, -1, -1, -1 },
8463 { 0, 1, 2, 3, -1, -1, -1, -1, -1 },
8464 { 2, 0, 1, 3, 4, -1, -1, -1, -1 },
8465 { 0, 1, 3, 4, 2, -1, -1, -1, -1 },
8466 { 2, 0, 1, 4, 5, 3, -1, -1, -1 },
8467 { 2, 3, 0, 1, 5, 6, 4, -1, -1 },
8468 { 2, 0, 1, 3, 4, 5, 6, -1, -1 },
8469 { 0, 5, 3, 4, 1, 2, 6, -1, -1 },
8470 { 3, 2, 4, 0, 1, 6, 7, 5, -1 },
8471 { 4, 5, 0, 1, 7, 2, 8, 3, 6 },
8472 { 3, 2, 4, 0, 1, 5, 8, 7, 6 },
8473};
8474
8475const uint16_t ff_dca_vlc_offs[63] = {8157const uint16_t ff_dca_vlc_offs[63] = {
8476 0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364,8158 0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364,
8477 5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508,8159 5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508,
libavcodec/dcadata.h+0−10
@@ -45,7 +45,6 @@ extern const float ff_dca_fir_32bands_nonperfect[512]; · 44 unmodified lines
45 45
46extern const float ff_dca_lfe_fir_64[256];46extern const float ff_dca_lfe_fir_64[256];
47extern const float ff_dca_lfe_fir_128[256];47extern const float ff_dca_lfe_fir_128[256];
48extern const float ff_dca_lfe_xll_fir_64[256];
49extern const float ff_dca_fir_64bands[1024];48extern const float ff_dca_fir_64bands[1024];
50 49
51#define FF_DCA_DMIXTABLE_SIZE 24250#define FF_DCA_DMIXTABLE_SIZE 242
@@ -54,21 +53,12 @@ extern const float ff_dca_fir_64bands[1024]; · 2 unmodified lines
54extern const uint16_t ff_dca_dmixtable[FF_DCA_DMIXTABLE_SIZE];53extern const uint16_t ff_dca_dmixtable[FF_DCA_DMIXTABLE_SIZE];
55extern const uint32_t ff_dca_inv_dmixtable[FF_DCA_INV_DMIXTABLE_SIZE];54extern const uint32_t ff_dca_inv_dmixtable[FF_DCA_INV_DMIXTABLE_SIZE];
56 55
57extern const float ff_dca_default_coeffs[10][6][2];
58
59extern const uint32_t ff_dca_map_xxch_to_native[28];
60extern const int ff_dca_ext_audio_descr_mask[8];
61
62extern const uint64_t ff_dca_core_channel_layout[16];
63
64extern const int32_t ff_dca_sampling_freqs[16];56extern const int32_t ff_dca_sampling_freqs[16];
65 57
66extern const int8_t ff_dca_lfe_index[16];58extern const int8_t ff_dca_lfe_index[16];
67 59
68extern const int8_t ff_dca_channel_reorder_lfe[16][9];60extern const int8_t ff_dca_channel_reorder_lfe[16][9];
69extern const int8_t ff_dca_channel_reorder_lfe_xch[16][9];
70extern const int8_t ff_dca_channel_reorder_nolfe[16][9];61extern const int8_t ff_dca_channel_reorder_nolfe[16][9];
71extern const int8_t ff_dca_channel_reorder_nolfe_xch[16][9];
72 62
73extern const uint16_t ff_dca_vlc_offs[63];63extern const uint16_t ff_dca_vlc_offs[63];
74 64
libavcodec/dcadec.c+0−2067
@@ -1,2067 +0,0 @@
1/*
2 * DCA compatible decoder
3 * Copyright (C) 2004 Gildas Bazin
4 * Copyright (C) 2004 Benjamin Zores
5 * Copyright (C) 2006 Benjamin Larsson
6 * Copyright (C) 2007 Konstantin Shishkov
7 * Copyright (C) 2012 Paul B Mahol
8 * Copyright (C) 2014 Niels Möller
9 *
10 * This file is part of FFmpeg.
11 *
12 * FFmpeg is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
16 *
17 * FFmpeg is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with FFmpeg; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27#include <math.h>
28#include <stddef.h>
29#include <stdio.h>
30
31#include "libavutil/attributes.h"
32#include "libavutil/channel_layout.h"
33#include "libavutil/common.h"
34#include "libavutil/float_dsp.h"
35#include "libavutil/internal.h"
36#include "libavutil/intreadwrite.h"
37#include "libavutil/mathematics.h"
38#include "libavutil/opt.h"
39#include "libavutil/samplefmt.h"
40
41#include "avcodec.h"
42#include "dca.h"
43#include "dca_syncwords.h"
44#include "dcadata.h"
45#include "dcadsp.h"
46#include "dcahuff.h"
47#include "fft.h"
48#include "fmtconvert.h"
49#include "get_bits.h"
50#include "internal.h"
51#include "mathops.h"
52#include "profiles.h"
53#include "synth_filter.h"
54
55#if ARCH_ARM
56# include "arm/dca.h"
57#endif
58
59enum DCAMode {
60 DCA_MONO = 0,
61 DCA_CHANNEL,
62 DCA_STEREO,
63 DCA_STEREO_SUMDIFF,
64 DCA_STEREO_TOTAL,
65 DCA_3F,
66 DCA_2F1R,
67 DCA_3F1R,
68 DCA_2F2R,
69 DCA_3F2R,
70 DCA_4F2R
71};
72
73
74enum DCAXxchSpeakerMask {
75 DCA_XXCH_FRONT_CENTER = 0x0000001,
76 DCA_XXCH_FRONT_LEFT = 0x0000002,
77 DCA_XXCH_FRONT_RIGHT = 0x0000004,
78 DCA_XXCH_SIDE_REAR_LEFT = 0x0000008,
79 DCA_XXCH_SIDE_REAR_RIGHT = 0x0000010,
80 DCA_XXCH_LFE1 = 0x0000020,
81 DCA_XXCH_REAR_CENTER = 0x0000040,
82 DCA_XXCH_SURROUND_REAR_LEFT = 0x0000080,
83 DCA_XXCH_SURROUND_REAR_RIGHT = 0x0000100,
84 DCA_XXCH_SIDE_SURROUND_LEFT = 0x0000200,
85 DCA_XXCH_SIDE_SURROUND_RIGHT = 0x0000400,
86 DCA_XXCH_FRONT_CENTER_LEFT = 0x0000800,
87 DCA_XXCH_FRONT_CENTER_RIGHT = 0x0001000,
88 DCA_XXCH_FRONT_HIGH_LEFT = 0x0002000,
89 DCA_XXCH_FRONT_HIGH_CENTER = 0x0004000,
90 DCA_XXCH_FRONT_HIGH_RIGHT = 0x0008000,
91 DCA_XXCH_LFE2 = 0x0010000,
92 DCA_XXCH_SIDE_FRONT_LEFT = 0x0020000,
93 DCA_XXCH_SIDE_FRONT_RIGHT = 0x0040000,
94 DCA_XXCH_OVERHEAD = 0x0080000,
95 DCA_XXCH_SIDE_HIGH_LEFT = 0x0100000,
96 DCA_XXCH_SIDE_HIGH_RIGHT = 0x0200000,
97 DCA_XXCH_REAR_HIGH_CENTER = 0x0400000,
98 DCA_XXCH_REAR_HIGH_LEFT = 0x0800000,
99 DCA_XXCH_REAR_HIGH_RIGHT = 0x1000000,
100 DCA_XXCH_REAR_LOW_CENTER = 0x2000000,
101 DCA_XXCH_REAR_LOW_LEFT = 0x4000000,
102 DCA_XXCH_REAR_LOW_RIGHT = 0x8000000,
103};
104
105#define DCA_DOLBY 101 /* FIXME */
106
107#define DCA_CHANNEL_BITS 6
108#define DCA_CHANNEL_MASK 0x3F
109
110#define DCA_LFE 0x80
111
112#define HEADER_SIZE 14
113
114#define DCA_NSYNCAUX 0x9A1105A0
115
116/** Bit allocation */
117typedef struct BitAlloc {
118 int offset; ///< code values offset
119 int maxbits[8]; ///< max bits in VLC
120 int wrap; ///< wrap for get_vlc2()
121 VLC vlc[8]; ///< actual codes
122} BitAlloc;
123
124static BitAlloc dca_bitalloc_index; ///< indexes for samples VLC select
125static BitAlloc dca_tmode; ///< transition mode VLCs
126static BitAlloc dca_scalefactor; ///< scalefactor VLCs
127static BitAlloc dca_smpl_bitalloc[11]; ///< samples VLCs
128
129static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba,
130 int idx)
131{
132 return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) +
133 ba->offset;
134}
135
136static float dca_dmix_code(unsigned code);
137
138static av_cold void dca_init_vlcs(void)
139{
140 static int vlcs_initialized = 0;
141 int i, j, c = 14;
142 static VLC_TYPE dca_table[23622][2];
143
144 if (vlcs_initialized)
145 return;
146
147 dca_bitalloc_index.offset = 1;
148 dca_bitalloc_index.wrap = 2;
149 for (i = 0; i < 5; i++) {
150 dca_bitalloc_index.vlc[i].table = &dca_table[ff_dca_vlc_offs[i]];
151 dca_bitalloc_index.vlc[i].table_allocated = ff_dca_vlc_offs[i + 1] - ff_dca_vlc_offs[i];
152 init_vlc(&dca_bitalloc_index.vlc[i], bitalloc_12_vlc_bits[i], 12,
153 bitalloc_12_bits[i], 1, 1,
154 bitalloc_12_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
155 }
156 dca_scalefactor.offset = -64;
157 dca_scalefactor.wrap = 2;
158 for (i = 0; i < 5; i++) {
159 dca_scalefactor.vlc[i].table = &dca_table[ff_dca_vlc_offs[i + 5]];
160 dca_scalefactor.vlc[i].table_allocated = ff_dca_vlc_offs[i + 6] - ff_dca_vlc_offs[i + 5];
161 init_vlc(&dca_scalefactor.vlc[i], SCALES_VLC_BITS, 129,
162 scales_bits[i], 1, 1,
163 scales_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
164 }
165 dca_tmode.offset = 0;
166 dca_tmode.wrap = 1;
167 for (i = 0; i < 4; i++) {
168 dca_tmode.vlc[i].table = &dca_table[ff_dca_vlc_offs[i + 10]];
169 dca_tmode.vlc[i].table_allocated = ff_dca_vlc_offs[i + 11] - ff_dca_vlc_offs[i + 10];
170 init_vlc(&dca_tmode.vlc[i], tmode_vlc_bits[i], 4,
171 tmode_bits[i], 1, 1,
172 tmode_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
173 }
174
175 for (i = 0; i < 10; i++)
176 for (j = 0; j < 7; j++) {
177 if (!bitalloc_codes[i][j])
178 break;
179 dca_smpl_bitalloc[i + 1].offset = bitalloc_offsets[i];
180 dca_smpl_bitalloc[i + 1].wrap = 1 + (j > 4);
181 dca_smpl_bitalloc[i + 1].vlc[j].table = &dca_table[ff_dca_vlc_offs[c]];
182 dca_smpl_bitalloc[i + 1].vlc[j].table_allocated = ff_dca_vlc_offs[c + 1] - ff_dca_vlc_offs[c];
183
184 init_vlc(&dca_smpl_bitalloc[i + 1].vlc[j], bitalloc_maxbits[i][j],
185 bitalloc_sizes[i],
186 bitalloc_bits[i][j], 1, 1,
187 bitalloc_codes[i][j], 2, 2, INIT_VLC_USE_NEW_STATIC);
188 c++;
189 }
190 vlcs_initialized = 1;
191}
192
193static inline void get_array(GetBitContext *gb, int *dst, int len, int bits)
194{
195 while (len--)
196 *dst++ = get_bits(gb, bits);
197}
198
199static inline int dca_xxch2index(DCAContext *s, int xxch_ch)
200{
201 int i, base, mask;
202
203 /* locate channel set containing the channel */
204 for (i = -1, base = 0, mask = (s->xxch_core_spkmask & ~DCA_XXCH_LFE1);
205 i <= s->xxch_chset && !(mask & xxch_ch); mask = s->xxch_spk_masks[++i])
206 base += av_popcount(mask);
207
208 return base + av_popcount(mask & (xxch_ch - 1));
209}
210
211static int dca_parse_audio_coding_header(DCAContext *s, int base_channel,
212 int xxch)
213{
214 int i, j;
215 static const uint8_t adj_table[4] = { 16, 18, 20, 23 };
216 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
217 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
218 int hdr_pos = 0, hdr_size = 0;
219 float scale_factor;
220 int this_chans, acc_mask;
221 int embedded_downmix;
222 int nchans, mask[8];
223 int coeff, ichan;
224
225 /* xxch has arbitrary sized audio coding headers */
226 if (xxch) {
227 hdr_pos = get_bits_count(&s->gb);
228 hdr_size = get_bits(&s->gb, 7) + 1;
229 }
230
231 nchans = get_bits(&s->gb, 3) + 1;
232 if (xxch && nchans >= 3) {
233 av_log(s->avctx, AV_LOG_ERROR, "nchans %d is too large\n", nchans);
234 return AVERROR_INVALIDDATA;
235 } else if (nchans + base_channel > DCA_PRIM_CHANNELS_MAX) {
236 av_log(s->avctx, AV_LOG_ERROR, "channel sum %d + %d is too large\n", nchans, base_channel);
237 return AVERROR_INVALIDDATA;
238 }
239
240 s->audio_header.total_channels = nchans + base_channel;
241 s->audio_header.prim_channels = s->audio_header.total_channels;
242
243 /* obtain speaker layout mask & downmix coefficients for XXCH */
244 if (xxch) {
245 acc_mask = s->xxch_core_spkmask;
246
247 this_chans = get_bits(&s->gb, s->xxch_nbits_spk_mask - 6) << 6;
248 s->xxch_spk_masks[s->xxch_chset] = this_chans;
249 s->xxch_chset_nch[s->xxch_chset] = nchans;
250
251 for (i = 0; i <= s->xxch_chset; i++)
252 acc_mask |= s->xxch_spk_masks[i];
253
254 /* check for downmixing information */
255 if (get_bits1(&s->gb)) {
256 embedded_downmix = get_bits1(&s->gb);
257 coeff = get_bits(&s->gb, 6);
258
259 if (coeff<1 || coeff>61) {
260 av_log(s->avctx, AV_LOG_ERROR, "6bit coeff %d is out of range\n", coeff);
261 return AVERROR_INVALIDDATA;
262 }
263
264 scale_factor = -1.0f / dca_dmix_code((coeff<<2)-3);
265
266 s->xxch_dmix_sf[s->xxch_chset] = scale_factor;
267
268 for (i = base_channel; i < s->audio_header.prim_channels; i++) {
269 mask[i] = get_bits(&s->gb, s->xxch_nbits_spk_mask);
270 }
271
272 for (j = base_channel; j < s->audio_header.prim_channels; j++) {
273 memset(s->xxch_dmix_coeff[j], 0, sizeof(s->xxch_dmix_coeff[0]));
274 s->xxch_dmix_embedded |= (embedded_downmix << j);
275 for (i = 0; i < s->xxch_nbits_spk_mask; i++) {
276 if (mask[j] & (1 << i)) {
277 if ((1 << i) == DCA_XXCH_LFE1) {
278 av_log(s->avctx, AV_LOG_WARNING,
279 "DCA-XXCH: dmix to LFE1 not supported.\n");
280 continue;
281 }
282
283 coeff = get_bits(&s->gb, 7);
284 ichan = dca_xxch2index(s, 1 << i);
285 if ((coeff&63)<1 || (coeff&63)>61) {
286 av_log(s->avctx, AV_LOG_ERROR, "7bit coeff %d is out of range\n", coeff);
287 return AVERROR_INVALIDDATA;
288 }
289 s->xxch_dmix_coeff[j][ichan] = dca_dmix_code((coeff<<2)-3);
290 }
291 }
292 }
293 }
294 }
295
296 if (s->audio_header.prim_channels > DCA_PRIM_CHANNELS_MAX)
297 s->audio_header.prim_channels = DCA_PRIM_CHANNELS_MAX;
298
299 for (i = base_channel; i < s->audio_header.prim_channels; i++) {
300 s->audio_header.subband_activity[i] = get_bits(&s->gb, 5) + 2;
301 if (s->audio_header.subband_activity[i] > DCA_SUBBANDS)
302 s->audio_header.subband_activity[i] = DCA_SUBBANDS;
303 }
304 for (i = base_channel; i < s->audio_header.prim_channels; i++) {
305 s->audio_header.vq_start_subband[i] = get_bits(&s->gb, 5) + 1;
306 if (s->audio_header.vq_start_subband[i] > DCA_SUBBANDS)
307 s->audio_header.vq_start_subband[i] = DCA_SUBBANDS;
308 }
309 get_array(&s->gb, s->audio_header.joint_intensity + base_channel,
310 s->audio_header.prim_channels - base_channel, 3);
311 get_array(&s->gb, s->audio_header.transient_huffman + base_channel,
312 s->audio_header.prim_channels - base_channel, 2);
313 get_array(&s->gb, s->audio_header.scalefactor_huffman + base_channel,
314 s->audio_header.prim_channels - base_channel, 3);
315 get_array(&s->gb, s->audio_header.bitalloc_huffman + base_channel,
316 s->audio_header.prim_channels - base_channel, 3);
317
318 /* Get codebooks quantization indexes */
319 if (!base_channel)
320 memset(s->audio_header.quant_index_huffman, 0, sizeof(s->audio_header.quant_index_huffman));
321 for (j = 1; j < 11; j++)
322 for (i = base_channel; i < s->audio_header.prim_channels; i++)
323 s->audio_header.quant_index_huffman[i][j] = get_bits(&s->gb, bitlen[j]);
324
325 /* Get scale factor adjustment */
326 for (j = 0; j < 11; j++)
327 for (i = base_channel; i < s->audio_header.prim_channels; i++)
328 s->audio_header.scalefactor_adj[i][j] = 16;
329
330 for (j = 1; j < 11; j++)
331 for (i = base_channel; i < s->audio_header.prim_channels; i++)
332 if (s->audio_header.quant_index_huffman[i][j] < thr[j])
333 s->audio_header.scalefactor_adj[i][j] = adj_table[get_bits(&s->gb, 2)];
334
335 if (!xxch) {
336 if (s->crc_present) {
337 /* Audio header CRC check */
338 get_bits(&s->gb, 16);
339 }
340 } else {
341 /* Skip to the end of the header, also ignore CRC if present */
342 i = get_bits_count(&s->gb);
343 if (hdr_pos + 8 * hdr_size > i)
344 skip_bits_long(&s->gb, hdr_pos + 8 * hdr_size - i);
345 }
346
347 s->current_subframe = 0;
348 s->current_subsubframe = 0;
349
350 return 0;
351}
352
353static int dca_parse_frame_header(DCAContext *s)
354{
355 init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);
356
357 /* Sync code */
358 skip_bits_long(&s->gb, 32);
359
360 /* Frame header */
361 s->frame_type = get_bits(&s->gb, 1);
362 s->samples_deficit = get_bits(&s->gb, 5) + 1;
363 s->crc_present = get_bits(&s->gb, 1);
364 s->sample_blocks = get_bits(&s->gb, 7) + 1;
365 s->frame_size = get_bits(&s->gb, 14) + 1;
366 if (s->frame_size < 95)
367 return AVERROR_INVALIDDATA;
368 s->amode = get_bits(&s->gb, 6);
369 s->sample_rate = avpriv_dca_sample_rates[get_bits(&s->gb, 4)];
370 if (!s->sample_rate)
371 return AVERROR_INVALIDDATA;
372 s->bit_rate_index = get_bits(&s->gb, 5);
373 s->bit_rate = ff_dca_bit_rates[s->bit_rate_index];
374 if (!s->bit_rate)
375 return AVERROR_INVALIDDATA;
376
377 skip_bits1(&s->gb); // always 0 (reserved, cf. ETSI TS 102 114 V1.4.1)
378 s->dynrange = get_bits(&s->gb, 1);
379 s->timestamp = get_bits(&s->gb, 1);
380 s->aux_data = get_bits(&s->gb, 1);
381 s->hdcd = get_bits(&s->gb, 1);
382 s->ext_descr = get_bits(&s->gb, 3);
383 s->ext_coding = get_bits(&s->gb, 1);
384 s->aspf = get_bits(&s->gb, 1);
385 s->lfe = get_bits(&s->gb, 2);
386 s->predictor_history = get_bits(&s->gb, 1);
387
388 if (s->lfe > 2) {
389 s->lfe = 0;
390 av_log(s->avctx, AV_LOG_ERROR, "Invalid LFE value: %d\n", s->lfe);
391 return AVERROR_INVALIDDATA;
392 }
393
394 /* TODO: check CRC */
395 if (s->crc_present)
396 s->header_crc = get_bits(&s->gb, 16);
397
398 s->multirate_inter = get_bits(&s->gb, 1);
399 s->version = get_bits(&s->gb, 4);
400 s->copy_history = get_bits(&s->gb, 2);
401 s->source_pcm_res = get_bits(&s->gb, 3);
402 s->front_sum = get_bits(&s->gb, 1);
403 s->surround_sum = get_bits(&s->gb, 1);
404 s->dialog_norm = get_bits(&s->gb, 4);
405
406 /* FIXME: channels mixing levels */
407 s->output = s->amode;
408 if (s->lfe)
409 s->output |= DCA_LFE;
410
411 /* Primary audio coding header */
412 s->audio_header.subframes = get_bits(&s->gb, 4) + 1;
413
414 return dca_parse_audio_coding_header(s, 0, 0);
415}
416
417static inline int get_scale(GetBitContext *gb, int level, int value, int log2range)
418{
419 if (level < 5) {
420 /* huffman encoded */
421 value += get_bitalloc(gb, &dca_scalefactor, level);
422 value = av_clip(value, 0, (1 << log2range) - 1);
423 } else if (level < 8) {
424 if (level + 1 > log2range) {
425 skip_bits(gb, level + 1 - log2range);
426 value = get_bits(gb, log2range);
427 } else {
428 value = get_bits(gb, level + 1);
429 }
430 }
431 return value;
432}
433
434static int dca_subframe_header(DCAContext *s, int base_channel, int block_index)
435{
436 /* Primary audio coding side information */
437 int j, k;
438
439 if (get_bits_left(&s->gb) < 0)
440 return AVERROR_INVALIDDATA;
441
442 if (!base_channel) {
443 s->subsubframes[s->current_subframe] = get_bits(&s->gb, 2) + 1;
444 if (block_index + s->subsubframes[s->current_subframe] > (s->sample_blocks / SAMPLES_PER_SUBBAND)) {
445 s->subsubframes[s->current_subframe] = 1;
446 return AVERROR_INVALIDDATA;
447 }
448 s->partial_samples[s->current_subframe] = get_bits(&s->gb, 3);
449 }
450
451 for (j = base_channel; j < s->audio_header.prim_channels; j++) {
452 for (k = 0; k < s->audio_header.subband_activity[j]; k++)
453 s->dca_chan[j].prediction_mode[k] = get_bits(&s->gb, 1);
454 }
455
456 /* Get prediction codebook */
457 for (j = base_channel; j < s->audio_header.prim_channels; j++) {
458 for (k = 0; k < s->audio_header.subband_activity[j]; k++) {
459 if (s->dca_chan[j].prediction_mode[k] > 0) {
460 /* (Prediction coefficient VQ address) */
461 s->dca_chan[j].prediction_vq[k] = get_bits(&s->gb, 12);
462 }
463 }
464 }
465
466 /* Bit allocation index */
467 for (j = base_channel; j < s->audio_header.prim_channels; j++) {
468 for (k = 0; k < s->audio_header.vq_start_subband[j]; k++) {
469 if (s->audio_header.bitalloc_huffman[j] == 6)
470 s->dca_chan[j].bitalloc[k] = get_bits(&s->gb, 5);
471 else if (s->audio_header.bitalloc_huffman[j] == 5)
472 s->dca_chan[j].bitalloc[k] = get_bits(&s->gb, 4);
473 else if (s->audio_header.bitalloc_huffman[j] == 7) {
474 av_log(s->avctx, AV_LOG_ERROR,
475 "Invalid bit allocation index\n");
476 return AVERROR_INVALIDDATA;
477 } else {
478 s->dca_chan[j].bitalloc[k] =
479 get_bitalloc(&s->gb, &dca_bitalloc_index, s->audio_header.bitalloc_huffman[j]);
480 }
481
482 if (s->dca_chan[j].bitalloc[k] > 26) {
483 ff_dlog(s->avctx, "bitalloc index [%i][%i] too big (%i)\n",
484 j, k, s->dca_chan[j].bitalloc[k]);
485 return AVERROR_INVALIDDATA;
486 }
487 }
488 }
489
490 /* Transition mode */
491 for (j = base_channel; j < s->audio_header.prim_channels; j++) {
492 for (k = 0; k < s->audio_header.subband_activity[j]; k++) {
493 s->dca_chan[j].transition_mode[k] = 0;
494 if (s->subsubframes[s->current_subframe] > 1 &&
495 k < s->audio_header.vq_start_subband[j] && s->dca_chan[j].bitalloc[k] > 0) {
496 s->dca_chan[j].transition_mode[k] =
497 get_bitalloc(&s->gb, &dca_tmode, s->audio_header.transient_huffman[j]);
498 }
499 }
500 }
501
502 if (get_bits_left(&s->gb) < 0)
503 return AVERROR_INVALIDDATA;
504
505 for (j = base_channel; j < s->audio_header.prim_channels; j++) {
506 const uint32_t *scale_table;
507 int scale_sum, log_size;
508
509 memset(s->dca_chan[j].scale_factor, 0,
510 s->audio_header.subband_activity[j] * sizeof(s->dca_chan[j].scale_factor[0][0]) * 2);
511
512 if (s->audio_header.scalefactor_huffman[j] == 6) {
513 scale_table = ff_dca_scale_factor_quant7;
514 log_size = 7;
515 } else {
516 scale_table = ff_dca_scale_factor_quant6;
517 log_size = 6;
518 }
519
520 /* When huffman coded, only the difference is encoded */
521 scale_sum = 0;
522
523 for (k = 0; k < s->audio_header.subband_activity[j]; k++) {
524 if (k >= s->audio_header.vq_start_subband[j] || s->dca_chan[j].bitalloc[k] > 0) {
525 scale_sum = get_scale(&s->gb, s->audio_header.scalefactor_huffman[j], scale_sum, log_size);
526 s->dca_chan[j].scale_factor[k][0] = scale_table[scale_sum];
527 }
528
529 if (k < s->audio_header.vq_start_subband[j] && s->dca_chan[j].transition_mode[k]) {
530 /* Get second scale factor */
531 scale_sum = get_scale(&s->gb, s->audio_header.scalefactor_huffman[j], scale_sum, log_size);
532 s->dca_chan[j].scale_factor[k][1] = scale_table[scale_sum];
533 }
534 }
535 }
536
537 /* Joint subband scale factor codebook select */
538 for (j = base_channel; j < s->audio_header.prim_channels; j++) {
539 /* Transmitted only if joint subband coding enabled */
540 if (s->audio_header.joint_intensity[j] > 0)
541 s->dca_chan[j].joint_huff = get_bits(&s->gb, 3);
542 }
543
544 if (get_bits_left(&s->gb) < 0)
545 return AVERROR_INVALIDDATA;
546
547 /* Scale factors for joint subband coding */
548 for (j = base_channel; j < s->audio_header.prim_channels; j++) {
549 int source_channel;
550
551 /* Transmitted only if joint subband coding enabled */
552 if (s->audio_header.joint_intensity[j] > 0) {
553 int scale = 0;
554 source_channel = s->audio_header.joint_intensity[j] - 1;
555
556 /* When huffman coded, only the difference is encoded
557 * (is this valid as well for joint scales ???) */
558
559 for (k = s->audio_header.subband_activity[j];
560 k < s->audio_header.subband_activity[source_channel]; k++) {
561 scale = get_scale(&s->gb, s->dca_chan[j].joint_huff, 64 /* bias */, 7);
562 s->dca_chan[j].joint_scale_factor[k] = scale; /*joint_scale_table[scale]; */
563 }
564
565 if (!(s->debug_flag & 0x02)) {
566 av_log(s->avctx, AV_LOG_DEBUG,
567 "Joint stereo coding not supported\n");
568 s->debug_flag |= 0x02;
569 }
570 }
571 }
572
573 /* Dynamic range coefficient */
574 if (!base_channel && s->dynrange)
575 s->dynrange_coef = get_bits(&s->gb, 8);
576
577 /* Side information CRC check word */
578 if (s->crc_present) {
579 get_bits(&s->gb, 16);
580 }
581
582 /*
583 * Primary audio data arrays
584 */
585
586 /* VQ encoded high frequency subbands */
587 for (j = base_channel; j < s->audio_header.prim_channels; j++)
588 for (k = s->audio_header.vq_start_subband[j]; k < s->audio_header.subband_activity[j]; k++)
589 /* 1 vector -> 32 samples */
590 s->dca_chan[j].high_freq_vq[k] = get_bits(&s->gb, 10);
591
592 /* Low frequency effect data */
593 if (!base_channel && s->lfe) {
594 int quant7;
595 /* LFE samples */
596 int lfe_samples = 2 * s->lfe * (4 + block_index);
597 int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]);
598 float lfe_scale;
599
600 for (j = lfe_samples; j < lfe_end_sample; j++) {
601 /* Signed 8 bits int */
602 s->lfe_data[j] = get_sbits(&s->gb, 8);
603 }
604
605 /* Scale factor index */
606 quant7 = get_bits(&s->gb, 8);
607 if (quant7 > 127) {
608 avpriv_request_sample(s->avctx, "LFEScaleIndex larger than 127");
609 return AVERROR_INVALIDDATA;
610 }
611 s->lfe_scale_factor = ff_dca_scale_factor_quant7[quant7];
612
613 /* Quantization step size * scale factor */
614 lfe_scale = 0.035 * s->lfe_scale_factor;
615
616 for (j = lfe_samples; j < lfe_end_sample; j++)
617 s->lfe_data[j] *= lfe_scale;
618 }
619
620 return 0;
621}
622
623static void qmf_32_subbands(DCAContext *s, int chans,
624 float samples_in[DCA_SUBBANDS][SAMPLES_PER_SUBBAND], float *samples_out,
625 float scale)
626{
627 const float *prCoeff;
628
629 int sb_act = s->audio_header.subband_activity[chans];
630
631 scale *= sqrt(1 / 8.0);
632
633 /* Select filter */
634 if (!s->multirate_inter) /* Non-perfect reconstruction */
635 prCoeff = ff_dca_fir_32bands_nonperfect;
636 else /* Perfect reconstruction */
637 prCoeff = ff_dca_fir_32bands_perfect;
638
639 s->dcadsp.qmf_32_subbands(samples_in, sb_act, &s->synth, &s->imdct,
640 s->dca_chan[chans].subband_fir_hist,
641 &s->dca_chan[chans].hist_index,
642 s->dca_chan[chans].subband_fir_noidea, prCoeff,
643 samples_out, s->raXin, scale);
644}
645
646static QMF64_table *qmf64_precompute(void)
647{
648 unsigned i, j;
649 QMF64_table *table = av_malloc(sizeof(*table));
650 if (!table)
651 return NULL;
652
653 for (i = 0; i < 32; i++)
654 for (j = 0; j < 32; j++)
655 table->dct4_coeff[i][j] = cos((2 * i + 1) * (2 * j + 1) * M_PI / 128);
656 for (i = 0; i < 32; i++)
657 for (j = 0; j < 32; j++)
658 table->dct2_coeff[i][j] = cos((2 * i + 1) * j * M_PI / 64);
659
660 /* FIXME: Is the factor 0.125 = 1/8 right? */
661 for (i = 0; i < 32; i++)
662 table->rcos[i] = 0.125 / cos((2 * i + 1) * M_PI / 256);
663 for (i = 0; i < 32; i++)
664 table->rsin[i] = -0.125 / sin((2 * i + 1) * M_PI / 256);
665
666 return table;
667}
668
669/* FIXME: Totally unoptimized. Based on the reference code and
670 * http://multimedia.cx/mirror/dca-transform.pdf, with guessed tweaks
671 * for doubling the size. */
672static void qmf_64_subbands(DCAContext *s, int chans,
673 float samples_in[DCA_SUBBANDS_X96K][SAMPLES_PER_SUBBAND],
674 float *samples_out, float scale)
675{
676 float raXin[64];
677 float A[32], B[32];
678 float *raX = s->dca_chan[chans].subband_fir_hist;
679 float *raZ = s->dca_chan[chans].subband_fir_noidea;
680 unsigned i, j, k, subindex;
681
682 for (i = s->audio_header.subband_activity[chans]; i < DCA_SUBBANDS_X96K; i++)
683 raXin[i] = 0.0;
684 for (subindex = 0; subindex < SAMPLES_PER_SUBBAND; subindex++) {
685 for (i = 0; i < s->audio_header.subband_activity[chans]; i++)
686 raXin[i] = samples_in[i][subindex];
687
688 for (k = 0; k < 32; k++) {
689 A[k] = 0.0;
690 for (i = 0; i < 32; i++)
691 A[k] += (raXin[2 * i] + raXin[2 * i + 1]) * s->qmf64_table->dct4_coeff[k][i];
692 }
693 for (k = 0; k < 32; k++) {
694 B[k] = raXin[0] * s->qmf64_table->dct2_coeff[k][0];
695 for (i = 1; i < 32; i++)
696 B[k] += (raXin[2 * i] + raXin[2 * i - 1]) * s->qmf64_table->dct2_coeff[k][i];
697 }
698 for (k = 0; k < 32; k++) {
699 raX[k] = s->qmf64_table->rcos[k] * (A[k] + B[k]);
700 raX[63 - k] = s->qmf64_table->rsin[k] * (A[k] - B[k]);
701 }
702
703 for (i = 0; i < DCA_SUBBANDS_X96K; i++) {
704 float out = raZ[i];
705 for (j = 0; j < 1024; j += 128)
706 out += ff_dca_fir_64bands[j + i] * (raX[j + i] - raX[j + 63 - i]);
707 *samples_out++ = out * scale;
708 }
709
710 for (i = 0; i < DCA_SUBBANDS_X96K; i++) {
711 float hist = 0.0;
712 for (j = 0; j < 1024; j += 128)
713 hist += ff_dca_fir_64bands[64 + j + i] * (-raX[i + j] - raX[j + 63 - i]);
714
715 raZ[i] = hist;
716 }
717
718 /* FIXME: Make buffer circular, to avoid this move. */
719 memmove(raX + 64, raX, (1024 - 64) * sizeof(*raX));
720 }
721}
722
723static void lfe_interpolation_fir(DCAContext *s, const float *samples_in,
724 float *samples_out)
725{
726 /* samples_in: An array holding decimated samples.
727 * Samples in current subframe starts from samples_in[0],
728 * while samples_in[-1], samples_in[-2], ..., stores samples
729 * from last subframe as history.
730 *
731 * samples_out: An array holding interpolated samples
732 */
733
734 int idx;
735 const float *prCoeff;
736 int deciindex;
737
738 /* Select decimation filter */
739 if (s->lfe == 1) {
740 idx = 1;
741 prCoeff = ff_dca_lfe_fir_128;
742 } else {
743 idx = 0;
744 if (s->exss_ext_mask & DCA_EXT_EXSS_XLL)
745 prCoeff = ff_dca_lfe_xll_fir_64;
746 else
747 prCoeff = ff_dca_lfe_fir_64;
748 }
749 /* Interpolation */
750 for (deciindex = 0; deciindex < 2 * s->lfe; deciindex++) {
751 s->dcadsp.lfe_fir[idx](samples_out, samples_in, prCoeff);
752 samples_in++;
753 samples_out += 2 * 32 * (1 + idx);
754 }
755}
756
757/* downmixing routines */
758#define MIX_REAR1(samples, s1, rs, coef) \
759 samples[0][i] += samples[s1][i] * coef[rs][0]; \
760 samples[1][i] += samples[s1][i] * coef[rs][1];
761
762#define MIX_REAR2(samples, s1, s2, rs, coef) \
763 samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \
764 samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1];
765
766#define MIX_FRONT3(samples, coef) \
767 t = samples[c][i]; \
768 u = samples[l][i]; \
769 v = samples[r][i]; \
770 samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \
771 samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1];
772
773#define DOWNMIX_TO_STEREO(op1, op2) \
774 for (i = 0; i < 256; i++) { \
775 op1 \
776 op2 \
777 }
778
779static void dca_downmix(float **samples, int srcfmt, int lfe_present,
780 float coef[DCA_PRIM_CHANNELS_MAX + 1][2],
781 const int8_t *channel_mapping)
782{
783 int c, l, r, sl, sr, s;
784 int i;
785 float t, u, v;
786
787 switch (srcfmt) {
788 case DCA_MONO:
789 case DCA_4F2R:
790 av_log(NULL, AV_LOG_ERROR, "Not implemented!\n");
791 break;
792 case DCA_CHANNEL:
793 case DCA_STEREO:
794 case DCA_STEREO_TOTAL:
795 case DCA_STEREO_SUMDIFF:
796 break;
797 case DCA_3F:
798 c = channel_mapping[0];
799 l = channel_mapping[1];
800 r = channel_mapping[2];
801 DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef), );
802 break;
803 case DCA_2F1R:
804 s = channel_mapping[2];
805 DOWNMIX_TO_STEREO(MIX_REAR1(samples, s, 2, coef), );
806 break;
807 case DCA_3F1R:
808 c = channel_mapping[0];
809 l = channel_mapping[1];
810 r = channel_mapping[2];
811 s = channel_mapping[3];
812 DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef),
813 MIX_REAR1(samples, s, 3, coef));
814 break;
815 case DCA_2F2R:
816 sl = channel_mapping[2];
817 sr = channel_mapping[3];
818 DOWNMIX_TO_STEREO(MIX_REAR2(samples, sl, sr, 2, coef), );
819 break;
820 case DCA_3F2R:
821 c = channel_mapping[0];
822 l = channel_mapping[1];
823 r = channel_mapping[2];
824 sl = channel_mapping[3];
825 sr = channel_mapping[4];
826 DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef),
827 MIX_REAR2(samples, sl, sr, 3, coef));
828 break;
829 }
830 if (lfe_present) {
831 int lf_buf = ff_dca_lfe_index[srcfmt];
832 int lf_idx = ff_dca_channels[srcfmt];
833 for (i = 0; i < 256; i++) {
834 samples[0][i] += samples[lf_buf][i] * coef[lf_idx][0];
835 samples[1][i] += samples[lf_buf][i] * coef[lf_idx][1];
836 }
837 }
838}
839
840#ifndef decode_blockcodes
841/* Very compact version of the block code decoder that does not use table
842 * look-up but is slightly slower */
843static int decode_blockcode(int code, int levels, int32_t *values)
844{
845 int i;
846 int offset = (levels - 1) >> 1;
847
848 for (i = 0; i < 4; i++) {
849 int div = FASTDIV(code, levels);
850 values[i] = code - offset - div * levels;
851 code = div;
852 }
853
854 return code;
855}
856
857static int decode_blockcodes(int code1, int code2, int levels, int32_t *values)
858{
859 return decode_blockcode(code1, levels, values) |
860 decode_blockcode(code2, levels, values + 4);
861}
862#endif
863
864static const uint8_t abits_sizes[7] = { 7, 10, 12, 13, 15, 17, 19 };
865static const uint8_t abits_levels[7] = { 3, 5, 7, 9, 13, 17, 25 };
866
867static int dca_subsubframe(DCAContext *s, int base_channel, int block_index)
868{
869 int k, l;
870 int subsubframe = s->current_subsubframe;
871 const uint32_t *quant_step_table;
872
873 /*
874 * Audio data
875 */
876
877 /* Select quantization step size table */
878 if (s->bit_rate_index == 0x1f)
879 quant_step_table = ff_dca_lossless_quant;
880 else
881 quant_step_table = ff_dca_lossy_quant;
882
883 for (k = base_channel; k < s->audio_header.prim_channels; k++) {
884 int32_t (*subband_samples)[8] = s->dca_chan[k].subband_samples[block_index];
885
886 if (get_bits_left(&s->gb) < 0)
887 return AVERROR_INVALIDDATA;
888
889 for (l = 0; l < s->audio_header.vq_start_subband[k]; l++) {
890 int m;
891
892 /* Select the mid-tread linear quantizer */
893 int abits = s->dca_chan[k].bitalloc[l];
894
895 uint32_t quant_step_size = quant_step_table[abits];
896
897 /*
898 * Extract bits from the bit stream
899 */
900 if (!abits)
901 memset(subband_samples[l], 0, SAMPLES_PER_SUBBAND *
902 sizeof(subband_samples[l][0]));
903 else {
904 uint32_t rscale;
905 /* Deal with transients */
906 int sfi = s->dca_chan[k].transition_mode[l] &&
907 subsubframe >= s->dca_chan[k].transition_mode[l];
908 /* Determine quantization index code book and its type.
909 Select quantization index code book */
910 int sel = s->audio_header.quant_index_huffman[k][abits];
911
912 rscale = (s->dca_chan[k].scale_factor[l][sfi] *
913 s->audio_header.scalefactor_adj[k][sel] + 8) >> 4;
914
915 if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table) {
916 if (abits <= 7) {
917 /* Block code */
918 int block_code1, block_code2, size, levels, err;
919
920 size = abits_sizes[abits - 1];
921 levels = abits_levels[abits - 1];
922
923 block_code1 = get_bits(&s->gb, size);
924 block_code2 = get_bits(&s->gb, size);
925 err = decode_blockcodes(block_code1, block_code2,
926 levels, subband_samples[l]);
927 if (err) {
928 av_log(s->avctx, AV_LOG_ERROR,
929 "ERROR: block code look-up failed\n");
930 return AVERROR_INVALIDDATA;
931 }
932 } else {
933 /* no coding */
934 for (m = 0; m < SAMPLES_PER_SUBBAND; m++)
935 subband_samples[l][m] = get_sbits(&s->gb, abits - 3);
936 }
937 } else {
938 /* Huffman coded */
939 for (m = 0; m < SAMPLES_PER_SUBBAND; m++)
940 subband_samples[l][m] = get_bitalloc(&s->gb,
941 &dca_smpl_bitalloc[abits], sel);
942 }
943 s->dcadsp.dequantize(subband_samples[l], quant_step_size, rscale);
944 }
945 }
946
947 for (l = 0; l < s->audio_header.vq_start_subband[k]; l++) {
948 int m;
949 /*
950 * Inverse ADPCM if in prediction mode
951 */
952 if (s->dca_chan[k].prediction_mode[l]) {
953 int n;
954 if (s->predictor_history)
955 subband_samples[l][0] += (ff_dca_adpcm_vb[s->dca_chan[k].prediction_vq[l]][0] *
956 (int64_t)s->dca_chan[k].subband_samples_hist[l][3] +
957 ff_dca_adpcm_vb[s->dca_chan[k].prediction_vq[l]][1] *
958 (int64_t)s->dca_chan[k].subband_samples_hist[l][2] +
959 ff_dca_adpcm_vb[s->dca_chan[k].prediction_vq[l]][2] *
960 (int64_t)s->dca_chan[k].subband_samples_hist[l][1] +
961 ff_dca_adpcm_vb[s->dca_chan[k].prediction_vq[l]][3] *
962 (int64_t)s->dca_chan[k].subband_samples_hist[l][0]) +
963 (1 << 12) >> 13;
964 for (m = 1; m < SAMPLES_PER_SUBBAND; m++) {
965 int64_t sum = ff_dca_adpcm_vb[s->dca_chan[k].prediction_vq[l]][0] *
966 (int64_t)subband_samples[l][m - 1];
967 for (n = 2; n <= 4; n++)
968 if (m >= n)
969 sum += ff_dca_adpcm_vb[s->dca_chan[k].prediction_vq[l]][n - 1] *
970 (int64_t)subband_samples[l][m - n];
971 else if (s->predictor_history)
972 sum += ff_dca_adpcm_vb[s->dca_chan[k].prediction_vq[l]][n - 1] *
973 (int64_t)s->dca_chan[k].subband_samples_hist[l][m - n + 4];
974 subband_samples[l][m] += (int32_t)(sum + (1 << 12) >> 13);
975 }
976 }
977
978 }
979 /* Backup predictor history for adpcm */
980 for (l = 0; l < DCA_SUBBANDS; l++)
981 AV_COPY128(s->dca_chan[k].subband_samples_hist[l], &subband_samples[l][4]);
982
983
984 /*
985 * Decode VQ encoded high frequencies
986 */
987 if (s->audio_header.subband_activity[k] > s->audio_header.vq_start_subband[k]) {
988 if (!(s->debug_flag & 0x01)) {
989 av_log(s->avctx, AV_LOG_DEBUG,
990 "Stream with high frequencies VQ coding\n");
991 s->debug_flag |= 0x01;
992 }
993
994 s->dcadsp.decode_hf(subband_samples, s->dca_chan[k].high_freq_vq,
995 ff_dca_high_freq_vq,
996 subsubframe * SAMPLES_PER_SUBBAND,
997 s->dca_chan[k].scale_factor,
998 s->audio_header.vq_start_subband[k],
999 s->audio_header.subband_activity[k]);
1000 }
1001 }
1002
1003 /* Check for DSYNC after subsubframe */
1004 if (s->aspf || subsubframe == s->subsubframes[s->current_subframe] - 1) {
1005 if (get_bits(&s->gb, 16) != 0xFFFF) {
1006 av_log(s->avctx, AV_LOG_ERROR, "Didn't get subframe DSYNC\n");
1007 return AVERROR_INVALIDDATA;
1008 }
1009 }
1010
1011 return 0;
1012}
1013
1014static int dca_filter_channels(DCAContext *s, int block_index, int upsample)
1015{
1016 int k;
1017
1018 if (upsample) {
1019 LOCAL_ALIGNED(32, float, samples, [DCA_SUBBANDS_X96K], [SAMPLES_PER_SUBBAND]);
1020
1021 if (!s->qmf64_table) {
1022 s->qmf64_table = qmf64_precompute();
1023 if (!s->qmf64_table)
1024 return AVERROR(ENOMEM);
1025 }
1026
1027 /* 64 subbands QMF */
1028 for (k = 0; k < s->audio_header.prim_channels; k++) {
1029 int32_t (*subband_samples)[SAMPLES_PER_SUBBAND] =
1030 s->dca_chan[k].subband_samples[block_index];
1031
1032 s->fmt_conv.int32_to_float(samples[0], subband_samples[0],
1033 DCA_SUBBANDS_X96K * SAMPLES_PER_SUBBAND);
1034
1035 if (s->channel_order_tab[k] >= 0)
1036 qmf_64_subbands(s, k, samples,
1037 s->samples_chanptr[s->channel_order_tab[k]],
1038 /* Upsampling needs a factor 2 here. */
1039 M_SQRT2 / 32768.0);
1040 }
1041 } else {
1042 /* 32 subbands QMF */
1043 LOCAL_ALIGNED(32, float, samples, [DCA_SUBBANDS], [SAMPLES_PER_SUBBAND]);
1044
1045 for (k = 0; k < s->audio_header.prim_channels; k++) {
1046 int32_t (*subband_samples)[SAMPLES_PER_SUBBAND] =
1047 s->dca_chan[k].subband_samples[block_index];
1048
1049 s->fmt_conv.int32_to_float(samples[0], subband_samples[0],
1050 DCA_SUBBANDS * SAMPLES_PER_SUBBAND);
1051
1052 if (s->channel_order_tab[k] >= 0)
1053 qmf_32_subbands(s, k, samples,
1054 s->samples_chanptr[s->channel_order_tab[k]],
1055 M_SQRT1_2 / 32768.0);
1056 }
1057 }
1058
1059 /* Generate LFE samples for this subsubframe FIXME!!! */
1060 if (s->lfe) {
1061 float *samples = s->samples_chanptr[s->lfe_index];
1062 lfe_interpolation_fir(s,
1063 s->lfe_data + 2 * s->lfe * (block_index + 4),
1064 samples);
1065 if (upsample) {
1066 unsigned i;
1067 /* Should apply the filter in Table 6-11 when upsampling. For
1068 * now, just duplicate. */
1069 for (i = 255; i > 0; i--) {
1070 samples[2 * i] =
1071 samples[2 * i + 1] = samples[i];
1072 }
1073 samples[1] = samples[0];
1074 }
1075 }
1076
1077 /* FIXME: This downmixing is probably broken with upsample.
1078 * Probably totally broken also with XLL in general. */
1079 /* Downmixing to Stereo */
1080 if (s->audio_header.prim_channels + !!s->lfe > 2 &&
1081 s->avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
1082 dca_downmix(s->samples_chanptr, s->amode, !!s->lfe, s->downmix_coef,
1083 s->channel_order_tab);
1084 }
1085
1086 return 0;
1087}
1088
1089static int dca_subframe_footer(DCAContext *s, int base_channel)
1090{
1091 int in, out, aux_data_count, aux_data_end, reserved;
1092 uint32_t nsyncaux;
1093
1094 /*
1095 * Unpack optional information
1096 */
1097
1098 /* presumably optional information only appears in the core? */
1099 if (!base_channel) {
1100 if (s->timestamp)
1101 skip_bits_long(&s->gb, 32);
1102
1103 if (s->aux_data) {
1104 aux_data_count = get_bits(&s->gb, 6);
1105
1106 // align (32-bit)
1107 skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);
1108
1109 aux_data_end = 8 * aux_data_count + get_bits_count(&s->gb);
1110
1111 if ((nsyncaux = get_bits_long(&s->gb, 32)) != DCA_NSYNCAUX) {
1112 av_log(s->avctx, AV_LOG_ERROR, "nSYNCAUX mismatch %#"PRIx32"\n",
1113 nsyncaux);
1114 return AVERROR_INVALIDDATA;
1115 }
1116
1117 if (get_bits1(&s->gb)) { // bAUXTimeStampFlag
1118 avpriv_request_sample(s->avctx,
1119 "Auxiliary Decode Time Stamp Flag");
1120 // align (4-bit)
1121 skip_bits(&s->gb, (-get_bits_count(&s->gb)) & 4);
1122 // 44 bits: nMSByte (8), nMarker (4), nLSByte (28), nMarker (4)
1123 skip_bits_long(&s->gb, 44);
1124 }
1125
1126 if ((s->core_downmix = get_bits1(&s->gb))) {
1127 int am = get_bits(&s->gb, 3);
1128 switch (am) {
1129 case 0:
1130 s->core_downmix_amode = DCA_MONO;
1131 break;
1132 case 1:
1133 s->core_downmix_amode = DCA_STEREO;
1134 break;
1135 case 2:
1136 s->core_downmix_amode = DCA_STEREO_TOTAL;
1137 break;
1138 case 3:
1139 s->core_downmix_amode = DCA_3F;
1140 break;
1141 case 4:
1142 s->core_downmix_amode = DCA_2F1R;
1143 break;
1144 case 5:
1145 s->core_downmix_amode = DCA_2F2R;
1146 break;
1147 case 6:
1148 s->core_downmix_amode = DCA_3F1R;
1149 break;
1150 default:
1151 av_log(s->avctx, AV_LOG_ERROR,
1152 "Invalid mode %d for embedded downmix coefficients\n",
1153 am);
1154 return AVERROR_INVALIDDATA;
1155 }
1156 for (out = 0; out < ff_dca_channels[s->core_downmix_amode]; out++) {
1157 for (in = 0; in < s->audio_header.prim_channels + !!s->lfe; in++) {
1158 uint16_t tmp = get_bits(&s->gb, 9);
1159 if ((tmp & 0xFF) > 241) {
1160 av_log(s->avctx, AV_LOG_ERROR,
1161 "Invalid downmix coefficient code %"PRIu16"\n",
1162 tmp);
1163 return AVERROR_INVALIDDATA;
1164 }
1165 s->core_downmix_codes[in][out] = tmp;
1166 }
1167 }
1168 }
1169
1170 align_get_bits(&s->gb); // byte align
1171 skip_bits(&s->gb, 16); // nAUXCRC16
1172
1173 /*
1174 * additional data (reserved, cf. ETSI TS 102 114 V1.4.1)
1175 *
1176 * Note: don't check for overreads, aux_data_count can't be trusted.
1177 */
1178 if ((reserved = (aux_data_end - get_bits_count(&s->gb))) > 0) {
1179 avpriv_request_sample(s->avctx,
1180 "Core auxiliary data reserved content");
1181 skip_bits_long(&s->gb, reserved);
1182 }
1183 }
1184
1185 if (s->crc_present && s->dynrange)
1186 get_bits(&s->gb, 16);
1187 }
1188
1189 return 0;
1190}
1191
1192/**
1193 * Decode a dca frame block
1194 *
1195 * @param s pointer to the DCAContext
1196 */
1197
1198static int dca_decode_block(DCAContext *s, int base_channel, int block_index)
1199{
1200 int ret;
1201
1202 /* Sanity check */
1203 if (s->current_subframe >= s->audio_header.subframes) {
1204 av_log(s->avctx, AV_LOG_DEBUG, "check failed: %i>%i",
1205 s->current_subframe, s->audio_header.subframes);
1206 return AVERROR_INVALIDDATA;
1207 }
1208
1209 if (!s->current_subsubframe) {
1210 /* Read subframe header */
1211 if ((ret = dca_subframe_header(s, base_channel, block_index)))
1212 return ret;
1213 }
1214
1215 /* Read subsubframe */
1216 if ((ret = dca_subsubframe(s, base_channel, block_index)))
1217 return ret;
1218
1219 /* Update state */
1220 s->current_subsubframe++;
1221 if (s->current_subsubframe >= s->subsubframes[s->current_subframe]) {
1222 s->current_subsubframe = 0;
1223 s->current_subframe++;
1224 }
1225 if (s->current_subframe >= s->audio_header.subframes) {
1226 /* Read subframe footer */
1227 if ((ret = dca_subframe_footer(s, base_channel)))
1228 return ret;
1229 }
1230
1231 return 0;
1232}
1233
1234int ff_dca_xbr_parse_frame(DCAContext *s)
1235{
1236 int scale_table_high[DCA_CHSET_CHANS_MAX][DCA_SUBBANDS][2];
1237 int active_bands[DCA_CHSETS_MAX][DCA_CHSET_CHANS_MAX];
1238 int abits_high[DCA_CHSET_CHANS_MAX][DCA_SUBBANDS];
1239 int anctemp[DCA_CHSET_CHANS_MAX];
1240 int chset_fsize[DCA_CHSETS_MAX];
1241 int n_xbr_ch[DCA_CHSETS_MAX];
1242 int hdr_size, num_chsets, xbr_tmode, hdr_pos;
1243 int i, j, k, l, chset, chan_base;
1244
1245 av_log(s->avctx, AV_LOG_DEBUG, "DTS-XBR: decoding XBR extension\n");
1246
1247 /* get bit position of sync header */
1248 hdr_pos = get_bits_count(&s->gb) - 32;
1249
1250 hdr_size = get_bits(&s->gb, 6) + 1;
1251 num_chsets = get_bits(&s->gb, 2) + 1;
1252
1253 for(i = 0; i < num_chsets; i++)
1254 chset_fsize[i] = get_bits(&s->gb, 14) + 1;
1255
1256 xbr_tmode = get_bits1(&s->gb);
1257
1258 for(i = 0; i < num_chsets; i++) {
1259 n_xbr_ch[i] = get_bits(&s->gb, 3) + 1;
1260 k = get_bits(&s->gb, 2) + 5;
1261 for(j = 0; j < n_xbr_ch[i]; j++) {
1262 active_bands[i][j] = get_bits(&s->gb, k) + 1;
1263 if (active_bands[i][j] > DCA_SUBBANDS) {
1264 av_log(s->avctx, AV_LOG_ERROR, "too many active subbands (%d)\n", active_bands[i][j]);
1265 return AVERROR_INVALIDDATA;
1266 }
1267 }
1268 }
1269
1270 /* skip to the end of the header */
1271 i = get_bits_count(&s->gb);
1272 if(hdr_pos + hdr_size * 8 > i)
1273 skip_bits_long(&s->gb, hdr_pos + hdr_size * 8 - i);
1274
1275 /* loop over the channel data sets */
1276 /* only decode as many channels as we've decoded base data for */
1277 for(chset = 0, chan_base = 0;
1278 chset < num_chsets && chan_base + n_xbr_ch[chset] <= s->audio_header.prim_channels;
1279 chan_base += n_xbr_ch[chset++]) {
1280 int start_posn = get_bits_count(&s->gb);
1281 int subsubframe = 0;
1282 int subframe = 0;
1283
1284 /* loop over subframes */
1285 for (k = 0; k < (s->sample_blocks / 8); k++) {
1286 /* parse header if we're on first subsubframe of a block */
1287 if(subsubframe == 0) {
1288 /* Parse subframe header */
1289 for(i = 0; i < n_xbr_ch[chset]; i++) {
1290 anctemp[i] = get_bits(&s->gb, 2) + 2;
1291 }
1292
1293 for(i = 0; i < n_xbr_ch[chset]; i++) {
1294 get_array(&s->gb, abits_high[i], active_bands[chset][i], anctemp[i]);
1295 }
1296
1297 for(i = 0; i < n_xbr_ch[chset]; i++) {
1298 anctemp[i] = get_bits(&s->gb, 3);
1299 if(anctemp[i] < 1) {
1300 av_log(s->avctx, AV_LOG_ERROR, "DTS-XBR: SYNC ERROR\n");
1301 return AVERROR_INVALIDDATA;
1302 }
1303 }
1304
1305 /* generate scale factors */
1306 for(i = 0; i < n_xbr_ch[chset]; i++) {
1307 const uint32_t *scale_table;
1308 int nbits;
1309 int scale_table_size;
1310
1311 if (s->audio_header.scalefactor_huffman[chan_base+i] == 6) {
1312 scale_table = ff_dca_scale_factor_quant7;
1313 scale_table_size = FF_ARRAY_ELEMS(ff_dca_scale_factor_quant7);
1314 } else {
1315 scale_table = ff_dca_scale_factor_quant6;
1316 scale_table_size = FF_ARRAY_ELEMS(ff_dca_scale_factor_quant6);
1317 }
1318
1319 nbits = anctemp[i];
1320
1321 for(j = 0; j < active_bands[chset][i]; j++) {
1322 if(abits_high[i][j] > 0) {
1323 int index = get_bits(&s->gb, nbits);
1324 if (index >= scale_table_size) {
1325 av_log(s->avctx, AV_LOG_ERROR, "scale table index %d invalid\n", index);
1326 return AVERROR_INVALIDDATA;
1327 }
1328 scale_table_high[i][j][0] = scale_table[index];
1329
1330 if(xbr_tmode && s->dca_chan[i].transition_mode[j]) {
1331 int index = get_bits(&s->gb, nbits);
1332 if (index >= scale_table_size) {
1333 av_log(s->avctx, AV_LOG_ERROR, "scale table index %d invalid\n", index);
1334 return AVERROR_INVALIDDATA;
1335 }
1336 scale_table_high[i][j][1] = scale_table[index];
1337 }
1338 }
1339 }
1340 }
1341 }
1342
1343 /* decode audio array for this block */
1344 for(i = 0; i < n_xbr_ch[chset]; i++) {
1345 for(j = 0; j < active_bands[chset][i]; j++) {
1346 const int xbr_abits = abits_high[i][j];
1347 const uint32_t quant_step_size = ff_dca_lossless_quant[xbr_abits];
1348 const int sfi = xbr_tmode && s->dca_chan[i].transition_mode[j] && subsubframe >= s->dca_chan[i].transition_mode[j];
1349 const uint32_t rscale = scale_table_high[i][j][sfi];
1350 int32_t *subband_samples = s->dca_chan[chan_base+i].subband_samples[k][j];
1351 int32_t block[SAMPLES_PER_SUBBAND];
1352
1353 if(xbr_abits <= 0)
1354 continue;
1355
1356 if(xbr_abits > 7) {
1357 get_array(&s->gb, block, SAMPLES_PER_SUBBAND, xbr_abits - 3);
1358 } else {
1359 int block_code1, block_code2, size, levels, err;
1360
1361 size = abits_sizes[xbr_abits - 1];
1362 levels = abits_levels[xbr_abits - 1];
1363
1364 block_code1 = get_bits(&s->gb, size);
1365 block_code2 = get_bits(&s->gb, size);
1366 err = decode_blockcodes(block_code1, block_code2,
1367 levels, block);
1368 if (err) {
1369 av_log(s->avctx, AV_LOG_ERROR,
1370 "ERROR: DTS-XBR: block code look-up failed\n");
1371 return AVERROR_INVALIDDATA;
1372 }
1373 }
1374
1375 /* scale & sum into subband */
1376 s->dcadsp.dequantize(block, quant_step_size, rscale);
1377 for(l = 0; l < SAMPLES_PER_SUBBAND; l++)
1378 subband_samples[l] += block[l];
1379 }
1380 }
1381
1382 /* check DSYNC marker */
1383 if(s->aspf || subsubframe == s->subsubframes[subframe] - 1) {
1384 if(get_bits(&s->gb, 16) != 0xffff) {
1385 av_log(s->avctx, AV_LOG_ERROR, "DTS-XBR: Didn't get subframe DSYNC\n");
1386 return AVERROR_INVALIDDATA;
1387 }
1388 }
1389
1390 /* advance sub-sub-frame index */
1391 if(++subsubframe >= s->subsubframes[subframe]) {
1392 subsubframe = 0;
1393 subframe++;
1394 }
1395 }
1396
1397 /* skip to next channel set */
1398 i = get_bits_count(&s->gb);
1399 if(start_posn + chset_fsize[chset] * 8 != i) {
1400 j = start_posn + chset_fsize[chset] * 8 - i;
1401 if(j < 0 || j >= 8)
1402 av_log(s->avctx, AV_LOG_ERROR, "DTS-XBR: end of channel set,"
1403 " skipping further than expected (%d bits)\n", j);
1404 skip_bits_long(&s->gb, j);
1405 }
1406 }
1407
1408 return 0;
1409}
1410
1411
1412/* parse initial header for XXCH and dump details */
1413int ff_dca_xxch_decode_frame(DCAContext *s)
1414{
1415 int hdr_size, spkmsk_bits, num_chsets, core_spk, hdr_pos;
1416 int i, chset, base_channel, chstart, fsize[8];
1417
1418 /* assume header word has already been parsed */
1419 hdr_pos = get_bits_count(&s->gb) - 32;
1420 hdr_size = get_bits(&s->gb, 6) + 1;
1421 /*chhdr_crc =*/ skip_bits1(&s->gb);
1422 spkmsk_bits = get_bits(&s->gb, 5) + 1;
1423 num_chsets = get_bits(&s->gb, 2) + 1;
1424
1425 for (i = 0; i < num_chsets; i++)
1426 fsize[i] = get_bits(&s->gb, 14) + 1;
1427
1428 core_spk = get_bits(&s->gb, spkmsk_bits);
1429 s->xxch_core_spkmask = core_spk;
1430 s->xxch_nbits_spk_mask = spkmsk_bits;
1431 s->xxch_dmix_embedded = 0;
1432
1433 /* skip to the end of the header */
1434 i = get_bits_count(&s->gb);
1435 if (hdr_pos + hdr_size * 8 > i)
1436 skip_bits_long(&s->gb, hdr_pos + hdr_size * 8 - i);
1437
1438 for (chset = 0; chset < num_chsets; chset++) {
1439 chstart = get_bits_count(&s->gb);
1440 base_channel = s->audio_header.prim_channels;
1441 s->xxch_chset = chset;
1442
1443 /* XXCH and Core headers differ, see 6.4.2 "XXCH Channel Set Header" vs.
1444 5.3.2 "Primary Audio Coding Header", DTS Spec 1.3.1 */
1445 dca_parse_audio_coding_header(s, base_channel, 1);
1446
1447 /* decode channel data */
1448 for (i = 0; i < (s->sample_blocks / 8); i++) {
1449 if (dca_decode_block(s, base_channel, i)) {
1450 av_log(s->avctx, AV_LOG_ERROR,
1451 "Error decoding DTS-XXCH extension\n");
1452 continue;
1453 }
1454 }
1455
1456 /* skip to end of this section */
1457 i = get_bits_count(&s->gb);
1458 if (chstart + fsize[chset] * 8 > i)
1459 skip_bits_long(&s->gb, chstart + fsize[chset] * 8 - i);
1460 }
1461 s->xxch_chset = num_chsets;
1462
1463 return 0;
1464}
1465
1466static float dca_dmix_code(unsigned code)
1467{
1468 int sign = (code >> 8) - 1;
1469 code &= 0xff;
1470 return ((ff_dca_dmixtable[code] ^ sign) - sign) * (1.0 / (1 << 15));
1471}
1472
1473static int scan_for_extensions(AVCodecContext *avctx)
1474{
1475 DCAContext *s = avctx->priv_data;
1476 int core_ss_end, ret = 0;
1477
1478 core_ss_end = FFMIN(s->frame_size, s->dca_buffer_size) * 8;
1479
1480 /* only scan for extensions if ext_descr was unknown or indicated a
1481 * supported XCh extension */
1482 if (s->core_ext_mask < 0 || s->core_ext_mask & (DCA_EXT_XCH | DCA_EXT_XXCH)) {
1483 /* if ext_descr was unknown, clear s->core_ext_mask so that the
1484 * extensions scan can fill it up */
1485 s->core_ext_mask = FFMAX(s->core_ext_mask, 0);
1486
1487 /* extensions start at 32-bit boundaries into bitstream */
1488 skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);
1489
1490 while (core_ss_end - get_bits_count(&s->gb) >= 32) {
1491 uint32_t bits = get_bits_long(&s->gb, 32);
1492 int i;
1493
1494 switch (bits) {
1495 case DCA_SYNCWORD_XCH: {
1496 int ext_amode, xch_fsize;
1497
1498 s->xch_base_channel = s->audio_header.prim_channels;
1499
1500 /* validate sync word using XCHFSIZE field */
1501 xch_fsize = show_bits(&s->gb, 10);
1502 if ((s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize) &&
1503 (s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize + 1))
1504 continue;
1505
1506 /* skip length-to-end-of-frame field for the moment */
1507 skip_bits(&s->gb, 10);
1508
1509 s->core_ext_mask |= DCA_EXT_XCH;
1510
1511 /* extension amode(number of channels in extension) should be 1 */
1512 /* AFAIK XCh is not used for more channels */
1513 if ((ext_amode = get_bits(&s->gb, 4)) != 1) {
1514 av_log(avctx, AV_LOG_ERROR,
1515 "XCh extension amode %d not supported!\n",
1516 ext_amode);
1517 continue;
1518 }
1519
1520 if (s->xch_base_channel < 2) {
1521 avpriv_request_sample(avctx, "XCh with fewer than 2 base channels");
1522 continue;
1523 }
1524
1525 /* much like core primary audio coding header */
1526 dca_parse_audio_coding_header(s, s->xch_base_channel, 0);
1527
1528 for (i = 0; i < (s->sample_blocks / 8); i++)
1529 if ((ret = dca_decode_block(s, s->xch_base_channel, i))) {
1530 av_log(avctx, AV_LOG_ERROR, "error decoding XCh extension\n");
1531 continue;
1532 }
1533
1534 s->xch_present = 1;
1535 break;
1536 }
1537 case DCA_SYNCWORD_XXCH:
1538 /* XXCh: extended channels */
1539 /* usually found either in core or HD part in DTS-HD HRA streams,
1540 * but not in DTS-ES which contains XCh extensions instead */
1541 s->core_ext_mask |= DCA_EXT_XXCH;
1542 ff_dca_xxch_decode_frame(s);
1543 break;
1544
1545 case 0x1d95f262: {
1546 int fsize96 = show_bits(&s->gb, 12) + 1;
1547 if (s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + fsize96)
1548 continue;
1549
1550 av_log(avctx, AV_LOG_DEBUG, "X96 extension found at %d bits\n",
1551 get_bits_count(&s->gb));
1552 skip_bits(&s->gb, 12);
1553 av_log(avctx, AV_LOG_DEBUG, "FSIZE96 = %d bytes\n", fsize96);
1554 av_log(avctx, AV_LOG_DEBUG, "REVNO = %d\n", get_bits(&s->gb, 4));
1555
1556 s->core_ext_mask |= DCA_EXT_X96;
1557 break;
1558 }
1559 }
1560
1561 skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);
1562 }
1563 } else {
1564 /* no supported extensions, skip the rest of the core substream */
1565 skip_bits_long(&s->gb, core_ss_end - get_bits_count(&s->gb));
1566 }
1567
1568 if (s->core_ext_mask & DCA_EXT_X96)
1569 s->profile = FF_PROFILE_DTS_96_24;
1570 else if (s->core_ext_mask & (DCA_EXT_XCH | DCA_EXT_XXCH))
1571 s->profile = FF_PROFILE_DTS_ES;
1572
1573 /* check for ExSS (HD part) */
1574 if (s->dca_buffer_size - s->frame_size > 32 &&
1575 get_bits_long(&s->gb, 32) == DCA_SYNCWORD_SUBSTREAM)
1576 ff_dca_exss_parse_header(s);
1577
1578 return ret;
1579}
1580
1581static int set_channel_layout(AVCodecContext *avctx, int *channels, int num_core_channels)
1582{
1583 DCAContext *s = avctx->priv_data;
1584 int i, j, chset, mask;
1585 int channel_layout, channel_mask;
1586 int posn, lavc;
1587
1588 /* If we have XXCH then the channel layout is managed differently */
1589 /* note that XLL will also have another way to do things */
1590 if (!(s->core_ext_mask & DCA_EXT_XXCH)) {
1591 /* xxx should also do MA extensions */
1592 if (s->amode < 16) {
1593 avctx->channel_layout = ff_dca_core_channel_layout[s->amode];
1594
1595 if (s->audio_header.prim_channels + !!s->lfe > 2 &&
1596 avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
1597 /*
1598 * Neither the core's auxiliary data nor our default tables contain
1599 * downmix coefficients for the additional channel coded in the XCh
1600 * extension, so when we're doing a Stereo downmix, don't decode it.
1601 */
1602 s->xch_disable = 1;
1603 }
1604
1605 if (s->xch_present && !s->xch_disable) {
1606 if (avctx->channel_layout & AV_CH_BACK_CENTER) {
1607 avpriv_request_sample(avctx, "XCh with Back center channel");
1608 return AVERROR_INVALIDDATA;
1609 }
1610 avctx->channel_layout |= AV_CH_BACK_CENTER;
1611 if (s->lfe) {
1612 avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
1613 s->channel_order_tab = ff_dca_channel_reorder_lfe_xch[s->amode];
1614 } else {
1615 s->channel_order_tab = ff_dca_channel_reorder_nolfe_xch[s->amode];
1616 }
1617 if (s->channel_order_tab[s->xch_base_channel] < 0)
1618 return AVERROR_INVALIDDATA;
1619 } else {
1620 *channels = num_core_channels + !!s->lfe;
1621 s->xch_present = 0; /* disable further xch processing */
1622 if (s->lfe) {
1623 avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
1624 s->channel_order_tab = ff_dca_channel_reorder_lfe[s->amode];
1625 } else
1626 s->channel_order_tab = ff_dca_channel_reorder_nolfe[s->amode];
1627 }
1628
1629 if (*channels > !!s->lfe &&
1630 s->channel_order_tab[*channels - 1 - !!s->lfe] < 0)
1631 return AVERROR_INVALIDDATA;
1632
1633 if (av_get_channel_layout_nb_channels(avctx->channel_layout) != *channels) {
1634 av_log(avctx, AV_LOG_ERROR, "Number of channels %d mismatches layout %d\n", *channels, av_get_channel_layout_nb_channels(avctx->channel_layout));
1635 return AVERROR_INVALIDDATA;
1636 }
1637
1638 if (num_core_channels + !!s->lfe > 2 &&
1639 avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
1640 *channels = 2;
1641 s->output = s->audio_header.prim_channels == 2 ? s->amode : DCA_STEREO;
1642 avctx->channel_layout = AV_CH_LAYOUT_STEREO;
1643 }
1644 else if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE) {
1645 static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
1646 s->channel_order_tab = dca_channel_order_native;
1647 }
1648 s->lfe_index = ff_dca_lfe_index[s->amode];
1649 } else {
1650 av_log(avctx, AV_LOG_ERROR,
1651 "Non standard configuration %d !\n", s->amode);
1652 return AVERROR_INVALIDDATA;
1653 }
1654
1655 s->xxch_dmix_embedded = 0;
1656 } else {
1657 /* we only get here if an XXCH channel set can be added to the mix */
1658 channel_mask = s->xxch_core_spkmask;
1659
1660 {
1661 *channels = s->audio_header.prim_channels + !!s->lfe;
1662 for (i = 0; i < s->xxch_chset; i++) {
1663 channel_mask |= s->xxch_spk_masks[i];
1664 }
1665 }
1666
1667 /* Given the DTS spec'ed channel mask, generate an avcodec version */
1668 channel_layout = 0;
1669 for (i = 0; i < s->xxch_nbits_spk_mask; ++i) {
1670 if (channel_mask & (1 << i)) {
1671 channel_layout |= ff_dca_map_xxch_to_native[i];
1672 }
1673 }
1674
1675 /* make sure that we have managed to get equivalent dts/avcodec channel
1676 * masks in some sense -- unfortunately some channels could overlap */
1677 if (av_popcount(channel_mask) != av_popcount(channel_layout)) {
1678 av_log(avctx, AV_LOG_DEBUG,
1679 "DTS-XXCH: Inconsistent avcodec/dts channel layouts\n");
1680 return AVERROR_INVALIDDATA;
1681 }
1682
1683 avctx->channel_layout = channel_layout;
1684
1685 if (!(avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE)) {
1686 /* Estimate DTS --> avcodec ordering table */
1687 for (chset = -1, j = 0; chset < s->xxch_chset; ++chset) {
1688 mask = chset >= 0 ? s->xxch_spk_masks[chset]
1689 : s->xxch_core_spkmask;
1690 for (i = 0; i < s->xxch_nbits_spk_mask; i++) {
1691 if (mask & ~(DCA_XXCH_LFE1 | DCA_XXCH_LFE2) & (1 << i)) {
1692 lavc = ff_dca_map_xxch_to_native[i];
1693 posn = av_popcount(channel_layout & (lavc - 1));
1694 s->xxch_order_tab[j++] = posn;
1695 }
1696 }
1697
1698 }
1699
1700 s->lfe_index = av_popcount(channel_layout & (AV_CH_LOW_FREQUENCY-1));
1701 } else { /* native ordering */
1702 for (i = 0; i < *channels; i++)
1703 s->xxch_order_tab[i] = i;
1704
1705 s->lfe_index = *channels - 1;
1706 }
1707
1708 s->channel_order_tab = s->xxch_order_tab;
1709 }
1710
1711 return 0;
1712}
1713
1714/**
1715 * Main frame decoding function
1716 * FIXME add arguments
1717 */
1718static int dca_decode_frame(AVCodecContext *avctx, void *data,
1719 int *got_frame_ptr, AVPacket *avpkt)
1720{
1721 AVFrame *frame = data;
1722 const uint8_t *buf = avpkt->data;
1723 int buf_size = avpkt->size;
1724 int lfe_samples;
1725 int num_core_channels = 0;
1726 int i, ret;
1727 float **samples_flt;
1728 float *src_chan;
1729 float *dst_chan;
1730 DCAContext *s = avctx->priv_data;
1731 int channels, full_channels;
1732 float scale;
1733 int achan;
1734 int chset;
1735 int mask;
1736 int j, k;
1737 int endch;
1738 int upsample = 0;
1739
1740 s->exss_ext_mask = 0;
1741 s->xch_present = 0;
1742
1743 s->dca_buffer_size = AVERROR_INVALIDDATA;
1744 for (i = 0; i < buf_size - 3 && s->dca_buffer_size == AVERROR_INVALIDDATA; i++)
1745 s->dca_buffer_size = avpriv_dca_convert_bitstream(buf + i, buf_size - i, s->dca_buffer,
1746 DCA_MAX_FRAME_SIZE + DCA_MAX_EXSS_HEADER_SIZE);
1747
1748 if (s->dca_buffer_size == AVERROR_INVALIDDATA) {
1749 av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");
1750 return AVERROR_INVALIDDATA;
1751 }
1752
1753 if ((ret = dca_parse_frame_header(s)) < 0) {
1754 // seems like the frame is corrupt, try with the next one
1755 return ret;
1756 }
1757 // set AVCodec values with parsed data
1758 avctx->sample_rate = s->sample_rate;
1759
1760 s->profile = FF_PROFILE_DTS;
1761
1762 for (i = 0; i < (s->sample_blocks / SAMPLES_PER_SUBBAND); i++) {
1763 if ((ret = dca_decode_block(s, 0, i))) {
1764 av_log(avctx, AV_LOG_ERROR, "error decoding block\n");
1765 return ret;
1766 }
1767 }
1768
1769 /* record number of core channels incase less than max channels are requested */
1770 num_core_channels = s->audio_header.prim_channels;
1771
1772 if (s->audio_header.prim_channels + !!s->lfe > 2 &&
1773 avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
1774 /* Stereo downmix coefficients
1775 *
1776 * The decoder can only downmix to 2-channel, so we need to ensure
1777 * embedded downmix coefficients are actually targeting 2-channel.
1778 */
1779 if (s->core_downmix && (s->core_downmix_amode == DCA_STEREO ||
1780 s->core_downmix_amode == DCA_STEREO_TOTAL)) {
1781 for (i = 0; i < num_core_channels + !!s->lfe; i++) {
1782 /* Range checked earlier */
1783 s->downmix_coef[i][0] = dca_dmix_code(s->core_downmix_codes[i][0]);
1784 s->downmix_coef[i][1] = dca_dmix_code(s->core_downmix_codes[i][1]);
1785 }
1786 s->output = s->core_downmix_amode;
1787 } else {
1788 int am = s->amode & DCA_CHANNEL_MASK;
1789 if (am >= FF_ARRAY_ELEMS(ff_dca_default_coeffs)) {
1790 av_log(s->avctx, AV_LOG_ERROR,
1791 "Invalid channel mode %d\n", am);
1792 return AVERROR_INVALIDDATA;
1793 }
1794 if (num_core_channels + !!s->lfe >
1795 FF_ARRAY_ELEMS(ff_dca_default_coeffs[0])) {
1796 avpriv_request_sample(s->avctx, "Downmixing %d channels",
1797 s->audio_header.prim_channels + !!s->lfe);
1798 return AVERROR_PATCHWELCOME;
1799 }
1800 for (i = 0; i < num_core_channels + !!s->lfe; i++) {
1801 s->downmix_coef[i][0] = ff_dca_default_coeffs[am][i][0];
1802 s->downmix_coef[i][1] = ff_dca_default_coeffs[am][i][1];
1803 }
1804 }
1805 ff_dlog(s->avctx, "Stereo downmix coeffs:\n");
1806 for (i = 0; i < num_core_channels + !!s->lfe; i++) {
1807 ff_dlog(s->avctx, "L, input channel %d = %f\n", i,
1808 s->downmix_coef[i][0]);
1809 ff_dlog(s->avctx, "R, input channel %d = %f\n", i,
1810 s->downmix_coef[i][1]);
1811 }
1812 ff_dlog(s->avctx, "\n");
1813 }
1814
1815 if (s->ext_coding)
1816 s->core_ext_mask = ff_dca_ext_audio_descr_mask[s->ext_descr];
1817 else
1818 s->core_ext_mask = 0;
1819
1820 ret = scan_for_extensions(avctx);
1821
1822 avctx->profile = s->profile;
1823
1824 full_channels = channels = s->audio_header.prim_channels + !!s->lfe;
1825
1826 ret = set_channel_layout(avctx, &channels, num_core_channels);
1827 if (ret < 0)
1828 return ret;
1829
1830 /* get output buffer */
1831 frame->nb_samples = 256 * (s->sample_blocks / SAMPLES_PER_SUBBAND);
1832 if (s->exss_ext_mask & DCA_EXT_EXSS_XLL) {
1833 int xll_nb_samples = s->xll_segments * s->xll_smpl_in_seg;
1834 /* Check for invalid/unsupported conditions first */
1835 if (s->xll_residual_channels > channels) {
1836 av_log(s->avctx, AV_LOG_WARNING,
1837 "DCA: too many residual channels (%d, core channels %d). Disabling XLL\n",
1838 s->xll_residual_channels, channels);
1839 s->exss_ext_mask &= ~DCA_EXT_EXSS_XLL;
1840 } else if (xll_nb_samples != frame->nb_samples &&
1841 2 * frame->nb_samples != xll_nb_samples) {
1842 av_log(s->avctx, AV_LOG_WARNING,
1843 "DCA: unsupported upsampling (%d XLL samples, %d core samples). Disabling XLL\n",
1844 xll_nb_samples, frame->nb_samples);
1845 s->exss_ext_mask &= ~DCA_EXT_EXSS_XLL;
1846 } else {
1847 if (2 * frame->nb_samples == xll_nb_samples) {
1848 av_log(s->avctx, AV_LOG_INFO,
1849 "XLL: upsampling core channels by a factor of 2\n");
1850 upsample = 1;
1851
1852 frame->nb_samples = xll_nb_samples;
1853 // FIXME: Is it good enough to copy from the first channel set?
1854 avctx->sample_rate = s->xll_chsets[0].sampling_frequency;
1855 }
1856 /* If downmixing to stereo, don't decode additional channels.
1857 * FIXME: Using the xch_disable flag for this doesn't seem right. */
1858 if (!s->xch_disable)
1859 channels = s->xll_channels;
1860 }
1861 }
1862
1863 if (avctx->channels != channels) {
1864 if (avctx->channels)
1865 av_log(avctx, AV_LOG_INFO, "Number of channels changed in DCA decoder (%d -> %d)\n", avctx->channels, channels);
1866 avctx->channels = channels;
1867 }
1868
1869 /* FIXME: This is an ugly hack, to just revert to the default
1870 * layout if we have additional channels. Need to convert the XLL
1871 * channel masks to ffmpeg channel_layout mask. */
1872 if (av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels)
1873 avctx->channel_layout = 0;
1874
1875 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
1876 return ret;
1877 samples_flt = (float **) frame->extended_data;
1878
1879 /* allocate buffer for extra channels if downmixing */
1880 if (avctx->channels < full_channels) {
1881 ret = av_samples_get_buffer_size(NULL, full_channels - channels,
1882 frame->nb_samples,
1883 avctx->sample_fmt, 0);
1884 if (ret < 0)
1885 return ret;
1886
1887 av_fast_malloc(&s->extra_channels_buffer,
1888 &s->extra_channels_buffer_size, ret);
1889 if (!s->extra_channels_buffer)
1890 return AVERROR(ENOMEM);
1891
1892 ret = av_samples_fill_arrays((uint8_t **) s->extra_channels, NULL,
1893 s->extra_channels_buffer,
1894 full_channels - channels,
1895 frame->nb_samples, avctx->sample_fmt, 0);
1896 if (ret < 0)
1897 return ret;
1898 }
1899
1900 /* filter to get final output */
1901 for (i = 0; i < (s->sample_blocks / SAMPLES_PER_SUBBAND); i++) {
1902 int ch;
1903 unsigned block = upsample ? 512 : 256;
1904 for (ch = 0; ch < channels; ch++)
1905 s->samples_chanptr[ch] = samples_flt[ch] + i * block;
1906 for (; ch < full_channels; ch++)
1907 s->samples_chanptr[ch] = s->extra_channels[ch - channels] + i * block;
1908
1909 dca_filter_channels(s, i, upsample);
1910
1911 /* If this was marked as a DTS-ES stream we need to subtract back- */
1912 /* channel from SL & SR to remove matrixed back-channel signal */
1913 if ((s->source_pcm_res & 1) && s->xch_present) {
1914 float *back_chan = s->samples_chanptr[s->channel_order_tab[s->xch_base_channel]];
1915 float *lt_chan = s->samples_chanptr[s->channel_order_tab[s->xch_base_channel - 2]];
1916 float *rt_chan = s->samples_chanptr[s->channel_order_tab[s->xch_base_channel - 1]];
1917 s->fdsp->vector_fmac_scalar(lt_chan, back_chan, -M_SQRT1_2, 256);
1918 s->fdsp->vector_fmac_scalar(rt_chan, back_chan, -M_SQRT1_2, 256);
1919 }
1920
1921 /* If stream contains XXCH, we might need to undo an embedded downmix */
1922 if (s->xxch_dmix_embedded) {
1923 /* Loop over channel sets in turn */
1924 ch = num_core_channels;
1925 for (chset = 0; chset < s->xxch_chset; chset++) {
1926 endch = ch + s->xxch_chset_nch[chset];
1927 mask = s->xxch_dmix_embedded;
1928
1929 /* undo downmix */
1930 for (j = ch; j < endch; j++) {
1931 if (mask & (1 << j)) { /* this channel has been mixed-out */
1932 src_chan = s->samples_chanptr[s->channel_order_tab[j]];
1933 for (k = 0; k < endch; k++) {
1934 achan = s->channel_order_tab[k];
1935 scale = s->xxch_dmix_coeff[j][k];
1936 if (scale != 0.0) {
1937 dst_chan = s->samples_chanptr[achan];
1938 s->fdsp->vector_fmac_scalar(dst_chan, src_chan,
1939 -scale, 256);
1940 }
1941 }
1942 }
1943 }
1944
1945 /* if a downmix has been embedded then undo the pre-scaling */
1946 if ((mask & (1 << ch)) && s->xxch_dmix_sf[chset] != 1.0f) {
1947 scale = s->xxch_dmix_sf[chset];
1948
1949 for (j = 0; j < ch; j++) {
1950 src_chan = s->samples_chanptr[s->channel_order_tab[j]];
1951 for (k = 0; k < 256; k++)
1952 src_chan[k] *= scale;
1953 }
1954
1955 /* LFE channel is always part of core, scale if it exists */
1956 if (s->lfe) {
1957 src_chan = s->samples_chanptr[s->lfe_index];
1958 for (k = 0; k < 256; k++)
1959 src_chan[k] *= scale;
1960 }
1961 }
1962
1963 ch = endch;
1964 }
1965
1966 }
1967 }
1968
1969 /* update lfe history */
1970 lfe_samples = 2 * s->lfe * (s->sample_blocks / SAMPLES_PER_SUBBAND);
1971 for (i = 0; i < 2 * s->lfe * 4; i++)
1972 s->lfe_data[i] = s->lfe_data[i + lfe_samples];
1973
1974 if (s->exss_ext_mask & DCA_EXT_EXSS_XLL) {
1975 ret = ff_dca_xll_decode_audio(s, frame);
1976 if (ret < 0)
1977 return ret;
1978 }
1979 /* AVMatrixEncoding
1980 *
1981 * DCA_STEREO_TOTAL (Lt/Rt) is equivalent to Dolby Surround */
1982 ret = ff_side_data_update_matrix_encoding(frame,
1983 (s->output & ~DCA_LFE) == DCA_STEREO_TOTAL ?
1984 AV_MATRIX_ENCODING_DOLBY : AV_MATRIX_ENCODING_NONE);
1985 if (ret < 0)
1986 return ret;
1987
1988 if ( avctx->profile != FF_PROFILE_DTS_HD_MA
1989 && avctx->profile != FF_PROFILE_DTS_HD_HRA)
1990 avctx->bit_rate = s->bit_rate;
1991 *got_frame_ptr = 1;
1992
1993 return buf_size;
1994}
1995
1996/**
1997 * DCA initialization
1998 *
1999 * @param avctx pointer to the AVCodecContext
2000 */
2001
2002static av_cold int dca_decode_init(AVCodecContext *avctx)
2003{
2004 DCAContext *s = avctx->priv_data;
2005
2006 s->avctx = avctx;
2007 dca_init_vlcs();
2008
2009 s->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
2010 if (!s->fdsp)
2011 return AVERROR(ENOMEM);
2012
2013 ff_mdct_init(&s->imdct, 6, 1, 1.0);
2014 ff_synth_filter_init(&s->synth);
2015 ff_dcadsp_init(&s->dcadsp);
2016 ff_fmt_convert_init(&s->fmt_conv, avctx);
2017
2018 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
2019
2020 /* allow downmixing to stereo */
2021 if (avctx->channels > 2 &&
2022 avctx->request_channel_layout == AV_CH_LAYOUT_STEREO)
2023 avctx->channels = 2;
2024
2025 return 0;
2026}
2027
2028static av_cold int dca_decode_end(AVCodecContext *avctx)
2029{
2030 DCAContext *s = avctx->priv_data;
2031 ff_mdct_end(&s->imdct);
2032 av_freep(&s->extra_channels_buffer);
2033 av_freep(&s->fdsp);
2034 av_freep(&s->xll_sample_buf);
2035 av_freep(&s->qmf64_table);
2036 return 0;
2037}
2038
2039static const AVOption options[] = {
2040 { "disable_xch", "disable decoding of the XCh extension", offsetof(DCAContext, xch_disable), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM },
2041 { "disable_xll", "disable decoding of the XLL extension", offsetof(DCAContext, xll_disable), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM },
2042 { NULL },
2043};
2044
2045static const AVClass dca_decoder_class = {
2046 .class_name = "DCA decoder",
2047 .item_name = av_default_item_name,
2048 .option = options,
2049 .version = LIBAVUTIL_VERSION_INT,
2050 .category = AV_CLASS_CATEGORY_DECODER,
2051};
2052
2053AVCodec ff_dca_decoder = {
2054 .name = "dca",
2055 .long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"),
2056 .type = AVMEDIA_TYPE_AUDIO,
2057 .id = AV_CODEC_ID_DTS,
2058 .priv_data_size = sizeof(DCAContext),
2059 .init = dca_decode_init,
2060 .decode = dca_decode_frame,
2061 .close = dca_decode_end,
2062 .capabilities = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1,
2063 .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
2064 AV_SAMPLE_FMT_NONE },
2065 .profiles = NULL_IF_CONFIG_SMALL(ff_dca_profiles),
2066 .priv_class = &dca_decoder_class,
2067};
libavcodec/dcadsp.c+0−134
@@ -1,134 +0,0 @@
1/*
2 * Copyright (c) 2004 Gildas Bazin
3 * Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "config.h"
23
24#include "libavutil/attributes.h"
25#include "libavutil/intreadwrite.h"
26
27#include "dcadsp.h"
28#include "dcamath.h"
29
30static void decode_hf_c(int32_t dst[DCA_SUBBANDS][SAMPLES_PER_SUBBAND],
31 const int32_t vq_num[DCA_SUBBANDS],
32 const int8_t hf_vq[1024][32], intptr_t vq_offset,
33 int32_t scale[DCA_SUBBANDS][2],
34 intptr_t start, intptr_t end)
35{
36 int i, j;
37
38 for (j = start; j < end; j++) {
39 const int8_t *ptr = &hf_vq[vq_num[j]][vq_offset];
40 for (i = 0; i < 8; i++)
41 dst[j][i] = ptr[i] * scale[j][0] + 8 >> 4;
42 }
43}
44
45static inline void dca_lfe_fir(float *out, const float *in, const float *coefs,
46 int decifactor)
47{
48 float *out2 = out + 2 * decifactor - 1;
49 int num_coeffs = 256 / decifactor;
50 int j, k;
51
52 /* One decimated sample generates 2*decifactor interpolated ones */
53 for (k = 0; k < decifactor; k++) {
54 float v0 = 0.0;
55 float v1 = 0.0;
56 for (j = 0; j < num_coeffs; j++, coefs++) {
57 v0 += in[-j] * *coefs;
58 v1 += in[j + 1 - num_coeffs] * *coefs;
59 }
60 *out++ = v0;
61 *out2-- = v1;
62 }
63}
64
65static void dca_qmf_32_subbands(float samples_in[DCA_SUBBANDS][SAMPLES_PER_SUBBAND], int sb_act,
66 SynthFilterContext *synth, FFTContext *imdct,
67 float synth_buf_ptr[512],
68 int *synth_buf_offset, float synth_buf2[32],
69 const float window[512], float *samples_out,
70 float raXin[32], float scale)
71{
72 int i;
73 int subindex;
74
75 for (i = sb_act; i < 32; i++)
76 raXin[i] = 0.0;
77
78 /* Reconstructed channel sample index */
79 for (subindex = 0; subindex < 8; subindex++) {
80 /* Load in one sample from each subband and clear inactive subbands */
81 for (i = 0; i < sb_act; i++) {
82 unsigned sign = (i - 1) & 2;
83 uint32_t v = AV_RN32A(&samples_in[i][subindex]) ^ sign << 30;
84 AV_WN32A(&raXin[i], v);
85 }
86
87 synth->synth_filter_float(imdct, synth_buf_ptr, synth_buf_offset,
88 synth_buf2, window, samples_out, raXin,
89 scale);
90 samples_out += 32;
91 }
92}
93
94static void dequantize_c(int32_t *samples, uint32_t step_size, uint32_t scale)
95{
96 int64_t step = (int64_t)step_size * scale;
97 int shift, i;
98 int32_t step_scale;
99
100 if (step > (1 << 23))
101 shift = av_log2(step >> 23) + 1;
102 else
103 shift = 0;
104 step_scale = (int32_t)(step >> shift);
105
106 for (i = 0; i < SAMPLES_PER_SUBBAND; i++)
107 samples[i] = dca_clip23(dca_norm((int64_t)samples[i] * step_scale, 22 - shift));
108}
109
110static void dca_lfe_fir0_c(float *out, const float *in, const float *coefs)
111{
112 dca_lfe_fir(out, in, coefs, 32);
113}
114
115static void dca_lfe_fir1_c(float *out, const float *in, const float *coefs)
116{
117 dca_lfe_fir(out, in, coefs, 64);
118}
119
120av_cold void ff_dcadsp_init(DCADSPContext *s)
121{
122 s->lfe_fir[0] = dca_lfe_fir0_c;
123 s->lfe_fir[1] = dca_lfe_fir1_c;
124 s->qmf_32_subbands = dca_qmf_32_subbands;
125 s->decode_hf = decode_hf_c;
126 s->dequantize = dequantize_c;
127
128 if (ARCH_AARCH64)
129 ff_dcadsp_init_aarch64(s);
130 if (ARCH_ARM)
131 ff_dcadsp_init_arm(s);
132 if (ARCH_X86)
133 ff_dcadsp_init_x86(s);
134}
libavcodec/dcadsp.h+0−51
@@ -1,51 +0,0 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVCODEC_DCADSP_H
20#define AVCODEC_DCADSP_H
21
22#include "avfft.h"
23#include "synth_filter.h"
24
25#define DCA_SUBBANDS_X96K 64
26#define DCA_SUBBANDS 64
27#define SAMPLES_PER_SUBBAND 8 // number of samples per subband per subsubframe
28
29
30typedef struct DCADSPContext {
31 void (*lfe_fir[2])(float *out, const float *in, const float *coefs);
32 void (*qmf_32_subbands)(float samples_in[DCA_SUBBANDS][SAMPLES_PER_SUBBAND], int sb_act,
33 SynthFilterContext *synth, FFTContext *imdct,
34 float synth_buf_ptr[512],
35 int *synth_buf_offset, float synth_buf2[32],
36 const float window[512], float *samples_out,
37 float raXin[32], float scale);
38 void (*decode_hf)(int32_t dst[DCA_SUBBANDS][SAMPLES_PER_SUBBAND],
39 const int32_t vq_num[DCA_SUBBANDS],
40 const int8_t hf_vq[1024][32], intptr_t vq_offset,
41 int32_t scale[DCA_SUBBANDS][2],
42 intptr_t start, intptr_t end);
43 void (*dequantize)(int32_t *samples, uint32_t step_size, uint32_t scale);
44} DCADSPContext;
45
46void ff_dcadsp_init(DCADSPContext *s);
47void ff_dcadsp_init_aarch64(DCADSPContext *s);
48void ff_dcadsp_init_arm(DCADSPContext *s);
49void ff_dcadsp_init_x86(DCADSPContext *s);
50
51#endif /* AVCODEC_DCADSP_H */
libavcodec/dcamath.h+0−47
@@ -1,47 +0,0 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVCODEC_DCAMATH_H
20#define AVCODEC_DCAMATH_H
21
22#include "libavutil/common.h"
23
24
25// clip a signed integer into the (-2^23), (2^23-1) range
26static inline int dca_clip23(int a)
27{
28 return av_clip_intp2(a, 23);
29}
30
31static inline int32_t dca_norm(int64_t a, int bits)
32{
33 if (bits > 0)
34 return (int32_t)((a + (INT64_C(1) << (bits - 1))) >> bits);
35 else
36 return (int32_t)a;
37}
38
39static inline int64_t dca_round(int64_t a, int bits)
40{
41 if (bits > 0)
42 return (a + (INT64_C(1) << (bits - 1))) & ~((INT64_C(1) << bits) - 1);
43 else
44 return a;
45}
46
47#endif /* AVCODEC_DCAMATH_H */
libavcodec/x86/Makefile+2−4
@@ -44,8 +44,7 @@ OBJS-$(CONFIG_ADPCM_G722_ENCODER) += x86/g722dsp_init.o · 43 unmodified lines
44OBJS-$(CONFIG_ALAC_DECODER) += x86/alacdsp_init.o44OBJS-$(CONFIG_ALAC_DECODER) += x86/alacdsp_init.o
45OBJS-$(CONFIG_APNG_DECODER) += x86/pngdsp_init.o45OBJS-$(CONFIG_APNG_DECODER) += x86/pngdsp_init.o
46OBJS-$(CONFIG_CAVS_DECODER) += x86/cavsdsp.o46OBJS-$(CONFIG_CAVS_DECODER) += x86/cavsdsp.o
47OBJS-$(CONFIG_DCA_DECODER) += x86/dcadsp_init.o \47#OBJS-$(CONFIG_DCA_DECODER) += x86/synth_filter_init.o
48 x86/synth_filter_init.o
49OBJS-$(CONFIG_DNXHD_ENCODER) += x86/dnxhdenc_init.o48OBJS-$(CONFIG_DNXHD_ENCODER) += x86/dnxhdenc_init.o
50OBJS-$(CONFIG_HEVC_DECODER) += x86/hevcdsp_init.o49OBJS-$(CONFIG_HEVC_DECODER) += x86/hevcdsp_init.o
51OBJS-$(CONFIG_JPEG2000_DECODER) += x86/jpeg2000dsp_init.o50OBJS-$(CONFIG_JPEG2000_DECODER) += x86/jpeg2000dsp_init.o
@@ -133,8 +132,7 @@ YASM-OBJS-$(CONFIG_ADPCM_G722_DECODER) += x86/g722dsp.o · 81 unmodified lines
133YASM-OBJS-$(CONFIG_ADPCM_G722_ENCODER) += x86/g722dsp.o132YASM-OBJS-$(CONFIG_ADPCM_G722_ENCODER) += x86/g722dsp.o
134YASM-OBJS-$(CONFIG_ALAC_DECODER) += x86/alacdsp.o133YASM-OBJS-$(CONFIG_ALAC_DECODER) += x86/alacdsp.o
135YASM-OBJS-$(CONFIG_APNG_DECODER) += x86/pngdsp.o134YASM-OBJS-$(CONFIG_APNG_DECODER) += x86/pngdsp.o
136YASM-OBJS-$(CONFIG_DCA_DECODER) += x86/dcadsp.o \135#YASM-OBJS-$(CONFIG_DCA_DECODER) += x86/synth_filter.o
137 x86/synth_filter.o
138YASM-OBJS-$(CONFIG_DIRAC_DECODER) += x86/diracdsp_mmx.o x86/diracdsp_yasm.o \136YASM-OBJS-$(CONFIG_DIRAC_DECODER) += x86/diracdsp_mmx.o x86/diracdsp_yasm.o \
139 x86/dwt_yasm.o137 x86/dwt_yasm.o
140YASM-OBJS-$(CONFIG_DNXHD_ENCODER) += x86/dnxhdenc.o138YASM-OBJS-$(CONFIG_DNXHD_ENCODER) += x86/dnxhdenc.o
libavcodec/x86/dcadsp.asm+0−123
@@ -1,123 +0,0 @@
1;******************************************************************************
2;* SSE-optimized functions for the DCA decoder
3;* Copyright (C) 2012-2014 Christophe Gisquet <christophe.gisquet@gmail.com>
4;*
5;* This file is part of FFmpeg.
6;*
7;* FFmpeg is free software; you can redistribute it and/or
8;* modify it under the terms of the GNU Lesser General Public
9;* License as published by the Free Software Foundation; either
10;* version 2.1 of the License, or (at your option) any later version.
11;*
12;* FFmpeg is distributed in the hope that it will be useful,
13;* but WITHOUT ANY WARRANTY; without even the implied warranty of
14;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15;* Lesser General Public License for more details.
16;*
17;* You should have received a copy of the GNU Lesser General Public
18;* License along with FFmpeg; if not, write to the Free Software
19;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20;******************************************************************************
21
22%include "libavutil/x86/x86util.asm"
23
24SECTION_RODATA
25pf_inv16: times 4 dd 0x3D800000 ; 1/16
26
27SECTION .text
28
29; %1=v0/v1 %2=in1 %3=in2
30%macro FIR_LOOP 2-3
31.loop%1:
32%define va m1
33%define vb m2
34%if %1
35%define OFFSET 0
36%else
37%define OFFSET NUM_COEF*count
38%endif
39; for v0, incrementing and for v1, decrementing
40 mova va, [cf0q + OFFSET]
41 mova vb, [cf0q + OFFSET + 4*NUM_COEF]
42%if %0 == 3
43 mova m4, [cf0q + OFFSET + mmsize]
44 mova m0, [cf0q + OFFSET + 4*NUM_COEF + mmsize]
45%endif
46 mulps va, %2
47 mulps vb, %2
48%if %0 == 3
49%if cpuflag(fma3)
50 fmaddps va, m4, %3, va
51 fmaddps vb, m0, %3, vb
52%else
53 mulps m4, %3
54 mulps m0, %3
55 addps va, m4
56 addps vb, m0
57%endif
58%endif
59 ; va = va1 va2 va3 va4
60 ; vb = vb1 vb2 vb3 vb4
61%if %1
62 SWAP va, vb
63%endif
64 mova m4, va
65 unpcklps va, vb ; va3 vb3 va4 vb4
66 unpckhps m4, vb ; va1 vb1 va2 vb2
67 addps m4, va ; va1+3 vb1+3 va2+4 vb2+4
68 movhlps vb, m4 ; va1+3 vb1+3
69 addps vb, m4 ; va0..4 vb0..4
70 movlps [outq + count], vb
71%if %1
72 sub cf0q, 8*NUM_COEF
73%endif
74 add count, 8
75 jl .loop%1
76%endmacro
77
78; void dca_lfe_fir(float *out, float *in, float *coefs)
79%macro DCA_LFE_FIR 1
80cglobal dca_lfe_fir%1, 3,3,6-%1, out, in, cf0
81%define IN1 m3
82%define IN2 m5
83%define count inq
84%define NUM_COEF 4*(2-%1)
85%define NUM_OUT 32*(%1+1)
86
87 movu IN1, [inq + 4 - 1*mmsize]
88 shufps IN1, IN1, q0123
89%if %1 == 0
90 movu IN2, [inq + 4 - 2*mmsize]
91 shufps IN2, IN2, q0123
92%endif
93
94 mov count, -4*NUM_OUT
95 add cf0q, 4*NUM_COEF*NUM_OUT
96 add outq, 4*NUM_OUT
97 ; compute v0 first
98%if %1 == 0
99 FIR_LOOP 0, IN1, IN2
100%else
101 FIR_LOOP 0, IN1
102%endif
103 shufps IN1, IN1, q0123
104 mov count, -4*NUM_OUT
105 ; cf1 already correctly positioned
106 add outq, 4*NUM_OUT ; outq now at out2
107 sub cf0q, 8*NUM_COEF
108%if %1 == 0
109 shufps IN2, IN2, q0123
110 FIR_LOOP 1, IN2, IN1
111%else
112 FIR_LOOP 1, IN1
113%endif
114 RET
115%endmacro
116
117INIT_XMM sse
118DCA_LFE_FIR 0
119DCA_LFE_FIR 1
120%if HAVE_FMA3_EXTERNAL
121INIT_XMM fma3
122DCA_LFE_FIR 0
123%endif
libavcodec/x86/dcadsp_init.c+0−42
@@ -1,42 +0,0 @@
1/*
2 * Copyright (c) 2012-2014 Christophe Gisquet <christophe.gisquet@gmail.com>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "libavutil/attributes.h"
22#include "libavutil/cpu.h"
23#include "libavutil/x86/cpu.h"
24#include "libavcodec/dcadsp.h"
25
26void ff_dca_lfe_fir0_sse(float *out, const float *in, const float *coefs);
27void ff_dca_lfe_fir1_sse(float *out, const float *in, const float *coefs);
28void ff_dca_lfe_fir0_fma3(float *out, const float *in, const float *coefs);
29
30av_cold void ff_dcadsp_init_x86(DCADSPContext *s)
31{
32 int cpu_flags = av_get_cpu_flags();
33
34 if (EXTERNAL_SSE(cpu_flags)) {
35 s->lfe_fir[0] = ff_dca_lfe_fir0_sse;
36 s->lfe_fir[1] = ff_dca_lfe_fir1_sse;
37 }
38
39 if (EXTERNAL_FMA3(cpu_flags)) {
40 s->lfe_fir[0] = ff_dca_lfe_fir0_fma3;
41 }
42}
tests/checkasm/Makefile+1−1
@@ -1,7 +1,7 @@
1# libavcodec tests1# libavcodec tests
2AVCODECOBJS-$(CONFIG_ALAC_DECODER) += alacdsp.o2AVCODECOBJS-$(CONFIG_ALAC_DECODER) += alacdsp.o
3AVCODECOBJS-$(CONFIG_BSWAPDSP) += bswapdsp.o3AVCODECOBJS-$(CONFIG_BSWAPDSP) += bswapdsp.o
4AVCODECOBJS-$(CONFIG_DCA_DECODER) += dcadsp.o synth_filter.o4#AVCODECOBJS-$(CONFIG_DCA_DECODER) += synth_filter.o
5AVCODECOBJS-$(CONFIG_FLACDSP) += flacdsp.o5AVCODECOBJS-$(CONFIG_FLACDSP) += flacdsp.o
6AVCODECOBJS-$(CONFIG_FMTCONVERT) += fmtconvert.o6AVCODECOBJS-$(CONFIG_FMTCONVERT) += fmtconvert.o
7AVCODECOBJS-$(CONFIG_H264PRED) += h264pred.o7AVCODECOBJS-$(CONFIG_H264PRED) += h264pred.o
tests/checkasm/checkasm.c+2−3
@@ -71,10 +71,9 @@ static const struct { · 70 unmodified lines
71 #if CONFIG_BSWAPDSP71 #if CONFIG_BSWAPDSP
72 { "bswapdsp", checkasm_check_bswapdsp },72 { "bswapdsp", checkasm_check_bswapdsp },
73 #endif73 #endif
74 #if CONFIG_DCA_DECODER74/* #if CONFIG_DCA_DECODER
75 { "dcadsp", checkasm_check_dcadsp },
76 { "synth_filter", checkasm_check_synth_filter },75 { "synth_filter", checkasm_check_synth_filter },
77 #endif76 #endif*/
78 #if CONFIG_FLACDSP77 #if CONFIG_FLACDSP
79 { "flacdsp", checkasm_check_flacdsp },78 { "flacdsp", checkasm_check_flacdsp },
80 #endif79 #endif
tests/checkasm/checkasm.h+0−1
@@ -32,7 +32,6 @@ · 31 unmodified lines
32 32
33void checkasm_check_alacdsp(void);33void checkasm_check_alacdsp(void);
34void checkasm_check_bswapdsp(void);34void checkasm_check_bswapdsp(void);
35void checkasm_check_dcadsp(void);
36void checkasm_check_flacdsp(void);35void checkasm_check_flacdsp(void);
37void checkasm_check_fmtconvert(void);36void checkasm_check_fmtconvert(void);
38void checkasm_check_h264pred(void);37void checkasm_check_h264pred(void);
tests/checkasm/dcadsp.c+0−92
@@ -1,92 +0,0 @@
1/*
2 * Copyright (c) 2015 Janne Grunau
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <math.h>
22#include <string.h>
23#include <stdlib.h>
24
25#include "libavutil/internal.h"
26#include "libavutil/intfloat.h"
27#include "libavcodec/dca.h"
28#include "libavcodec/dcadsp.h"
29#include "libavcodec/dcadata.h"
30
31#include "checkasm.h"
32
33#define randomize_lfe_fir(size) \
34 do { \
35 int i; \
36 for (i = 0; i < size; i++) { \
37 float f = (float)rnd() / (UINT_MAX >> 1) - 1.0f; \
38 in[i] = f; \
39 } \
40 for (i = 0; i < 256; i++) { \
41 float f = (float)rnd() / (UINT_MAX >> 1) - 1.0f; \
42 coeffs[i] = f; \
43 } \
44 } while (0)
45
46#define check_lfe_fir(decifactor, eps) \
47 do { \
48 LOCAL_ALIGNED_16(float, in, [256 / decifactor]); \
49 LOCAL_ALIGNED_16(float, out0, [decifactor * 2]); \
50 LOCAL_ALIGNED_16(float, out1, [decifactor * 2]); \
51 LOCAL_ALIGNED_16(float, coeffs, [256]); \
52 int i; \
53 const float * in_ptr = in + (256 / decifactor) - 1; \
54 declare_func(void, float *out, const float *in, const float *coeffs); \
55 /* repeat the test several times */ \
56 for (i = 0; i < 32; i++) { \
57 int j; \
58 memset(out0, 0, sizeof(*out0) * 2 * decifactor); \
59 memset(out1, 0xFF, sizeof(*out1) * 2 * decifactor); \
60 randomize_lfe_fir(256 / decifactor); \
61 call_ref(out0, in_ptr, coeffs); \
62 call_new(out1, in_ptr, coeffs); \
63 for (j = 0; j < 2 * decifactor; j++) { \
64 if (!float_near_abs_eps(out0[j], out1[j], eps)) { \
65 if (0) { \
66 union av_intfloat32 x, y; x.f = out0[j]; y.f = out1[j]; \
67 fprintf(stderr, "%3d: %11g (0x%08x); %11g (0x%08x)\n", \
68 j, x.f, x.i, y.f, y.i); \
69 } \
70 fail(); \
71 break; \
72 } \
73 } \
74 bench_new(out1, in_ptr, coeffs); \
75 } \
76 } while (0)
77
78void checkasm_check_dcadsp(void)
79{
80 DCADSPContext c;
81
82 ff_dcadsp_init(&c);
83
84 /* values are limited to {-8, 8} so absolute epsilon is good enough */
85 if (check_func(c.lfe_fir[0], "dca_lfe_fir0"))
86 check_lfe_fir(32, 1.0e-6f);
87
88 if (check_func(c.lfe_fir[1], "dca_lfe_fir1"))
89 check_lfe_fir(64, 1.0e-6f);
90
91 report("dcadsp");
92}
tests/fate/acodec.mak+2−2
@@ -99,14 +99,14 @@ FATE_ACODEC-$(call ENCDEC, ALAC, MOV) += fate-acodec-alac · 98 unmodified lines
99fate-acodec-alac: FMT = mov99fate-acodec-alac: FMT = mov
100fate-acodec-alac: CODEC = alac -compression_level 1100fate-acodec-alac: CODEC = alac -compression_level 1
101 101
102FATE_ACODEC-$(call ENCDEC, DCA, DTS) += fate-acodec-dca102#FATE_ACODEC-$(call ENCDEC, DCA, DTS) += fate-acodec-dca
103fate-acodec-dca: tests/data/asynth-44100-2.wav103fate-acodec-dca: tests/data/asynth-44100-2.wav
104fate-acodec-dca: SRC = tests/data/asynth-44100-2.wav104fate-acodec-dca: SRC = tests/data/asynth-44100-2.wav
105fate-acodec-dca: CMD = md5 -i $(TARGET_PATH)/$(SRC) -c:a dca -strict -2 -f dts -flags +bitexact105fate-acodec-dca: CMD = md5 -i $(TARGET_PATH)/$(SRC) -c:a dca -strict -2 -f dts -flags +bitexact
106fate-acodec-dca: CMP = oneline106fate-acodec-dca: CMP = oneline
107fate-acodec-dca: REF = 7ffdefdf47069289990755c79387cc90107fate-acodec-dca: REF = 7ffdefdf47069289990755c79387cc90
108 108
109FATE_ACODEC-$(call ENCDEC, DCA, WAV) += fate-acodec-dca2109#FATE_ACODEC-$(call ENCDEC, DCA, WAV) += fate-acodec-dca2
110fate-acodec-dca2: CMD = enc_dec_pcm dts wav s16le $(SRC) -c:a dca -strict -2 -flags +bitexact110fate-acodec-dca2: CMD = enc_dec_pcm dts wav s16le $(SRC) -c:a dca -strict -2 -flags +bitexact
111fate-acodec-dca2: REF = $(SRC)111fate-acodec-dca2: REF = $(SRC)
112fate-acodec-dca2: CMP = stddev112fate-acodec-dca2: CMP = stddev
tests/fate/audio.mak+2−7
@@ -21,12 +21,7 @@ fate-dca-core: CMD = pcm -i $(TARGET_SAMPLES)/dts/dts.ts · 20 unmodified lines
21fate-dca-core: CMP = oneoff21fate-dca-core: CMP = oneoff
22fate-dca-core: REF = $(SAMPLES)/dts/dts.pcm22fate-dca-core: REF = $(SAMPLES)/dts/dts.pcm
23 23
24FATE_DCA-$(CONFIG_DTS_DEMUXER) += fate-dca-xll24#FATE_SAMPLES_AUDIO-$(CONFIG_DCA_DECODER) += $(FATE_DCA-yes)
25fate-dca-xll: CMD = pcm -disable_xll 0 -i $(TARGET_SAMPLES)/dts/master_audio_7.1_24bit.dts
26fate-dca-xll: CMP = oneoff
27fate-dca-xll: REF = $(SAMPLES)/dts/master_audio_7.1_24bit_2.pcm
28
29FATE_SAMPLES_AUDIO-$(CONFIG_DCA_DECODER) += $(FATE_DCA-yes)
30fate-dca: $(FATE_DCA-yes)25fate-dca: $(FATE_DCA-yes)
31 26
32FATE_SAMPLES_AUDIO-$(call DEMDEC, DSICIN, DSICINAUDIO) += fate-delphine-cin-audio27FATE_SAMPLES_AUDIO-$(call DEMDEC, DSICIN, DSICINAUDIO) += fate-delphine-cin-audio
@@ -36,7 +31,7 @@ FATE_SAMPLES_AUDIO-$(call DEMDEC, DSS, DSS_SP) += fate-dss-lp fate-dss-sp · 3 unmodified lines
36fate-dss-lp: CMD = framecrc -i $(TARGET_SAMPLES)/dss/lp.dss -frames 3031fate-dss-lp: CMD = framecrc -i $(TARGET_SAMPLES)/dss/lp.dss -frames 30
37fate-dss-sp: CMD = framecrc -i $(TARGET_SAMPLES)/dss/sp.dss -frames 3032fate-dss-sp: CMD = framecrc -i $(TARGET_SAMPLES)/dss/sp.dss -frames 30
38 33
39FATE_SAMPLES_AUDIO-$(call DEMDEC, DTS, DCA) += fate-dts_es34#FATE_SAMPLES_AUDIO-$(call DEMDEC, DTS, DCA) += fate-dts_es
40fate-dts_es: CMD = pcm -i $(TARGET_SAMPLES)/dts/dts_es.dts35fate-dts_es: CMD = pcm -i $(TARGET_SAMPLES)/dts/dts_es.dts
41fate-dts_es: CMP = oneoff36fate-dts_es: CMP = oneoff
42fate-dts_es: REF = $(SAMPLES)/dts/dts_es_2.pcm37fate-dts_es: REF = $(SAMPLES)/dts/dts_es_2.pcm

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t