Adds another safeguard to ensure AC3 pass-thru uses a 48khz sample rate.
[HandBrake.git] / contrib / patch-a52dec.patch
blobcf1c8a64ad74a5eb1c85ba28249a465a0615782d
1 diff -Naur a52dec_original/include/a52.h a52dec_patched/include/a52.h
2 --- a52dec_original/include/a52.h 2002-01-28 05:37:54.000000000 +0000
3 +++ a52dec_patched/include/a52.h 2007-04-04 19:12:57.000000000 +0100
4 @@ -48,6 +48,10 @@
5 #define A52_LFE 16
6 #define A52_ADJUST_LEVEL 32
8 +// this next constant can be ORed with A52_DOLBY to tell liba52 to use 5.0 DPLII matrix encoding,
9 +// rather than just 4.0 Dolby Surround matrix encoding
10 +#define A52_USE_DPLII 64
12 a52_state_t * a52_init (uint32_t mm_accel);
13 sample_t * a52_samples (a52_state_t * state);
14 int a52_syncinfo (uint8_t * buf, int * flags,
15 diff -Naur a52dec_original/liba52/a52_internal.h a52dec_patched/liba52/a52_internal.h
16 --- a52dec_original/liba52/a52_internal.h 2002-07-28 02:52:06.000000000 +0100
17 +++ a52dec_patched/liba52/a52_internal.h 2007-04-04 19:11:43.000000000 +0100
18 @@ -93,6 +93,10 @@
19 #define LEVEL_45DB 0.5946035575013605
20 #define LEVEL_6DB 0.5
22 +// these next two constants are used for DPL matrix encoding in downmix.c
23 +#define LEVEL_SQRT_1_2 0.5
24 +#define LEVEL_SQRT_3_4 0.8660254037844386
26 #define EXP_REUSE (0)
27 #define EXP_D15 (1)
28 #define EXP_D25 (2)
29 diff -Naur a52dec_original/liba52/downmix.c a52dec_patched/liba52/downmix.c
30 --- a52dec_original/liba52/downmix.c 2002-01-28 05:37:54.000000000 +0000
31 +++ a52dec_patched/liba52/downmix.c 2007-04-06 13:47:49.000000000 +0100
32 @@ -34,6 +34,7 @@
33 int a52_downmix_init (int input, int flags, sample_t * level,
34 sample_t clev, sample_t slev)
37 static uint8_t table[11][8] = {
38 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
39 A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO},
40 @@ -148,6 +149,9 @@
41 break;
44 + // add the DPLII flag back into the output if it was passed in
45 + output = output | (flags & A52_USE_DPLII);
47 return output;
50 @@ -418,17 +422,46 @@
54 -static void mix32toS (sample_t * samples, sample_t bias)
55 +static void mix32toS (sample_t * samples, sample_t bias, int use_dpl2)
57 - int i;
58 - sample_t common, surround;
60 - for (i = 0; i < 256; i++) {
61 - common = samples[i + 256] + bias;
62 - surround = samples[i + 768] + samples[i + 1024];
63 - samples[i] += common - surround;
64 - samples[i + 256] = samples[i + 512] + common + surround;
65 - }
66 + if (use_dpl2 == 1) {
68 + int i;
69 + sample_t cc, Lt, Rt, Ls, Rs, Lss, Rss;
71 + for (i = 0; i < 256; i++) {
73 + cc = samples[i + 256] * LEVEL_3DB;
75 + Lt = samples[i] + cc;
76 + Rt = samples[i + 512] + cc;
78 + Ls = samples[i + 768];
79 + Rs = samples[i + 1024];
81 + Lss = (LEVEL_SQRT_3_4 * Ls) - (LEVEL_SQRT_1_2 * Rs);
82 + Rss = -(LEVEL_SQRT_1_2 * Ls) + (LEVEL_SQRT_3_4 * Rs);
84 + samples[i] = bias + Lt + Lss;
85 + samples[i + 256] = bias + Rt + Rss;
87 + }
89 + } else {
91 + int i;
92 + sample_t common, surround;
94 + for (i = 0; i < 256; i++) {
95 + common = samples[i + 256] + bias;
96 + surround = samples[i + 768] + samples[i + 1024];
97 + samples[i] += common - surround;
98 + samples[i + 256] = samples[i + 512] + common + surround;
99 + }
105 static void move2to1 (sample_t * src, sample_t * dest, sample_t bias)
106 @@ -533,7 +566,7 @@
107 break;
109 case CONVERT (A52_3F2R, A52_DOLBY):
110 - mix32toS (samples, bias);
111 + mix32toS (samples, bias, ((output & A52_USE_DPLII) == A52_USE_DPLII));
112 break;
114 case CONVERT (A52_3F1R, A52_3F):