annotate ac3enc.c @ 11779:9371254837b5 libavcodec

Add support for the newly added Nut codec tags (added in Nut r669): Y1[00][16], [16][00]1Y, Y3[11][16], [16][11]3Y, Y3[10][16], [16][10]3Y, Y3[00][16], [16][00]3Y, Y4[11][ 8], Y2[00][ 8].
author stefano
date Wed, 26 May 2010 22:26:19 +0000
parents 7dd2a45249a9
children 8b28e74de2c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /*
7470
1a93d3bbe3ee cosmetics: make all references to AC-3 capitalized and hyphenated
jbr
parents: 7451
diff changeset
2 * The simplest AC-3 encoder
8629
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 7769
diff changeset
3 * Copyright (c) 2000 Fabrice Bellard
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3668
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3668
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3668
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
429
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3668
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3668
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
429
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
15 * Lesser General Public License for more details.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
16 *
429
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3668
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
20 */
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
21
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
22 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11560
diff changeset
23 * @file
7470
1a93d3bbe3ee cosmetics: make all references to AC-3 capitalized and hyphenated
jbr
parents: 7451
diff changeset
24 * The simplest AC-3 encoder.
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
25 */
64
5aa6292a1660 win32 fixes
glantau
parents: 25
diff changeset
26 //#define DEBUG
5aa6292a1660 win32 fixes
glantau
parents: 25
diff changeset
27 //#define DEBUG_BITALLOC
6763
f7cbb7733146 Use full path for #includes from another directory.
diego
parents: 6712
diff changeset
28 #include "libavutil/crc.h"
64
5aa6292a1660 win32 fixes
glantau
parents: 25
diff changeset
29 #include "avcodec.h"
10501
bdf4a9ca162a Move ff_reverse in libavcodec to av_reverse in libavutil.
cehoyos
parents: 10145
diff changeset
30 #include "libavutil/common.h" /* for av_reverse */
9411
4cb7c65fc775 Split bitstream.h, put the bitstream writer stuff in the new file
stefano
parents: 9142
diff changeset
31 #include "put_bits.h"
782
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
32 #include "ac3.h"
9513
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
33 #include "audioconvert.h"
782
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
34
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
35 typedef struct AC3EncodeContext {
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
36 PutBitContext pb;
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
37 int nb_channels;
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
38 int nb_all_channels;
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
39 int lfe_channel;
9452
42803399ba8a ac3enc: reorder input channels to AC-3 channel order
jbr
parents: 9431
diff changeset
40 const uint8_t *channel_map;
782
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
41 int bit_rate;
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 1014
diff changeset
42 unsigned int sample_rate;
6005
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
43 unsigned int bitstream_id;
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 1014
diff changeset
44 unsigned int frame_size_min; /* minimum frame size in case rounding is necessary */
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 1014
diff changeset
45 unsigned int frame_size; /* current frame size in words */
3246
219afc0c4a80 AC3: support encoding fractional frame sizes
corey
parents: 3221
diff changeset
46 unsigned int bits_written;
219afc0c4a80 AC3: support encoding fractional frame sizes
corey
parents: 3221
diff changeset
47 unsigned int samples_written;
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
48 int sr_shift;
6005
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
49 unsigned int frame_size_code;
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
50 unsigned int sr_code; /* frequency */
6005
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
51 unsigned int channel_mode;
782
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
52 int lfe;
6005
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
53 unsigned int bitstream_mode;
782
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
54 short last_samples[AC3_MAX_CHANNELS][256];
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 1014
diff changeset
55 unsigned int chbwcod[AC3_MAX_CHANNELS];
782
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
56 int nb_coefs[AC3_MAX_CHANNELS];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
57
782
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
58 /* bitrate allocation control */
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
59 int slow_gain_code, slow_decay_code, fast_decay_code, db_per_bit_code, floor_code;
782
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
60 AC3BitAllocParameters bit_alloc;
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
61 int coarse_snr_offset;
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
62 int fast_gain_code[AC3_MAX_CHANNELS];
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
63 int fine_snr_offset[AC3_MAX_CHANNELS];
782
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
64 /* mantissa encoding */
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
65 int mant1_cnt, mant2_cnt, mant4_cnt;
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
66 } AC3EncodeContext;
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
67
4643
1e175640dad3 Remove common code from AC-3 encoder and utilize ac3.c.
jbr
parents: 4641
diff changeset
68 static int16_t costab[64];
1e175640dad3 Remove common code from AC-3 encoder and utilize ac3.c.
jbr
parents: 4641
diff changeset
69 static int16_t sintab[64];
1e175640dad3 Remove common code from AC-3 encoder and utilize ac3.c.
jbr
parents: 4641
diff changeset
70 static int16_t xcos1[128];
1e175640dad3 Remove common code from AC-3 encoder and utilize ac3.c.
jbr
parents: 4641
diff changeset
71 static int16_t xsin1[128];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
72
986e461dc072 Initial revision
glantau
parents:
diff changeset
73 #define MDCT_NBITS 9
986e461dc072 Initial revision
glantau
parents:
diff changeset
74 #define N (1 << MDCT_NBITS)
986e461dc072 Initial revision
glantau
parents:
diff changeset
75
986e461dc072 Initial revision
glantau
parents:
diff changeset
76 /* new exponents are sent if their Norm 1 exceed this number */
986e461dc072 Initial revision
glantau
parents:
diff changeset
77 #define EXP_DIFF_THRESHOLD 1000
986e461dc072 Initial revision
glantau
parents:
diff changeset
78
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
79 static inline int16_t fix15(float a)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
80 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
81 int v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
82 v = (int)(a * (float)(1 << 15));
986e461dc072 Initial revision
glantau
parents:
diff changeset
83 if (v < -32767)
986e461dc072 Initial revision
glantau
parents:
diff changeset
84 v = -32767;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
85 else if (v > 32767)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
86 v = 32767;
986e461dc072 Initial revision
glantau
parents:
diff changeset
87 return v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
88 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
89
986e461dc072 Initial revision
glantau
parents:
diff changeset
90 typedef struct IComplex {
986e461dc072 Initial revision
glantau
parents:
diff changeset
91 short re,im;
986e461dc072 Initial revision
glantau
parents:
diff changeset
92 } IComplex;
986e461dc072 Initial revision
glantau
parents:
diff changeset
93
9007
043574c5c153 Add missing av_cold in static init/close functions.
stefano
parents: 8718
diff changeset
94 static av_cold void fft_init(int ln)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
95 {
6166
3941c21ad59c Remove two unused variables.
diego
parents: 6165
diff changeset
96 int i, n;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
97 float alpha;
986e461dc072 Initial revision
glantau
parents:
diff changeset
98
986e461dc072 Initial revision
glantau
parents:
diff changeset
99 n = 1 << ln;
986e461dc072 Initial revision
glantau
parents:
diff changeset
100
986e461dc072 Initial revision
glantau
parents:
diff changeset
101 for(i=0;i<(n/2);i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
102 alpha = 2 * M_PI * (float)i / (float)n;
986e461dc072 Initial revision
glantau
parents:
diff changeset
103 costab[i] = fix15(cos(alpha));
986e461dc072 Initial revision
glantau
parents:
diff changeset
104 sintab[i] = fix15(sin(alpha));
986e461dc072 Initial revision
glantau
parents:
diff changeset
105 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
106 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
107
986e461dc072 Initial revision
glantau
parents:
diff changeset
108 /* butter fly op */
986e461dc072 Initial revision
glantau
parents:
diff changeset
109 #define BF(pre, pim, qre, qim, pre1, pim1, qre1, qim1) \
986e461dc072 Initial revision
glantau
parents:
diff changeset
110 {\
986e461dc072 Initial revision
glantau
parents:
diff changeset
111 int ax, ay, bx, by;\
986e461dc072 Initial revision
glantau
parents:
diff changeset
112 bx=pre1;\
986e461dc072 Initial revision
glantau
parents:
diff changeset
113 by=pim1;\
986e461dc072 Initial revision
glantau
parents:
diff changeset
114 ax=qre1;\
986e461dc072 Initial revision
glantau
parents:
diff changeset
115 ay=qim1;\
986e461dc072 Initial revision
glantau
parents:
diff changeset
116 pre = (bx + ax) >> 1;\
986e461dc072 Initial revision
glantau
parents:
diff changeset
117 pim = (by + ay) >> 1;\
986e461dc072 Initial revision
glantau
parents:
diff changeset
118 qre = (bx - ax) >> 1;\
986e461dc072 Initial revision
glantau
parents:
diff changeset
119 qim = (by - ay) >> 1;\
986e461dc072 Initial revision
glantau
parents:
diff changeset
120 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
121
986e461dc072 Initial revision
glantau
parents:
diff changeset
122 #define CMUL(pre, pim, are, aim, bre, bim) \
986e461dc072 Initial revision
glantau
parents:
diff changeset
123 {\
986e461dc072 Initial revision
glantau
parents:
diff changeset
124 pre = (MUL16(are, bre) - MUL16(aim, bim)) >> 15;\
986e461dc072 Initial revision
glantau
parents:
diff changeset
125 pim = (MUL16(are, bim) + MUL16(bre, aim)) >> 15;\
986e461dc072 Initial revision
glantau
parents:
diff changeset
126 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
127
986e461dc072 Initial revision
glantau
parents:
diff changeset
128
986e461dc072 Initial revision
glantau
parents:
diff changeset
129 /* do a 2^n point complex fft on 2^ln points. */
986e461dc072 Initial revision
glantau
parents:
diff changeset
130 static void fft(IComplex *z, int ln)
986e461dc072 Initial revision
glantau
parents:
diff changeset
131 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
132 int j, l, np, np2;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
133 int nblocks, nloops;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
134 register IComplex *p,*q;
986e461dc072 Initial revision
glantau
parents:
diff changeset
135 int tmp_re, tmp_im;
986e461dc072 Initial revision
glantau
parents:
diff changeset
136
986e461dc072 Initial revision
glantau
parents:
diff changeset
137 np = 1 << ln;
986e461dc072 Initial revision
glantau
parents:
diff changeset
138
986e461dc072 Initial revision
glantau
parents:
diff changeset
139 /* reverse */
986e461dc072 Initial revision
glantau
parents:
diff changeset
140 for(j=0;j<np;j++) {
10501
bdf4a9ca162a Move ff_reverse in libavcodec to av_reverse in libavutil.
cehoyos
parents: 10145
diff changeset
141 int k = av_reverse[j] >> (8 - ln);
6140
bf4d7ce32af5 Use FFSWAP instead of "manual" swap
reimar
parents: 6108
diff changeset
142 if (k < j)
bf4d7ce32af5 Use FFSWAP instead of "manual" swap
reimar
parents: 6108
diff changeset
143 FFSWAP(IComplex, z[k], z[j]);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
144 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
145
986e461dc072 Initial revision
glantau
parents:
diff changeset
146 /* pass 0 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
147
986e461dc072 Initial revision
glantau
parents:
diff changeset
148 p=&z[0];
986e461dc072 Initial revision
glantau
parents:
diff changeset
149 j=(np >> 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
150 do {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
151 BF(p[0].re, p[0].im, p[1].re, p[1].im,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
152 p[0].re, p[0].im, p[1].re, p[1].im);
986e461dc072 Initial revision
glantau
parents:
diff changeset
153 p+=2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
154 } while (--j != 0);
986e461dc072 Initial revision
glantau
parents:
diff changeset
155
986e461dc072 Initial revision
glantau
parents:
diff changeset
156 /* pass 1 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
157
986e461dc072 Initial revision
glantau
parents:
diff changeset
158 p=&z[0];
986e461dc072 Initial revision
glantau
parents:
diff changeset
159 j=np >> 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
160 do {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
161 BF(p[0].re, p[0].im, p[2].re, p[2].im,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
162 p[0].re, p[0].im, p[2].re, p[2].im);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
163 BF(p[1].re, p[1].im, p[3].re, p[3].im,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
164 p[1].re, p[1].im, p[3].im, -p[3].re);
986e461dc072 Initial revision
glantau
parents:
diff changeset
165 p+=4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
166 } while (--j != 0);
986e461dc072 Initial revision
glantau
parents:
diff changeset
167
986e461dc072 Initial revision
glantau
parents:
diff changeset
168 /* pass 2 .. ln-1 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
169
986e461dc072 Initial revision
glantau
parents:
diff changeset
170 nblocks = np >> 3;
986e461dc072 Initial revision
glantau
parents:
diff changeset
171 nloops = 1 << 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
172 np2 = np >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
173 do {
986e461dc072 Initial revision
glantau
parents:
diff changeset
174 p = z;
986e461dc072 Initial revision
glantau
parents:
diff changeset
175 q = z + nloops;
986e461dc072 Initial revision
glantau
parents:
diff changeset
176 for (j = 0; j < nblocks; ++j) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
177
986e461dc072 Initial revision
glantau
parents:
diff changeset
178 BF(p->re, p->im, q->re, q->im,
986e461dc072 Initial revision
glantau
parents:
diff changeset
179 p->re, p->im, q->re, q->im);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
180
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
181 p++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
182 q++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
183 for(l = nblocks; l < np2; l += nblocks) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
184 CMUL(tmp_re, tmp_im, costab[l], -sintab[l], q->re, q->im);
986e461dc072 Initial revision
glantau
parents:
diff changeset
185 BF(p->re, p->im, q->re, q->im,
986e461dc072 Initial revision
glantau
parents:
diff changeset
186 p->re, p->im, tmp_re, tmp_im);
986e461dc072 Initial revision
glantau
parents:
diff changeset
187 p++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
188 q++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
189 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
190 p += nloops;
986e461dc072 Initial revision
glantau
parents:
diff changeset
191 q += nloops;
986e461dc072 Initial revision
glantau
parents:
diff changeset
192 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
193 nblocks = nblocks >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
194 nloops = nloops << 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
195 } while (nblocks != 0);
986e461dc072 Initial revision
glantau
parents:
diff changeset
196 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
197
986e461dc072 Initial revision
glantau
parents:
diff changeset
198 /* do a 512 point mdct */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
199 static void mdct512(int32_t *out, int16_t *in)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
200 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
201 int i, re, im, re1, im1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
202 int16_t rot[N];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
203 IComplex x[N/4];
986e461dc072 Initial revision
glantau
parents:
diff changeset
204
986e461dc072 Initial revision
glantau
parents:
diff changeset
205 /* shift to simplify computations */
986e461dc072 Initial revision
glantau
parents:
diff changeset
206 for(i=0;i<N/4;i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
207 rot[i] = -in[i + 3*N/4];
986e461dc072 Initial revision
glantau
parents:
diff changeset
208 for(i=N/4;i<N;i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
209 rot[i] = in[i - N/4];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
210
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
211 /* pre rotation */
986e461dc072 Initial revision
glantau
parents:
diff changeset
212 for(i=0;i<N/4;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
213 re = ((int)rot[2*i] - (int)rot[N-1-2*i]) >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
214 im = -((int)rot[N/2+2*i] - (int)rot[N/2-1-2*i]) >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
215 CMUL(x[i].re, x[i].im, re, im, -xcos1[i], xsin1[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
216 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
217
986e461dc072 Initial revision
glantau
parents:
diff changeset
218 fft(x, MDCT_NBITS - 2);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
219
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
220 /* post rotation */
986e461dc072 Initial revision
glantau
parents:
diff changeset
221 for(i=0;i<N/4;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
222 re = x[i].re;
986e461dc072 Initial revision
glantau
parents:
diff changeset
223 im = x[i].im;
986e461dc072 Initial revision
glantau
parents:
diff changeset
224 CMUL(re1, im1, re, im, xsin1[i], xcos1[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
225 out[2*i] = im1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
226 out[N/2-1-2*i] = re1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
227 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
228 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
229
986e461dc072 Initial revision
glantau
parents:
diff changeset
230 /* XXX: use another norm ? */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
231 static int calc_exp_diff(uint8_t *exp1, uint8_t *exp2, int n)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
232 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
233 int sum, i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
234 sum = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
235 for(i=0;i<n;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
236 sum += abs(exp1[i] - exp2[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
237 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
238 return sum;
986e461dc072 Initial revision
glantau
parents:
diff changeset
239 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
240
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
241 static void compute_exp_strategy(uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNELS],
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
242 uint8_t exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
243 int ch, int is_lfe)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
244 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
245 int i, j;
986e461dc072 Initial revision
glantau
parents:
diff changeset
246 int exp_diff;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
247
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
248 /* estimate if the exponent variation & decide if they should be
986e461dc072 Initial revision
glantau
parents:
diff changeset
249 reused in the next frame */
986e461dc072 Initial revision
glantau
parents:
diff changeset
250 exp_strategy[0][ch] = EXP_NEW;
986e461dc072 Initial revision
glantau
parents:
diff changeset
251 for(i=1;i<NB_BLOCKS;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
252 exp_diff = calc_exp_diff(exp[i][ch], exp[i-1][ch], N/2);
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9516
diff changeset
253 dprintf(NULL, "exp_diff=%d\n", exp_diff);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
254 if (exp_diff > EXP_DIFF_THRESHOLD)
986e461dc072 Initial revision
glantau
parents:
diff changeset
255 exp_strategy[i][ch] = EXP_NEW;
986e461dc072 Initial revision
glantau
parents:
diff changeset
256 else
986e461dc072 Initial revision
glantau
parents:
diff changeset
257 exp_strategy[i][ch] = EXP_REUSE;
986e461dc072 Initial revision
glantau
parents:
diff changeset
258 }
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
259 if (is_lfe)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
260 return;
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
261
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
262 /* now select the encoding strategy type : if exponents are often
986e461dc072 Initial revision
glantau
parents:
diff changeset
263 recoded, we use a coarse encoding */
986e461dc072 Initial revision
glantau
parents:
diff changeset
264 i = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
265 while (i < NB_BLOCKS) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
266 j = i + 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
267 while (j < NB_BLOCKS && exp_strategy[j][ch] == EXP_REUSE)
986e461dc072 Initial revision
glantau
parents:
diff changeset
268 j++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
269 switch(j - i) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
270 case 1:
986e461dc072 Initial revision
glantau
parents:
diff changeset
271 exp_strategy[i][ch] = EXP_D45;
986e461dc072 Initial revision
glantau
parents:
diff changeset
272 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
273 case 2:
986e461dc072 Initial revision
glantau
parents:
diff changeset
274 case 3:
986e461dc072 Initial revision
glantau
parents:
diff changeset
275 exp_strategy[i][ch] = EXP_D25;
986e461dc072 Initial revision
glantau
parents:
diff changeset
276 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
277 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
278 exp_strategy[i][ch] = EXP_D15;
986e461dc072 Initial revision
glantau
parents:
diff changeset
279 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
280 }
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
281 i = j;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
282 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
283 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
284
986e461dc072 Initial revision
glantau
parents:
diff changeset
285 /* set exp[i] to min(exp[i], exp1[i]) */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
286 static void exponent_min(uint8_t exp[N/2], uint8_t exp1[N/2], int n)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
287 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
288 int i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
289
986e461dc072 Initial revision
glantau
parents:
diff changeset
290 for(i=0;i<n;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
291 if (exp1[i] < exp[i])
986e461dc072 Initial revision
glantau
parents:
diff changeset
292 exp[i] = exp1[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
293 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
294 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
295
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
296 /* update the exponents so that they are the ones the decoder will
986e461dc072 Initial revision
glantau
parents:
diff changeset
297 decode. Return the number of bits used to code the exponents */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
298 static int encode_exp(uint8_t encoded_exp[N/2],
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
299 uint8_t exp[N/2],
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
300 int nb_exps,
986e461dc072 Initial revision
glantau
parents:
diff changeset
301 int exp_strategy)
986e461dc072 Initial revision
glantau
parents:
diff changeset
302 {
2157
4478e603a8e3 simpler delta decreasing algorithm patch by (Jeff Muizelaar <jrmuizel at student dot cs dot uwaterloo dot ca>)
michael
parents: 1819
diff changeset
303 int group_size, nb_groups, i, j, k, exp_min;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
304 uint8_t exp1[N/2];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
305
986e461dc072 Initial revision
glantau
parents:
diff changeset
306 switch(exp_strategy) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
307 case EXP_D15:
986e461dc072 Initial revision
glantau
parents:
diff changeset
308 group_size = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
309 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
310 case EXP_D25:
986e461dc072 Initial revision
glantau
parents:
diff changeset
311 group_size = 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
312 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
313 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
314 case EXP_D45:
986e461dc072 Initial revision
glantau
parents:
diff changeset
315 group_size = 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
316 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
317 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
318 nb_groups = ((nb_exps + (group_size * 3) - 4) / (3 * group_size)) * 3;
986e461dc072 Initial revision
glantau
parents:
diff changeset
319
986e461dc072 Initial revision
glantau
parents:
diff changeset
320 /* for each group, compute the minimum exponent */
986e461dc072 Initial revision
glantau
parents:
diff changeset
321 exp1[0] = exp[0]; /* DC exponent is handled separately */
986e461dc072 Initial revision
glantau
parents:
diff changeset
322 k = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
323 for(i=1;i<=nb_groups;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
324 exp_min = exp[k];
986e461dc072 Initial revision
glantau
parents:
diff changeset
325 assert(exp_min >= 0 && exp_min <= 24);
986e461dc072 Initial revision
glantau
parents:
diff changeset
326 for(j=1;j<group_size;j++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
327 if (exp[k+j] < exp_min)
986e461dc072 Initial revision
glantau
parents:
diff changeset
328 exp_min = exp[k+j];
986e461dc072 Initial revision
glantau
parents:
diff changeset
329 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
330 exp1[i] = exp_min;
986e461dc072 Initial revision
glantau
parents:
diff changeset
331 k += group_size;
986e461dc072 Initial revision
glantau
parents:
diff changeset
332 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
333
986e461dc072 Initial revision
glantau
parents:
diff changeset
334 /* constraint for DC exponent */
986e461dc072 Initial revision
glantau
parents:
diff changeset
335 if (exp1[0] > 15)
986e461dc072 Initial revision
glantau
parents:
diff changeset
336 exp1[0] = 15;
986e461dc072 Initial revision
glantau
parents:
diff changeset
337
2157
4478e603a8e3 simpler delta decreasing algorithm patch by (Jeff Muizelaar <jrmuizel at student dot cs dot uwaterloo dot ca>)
michael
parents: 1819
diff changeset
338 /* Decrease the delta between each groups to within 2
4478e603a8e3 simpler delta decreasing algorithm patch by (Jeff Muizelaar <jrmuizel at student dot cs dot uwaterloo dot ca>)
michael
parents: 1819
diff changeset
339 * so that they can be differentially encoded */
4478e603a8e3 simpler delta decreasing algorithm patch by (Jeff Muizelaar <jrmuizel at student dot cs dot uwaterloo dot ca>)
michael
parents: 1819
diff changeset
340 for (i=1;i<=nb_groups;i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
341 exp1[i] = FFMIN(exp1[i], exp1[i-1] + 2);
2157
4478e603a8e3 simpler delta decreasing algorithm patch by (Jeff Muizelaar <jrmuizel at student dot cs dot uwaterloo dot ca>)
michael
parents: 1819
diff changeset
342 for (i=nb_groups-1;i>=0;i--)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
343 exp1[i] = FFMIN(exp1[i], exp1[i+1] + 2);
2157
4478e603a8e3 simpler delta decreasing algorithm patch by (Jeff Muizelaar <jrmuizel at student dot cs dot uwaterloo dot ca>)
michael
parents: 1819
diff changeset
344
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
345 /* now we have the exponent values the decoder will see */
986e461dc072 Initial revision
glantau
parents:
diff changeset
346 encoded_exp[0] = exp1[0];
986e461dc072 Initial revision
glantau
parents:
diff changeset
347 k = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
348 for(i=1;i<=nb_groups;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
349 for(j=0;j<group_size;j++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
350 encoded_exp[k+j] = exp1[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
351 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
352 k += group_size;
986e461dc072 Initial revision
glantau
parents:
diff changeset
353 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
354
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
355 #if defined(DEBUG)
1602
fdb8244da1e5 av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1598
diff changeset
356 av_log(NULL, AV_LOG_DEBUG, "exponents: strategy=%d\n", exp_strategy);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
357 for(i=0;i<=nb_groups * group_size;i++) {
1602
fdb8244da1e5 av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1598
diff changeset
358 av_log(NULL, AV_LOG_DEBUG, "%d ", encoded_exp[i]);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
359 }
1602
fdb8244da1e5 av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1598
diff changeset
360 av_log(NULL, AV_LOG_DEBUG, "\n");
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
361 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
362
986e461dc072 Initial revision
glantau
parents:
diff changeset
363 return 4 + (nb_groups / 3) * 7;
986e461dc072 Initial revision
glantau
parents:
diff changeset
364 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
365
986e461dc072 Initial revision
glantau
parents:
diff changeset
366 /* return the size in bits taken by the mantissa */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
367 static int compute_mantissa_size(AC3EncodeContext *s, uint8_t *m, int nb_coefs)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
368 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
369 int bits, mant, i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
370
986e461dc072 Initial revision
glantau
parents:
diff changeset
371 bits = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
372 for(i=0;i<nb_coefs;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
373 mant = m[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
374 switch(mant) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
375 case 0:
986e461dc072 Initial revision
glantau
parents:
diff changeset
376 /* nothing */
986e461dc072 Initial revision
glantau
parents:
diff changeset
377 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
378 case 1:
986e461dc072 Initial revision
glantau
parents:
diff changeset
379 /* 3 mantissa in 5 bits */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
380 if (s->mant1_cnt == 0)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
381 bits += 5;
986e461dc072 Initial revision
glantau
parents:
diff changeset
382 if (++s->mant1_cnt == 3)
986e461dc072 Initial revision
glantau
parents:
diff changeset
383 s->mant1_cnt = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
384 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
385 case 2:
986e461dc072 Initial revision
glantau
parents:
diff changeset
386 /* 3 mantissa in 7 bits */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
387 if (s->mant2_cnt == 0)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
388 bits += 7;
986e461dc072 Initial revision
glantau
parents:
diff changeset
389 if (++s->mant2_cnt == 3)
986e461dc072 Initial revision
glantau
parents:
diff changeset
390 s->mant2_cnt = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
391 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
392 case 3:
986e461dc072 Initial revision
glantau
parents:
diff changeset
393 bits += 3;
986e461dc072 Initial revision
glantau
parents:
diff changeset
394 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
395 case 4:
986e461dc072 Initial revision
glantau
parents:
diff changeset
396 /* 2 mantissa in 7 bits */
986e461dc072 Initial revision
glantau
parents:
diff changeset
397 if (s->mant4_cnt == 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
398 bits += 7;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
399 if (++s->mant4_cnt == 2)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
400 s->mant4_cnt = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
401 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
402 case 14:
986e461dc072 Initial revision
glantau
parents:
diff changeset
403 bits += 14;
986e461dc072 Initial revision
glantau
parents:
diff changeset
404 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
405 case 15:
986e461dc072 Initial revision
glantau
parents:
diff changeset
406 bits += 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
407 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
408 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
409 bits += mant - 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
410 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
411 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
412 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
413 return bits;
986e461dc072 Initial revision
glantau
parents:
diff changeset
414 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
415
986e461dc072 Initial revision
glantau
parents:
diff changeset
416
4704
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
417 static void bit_alloc_masking(AC3EncodeContext *s,
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
418 uint8_t encoded_exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
419 uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNELS],
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
420 int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
421 int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50])
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
422 {
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
423 int blk, ch;
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
424 int16_t band_psd[NB_BLOCKS][AC3_MAX_CHANNELS][50];
4704
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
425
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
426 for(blk=0; blk<NB_BLOCKS; blk++) {
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
427 for(ch=0;ch<s->nb_all_channels;ch++) {
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
428 if(exp_strategy[blk][ch] == EXP_REUSE) {
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
429 memcpy(psd[blk][ch], psd[blk-1][ch], (N/2)*sizeof(int16_t));
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
430 memcpy(mask[blk][ch], mask[blk-1][ch], 50*sizeof(int16_t));
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
431 } else {
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
432 ff_ac3_bit_alloc_calc_psd(encoded_exp[blk][ch], 0,
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
433 s->nb_coefs[ch],
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
434 psd[blk][ch], band_psd[blk][ch]);
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
435 ff_ac3_bit_alloc_calc_mask(&s->bit_alloc, band_psd[blk][ch],
4704
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
436 0, s->nb_coefs[ch],
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
437 ff_ac3_fast_gain_tab[s->fast_gain_code[ch]],
4704
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
438 ch == s->lfe_channel,
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5089
diff changeset
439 DBA_NONE, 0, NULL, NULL, NULL,
4704
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
440 mask[blk][ch]);
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
441 }
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
442 }
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
443 }
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
444 }
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
445
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
446 static int bit_alloc(AC3EncodeContext *s,
4704
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
447 int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50],
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
448 int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
449 uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
450 int frame_bits, int coarse_snr_offset, int fine_snr_offset)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
451 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
452 int i, ch;
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
453 int snr_offset;
4705
84a455e801c0 simplify
jbr
parents: 4704
diff changeset
454
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
455 snr_offset = (((coarse_snr_offset - 15) << 4) + fine_snr_offset) << 2;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
456
986e461dc072 Initial revision
glantau
parents:
diff changeset
457 /* compute size */
986e461dc072 Initial revision
glantau
parents:
diff changeset
458 for(i=0;i<NB_BLOCKS;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
459 s->mant1_cnt = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
460 s->mant2_cnt = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
461 s->mant4_cnt = 0;
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
462 for(ch=0;ch<s->nb_all_channels;ch++) {
4706
1d8b06947276 cosmetics. align and condense.
jbr
parents: 4705
diff changeset
463 ff_ac3_bit_alloc_calc_bap(mask[i][ch], psd[i][ch], 0,
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
464 s->nb_coefs[ch], snr_offset,
7017
60fd9ae9540e pass bap table to ff_ac3_bit_alloc_calc_bap()
jbr
parents: 6763
diff changeset
465 s->bit_alloc.floor, ff_ac3_bap_tab,
60fd9ae9540e pass bap table to ff_ac3_bit_alloc_calc_bap()
jbr
parents: 6763
diff changeset
466 bap[i][ch]);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
467 frame_bits += compute_mantissa_size(s, bap[i][ch],
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
468 s->nb_coefs[ch]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
469 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
470 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
471 #if 0
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
472 printf("csnr=%d fsnr=%d frame_bits=%d diff=%d\n",
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
473 coarse_snr_offset, fine_snr_offset, frame_bits,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
474 16 * s->frame_size - ((frame_bits + 7) & ~7));
986e461dc072 Initial revision
glantau
parents:
diff changeset
475 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
476 return 16 * s->frame_size - frame_bits;
986e461dc072 Initial revision
glantau
parents:
diff changeset
477 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
478
986e461dc072 Initial revision
glantau
parents:
diff changeset
479 #define SNR_INC1 4
986e461dc072 Initial revision
glantau
parents:
diff changeset
480
986e461dc072 Initial revision
glantau
parents:
diff changeset
481 static int compute_bit_allocation(AC3EncodeContext *s,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
482 uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
483 uint8_t encoded_exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
484 uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNELS],
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
485 int frame_bits)
986e461dc072 Initial revision
glantau
parents:
diff changeset
486 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
487 int i, ch;
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
488 int coarse_snr_offset, fine_snr_offset;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
489 uint8_t bap1[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
4704
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
490 int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
491 int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50];
7129
322023e630a6 mark read-only data as const
stefang
parents: 7040
diff changeset
492 static const int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
493
986e461dc072 Initial revision
glantau
parents:
diff changeset
494 /* init default parameters */
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
495 s->slow_decay_code = 2;
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
496 s->fast_decay_code = 1;
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
497 s->slow_gain_code = 1;
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
498 s->db_per_bit_code = 2;
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
499 s->floor_code = 4;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
500 for(ch=0;ch<s->nb_all_channels;ch++)
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
501 s->fast_gain_code[ch] = 4;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
502
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
503 /* compute real values */
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
504 s->bit_alloc.sr_code = s->sr_code;
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
505 s->bit_alloc.sr_shift = s->sr_shift;
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
506 s->bit_alloc.slow_decay = ff_ac3_slow_decay_tab[s->slow_decay_code] >> s->sr_shift;
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
507 s->bit_alloc.fast_decay = ff_ac3_fast_decay_tab[s->fast_decay_code] >> s->sr_shift;
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
508 s->bit_alloc.slow_gain = ff_ac3_slow_gain_tab[s->slow_gain_code];
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
509 s->bit_alloc.db_per_bit = ff_ac3_db_per_bit_tab[s->db_per_bit_code];
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
510 s->bit_alloc.floor = ff_ac3_floor_tab[s->floor_code];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
511
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
512 /* header size */
986e461dc072 Initial revision
glantau
parents:
diff changeset
513 frame_bits += 65;
6005
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
514 // if (s->channel_mode == 2)
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
515 // frame_bits += 2;
6005
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
516 frame_bits += frame_bits_inc[s->channel_mode];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
517
986e461dc072 Initial revision
glantau
parents:
diff changeset
518 /* audio blocks */
986e461dc072 Initial revision
glantau
parents:
diff changeset
519 for(i=0;i<NB_BLOCKS;i++) {
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
520 frame_bits += s->nb_channels * 2 + 2; /* blksw * c, dithflag * c, dynrnge, cplstre */
6005
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
521 if (s->channel_mode == AC3_CHMODE_STEREO) {
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
522 frame_bits++; /* rematstr */
2644
6ff5dc0dbaf0 While adding stereo rematrixing, I came across something that needs to
michael
parents: 2398
diff changeset
523 if(i==0) frame_bits += 4;
6ff5dc0dbaf0 While adding stereo rematrixing, I came across something that needs to
michael
parents: 2398
diff changeset
524 }
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
525 frame_bits += 2 * s->nb_channels; /* chexpstr[2] * c */
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
526 if (s->lfe)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
527 frame_bits++; /* lfeexpstr */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
528 for(ch=0;ch<s->nb_channels;ch++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
529 if (exp_strategy[i][ch] != EXP_REUSE)
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
530 frame_bits += 6 + 2; /* chbwcod[6], gainrng[2] */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
531 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
532 frame_bits++; /* baie */
986e461dc072 Initial revision
glantau
parents:
diff changeset
533 frame_bits++; /* snr */
986e461dc072 Initial revision
glantau
parents:
diff changeset
534 frame_bits += 2; /* delta / skip */
986e461dc072 Initial revision
glantau
parents:
diff changeset
535 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
536 frame_bits++; /* cplinu for block 0 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
537 /* bit alloc info */
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
538 /* sdcycod[2], fdcycod[2], sgaincod[2], dbpbcod[2], floorcod[3] */
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
539 /* csnroffset[6] */
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
540 /* (fsnoffset[4] + fgaincod[4]) * c */
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
541 frame_bits += 2*4 + 3 + 6 + s->nb_all_channels * (4 + 3);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
542
1819
34cdcb221665 auxdatae, crcrs fix by (Jean-Francois Panisset <panisset at comcast dot net>)
michael
parents: 1602
diff changeset
543 /* auxdatae, crcrsv */
34cdcb221665 auxdatae, crcrs fix by (Jean-Francois Panisset <panisset at comcast dot net>)
michael
parents: 1602
diff changeset
544 frame_bits += 2;
34cdcb221665 auxdatae, crcrs fix by (Jean-Francois Panisset <panisset at comcast dot net>)
michael
parents: 1602
diff changeset
545
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
546 /* CRC */
986e461dc072 Initial revision
glantau
parents:
diff changeset
547 frame_bits += 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
548
4704
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
549 /* calculate psd and masking curve before doing bit allocation */
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
550 bit_alloc_masking(s, encoded_exp, exp_strategy, psd, mask);
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
551
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
552 /* now the big work begins : do the bit allocation. Modify the snr
986e461dc072 Initial revision
glantau
parents:
diff changeset
553 offset until we can pack everything in the requested frame size */
986e461dc072 Initial revision
glantau
parents:
diff changeset
554
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
555 coarse_snr_offset = s->coarse_snr_offset;
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
556 while (coarse_snr_offset >= 0 &&
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
557 bit_alloc(s, mask, psd, bap, frame_bits, coarse_snr_offset, 0) < 0)
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
558 coarse_snr_offset -= SNR_INC1;
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
559 if (coarse_snr_offset < 0) {
6081
64d36d15b3bb Do not give advice for which bitrate to choose.
jbr
parents: 6080
diff changeset
560 av_log(NULL, AV_LOG_ERROR, "Bit allocation failed. Try increasing the bitrate.\n");
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
561 return -1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
562 }
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
563 while ((coarse_snr_offset + SNR_INC1) <= 63 &&
4704
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
564 bit_alloc(s, mask, psd, bap1, frame_bits,
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
565 coarse_snr_offset + SNR_INC1, 0) >= 0) {
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
566 coarse_snr_offset += SNR_INC1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
567 memcpy(bap, bap1, sizeof(bap1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
568 }
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
569 while ((coarse_snr_offset + 1) <= 63 &&
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
570 bit_alloc(s, mask, psd, bap1, frame_bits, coarse_snr_offset + 1, 0) >= 0) {
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
571 coarse_snr_offset++;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
572 memcpy(bap, bap1, sizeof(bap1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
573 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
574
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
575 fine_snr_offset = 0;
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
576 while ((fine_snr_offset + SNR_INC1) <= 15 &&
4704
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
577 bit_alloc(s, mask, psd, bap1, frame_bits,
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
578 coarse_snr_offset, fine_snr_offset + SNR_INC1) >= 0) {
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
579 fine_snr_offset += SNR_INC1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
580 memcpy(bap, bap1, sizeof(bap1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
581 }
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
582 while ((fine_snr_offset + 1) <= 15 &&
4704
0cb02a723a62 utilize multi-stage AC-3 bit allocation. speeds up encoding by 25-30%
jbr
parents: 4686
diff changeset
583 bit_alloc(s, mask, psd, bap1, frame_bits,
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
584 coarse_snr_offset, fine_snr_offset + 1) >= 0) {
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
585 fine_snr_offset++;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
586 memcpy(bap, bap1, sizeof(bap1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
587 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
588
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
589 s->coarse_snr_offset = coarse_snr_offset;
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
590 for(ch=0;ch<s->nb_all_channels;ch++)
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
591 s->fine_snr_offset[ch] = fine_snr_offset;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
592 #if defined(DEBUG_BITALLOC)
986e461dc072 Initial revision
glantau
parents:
diff changeset
593 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
594 int j;
986e461dc072 Initial revision
glantau
parents:
diff changeset
595
986e461dc072 Initial revision
glantau
parents:
diff changeset
596 for(i=0;i<6;i++) {
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
597 for(ch=0;ch<s->nb_all_channels;ch++) {
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
598 printf("Block #%d Ch%d:\n", i, ch);
986e461dc072 Initial revision
glantau
parents:
diff changeset
599 printf("bap=");
986e461dc072 Initial revision
glantau
parents:
diff changeset
600 for(j=0;j<s->nb_coefs[ch];j++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
601 printf("%d ",bap[i][ch][j]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
602 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
603 printf("\n");
986e461dc072 Initial revision
glantau
parents:
diff changeset
604 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
605 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
606 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
607 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
608 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
609 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
610
9513
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
611 static av_cold int set_channel_info(AC3EncodeContext *s, int channels,
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
612 int64_t *channel_layout)
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
613 {
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
614 int ch_layout;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
615
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
616 if (channels < 1 || channels > AC3_MAX_CHANNELS)
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
617 return -1;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
618 if ((uint64_t)*channel_layout > 0x7FF)
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
619 return -1;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
620 ch_layout = *channel_layout;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
621 if (!ch_layout)
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
622 ch_layout = avcodec_guess_channel_layout(channels, CODEC_ID_AC3, NULL);
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
623 if (avcodec_channel_layout_num_channels(ch_layout) != channels)
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
624 return -1;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
625
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
626 s->lfe = !!(ch_layout & CH_LOW_FREQUENCY);
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
627 s->nb_all_channels = channels;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
628 s->nb_channels = channels - s->lfe;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
629 s->lfe_channel = s->lfe ? s->nb_channels : -1;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
630 if (s->lfe)
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
631 ch_layout -= CH_LOW_FREQUENCY;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
632
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
633 switch (ch_layout) {
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
634 case CH_LAYOUT_MONO: s->channel_mode = AC3_CHMODE_MONO; break;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
635 case CH_LAYOUT_STEREO: s->channel_mode = AC3_CHMODE_STEREO; break;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
636 case CH_LAYOUT_SURROUND: s->channel_mode = AC3_CHMODE_3F; break;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
637 case CH_LAYOUT_2_1: s->channel_mode = AC3_CHMODE_2F1R; break;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
638 case CH_LAYOUT_4POINT0: s->channel_mode = AC3_CHMODE_3F1R; break;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
639 case CH_LAYOUT_QUAD:
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
640 case CH_LAYOUT_2_2: s->channel_mode = AC3_CHMODE_2F2R; break;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
641 case CH_LAYOUT_5POINT0:
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
642 case CH_LAYOUT_5POINT0_BACK: s->channel_mode = AC3_CHMODE_3F2R; break;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
643 default:
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
644 return -1;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
645 }
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
646
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
647 s->channel_map = ff_ac3_enc_channel_map[s->channel_mode][s->lfe];
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
648 *channel_layout = ch_layout;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
649 if (s->lfe)
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
650 *channel_layout |= CH_LOW_FREQUENCY;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
651
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
652 return 0;
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
653 }
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
654
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6516
diff changeset
655 static av_cold int AC3_encode_init(AVCodecContext *avctx)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
656 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
657 int freq = avctx->sample_rate;
986e461dc072 Initial revision
glantau
parents:
diff changeset
658 int bitrate = avctx->bit_rate;
986e461dc072 Initial revision
glantau
parents:
diff changeset
659 AC3EncodeContext *s = avctx->priv_data;
782
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
660 int i, j, ch;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
661 float alpha;
6083
77d27412c35d use cutoff frequency to adjust bandwidth in ac3 encoder
jbr
parents: 6082
diff changeset
662 int bw_code;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
663
986e461dc072 Initial revision
glantau
parents:
diff changeset
664 avctx->frame_size = AC3_FRAME_SIZE;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
665
4645
056127e5df89 remove redundancy in AC-3 parser by using common tables from ac3tab.h
jbr
parents: 4643
diff changeset
666 ac3_common_init();
056127e5df89 remove redundancy in AC-3 parser by using common tables from ac3tab.h
jbr
parents: 4643
diff changeset
667
9516
f15a920ce40e ac3enc: log a warning message if the channel layout is not specified at
jbr
parents: 9513
diff changeset
668 if (!avctx->channel_layout) {
f15a920ce40e ac3enc: log a warning message if the channel layout is not specified at
jbr
parents: 9513
diff changeset
669 av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "
f15a920ce40e ac3enc: log a warning message if the channel layout is not specified at
jbr
parents: 9513
diff changeset
670 "encoder will guess the layout, but it "
f15a920ce40e ac3enc: log a warning message if the channel layout is not specified at
jbr
parents: 9513
diff changeset
671 "might be incorrect.\n");
f15a920ce40e ac3enc: log a warning message if the channel layout is not specified at
jbr
parents: 9513
diff changeset
672 }
9513
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
673 if (set_channel_info(s, avctx->channels, &avctx->channel_layout)) {
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
674 av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n");
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
675 return -1;
9513
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
676 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
677
986e461dc072 Initial revision
glantau
parents:
diff changeset
678 /* frequency */
986e461dc072 Initial revision
glantau
parents:
diff changeset
679 for(i=0;i<3;i++) {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
680 for(j=0;j<3;j++)
6002
29635f7c3d9c cosmetics: rename ac3 tables
jbr
parents: 5942
diff changeset
681 if ((ff_ac3_sample_rate_tab[j] >> i) == freq)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
682 goto found;
986e461dc072 Initial revision
glantau
parents:
diff changeset
683 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
684 return -1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
685 found:
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
686 s->sample_rate = freq;
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
687 s->sr_shift = i;
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
688 s->sr_code = j;
6005
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
689 s->bitstream_id = 8 + s->sr_shift;
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
690 s->bitstream_mode = 0; /* complete main audio service */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
691
986e461dc072 Initial revision
glantau
parents:
diff changeset
692 /* bitrate & frame size */
986e461dc072 Initial revision
glantau
parents:
diff changeset
693 for(i=0;i<19;i++) {
6082
f17aad297a38 use bps instead of kbps for bitrate
jbr
parents: 6081
diff changeset
694 if ((ff_ac3_bitrate_tab[i] >> s->sr_shift)*1000 == bitrate)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
695 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
696 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
697 if (i == 19)
986e461dc072 Initial revision
glantau
parents:
diff changeset
698 return -1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
699 s->bit_rate = bitrate;
6005
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
700 s->frame_size_code = i << 1;
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
701 s->frame_size_min = ff_ac3_frame_size_tab[s->frame_size_code][s->sr_code];
3246
219afc0c4a80 AC3: support encoding fractional frame sizes
corey
parents: 3221
diff changeset
702 s->bits_written = 0;
219afc0c4a80 AC3: support encoding fractional frame sizes
corey
parents: 3221
diff changeset
703 s->samples_written = 0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
704 s->frame_size = s->frame_size_min;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
705
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
706 /* bit allocation init */
6083
77d27412c35d use cutoff frequency to adjust bandwidth in ac3 encoder
jbr
parents: 6082
diff changeset
707 if(avctx->cutoff) {
77d27412c35d use cutoff frequency to adjust bandwidth in ac3 encoder
jbr
parents: 6082
diff changeset
708 /* calculate bandwidth based on user-specified cutoff frequency */
77d27412c35d use cutoff frequency to adjust bandwidth in ac3 encoder
jbr
parents: 6082
diff changeset
709 int cutoff = av_clip(avctx->cutoff, 1, s->sample_rate >> 1);
77d27412c35d use cutoff frequency to adjust bandwidth in ac3 encoder
jbr
parents: 6082
diff changeset
710 int fbw_coeffs = cutoff * 512 / s->sample_rate;
77d27412c35d use cutoff frequency to adjust bandwidth in ac3 encoder
jbr
parents: 6082
diff changeset
711 bw_code = av_clip((fbw_coeffs - 73) / 3, 0, 60);
77d27412c35d use cutoff frequency to adjust bandwidth in ac3 encoder
jbr
parents: 6082
diff changeset
712 } else {
77d27412c35d use cutoff frequency to adjust bandwidth in ac3 encoder
jbr
parents: 6082
diff changeset
713 /* use default bandwidth setting */
77d27412c35d use cutoff frequency to adjust bandwidth in ac3 encoder
jbr
parents: 6082
diff changeset
714 /* XXX: should compute the bandwidth according to the frame
6516
dbb902bb2347 two more typos spotted by Mike
diego
parents: 6515
diff changeset
715 size, so that we avoid annoying high frequency artifacts */
6083
77d27412c35d use cutoff frequency to adjust bandwidth in ac3 encoder
jbr
parents: 6082
diff changeset
716 bw_code = 50;
77d27412c35d use cutoff frequency to adjust bandwidth in ac3 encoder
jbr
parents: 6082
diff changeset
717 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
718 for(ch=0;ch<s->nb_channels;ch++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
719 /* bandwidth for each channel */
6083
77d27412c35d use cutoff frequency to adjust bandwidth in ac3 encoder
jbr
parents: 6082
diff changeset
720 s->chbwcod[ch] = bw_code;
77d27412c35d use cutoff frequency to adjust bandwidth in ac3 encoder
jbr
parents: 6082
diff changeset
721 s->nb_coefs[ch] = bw_code * 3 + 73;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
722 }
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
723 if (s->lfe) {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
724 s->nb_coefs[s->lfe_channel] = 7; /* fixed */
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
725 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
726 /* initial snr offset */
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
727 s->coarse_snr_offset = 40;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
728
986e461dc072 Initial revision
glantau
parents:
diff changeset
729 /* mdct init */
986e461dc072 Initial revision
glantau
parents:
diff changeset
730 fft_init(MDCT_NBITS - 2);
986e461dc072 Initial revision
glantau
parents:
diff changeset
731 for(i=0;i<N/4;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
732 alpha = 2 * M_PI * (i + 1.0 / 8.0) / (float)N;
986e461dc072 Initial revision
glantau
parents:
diff changeset
733 xcos1[i] = fix15(-cos(alpha));
986e461dc072 Initial revision
glantau
parents:
diff changeset
734 xsin1[i] = fix15(-sin(alpha));
986e461dc072 Initial revision
glantau
parents:
diff changeset
735 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
736
925
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 782
diff changeset
737 avctx->coded_frame= avcodec_alloc_frame();
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 782
diff changeset
738 avctx->coded_frame->key_frame= 1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
739
986e461dc072 Initial revision
glantau
parents:
diff changeset
740 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
741 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
742
7470
1a93d3bbe3ee cosmetics: make all references to AC-3 capitalized and hyphenated
jbr
parents: 7451
diff changeset
743 /* output the AC-3 frame header */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
744 static void output_frame_header(AC3EncodeContext *s, unsigned char *frame)
986e461dc072 Initial revision
glantau
parents:
diff changeset
745 {
1522
79dddc5cd990 removed the obsolete and unused parameters of init_put_bits
alex
parents: 1408
diff changeset
746 init_put_bits(&s->pb, frame, AC3_MAX_CODED_FRAME_SIZE);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
747
986e461dc072 Initial revision
glantau
parents:
diff changeset
748 put_bits(&s->pb, 16, 0x0b77); /* frame header */
986e461dc072 Initial revision
glantau
parents:
diff changeset
749 put_bits(&s->pb, 16, 0); /* crc1: will be filled later */
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
750 put_bits(&s->pb, 2, s->sr_code);
6005
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
751 put_bits(&s->pb, 6, s->frame_size_code + (s->frame_size - s->frame_size_min));
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
752 put_bits(&s->pb, 5, s->bitstream_id);
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
753 put_bits(&s->pb, 3, s->bitstream_mode);
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
754 put_bits(&s->pb, 3, s->channel_mode);
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
755 if ((s->channel_mode & 0x01) && s->channel_mode != AC3_CHMODE_MONO)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
756 put_bits(&s->pb, 2, 1); /* XXX -4.5 dB */
6005
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
757 if (s->channel_mode & 0x04)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
758 put_bits(&s->pb, 2, 1); /* XXX -6 dB */
6005
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
759 if (s->channel_mode == AC3_CHMODE_STEREO)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
760 put_bits(&s->pb, 2, 0); /* surround not indicated */
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
761 put_bits(&s->pb, 1, s->lfe); /* LFE */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
762 put_bits(&s->pb, 5, 31); /* dialog norm: -31 db */
986e461dc072 Initial revision
glantau
parents:
diff changeset
763 put_bits(&s->pb, 1, 0); /* no compression control word */
986e461dc072 Initial revision
glantau
parents:
diff changeset
764 put_bits(&s->pb, 1, 0); /* no lang code */
986e461dc072 Initial revision
glantau
parents:
diff changeset
765 put_bits(&s->pb, 1, 0); /* no audio production info */
986e461dc072 Initial revision
glantau
parents:
diff changeset
766 put_bits(&s->pb, 1, 0); /* no copyright */
986e461dc072 Initial revision
glantau
parents:
diff changeset
767 put_bits(&s->pb, 1, 1); /* original bitstream */
986e461dc072 Initial revision
glantau
parents:
diff changeset
768 put_bits(&s->pb, 1, 0); /* no time code 1 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
769 put_bits(&s->pb, 1, 0); /* no time code 2 */
6080
0f1a318ecb22 fix typo
jbr
parents: 6005
diff changeset
770 put_bits(&s->pb, 1, 0); /* no additional bit stream info */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
771 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
772
986e461dc072 Initial revision
glantau
parents:
diff changeset
773 /* symetric quantization on 'levels' levels */
986e461dc072 Initial revision
glantau
parents:
diff changeset
774 static inline int sym_quant(int c, int e, int levels)
986e461dc072 Initial revision
glantau
parents:
diff changeset
775 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
776 int v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
777
986e461dc072 Initial revision
glantau
parents:
diff changeset
778 if (c >= 0) {
87
6f0e167504e8 fixed symetric quantization (better quality!)
glantau
parents: 65
diff changeset
779 v = (levels * (c << e)) >> 24;
6f0e167504e8 fixed symetric quantization (better quality!)
glantau
parents: 65
diff changeset
780 v = (v + 1) >> 1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
781 v = (levels >> 1) + v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
782 } else {
87
6f0e167504e8 fixed symetric quantization (better quality!)
glantau
parents: 65
diff changeset
783 v = (levels * ((-c) << e)) >> 24;
6f0e167504e8 fixed symetric quantization (better quality!)
glantau
parents: 65
diff changeset
784 v = (v + 1) >> 1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
785 v = (levels >> 1) - v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
786 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
787 assert (v >= 0 && v < levels);
986e461dc072 Initial revision
glantau
parents:
diff changeset
788 return v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
789 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
790
986e461dc072 Initial revision
glantau
parents:
diff changeset
791 /* asymetric quantization on 2^qbits levels */
986e461dc072 Initial revision
glantau
parents:
diff changeset
792 static inline int asym_quant(int c, int e, int qbits)
986e461dc072 Initial revision
glantau
parents:
diff changeset
793 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
794 int lshift, m, v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
795
986e461dc072 Initial revision
glantau
parents:
diff changeset
796 lshift = e + qbits - 24;
986e461dc072 Initial revision
glantau
parents:
diff changeset
797 if (lshift >= 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
798 v = c << lshift;
986e461dc072 Initial revision
glantau
parents:
diff changeset
799 else
986e461dc072 Initial revision
glantau
parents:
diff changeset
800 v = c >> (-lshift);
986e461dc072 Initial revision
glantau
parents:
diff changeset
801 /* rounding */
986e461dc072 Initial revision
glantau
parents:
diff changeset
802 v = (v + 1) >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
803 m = (1 << (qbits-1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
804 if (v >= m)
986e461dc072 Initial revision
glantau
parents:
diff changeset
805 v = m - 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
806 assert(v >= -m);
986e461dc072 Initial revision
glantau
parents:
diff changeset
807 return v & ((1 << qbits)-1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
808 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
809
7470
1a93d3bbe3ee cosmetics: make all references to AC-3 capitalized and hyphenated
jbr
parents: 7451
diff changeset
810 /* Output one audio block. There are NB_BLOCKS audio blocks in one AC-3
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
811 frame */
986e461dc072 Initial revision
glantau
parents:
diff changeset
812 static void output_audio_block(AC3EncodeContext *s,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
813 uint8_t exp_strategy[AC3_MAX_CHANNELS],
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
814 uint8_t encoded_exp[AC3_MAX_CHANNELS][N/2],
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
815 uint8_t bap[AC3_MAX_CHANNELS][N/2],
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
816 int32_t mdct_coefs[AC3_MAX_CHANNELS][N/2],
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
817 int8_t global_exp[AC3_MAX_CHANNELS],
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
818 int block_num)
986e461dc072 Initial revision
glantau
parents:
diff changeset
819 {
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1106
diff changeset
820 int ch, nb_groups, group_size, i, baie, rbnd;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
821 uint8_t *p;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
822 uint16_t qmant[AC3_MAX_CHANNELS][N/2];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
823 int exp0, exp1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
824 int mant1_cnt, mant2_cnt, mant4_cnt;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
825 uint16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
826 int delta0, delta1, delta2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
827
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
828 for(ch=0;ch<s->nb_channels;ch++)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
829 put_bits(&s->pb, 1, 0); /* 512 point MDCT */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
830 for(ch=0;ch<s->nb_channels;ch++)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
831 put_bits(&s->pb, 1, 1); /* no dither */
986e461dc072 Initial revision
glantau
parents:
diff changeset
832 put_bits(&s->pb, 1, 0); /* no dynamic range */
986e461dc072 Initial revision
glantau
parents:
diff changeset
833 if (block_num == 0) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
834 /* for block 0, even if no coupling, we must say it. This is a
986e461dc072 Initial revision
glantau
parents:
diff changeset
835 waste of bit :-) */
986e461dc072 Initial revision
glantau
parents:
diff changeset
836 put_bits(&s->pb, 1, 1); /* coupling strategy present */
986e461dc072 Initial revision
glantau
parents:
diff changeset
837 put_bits(&s->pb, 1, 0); /* no coupling strategy */
986e461dc072 Initial revision
glantau
parents:
diff changeset
838 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
839 put_bits(&s->pb, 1, 0); /* no new coupling strategy */
986e461dc072 Initial revision
glantau
parents:
diff changeset
840 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
841
6005
7d9dddd54817 cosmetics: rename common ac3 variables
jbr
parents: 6003
diff changeset
842 if (s->channel_mode == AC3_CHMODE_STEREO)
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1106
diff changeset
843 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
844 if(block_num==0)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
845 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
846 /* first block must define rematrixing (rematstr) */
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
847 put_bits(&s->pb, 1, 1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
848
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
849 /* dummy rematrixing rematflg(1:4)=0 */
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
850 for (rbnd=0;rbnd<4;rbnd++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
851 put_bits(&s->pb, 1, 0);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
852 }
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
853 else
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
854 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
855 /* no matrixing (but should be used in the future) */
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
856 put_bits(&s->pb, 1, 0);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
857 }
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1106
diff changeset
858 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
859
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
860 #if defined(DEBUG)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
861 {
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1106
diff changeset
862 static int count = 0;
1602
fdb8244da1e5 av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1598
diff changeset
863 av_log(NULL, AV_LOG_DEBUG, "Block #%d (%d)\n", block_num, count++);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
864 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
865 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
866 /* exponent strategy */
986e461dc072 Initial revision
glantau
parents:
diff changeset
867 for(ch=0;ch<s->nb_channels;ch++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
868 put_bits(&s->pb, 2, exp_strategy[ch]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
869 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
870
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
871 if (s->lfe) {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
872 put_bits(&s->pb, 1, exp_strategy[s->lfe_channel]);
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
873 }
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
874
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
875 for(ch=0;ch<s->nb_channels;ch++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
876 if (exp_strategy[ch] != EXP_REUSE)
986e461dc072 Initial revision
glantau
parents:
diff changeset
877 put_bits(&s->pb, 6, s->chbwcod[ch]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
878 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
879
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
880 /* exponents */
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
881 for (ch = 0; ch < s->nb_all_channels; ch++) {
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
882 switch(exp_strategy[ch]) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
883 case EXP_REUSE:
986e461dc072 Initial revision
glantau
parents:
diff changeset
884 continue;
986e461dc072 Initial revision
glantau
parents:
diff changeset
885 case EXP_D15:
986e461dc072 Initial revision
glantau
parents:
diff changeset
886 group_size = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
887 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
888 case EXP_D25:
986e461dc072 Initial revision
glantau
parents:
diff changeset
889 group_size = 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
890 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
891 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
892 case EXP_D45:
986e461dc072 Initial revision
glantau
parents:
diff changeset
893 group_size = 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
894 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
895 }
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
896 nb_groups = (s->nb_coefs[ch] + (group_size * 3) - 4) / (3 * group_size);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
897 p = encoded_exp[ch];
986e461dc072 Initial revision
glantau
parents:
diff changeset
898
986e461dc072 Initial revision
glantau
parents:
diff changeset
899 /* first exponent */
986e461dc072 Initial revision
glantau
parents:
diff changeset
900 exp1 = *p++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
901 put_bits(&s->pb, 4, exp1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
902
986e461dc072 Initial revision
glantau
parents:
diff changeset
903 /* next ones are delta encoded */
986e461dc072 Initial revision
glantau
parents:
diff changeset
904 for(i=0;i<nb_groups;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
905 /* merge three delta in one code */
986e461dc072 Initial revision
glantau
parents:
diff changeset
906 exp0 = exp1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
907 exp1 = p[0];
986e461dc072 Initial revision
glantau
parents:
diff changeset
908 p += group_size;
986e461dc072 Initial revision
glantau
parents:
diff changeset
909 delta0 = exp1 - exp0 + 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
910
986e461dc072 Initial revision
glantau
parents:
diff changeset
911 exp0 = exp1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
912 exp1 = p[0];
986e461dc072 Initial revision
glantau
parents:
diff changeset
913 p += group_size;
986e461dc072 Initial revision
glantau
parents:
diff changeset
914 delta1 = exp1 - exp0 + 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
915
986e461dc072 Initial revision
glantau
parents:
diff changeset
916 exp0 = exp1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
917 exp1 = p[0];
986e461dc072 Initial revision
glantau
parents:
diff changeset
918 p += group_size;
986e461dc072 Initial revision
glantau
parents:
diff changeset
919 delta2 = exp1 - exp0 + 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
920
986e461dc072 Initial revision
glantau
parents:
diff changeset
921 put_bits(&s->pb, 7, ((delta0 * 5 + delta1) * 5) + delta2);
986e461dc072 Initial revision
glantau
parents:
diff changeset
922 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
923
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
924 if (ch != s->lfe_channel)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
925 put_bits(&s->pb, 2, 0); /* no gain range info */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
926 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
927
986e461dc072 Initial revision
glantau
parents:
diff changeset
928 /* bit allocation info */
986e461dc072 Initial revision
glantau
parents:
diff changeset
929 baie = (block_num == 0);
986e461dc072 Initial revision
glantau
parents:
diff changeset
930 put_bits(&s->pb, 1, baie);
986e461dc072 Initial revision
glantau
parents:
diff changeset
931 if (baie) {
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
932 put_bits(&s->pb, 2, s->slow_decay_code);
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
933 put_bits(&s->pb, 2, s->fast_decay_code);
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
934 put_bits(&s->pb, 2, s->slow_gain_code);
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
935 put_bits(&s->pb, 2, s->db_per_bit_code);
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
936 put_bits(&s->pb, 3, s->floor_code);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
937 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
938
986e461dc072 Initial revision
glantau
parents:
diff changeset
939 /* snr offset */
986e461dc072 Initial revision
glantau
parents:
diff changeset
940 put_bits(&s->pb, 1, baie); /* always present with bai */
986e461dc072 Initial revision
glantau
parents:
diff changeset
941 if (baie) {
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
942 put_bits(&s->pb, 6, s->coarse_snr_offset);
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
943 for(ch=0;ch<s->nb_all_channels;ch++) {
6003
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
944 put_bits(&s->pb, 4, s->fine_snr_offset[ch]);
608c8e9ac412 cosmetics: rename ac3 bit allocation variables
jbr
parents: 6002
diff changeset
945 put_bits(&s->pb, 3, s->fast_gain_code[ch]);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
946 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
947 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
948
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
949 put_bits(&s->pb, 1, 0); /* no delta bit allocation */
986e461dc072 Initial revision
glantau
parents:
diff changeset
950 put_bits(&s->pb, 1, 0); /* no data to skip */
986e461dc072 Initial revision
glantau
parents:
diff changeset
951
986e461dc072 Initial revision
glantau
parents:
diff changeset
952 /* mantissa encoding : we use two passes to handle the grouping. A
986e461dc072 Initial revision
glantau
parents:
diff changeset
953 one pass method may be faster, but it would necessitate to
986e461dc072 Initial revision
glantau
parents:
diff changeset
954 modify the output stream. */
986e461dc072 Initial revision
glantau
parents:
diff changeset
955
986e461dc072 Initial revision
glantau
parents:
diff changeset
956 /* first pass: quantize */
986e461dc072 Initial revision
glantau
parents:
diff changeset
957 mant1_cnt = mant2_cnt = mant4_cnt = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
958 qmant1_ptr = qmant2_ptr = qmant4_ptr = NULL;
986e461dc072 Initial revision
glantau
parents:
diff changeset
959
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
960 for (ch = 0; ch < s->nb_all_channels; ch++) {
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
961 int b, c, e, v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
962
986e461dc072 Initial revision
glantau
parents:
diff changeset
963 for(i=0;i<s->nb_coefs[ch];i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
964 c = mdct_coefs[ch][i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
965 e = encoded_exp[ch][i] - global_exp[ch];
986e461dc072 Initial revision
glantau
parents:
diff changeset
966 b = bap[ch][i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
967 switch(b) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
968 case 0:
986e461dc072 Initial revision
glantau
parents:
diff changeset
969 v = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
970 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
971 case 1:
986e461dc072 Initial revision
glantau
parents:
diff changeset
972 v = sym_quant(c, e, 3);
986e461dc072 Initial revision
glantau
parents:
diff changeset
973 switch(mant1_cnt) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
974 case 0:
986e461dc072 Initial revision
glantau
parents:
diff changeset
975 qmant1_ptr = &qmant[ch][i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
976 v = 9 * v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
977 mant1_cnt = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
978 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
979 case 1:
986e461dc072 Initial revision
glantau
parents:
diff changeset
980 *qmant1_ptr += 3 * v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
981 mant1_cnt = 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
982 v = 128;
986e461dc072 Initial revision
glantau
parents:
diff changeset
983 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
984 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
985 *qmant1_ptr += v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
986 mant1_cnt = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
987 v = 128;
986e461dc072 Initial revision
glantau
parents:
diff changeset
988 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
989 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
990 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
991 case 2:
986e461dc072 Initial revision
glantau
parents:
diff changeset
992 v = sym_quant(c, e, 5);
986e461dc072 Initial revision
glantau
parents:
diff changeset
993 switch(mant2_cnt) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
994 case 0:
986e461dc072 Initial revision
glantau
parents:
diff changeset
995 qmant2_ptr = &qmant[ch][i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
996 v = 25 * v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
997 mant2_cnt = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
998 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
999 case 1:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1000 *qmant2_ptr += 5 * v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1001 mant2_cnt = 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1002 v = 128;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1003 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1004 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1005 *qmant2_ptr += v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1006 mant2_cnt = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1007 v = 128;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1008 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1009 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1010 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1011 case 3:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1012 v = sym_quant(c, e, 7);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1013 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1014 case 4:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1015 v = sym_quant(c, e, 11);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1016 switch(mant4_cnt) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1017 case 0:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1018 qmant4_ptr = &qmant[ch][i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1019 v = 11 * v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1020 mant4_cnt = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1021 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1022 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1023 *qmant4_ptr += v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1024 mant4_cnt = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1025 v = 128;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1026 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1027 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1028 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1029 case 5:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1030 v = sym_quant(c, e, 15);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1031 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1032 case 14:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1033 v = asym_quant(c, e, 14);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1034 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1035 case 15:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1036 v = asym_quant(c, e, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1037 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1038 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1039 v = asym_quant(c, e, b - 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1040 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1041 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1042 qmant[ch][i] = v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1043 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1044 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1045
986e461dc072 Initial revision
glantau
parents:
diff changeset
1046 /* second pass : output the values */
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
1047 for (ch = 0; ch < s->nb_all_channels; ch++) {
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1048 int b, q;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1049
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1050 for(i=0;i<s->nb_coefs[ch];i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1051 q = qmant[ch][i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1052 b = bap[ch][i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1053 switch(b) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1054 case 0:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1055 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1056 case 1:
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1057 if (q != 128)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1058 put_bits(&s->pb, 5, q);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1059 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1060 case 2:
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1061 if (q != 128)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1062 put_bits(&s->pb, 7, q);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1063 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1064 case 3:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1065 put_bits(&s->pb, 3, q);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1066 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1067 case 4:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1068 if (q != 128)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1069 put_bits(&s->pb, 7, q);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1070 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1071 case 14:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1072 put_bits(&s->pb, 14, q);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1073 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1074 case 15:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1075 put_bits(&s->pb, 16, q);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1076 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1077 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1078 put_bits(&s->pb, b - 1, q);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1079 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1080 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1081 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1082 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1083 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1084
986e461dc072 Initial revision
glantau
parents:
diff changeset
1085 #define CRC16_POLY ((1 << 0) | (1 << 2) | (1 << 15) | (1 << 16))
986e461dc072 Initial revision
glantau
parents:
diff changeset
1086
986e461dc072 Initial revision
glantau
parents:
diff changeset
1087 static unsigned int mul_poly(unsigned int a, unsigned int b, unsigned int poly)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1088 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1089 unsigned int c;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1090
986e461dc072 Initial revision
glantau
parents:
diff changeset
1091 c = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1092 while (a) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1093 if (a & 1)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1094 c ^= b;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1095 a = a >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1096 b = b << 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1097 if (b & (1 << 16))
986e461dc072 Initial revision
glantau
parents:
diff changeset
1098 b ^= poly;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1099 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1100 return c;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1101 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1102
986e461dc072 Initial revision
glantau
parents:
diff changeset
1103 static unsigned int pow_poly(unsigned int a, unsigned int n, unsigned int poly)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1104 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1105 unsigned int r;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1106 r = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1107 while (n) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1108 if (n & 1)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1109 r = mul_poly(r, a, poly);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1110 a = mul_poly(a, a, poly);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1111 n >>= 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1112 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1113 return r;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1114 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1115
986e461dc072 Initial revision
glantau
parents:
diff changeset
1116
986e461dc072 Initial revision
glantau
parents:
diff changeset
1117 /* compute log2(max(abs(tab[]))) */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1118 static int log2_tab(int16_t *tab, int n)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1119 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1120 int i, v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1121
986e461dc072 Initial revision
glantau
parents:
diff changeset
1122 v = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1123 for(i=0;i<n;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1124 v |= abs(tab[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1125 }
65
bc27d8c5dc2e renamed log2 to av_log2
glantau
parents: 64
diff changeset
1126 return av_log2(v);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1127 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1128
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1129 static void lshift_tab(int16_t *tab, int n, int lshift)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1130 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1131 int i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1132
986e461dc072 Initial revision
glantau
parents:
diff changeset
1133 if (lshift > 0) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1134 for(i=0;i<n;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1135 tab[i] <<= lshift;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1136 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1137 } else if (lshift < 0) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1138 lshift = -lshift;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1139 for(i=0;i<n;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1140 tab[i] >>= lshift;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1141 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1142 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1143 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1144
986e461dc072 Initial revision
glantau
parents:
diff changeset
1145 /* fill the end of the frame and compute the two crcs */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1146 static int output_frame_end(AC3EncodeContext *s)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1147 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1148 int frame_size, frame_size_58, n, crc1, crc2, crc_inv;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1149 uint8_t *frame;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1150
986e461dc072 Initial revision
glantau
parents:
diff changeset
1151 frame_size = s->frame_size; /* frame size in words */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1152 /* align to 8 bits */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1153 flush_put_bits(&s->pb);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1154 /* add zero bytes to reach the frame size */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1155 frame = s->pb.buf;
9431
932543edc1d2 Rename pbBufPtr() to put_bits_ptr().
stefano
parents: 9428
diff changeset
1156 n = 2 * s->frame_size - (put_bits_ptr(&s->pb) - frame) - 2;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1157 assert(n >= 0);
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1106
diff changeset
1158 if(n>0)
9431
932543edc1d2 Rename pbBufPtr() to put_bits_ptr().
stefano
parents: 9428
diff changeset
1159 memset(put_bits_ptr(&s->pb), 0, n);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1160
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1161 /* Now we must compute both crcs : this is not so easy for crc1
986e461dc072 Initial revision
glantau
parents:
diff changeset
1162 because it is at the beginning of the data... */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1163 frame_size_58 = (frame_size >> 1) + (frame_size >> 3);
6108
75804d49f33b improve CRC API
aurel
parents: 6083
diff changeset
1164 crc1 = bswap_16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
75804d49f33b improve CRC API
aurel
parents: 6083
diff changeset
1165 frame + 4, 2 * frame_size_58 - 4));
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1166 /* XXX: could precompute crc_inv */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1167 crc_inv = pow_poly((CRC16_POLY >> 1), (16 * frame_size_58) - 16, CRC16_POLY);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1168 crc1 = mul_poly(crc_inv, crc1, CRC16_POLY);
5089
bff60ecc02f9 Use AV_xx throughout libavcodec
ramiro
parents: 4706
diff changeset
1169 AV_WB16(frame+2,crc1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1170
6108
75804d49f33b improve CRC API
aurel
parents: 6083
diff changeset
1171 crc2 = bswap_16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
75804d49f33b improve CRC API
aurel
parents: 6083
diff changeset
1172 frame + 2 * frame_size_58,
75804d49f33b improve CRC API
aurel
parents: 6083
diff changeset
1173 (frame_size - frame_size_58) * 2 - 2));
5089
bff60ecc02f9 Use AV_xx throughout libavcodec
ramiro
parents: 4706
diff changeset
1174 AV_WB16(frame+2*frame_size-2,crc2);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1175
986e461dc072 Initial revision
glantau
parents:
diff changeset
1176 // printf("n=%d frame_size=%d\n", n, frame_size);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1177 return frame_size * 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1178 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1179
782
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
1180 static int AC3_encode_frame(AVCodecContext *avctx,
dd7d5748d064 preparing integration of new AC3 decoder
bellard
parents: 429
diff changeset
1181 unsigned char *frame, int buf_size, void *data)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1182 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1183 AC3EncodeContext *s = avctx->priv_data;
2367
c353719836af fix some type mismatches patch by (Jeff Muizelaar <muizelaar rogers com>)
michael
parents: 2157
diff changeset
1184 int16_t *samples = data;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1185 int i, j, k, v, ch;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1186 int16_t input_samples[N];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1187 int32_t mdct_coef[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1188 uint8_t exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1189 uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNELS];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1190 uint8_t encoded_exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1191 uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1192 int8_t exp_samples[NB_BLOCKS][AC3_MAX_CHANNELS];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1193 int frame_bits;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1194
986e461dc072 Initial revision
glantau
parents:
diff changeset
1195 frame_bits = 0;
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
1196 for(ch=0;ch<s->nb_all_channels;ch++) {
9452
42803399ba8a ac3enc: reorder input channels to AC-3 channel order
jbr
parents: 9431
diff changeset
1197 int ich = s->channel_map[ch];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1198 /* fixed mdct to the six sub blocks & exponent computation */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1199 for(i=0;i<NB_BLOCKS;i++) {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1200 int16_t *sptr;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1201 int sinc;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1202
986e461dc072 Initial revision
glantau
parents:
diff changeset
1203 /* compute input samples */
9452
42803399ba8a ac3enc: reorder input channels to AC-3 channel order
jbr
parents: 9431
diff changeset
1204 memcpy(input_samples, s->last_samples[ich], N/2 * sizeof(int16_t));
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
1205 sinc = s->nb_all_channels;
9452
42803399ba8a ac3enc: reorder input channels to AC-3 channel order
jbr
parents: 9431
diff changeset
1206 sptr = samples + (sinc * (N/2) * i) + ich;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1207 for(j=0;j<N/2;j++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1208 v = *sptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1209 input_samples[j + N/2] = v;
9452
42803399ba8a ac3enc: reorder input channels to AC-3 channel order
jbr
parents: 9431
diff changeset
1210 s->last_samples[ich][j] = v;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1211 sptr += sinc;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1212 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1213
986e461dc072 Initial revision
glantau
parents:
diff changeset
1214 /* apply the MDCT window */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1215 for(j=0;j<N/2;j++) {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1216 input_samples[j] = MUL16(input_samples[j],
4643
1e175640dad3 Remove common code from AC-3 encoder and utilize ac3.c.
jbr
parents: 4641
diff changeset
1217 ff_ac3_window[j]) >> 15;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1218 input_samples[N-j-1] = MUL16(input_samples[N-j-1],
4643
1e175640dad3 Remove common code from AC-3 encoder and utilize ac3.c.
jbr
parents: 4641
diff changeset
1219 ff_ac3_window[j]) >> 15;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1220 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1221
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1222 /* Normalize the samples to use the maximum available
986e461dc072 Initial revision
glantau
parents:
diff changeset
1223 precision */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1224 v = 14 - log2_tab(input_samples, N);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1225 if (v < 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1226 v = 0;
4686
3a891d2379ce AC-3 encoded volume is too high. Revert revision 7160:
jbr
parents: 4645
diff changeset
1227 exp_samples[i][ch] = v - 9;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1228 lshift_tab(input_samples, N, v);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1229
986e461dc072 Initial revision
glantau
parents:
diff changeset
1230 /* do the MDCT */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1231 mdct512(mdct_coef[i][ch], input_samples);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1232
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1233 /* compute "exponents". We take into account the
986e461dc072 Initial revision
glantau
parents:
diff changeset
1234 normalization there */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1235 for(j=0;j<N/2;j++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1236 int e;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1237 v = abs(mdct_coef[i][ch][j]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1238 if (v == 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1239 e = 24;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1240 else {
65
bc27d8c5dc2e renamed log2 to av_log2
glantau
parents: 64
diff changeset
1241 e = 23 - av_log2(v) + exp_samples[i][ch];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1242 if (e >= 24) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1243 e = 24;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1244 mdct_coef[i][ch][j] = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1245 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1246 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1247 exp[i][ch][j] = e;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1248 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1249 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1250
314
289eb941b8ba * encoding of AC3 with more than 2 channels
kabi
parents: 234
diff changeset
1251 compute_exp_strategy(exp_strategy, exp, ch, ch == s->lfe_channel);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1252
986e461dc072 Initial revision
glantau
parents:
diff changeset
1253 /* compute the exponents as the decoder will see them. The
986e461dc072 Initial revision
glantau
parents:
diff changeset
1254 EXP_REUSE case must be handled carefully : we select the
986e461dc072 Initial revision
glantau
parents:
diff changeset
1255 min of the exponents */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1256 i = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1257 while (i < NB_BLOCKS) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1258 j = i + 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1259 while (j < NB_BLOCKS && exp_strategy[j][ch] == EXP_REUSE) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1260 exponent_min(exp[i][ch], exp[j][ch], s->nb_coefs[ch]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1261 j++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1262 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1263 frame_bits += encode_exp(encoded_exp[i][ch],
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1264 exp[i][ch], s->nb_coefs[ch],
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1265 exp_strategy[i][ch]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1266 /* copy encoded exponents for reuse case */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1267 for(k=i+1;k<j;k++) {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1268 memcpy(encoded_exp[k][ch], encoded_exp[i][ch],
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1269 s->nb_coefs[ch] * sizeof(uint8_t));
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1270 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1271 i = j;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1272 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1273 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1274
3246
219afc0c4a80 AC3: support encoding fractional frame sizes
corey
parents: 3221
diff changeset
1275 /* adjust for fractional frame sizes */
6082
f17aad297a38 use bps instead of kbps for bitrate
jbr
parents: 6081
diff changeset
1276 while(s->bits_written >= s->bit_rate && s->samples_written >= s->sample_rate) {
f17aad297a38 use bps instead of kbps for bitrate
jbr
parents: 6081
diff changeset
1277 s->bits_written -= s->bit_rate;
3246
219afc0c4a80 AC3: support encoding fractional frame sizes
corey
parents: 3221
diff changeset
1278 s->samples_written -= s->sample_rate;
219afc0c4a80 AC3: support encoding fractional frame sizes
corey
parents: 3221
diff changeset
1279 }
6082
f17aad297a38 use bps instead of kbps for bitrate
jbr
parents: 6081
diff changeset
1280 s->frame_size = s->frame_size_min + (s->bits_written * s->sample_rate < s->samples_written * s->bit_rate);
3246
219afc0c4a80 AC3: support encoding fractional frame sizes
corey
parents: 3221
diff changeset
1281 s->bits_written += s->frame_size * 16;
219afc0c4a80 AC3: support encoding fractional frame sizes
corey
parents: 3221
diff changeset
1282 s->samples_written += AC3_FRAME_SIZE;
219afc0c4a80 AC3: support encoding fractional frame sizes
corey
parents: 3221
diff changeset
1283
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1284 compute_bit_allocation(s, bap, encoded_exp, exp_strategy, frame_bits);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1285 /* everything is known... let's output the frame */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1286 output_frame_header(s, frame);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1287
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1288 for(i=0;i<NB_BLOCKS;i++) {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1289 output_audio_block(s, exp_strategy[i], encoded_exp[i],
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1290 bap[i], mdct_coef[i], exp_samples[i], i);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1291 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1292 return output_frame_end(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1293 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1294
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6516
diff changeset
1295 static av_cold int AC3_encode_close(AVCodecContext *avctx)
925
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 782
diff changeset
1296 {
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 782
diff changeset
1297 av_freep(&avctx->coded_frame);
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (M«©ns Rullg«©rd))
michaelni
parents: 925
diff changeset
1298 return 0;
925
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 782
diff changeset
1299 }
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 782
diff changeset
1300
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1301 #if 0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1302 /*************************************************************************/
986e461dc072 Initial revision
glantau
parents:
diff changeset
1303 /* TEST */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1304
5380
389366aa3458 Fix the self tests which are contained in some codecs and are using random().
takis
parents: 5331
diff changeset
1305 #undef random
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1306 #define FN (N/4)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1307
986e461dc072 Initial revision
glantau
parents:
diff changeset
1308 void fft_test(void)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1309 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1310 IComplex in[FN], in1[FN];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1311 int k, n, i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1312 float sum_re, sum_im, a;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1313
986e461dc072 Initial revision
glantau
parents:
diff changeset
1314 /* FFT test */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1315
986e461dc072 Initial revision
glantau
parents:
diff changeset
1316 for(i=0;i<FN;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1317 in[i].re = random() % 65535 - 32767;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1318 in[i].im = random() % 65535 - 32767;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1319 in1[i] = in[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1320 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1321 fft(in, 7);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1322
986e461dc072 Initial revision
glantau
parents:
diff changeset
1323 /* do it by hand */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1324 for(k=0;k<FN;k++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1325 sum_re = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1326 sum_im = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1327 for(n=0;n<FN;n++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1328 a = -2 * M_PI * (n * k) / FN;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1329 sum_re += in1[n].re * cos(a) - in1[n].im * sin(a);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1330 sum_im += in1[n].re * sin(a) + in1[n].im * cos(a);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1331 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1332 printf("%3d: %6d,%6d %6.0f,%6.0f\n",
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1333 k, in[k].re, in[k].im, sum_re / FN, sum_im / FN);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1334 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1335 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1336
986e461dc072 Initial revision
glantau
parents:
diff changeset
1337 void mdct_test(void)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1338 {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1339 int16_t input[N];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1340 int32_t output[N/2];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1341 float input1[N];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1342 float output1[N/2];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1343 float s, a, err, e, emax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1344 int i, k, n;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1345
986e461dc072 Initial revision
glantau
parents:
diff changeset
1346 for(i=0;i<N;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1347 input[i] = (random() % 65535 - 32767) * 9 / 10;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1348 input1[i] = input[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1349 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1350
986e461dc072 Initial revision
glantau
parents:
diff changeset
1351 mdct512(output, input);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1352
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1353 /* do it by hand */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1354 for(k=0;k<N/2;k++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1355 s = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1356 for(n=0;n<N;n++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1357 a = (2*M_PI*(2*n+1+N/2)*(2*k+1) / (4 * N));
986e461dc072 Initial revision
glantau
parents:
diff changeset
1358 s += input1[n] * cos(a);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1359 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1360 output1[k] = -2 * s / N;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1361 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1362
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1363 err = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1364 emax = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1365 for(i=0;i<N/2;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1366 printf("%3d: %7d %7.0f\n", i, output[i], output1[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1367 e = output[i] - output1[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1368 if (e > emax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1369 emax = e;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1370 err += e * e;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1371 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1372 printf("err2=%f emax=%f\n", err / (N/2), emax);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1373 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1374
986e461dc072 Initial revision
glantau
parents:
diff changeset
1375 void test_ac3(void)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1376 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1377 AC3EncodeContext ctx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1378 unsigned char frame[AC3_MAX_CODED_FRAME_SIZE];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1379 short samples[AC3_FRAME_SIZE];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1380 int ret, i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2644
diff changeset
1381
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1382 AC3_encode_init(&ctx, 44100, 64000, 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1383
986e461dc072 Initial revision
glantau
parents:
diff changeset
1384 fft_test();
986e461dc072 Initial revision
glantau
parents:
diff changeset
1385 mdct_test();
986e461dc072 Initial revision
glantau
parents:
diff changeset
1386
986e461dc072 Initial revision
glantau
parents:
diff changeset
1387 for(i=0;i<AC3_FRAME_SIZE;i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1388 samples[i] = (int)(sin(2*M_PI*i*1000.0/44100) * 10000);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1389 ret = AC3_encode_frame(&ctx, frame, samples);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1390 printf("ret=%d\n", ret);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1391 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1392 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
1393
986e461dc072 Initial revision
glantau
parents:
diff changeset
1394 AVCodec ac3_encoder = {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1395 "ac3",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 10501
diff changeset
1396 AVMEDIA_TYPE_AUDIO,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1397 CODEC_ID_AC3,
986e461dc072 Initial revision
glantau
parents:
diff changeset
1398 sizeof(AC3EncodeContext),
986e461dc072 Initial revision
glantau
parents:
diff changeset
1399 AC3_encode_init,
986e461dc072 Initial revision
glantau
parents:
diff changeset
1400 AC3_encode_frame,
925
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 782
diff changeset
1401 AC3_encode_close,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1402 NULL,
10145
7955db355703 Make sample_fmts and channel_layouts compound literals const to reduce size of
reimar
parents: 9999
diff changeset
1403 .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
7769
e5f7a43f63ae create a separate codec_id for E-AC-3
jbr
parents: 7626
diff changeset
1404 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
10145
7955db355703 Make sample_fmts and channel_layouts compound literals const to reduce size of
reimar
parents: 9999
diff changeset
1405 .channel_layouts = (const int64_t[]){
9513
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1406 CH_LAYOUT_MONO,
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1407 CH_LAYOUT_STEREO,
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1408 CH_LAYOUT_2_1,
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1409 CH_LAYOUT_SURROUND,
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1410 CH_LAYOUT_2_2,
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1411 CH_LAYOUT_QUAD,
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1412 CH_LAYOUT_4POINT0,
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1413 CH_LAYOUT_5POINT0,
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1414 CH_LAYOUT_5POINT0_BACK,
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1415 (CH_LAYOUT_MONO | CH_LOW_FREQUENCY),
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1416 (CH_LAYOUT_STEREO | CH_LOW_FREQUENCY),
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1417 (CH_LAYOUT_2_1 | CH_LOW_FREQUENCY),
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1418 (CH_LAYOUT_SURROUND | CH_LOW_FREQUENCY),
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1419 (CH_LAYOUT_2_2 | CH_LOW_FREQUENCY),
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1420 (CH_LAYOUT_QUAD | CH_LOW_FREQUENCY),
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1421 (CH_LAYOUT_4POINT0 | CH_LOW_FREQUENCY),
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1422 CH_LAYOUT_5POINT1,
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1423 CH_LAYOUT_5POINT1_BACK,
24532a2d9d2c Add channel layout support to the AC-3 encoder.
jbr
parents: 9452
diff changeset
1424 0 },
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1425 };