summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2005-02-16 11:02:11 +0000
committerDave Chapman <dave@dchapman.com>2005-02-16 11:02:11 +0000
commit3bd167771d23edbfcf11ea4d5f0f75faf53af0c9 (patch)
tree8caa153a8c30654e7488cbc50eaa650e6c43fe72
parent1f9610d43cefc10a1e47924ad65ce0f78c63bc66 (diff)
downloadrockbox-3bd167771d23edbfcf11ea4d5f0f75faf53af0c9.tar.gz
rockbox-3bd167771d23edbfcf11ea4d5f0f75faf53af0c9.zip
Initial import of the unmodified version of liba52-0.7.5-cvs, checked out of the Sourceforge CVS repository today.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5970 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/liba52/AUTHORS23
-rw-r--r--apps/codecs/liba52/COPYING340
-rw-r--r--apps/codecs/liba52/ChangeLog97
-rw-r--r--apps/codecs/liba52/HISTORY28
-rw-r--r--apps/codecs/liba52/INSTALL58
-rw-r--r--apps/codecs/liba52/Makefile47
-rw-r--r--apps/codecs/liba52/NEWS46
-rw-r--r--apps/codecs/liba52/README180
-rw-r--r--apps/codecs/liba52/README.rockbox27
-rw-r--r--apps/codecs/liba52/SOURCES5
-rw-r--r--apps/codecs/liba52/TODO17
-rw-r--r--apps/codecs/liba52/a52.h67
-rw-r--r--apps/codecs/liba52/a52_internal.h160
-rw-r--r--apps/codecs/liba52/attributes.h37
-rw-r--r--apps/codecs/liba52/bit_allocate.c265
-rw-r--r--apps/codecs/liba52/bitstream.c97
-rw-r--r--apps/codecs/liba52/bitstream.h77
-rw-r--r--apps/codecs/liba52/config.h21
-rw-r--r--apps/codecs/liba52/downmix.c685
-rw-r--r--apps/codecs/liba52/imdct.c429
-rw-r--r--apps/codecs/liba52/mm_accel.h37
-rw-r--r--apps/codecs/liba52/parse.c946
-rw-r--r--apps/codecs/liba52/tables.h246
-rw-r--r--apps/codecs/liba52/tendra.h35
24 files changed, 3970 insertions, 0 deletions
diff --git a/apps/codecs/liba52/AUTHORS b/apps/codecs/liba52/AUTHORS
new file mode 100644
index 0000000000..b9ded1bc4d
--- /dev/null
+++ b/apps/codecs/liba52/AUTHORS
@@ -0,0 +1,23 @@
1Aaron Holtzman <aholtzma@ess.engr.uvic.ca> started the project and
2made the initial working implementation.
3
4Michel Lespinasse <walken@zoy.org> did major changes for speed and
5conformance and is the current maintainer.
6
7Other contributors include:
8 Gildas Bazin <gbazin@netcourrier.com> - mingw32 port
9 Billy Biggs <vektor@div8.net> - most of liba52.txt
10 Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com> - fixed point version
11 Eduard Hasenleithner <eduardh@aon.at> - gcc 3.0 fixes
12 Håkan Hjort <d95hjort@dtek.chalmers.se> - Solaris output, mlib code
13 Charles M. Hannum <root@ihack.net> - fixes
14 Chris Hodges <hodges@stradis.com> - made the library reentrant
15 Michael Holzt <kju@flummi.de> - OSS output.c and misc errata
16 Angelos Keromytis <angelos@dsl.cis.upenn.edu> - OpenBSD fixes
17 David I. Lehn <dlehn@vt.edu> - API cleanup suggestion
18 Don Mahurin <dmahurin@dma.org> - stdin support for extract_a52
19 Jim Miller <jmiller@heli.engr.sgi.com> - IRIX output.c
20 Takefumi Sayo <stake@niagara.shiojiri.ne.jp> - FreeBSD tweak
21 Shoji Tokunaga <toku@mac.com> - aif file output
22
23(let me know if I forgot anyone)
diff --git a/apps/codecs/liba52/COPYING b/apps/codecs/liba52/COPYING
new file mode 100644
index 0000000000..60549be514
--- /dev/null
+++ b/apps/codecs/liba52/COPYING
@@ -0,0 +1,340 @@
1 GNU GENERAL PUBLIC LICENSE
2 Version 2, June 1991
3
4 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6 Everyone is permitted to copy and distribute verbatim copies
7 of this license document, but changing it is not allowed.
8
9 Preamble
10
11 The licenses for most software are designed to take away your
12freedom to share and change it. By contrast, the GNU General Public
13License is intended to guarantee your freedom to share and change free
14software--to make sure the software is free for all its users. This
15General Public License applies to most of the Free Software
16Foundation's software and to any other program whose authors commit to
17using it. (Some other Free Software Foundation software is covered by
18the GNU Library General Public License instead.) You can apply it to
19your programs, too.
20
21 When we speak of free software, we are referring to freedom, not
22price. Our General Public Licenses are designed to make sure that you
23have the freedom to distribute copies of free software (and charge for
24this service if you wish), that you receive source code or can get it
25if you want it, that you can change the software or use pieces of it
26in new free programs; and that you know you can do these things.
27
28 To protect your rights, we need to make restrictions that forbid
29anyone to deny you these rights or to ask you to surrender the rights.
30These restrictions translate to certain responsibilities for you if you
31distribute copies of the software, or if you modify it.
32
33 For example, if you distribute copies of such a program, whether
34gratis or for a fee, you must give the recipients all the rights that
35you have. You must make sure that they, too, receive or can get the
36source code. And you must show them these terms so they know their
37rights.
38
39 We protect your rights with two steps: (1) copyright the software, and
40(2) offer you this license which gives you legal permission to copy,
41distribute and/or modify the software.
42
43 Also, for each author's protection and ours, we want to make certain
44that everyone understands that there is no warranty for this free
45software. If the software is modified by someone else and passed on, we
46want its recipients to know that what they have is not the original, so
47that any problems introduced by others will not reflect on the original
48authors' reputations.
49
50 Finally, any free program is threatened constantly by software
51patents. We wish to avoid the danger that redistributors of a free
52program will individually obtain patent licenses, in effect making the
53program proprietary. To prevent this, we have made it clear that any
54patent must be licensed for everyone's free use or not licensed at all.
55
56 The precise terms and conditions for copying, distribution and
57modification follow.
58
59 GNU GENERAL PUBLIC LICENSE
60 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
62 0. This License applies to any program or other work which contains
63a notice placed by the copyright holder saying it may be distributed
64under the terms of this General Public License. The "Program", below,
65refers to any such program or work, and a "work based on the Program"
66means either the Program or any derivative work under copyright law:
67that is to say, a work containing the Program or a portion of it,
68either verbatim or with modifications and/or translated into another
69language. (Hereinafter, translation is included without limitation in
70the term "modification".) Each licensee is addressed as "you".
71
72Activities other than copying, distribution and modification are not
73covered by this License; they are outside its scope. The act of
74running the Program is not restricted, and the output from the Program
75is covered only if its contents constitute a work based on the
76Program (independent of having been made by running the Program).
77Whether that is true depends on what the Program does.
78
79 1. You may copy and distribute verbatim copies of the Program's
80source code as you receive it, in any medium, provided that you
81conspicuously and appropriately publish on each copy an appropriate
82copyright notice and disclaimer of warranty; keep intact all the
83notices that refer to this License and to the absence of any warranty;
84and give any other recipients of the Program a copy of this License
85along with the Program.
86
87You may charge a fee for the physical act of transferring a copy, and
88you may at your option offer warranty protection in exchange for a fee.
89
90 2. You may modify your copy or copies of the Program or any portion
91of it, thus forming a work based on the Program, and copy and
92distribute such modifications or work under the terms of Section 1
93above, provided that you also meet all of these conditions:
94
95 a) You must cause the modified files to carry prominent notices
96 stating that you changed the files and the date of any change.
97
98 b) You must cause any work that you distribute or publish, that in
99 whole or in part contains or is derived from the Program or any
100 part thereof, to be licensed as a whole at no charge to all third
101 parties under the terms of this License.
102
103 c) If the modified program normally reads commands interactively
104 when run, you must cause it, when started running for such
105 interactive use in the most ordinary way, to print or display an
106 announcement including an appropriate copyright notice and a
107 notice that there is no warranty (or else, saying that you provide
108 a warranty) and that users may redistribute the program under
109 these conditions, and telling the user how to view a copy of this
110 License. (Exception: if the Program itself is interactive but
111 does not normally print such an announcement, your work based on
112 the Program is not required to print an announcement.)
113
114These requirements apply to the modified work as a whole. If
115identifiable sections of that work are not derived from the Program,
116and can be reasonably considered independent and separate works in
117themselves, then this License, and its terms, do not apply to those
118sections when you distribute them as separate works. But when you
119distribute the same sections as part of a whole which is a work based
120on the Program, the distribution of the whole must be on the terms of
121this License, whose permissions for other licensees extend to the
122entire whole, and thus to each and every part regardless of who wrote it.
123
124Thus, it is not the intent of this section to claim rights or contest
125your rights to work written entirely by you; rather, the intent is to
126exercise the right to control the distribution of derivative or
127collective works based on the Program.
128
129In addition, mere aggregation of another work not based on the Program
130with the Program (or with a work based on the Program) on a volume of
131a storage or distribution medium does not bring the other work under
132the scope of this License.
133
134 3. You may copy and distribute the Program (or a work based on it,
135under Section 2) in object code or executable form under the terms of
136Sections 1 and 2 above provided that you also do one of the following:
137
138 a) Accompany it with the complete corresponding machine-readable
139 source code, which must be distributed under the terms of Sections
140 1 and 2 above on a medium customarily used for software interchange; or,
141
142 b) Accompany it with a written offer, valid for at least three
143 years, to give any third party, for a charge no more than your
144 cost of physically performing source distribution, a complete
145 machine-readable copy of the corresponding source code, to be
146 distributed under the terms of Sections 1 and 2 above on a medium
147 customarily used for software interchange; or,
148
149 c) Accompany it with the information you received as to the offer
150 to distribute corresponding source code. (This alternative is
151 allowed only for noncommercial distribution and only if you
152 received the program in object code or executable form with such
153 an offer, in accord with Subsection b above.)
154
155The source code for a work means the preferred form of the work for
156making modifications to it. For an executable work, complete source
157code means all the source code for all modules it contains, plus any
158associated interface definition files, plus the scripts used to
159control compilation and installation of the executable. However, as a
160special exception, the source code distributed need not include
161anything that is normally distributed (in either source or binary
162form) with the major components (compiler, kernel, and so on) of the
163operating system on which the executable runs, unless that component
164itself accompanies the executable.
165
166If distribution of executable or object code is made by offering
167access to copy from a designated place, then offering equivalent
168access to copy the source code from the same place counts as
169distribution of the source code, even though third parties are not
170compelled to copy the source along with the object code.
171
172 4. You may not copy, modify, sublicense, or distribute the Program
173except as expressly provided under this License. Any attempt
174otherwise to copy, modify, sublicense or distribute the Program is
175void, and will automatically terminate your rights under this License.
176However, parties who have received copies, or rights, from you under
177this License will not have their licenses terminated so long as such
178parties remain in full compliance.
179
180 5. You are not required to accept this License, since you have not
181signed it. However, nothing else grants you permission to modify or
182distribute the Program or its derivative works. These actions are
183prohibited by law if you do not accept this License. Therefore, by
184modifying or distributing the Program (or any work based on the
185Program), you indicate your acceptance of this License to do so, and
186all its terms and conditions for copying, distributing or modifying
187the Program or works based on it.
188
189 6. Each time you redistribute the Program (or any work based on the
190Program), the recipient automatically receives a license from the
191original licensor to copy, distribute or modify the Program subject to
192these terms and conditions. You may not impose any further
193restrictions on the recipients' exercise of the rights granted herein.
194You are not responsible for enforcing compliance by third parties to
195this License.
196
197 7. If, as a consequence of a court judgment or allegation of patent
198infringement or for any other reason (not limited to patent issues),
199conditions are imposed on you (whether by court order, agreement or
200otherwise) that contradict the conditions of this License, they do not
201excuse you from the conditions of this License. If you cannot
202distribute so as to satisfy simultaneously your obligations under this
203License and any other pertinent obligations, then as a consequence you
204may not distribute the Program at all. For example, if a patent
205license would not permit royalty-free redistribution of the Program by
206all those who receive copies directly or indirectly through you, then
207the only way you could satisfy both it and this License would be to
208refrain entirely from distribution of the Program.
209
210If any portion of this section is held invalid or unenforceable under
211any particular circumstance, the balance of the section is intended to
212apply and the section as a whole is intended to apply in other
213circumstances.
214
215It is not the purpose of this section to induce you to infringe any
216patents or other property right claims or to contest validity of any
217such claims; this section has the sole purpose of protecting the
218integrity of the free software distribution system, which is
219implemented by public license practices. Many people have made
220generous contributions to the wide range of software distributed
221through that system in reliance on consistent application of that
222system; it is up to the author/donor to decide if he or she is willing
223to distribute software through any other system and a licensee cannot
224impose that choice.
225
226This section is intended to make thoroughly clear what is believed to
227be a consequence of the rest of this License.
228
229 8. If the distribution and/or use of the Program is restricted in
230certain countries either by patents or by copyrighted interfaces, the
231original copyright holder who places the Program under this License
232may add an explicit geographical distribution limitation excluding
233those countries, so that distribution is permitted only in or among
234countries not thus excluded. In such case, this License incorporates
235the limitation as if written in the body of this License.
236
237 9. The Free Software Foundation may publish revised and/or new versions
238of the General Public License from time to time. Such new versions will
239be similar in spirit to the present version, but may differ in detail to
240address new problems or concerns.
241
242Each version is given a distinguishing version number. If the Program
243specifies a version number of this License which applies to it and "any
244later version", you have the option of following the terms and conditions
245either of that version or of any later version published by the Free
246Software Foundation. If the Program does not specify a version number of
247this License, you may choose any version ever published by the Free Software
248Foundation.
249
250 10. If you wish to incorporate parts of the Program into other free
251programs whose distribution conditions are different, write to the author
252to ask for permission. For software which is copyrighted by the Free
253Software Foundation, write to the Free Software Foundation; we sometimes
254make exceptions for this. Our decision will be guided by the two goals
255of preserving the free status of all derivatives of our free software and
256of promoting the sharing and reuse of software generally.
257
258 NO WARRANTY
259
260 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268REPAIR OR CORRECTION.
269
270 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278POSSIBILITY OF SUCH DAMAGES.
279
280 END OF TERMS AND CONDITIONS
281
282 How to Apply These Terms to Your New Programs
283
284 If you develop a new program, and you want it to be of the greatest
285possible use to the public, the best way to achieve this is to make it
286free software which everyone can redistribute and change under these terms.
287
288 To do so, attach the following notices to the program. It is safest
289to attach them to the start of each source file to most effectively
290convey the exclusion of warranty; and each file should have at least
291the "copyright" line and a pointer to where the full notice is found.
292
293 <one line to give the program's name and a brief idea of what it does.>
294 Copyright (C) 19yy <name of author>
295
296 This program is free software; you can redistribute it and/or modify
297 it under the terms of the GNU General Public License as published by
298 the Free Software Foundation; either version 2 of the License, or
299 (at your option) any later version.
300
301 This program is distributed in the hope that it will be useful,
302 but WITHOUT ANY WARRANTY; without even the implied warranty of
303 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 GNU General Public License for more details.
305
306 You should have received a copy of the GNU General Public License
307 along with this program; if not, write to the Free Software
308 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
309
310
311Also add information on how to contact you by electronic and paper mail.
312
313If the program is interactive, make it output a short notice like this
314when it starts in an interactive mode:
315
316 Gnomovision version 69, Copyright (C) 19yy name of author
317 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318 This is free software, and you are welcome to redistribute it
319 under certain conditions; type `show c' for details.
320
321The hypothetical commands `show w' and `show c' should show the appropriate
322parts of the General Public License. Of course, the commands you use may
323be called something other than `show w' and `show c'; they could even be
324mouse-clicks or menu items--whatever suits your program.
325
326You should also get your employer (if you work as a programmer) or your
327school, if any, to sign a "copyright disclaimer" for the program, if
328necessary. Here is a sample; alter the names:
329
330 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331 `Gnomovision' (which makes passes at compilers) written by James Hacker.
332
333 <signature of Ty Coon>, 1 April 1989
334 Ty Coon, President of Vice
335
336This General Public License does not permit incorporating your program into
337proprietary programs. If your program is a subroutine library, you may
338consider it more useful to permit linking proprietary applications with the
339library. If this is what you want to do, use the GNU Library General
340Public License instead of this License.
diff --git a/apps/codecs/liba52/ChangeLog b/apps/codecs/liba52/ChangeLog
new file mode 100644
index 0000000000..4adac364eb
--- /dev/null
+++ b/apps/codecs/liba52/ChangeLog
@@ -0,0 +1,97 @@
1a52dec-0.7.4 Sat Jul 27 20:44:00 PDT 2002
2-The library is now fully reentrant.
3-Added win32 output module, al file output, gain control.
4-A few additional portability enhancements.
5
6a52dec-0.7.3 Wed Feb 20 23:38:22 PST 2002
7-rewrite of the imdct code, making a52dec 40% to 80% faster than version 0.7.2
8-fixed one memory corruption problem in parse.c
9-small liba52 portability fixes
10-byte order and CRLF bugfixes in wav file output
11-aif file output
12-IRIX al sound output (untested, tell us if it works)
13
14a52dec-0.7.2 Sun Dec 16 14:39:56 PST 2001
15-demuxer improvements, with support for TS streams.
16-smaller demux buffer, making it easier to use a52dec as a pipe
17-wav output
18-avoid -fPIC when possible (-prefer-non-pic)
19-support for vc++ and TenDRA
20-portability fixes
21
22a52dec-0.7.1b Fri Aug 31 02:37:23 PDT 2001
23-removed an #include <stdint.h> that was only breaking libc5 builds
24
25a52dec-0.7.1 Thu Aug 30 02:13:23 PDT 2001
26-gcc 3.0 fixes
27-mlib fixes (now passes the test suite)
28-in a52dec.c, made sample_data and flags static
29-removed a few statics in liba52/parse.c (still not reentrant, but closer)
30
31a52dec-0.7.0 Thu Aug 23 23:18:00 PDT 2001
32-Downmix to arbitrary speaker configurations
33-Dynamic range compression
34-Major speedups: 2x for 2.0 streams with 2.0 output,
35 3x for 5.1 streams with 2.0 output.
36-New library interface
37-Rematrixing bugfix
38-Higher precision
39
40ac3dec-0.6.1 Mon Mar 27 20:27:06 EST 2000
41-Fix another 2.0 problem (rematrix was wrong).
42-Fix the never resync on a bad crc bug.
43
44ac3dec-0.6.0 Sat Mar 18 19:43:25 EST 2000
45-New library interface
46-Fix bug wrt coupling channels that was causing sound quality problems.
47-Fix 2.0 mode problems (aka the I forgot to implement the phase flags bug).
48-All around speed improvements (almost twice as fast)
49-Improved robustness when fed bad data. The entire frame is checksummed before playback.
50
51ac3dec-0.5.6 Tue Nov 16 00:37:34 EST 1999
52-Irix support
53-Alpha fixes
54-Minor performance enhancements to downmix and imdct
55-OpenBSD fixes
56-extract_ac3 can now read from stdin
57-Change output_linux to block on write instead of using the
58 ring buffer. Let me know if this causes/fixes any problems
59
60ac3dec-0.5.5 Wed Aug 25 15:36:44 EDT 1999
61-Fixed a cut and paste bug (argh!) in parse.c which potentially
62 screwed up delta bit allocation info.
63-Martin Mueller <mamueller@topmail.de> informed me that I was missing
64 some corrections from the AC-3 errata document. It turns out that
65 I used an earlier version of the errata when I initially wrote ac3dec.
66 Fortunately the errata fix the outstanding bugs that I was pulling
67 my hair out on for a long time. Woohoo! Thanks Martin. Kudos to Dolby
68 Labs for keeping their documentation up to date as well.
69-stereo downmixing (downmix.c) is now in. Matrix encoded surround
70 (Dolby Prologic Surround) should work too.
71-clipping due to high level signals has been fixed. We normalize a
72 block of samples by its maximum absolute value if the max exceeds
73 the %100 digital level. This shouldn't be a problem, but for some
74 reason some channels have a dynamic range that exceeds [-1.0,1.0].
75 I blame the encoder :)
76-Multiple track support in extract_ac3. Simply just give it the track
77 number you want [1,8] after the filename.
78
79ac3dec-0.5.4 Thu Jul 29 16:55:10 PDT 1999
80-Fixed a stupid bug with the coupling channel that was causing
81 high frequencies to be attenuated.
82-Re-wrote the extract_ac3 tool.
83-Added to a tool to verify the checksums on a given AC3 stream.
84 (tools/verify_ac3)
85
86ac3dec-0.5.3 Mon Jul 12 10:45:56 PDT 1999
87-Fixed problems related to streams with coupling channel enabled.
88-Minor performance enhancements
89
90ac3dec-0.5.2 Sun Jul 4 12:00:25 PDT 1999
91-output_linux.c patch provided by Michael Holzt <kju@flummi.de>
92
93ac3dec-0.5.1 Wed Jun 30 17:48:52 PDT 1999
94-Compiles and dies gracefully under Linux now.
95
96ac3dec-0.5.0 Wed Jun 23 11:06:06 EDT 1999
97-First public release of ac3dec.
diff --git a/apps/codecs/liba52/HISTORY b/apps/codecs/liba52/HISTORY
new file mode 100644
index 0000000000..c2b9d02ee1
--- /dev/null
+++ b/apps/codecs/liba52/HISTORY
@@ -0,0 +1,28 @@
1changes that affected the PCM output:
2
32001/05/14 05:48:59 - aaron's 0.6.1 was cutting before the end
4
52001/06/04 01:42:47 - slightly adjusted some values (volume, downmix adjustemtn, clev/slev tables)
62001/06/04 05:48:31 - added adjust_level to the downmix
7
82001/06/12
92001/06/13 - changed the order of the dither() calls
10 also introduced bug with thx_2_0 stream
11
122001/06/22 08:23:37 - fixed bug with thx_2_0 stream (see parse.c)
13
142001/07/02 08:44:55 - changed float-to-int conversion (+ added saturation)
15
162001/07/06 06:53:01 - more precise imdct init, more precise q_* coefficients
17
182001/07/06 08:52:30 - rematrixing fixes
19
202001/07/26 21:31:39 - do 3dB dither reduction in coeff_get() not dither_gen()
21
222001/08/09 08:11:31 - implemented dynamic range compression
23
242002/02/24 08:54:49 - window function computed at runtime, with more precision
25
262003/01/28 06.57:37 - switched to integer q_* coefficients
27
282003/01/28 07:39:35 - use level of 0.75 for dithering instead of 0.707
diff --git a/apps/codecs/liba52/INSTALL b/apps/codecs/liba52/INSTALL
new file mode 100644
index 0000000000..30a07fecff
--- /dev/null
+++ b/apps/codecs/liba52/INSTALL
@@ -0,0 +1,58 @@
1Unix build instructions
2-----------------------
3
4./configure
5make
6make install
7
8If you install from CVS you'll have to run ./bootstrap first
9
10
11Building for win32
12------------------
13
14There are at least three ways to do it:
15
16- natively on Windows using Microsoft VC++ and the vc++ project
17 included in this distribution.
18
19- natively on Windows using MSYS + MINGW (www.mingw.org) (MSYS is a
20 minimal build environnement to compile unixish projects under
21 windows. It provides all the common unix tools like sh, gmake...)
22
23- or on Linux, using the mingw32 cross-compiler
24
25
26Building using MSYS + MINGW on windows
27--------------------------------------
28
29First you will need to download and install the latest MSYS (version
301.0.7 as of now) and MINGW. The installation is really easy. Begin
31with the MSYS auto-installer and once this is done, extract MINGW into
32c:\msys\1.0\mingw. You also have to remember to remove the make
33utility included with MINGW as it conflicts with the one from MSYS
34(just rename or remove c:\msys\1.0\mingw\bin\make.exe).
35
36http://prdownloads.sourceforge.net/mingw/MSYS-1.0.7-i686-2002.04.24-1.exe
37http://prdownloads.sourceforge.net/mingw/MinGW-1.1.tar.gz
38
39Then you can build the package using:
40# ./configure
41# make
42
43
44Building using the mingw32 cross-compiler
45-----------------------------------------
46
47You need to install mingw32 first. For Debian GNU/Linux users, there
48is a mingw32 package. Otherwise you might get it from the mingw site
49at http://www.mingw.org/download.shtml.
50
51The videolan project also keeps precompiled mingw32 binaries at
52http://www.videolan.org/vlc/windows.html . If you install these,
53you'll have to set your PATH accordingly to include
54/usr/local/cross-tools/bin too.
55
56The build should then proceed using something like:
57# CC=i586-mingw32msvc-gcc ./configure --host=i586-mingw32msvc
58# make
diff --git a/apps/codecs/liba52/Makefile b/apps/codecs/liba52/Makefile
new file mode 100644
index 0000000000..53e6d24dde
--- /dev/null
+++ b/apps/codecs/liba52/Makefile
@@ -0,0 +1,47 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9
10# ../.. for the plugin.h in the apps dir
11# .. for stuff in the plugins dir
12# . for stuff in the pluginlib dir
13INCLUDES=-I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
14 -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(APPSDIR)/plugins/liba52/
15
16ifdef APPEXTRA
17INCLUDES += -I$(APPSDIR)/$(APPEXTRA)
18endif
19
20A52OPTS =
21CFLAGS = $(GCCOPTS) $(A52OPTS) $(INCLUDES) $(TARGET) $(EXTRA_DEFINES) -DMEM=${MEMORYSIZE}
22
23SRC := $(shell cat SOURCES | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) $(DEFINES) -E -P -include "config.h" - )
24SOURCES = $(SRC)
25OBJS := $(SRC:%.c=$(OBJDIR)/liba52/%.o)
26DEPFILE = $(OBJDIR)/dep-liba52
27DIRS =
28
29OUTPUT = $(OBJDIR)/liba52.a
30
31all: $(OUTPUT)
32
33$(OUTPUT): $(OBJS)
34 @echo "AR $@"
35 @$(AR) ruv $@ $+ >/dev/null 2>&1
36
37$(OBJDIR)/liba52/%.o: $(APPSDIR)/plugins/liba52/%.c
38 mkdir -p $(OBJDIR)/liba52
39 $(CC) -c -O2 $(CFLAGS) -I$(APPSDIR)/plugins/liba52/ $< -o $@
40
41include $(TOOLSDIR)/make.inc
42
43clean:
44 @echo "cleaning liba52"
45 @rm -f $(OBJS) $(OUTPUT) $(DEPFILE)
46
47-include $(DEPFILE)
diff --git a/apps/codecs/liba52/NEWS b/apps/codecs/liba52/NEWS
new file mode 100644
index 0000000000..4bee9cac8d
--- /dev/null
+++ b/apps/codecs/liba52/NEWS
@@ -0,0 +1,46 @@
1a52dec-0.7.4 Sat Jul 27 20:44:00 PDT 2002
2
3The library is now fully reentrant.
4
5Added win32 output module, al file output, gain control.
6
7A few additional portability enhancements.
8
9
10a52dec-0.7.3 Wed Feb 20 23:38:22 PST 2002
11
12Performance enhancements, from 40% to 80% depending on streams.
13
14Fixed a few embarassing bugs in liba52: one memory corruption issue
15and a few minor portability problems.
16
17Several new output modules, and fixes in the existing .wav file output.
18
19
20a52dec-0.7.2 Sun Dec 16 14:39:56 PST 2001
21
22Minor bugfixes, performance and portability enhancements.
23
24Also added wav format output, and reduced the demux buffer size which
25makes it easier to use a52dec as a pipe.
26
27
28a52dec-0.7.1 Thu Aug 30 02:13:23 PDT 2001
29
30Minor release for bugfixes. Looks like 0.7.0 was a bit rushed out.
31
32Now compiles with gcc 3.0, made sure mlib implementation works, and
33fixed a small bug in the a52dec test program.
34
35
36a52dec-0.7.0 Thu Aug 23 23:18:00 PDT 2001
37
38First release since more than one year !
39
40The most user-noticeable additions are the downmix to arbitrary
41speaker configurations, and the implementation of dynamic range
42compression.
43
44The speed has been improved by a factor of 2 to 3, the conformance and
45precision should be higher, and we also fixed a small bug when playing
46stereo rematrixed streams.
diff --git a/apps/codecs/liba52/README b/apps/codecs/liba52/README
new file mode 100644
index 0000000000..eb6c64df84
--- /dev/null
+++ b/apps/codecs/liba52/README
@@ -0,0 +1,180 @@
1
2
3ABOUT LIBA52
4
5liba52 is a free library for decoding ATSC A/52 streams. It is
6released under the terms of the GPL license. The A/52 standard is used
7in a variety of applications, including digital television and DVD. It
8is also known as AC-3.
9
10The main goals in liba52 development are:
11
12 * Portability - Currently all of the code is written in C, and
13 when we write platform-specific optimizations we will always
14 keep a generic C routine to fall back on.
15
16 * Reuseability - we do not want liba52 to include any
17 project-specific code, but it should still include enough
18 features to be used by very diverse projects.
19
20 * Precision - We are trying to implement all of the A/52
21 standard, and to have a very precise output by doing all the
22 calculations in floating point. We have a test suite that
23 detects any deviation in the output when compared to previous
24 versions. We do not have access to official A/52 test vectors
25 though, so we have to use our judgement to ensure that such
26 deviations are only intruduced when we fix bugs !
27
28 * Speed - liba52 is really fast, on any modern PC it should take
29 only a few percent of CPU time.
30
31The project homepage is at http://liba52.sourceforge.net/
32
33
34A52DEC
35
36a52dec is a test program for liba52. It decodes ATSC A/52 streams, and
37also includes a demultiplexer for mpeg-1 and mpeg-2 program streams.
38
39The liba52 source code is always distributed in the a52dec package, to
40make sure it easier for people to test it.
41
42The basic usage is to just type "a52dec file" where file is an ATSC
43A/52 file.
44
45The "-s" option must be used for multiplexed (audio and video) mpeg-2
46files. These files are usualy found on the internet or on unencrypted
47DVDs.
48
49The "-o" option is used to select a given output layer. By default
50a52dec does a stereo downmix and outputs to your speakers, but you can
51try other choices using this option. This is also used for performance
52testing and conformance testing.
53
54The "-c" option is used to disable all optimizations (currently only djbfft).
55
56The "-r" option is used to disable the dynamic range compression.
57
58
59OTHER PROJECTS USING LIBA52
60
61liba52 (and its ancestor libac3) is being used by various other
62projects, including:
63
64 * xine (http://xine.sourceforge.net/) - started as a simple
65 mpeg-2 audio and video decoder, but it since became a
66 full-featured DVD and video media player.
67
68 * VideoLAN (http://www.videolan.org/) - video streaming over an
69 ethernet network, can also be used as a standalone player.
70
71 * MPlayer (http://www.MPlayerHQ.hu) - another good player, it is
72 also very robust against damaged streams.
73
74 * movietime (http://movietime.sourceforge.net/) - still quite
75 young, but it looks very promising !
76
77 * ffmpeg (http://ffmpeg.sourceforge.net/) - a nice audio/video
78 encoder and transcoder, uses liba52 for decoding A/52 streams.
79
80 * Ogle (http://www.dtek.chalmers.se/groups/dvd/) - a good DVD
81 player with menu support
82
83 * a52decX (http://homepage1.nifty.com/~toku/software_en.html) -
84 a graphical interface for a52dec in macintosh osX.
85
86 * TCVP (http://tcvp.sf.net) - video and music player for unix.
87
88 * bd4go (http://denisx.dyndns.org/bd4go/) - another graphical
89 interface for macintosh osX.
90
91 * drip (http://drip.sourceforge.net/) - a DVD to DIVX transcoder.
92
93 * OMS (http://www.linuxvideo.org/oms/)
94
95 * XMPS (http://xmps.sourceforge.net/)
96
97 * GStreamer (http://www.gstreamer.net/) - a framework for
98 streaming media; it has an A/52 decoding plugin based on liba52.
99
100 * mpeglib (http://mpeglib.sourceforge.net/) - a video decoding
101 library that usess liba52 when decoding A/52 streams.
102
103If you use liba52 in another project, let us know !
104
105
106TASKS
107
108There are several places where we could easily use some help:
109
110 * Web design: This site sucks ! at the very least, we'd like to
111 come up with a nicer background picture and a logo.
112
113 * Testing: If you find any stream that does not decode right
114 with liba52, let us know ! The best thing would be to mail to
115 the liba52-devel mailing list. Also if you have access to
116 encoders, we'd love to get test streams that would be free of
117 rights - so that we can put them on this server.
118
119 * Coding: you can have a look in the TODO file first ! The most
120 important item is probably to make the code fully reentrant.
121
122 * Porting: If you're porting to a new architecture, you might
123 want to experiment with the compile flags defined in
124 configure.in . When you figure out whats fastest on your
125 platform, send us a patch !
126
127
128REFERENCES
129
130The A/52 standard, as published by the ATSC, is available at
131http://www.atsc.org/standards/a_52a.pdf
132
133
134CVS SNAPSHOTS
135
136A daily snapshot is created using "make distcheck" every night and
137uploaded to http://liba52.sourceforge.net/files/a52dec-snapshot.tar.gz .
138It is easier to use than the CVS repository, because you do not need
139to have the right versions of automake, autoconf and libtool
140installed. It might be convenient when working on a liba52 port for
141example.
142
143
144CVS REPOSITORY
145
146The latest liba52 and a52dec source code can always be found by
147anonymous CVS:
148
149# export CVSROOT=:pserver:anonymous@cvs.liba52.sourceforge.net:/cvsroot/liba52
150# cvs login (Just press Return when prompted for a password)
151# cvs checkout a52dec
152
153You can also browse the latest changes online at
154http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/liba52/a52dec/
155
156The other CVS modules are ac3dec-livid for the CVS history of the
157project while it was still hosted on the linuxvideo.org servers, and
158ac3dec for the CVS history of the project while the linuxvideo.org
159servers were down and before the library switched its name to liba52.
160
161
162MAILING LISTS
163
164See the subscription information at http://liba52.sourceforge.net/lists.html
165
166liba52-devel
167
168This is the main mailing list for technical discussion about
169liba52. Anyone wanting to work on liba52, or maybe just stay informed
170about the development process, should probably subscribe to this list.
171
172liba52-checkins
173
174All liba52 checkins are announced there. This is a good way to keep
175track of what goes into CVS.
176
177liba52-announce
178
179This is a very low traffic mailing list, only for announcements of new
180versions of liba52. Only project administrators can post there.
diff --git a/apps/codecs/liba52/README.rockbox b/apps/codecs/liba52/README.rockbox
new file mode 100644
index 0000000000..79768c5d72
--- /dev/null
+++ b/apps/codecs/liba52/README.rockbox
@@ -0,0 +1,27 @@
1Library: liba52-0.7.5 (CVS version 2005-02-16)
2Imported: 2005-02-16 by Dave Chapman
3
4
5This directory contains a local version of liba52 for decoding ATSC
6A/52 (aka AC-3) audio streams. A/52 is commonly used in digital TV and
7on DVDs.
8
9LICENSING INFORMATION
10
11liba52 is released under the GNU General Public License as described
12in the COPYING file in this directory.
13
14
15IMPORT DETAILS
16
17The base version first imported into Rockbox was the CVS version of
18liba52-0.7.5 (0.7.4 was at the time the latest official) which was
19checked out of sourceforge on 2005-02-16.
20
21The .[ch] files from a52dec/liba52/ and a52dec/include/ as well as the
22documentation files in a52dec/ were imported into Rockbox. The other
23files in the archive relate to the test player (a52dec) and were not
24imported.
25
26A simple config.h file was added to enable liba52's fixed-point
27integer-only mode and to specify the endianness of the target CPU.
diff --git a/apps/codecs/liba52/SOURCES b/apps/codecs/liba52/SOURCES
new file mode 100644
index 0000000000..733b95e8a6
--- /dev/null
+++ b/apps/codecs/liba52/SOURCES
@@ -0,0 +1,5 @@
1bit_allocate.c
2bitstream.c
3downmix.c
4imdct.c
5parse.c
diff --git a/apps/codecs/liba52/TODO b/apps/codecs/liba52/TODO
new file mode 100644
index 0000000000..dc5fb84203
--- /dev/null
+++ b/apps/codecs/liba52/TODO
@@ -0,0 +1,17 @@
1* look at possible overflow/precision issues in integer port
2
3* redo all bit allocation if previous frame had zero_snr_offsets
4* make dynrng work in dual-channel streams
5
6* implement A/52a downmix extensions
7* reduce size of delay buffer by 50%
8* include float->s16 conversion in liba52 API ?
9* include up/downsampling 44100<->48000 in liba52 API ?
10* include audio dithering in liba52 API ?
11* API extensions might be at a different level (base vs. extended)
12
13* use restrict pointers where appropriate
14* avoid overflows, including reading the a52 stream !!!
15* faster bitstream parsing ?
16* make dither code faster (generate dither table in advance ?)
17* SIMD optimizations
diff --git a/apps/codecs/liba52/a52.h b/apps/codecs/liba52/a52.h
new file mode 100644
index 0000000000..aa4e7f6243
--- /dev/null
+++ b/apps/codecs/liba52/a52.h
@@ -0,0 +1,67 @@
1/*
2 * a52.h
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 *
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
8 *
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#ifndef A52_H
25#define A52_H
26
27#if defined(LIBA52_FIXED)
28typedef int32_t sample_t;
29typedef int32_t level_t;
30#elif defined(LIBA52_DOUBLE)
31typedef double sample_t;
32typedef double level_t;
33#else
34typedef float sample_t;
35typedef float level_t;
36#endif
37
38typedef struct a52_state_s a52_state_t;
39
40#define A52_CHANNEL 0
41#define A52_MONO 1
42#define A52_STEREO 2
43#define A52_3F 3
44#define A52_2F1R 4
45#define A52_3F1R 5
46#define A52_2F2R 6
47#define A52_3F2R 7
48#define A52_CHANNEL1 8
49#define A52_CHANNEL2 9
50#define A52_DOLBY 10
51#define A52_CHANNEL_MASK 15
52
53#define A52_LFE 16
54#define A52_ADJUST_LEVEL 32
55
56a52_state_t * a52_init (uint32_t mm_accel);
57sample_t * a52_samples (a52_state_t * state);
58int a52_syncinfo (uint8_t * buf, int * flags,
59 int * sample_rate, int * bit_rate);
60int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
61 level_t * level, sample_t bias);
62void a52_dynrng (a52_state_t * state,
63 level_t (* call) (level_t, void *), void * data);
64int a52_block (a52_state_t * state);
65void a52_free (a52_state_t * state);
66
67#endif /* A52_H */
diff --git a/apps/codecs/liba52/a52_internal.h b/apps/codecs/liba52/a52_internal.h
new file mode 100644
index 0000000000..a158227699
--- /dev/null
+++ b/apps/codecs/liba52/a52_internal.h
@@ -0,0 +1,160 @@
1/*
2 * a52_internal.h
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 *
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
8 *
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24typedef struct {
25 uint8_t bai; /* fine SNR offset, fast gain */
26 uint8_t deltbae; /* delta bit allocation exists */
27 int8_t deltba[50]; /* per-band delta bit allocation */
28} ba_t;
29
30typedef struct {
31 uint8_t exp[256]; /* decoded channel exponents */
32 int8_t bap[256]; /* derived channel bit allocation */
33} expbap_t;
34
35struct a52_state_s {
36 uint8_t fscod; /* sample rate */
37 uint8_t halfrate; /* halfrate factor */
38 uint8_t acmod; /* coded channels */
39 uint8_t lfeon; /* coded lfe channel */
40 level_t clev; /* centre channel mix level */
41 level_t slev; /* surround channels mix level */
42
43 int output; /* type of output */
44 level_t level; /* output level */
45 sample_t bias; /* output bias */
46
47 int dynrnge; /* apply dynamic range */
48 level_t dynrng; /* dynamic range */
49 void * dynrngdata; /* dynamic range callback funtion and data */
50 level_t (* dynrngcall) (level_t range, void * dynrngdata);
51
52 uint8_t chincpl; /* channel coupled */
53 uint8_t phsflginu; /* phase flags in use (stereo only) */
54 uint8_t cplstrtmant; /* coupling channel start mantissa */
55 uint8_t cplendmant; /* coupling channel end mantissa */
56 uint32_t cplbndstrc; /* coupling band structure */
57 level_t cplco[5][18]; /* coupling coordinates */
58
59 /* derived information */
60 uint8_t cplstrtbnd; /* coupling start band (for bit allocation) */
61 uint8_t ncplbnd; /* number of coupling bands */
62
63 uint8_t rematflg; /* stereo rematrixing */
64
65 uint8_t endmant[5]; /* channel end mantissa */
66
67 uint16_t bai; /* bit allocation information */
68
69 uint32_t * buffer_start;
70 uint16_t lfsr_state; /* dither state */
71 uint32_t bits_left;
72 uint32_t current_word;
73
74 uint8_t csnroffst; /* coarse SNR offset */
75 ba_t cplba; /* coupling bit allocation parameters */
76 ba_t ba[5]; /* channel bit allocation parameters */
77 ba_t lfeba; /* lfe bit allocation parameters */
78
79 uint8_t cplfleak; /* coupling fast leak init */
80 uint8_t cplsleak; /* coupling slow leak init */
81
82 expbap_t cpl_expbap;
83 expbap_t fbw_expbap[5];
84 expbap_t lfe_expbap;
85
86 sample_t * samples;
87 int downmixed;
88};
89
90#define LEVEL_PLUS6DB 2.0
91#define LEVEL_PLUS3DB 1.4142135623730951
92#define LEVEL_3DB 0.7071067811865476
93#define LEVEL_45DB 0.5946035575013605
94#define LEVEL_6DB 0.5
95
96#define EXP_REUSE (0)
97#define EXP_D15 (1)
98#define EXP_D25 (2)
99#define EXP_D45 (3)
100
101#define DELTA_BIT_REUSE (0)
102#define DELTA_BIT_NEW (1)
103#define DELTA_BIT_NONE (2)
104#define DELTA_BIT_RESERVED (3)
105
106void a52_bit_allocate (a52_state_t * state, ba_t * ba, int bndstart,
107 int start, int end, int fastleak, int slowleak,
108 expbap_t * expbap);
109
110int a52_downmix_init (int input, int flags, level_t * level,
111 level_t clev, level_t slev);
112int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
113 level_t clev, level_t slev);
114void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias,
115 level_t clev, level_t slev);
116void a52_upmix (sample_t * samples, int acmod, int output);
117
118void a52_imdct_init (uint32_t mm_accel);
119void a52_imdct_256 (sample_t * data, sample_t * delay, sample_t bias);
120void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias);
121
122#define ROUND(x) ((int)((x) + ((x) > 0 ? 0.5 : -0.5)))
123
124#ifndef LIBA52_FIXED
125
126typedef sample_t quantizer_t;
127#define SAMPLE(x) (x)
128#define LEVEL(x) (x)
129#define MUL(a,b) ((a) * (b))
130#define MUL_L(a,b) ((a) * (b))
131#define MUL_C(a,b) ((a) * (b))
132#define DIV(a,b) ((a) / (b))
133#define BIAS(x) ((x) + bias)
134
135#else /* LIBA52_FIXED */
136
137typedef int16_t quantizer_t;
138#define SAMPLE(x) (sample_t)((x) * (1 << 30))
139#define LEVEL(x) (level_t)((x) * (1 << 26))
140
141#if 0
142#define MUL(a,b) ((int)(((int64_t)(a) * (b) + (1 << 29)) >> 30))
143#define MUL_L(a,b) ((int)(((int64_t)(a) * (b) + (1 << 25)) >> 26))
144#elif 1
145#define MUL(a,b) \
146({ int32_t _ta=(a), _tb=(b), _tc; \
147 _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)(((_tc >> 14))+ (((_ta >> 16)*(_tb >> 16)) << 2 )); })
148#define MUL_L(a,b) \
149({ int32_t _ta=(a), _tb=(b), _tc; \
150 _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)((_tc >> 10) + (((_ta >> 16)*(_tb >> 16)) << 6)); })
151#else
152#define MUL(a,b) (((a) >> 15) * ((b) >> 15))
153#define MUL_L(a,b) (((a) >> 13) * ((b) >> 13))
154#endif
155
156#define MUL_C(a,b) MUL_L (a, LEVEL (b))
157#define DIV(a,b) ((((int64_t)LEVEL (a)) << 26) / (b))
158#define BIAS(x) (x)
159
160#endif
diff --git a/apps/codecs/liba52/attributes.h b/apps/codecs/liba52/attributes.h
new file mode 100644
index 0000000000..988abc0311
--- /dev/null
+++ b/apps/codecs/liba52/attributes.h
@@ -0,0 +1,37 @@
1/*
2 * attributes.h
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 *
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
8 *
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24/* use gcc attribs to align critical data structures */
25#ifdef ATTRIBUTE_ALIGNED_MAX
26#define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
27#else
28#define ATTR_ALIGN(align)
29#endif
30
31#ifdef HAVE_BUILTIN_EXPECT
32#define likely(x) __builtin_expect ((x) != 0, 1)
33#define unlikely(x) __builtin_expect ((x) != 0, 0)
34#else
35#define likely(x) (x)
36#define unlikely(x) (x)
37#endif
diff --git a/apps/codecs/liba52/bit_allocate.c b/apps/codecs/liba52/bit_allocate.c
new file mode 100644
index 0000000000..c8da24e9e6
--- /dev/null
+++ b/apps/codecs/liba52/bit_allocate.c
@@ -0,0 +1,265 @@
1/*
2 * bit_allocate.c
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 *
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
8 *
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include "config.h"
25
26#include <inttypes.h>
27
28#include "a52.h"
29#include "a52_internal.h"
30
31static int hthtab[3][50] = {
32 {0x730, 0x730, 0x7c0, 0x800, 0x820, 0x840, 0x850, 0x850, 0x860, 0x860,
33 0x860, 0x860, 0x860, 0x870, 0x870, 0x870, 0x880, 0x880, 0x890, 0x890,
34 0x8a0, 0x8a0, 0x8b0, 0x8b0, 0x8c0, 0x8c0, 0x8d0, 0x8e0, 0x8f0, 0x900,
35 0x910, 0x910, 0x910, 0x910, 0x900, 0x8f0, 0x8c0, 0x870, 0x820, 0x7e0,
36 0x7a0, 0x770, 0x760, 0x7a0, 0x7c0, 0x7c0, 0x6e0, 0x400, 0x3c0, 0x3c0},
37 {0x710, 0x710, 0x7a0, 0x7f0, 0x820, 0x830, 0x840, 0x850, 0x850, 0x860,
38 0x860, 0x860, 0x860, 0x860, 0x870, 0x870, 0x870, 0x880, 0x880, 0x880,
39 0x890, 0x890, 0x8a0, 0x8a0, 0x8b0, 0x8b0, 0x8c0, 0x8c0, 0x8e0, 0x8f0,
40 0x900, 0x910, 0x910, 0x910, 0x910, 0x900, 0x8e0, 0x8b0, 0x870, 0x820,
41 0x7e0, 0x7b0, 0x760, 0x770, 0x7a0, 0x7c0, 0x780, 0x5d0, 0x3c0, 0x3c0},
42 {0x680, 0x680, 0x750, 0x7b0, 0x7e0, 0x810, 0x820, 0x830, 0x840, 0x850,
43 0x850, 0x850, 0x860, 0x860, 0x860, 0x860, 0x860, 0x860, 0x860, 0x860,
44 0x870, 0x870, 0x870, 0x870, 0x880, 0x880, 0x880, 0x890, 0x8a0, 0x8b0,
45 0x8c0, 0x8d0, 0x8e0, 0x8f0, 0x900, 0x910, 0x910, 0x910, 0x900, 0x8f0,
46 0x8d0, 0x8b0, 0x840, 0x7f0, 0x790, 0x760, 0x7a0, 0x7c0, 0x7b0, 0x720}
47};
48
49static int8_t baptab[305] = {
50 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
51 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
52 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
53 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
54 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
55 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, /* 93 padding elems */
56
57 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 14, 14, 14, 14, 14,
58 14, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9,
59 9, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5,
60 5, 4, 4, -3, -3, 3, 3, 3, -2, -2, -1, -1, -1, -1, -1, 0,
61
62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
64 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
66 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
68 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
69 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
70 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
71 0, 0, 0, 0 /* 148 padding elems */
72};
73
74static int bndtab[30] = {21, 22, 23, 24, 25, 26, 27, 28, 31, 34,
75 37, 40, 43, 46, 49, 55, 61, 67, 73, 79,
76 85, 97, 109, 121, 133, 157, 181, 205, 229, 253};
77
78static int8_t latab[256] = {
79 -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53,
80 -52, -52, -51, -50, -49, -48, -47, -47, -46, -45, -44, -44,
81 -43, -42, -41, -41, -40, -39, -38, -38, -37, -36, -36, -35,
82 -35, -34, -33, -33, -32, -32, -31, -30, -30, -29, -29, -28,
83 -28, -27, -27, -26, -26, -25, -25, -24, -24, -23, -23, -22,
84 -22, -21, -21, -21, -20, -20, -19, -19, -19, -18, -18, -18,
85 -17, -17, -17, -16, -16, -16, -15, -15, -15, -14, -14, -14,
86 -13, -13, -13, -13, -12, -12, -12, -12, -11, -11, -11, -11,
87 -10, -10, -10, -10, -10, -9, -9, -9, -9, -9, -8, -8,
88 -8, -8, -8, -8, -7, -7, -7, -7, -7, -7, -6, -6,
89 -6, -6, -6, -6, -6, -6, -5, -5, -5, -5, -5, -5,
90 -5, -5, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
91 -4, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
92 -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2,
93 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1,
94 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
95 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
96 -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0
101};
102
103#define UPDATE_LEAK() \
104do { \
105 fastleak += fdecay; \
106 if (fastleak > psd + fgain) \
107 fastleak = psd + fgain; \
108 slowleak += sdecay; \
109 if (slowleak > psd + sgain) \
110 slowleak = psd + sgain; \
111} while (0)
112
113#define COMPUTE_MASK() \
114do { \
115 if (psd > dbknee) \
116 mask -= (psd - dbknee) >> 2; \
117 if (mask > hth [i >> halfrate]) \
118 mask = hth [i >> halfrate]; \
119 mask -= snroffset + 128 * deltba[i]; \
120 mask = (mask > 0) ? 0 : ((-mask) >> 5); \
121 mask -= floor; \
122} while (0)
123
124void a52_bit_allocate (a52_state_t * state, ba_t * ba, int bndstart,
125 int start, int end, int fastleak, int slowleak,
126 expbap_t * expbap)
127{
128 static int slowgain[4] = {0x540, 0x4d8, 0x478, 0x410};
129 static int dbpbtab[4] = {0xc00, 0x500, 0x300, 0x100};
130 static int floortab[8] = {0x910, 0x950, 0x990, 0x9d0,
131 0xa10, 0xa90, 0xb10, 0x1400};
132
133 int i, j;
134 uint8_t * exp;
135 int8_t * bap;
136 int fdecay, fgain, sdecay, sgain, dbknee, floor, snroffset;
137 int psd, mask;
138 int8_t * deltba;
139 int * hth;
140 int halfrate;
141
142 halfrate = state->halfrate;
143 fdecay = (63 + 20 * ((state->bai >> 7) & 3)) >> halfrate; /* fdcycod */
144 fgain = 128 + 128 * (ba->bai & 7); /* fgaincod */
145 sdecay = (15 + 2 * (state->bai >> 9)) >> halfrate; /* sdcycod */
146 sgain = slowgain[(state->bai >> 5) & 3]; /* sgaincod */
147 dbknee = dbpbtab[(state->bai >> 3) & 3]; /* dbpbcod */
148 hth = hthtab[state->fscod];
149 /*
150 * if there is no delta bit allocation, make deltba point to an area
151 * known to contain zeroes. baptab+156 here.
152 */
153 deltba = (ba->deltbae == DELTA_BIT_NONE) ? baptab + 156 : ba->deltba;
154 floor = floortab[state->bai & 7]; /* floorcod */
155 snroffset = 960 - 64 * state->csnroffst - 4 * (ba->bai >> 3) + floor;
156 floor >>= 5;
157
158 exp = expbap->exp;
159 bap = expbap->bap;
160
161 i = bndstart;
162 j = start;
163 if (start == 0) { /* not the coupling channel */
164 int lowcomp;
165
166 lowcomp = 0;
167 j = end - 1;
168 do {
169 if (i < j) {
170 if (exp[i+1] == exp[i] - 2)
171 lowcomp = 384;
172 else if (lowcomp && (exp[i+1] > exp[i]))
173 lowcomp -= 64;
174 }
175 psd = 128 * exp[i];
176 mask = psd + fgain + lowcomp;
177 COMPUTE_MASK ();
178 bap[i] = (baptab+156)[mask + 4 * exp[i]];
179 i++;
180 } while ((i < 3) || ((i < 7) && (exp[i] > exp[i-1])));
181 fastleak = psd + fgain;
182 slowleak = psd + sgain;
183
184 while (i < 7) {
185 if (i < j) {
186 if (exp[i+1] == exp[i] - 2)
187 lowcomp = 384;
188 else if (lowcomp && (exp[i+1] > exp[i]))
189 lowcomp -= 64;
190 }
191 psd = 128 * exp[i];
192 UPDATE_LEAK ();
193 mask = ((fastleak + lowcomp < slowleak) ?
194 fastleak + lowcomp : slowleak);
195 COMPUTE_MASK ();
196 bap[i] = (baptab+156)[mask + 4 * exp[i]];
197 i++;
198 }
199
200 if (end == 7) /* lfe channel */
201 return;
202
203 do {
204 if (exp[i+1] == exp[i] - 2)
205 lowcomp = 320;
206 else if (lowcomp && (exp[i+1] > exp[i]))
207 lowcomp -= 64;
208 psd = 128 * exp[i];
209 UPDATE_LEAK ();
210 mask = ((fastleak + lowcomp < slowleak) ?
211 fastleak + lowcomp : slowleak);
212 COMPUTE_MASK ();
213 bap[i] = (baptab+156)[mask + 4 * exp[i]];
214 i++;
215 } while (i < 20);
216
217 while (lowcomp > 128) { /* two iterations maximum */
218 lowcomp -= 128;
219 psd = 128 * exp[i];
220 UPDATE_LEAK ();
221 mask = ((fastleak + lowcomp < slowleak) ?
222 fastleak + lowcomp : slowleak);
223 COMPUTE_MASK ();
224 bap[i] = (baptab+156)[mask + 4 * exp[i]];
225 i++;
226 }
227 j = i;
228 }
229
230 do {
231 int startband, endband;
232
233 startband = j;
234 endband = (bndtab[i-20] < end) ? bndtab[i-20] : end;
235 psd = 128 * exp[j++];
236 while (j < endband) {
237 int next, delta;
238
239 next = 128 * exp[j++];
240 delta = next - psd;
241 switch (delta >> 9) {
242 case -6: case -5: case -4: case -3: case -2:
243 psd = next;
244 break;
245 case -1:
246 psd = next + latab[(-delta) >> 1];
247 break;
248 case 0:
249 psd += latab[delta >> 1];
250 break;
251 }
252 }
253 /* minpsd = -289 */
254 UPDATE_LEAK ();
255 mask = (fastleak < slowleak) ? fastleak : slowleak;
256 COMPUTE_MASK ();
257 i++;
258 j = startband;
259 do {
260 /* max(mask+4*exp)=147=-(minpsd+fgain-deltba-snroffset)>>5+4*exp */
261 /* min(mask+4*exp)=-156=-(sgain-deltba-snroffset)>>5 */
262 bap[j] = (baptab+156)[mask + 4 * exp[j]];
263 } while (++j < endband);
264 } while (j < end);
265}
diff --git a/apps/codecs/liba52/bitstream.c b/apps/codecs/liba52/bitstream.c
new file mode 100644
index 0000000000..05e4940dc4
--- /dev/null
+++ b/apps/codecs/liba52/bitstream.c
@@ -0,0 +1,97 @@
1/*
2 * bitstream.c
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 *
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
8 *
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include "config.h"
25
26#include <inttypes.h>
27
28#include "a52.h"
29#include "a52_internal.h"
30#include "bitstream.h"
31
32#define BUFFER_SIZE 4096
33
34void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf)
35{
36 int align;
37
38 align = (long)buf & 3;
39 state->buffer_start = (uint32_t *) (buf - align);
40 state->bits_left = 0;
41 state->current_word = 0;
42 bitstream_get (state, align * 8);
43 bitstream_get_2 (state, 0); /* pretend function is used - keep gcc happy */
44}
45
46static inline void bitstream_fill_current (a52_state_t * state)
47{
48 uint32_t tmp;
49
50 tmp = *(state->buffer_start++);
51 state->current_word = swab32 (tmp);
52}
53
54/*
55 * The fast paths for _get is in the
56 * bitstream.h header file so it can be inlined.
57 *
58 * The "bottom half" of this routine is suffixed _bh
59 *
60 * -ah
61 */
62
63uint32_t a52_bitstream_get_bh (a52_state_t * state, uint32_t num_bits)
64{
65 uint32_t result;
66
67 num_bits -= state->bits_left;
68 result = ((state->current_word << (32 - state->bits_left)) >>
69 (32 - state->bits_left));
70
71 bitstream_fill_current (state);
72
73 if (num_bits != 0)
74 result = (result << num_bits) | (state->current_word >> (32 - num_bits));
75
76 state->bits_left = 32 - num_bits;
77
78 return result;
79}
80
81int32_t a52_bitstream_get_bh_2 (a52_state_t * state, uint32_t num_bits)
82{
83 int32_t result;
84
85 num_bits -= state->bits_left;
86 result = ((((int32_t)state->current_word) << (32 - state->bits_left)) >>
87 (32 - state->bits_left));
88
89 bitstream_fill_current(state);
90
91 if (num_bits != 0)
92 result = (result << num_bits) | (state->current_word >> (32 - num_bits));
93
94 state->bits_left = 32 - num_bits;
95
96 return result;
97}
diff --git a/apps/codecs/liba52/bitstream.h b/apps/codecs/liba52/bitstream.h
new file mode 100644
index 0000000000..f559fbf833
--- /dev/null
+++ b/apps/codecs/liba52/bitstream.h
@@ -0,0 +1,77 @@
1/*
2 * bitstream.h
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 *
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
8 *
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24/* (stolen from the kernel) */
25#ifdef WORDS_BIGENDIAN
26
27# define swab32(x) (x)
28
29#else
30
31# if 0 && defined (__i386__)
32
33# define swab32(x) __i386_swab32(x)
34 static inline const uint32_t __i386_swab32(uint32_t x)
35 {
36 __asm__("bswap %0" : "=r" (x) : "0" (x));
37 return x;
38 }
39
40# else
41
42# define swab32(x)\
43((((uint8_t*)&x)[0] << 24) | (((uint8_t*)&x)[1] << 16) | \
44 (((uint8_t*)&x)[2] << 8) | (((uint8_t*)&x)[3]))
45
46# endif
47#endif
48
49void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf);
50uint32_t a52_bitstream_get_bh (a52_state_t * state, uint32_t num_bits);
51int32_t a52_bitstream_get_bh_2 (a52_state_t * state, uint32_t num_bits);
52
53static inline uint32_t bitstream_get (a52_state_t * state, uint32_t num_bits)
54{
55 uint32_t result;
56
57 if (num_bits < state->bits_left) {
58 result = (state->current_word << (32 - state->bits_left)) >> (32 - num_bits);
59 state->bits_left -= num_bits;
60 return result;
61 }
62
63 return a52_bitstream_get_bh (state, num_bits);
64}
65
66static inline int32_t bitstream_get_2 (a52_state_t * state, uint32_t num_bits)
67{
68 int32_t result;
69
70 if (num_bits < state->bits_left) {
71 result = (((int32_t)state->current_word) << (32 - state->bits_left)) >> (32 - num_bits);
72 state->bits_left -= num_bits;
73 return result;
74 }
75
76 return a52_bitstream_get_bh_2 (state, num_bits);
77}
diff --git a/apps/codecs/liba52/config.h b/apps/codecs/liba52/config.h
new file mode 100644
index 0000000000..dc8515971c
--- /dev/null
+++ b/apps/codecs/liba52/config.h
@@ -0,0 +1,21 @@
1/* a52dec profiling */
2/* #undef A52DEC_GPROF */
3
4/* Define to 1 if you have the `memalign' function. */
5/* #undef HAVE_MEMALIGN 1 */
6
7/* liba52 djbfft support */
8/* #undef LIBA52_DJBFFT */
9
10/* a52 sample precision */
11/* #undef LIBA52_DOUBLE */
12
13/* use fixed-point arithmetic */
14#define LIBA52_FIXED
15
16/* Define to 1 if your processor stores words with the most significant byte
17 first (like Motorola and SPARC, unlike Intel and VAX). */
18
19/* Used in bitstream.h */
20
21#define WORDS_BIGENDIAN 1
diff --git a/apps/codecs/liba52/downmix.c b/apps/codecs/liba52/downmix.c
new file mode 100644
index 0000000000..5660951486
--- /dev/null
+++ b/apps/codecs/liba52/downmix.c
@@ -0,0 +1,685 @@
1/*
2 * downmix.c
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 *
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
8 *
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include "config.h"
25
26#include <string.h>
27#include <inttypes.h>
28
29#include "a52.h"
30#include "a52_internal.h"
31
32#define CONVERT(acmod,output) (((output) << 3) + (acmod))
33
34int a52_downmix_init (int input, int flags, level_t * level,
35 level_t clev, level_t slev)
36{
37 static uint8_t table[11][8] = {
38 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
39 A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO},
40 {A52_MONO, A52_MONO, A52_MONO, A52_MONO,
41 A52_MONO, A52_MONO, A52_MONO, A52_MONO},
42 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
43 A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO},
44 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
45 A52_STEREO, A52_3F, A52_STEREO, A52_3F},
46 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
47 A52_2F1R, A52_2F1R, A52_2F1R, A52_2F1R},
48 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
49 A52_2F1R, A52_3F1R, A52_2F1R, A52_3F1R},
50 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
51 A52_2F2R, A52_2F2R, A52_2F2R, A52_2F2R},
52 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
53 A52_2F2R, A52_3F2R, A52_2F2R, A52_3F2R},
54 {A52_CHANNEL1, A52_MONO, A52_MONO, A52_MONO,
55 A52_MONO, A52_MONO, A52_MONO, A52_MONO},
56 {A52_CHANNEL2, A52_MONO, A52_MONO, A52_MONO,
57 A52_MONO, A52_MONO, A52_MONO, A52_MONO},
58 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_DOLBY,
59 A52_DOLBY, A52_DOLBY, A52_DOLBY, A52_DOLBY}
60 };
61 int output;
62
63 output = flags & A52_CHANNEL_MASK;
64 if (output > A52_DOLBY)
65 return -1;
66
67 output = table[output][input & 7];
68
69 if (output == A52_STEREO &&
70 (input == A52_DOLBY || (input == A52_3F && clev == LEVEL (LEVEL_3DB))))
71 output = A52_DOLBY;
72
73 if (flags & A52_ADJUST_LEVEL) {
74 level_t adjust;
75
76 switch (CONVERT (input & 7, output)) {
77
78 case CONVERT (A52_3F, A52_MONO):
79 adjust = DIV (LEVEL_3DB, LEVEL (1) + clev);
80 break;
81
82 case CONVERT (A52_STEREO, A52_MONO):
83 case CONVERT (A52_2F2R, A52_2F1R):
84 case CONVERT (A52_3F2R, A52_3F1R):
85 level_3db:
86 adjust = LEVEL (LEVEL_3DB);
87 break;
88
89 case CONVERT (A52_3F2R, A52_2F1R):
90 if (clev < LEVEL (LEVEL_PLUS3DB - 1))
91 goto level_3db;
92 /* break thru */
93 case CONVERT (A52_3F, A52_STEREO):
94 case CONVERT (A52_3F1R, A52_2F1R):
95 case CONVERT (A52_3F1R, A52_2F2R):
96 case CONVERT (A52_3F2R, A52_2F2R):
97 adjust = DIV (1, LEVEL (1) + clev);
98 break;
99
100 case CONVERT (A52_2F1R, A52_MONO):
101 adjust = DIV (LEVEL_PLUS3DB, LEVEL (2) + slev);
102 break;
103
104 case CONVERT (A52_2F1R, A52_STEREO):
105 case CONVERT (A52_3F1R, A52_3F):
106 adjust = DIV (1, LEVEL (1) + MUL_C (slev, LEVEL_3DB));
107 break;
108
109 case CONVERT (A52_3F1R, A52_MONO):
110 adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + MUL_C (slev, 0.5));
111 break;
112
113 case CONVERT (A52_3F1R, A52_STEREO):
114 adjust = DIV (1, LEVEL (1) + clev + MUL_C (slev, LEVEL_3DB));
115 break;
116
117 case CONVERT (A52_2F2R, A52_MONO):
118 adjust = DIV (LEVEL_3DB, LEVEL (1) + slev);
119 break;
120
121 case CONVERT (A52_2F2R, A52_STEREO):
122 case CONVERT (A52_3F2R, A52_3F):
123 adjust = DIV (1, LEVEL (1) + slev);
124 break;
125
126 case CONVERT (A52_3F2R, A52_MONO):
127 adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + slev);
128 break;
129
130 case CONVERT (A52_3F2R, A52_STEREO):
131 adjust = DIV (1, LEVEL (1) + clev + slev);
132 break;
133
134 case CONVERT (A52_MONO, A52_DOLBY):
135 adjust = LEVEL (LEVEL_PLUS3DB);
136 break;
137
138 case CONVERT (A52_3F, A52_DOLBY):
139 case CONVERT (A52_2F1R, A52_DOLBY):
140 adjust = LEVEL (1 / (1 + LEVEL_3DB));
141 break;
142
143 case CONVERT (A52_3F1R, A52_DOLBY):
144 case CONVERT (A52_2F2R, A52_DOLBY):
145 adjust = LEVEL (1 / (1 + 2 * LEVEL_3DB));
146 break;
147
148 case CONVERT (A52_3F2R, A52_DOLBY):
149 adjust = LEVEL (1 / (1 + 3 * LEVEL_3DB));
150 break;
151
152 default:
153 return output;
154 }
155
156 *level = MUL_L (*level, adjust);
157 }
158
159 return output;
160}
161
162int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
163 level_t clev, level_t slev)
164{
165 level_t level_3db;
166
167 level_3db = MUL_C (level, LEVEL_3DB);
168
169 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
170
171 case CONVERT (A52_CHANNEL, A52_CHANNEL):
172 case CONVERT (A52_MONO, A52_MONO):
173 case CONVERT (A52_STEREO, A52_STEREO):
174 case CONVERT (A52_3F, A52_3F):
175 case CONVERT (A52_2F1R, A52_2F1R):
176 case CONVERT (A52_3F1R, A52_3F1R):
177 case CONVERT (A52_2F2R, A52_2F2R):
178 case CONVERT (A52_3F2R, A52_3F2R):
179 case CONVERT (A52_STEREO, A52_DOLBY):
180 coeff[0] = coeff[1] = coeff[2] = coeff[3] = coeff[4] = level;
181 return 0;
182
183 case CONVERT (A52_CHANNEL, A52_MONO):
184 coeff[0] = coeff[1] = MUL_C (level, LEVEL_6DB);
185 return 3;
186
187 case CONVERT (A52_STEREO, A52_MONO):
188 coeff[0] = coeff[1] = level_3db;
189 return 3;
190
191 case CONVERT (A52_3F, A52_MONO):
192 coeff[0] = coeff[2] = level_3db;
193 coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
194 return 7;
195
196 case CONVERT (A52_2F1R, A52_MONO):
197 coeff[0] = coeff[1] = level_3db;
198 coeff[2] = MUL_L (level_3db, slev);
199 return 7;
200
201 case CONVERT (A52_2F2R, A52_MONO):
202 coeff[0] = coeff[1] = level_3db;
203 coeff[2] = coeff[3] = MUL_L (level_3db, slev);
204 return 15;
205
206 case CONVERT (A52_3F1R, A52_MONO):
207 coeff[0] = coeff[2] = level_3db;
208 coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
209 coeff[3] = MUL_L (level_3db, slev);
210 return 15;
211
212 case CONVERT (A52_3F2R, A52_MONO):
213 coeff[0] = coeff[2] = level_3db;
214 coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
215 coeff[3] = coeff[4] = MUL_L (level_3db, slev);
216 return 31;
217
218 case CONVERT (A52_MONO, A52_DOLBY):
219 coeff[0] = level_3db;
220 return 0;
221
222 case CONVERT (A52_3F, A52_DOLBY):
223 coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
224 coeff[1] = level_3db;
225 return 7;
226
227 case CONVERT (A52_3F, A52_STEREO):
228 case CONVERT (A52_3F1R, A52_2F1R):
229 case CONVERT (A52_3F2R, A52_2F2R):
230 coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
231 coeff[1] = MUL_L (level, clev);
232 return 7;
233
234 case CONVERT (A52_2F1R, A52_DOLBY):
235 coeff[0] = coeff[1] = level;
236 coeff[2] = level_3db;
237 return 7;
238
239 case CONVERT (A52_2F1R, A52_STEREO):
240 coeff[0] = coeff[1] = level;
241 coeff[2] = MUL_L (level_3db, slev);
242 return 7;
243
244 case CONVERT (A52_3F1R, A52_DOLBY):
245 coeff[0] = coeff[2] = level;
246 coeff[1] = coeff[3] = level_3db;
247 return 15;
248
249 case CONVERT (A52_3F1R, A52_STEREO):
250 coeff[0] = coeff[2] = level;
251 coeff[1] = MUL_L (level, clev);
252 coeff[3] = MUL_L (level_3db, slev);
253 return 15;
254
255 case CONVERT (A52_2F2R, A52_DOLBY):
256 coeff[0] = coeff[1] = level;
257 coeff[2] = coeff[3] = level_3db;
258 return 15;
259
260 case CONVERT (A52_2F2R, A52_STEREO):
261 coeff[0] = coeff[1] = level;
262 coeff[2] = coeff[3] = MUL_L (level, slev);
263 return 15;
264
265 case CONVERT (A52_3F2R, A52_DOLBY):
266 coeff[0] = coeff[2] = level;
267 coeff[1] = coeff[3] = coeff[4] = level_3db;
268 return 31;
269
270 case CONVERT (A52_3F2R, A52_2F1R):
271 coeff[0] = coeff[2] = level;
272 coeff[1] = MUL_L (level, clev);
273 coeff[3] = coeff[4] = level_3db;
274 return 31;
275
276 case CONVERT (A52_3F2R, A52_STEREO):
277 coeff[0] = coeff[2] = level;
278 coeff[1] = MUL_L (level, clev);
279 coeff[3] = coeff[4] = MUL_L (level, slev);
280 return 31;
281
282 case CONVERT (A52_3F1R, A52_3F):
283 coeff[0] = coeff[1] = coeff[2] = level;
284 coeff[3] = MUL_L (level_3db, slev);
285 return 13;
286
287 case CONVERT (A52_3F2R, A52_3F):
288 coeff[0] = coeff[1] = coeff[2] = level;
289 coeff[3] = coeff[4] = MUL_L (level, slev);
290 return 29;
291
292 case CONVERT (A52_2F2R, A52_2F1R):
293 coeff[0] = coeff[1] = level;
294 coeff[2] = coeff[3] = level_3db;
295 return 12;
296
297 case CONVERT (A52_3F2R, A52_3F1R):
298 coeff[0] = coeff[1] = coeff[2] = level;
299 coeff[3] = coeff[4] = level_3db;
300 return 24;
301
302 case CONVERT (A52_2F1R, A52_2F2R):
303 coeff[0] = coeff[1] = level;
304 coeff[2] = level_3db;
305 return 0;
306
307 case CONVERT (A52_3F1R, A52_2F2R):
308 coeff[0] = coeff[2] = level;
309 coeff[1] = MUL_L (level, clev);
310 coeff[3] = level_3db;
311 return 7;
312
313 case CONVERT (A52_3F1R, A52_3F2R):
314 coeff[0] = coeff[1] = coeff[2] = level;
315 coeff[3] = level_3db;
316 return 0;
317
318 case CONVERT (A52_CHANNEL, A52_CHANNEL1):
319 coeff[0] = level;
320 coeff[1] = 0;
321 return 0;
322
323 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
324 coeff[0] = 0;
325 coeff[1] = level;
326 return 0;
327 }
328
329 return -1; /* NOTREACHED */
330}
331
332static void mix2to1 (sample_t * dest, sample_t * src, sample_t bias)
333{
334 int i;
335
336 for (i = 0; i < 256; i++)
337 dest[i] += BIAS (src[i]);
338}
339
340static void mix3to1 (sample_t * samples, sample_t bias)
341{
342 int i;
343
344 for (i = 0; i < 256; i++)
345 samples[i] += BIAS (samples[i + 256] + samples[i + 512]);
346}
347
348static void mix4to1 (sample_t * samples, sample_t bias)
349{
350 int i;
351
352 for (i = 0; i < 256; i++)
353 samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
354 samples[i + 768]);
355}
356
357static void mix5to1 (sample_t * samples, sample_t bias)
358{
359 int i;
360
361 for (i = 0; i < 256; i++)
362 samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
363 samples[i + 768] + samples[i + 1024]);
364}
365
366static void mix3to2 (sample_t * samples, sample_t bias)
367{
368 int i;
369 sample_t common;
370
371 for (i = 0; i < 256; i++) {
372 common = BIAS (samples[i + 256]);
373 samples[i] += common;
374 samples[i + 256] = samples[i + 512] + common;
375 }
376}
377
378static void mix21to2 (sample_t * left, sample_t * right, sample_t bias)
379{
380 int i;
381 sample_t common;
382
383 for (i = 0; i < 256; i++) {
384 common = BIAS (right[i + 256]);
385 left[i] += common;
386 right[i] += common;
387 }
388}
389
390static void mix21toS (sample_t * samples, sample_t bias)
391{
392 int i;
393 sample_t surround;
394
395 for (i = 0; i < 256; i++) {
396 surround = samples[i + 512];
397 samples[i] += BIAS (-surround);
398 samples[i + 256] += BIAS (surround);
399 }
400}
401
402static void mix31to2 (sample_t * samples, sample_t bias)
403{
404 int i;
405 sample_t common;
406
407 for (i = 0; i < 256; i++) {
408 common = BIAS (samples[i + 256] + samples[i + 768]);
409 samples[i] += common;
410 samples[i + 256] = samples[i + 512] + common;
411 }
412}
413
414static void mix31toS (sample_t * samples, sample_t bias)
415{
416 int i;
417 sample_t common, surround;
418
419 for (i = 0; i < 256; i++) {
420 common = BIAS (samples[i + 256]);
421 surround = samples[i + 768];
422 samples[i] += common - surround;
423 samples[i + 256] = samples[i + 512] + common + surround;
424 }
425}
426
427static void mix22toS (sample_t * samples, sample_t bias)
428{
429 int i;
430 sample_t surround;
431
432 for (i = 0; i < 256; i++) {
433 surround = samples[i + 512] + samples[i + 768];
434 samples[i] += BIAS (-surround);
435 samples[i + 256] += BIAS (surround);
436 }
437}
438
439static void mix32to2 (sample_t * samples, sample_t bias)
440{
441 int i;
442 sample_t common;
443
444 for (i = 0; i < 256; i++) {
445 common = BIAS (samples[i + 256]);
446 samples[i] += common + samples[i + 768];
447 samples[i + 256] = common + samples[i + 512] + samples[i + 1024];
448 }
449}
450
451static void mix32toS (sample_t * samples, sample_t bias)
452{
453 int i;
454 sample_t common, surround;
455
456 for (i = 0; i < 256; i++) {
457 common = BIAS (samples[i + 256]);
458 surround = samples[i + 768] + samples[i + 1024];
459 samples[i] += common - surround;
460 samples[i + 256] = samples[i + 512] + common + surround;
461 }
462}
463
464static void move2to1 (sample_t * src, sample_t * dest, sample_t bias)
465{
466 int i;
467
468 for (i = 0; i < 256; i++)
469 dest[i] = BIAS (src[i] + src[i + 256]);
470}
471
472static void zero (sample_t * samples)
473{
474 int i;
475
476 for (i = 0; i < 256; i++)
477 samples[i] = 0;
478}
479
480void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias,
481 level_t clev, level_t slev)
482{
483 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
484
485 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
486 memcpy (samples, samples + 256, 256 * sizeof (sample_t));
487 break;
488
489 case CONVERT (A52_CHANNEL, A52_MONO):
490 case CONVERT (A52_STEREO, A52_MONO):
491 mix_2to1:
492 mix2to1 (samples, samples + 256, bias);
493 break;
494
495 case CONVERT (A52_2F1R, A52_MONO):
496 if (slev == 0)
497 goto mix_2to1;
498 case CONVERT (A52_3F, A52_MONO):
499 mix_3to1:
500 mix3to1 (samples, bias);
501 break;
502
503 case CONVERT (A52_3F1R, A52_MONO):
504 if (slev == 0)
505 goto mix_3to1;
506 case CONVERT (A52_2F2R, A52_MONO):
507 if (slev == 0)
508 goto mix_2to1;
509 mix4to1 (samples, bias);
510 break;
511
512 case CONVERT (A52_3F2R, A52_MONO):
513 if (slev == 0)
514 goto mix_3to1;
515 mix5to1 (samples, bias);
516 break;
517
518 case CONVERT (A52_MONO, A52_DOLBY):
519 memcpy (samples + 256, samples, 256 * sizeof (sample_t));
520 break;
521
522 case CONVERT (A52_3F, A52_STEREO):
523 case CONVERT (A52_3F, A52_DOLBY):
524 mix_3to2:
525 mix3to2 (samples, bias);
526 break;
527
528 case CONVERT (A52_2F1R, A52_STEREO):
529 if (slev == 0)
530 break;
531 mix21to2 (samples, samples + 256, bias);
532 break;
533
534 case CONVERT (A52_2F1R, A52_DOLBY):
535 mix21toS (samples, bias);
536 break;
537
538 case CONVERT (A52_3F1R, A52_STEREO):
539 if (slev == 0)
540 goto mix_3to2;
541 mix31to2 (samples, bias);
542 break;
543
544 case CONVERT (A52_3F1R, A52_DOLBY):
545 mix31toS (samples, bias);
546 break;
547
548 case CONVERT (A52_2F2R, A52_STEREO):
549 if (slev == 0)
550 break;
551 mix2to1 (samples, samples + 512, bias);
552 mix2to1 (samples + 256, samples + 768, bias);
553 break;
554
555 case CONVERT (A52_2F2R, A52_DOLBY):
556 mix22toS (samples, bias);
557 break;
558
559 case CONVERT (A52_3F2R, A52_STEREO):
560 if (slev == 0)
561 goto mix_3to2;
562 mix32to2 (samples, bias);
563 break;
564
565 case CONVERT (A52_3F2R, A52_DOLBY):
566 mix32toS (samples, bias);
567 break;
568
569 case CONVERT (A52_3F1R, A52_3F):
570 if (slev == 0)
571 break;
572 mix21to2 (samples, samples + 512, bias);
573 break;
574
575 case CONVERT (A52_3F2R, A52_3F):
576 if (slev == 0)
577 break;
578 mix2to1 (samples, samples + 768, bias);
579 mix2to1 (samples + 512, samples + 1024, bias);
580 break;
581
582 case CONVERT (A52_3F1R, A52_2F1R):
583 mix3to2 (samples, bias);
584 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
585 break;
586
587 case CONVERT (A52_2F2R, A52_2F1R):
588 mix2to1 (samples + 512, samples + 768, bias);
589 break;
590
591 case CONVERT (A52_3F2R, A52_2F1R):
592 mix3to2 (samples, bias);
593 move2to1 (samples + 768, samples + 512, bias);
594 break;
595
596 case CONVERT (A52_3F2R, A52_3F1R):
597 mix2to1 (samples + 768, samples + 1024, bias);
598 break;
599
600 case CONVERT (A52_2F1R, A52_2F2R):
601 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
602 break;
603
604 case CONVERT (A52_3F1R, A52_2F2R):
605 mix3to2 (samples, bias);
606 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
607 break;
608
609 case CONVERT (A52_3F2R, A52_2F2R):
610 mix3to2 (samples, bias);
611 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
612 memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
613 break;
614
615 case CONVERT (A52_3F1R, A52_3F2R):
616 memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
617 break;
618 }
619}
620
621void a52_upmix (sample_t * samples, int acmod, int output)
622{
623 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
624
625 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
626 memcpy (samples + 256, samples, 256 * sizeof (sample_t));
627 break;
628
629 case CONVERT (A52_3F2R, A52_MONO):
630 zero (samples + 1024);
631 case CONVERT (A52_3F1R, A52_MONO):
632 case CONVERT (A52_2F2R, A52_MONO):
633 zero (samples + 768);
634 case CONVERT (A52_3F, A52_MONO):
635 case CONVERT (A52_2F1R, A52_MONO):
636 zero (samples + 512);
637 case CONVERT (A52_CHANNEL, A52_MONO):
638 case CONVERT (A52_STEREO, A52_MONO):
639 zero (samples + 256);
640 break;
641
642 case CONVERT (A52_3F2R, A52_STEREO):
643 case CONVERT (A52_3F2R, A52_DOLBY):
644 zero (samples + 1024);
645 case CONVERT (A52_3F1R, A52_STEREO):
646 case CONVERT (A52_3F1R, A52_DOLBY):
647 zero (samples + 768);
648 case CONVERT (A52_3F, A52_STEREO):
649 case CONVERT (A52_3F, A52_DOLBY):
650 mix_3to2:
651 memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
652 zero (samples + 256);
653 break;
654
655 case CONVERT (A52_2F2R, A52_STEREO):
656 case CONVERT (A52_2F2R, A52_DOLBY):
657 zero (samples + 768);
658 case CONVERT (A52_2F1R, A52_STEREO):
659 case CONVERT (A52_2F1R, A52_DOLBY):
660 zero (samples + 512);
661 break;
662
663 case CONVERT (A52_3F2R, A52_3F):
664 zero (samples + 1024);
665 case CONVERT (A52_3F1R, A52_3F):
666 case CONVERT (A52_2F2R, A52_2F1R):
667 zero (samples + 768);
668 break;
669
670 case CONVERT (A52_3F2R, A52_3F1R):
671 zero (samples + 1024);
672 break;
673
674 case CONVERT (A52_3F2R, A52_2F1R):
675 zero (samples + 1024);
676 case CONVERT (A52_3F1R, A52_2F1R):
677 mix_31to21:
678 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
679 goto mix_3to2;
680
681 case CONVERT (A52_3F2R, A52_2F2R):
682 memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
683 goto mix_31to21;
684 }
685}
diff --git a/apps/codecs/liba52/imdct.c b/apps/codecs/liba52/imdct.c
new file mode 100644
index 0000000000..1cb3814907
--- /dev/null
+++ b/apps/codecs/liba52/imdct.c
@@ -0,0 +1,429 @@
1/*
2 * imdct.c
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 *
6 * The ifft algorithms in this file have been largely inspired by Dan
7 * Bernstein's work, djbfft, available at http://cr.yp.to/djbfft.html
8 *
9 * This file is part of a52dec, a free ATSC A-52 stream decoder.
10 * See http://liba52.sourceforge.net/ for updates.
11 *
12 * a52dec is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * a52dec is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27#include "config.h"
28
29#include <math.h>
30#include <stdio.h>
31#ifdef LIBA52_DJBFFT
32#include <fftc4.h>
33#include <fftc8.h>
34#endif
35#ifndef M_PI
36#define M_PI 3.1415926535897932384626433832795029
37#endif
38#include <inttypes.h>
39
40#include "a52.h"
41#include "a52_internal.h"
42#include "mm_accel.h"
43
44typedef struct complex_s {
45 sample_t real;
46 sample_t imag;
47} complex_t;
48
49static uint8_t fftorder[] = {
50 0,128, 64,192, 32,160,224, 96, 16,144, 80,208,240,112, 48,176,
51 8,136, 72,200, 40,168,232,104,248,120, 56,184, 24,152,216, 88,
52 4,132, 68,196, 36,164,228,100, 20,148, 84,212,244,116, 52,180,
53 252,124, 60,188, 28,156,220, 92, 12,140, 76,204,236,108, 44,172,
54 2,130, 66,194, 34,162,226, 98, 18,146, 82,210,242,114, 50,178,
55 10,138, 74,202, 42,170,234,106,250,122, 58,186, 26,154,218, 90,
56 254,126, 62,190, 30,158,222, 94, 14,142, 78,206,238,110, 46,174,
57 6,134, 70,198, 38,166,230,102,246,118, 54,182, 22,150,214, 86
58};
59
60/* Root values for IFFT */
61static sample_t roots16[3];
62static sample_t roots32[7];
63static sample_t roots64[15];
64static sample_t roots128[31];
65
66/* Twiddle factors for IMDCT */
67static complex_t pre1[128];
68static complex_t post1[64];
69static complex_t pre2[64];
70static complex_t post2[32];
71
72static sample_t a52_imdct_window[256];
73
74static void (* ifft128) (complex_t * buf);
75static void (* ifft64) (complex_t * buf);
76
77static inline void ifft2 (complex_t * buf)
78{
79 sample_t r, i;
80
81 r = buf[0].real;
82 i = buf[0].imag;
83 buf[0].real += buf[1].real;
84 buf[0].imag += buf[1].imag;
85 buf[1].real = r - buf[1].real;
86 buf[1].imag = i - buf[1].imag;
87}
88
89static inline void ifft4 (complex_t * buf)
90{
91 sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
92
93 tmp1 = buf[0].real + buf[1].real;
94 tmp2 = buf[3].real + buf[2].real;
95 tmp3 = buf[0].imag + buf[1].imag;
96 tmp4 = buf[2].imag + buf[3].imag;
97 tmp5 = buf[0].real - buf[1].real;
98 tmp6 = buf[0].imag - buf[1].imag;
99 tmp7 = buf[2].imag - buf[3].imag;
100 tmp8 = buf[3].real - buf[2].real;
101
102 buf[0].real = tmp1 + tmp2;
103 buf[0].imag = tmp3 + tmp4;
104 buf[2].real = tmp1 - tmp2;
105 buf[2].imag = tmp3 - tmp4;
106 buf[1].real = tmp5 + tmp7;
107 buf[1].imag = tmp6 + tmp8;
108 buf[3].real = tmp5 - tmp7;
109 buf[3].imag = tmp6 - tmp8;
110}
111
112/* basic radix-2 ifft butterfly */
113
114#define BUTTERFLY_0(t0,t1,W0,W1,d0,d1) do { \
115 t0 = MUL (W1, d1) + MUL (W0, d0); \
116 t1 = MUL (W0, d1) - MUL (W1, d0); \
117} while (0)
118
119/* radix-2 ifft butterfly with bias */
120
121#define BUTTERFLY_B(t0,t1,W0,W1,d0,d1) do { \
122 t0 = BIAS (MUL (d1, W1) + MUL (d0, W0)); \
123 t1 = BIAS (MUL (d1, W0) - MUL (d0, W1)); \
124} while (0)
125
126/* the basic split-radix ifft butterfly */
127
128#define BUTTERFLY(a0,a1,a2,a3,wr,wi) do { \
129 BUTTERFLY_0 (tmp5, tmp6, wr, wi, a2.real, a2.imag); \
130 BUTTERFLY_0 (tmp8, tmp7, wr, wi, a3.imag, a3.real); \
131 tmp1 = tmp5 + tmp7; \
132 tmp2 = tmp6 + tmp8; \
133 tmp3 = tmp6 - tmp8; \
134 tmp4 = tmp7 - tmp5; \
135 a2.real = a0.real - tmp1; \
136 a2.imag = a0.imag - tmp2; \
137 a3.real = a1.real - tmp3; \
138 a3.imag = a1.imag - tmp4; \
139 a0.real += tmp1; \
140 a0.imag += tmp2; \
141 a1.real += tmp3; \
142 a1.imag += tmp4; \
143} while (0)
144
145/* split-radix ifft butterfly, specialized for wr=1 wi=0 */
146
147#define BUTTERFLY_ZERO(a0,a1,a2,a3) do { \
148 tmp1 = a2.real + a3.real; \
149 tmp2 = a2.imag + a3.imag; \
150 tmp3 = a2.imag - a3.imag; \
151 tmp4 = a3.real - a2.real; \
152 a2.real = a0.real - tmp1; \
153 a2.imag = a0.imag - tmp2; \
154 a3.real = a1.real - tmp3; \
155 a3.imag = a1.imag - tmp4; \
156 a0.real += tmp1; \
157 a0.imag += tmp2; \
158 a1.real += tmp3; \
159 a1.imag += tmp4; \
160} while (0)
161
162/* split-radix ifft butterfly, specialized for wr=wi */
163
164#define BUTTERFLY_HALF(a0,a1,a2,a3,w) do { \
165 tmp5 = MUL (a2.real + a2.imag, w); \
166 tmp6 = MUL (a2.imag - a2.real, w); \
167 tmp7 = MUL (a3.real - a3.imag, w); \
168 tmp8 = MUL (a3.imag + a3.real, w); \
169 tmp1 = tmp5 + tmp7; \
170 tmp2 = tmp6 + tmp8; \
171 tmp3 = tmp6 - tmp8; \
172 tmp4 = tmp7 - tmp5; \
173 a2.real = a0.real - tmp1; \
174 a2.imag = a0.imag - tmp2; \
175 a3.real = a1.real - tmp3; \
176 a3.imag = a1.imag - tmp4; \
177 a0.real += tmp1; \
178 a0.imag += tmp2; \
179 a1.real += tmp3; \
180 a1.imag += tmp4; \
181} while (0)
182
183static inline void ifft8 (complex_t * buf)
184{
185 sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
186
187 ifft4 (buf);
188 ifft2 (buf + 4);
189 ifft2 (buf + 6);
190 BUTTERFLY_ZERO (buf[0], buf[2], buf[4], buf[6]);
191 BUTTERFLY_HALF (buf[1], buf[3], buf[5], buf[7], roots16[1]);
192}
193
194static void ifft_pass (complex_t * buf, sample_t * weight, int n)
195{
196 complex_t * buf1;
197 complex_t * buf2;
198 complex_t * buf3;
199 sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
200 int i;
201
202 buf++;
203 buf1 = buf + n;
204 buf2 = buf + 2 * n;
205 buf3 = buf + 3 * n;
206
207 BUTTERFLY_ZERO (buf[-1], buf1[-1], buf2[-1], buf3[-1]);
208
209 i = n - 1;
210
211 do {
212 BUTTERFLY (buf[0], buf1[0], buf2[0], buf3[0],
213 weight[0], weight[2*i-n]);
214 buf++;
215 buf1++;
216 buf2++;
217 buf3++;
218 weight++;
219 } while (--i);
220}
221
222static void ifft16 (complex_t * buf)
223{
224 ifft8 (buf);
225 ifft4 (buf + 8);
226 ifft4 (buf + 12);
227 ifft_pass (buf, roots16, 4);
228}
229
230static void ifft32 (complex_t * buf)
231{
232 ifft16 (buf);
233 ifft8 (buf + 16);
234 ifft8 (buf + 24);
235 ifft_pass (buf, roots32, 8);
236}
237
238static void ifft64_c (complex_t * buf)
239{
240 ifft32 (buf);
241 ifft16 (buf + 32);
242 ifft16 (buf + 48);
243 ifft_pass (buf, roots64, 16);
244}
245
246static void ifft128_c (complex_t * buf)
247{
248 ifft32 (buf);
249 ifft16 (buf + 32);
250 ifft16 (buf + 48);
251 ifft_pass (buf, roots64, 16);
252
253 ifft32 (buf + 64);
254 ifft32 (buf + 96);
255 ifft_pass (buf, roots128, 32);
256}
257
258void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias)
259{
260 int i, k;
261 sample_t t_r, t_i, a_r, a_i, b_r, b_i, w_1, w_2;
262 const sample_t * window = a52_imdct_window;
263 complex_t buf[128];
264
265 for (i = 0; i < 128; i++) {
266 k = fftorder[i];
267 t_r = pre1[i].real;
268 t_i = pre1[i].imag;
269 BUTTERFLY_0 (buf[i].real, buf[i].imag, t_r, t_i, data[k], data[255-k]);
270 }
271
272 ifft128 (buf);
273
274 /* Post IFFT complex multiply plus IFFT complex conjugate*/
275 /* Window and convert to real valued signal */
276 for (i = 0; i < 64; i++) {
277 /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
278 t_r = post1[i].real;
279 t_i = post1[i].imag;
280 BUTTERFLY_0 (a_r, a_i, t_i, t_r, buf[i].imag, buf[i].real);
281 BUTTERFLY_0 (b_r, b_i, t_r, t_i, buf[127-i].imag, buf[127-i].real);
282
283 w_1 = window[2*i];
284 w_2 = window[255-2*i];
285 BUTTERFLY_B (data[255-2*i], data[2*i], w_2, w_1, a_r, delay[2*i]);
286 delay[2*i] = a_i;
287
288 w_1 = window[2*i+1];
289 w_2 = window[254-2*i];
290 BUTTERFLY_B (data[2*i+1], data[254-2*i], w_1, w_2, b_r, delay[2*i+1]);
291 delay[2*i+1] = b_i;
292 }
293}
294
295void a52_imdct_256 (sample_t * data, sample_t * delay, sample_t bias)
296{
297 int i, k;
298 sample_t t_r, t_i, a_r, a_i, b_r, b_i, c_r, c_i, d_r, d_i, w_1, w_2;
299 const sample_t * window = a52_imdct_window;
300 complex_t buf1[64], buf2[64];
301
302 /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
303 for (i = 0; i < 64; i++) {
304 k = fftorder[i];
305 t_r = pre2[i].real;
306 t_i = pre2[i].imag;
307 BUTTERFLY_0 (buf1[i].real, buf1[i].imag, t_r, t_i, data[k], data[254-k]);
308 BUTTERFLY_0 (buf2[i].real, buf2[i].imag, t_r, t_i, data[k+1], data[255-k]);
309 }
310
311 ifft64 (buf1);
312 ifft64 (buf2);
313
314 /* Post IFFT complex multiply */
315 /* Window and convert to real valued signal */
316 for (i = 0; i < 32; i++) {
317 /* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */
318 t_r = post2[i].real;
319 t_i = post2[i].imag;
320 BUTTERFLY_0 (a_r, a_i, t_i, t_r, buf1[i].imag, buf1[i].real);
321 BUTTERFLY_0 (b_r, b_i, t_r, t_i, buf1[63-i].imag, buf1[63-i].real);
322 BUTTERFLY_0 (c_r, c_i, t_i, t_r, buf2[i].imag, buf2[i].real);
323 BUTTERFLY_0 (d_r, d_i, t_r, t_i, buf2[63-i].imag, buf2[63-i].real);
324
325 w_1 = window[2*i];
326 w_2 = window[255-2*i];
327 BUTTERFLY_B (data[255-2*i], data[2*i], w_2, w_1, a_r, delay[2*i]);
328 delay[2*i] = c_i;
329
330 w_1 = window[128+2*i];
331 w_2 = window[127-2*i];
332 BUTTERFLY_B (data[128+2*i], data[127-2*i], w_1, w_2, a_i, delay[127-2*i]);
333 delay[127-2*i] = c_r;
334
335 w_1 = window[2*i+1];
336 w_2 = window[254-2*i];
337 BUTTERFLY_B (data[254-2*i], data[2*i+1], w_2, w_1, b_i, delay[2*i+1]);
338 delay[2*i+1] = d_r;
339
340 w_1 = window[129+2*i];
341 w_2 = window[126-2*i];
342 BUTTERFLY_B (data[129+2*i], data[126-2*i], w_1, w_2, b_r, delay[126-2*i]);
343 delay[126-2*i] = d_i;
344 }
345}
346
347static double besselI0 (double x)
348{
349 double bessel = 1;
350 int i = 100;
351
352 do
353 bessel = bessel * x / (i * i) + 1;
354 while (--i);
355 return bessel;
356}
357
358void a52_imdct_init (uint32_t mm_accel)
359{
360 int i, k;
361 double sum;
362 double local_imdct_window[256];
363
364 /* compute imdct window - kaiser-bessel derived window, alpha = 5.0 */
365 sum = 0;
366 for (i = 0; i < 256; i++) {
367 sum += besselI0 (i * (256 - i) * (5 * M_PI / 256) * (5 * M_PI / 256));
368 local_imdct_window[i] = sum;
369 }
370 sum++;
371 for (i = 0; i < 256; i++)
372 a52_imdct_window[i] = SAMPLE (sqrt (local_imdct_window[i] / sum));
373
374 for (i = 0; i < 3; i++)
375 roots16[i] = SAMPLE (cos ((M_PI / 8) * (i + 1)));
376
377 for (i = 0; i < 7; i++)
378 roots32[i] = SAMPLE (cos ((M_PI / 16) * (i + 1)));
379
380 for (i = 0; i < 15; i++)
381 roots64[i] = SAMPLE (cos ((M_PI / 32) * (i + 1)));
382
383 for (i = 0; i < 31; i++)
384 roots128[i] = SAMPLE (cos ((M_PI / 64) * (i + 1)));
385
386 for (i = 0; i < 64; i++) {
387 k = fftorder[i] / 2 + 64;
388 pre1[i].real = SAMPLE (cos ((M_PI / 256) * (k - 0.25)));
389 pre1[i].imag = SAMPLE (sin ((M_PI / 256) * (k - 0.25)));
390 }
391
392 for (i = 64; i < 128; i++) {
393 k = fftorder[i] / 2 + 64;
394 pre1[i].real = SAMPLE (-cos ((M_PI / 256) * (k - 0.25)));
395 pre1[i].imag = SAMPLE (-sin ((M_PI / 256) * (k - 0.25)));
396 }
397
398 for (i = 0; i < 64; i++) {
399 post1[i].real = SAMPLE (cos ((M_PI / 256) * (i + 0.5)));
400 post1[i].imag = SAMPLE (sin ((M_PI / 256) * (i + 0.5)));
401 }
402
403 for (i = 0; i < 64; i++) {
404 k = fftorder[i] / 4;
405 pre2[i].real = SAMPLE (cos ((M_PI / 128) * (k - 0.25)));
406 pre2[i].imag = SAMPLE (sin ((M_PI / 128) * (k - 0.25)));
407 }
408
409 for (i = 0; i < 32; i++) {
410 post2[i].real = SAMPLE (cos ((M_PI / 128) * (i + 0.5)));
411 post2[i].imag = SAMPLE (sin ((M_PI / 128) * (i + 0.5)));
412 }
413
414#ifdef LIBA52_DJBFFT
415 if (mm_accel & MM_ACCEL_DJBFFT) {
416#ifndef LIBA52_DOUBLE
417 ifft128 = (void (*) (complex_t *)) fftc4_un128;
418 ifft64 = (void (*) (complex_t *)) fftc4_un64;
419#else
420 ifft128 = (void (*) (complex_t *)) fftc8_un128;
421 ifft64 = (void (*) (complex_t *)) fftc8_un64;
422#endif
423 } else
424#endif
425 {
426 ifft128 = ifft128_c;
427 ifft64 = ifft64_c;
428 }
429}
diff --git a/apps/codecs/liba52/mm_accel.h b/apps/codecs/liba52/mm_accel.h
new file mode 100644
index 0000000000..f569787aec
--- /dev/null
+++ b/apps/codecs/liba52/mm_accel.h
@@ -0,0 +1,37 @@
1/*
2 * mm_accel.h
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 *
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
8 *
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#ifndef MM_ACCEL_H
25#define MM_ACCEL_H
26
27/* generic accelerations */
28#define MM_ACCEL_DJBFFT 0x00000001
29
30/* x86 accelerations */
31#define MM_ACCEL_X86_MMX 0x80000000
32#define MM_ACCEL_X86_3DNOW 0x40000000
33#define MM_ACCEL_X86_MMXEXT 0x20000000
34
35uint32_t mm_accel (void);
36
37#endif /* MM_ACCEL_H */
diff --git a/apps/codecs/liba52/parse.c b/apps/codecs/liba52/parse.c
new file mode 100644
index 0000000000..505a335f09
--- /dev/null
+++ b/apps/codecs/liba52/parse.c
@@ -0,0 +1,946 @@
1/*
2 * parse.c
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 *
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
8 *
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include "config.h"
25
26#include <stdlib.h>
27#include <string.h>
28#include <inttypes.h>
29
30#include "a52.h"
31#include "a52_internal.h"
32#include "bitstream.h"
33#include "tables.h"
34
35#if defined(HAVE_MEMALIGN) && !defined(__cplusplus)
36/* some systems have memalign() but no declaration for it */
37void * memalign (size_t align, size_t size);
38#else
39/* assume malloc alignment is sufficient */
40#define memalign(align,size) malloc (size)
41#endif
42
43typedef struct {
44 quantizer_t q1[2];
45 quantizer_t q2[2];
46 quantizer_t q4;
47 int q1_ptr;
48 int q2_ptr;
49 int q4_ptr;
50} quantizer_set_t;
51
52static uint8_t halfrate[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
53
54a52_state_t * a52_init (uint32_t mm_accel)
55{
56 a52_state_t * state;
57 int i;
58
59 state = (a52_state_t *) malloc (sizeof (a52_state_t));
60 if (state == NULL)
61 return NULL;
62
63 state->samples = (sample_t *) memalign (16, 256 * 12 * sizeof (sample_t));
64 if (state->samples == NULL) {
65 free (state);
66 return NULL;
67 }
68
69 for (i = 0; i < 256 * 12; i++)
70 state->samples[i] = 0;
71
72 state->downmixed = 1;
73
74 state->lfsr_state = 1;
75
76 a52_imdct_init (mm_accel);
77
78 return state;
79}
80
81sample_t * a52_samples (a52_state_t * state)
82{
83 return state->samples;
84}
85
86int a52_syncinfo (uint8_t * buf, int * flags,
87 int * sample_rate, int * bit_rate)
88{
89 static int rate[] = { 32, 40, 48, 56, 64, 80, 96, 112,
90 128, 160, 192, 224, 256, 320, 384, 448,
91 512, 576, 640};
92 static uint8_t lfeon[8] = {0x10, 0x10, 0x04, 0x04, 0x04, 0x01, 0x04, 0x01};
93 int frmsizecod;
94 int bitrate;
95 int half;
96 int acmod;
97
98 if ((buf[0] != 0x0b) || (buf[1] != 0x77)) /* syncword */
99 return 0;
100
101 if (buf[5] >= 0x60) /* bsid >= 12 */
102 return 0;
103 half = halfrate[buf[5] >> 3];
104
105 /* acmod, dsurmod and lfeon */
106 acmod = buf[6] >> 5;
107 *flags = ((((buf[6] & 0xf8) == 0x50) ? A52_DOLBY : acmod) |
108 ((buf[6] & lfeon[acmod]) ? A52_LFE : 0));
109
110 frmsizecod = buf[4] & 63;
111 if (frmsizecod >= 38)
112 return 0;
113 bitrate = rate [frmsizecod >> 1];
114 *bit_rate = (bitrate * 1000) >> half;
115
116 switch (buf[4] & 0xc0) {
117 case 0:
118 *sample_rate = 48000 >> half;
119 return 4 * bitrate;
120 case 0x40:
121 *sample_rate = 44100 >> half;
122 return 2 * (320 * bitrate / 147 + (frmsizecod & 1));
123 case 0x80:
124 *sample_rate = 32000 >> half;
125 return 6 * bitrate;
126 default:
127 return 0;
128 }
129}
130
131int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
132 level_t * level, sample_t bias)
133{
134 static level_t clev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_45DB),
135 LEVEL (LEVEL_6DB), LEVEL (LEVEL_45DB) };
136 static level_t slev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_6DB),
137 0, LEVEL (LEVEL_6DB) };
138 int chaninfo;
139 int acmod;
140
141 state->fscod = buf[4] >> 6;
142 state->halfrate = halfrate[buf[5] >> 3];
143 state->acmod = acmod = buf[6] >> 5;
144
145 a52_bitstream_set_ptr (state, buf + 6);
146 bitstream_get (state, 3); /* skip acmod we already parsed */
147
148 if ((acmod == 2) && (bitstream_get (state, 2) == 2)) /* dsurmod */
149 acmod = A52_DOLBY;
150
151 state->clev = state->slev = 0;
152
153 if ((acmod & 1) && (acmod != 1))
154 state->clev = clev[bitstream_get (state, 2)]; /* cmixlev */
155
156 if (acmod & 4)
157 state->slev = slev[bitstream_get (state, 2)]; /* surmixlev */
158
159 state->lfeon = bitstream_get (state, 1);
160
161 state->output = a52_downmix_init (acmod, *flags, level,
162 state->clev, state->slev);
163 if (state->output < 0)
164 return 1;
165 if (state->lfeon && (*flags & A52_LFE))
166 state->output |= A52_LFE;
167 *flags = state->output;
168 /* the 2* compensates for differences in imdct */
169 state->dynrng = state->level = MUL_C (*level, 2);
170 state->bias = bias;
171 state->dynrnge = 1;
172 state->dynrngcall = NULL;
173 state->cplba.deltbae = DELTA_BIT_NONE;
174 state->ba[0].deltbae = state->ba[1].deltbae = state->ba[2].deltbae =
175 state->ba[3].deltbae = state->ba[4].deltbae = DELTA_BIT_NONE;
176
177 chaninfo = !acmod;
178 do {
179 bitstream_get (state, 5); /* dialnorm */
180 if (bitstream_get (state, 1)) /* compre */
181 bitstream_get (state, 8); /* compr */
182 if (bitstream_get (state, 1)) /* langcode */
183 bitstream_get (state, 8); /* langcod */
184 if (bitstream_get (state, 1)) /* audprodie */
185 bitstream_get (state, 7); /* mixlevel + roomtyp */
186 } while (chaninfo--);
187
188 bitstream_get (state, 2); /* copyrightb + origbs */
189
190 if (bitstream_get (state, 1)) /* timecod1e */
191 bitstream_get (state, 14); /* timecod1 */
192 if (bitstream_get (state, 1)) /* timecod2e */
193 bitstream_get (state, 14); /* timecod2 */
194
195 if (bitstream_get (state, 1)) { /* addbsie */
196 int addbsil;
197
198 addbsil = bitstream_get (state, 6);
199 do {
200 bitstream_get (state, 8); /* addbsi */
201 } while (addbsil--);
202 }
203
204 return 0;
205}
206
207void a52_dynrng (a52_state_t * state,
208 level_t (* call) (level_t, void *), void * data)
209{
210 state->dynrnge = 0;
211 if (call) {
212 state->dynrnge = 1;
213 state->dynrngcall = call;
214 state->dynrngdata = data;
215 }
216}
217
218static int parse_exponents (a52_state_t * state, int expstr, int ngrps,
219 uint8_t exponent, uint8_t * dest)
220{
221 int exps;
222
223 while (ngrps--) {
224 exps = bitstream_get (state, 7);
225
226 exponent += exp_1[exps];
227 if (exponent > 24)
228 return 1;
229
230 switch (expstr) {
231 case EXP_D45:
232 *(dest++) = exponent;
233 *(dest++) = exponent;
234 case EXP_D25:
235 *(dest++) = exponent;
236 case EXP_D15:
237 *(dest++) = exponent;
238 }
239
240 exponent += exp_2[exps];
241 if (exponent > 24)
242 return 1;
243
244 switch (expstr) {
245 case EXP_D45:
246 *(dest++) = exponent;
247 *(dest++) = exponent;
248 case EXP_D25:
249 *(dest++) = exponent;
250 case EXP_D15:
251 *(dest++) = exponent;
252 }
253
254 exponent += exp_3[exps];
255 if (exponent > 24)
256 return 1;
257
258 switch (expstr) {
259 case EXP_D45:
260 *(dest++) = exponent;
261 *(dest++) = exponent;
262 case EXP_D25:
263 *(dest++) = exponent;
264 case EXP_D15:
265 *(dest++) = exponent;
266 }
267 }
268
269 return 0;
270}
271
272static int parse_deltba (a52_state_t * state, int8_t * deltba)
273{
274 int deltnseg, deltlen, delta, j;
275
276 memset (deltba, 0, 50);
277
278 deltnseg = bitstream_get (state, 3);
279 j = 0;
280 do {
281 j += bitstream_get (state, 5);
282 deltlen = bitstream_get (state, 4);
283 delta = bitstream_get (state, 3);
284 delta -= (delta >= 4) ? 3 : 4;
285 if (!deltlen)
286 continue;
287 if (j + deltlen >= 50)
288 return 1;
289 while (deltlen--)
290 deltba[j++] = delta;
291 } while (deltnseg--);
292
293 return 0;
294}
295
296static inline int zero_snr_offsets (int nfchans, a52_state_t * state)
297{
298 int i;
299
300 if ((state->csnroffst) ||
301 (state->chincpl && state->cplba.bai >> 3) || /* cplinu, fsnroffst */
302 (state->lfeon && state->lfeba.bai >> 3)) /* fsnroffst */
303 return 0;
304 for (i = 0; i < nfchans; i++)
305 if (state->ba[i].bai >> 3) /* fsnroffst */
306 return 0;
307 return 1;
308}
309
310static inline int16_t dither_gen (a52_state_t * state)
311{
312 int16_t nstate;
313
314 nstate = dither_lut[state->lfsr_state >> 8] ^ (state->lfsr_state << 8);
315
316 state->lfsr_state = (uint16_t) nstate;
317
318 return (3 * nstate) >> 2;
319}
320
321#ifndef LIBA52_FIXED
322#define COEFF(c,t,l,s,e) (c) = (t) * (s)[e]
323#else
324#define COEFF(c,_t,_l,s,e) do { \
325 quantizer_t t = (_t); \
326 level_t l = (_l); \
327 int shift = e - 5; \
328 sample_t tmp = t * (l >> 16) + ((t * (l & 0xffff)) >> 16); \
329 if (shift >= 0) \
330 (c) = tmp >> shift; \
331 else \
332 (c) = tmp << -shift; \
333} while (0)
334#endif
335
336static void coeff_get (a52_state_t * state, sample_t * coeff,
337 expbap_t * expbap, quantizer_set_t * quant,
338 level_t level, int dither, int end)
339{
340 int i;
341 uint8_t * exp;
342 int8_t * bap;
343
344#ifndef LIBA52_FIXED
345 sample_t factor[25];
346
347 for (i = 0; i <= 24; i++)
348 factor[i] = scale_factor[i] * level;
349#endif
350
351 exp = expbap->exp;
352 bap = expbap->bap;
353
354 for (i = 0; i < end; i++) {
355 int bapi;
356
357 bapi = bap[i];
358 switch (bapi) {
359 case 0:
360 if (dither) {
361 COEFF (coeff[i], dither_gen (state), level, factor, exp[i]);
362 continue;
363 } else {
364 coeff[i] = 0;
365 continue;
366 }
367
368 case -1:
369 if (quant->q1_ptr >= 0) {
370 COEFF (coeff[i], quant->q1[quant->q1_ptr--], level,
371 factor, exp[i]);
372 continue;
373 } else {
374 int code;
375
376 code = bitstream_get (state, 5);
377
378 quant->q1_ptr = 1;
379 quant->q1[0] = q_1_2[code];
380 quant->q1[1] = q_1_1[code];
381 COEFF (coeff[i], q_1_0[code], level, factor, exp[i]);
382 continue;
383 }
384
385 case -2:
386 if (quant->q2_ptr >= 0) {
387 COEFF (coeff[i], quant->q2[quant->q2_ptr--], level,
388 factor, exp[i]);
389 continue;
390 } else {
391 int code;
392
393 code = bitstream_get (state, 7);
394
395 quant->q2_ptr = 1;
396 quant->q2[0] = q_2_2[code];
397 quant->q2[1] = q_2_1[code];
398 COEFF (coeff[i], q_2_0[code], level, factor, exp[i]);
399 continue;
400 }
401
402 case 3:
403 COEFF (coeff[i], q_3[bitstream_get (state, 3)], level,
404 factor, exp[i]);
405 continue;
406
407 case -3:
408 if (quant->q4_ptr == 0) {
409 quant->q4_ptr = -1;
410 COEFF (coeff[i], quant->q4, level, factor, exp[i]);
411 continue;
412 } else {
413 int code;
414
415 code = bitstream_get (state, 7);
416
417 quant->q4_ptr = 0;
418 quant->q4 = q_4_1[code];
419 COEFF (coeff[i], q_4_0[code], level, factor, exp[i]);
420 continue;
421 }
422
423 case 4:
424 COEFF (coeff[i], q_5[bitstream_get (state, 4)], level,
425 factor, exp[i]);
426 continue;
427
428 default:
429 COEFF (coeff[i], bitstream_get_2 (state, bapi) << (16 - bapi),
430 level, factor, exp[i]);
431 }
432 }
433}
434
435static void coeff_get_coupling (a52_state_t * state, int nfchans,
436 level_t * coeff, sample_t (* samples)[256],
437 quantizer_set_t * quant, uint8_t dithflag[5])
438{
439 int cplbndstrc, bnd, i, i_end, ch;
440 uint8_t * exp;
441 int8_t * bap;
442 level_t cplco[5];
443
444 exp = state->cpl_expbap.exp;
445 bap = state->cpl_expbap.bap;
446 bnd = 0;
447 cplbndstrc = state->cplbndstrc;
448 i = state->cplstrtmant;
449 while (i < state->cplendmant) {
450 i_end = i + 12;
451 while (cplbndstrc & 1) {
452 cplbndstrc >>= 1;
453 i_end += 12;
454 }
455 cplbndstrc >>= 1;
456 for (ch = 0; ch < nfchans; ch++)
457 cplco[ch] = MUL_L (state->cplco[ch][bnd], coeff[ch]);
458 bnd++;
459
460 while (i < i_end) {
461 quantizer_t cplcoeff;
462 int bapi;
463
464 bapi = bap[i];
465 switch (bapi) {
466 case 0:
467 for (ch = 0; ch < nfchans; ch++)
468 if ((state->chincpl >> ch) & 1) {
469 if (dithflag[ch])
470#ifndef LIBA52_FIXED
471 samples[ch][i] = (scale_factor[exp[i]] *
472 cplco[ch] * dither_gen (state));
473#else
474 COEFF (samples[ch][i], dither_gen (state),
475 cplco[ch], scale_factor, exp[i]);
476#endif
477 else
478 samples[ch][i] = 0;
479 }
480 i++;
481 continue;
482
483 case -1:
484 if (quant->q1_ptr >= 0) {
485 cplcoeff = quant->q1[quant->q1_ptr--];
486 break;
487 } else {
488 int code;
489
490 code = bitstream_get (state, 5);
491
492 quant->q1_ptr = 1;
493 quant->q1[0] = q_1_2[code];
494 quant->q1[1] = q_1_1[code];
495 cplcoeff = q_1_0[code];
496 break;
497 }
498
499 case -2:
500 if (quant->q2_ptr >= 0) {
501 cplcoeff = quant->q2[quant->q2_ptr--];
502 break;
503 } else {
504 int code;
505
506 code = bitstream_get (state, 7);
507
508 quant->q2_ptr = 1;
509 quant->q2[0] = q_2_2[code];
510 quant->q2[1] = q_2_1[code];
511 cplcoeff = q_2_0[code];
512 break;
513 }
514
515 case 3:
516 cplcoeff = q_3[bitstream_get (state, 3)];
517 break;
518
519 case -3:
520 if (quant->q4_ptr == 0) {
521 quant->q4_ptr = -1;
522 cplcoeff = quant->q4;
523 break;
524 } else {
525 int code;
526
527 code = bitstream_get (state, 7);
528
529 quant->q4_ptr = 0;
530 quant->q4 = q_4_1[code];
531 cplcoeff = q_4_0[code];
532 break;
533 }
534
535 case 4:
536 cplcoeff = q_5[bitstream_get (state, 4)];
537 break;
538
539 default:
540 cplcoeff = bitstream_get_2 (state, bapi) << (16 - bapi);
541 }
542#ifndef LIBA52_FIXED
543 cplcoeff *= scale_factor[exp[i]];
544#endif
545 for (ch = 0; ch < nfchans; ch++)
546 if ((state->chincpl >> ch) & 1)
547#ifndef LIBA52_FIXED
548 samples[ch][i] = cplcoeff * cplco[ch];
549#else
550 COEFF (samples[ch][i], cplcoeff, cplco[ch],
551 scale_factor, exp[i]);
552#endif
553 i++;
554 }
555 }
556}
557
558int a52_block (a52_state_t * state)
559{
560 static const uint8_t nfchans_tbl[] = {2, 1, 2, 3, 3, 4, 4, 5, 1, 1, 2};
561 static int rematrix_band[4] = {25, 37, 61, 253};
562 int i, nfchans, chaninfo;
563 uint8_t cplexpstr, chexpstr[5], lfeexpstr, do_bit_alloc, done_cpl;
564 uint8_t blksw[5], dithflag[5];
565 level_t coeff[5];
566 int chanbias;
567 quantizer_set_t quant;
568 sample_t * samples;
569
570 nfchans = nfchans_tbl[state->acmod];
571
572 for (i = 0; i < nfchans; i++)
573 blksw[i] = bitstream_get (state, 1);
574
575 for (i = 0; i < nfchans; i++)
576 dithflag[i] = bitstream_get (state, 1);
577
578 chaninfo = !state->acmod;
579 do {
580 if (bitstream_get (state, 1)) { /* dynrnge */
581 int dynrng;
582
583 dynrng = bitstream_get_2 (state, 8);
584 if (state->dynrnge) {
585 level_t range;
586
587#if !defined(LIBA52_FIXED)
588 range = ((((dynrng & 0x1f) | 0x20) << 13) *
589 scale_factor[3 - (dynrng >> 5)]);
590#else
591 range = ((dynrng & 0x1f) | 0x20) << (21 + (dynrng >> 5));
592#endif
593 if (state->dynrngcall)
594 range = state->dynrngcall (range, state->dynrngdata);
595 state->dynrng = MUL_L (state->level, range);
596 }
597 }
598 } while (chaninfo--);
599
600 if (bitstream_get (state, 1)) { /* cplstre */
601 state->chincpl = 0;
602 if (bitstream_get (state, 1)) { /* cplinu */
603 static uint8_t bndtab[16] = {31, 35, 37, 39, 41, 42, 43, 44,
604 45, 45, 46, 46, 47, 47, 48, 48};
605 int cplbegf;
606 int cplendf;
607 int ncplsubnd;
608
609 for (i = 0; i < nfchans; i++)
610 state->chincpl |= bitstream_get (state, 1) << i;
611 switch (state->acmod) {
612 case 0: case 1:
613 return 1;
614 case 2:
615 state->phsflginu = bitstream_get (state, 1);
616 }
617 cplbegf = bitstream_get (state, 4);
618 cplendf = bitstream_get (state, 4);
619
620 if (cplendf + 3 - cplbegf < 0)
621 return 1;
622 state->ncplbnd = ncplsubnd = cplendf + 3 - cplbegf;
623 state->cplstrtbnd = bndtab[cplbegf];
624 state->cplstrtmant = cplbegf * 12 + 37;
625 state->cplendmant = cplendf * 12 + 73;
626
627 state->cplbndstrc = 0;
628 for (i = 0; i < ncplsubnd - 1; i++)
629 if (bitstream_get (state, 1)) {
630 state->cplbndstrc |= 1 << i;
631 state->ncplbnd--;
632 }
633 }
634 }
635
636 if (state->chincpl) { /* cplinu */
637 int j, cplcoe;
638
639 cplcoe = 0;
640 for (i = 0; i < nfchans; i++)
641 if ((state->chincpl) >> i & 1)
642 if (bitstream_get (state, 1)) { /* cplcoe */
643 int mstrcplco, cplcoexp, cplcomant;
644
645 cplcoe = 1;
646 mstrcplco = 3 * bitstream_get (state, 2);
647 for (j = 0; j < state->ncplbnd; j++) {
648 cplcoexp = bitstream_get (state, 4);
649 cplcomant = bitstream_get (state, 4);
650 if (cplcoexp == 15)
651 cplcomant <<= 14;
652 else
653 cplcomant = (cplcomant | 0x10) << 13;
654#ifndef LIBA52_FIXED
655 state->cplco[i][j] =
656 cplcomant * scale_factor[cplcoexp + mstrcplco];
657#else
658 state->cplco[i][j] = (cplcomant << 11) >> (cplcoexp + mstrcplco);
659#endif
660
661 }
662 }
663 if ((state->acmod == 2) && state->phsflginu && cplcoe)
664 for (j = 0; j < state->ncplbnd; j++)
665 if (bitstream_get (state, 1)) /* phsflg */
666 state->cplco[1][j] = -state->cplco[1][j];
667 }
668
669 if ((state->acmod == 2) && (bitstream_get (state, 1))) { /* rematstr */
670 int end;
671
672 state->rematflg = 0;
673 end = (state->chincpl) ? state->cplstrtmant : 253; /* cplinu */
674 i = 0;
675 do
676 state->rematflg |= bitstream_get (state, 1) << i;
677 while (rematrix_band[i++] < end);
678 }
679
680 cplexpstr = EXP_REUSE;
681 lfeexpstr = EXP_REUSE;
682 if (state->chincpl) /* cplinu */
683 cplexpstr = bitstream_get (state, 2);
684 for (i = 0; i < nfchans; i++)
685 chexpstr[i] = bitstream_get (state, 2);
686 if (state->lfeon)
687 lfeexpstr = bitstream_get (state, 1);
688
689 for (i = 0; i < nfchans; i++)
690 if (chexpstr[i] != EXP_REUSE) {
691 if ((state->chincpl >> i) & 1)
692 state->endmant[i] = state->cplstrtmant;
693 else {
694 int chbwcod;
695
696 chbwcod = bitstream_get (state, 6);
697 if (chbwcod > 60)
698 return 1;
699 state->endmant[i] = chbwcod * 3 + 73;
700 }
701 }
702
703 do_bit_alloc = 0;
704
705 if (cplexpstr != EXP_REUSE) {
706 int cplabsexp, ncplgrps;
707
708 do_bit_alloc = 64;
709 ncplgrps = ((state->cplendmant - state->cplstrtmant) /
710 (3 << (cplexpstr - 1)));
711 cplabsexp = bitstream_get (state, 4) << 1;
712 if (parse_exponents (state, cplexpstr, ncplgrps, cplabsexp,
713 state->cpl_expbap.exp + state->cplstrtmant))
714 return 1;
715 }
716 for (i = 0; i < nfchans; i++)
717 if (chexpstr[i] != EXP_REUSE) {
718 int grp_size, nchgrps;
719
720 do_bit_alloc |= 1 << i;
721 grp_size = 3 << (chexpstr[i] - 1);
722 nchgrps = (state->endmant[i] + grp_size - 4) / grp_size;
723 state->fbw_expbap[i].exp[0] = bitstream_get (state, 4);
724 if (parse_exponents (state, chexpstr[i], nchgrps,
725 state->fbw_expbap[i].exp[0],
726 state->fbw_expbap[i].exp + 1))
727 return 1;
728 bitstream_get (state, 2); /* gainrng */
729 }
730 if (lfeexpstr != EXP_REUSE) {
731 do_bit_alloc |= 32;
732 state->lfe_expbap.exp[0] = bitstream_get (state, 4);
733 if (parse_exponents (state, lfeexpstr, 2, state->lfe_expbap.exp[0],
734 state->lfe_expbap.exp + 1))
735 return 1;
736 }
737
738 if (bitstream_get (state, 1)) { /* baie */
739 do_bit_alloc = 127;
740 state->bai = bitstream_get (state, 11);
741 }
742 if (bitstream_get (state, 1)) { /* snroffste */
743 do_bit_alloc = 127;
744 state->csnroffst = bitstream_get (state, 6);
745 if (state->chincpl) /* cplinu */
746 state->cplba.bai = bitstream_get (state, 7);
747 for (i = 0; i < nfchans; i++)
748 state->ba[i].bai = bitstream_get (state, 7);
749 if (state->lfeon)
750 state->lfeba.bai = bitstream_get (state, 7);
751 }
752 if ((state->chincpl) && (bitstream_get (state, 1))) { /* cplleake */
753 do_bit_alloc |= 64;
754 state->cplfleak = 9 - bitstream_get (state, 3);
755 state->cplsleak = 9 - bitstream_get (state, 3);
756 }
757
758 if (bitstream_get (state, 1)) { /* deltbaie */
759 do_bit_alloc = 127;
760 if (state->chincpl) /* cplinu */
761 state->cplba.deltbae = bitstream_get (state, 2);
762 for (i = 0; i < nfchans; i++)
763 state->ba[i].deltbae = bitstream_get (state, 2);
764 if (state->chincpl && /* cplinu */
765 (state->cplba.deltbae == DELTA_BIT_NEW) &&
766 parse_deltba (state, state->cplba.deltba))
767 return 1;
768 for (i = 0; i < nfchans; i++)
769 if ((state->ba[i].deltbae == DELTA_BIT_NEW) &&
770 parse_deltba (state, state->ba[i].deltba))
771 return 1;
772 }
773
774 if (do_bit_alloc) {
775 if (zero_snr_offsets (nfchans, state)) {
776 memset (state->cpl_expbap.bap, 0, sizeof (state->cpl_expbap.bap));
777 for (i = 0; i < nfchans; i++)
778 memset (state->fbw_expbap[i].bap, 0,
779 sizeof (state->fbw_expbap[i].bap));
780 memset (state->lfe_expbap.bap, 0, sizeof (state->lfe_expbap.bap));
781 } else {
782 if (state->chincpl && (do_bit_alloc & 64)) /* cplinu */
783 a52_bit_allocate (state, &state->cplba, state->cplstrtbnd,
784 state->cplstrtmant, state->cplendmant,
785 state->cplfleak << 8, state->cplsleak << 8,
786 &state->cpl_expbap);
787 for (i = 0; i < nfchans; i++)
788 if (do_bit_alloc & (1 << i))
789 a52_bit_allocate (state, state->ba + i, 0, 0,
790 state->endmant[i], 0, 0,
791 state->fbw_expbap +i);
792 if (state->lfeon && (do_bit_alloc & 32)) {
793 state->lfeba.deltbae = DELTA_BIT_NONE;
794 a52_bit_allocate (state, &state->lfeba, 0, 0, 7, 0, 0,
795 &state->lfe_expbap);
796 }
797 }
798 }
799
800 if (bitstream_get (state, 1)) { /* skiple */
801 i = bitstream_get (state, 9); /* skipl */
802 while (i--)
803 bitstream_get (state, 8);
804 }
805
806 samples = state->samples;
807 if (state->output & A52_LFE)
808 samples += 256; /* shift for LFE channel */
809
810 chanbias = a52_downmix_coeff (coeff, state->acmod, state->output,
811 state->dynrng, state->clev, state->slev);
812
813 quant.q1_ptr = quant.q2_ptr = quant.q4_ptr = -1;
814 done_cpl = 0;
815
816 for (i = 0; i < nfchans; i++) {
817 int j;
818
819 coeff_get (state, samples + 256 * i, state->fbw_expbap +i, &quant,
820 coeff[i], dithflag[i], state->endmant[i]);
821
822 if ((state->chincpl >> i) & 1) {
823 if (!done_cpl) {
824 done_cpl = 1;
825 coeff_get_coupling (state, nfchans, coeff,
826 (sample_t (*)[256])samples, &quant,
827 dithflag);
828 }
829 j = state->cplendmant;
830 } else
831 j = state->endmant[i];
832 do
833 (samples + 256 * i)[j] = 0;
834 while (++j < 256);
835 }
836
837 if (state->acmod == 2) {
838 int j, end, band, rematflg;
839
840 end = ((state->endmant[0] < state->endmant[1]) ?
841 state->endmant[0] : state->endmant[1]);
842
843 i = 0;
844 j = 13;
845 rematflg = state->rematflg;
846 do {
847 if (! (rematflg & 1)) {
848 rematflg >>= 1;
849 j = rematrix_band[i++];
850 continue;
851 }
852 rematflg >>= 1;
853 band = rematrix_band[i++];
854 if (band > end)
855 band = end;
856 do {
857 sample_t tmp0, tmp1;
858
859 tmp0 = samples[j];
860 tmp1 = (samples+256)[j];
861 samples[j] = tmp0 + tmp1;
862 (samples+256)[j] = tmp0 - tmp1;
863 } while (++j < band);
864 } while (j < end);
865 }
866
867 if (state->lfeon) {
868 if (state->output & A52_LFE) {
869 coeff_get (state, samples - 256, &state->lfe_expbap, &quant,
870 state->dynrng, 0, 7);
871 for (i = 7; i < 256; i++)
872 (samples-256)[i] = 0;
873 a52_imdct_512 (samples - 256, samples + 1536 - 256, state->bias);
874 } else {
875 /* just skip the LFE coefficients */
876 coeff_get (state, samples + 1280, &state->lfe_expbap, &quant,
877 0, 0, 7);
878 }
879 }
880
881 i = 0;
882 if (nfchans_tbl[state->output & A52_CHANNEL_MASK] < nfchans)
883 for (i = 1; i < nfchans; i++)
884 if (blksw[i] != blksw[0])
885 break;
886
887 if (i < nfchans) {
888 if (state->downmixed) {
889 state->downmixed = 0;
890 a52_upmix (samples + 1536, state->acmod, state->output);
891 }
892
893 for (i = 0; i < nfchans; i++) {
894 sample_t bias;
895
896 bias = 0;
897 if (!(chanbias & (1 << i)))
898 bias = state->bias;
899
900 if (coeff[i]) {
901 if (blksw[i])
902 a52_imdct_256 (samples + 256 * i, samples + 1536 + 256 * i,
903 bias);
904 else
905 a52_imdct_512 (samples + 256 * i, samples + 1536 + 256 * i,
906 bias);
907 } else {
908 int j;
909
910 for (j = 0; j < 256; j++)
911 (samples + 256 * i)[j] = bias;
912 }
913 }
914
915 a52_downmix (samples, state->acmod, state->output, state->bias,
916 state->clev, state->slev);
917 } else {
918 nfchans = nfchans_tbl[state->output & A52_CHANNEL_MASK];
919
920 a52_downmix (samples, state->acmod, state->output, 0,
921 state->clev, state->slev);
922
923 if (!state->downmixed) {
924 state->downmixed = 1;
925 a52_downmix (samples + 1536, state->acmod, state->output, 0,
926 state->clev, state->slev);
927 }
928
929 if (blksw[0])
930 for (i = 0; i < nfchans; i++)
931 a52_imdct_256 (samples + 256 * i, samples + 1536 + 256 * i,
932 state->bias);
933 else
934 for (i = 0; i < nfchans; i++)
935 a52_imdct_512 (samples + 256 * i, samples + 1536 + 256 * i,
936 state->bias);
937 }
938
939 return 0;
940}
941
942void a52_free (a52_state_t * state)
943{
944 free (state->samples);
945 free (state);
946}
diff --git a/apps/codecs/liba52/tables.h b/apps/codecs/liba52/tables.h
new file mode 100644
index 0000000000..b067c63f69
--- /dev/null
+++ b/apps/codecs/liba52/tables.h
@@ -0,0 +1,246 @@
1/*
2 * tables.h
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 *
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
8 *
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24static const int8_t exp_1[128] = {
25 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
26 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
27 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
28 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
29 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
30 25,25,25
31};
32static const int8_t exp_2[128] = {
33 -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
34 -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
35 -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
36 -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
37 -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
38 25,25,25
39};
40static const int8_t exp_3[128] = {
41 -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
42 -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
43 -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
44 -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
45 -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
46 25,25,25
47};
48
49#define Q(x) ROUND (32768.0 * x)
50
51#define Q0 Q (-2/3)
52#define Q1 Q (0)
53#define Q2 Q (2/3)
54
55static const quantizer_t q_1_0[32] = {
56 Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0,
57 Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1,
58 Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2,
59 0, 0, 0, 0, 0
60};
61
62static const quantizer_t q_1_1[32] = {
63 Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2,
64 Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2,
65 Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2,
66 0, 0, 0, 0, 0
67};
68
69static const quantizer_t q_1_2[32] = {
70 Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2,
71 Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2,
72 Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2,
73 0, 0, 0, 0, 0
74};
75
76#undef Q0
77#undef Q1
78#undef Q2
79
80#define Q0 Q (-4/5)
81#define Q1 Q (-2/5)
82#define Q2 Q (0)
83#define Q3 Q (2/5)
84#define Q4 Q (4/5)
85
86static const quantizer_t q_2_0[128] = {
87 Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,
88 Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,
89 Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,
90 Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,
91 Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,
92 0,0,0
93};
94
95static const quantizer_t q_2_1[128] = {
96 Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
97 Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
98 Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
99 Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
100 Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
101 0,0,0
102};
103
104static const quantizer_t q_2_2[128] = {
105 Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
106 Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
107 Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
108 Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
109 Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
110 0,0,0
111};
112
113#undef Q0
114#undef Q1
115#undef Q2
116#undef Q3
117#undef Q4
118
119static const quantizer_t q_3[8] = {
120 Q (-6/7), Q (-4/7), Q (-2/7), Q (0), Q (2/7), Q (4/7), Q (6/7), 0
121};
122
123#define Q0 Q (-10/11)
124#define Q1 Q (-8/11)
125#define Q2 Q (-6/11)
126#define Q3 Q (-4/11)
127#define Q4 Q (-2/11)
128#define Q5 Q (0)
129#define Q6 Q (2/11)
130#define Q7 Q (4/11)
131#define Q8 Q (6/11)
132#define Q9 Q (8/11)
133#define QA Q (10/11)
134
135static const quantizer_t q_4_0[128] = {
136 Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0,
137 Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1,
138 Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2,
139 Q3, Q3, Q3, Q3, Q3, Q3, Q3, Q3, Q3, Q3, Q3,
140 Q4, Q4, Q4, Q4, Q4, Q4, Q4, Q4, Q4, Q4, Q4,
141 Q5, Q5, Q5, Q5, Q5, Q5, Q5, Q5, Q5, Q5, Q5,
142 Q6, Q6, Q6, Q6, Q6, Q6, Q6, Q6, Q6, Q6, Q6,
143 Q7, Q7, Q7, Q7, Q7, Q7, Q7, Q7, Q7, Q7, Q7,
144 Q8, Q8, Q8, Q8, Q8, Q8, Q8, Q8, Q8, Q8, Q8,
145 Q9, Q9, Q9, Q9, Q9, Q9, Q9, Q9, Q9, Q9, Q9,
146 QA, QA, QA, QA, QA, QA, QA, QA, QA, QA, QA,
147 0, 0, 0, 0, 0, 0, 0
148};
149
150static const quantizer_t q_4_1[128] = {
151 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
152 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
153 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
154 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
155 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
156 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
157 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
158 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
159 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
160 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
161 Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
162 0, 0, 0, 0, 0, 0, 0
163};
164
165#undef Q0
166#undef Q1
167#undef Q2
168#undef Q3
169#undef Q4
170#undef Q5
171#undef Q6
172#undef Q7
173#undef Q8
174#undef Q9
175#undef QA
176
177static const quantizer_t q_5[16] = {
178 Q (-14/15), Q (-12/15), Q (-10/15), Q (-8/15), Q (-6/15),
179 Q (-4/15), Q (-2/15), Q (0), Q (2/15), Q (4/15),
180 Q (6/15), Q (8/15), Q (10/15), Q (12/15), Q (14/15), 0
181};
182
183#ifndef LIBA52_FIXED
184static const sample_t scale_factor[25] = {
185 0.000030517578125,
186 0.0000152587890625,
187 0.00000762939453125,
188 0.000003814697265625,
189 0.0000019073486328125,
190 0.00000095367431640625,
191 0.000000476837158203125,
192 0.0000002384185791015625,
193 0.00000011920928955078125,
194 0.000000059604644775390625,
195 0.0000000298023223876953125,
196 0.00000001490116119384765625,
197 0.000000007450580596923828125,
198 0.0000000037252902984619140625,
199 0.00000000186264514923095703125,
200 0.000000000931322574615478515625,
201 0.0000000004656612873077392578125,
202 0.00000000023283064365386962890625,
203 0.000000000116415321826934814453125,
204 0.0000000000582076609134674072265625,
205 0.00000000002910383045673370361328125,
206 0.000000000014551915228366851806640625,
207 0.0000000000072759576141834259033203125,
208 0.00000000000363797880709171295166015625,
209 0.000000000001818989403545856475830078125
210};
211#endif
212
213static const uint16_t dither_lut[256] = {
214 0x0000, 0xa011, 0xe033, 0x4022, 0x6077, 0xc066, 0x8044, 0x2055,
215 0xc0ee, 0x60ff, 0x20dd, 0x80cc, 0xa099, 0x0088, 0x40aa, 0xe0bb,
216 0x21cd, 0x81dc, 0xc1fe, 0x61ef, 0x41ba, 0xe1ab, 0xa189, 0x0198,
217 0xe123, 0x4132, 0x0110, 0xa101, 0x8154, 0x2145, 0x6167, 0xc176,
218 0x439a, 0xe38b, 0xa3a9, 0x03b8, 0x23ed, 0x83fc, 0xc3de, 0x63cf,
219 0x8374, 0x2365, 0x6347, 0xc356, 0xe303, 0x4312, 0x0330, 0xa321,
220 0x6257, 0xc246, 0x8264, 0x2275, 0x0220, 0xa231, 0xe213, 0x4202,
221 0xa2b9, 0x02a8, 0x428a, 0xe29b, 0xc2ce, 0x62df, 0x22fd, 0x82ec,
222 0x8734, 0x2725, 0x6707, 0xc716, 0xe743, 0x4752, 0x0770, 0xa761,
223 0x47da, 0xe7cb, 0xa7e9, 0x07f8, 0x27ad, 0x87bc, 0xc79e, 0x678f,
224 0xa6f9, 0x06e8, 0x46ca, 0xe6db, 0xc68e, 0x669f, 0x26bd, 0x86ac,
225 0x6617, 0xc606, 0x8624, 0x2635, 0x0660, 0xa671, 0xe653, 0x4642,
226 0xc4ae, 0x64bf, 0x249d, 0x848c, 0xa4d9, 0x04c8, 0x44ea, 0xe4fb,
227 0x0440, 0xa451, 0xe473, 0x4462, 0x6437, 0xc426, 0x8404, 0x2415,
228 0xe563, 0x4572, 0x0550, 0xa541, 0x8514, 0x2505, 0x6527, 0xc536,
229 0x258d, 0x859c, 0xc5be, 0x65af, 0x45fa, 0xe5eb, 0xa5c9, 0x05d8,
230 0xae79, 0x0e68, 0x4e4a, 0xee5b, 0xce0e, 0x6e1f, 0x2e3d, 0x8e2c,
231 0x6e97, 0xce86, 0x8ea4, 0x2eb5, 0x0ee0, 0xaef1, 0xeed3, 0x4ec2,
232 0x8fb4, 0x2fa5, 0x6f87, 0xcf96, 0xefc3, 0x4fd2, 0x0ff0, 0xafe1,
233 0x4f5a, 0xef4b, 0xaf69, 0x0f78, 0x2f2d, 0x8f3c, 0xcf1e, 0x6f0f,
234 0xede3, 0x4df2, 0x0dd0, 0xadc1, 0x8d94, 0x2d85, 0x6da7, 0xcdb6,
235 0x2d0d, 0x8d1c, 0xcd3e, 0x6d2f, 0x4d7a, 0xed6b, 0xad49, 0x0d58,
236 0xcc2e, 0x6c3f, 0x2c1d, 0x8c0c, 0xac59, 0x0c48, 0x4c6a, 0xec7b,
237 0x0cc0, 0xacd1, 0xecf3, 0x4ce2, 0x6cb7, 0xcca6, 0x8c84, 0x2c95,
238 0x294d, 0x895c, 0xc97e, 0x696f, 0x493a, 0xe92b, 0xa909, 0x0918,
239 0xe9a3, 0x49b2, 0x0990, 0xa981, 0x89d4, 0x29c5, 0x69e7, 0xc9f6,
240 0x0880, 0xa891, 0xe8b3, 0x48a2, 0x68f7, 0xc8e6, 0x88c4, 0x28d5,
241 0xc86e, 0x687f, 0x285d, 0x884c, 0xa819, 0x0808, 0x482a, 0xe83b,
242 0x6ad7, 0xcac6, 0x8ae4, 0x2af5, 0x0aa0, 0xaab1, 0xea93, 0x4a82,
243 0xaa39, 0x0a28, 0x4a0a, 0xea1b, 0xca4e, 0x6a5f, 0x2a7d, 0x8a6c,
244 0x4b1a, 0xeb0b, 0xab29, 0x0b38, 0x2b6d, 0x8b7c, 0xcb5e, 0x6b4f,
245 0x8bf4, 0x2be5, 0x6bc7, 0xcbd6, 0xeb83, 0x4b92, 0x0bb0, 0xaba1
246};
diff --git a/apps/codecs/liba52/tendra.h b/apps/codecs/liba52/tendra.h
new file mode 100644
index 0000000000..cc740fceeb
--- /dev/null
+++ b/apps/codecs/liba52/tendra.h
@@ -0,0 +1,35 @@
1/*
2 * tendra.h
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 *
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
8 *
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#pragma TenDRA begin
25#pragma TenDRA longlong type warning
26
27#ifdef TenDRA_check
28
29#pragma TenDRA conversion analysis (pointer-int explicit) off
30#pragma TenDRA implicit function declaration off
31
32/* avoid the "No declarations in translation unit" problem */
33int TenDRA;
34
35#endif /* TenDRA_check */