summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/liba52
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/liba52')
-rw-r--r--lib/rbcodec/codecs/liba52/AUTHORS23
-rw-r--r--lib/rbcodec/codecs/liba52/COPYING340
-rw-r--r--lib/rbcodec/codecs/liba52/ChangeLog97
-rw-r--r--lib/rbcodec/codecs/liba52/HISTORY28
-rw-r--r--lib/rbcodec/codecs/liba52/INSTALL58
-rw-r--r--lib/rbcodec/codecs/liba52/NEWS46
-rw-r--r--lib/rbcodec/codecs/liba52/README180
-rw-r--r--lib/rbcodec/codecs/liba52/README.rockbox27
-rw-r--r--lib/rbcodec/codecs/liba52/SOURCES5
-rw-r--r--lib/rbcodec/codecs/liba52/TODO17
-rw-r--r--lib/rbcodec/codecs/liba52/a52.h67
-rw-r--r--lib/rbcodec/codecs/liba52/a52_internal.h215
-rw-r--r--lib/rbcodec/codecs/liba52/attributes.h37
-rw-r--r--lib/rbcodec/codecs/liba52/bit_allocate.c265
-rw-r--r--lib/rbcodec/codecs/liba52/bitstream.c97
-rw-r--r--lib/rbcodec/codecs/liba52/bitstream.h54
-rw-r--r--lib/rbcodec/codecs/liba52/config-a52.h26
-rw-r--r--lib/rbcodec/codecs/liba52/downmix.c688
-rw-r--r--lib/rbcodec/codecs/liba52/imdct.c486
-rw-r--r--lib/rbcodec/codecs/liba52/imdct_lookups.h15
-rw-r--r--lib/rbcodec/codecs/liba52/liba52.make18
-rw-r--r--lib/rbcodec/codecs/liba52/mm_accel.h37
-rw-r--r--lib/rbcodec/codecs/liba52/parse.c956
-rw-r--r--lib/rbcodec/codecs/liba52/tables.h246
-rw-r--r--lib/rbcodec/codecs/liba52/tendra.h35
25 files changed, 4063 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/liba52/AUTHORS b/lib/rbcodec/codecs/liba52/AUTHORS
new file mode 100644
index 0000000000..a6bd695228
--- /dev/null
+++ b/lib/rbcodec/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/lib/rbcodec/codecs/liba52/COPYING b/lib/rbcodec/codecs/liba52/COPYING
new file mode 100644
index 0000000000..60549be514
--- /dev/null
+++ b/lib/rbcodec/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/lib/rbcodec/codecs/liba52/ChangeLog b/lib/rbcodec/codecs/liba52/ChangeLog
new file mode 100644
index 0000000000..4adac364eb
--- /dev/null
+++ b/lib/rbcodec/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/lib/rbcodec/codecs/liba52/HISTORY b/lib/rbcodec/codecs/liba52/HISTORY
new file mode 100644
index 0000000000..c2b9d02ee1
--- /dev/null
+++ b/lib/rbcodec/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/lib/rbcodec/codecs/liba52/INSTALL b/lib/rbcodec/codecs/liba52/INSTALL
new file mode 100644
index 0000000000..30a07fecff
--- /dev/null
+++ b/lib/rbcodec/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/lib/rbcodec/codecs/liba52/NEWS b/lib/rbcodec/codecs/liba52/NEWS
new file mode 100644
index 0000000000..4bee9cac8d
--- /dev/null
+++ b/lib/rbcodec/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/lib/rbcodec/codecs/liba52/README b/lib/rbcodec/codecs/liba52/README
new file mode 100644
index 0000000000..eb6c64df84
--- /dev/null
+++ b/lib/rbcodec/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/lib/rbcodec/codecs/liba52/README.rockbox b/lib/rbcodec/codecs/liba52/README.rockbox
new file mode 100644
index 0000000000..79768c5d72
--- /dev/null
+++ b/lib/rbcodec/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/lib/rbcodec/codecs/liba52/SOURCES b/lib/rbcodec/codecs/liba52/SOURCES
new file mode 100644
index 0000000000..733b95e8a6
--- /dev/null
+++ b/lib/rbcodec/codecs/liba52/SOURCES
@@ -0,0 +1,5 @@
1bit_allocate.c
2bitstream.c
3downmix.c
4imdct.c
5parse.c
diff --git a/lib/rbcodec/codecs/liba52/TODO b/lib/rbcodec/codecs/liba52/TODO
new file mode 100644
index 0000000000..dc5fb84203
--- /dev/null
+++ b/lib/rbcodec/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/lib/rbcodec/codecs/liba52/a52.h b/lib/rbcodec/codecs/liba52/a52.h
new file mode 100644
index 0000000000..e852e8d6bb
--- /dev/null
+++ b/lib/rbcodec/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/lib/rbcodec/codecs/liba52/a52_internal.h b/lib/rbcodec/codecs/liba52/a52_internal.h
new file mode 100644
index 0000000000..3b3d21c9a3
--- /dev/null
+++ b/lib/rbcodec/codecs/liba52/a52_internal.h
@@ -0,0 +1,215 @@
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,
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);
120void a52_imdct_512 (sample_t * data, sample_t * delay);
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 defined(CPU_COLDFIRE)
145/* loses 1 bit of accuracy */
146#define MUL(a, b) \
147({ \
148 int32_t t; \
149 asm volatile ( \
150 "mac.l %[A], %[B], %%acc0\n\t" \
151 "movclr.l %%acc0, %[t]\n\t" \
152 "asl.l #1, %[t]" \
153 : [t] "=d" (t) \
154 : [A] "r" ((a)), [B] "r" ((b))); \
155 t; \
156})
157/* loses 5 bits of accuracy */
158#define MUL_L(a, b) \
159({ \
160 int32_t t; \
161 asm volatile ( \
162 "mac.l %[A], %[B], %%acc0\n\t" \
163 "movclr.l %%acc0, %[t]\n\t" \
164 "asl.l #5, %[t]" \
165 : [t] "=d" (t) \
166 : [A] "r" ((a)), [B] "r" ((b))); \
167 t; \
168})
169
170#elif defined(CPU_ARM)
171#define MUL(x, y) \
172 ({ int32_t __hi; \
173 uint32_t __lo; \
174 int32_t __result; \
175 asm ("smull %0, %1, %3, %4\n\t" \
176 "movs %2, %1, lsl #2" \
177 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
178 : "%r" (x), "r" (y) \
179 : "cc"); \
180 __result; \
181 })
182
183
184#define MUL_L(x, y) \
185 ({ int32_t __hi; \
186 uint32_t __lo; \
187 int32_t __result; \
188 asm ("smull %0, %1, %3, %4\n\t" \
189 "movs %0, %0, lsr %5\n\t" \
190 "adc %2, %0, %1, lsl %6" \
191 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
192 : "%r" (x), "r" (y), \
193 "M" (26), "M" (32 - 26) \
194 : "cc"); \
195 __result; \
196 })
197
198
199#elif 1
200#define MUL(a,b) \
201({ int32_t _ta=(a), _tb=(b), _tc; \
202 _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)(((_tc >> 14))+ (((_ta >> 16)*(_tb >> 16)) << 2 )); })
203#define MUL_L(a,b) \
204({ int32_t _ta=(a), _tb=(b), _tc; \
205 _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)((_tc >> 10) + (((_ta >> 16)*(_tb >> 16)) << 6)); })
206#else
207#define MUL(a,b) (((a) >> 15) * ((b) >> 15))
208#define MUL_L(a,b) (((a) >> 13) * ((b) >> 13))
209#endif
210
211#define MUL_C(a,b) MUL_L (a, LEVEL (b))
212#define DIV(a,b) ((((int64_t)LEVEL (a)) << 26) / (b))
213#define BIAS(x) ((x))
214
215#endif
diff --git a/lib/rbcodec/codecs/liba52/attributes.h b/lib/rbcodec/codecs/liba52/attributes.h
new file mode 100644
index 0000000000..988abc0311
--- /dev/null
+++ b/lib/rbcodec/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/lib/rbcodec/codecs/liba52/bit_allocate.c b/lib/rbcodec/codecs/liba52/bit_allocate.c
new file mode 100644
index 0000000000..aaac245913
--- /dev/null
+++ b/lib/rbcodec/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-a52.h"
25
26#include <inttypes.h>
27
28#include "a52.h"
29#include "a52_internal.h"
30
31static int hthtab[3][50] IDATA_ATTR = {
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] IDATA_ATTR = {
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] IDATA_ATTR = {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] IDATA_ATTR = {
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/lib/rbcodec/codecs/liba52/bitstream.c b/lib/rbcodec/codecs/liba52/bitstream.c
new file mode 100644
index 0000000000..155368f1ed
--- /dev/null
+++ b/lib/rbcodec/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-a52.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/lib/rbcodec/codecs/liba52/bitstream.h b/lib/rbcodec/codecs/liba52/bitstream.h
new file mode 100644
index 0000000000..56de1571b7
--- /dev/null
+++ b/lib/rbcodec/codecs/liba52/bitstream.h
@@ -0,0 +1,54 @@
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#define swab32(x) (betoh32(x))
25
26void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf);
27uint32_t a52_bitstream_get_bh (a52_state_t * state, uint32_t num_bits);
28int32_t a52_bitstream_get_bh_2 (a52_state_t * state, uint32_t num_bits);
29
30static inline uint32_t bitstream_get (a52_state_t * state, uint32_t num_bits)
31{
32 uint32_t result;
33
34 if (num_bits < state->bits_left) {
35 result = (state->current_word << (32 - state->bits_left)) >> (32 - num_bits);
36 state->bits_left -= num_bits;
37 return result;
38 }
39
40 return a52_bitstream_get_bh (state, num_bits);
41}
42
43static inline int32_t bitstream_get_2 (a52_state_t * state, uint32_t num_bits)
44{
45 int32_t result;
46
47 if (num_bits < state->bits_left) {
48 result = (((int32_t)state->current_word) << (32 - state->bits_left)) >> (32 - num_bits);
49 state->bits_left -= num_bits;
50 return result;
51 }
52
53 return a52_bitstream_get_bh_2 (state, num_bits);
54}
diff --git a/lib/rbcodec/codecs/liba52/config-a52.h b/lib/rbcodec/codecs/liba52/config-a52.h
new file mode 100644
index 0000000000..ade7ecf9b8
--- /dev/null
+++ b/lib/rbcodec/codecs/liba52/config-a52.h
@@ -0,0 +1,26 @@
1#include "codeclib.h"
2
3/* a52dec profiling */
4/* #undef A52DEC_GPROF */
5
6/* Define to 1 if you have the `memalign' function. */
7/* #undef HAVE_MEMALIGN 1 */
8
9/* liba52 djbfft support */
10/* #undef LIBA52_DJBFFT */
11
12/* a52 sample precision */
13/* #undef LIBA52_DOUBLE */
14
15/* use fixed-point arithmetic */
16#define LIBA52_FIXED
17
18/* Define to 1 if your processor stores words with the most significant byte
19 first (like Motorola and SPARC, unlike Intel and VAX). */
20
21/* Used in bitstream.h */
22
23#ifdef ROCKBOX_BIG_ENDIAN
24#define WORDS_BIGENDIAN 1
25#endif
26
diff --git a/lib/rbcodec/codecs/liba52/downmix.c b/lib/rbcodec/codecs/liba52/downmix.c
new file mode 100644
index 0000000000..dd2867cb92
--- /dev/null
+++ b/lib/rbcodec/codecs/liba52/downmix.c
@@ -0,0 +1,688 @@
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-a52.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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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,
481 level_t clev, level_t slev)
482{
483 /* avoid compiler warning */
484 (void)clev;
485
486 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
487
488 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
489 memcpy (samples, samples + 256, 256 * sizeof (sample_t));
490 break;
491
492 case CONVERT (A52_CHANNEL, A52_MONO):
493 case CONVERT (A52_STEREO, A52_MONO):
494 mix_2to1:
495 mix2to1 (samples, samples + 256);
496 break;
497
498 case CONVERT (A52_2F1R, A52_MONO):
499 if (slev == 0)
500 goto mix_2to1;
501 case CONVERT (A52_3F, A52_MONO):
502 mix_3to1:
503 mix3to1 (samples);
504 break;
505
506 case CONVERT (A52_3F1R, A52_MONO):
507 if (slev == 0)
508 goto mix_3to1;
509 case CONVERT (A52_2F2R, A52_MONO):
510 if (slev == 0)
511 goto mix_2to1;
512 mix4to1 (samples);
513 break;
514
515 case CONVERT (A52_3F2R, A52_MONO):
516 if (slev == 0)
517 goto mix_3to1;
518 mix5to1 (samples);
519 break;
520
521 case CONVERT (A52_MONO, A52_DOLBY):
522 memcpy (samples + 256, samples, 256 * sizeof (sample_t));
523 break;
524
525 case CONVERT (A52_3F, A52_STEREO):
526 case CONVERT (A52_3F, A52_DOLBY):
527 mix_3to2:
528 mix3to2 (samples);
529 break;
530
531 case CONVERT (A52_2F1R, A52_STEREO):
532 if (slev == 0)
533 break;
534 mix21to2 (samples, samples + 256);
535 break;
536
537 case CONVERT (A52_2F1R, A52_DOLBY):
538 mix21toS (samples);
539 break;
540
541 case CONVERT (A52_3F1R, A52_STEREO):
542 if (slev == 0)
543 goto mix_3to2;
544 mix31to2 (samples);
545 break;
546
547 case CONVERT (A52_3F1R, A52_DOLBY):
548 mix31toS (samples);
549 break;
550
551 case CONVERT (A52_2F2R, A52_STEREO):
552 if (slev == 0)
553 break;
554 mix2to1 (samples, samples + 512);
555 mix2to1 (samples + 256, samples + 768);
556 break;
557
558 case CONVERT (A52_2F2R, A52_DOLBY):
559 mix22toS (samples);
560 break;
561
562 case CONVERT (A52_3F2R, A52_STEREO):
563 if (slev == 0)
564 goto mix_3to2;
565 mix32to2 (samples);
566 break;
567
568 case CONVERT (A52_3F2R, A52_DOLBY):
569 mix32toS (samples);
570 break;
571
572 case CONVERT (A52_3F1R, A52_3F):
573 if (slev == 0)
574 break;
575 mix21to2 (samples, samples + 512);
576 break;
577
578 case CONVERT (A52_3F2R, A52_3F):
579 if (slev == 0)
580 break;
581 mix2to1 (samples, samples + 768);
582 mix2to1 (samples + 512, samples + 1024);
583 break;
584
585 case CONVERT (A52_3F1R, A52_2F1R):
586 mix3to2 (samples);
587 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
588 break;
589
590 case CONVERT (A52_2F2R, A52_2F1R):
591 mix2to1 (samples + 512, samples + 768);
592 break;
593
594 case CONVERT (A52_3F2R, A52_2F1R):
595 mix3to2 (samples);
596 move2to1 (samples + 768, samples + 512);
597 break;
598
599 case CONVERT (A52_3F2R, A52_3F1R):
600 mix2to1 (samples + 768, samples + 1024);
601 break;
602
603 case CONVERT (A52_2F1R, A52_2F2R):
604 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
605 break;
606
607 case CONVERT (A52_3F1R, A52_2F2R):
608 mix3to2 (samples);
609 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
610 break;
611
612 case CONVERT (A52_3F2R, A52_2F2R):
613 mix3to2 (samples);
614 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
615 memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
616 break;
617
618 case CONVERT (A52_3F1R, A52_3F2R):
619 memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
620 break;
621 }
622}
623
624void a52_upmix (sample_t * samples, int acmod, int output)
625{
626 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
627
628 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
629 memcpy (samples + 256, samples, 256 * sizeof (sample_t));
630 break;
631
632 case CONVERT (A52_3F2R, A52_MONO):
633 zero (samples + 1024);
634 case CONVERT (A52_3F1R, A52_MONO):
635 case CONVERT (A52_2F2R, A52_MONO):
636 zero (samples + 768);
637 case CONVERT (A52_3F, A52_MONO):
638 case CONVERT (A52_2F1R, A52_MONO):
639 zero (samples + 512);
640 case CONVERT (A52_CHANNEL, A52_MONO):
641 case CONVERT (A52_STEREO, A52_MONO):
642 zero (samples + 256);
643 break;
644
645 case CONVERT (A52_3F2R, A52_STEREO):
646 case CONVERT (A52_3F2R, A52_DOLBY):
647 zero (samples + 1024);
648 case CONVERT (A52_3F1R, A52_STEREO):
649 case CONVERT (A52_3F1R, A52_DOLBY):
650 zero (samples + 768);
651 case CONVERT (A52_3F, A52_STEREO):
652 case CONVERT (A52_3F, A52_DOLBY):
653 mix_3to2:
654 memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
655 zero (samples + 256);
656 break;
657
658 case CONVERT (A52_2F2R, A52_STEREO):
659 case CONVERT (A52_2F2R, A52_DOLBY):
660 zero (samples + 768);
661 case CONVERT (A52_2F1R, A52_STEREO):
662 case CONVERT (A52_2F1R, A52_DOLBY):
663 zero (samples + 512);
664 break;
665
666 case CONVERT (A52_3F2R, A52_3F):
667 zero (samples + 1024);
668 case CONVERT (A52_3F1R, A52_3F):
669 case CONVERT (A52_2F2R, A52_2F1R):
670 zero (samples + 768);
671 break;
672
673 case CONVERT (A52_3F2R, A52_3F1R):
674 zero (samples + 1024);
675 break;
676
677 case CONVERT (A52_3F2R, A52_2F1R):
678 zero (samples + 1024);
679 case CONVERT (A52_3F1R, A52_2F1R):
680 mix_31to21:
681 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
682 goto mix_3to2;
683
684 case CONVERT (A52_3F2R, A52_2F2R):
685 memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
686 goto mix_31to21;
687 }
688}
diff --git a/lib/rbcodec/codecs/liba52/imdct.c b/lib/rbcodec/codecs/liba52/imdct.c
new file mode 100644
index 0000000000..e93424c5fa
--- /dev/null
+++ b/lib/rbcodec/codecs/liba52/imdct.c
@@ -0,0 +1,486 @@
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-a52.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 const 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 */
61//static sample_t roots16[3];
62//static sample_t roots32[7];
63//static sample_t roots64[15];
64//static sample_t roots128[31];
65
66/* Twiddle factors for IMDCT */
67//static complex_t pre1[128];
68//static complex_t post1[64];
69//static complex_t pre2[64];
70//static complex_t post2[32];
71
72//static sample_t a52_imdct_window[256];
73#include "imdct_lookups.h"
74
75
76/*
77static void (* ifft128) (complex_t * buf);
78static void (* ifft64) (complex_t * buf);
79
80static inline void ifft2 (complex_t * buf)
81{
82 sample_t r, i;
83
84 r = buf[0].real;
85 i = buf[0].imag;
86 buf[0].real += buf[1].real;
87 buf[0].imag += buf[1].imag;
88 buf[1].real = r - buf[1].real;
89 buf[1].imag = i - buf[1].imag;
90}
91
92static inline void ifft4 (complex_t * buf)
93{
94 sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
95
96 tmp1 = buf[0].real + buf[1].real;
97 tmp2 = buf[3].real + buf[2].real;
98 tmp3 = buf[0].imag + buf[1].imag;
99 tmp4 = buf[2].imag + buf[3].imag;
100 tmp5 = buf[0].real - buf[1].real;
101 tmp6 = buf[0].imag - buf[1].imag;
102 tmp7 = buf[2].imag - buf[3].imag;
103 tmp8 = buf[3].real - buf[2].real;
104
105 buf[0].real = tmp1 + tmp2;
106 buf[0].imag = tmp3 + tmp4;
107 buf[2].real = tmp1 - tmp2;
108 buf[2].imag = tmp3 - tmp4;
109 buf[1].real = tmp5 + tmp7;
110 buf[1].imag = tmp6 + tmp8;
111 buf[3].real = tmp5 - tmp7;
112 buf[3].imag = tmp6 - tmp8;
113}
114*/
115/* basic radix-2 ifft butterfly */
116
117#define BUTTERFLY_0(t0,t1,W0,W1,d0,d1) do { \
118 t0 = MUL (W1, d1) + MUL (W0, d0); \
119 t1 = MUL (W0, d1) - MUL (W1, d0); \
120} while (0)
121
122/* radix-2 ifft butterfly with bias */
123
124#define BUTTERFLY_B(t0,t1,W0,W1,d0,d1) do { \
125 t0 = BIAS (MUL (d1, W1) + MUL (d0, W0)); \
126 t1 = BIAS (MUL (d1, W0) - MUL (d0, W1)); \
127} while (0)
128
129/* the basic split-radix ifft butterfly */
130
131#define BUTTERFLY(a0,a1,a2,a3,wr,wi) do { \
132 BUTTERFLY_0 (tmp5, tmp6, wr, wi, a2.real, a2.imag); \
133 BUTTERFLY_0 (tmp8, tmp7, wr, wi, a3.imag, a3.real); \
134 tmp1 = tmp5 + tmp7; \
135 tmp2 = tmp6 + tmp8; \
136 tmp3 = tmp6 - tmp8; \
137 tmp4 = tmp7 - tmp5; \
138 a2.real = a0.real - tmp1; \
139 a2.imag = a0.imag - tmp2; \
140 a3.real = a1.real - tmp3; \
141 a3.imag = a1.imag - tmp4; \
142 a0.real += tmp1; \
143 a0.imag += tmp2; \
144 a1.real += tmp3; \
145 a1.imag += tmp4; \
146} while (0)
147
148/* split-radix ifft butterfly, specialized for wr=1 wi=0 */
149
150#define BUTTERFLY_ZERO(a0,a1,a2,a3) do { \
151 tmp1 = a2.real + a3.real; \
152 tmp2 = a2.imag + a3.imag; \
153 tmp3 = a2.imag - a3.imag; \
154 tmp4 = a3.real - a2.real; \
155 a2.real = a0.real - tmp1; \
156 a2.imag = a0.imag - tmp2; \
157 a3.real = a1.real - tmp3; \
158 a3.imag = a1.imag - tmp4; \
159 a0.real += tmp1; \
160 a0.imag += tmp2; \
161 a1.real += tmp3; \
162 a1.imag += tmp4; \
163} while (0)
164
165/* split-radix ifft butterfly, specialized for wr=wi */
166/*
167#define BUTTERFLY_HALF(a0,a1,a2,a3,w) do { \
168 tmp5 = MUL (a2.real + a2.imag, w); \
169 tmp6 = MUL (a2.imag - a2.real, w); \
170 tmp7 = MUL (a3.real - a3.imag, w); \
171 tmp8 = MUL (a3.imag + a3.real, w); \
172 tmp1 = tmp5 + tmp7; \
173 tmp2 = tmp6 + tmp8; \
174 tmp3 = tmp6 - tmp8; \
175 tmp4 = tmp7 - tmp5; \
176 a2.real = a0.real - tmp1; \
177 a2.imag = a0.imag - tmp2; \
178 a3.real = a1.real - tmp3; \
179 a3.imag = a1.imag - tmp4; \
180 a0.real += tmp1; \
181 a0.imag += tmp2; \
182 a1.real += tmp3; \
183 a1.imag += tmp4; \
184} while (0)
185
186static inline void ifft8 (complex_t * buf)
187{
188 sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
189
190 ifft4 (buf);
191 ifft2 (buf + 4);
192 ifft2 (buf + 6);
193 BUTTERFLY_ZERO (buf[0], buf[2], buf[4], buf[6]);
194 BUTTERFLY_HALF (buf[1], buf[3], buf[5], buf[7], roots16[1]);
195}
196
197static void ifft_pass (complex_t * buf, const sample_t * weight, int n)
198{
199 complex_t * buf1;
200 complex_t * buf2;
201 complex_t * buf3;
202 sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
203 int i;
204
205 buf++;
206 buf1 = buf + n;
207 buf2 = buf + 2 * n;
208 buf3 = buf + 3 * n;
209
210 BUTTERFLY_ZERO (buf[-1], buf1[-1], buf2[-1], buf3[-1]);
211
212 i = n - 1;
213
214 do {
215 BUTTERFLY (buf[0], buf1[0], buf2[0], buf3[0],
216 weight[0], weight[2*i-n]);
217 buf++;
218 buf1++;
219 buf2++;
220 buf3++;
221 weight++;
222 } while (--i);
223}
224
225static void ifft16 (complex_t * buf)
226{
227 ifft8 (buf);
228 ifft4 (buf + 8);
229 ifft4 (buf + 12);
230 ifft_pass (buf, roots16, 4);
231}
232
233static void ifft32 (complex_t * buf)
234{
235 ifft16 (buf);
236 ifft8 (buf + 16);
237 ifft8 (buf + 24);
238 ifft_pass (buf, roots32, 8);
239}
240
241static void ifft64_c (complex_t * buf)
242{
243 ifft32 (buf);
244 ifft16 (buf + 32);
245 ifft16 (buf + 48);
246 ifft_pass (buf, roots64, 16);
247}
248
249static void ifft128_c (complex_t * buf)
250{
251 ifft32 (buf);
252 ifft16 (buf + 32);
253 ifft16 (buf + 48);
254 ifft_pass (buf, roots64, 16);
255
256 ifft32 (buf + 64);
257 ifft32 (buf + 96);
258 ifft_pass (buf, roots128, 32);
259}
260*/
261void a52_imdct_512 (sample_t * data, sample_t * delay)
262{
263 int i, k;
264 sample_t t_r, t_i, a_r, a_i, b_r, b_i, w_1, w_2;
265 const sample_t * window = a52_imdct_window;
266 FFTComplex buf[128];
267
268 for (i = 0; i < 128; i++) {
269 k = fftorder[i];
270 t_r = pre1[i].real;
271 t_i = pre1[i].imag;
272 BUTTERFLY_0 (buf[i].re, buf[i].im, t_r, t_i, data[k], data[255-k]);
273 }
274
275 //ifft128 (buf);
276 ff_fft_calc_c(7, (FFTComplex *)&buf);
277
278 /* Post IFFT complex multiply plus IFFT complex conjugate*/
279 /* Window and convert to real valued signal */
280 for (i = 0; i < 64; i++) {
281 /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
282 t_r = post1[i].real;
283 t_i = post1[i].imag;
284 BUTTERFLY_0 (a_r, a_i, t_i, t_r, buf[i].im, buf[i].re);
285 BUTTERFLY_0 (b_r, b_i, t_r, t_i, buf[127-i].im, buf[127-i].re);
286
287 w_1 = window[2*i];
288 w_2 = window[255-2*i];
289 BUTTERFLY_B (data[255-2*i], data[2*i], w_2, w_1, a_r, delay[2*i]);
290 delay[2*i] = a_i;
291
292 w_1 = window[2*i+1];
293 w_2 = window[254-2*i];
294 BUTTERFLY_B (data[2*i+1], data[254-2*i], w_1, w_2, b_r, delay[2*i+1]);
295 delay[2*i+1] = b_i;
296 }
297}
298
299void a52_imdct_256 (sample_t * data, sample_t * delay)
300{
301 int i, k;
302 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;
303 const sample_t * window = a52_imdct_window;
304 FFTComplex buf1[64], buf2[64];
305
306 /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
307 for (i = 0; i < 64; i++) {
308 k = fftorder[i];
309 t_r = pre2[i].real;
310 t_i = pre2[i].imag;
311 BUTTERFLY_0 (buf1[i].re, buf1[i].im, t_r, t_i, data[k], data[254-k]);
312 BUTTERFLY_0 (buf2[i].re, buf2[i].im, t_r, t_i, data[k+1], data[255-k]);
313 }
314
315 //ifft64 (buf1);
316 //ifft64 (buf2);
317 ff_fft_calc_c(6, (FFTComplex *)&buf1);
318 ff_fft_calc_c(6, (FFTComplex *)&buf2);
319
320 /* Post IFFT complex multiply */
321 /* Window and convert to real valued signal */
322 for (i = 0; i < 32; i++) {
323 /* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */
324 t_r = post2[i].real;
325 t_i = post2[i].imag;
326 BUTTERFLY_0 (a_r, a_i, t_i, t_r, buf1[i].im, buf1[i].re);
327 BUTTERFLY_0 (b_r, b_i, t_r, t_i, buf1[63-i].im, buf1[63-i].re);
328 BUTTERFLY_0 (c_r, c_i, t_i, t_r, buf2[i].im, buf2[i].re);
329 BUTTERFLY_0 (d_r, d_i, t_r, t_i, buf2[63-i].im, buf2[63-i].re);
330
331 w_1 = window[2*i];
332 w_2 = window[255-2*i];
333 BUTTERFLY_B (data[255-2*i], data[2*i], w_2, w_1, a_r, delay[2*i]);
334 delay[2*i] = c_i;
335
336 w_1 = window[128+2*i];
337 w_2 = window[127-2*i];
338 BUTTERFLY_B (data[128+2*i], data[127-2*i], w_1, w_2, a_i, delay[127-2*i]);
339 delay[127-2*i] = c_r;
340
341 w_1 = window[2*i+1];
342 w_2 = window[254-2*i];
343 BUTTERFLY_B (data[254-2*i], data[2*i+1], w_2, w_1, b_i, delay[2*i+1]);
344 delay[2*i+1] = d_r;
345
346 w_1 = window[129+2*i];
347 w_2 = window[126-2*i];
348 BUTTERFLY_B (data[129+2*i], data[126-2*i], w_1, w_2, b_r, delay[126-2*i]);
349 delay[126-2*i] = d_i;
350 }
351}
352
353/*
354static double besselI0 (double x)
355{
356 double bessel = 1;
357 int i = 100;
358
359 do
360 bessel = bessel * x / (i * i) + 1;
361 while (--i);
362 return bessel;
363}
364*/
365
366void a52_imdct_init (uint32_t mm_accel)
367{
368 (void)mm_accel;
369 //ff_fft_init(&s128, 7, 1);
370 //ff_fft_init(&s64, 6, 1);
371
372/* int i, k;
373 double sum;
374 double local_imdct_window[256];*/
375
376 /* compute imdct window - kaiser-bessel derived window, alpha = 5.0 */
377 /* sum = 0;
378 for (i = 0; i < 256; i++) {
379 sum += besselI0 (i * (256 - i) * (5 * M_PI / 256) * (5 * M_PI / 256));
380 local_imdct_window[i] = sum;
381 }
382 sum++;
383 */
384 /* for (i = 0; i < 256; i++)
385 a52_imdct_window[i] = SAMPLE (sqrt (local_imdct_window[i] / sum));
386
387 printf("static sample_t a52_imdct_window[256]={");
388 for (i=0;i<256;i++) {
389 if ((i % 16)==0) { printf("\n"); }
390 printf("%d,",a52_imdct_window[i]);
391 }
392 printf("\n}\n");
393 */
394
395 /* for (i = 0; i < 3; i++)
396 roots16[i] = SAMPLE (cos ((M_PI / 8) * (i + 1)));
397
398 printf("static sample_t roots16[3]={%d,%d,%d};\n\n",roots16[0],roots16[1],roots16[2]);
399
400 for (i = 0; i < 7; i++)
401 roots32[i] = SAMPLE (cos ((M_PI / 16) * (i + 1)));
402
403 printf("static sample_t roots32[7]={");
404 for (i=0;i<7;i++) { printf("%d%s",roots32[i],(i < 6 ? "," : "")); }
405 printf("};\n");
406
407 for (i = 0; i < 15; i++)
408 roots64[i] = SAMPLE (cos ((M_PI / 32) * (i + 1)));
409
410 printf("static sample_t roots64[15]={");
411 for (i=0;i<15;i++) { printf("%d%s",roots64[i],(i < 14 ? "," : "")); }
412 printf("};\n");
413
414 for (i = 0; i < 31; i++)
415 roots128[i] = SAMPLE (cos ((M_PI / 64) * (i + 1)));
416
417 printf("static sample_t roots128[31]={");
418 for (i=0;i<31;i++) { printf("%d%s",roots128[i],(i < 30 ? "," : "")); }
419 printf("};\n");
420 */
421 /*
422 for (i = 0; i < 64; i++) {
423 k = fftorder[i] / 2 + 64;
424 pre1[i].real = SAMPLE (cos ((M_PI / 256) * (k - 0.25)));
425 pre1[i].imag = SAMPLE (sin ((M_PI / 256) * (k - 0.25)));
426 }
427
428 for (i = 64; i < 128; i++) {
429 k = fftorder[i] / 2 + 64;
430 pre1[i].real = SAMPLE (-cos ((M_PI / 256) * (k - 0.25)));
431 pre1[i].imag = SAMPLE (-sin ((M_PI / 256) * (k - 0.25)));
432 }
433
434 printf("static complex_t pre1[128]={");
435 for (i=0;i<128;i++) { printf("{%d,%d}%s",pre1[i].real,pre1[i].imag,(i < 127 ? "," : "")); }
436 printf("};\n");
437 */
438 /*
439 for (i = 0; i < 64; i++) {
440 post1[i].real = SAMPLE (cos ((M_PI / 256) * (i + 0.5)));
441 post1[i].imag = SAMPLE (sin ((M_PI / 256) * (i + 0.5)));
442 }
443
444 printf("static complex_t post1[64]={");
445 for (i=0;i<64;i++) { printf("{%d,%d}%s",post1[i].real,post1[i].imag,(i < 63 ? "," : "")); }
446 printf("};\n");
447 */
448
449 /*
450 for (i = 0; i < 64; i++) {
451 k = fftorder[i] / 4;
452 pre2[i].real = SAMPLE (cos ((M_PI / 128) * (k - 0.25)));
453 pre2[i].imag = SAMPLE (sin ((M_PI / 128) * (k - 0.25)));
454 }
455
456 printf("static complex_t pre2[64]={");
457 for (i=0;i<64;i++) { printf("{%d,%d}%s",pre2[i].real,pre2[i].imag,(i < 63 ? "," : "")); }
458 printf("};\n");
459
460 for (i = 0; i < 32; i++) {
461 post2[i].real = SAMPLE (cos ((M_PI / 128) * (i + 0.5)));
462 post2[i].imag = SAMPLE (sin ((M_PI / 128) * (i + 0.5)));
463 }
464
465 printf("static complex_t post2[32]={");
466 for (i=0;i<32;i++) { printf("{%d,%d}%s",post2[i].real,post2[i].imag,(i < 31 ? "," : "")); }
467 printf("};\n");
468
469
470#ifdef LIBA52_DJBFFT
471 if (mm_accel & MM_ACCEL_DJBFFT) {
472#ifndef LIBA52_DOUBLE
473 ifft128 = (void (*) (complex_t *)) fftc4_un128;
474 ifft64 = (void (*) (complex_t *)) fftc4_un64;
475#else
476 ifft128 = (void (*) (complex_t *)) fftc8_un128;
477 ifft64 = (void (*) (complex_t *)) fftc8_un64;
478#endif
479 } else
480#endif
481 {
482 ifft128 = ifft128_c;
483 ifft64 = ifft64_c;
484 }
485 */
486}
diff --git a/lib/rbcodec/codecs/liba52/imdct_lookups.h b/lib/rbcodec/codecs/liba52/imdct_lookups.h
new file mode 100644
index 0000000000..9d14fe21a7
--- /dev/null
+++ b/lib/rbcodec/codecs/liba52/imdct_lookups.h
@@ -0,0 +1,15 @@
1static const sample_t a52_imdct_window[256]ICONST_ATTR={
2 146020,261886,393529,545197,719447,918478,1144416,1399394,1685589,2005234,2360623,2754115,3188134,3665170,4187773,4758556, 5380193,6055411,6786995,7577779,8430645,9348521,10334375,11391212,12522071,13730020,15018150,16389576,17847424,19394833,21034947,22770912, 24605865,26542938,28585242,30735872,32997891,35374332,37868188,40482408,43219889,46083473,49075937,52199993,55458273,58853331,62387636,66063559, 69883377,73849259,77963266,82227341,86643307,91212859,95937560,100818835,105857968,111056092,116414194,121933098,127613474,133455822,139460477,145627601, 151957182,158449029,165102772,171917855,178893540,186028900,193322822,200774000,208380940,216141958,224055176,232118527,240329753,248686407,257185854,265825270, 274601649,283511802,292552357,301719768,311010314,320420105,329945084,339581031,349323572,359168178,369110174,379144743,389266934,399471665,409753732,420107815, 430528483,441010205,451547355,462134219,472765003,483433845,494134818,504861939,515609181,526370480,537139740,547910849,558677680,569434108,580174011,590891284, 601579849,612233658,622846709,633413050,643926788,654382103,664773249,675094567,685340494,695505569,705584441,715571877,725462772,735252152,744935184,754507184, 763963620,773300119,782512477,791596659,800548807,809365245,818042484,826577226,834966364,843206992,851296404,859232096,867011771,874633340,882094922,889394844, 896531647,903504079,910311101,916951881,923425798,929732436,935871584,941843233,947647575,953284997,958756080,964061593,969202490,974179906,978995149,983649698, 988145195,992483442,996666390,1000696136,1004574919,1008305104,1011889185,1015329772,1018629583,1021791439,1024818257,1027713038,1030478862,1033118881,1035636308,1038034411, 1040316504,1042485942,1044546109,1046500412,1048352275,1050105129,1051762405,1053327531,1054803917,1056194958,1057504020,1058734435,1059889501,1060972468,1061986539,1062934861, 1063820523,1064646551,1065415903,1066131467,1066796055,1067412403,1067983168,1068510924,1068998160,1069447282,1069860607,1070240366,1070588702,1070907668,1071199230,1071465266, 1071707567,1071927836,1072127692,1072308670,1072472221,1072619716,1072752449,1072871635,1072978415,1073073858,1073158963,1073234663,1073301826,1073361257,1073413702,1073459852, 1073500344,1073535763,1073566646,1073593486,1073616731,1073636791,1073654036,1073668804,1073681398,1073692090,1073701126,1073708726,1073715084,1073720373,1073724748,1073728344, 1073731279,1073733657,1073735568,1073737090,1073738291,1073739229,1073739951,1073740500,1073740912,1073741214,1073741431,1073741582,1073741685,1073741751,1073741792,1073741814
3};
4
5static const sample_t roots16[3]ICONST_ATTR={992008094,759250124,410903206};
6static const sample_t roots32[7]ICONST_ATTR={1053110175,992008094,892783698,759250124,596538995,410903206,209476638};
7static const sample_t roots64[15]ICONST_ATTR={1068571463,1053110175,1027506861,992008094,946955747,892783698,830013654,759250124,681174602,596538995,506158392,410903206,311690798,209476638,105245103};
8static const sample_t roots128[31]ICONST_ATTR={1072448454,1068571463,1062120190,1053110175,1041563127,1027506861,1010975241,992008094,970651112,946955747,920979082,892783698,862437519,830013654,795590212,759250124,721080937,681174602,639627257,596538995,552013618,506158392,459083785,410903206,361732725,311690798,260897981,209476638,157550647,105245103,52686014};
9
10static const complex_t pre1[128]ICONST_ATTR={{761575898,756917205},{3294193,1073736770},{413944710,990742792},{-407857834,993264059},{599275209,890949340},{-206244755,1053747885},{-593797166,894609652},{212706548,1052462554},{683717842,827919933},{-101966276,1068889322},{314841678,1026545772},{-503250790,948504162},{-678624950,832099562},{108522938,1068243547},{509061229,945398418},{-308536985,1028458279},{723518379,793374223},{-49395540,1072605046},{364832651,1009860703},{-456103709,972054993},{554836544,919281193},{-257701283,1042358649},{-636978326,864395809},{160808444,1061631832},{-718636707,797798713},{55975991,1072281769},{462059540,969238095},{-358629394,1012080264},{642270168,860471112},{-154291366,1062598550},{-549185496,922668301},{264092224,1040757801},{742770847,775379244},{-23057618,1073494224},{389505993,1000603111},{-432110916,982955574},{577229727,905387953},{-232042906,1048369016},{-615573145,879767700},{186813761,1057365652},{663193747,844449855},{-128167423,1066065014},{289554159,1033963197},{-526376678,935868098},{-698841306,815194659},{82274244,1070585098},{485706670,957606670},{-333683689,1020576650},{-737999227,779922204},{29644020,1073332537},{438134083,980285687},{-383359075,1002974238},{620959710,875974053},{-180322371,1058492015},{-571663505,908912724},{238471209,1046925492},{703830091,810891303},{-75703709,1071069770},{339939548,1018509994},{-479821763,960568883},{-657999815,848503239},{134706262,1065258526},{532109148,932620694},{-283204430,1035720404},{-752230014,-766205918},{9882456,-1073696345},{-401755603,-995747929},{420016001,-988184225},{-588296766,-898236282},{219160333,-1051137599},{604730690,-887255485},{-199775197,-1054993542},{-673506508,-836247862},{115075515,-1067557553},{-302220675,-1030332066},{514852501,-942257080},{688784992,-823709134},{-95405775,-1069494853},{-497421404,-951574195},{321134518,-1024594615},{-713727978,-802193167},{62554335,-1071918121},{-352412636,-1014261720},{467997975,-966384705},{-543513771,-926020671},{270473222,-1039117770},{647537829,-856514018},{-147768480,-1063525261},{728372812,-788919863},{-42813229,-1072887940},{-450130706,-974835294},{371022172,-1007603122},{-631662502,-868287963},{167319467,-1060625145},{560466703,-915859475},{-251300639,-1043920252},{747514502,-770807091},{-16470347,-1073615495},{-426071479,-985588453},{395638246,-998194311},{-610163404,-883528225},{193298118,-1056199480},{582774217,-901829094},{-225605866,-1049773069},{-693826210,-819467323},{88841682,-1070060119},{-327415267,-1022604883},{491573291,-954608403},{668362709,-840364678},{-121623758,-1066831367},{-520624390,-939080267},{295892987,-1032167062},{-733199822,-784435800},{36229307,-1073130440},{-377197724,-1005307605},{444140755,-977578893},{-566075760,-912403275},{244890534,-1045442552},{626322896,-872147426},{-173824191,-1059578527},{708792377,-806557418},{-69130323,-1071514117},{-473918791,-963494932},{346182609,-1016404991},{-652781111,-852524677},{141240030,-1064411930},{537821584,-929338177},{-276844037,-1037438616}};
11
12static const complex_t post1[64]ICONST_ATTR={{1073721611,6588355},{1073559912,19764075},{1073236539,32936819},{1072751541,46104602},{1072104991,59265442},{1071296985,72417357},{1070327646,85558366},{1069197119,98686490},{1067905576,111799753},{1066453209,124896178},{1064840239,137973795},{1063066908,151030634},{1061133483,164064728},{1059040255,177074114},{1056787539,190056834},{1054375675,203010932},{1051805026,215934457},{1049075979,228825463},{1046188946,241682009},{1043144359,254502159},{1039942680,267283981},{1036584388,280025551},{1033069991,292724951},{1029400017,305380267},{1025575020,317989594},{1021595574,330551034},{1017462280,343062693},{1013175760,355522688},{1008736660,367929143},{1004145647,380280189},{999403414,392573967},{994510674,404808624},{989468165,416982318},{984276645,429093217},{978936897,441139495},{973449725,453119340},{967815955,465030947},{962036435,476872521},{956112036,488642280},{950043650,500338452},{943832191,511959274},{937478594,523502998},{930983817,534967883},{924348836,546352205},{917574653,557654248},{910662286,568872310},{903612776,580004702},{896427186,591049747},{889106597,602005783},{881652112,612871159},{874064853,623644238},{866345963,634323399},{858496605,644907034},{850517961,655393547},{842411231,665781361},{834177638,676068911},{825818420,686254647},{817334837,696337035},{808728167,706314558},{799999705,716185713},{791150766,725949012},{782182683,735602987},{773096806,745146182},{763894503,754577161}};
13
14static const complex_t pre2[64]ICONST_ATTR={{1073721611,-6588355},{763894503,754577161},{994510674,404808624},{416982318,989468165},{1054375675,203010932},{602005783,889106597},{215934457,1051805026},{896427186,591049747},{1069197119,98686490},{686254647,825818420},{950043650,500338452},{317989594,1025575020},{111799753,1067905576},{834177638,676068911},{1029400017,305380267},{511959274,943832191},{1072751541,46104602},{725949012,791150766},{973449725,453119340},{367929143,1008736660},{1043144359,254502159},{557654248,917574653},{164064728,1061133483},{866345963,634323399},{59265442,1072104991},{799999705,716185713},{1013175760,355522688},{465030947,967815955},{1063066908,151030634},{644907034,858496605},{267283981,1039942680},{924348836,546352205},{1073559912,19764075},{745146182,773096806},{984276645,429093217},{392573967,999403414},{1049075979,228825463},{580004702,903612776},{190056834,1056787539},{881652112,612871159},{1066453209,124896178},{665781361,842411231},{937478594,523502998},{292724951,1033069991},{85558366,1070327646},{817334837,696337035},{1021595574,330551034},{488642280,956112036},{32936819,1073236539},{782182683,735602987},{1004145647,380280189},{441139495,978936897},{1059040255,177074114},{623644238,874064853},{241682009,1046188946},{910662286,568872310},{1071296985,72417357},{706314558,808728167},{962036435,476872521},{343062693,1017462280},{137973795,1064840239},{850517961,655393547},{1036584388,280025551},{534967883,930983817}};
15static const complex_t post2[32]ICONST_ATTR={{1073660973,13176463},{1073014239,39521454},{1071721163,65842639},{1069782521,92124162},{1067199482,118350193},{1063973603,144504935},{1060106825,170572632},{1055601479,196537583},{1050460278,222384146},{1044686318,248096754},{1038283079,273659918},{1031254417,299058239},{1023604566,324276418},{1015338134,349299266},{1006460100,374111709},{996975812,398698801},{986890983,423045731},{976211688,447137835},{964944359,470960600},{953095785,494499675},{940673100,517740882},{927683790,540670222},{914135677,563273882},{900036924,585538247},{885396022,607449906},{870221790,628995659},{854523369,650162530},{838310215,670937766},{821592095,691308855},{804379078,711263525},{786681534,730789756},{768510121,749875787}};
diff --git a/lib/rbcodec/codecs/liba52/liba52.make b/lib/rbcodec/codecs/liba52/liba52.make
new file mode 100644
index 0000000000..04cae4f080
--- /dev/null
+++ b/lib/rbcodec/codecs/liba52/liba52.make
@@ -0,0 +1,18 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9
10# liba52
11A52LIB := $(CODECDIR)/liba52.a
12A52LIB_SRC := $(call preprocess, $(RBCODECLIB_DIR)/codecs/liba52/SOURCES)
13A52LIB_OBJ := $(call c2obj, $(A52LIB_SRC))
14OTHER_SRC += $(A52LIB_SRC)
15
16$(A52LIB): $(A52LIB_OBJ)
17 $(SILENT)$(shell rm -f $@)
18 $(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null
diff --git a/lib/rbcodec/codecs/liba52/mm_accel.h b/lib/rbcodec/codecs/liba52/mm_accel.h
new file mode 100644
index 0000000000..aafc3fed82
--- /dev/null
+++ b/lib/rbcodec/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/lib/rbcodec/codecs/liba52/parse.c b/lib/rbcodec/codecs/liba52/parse.c
new file mode 100644
index 0000000000..c61c13cdb5
--- /dev/null
+++ b/lib/rbcodec/codecs/liba52/parse.c
@@ -0,0 +1,956 @@
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-a52.h"
25
26#include <string.h>
27#include <inttypes.h>
28
29#include "a52.h"
30#include "a52_internal.h"
31#include "bitstream.h"
32#include "tables.h"
33
34#if defined(HAVE_MEMALIGN) && !defined(__cplusplus)
35/* some systems have memalign() but no declaration for it */
36void * memalign (size_t align, size_t size);
37#else
38/* assume malloc alignment is sufficient */
39#define memalign(align,size) malloc (size)
40#endif
41
42typedef struct {
43 quantizer_t q1[2];
44 quantizer_t q2[2];
45 quantizer_t q4;
46 int q1_ptr;
47 int q2_ptr;
48 int q4_ptr;
49} quantizer_set_t;
50
51static a52_state_t istate IBSS_ATTR;
52static sample_t isamples[256*12] IBSS_ATTR;
53
54static uint8_t halfrate[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
55
56a52_state_t * a52_init (uint32_t mm_accel)
57{
58 a52_state_t * state;
59 int i;
60
61 #if defined(CPU_COLDFIRE)
62 coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_ROUND | EMAC_SATURATE);
63 #endif
64 /*
65 this needs to come back if we ever want two decoder instances
66 simultenously. NOTE, you also need to remove comments in a52_free.
67 state = (a52_state_t *) malloc (sizeof (a52_state_t));
68 if (state == NULL)
69 return NULL;
70
71 state->samples = (sample_t *) memalign (16, 256 * 12 * sizeof (sample_t));
72 if (state->samples == NULL) {
73 free (state);
74 return NULL;
75 }
76
77 */
78 state = &istate;
79 state->samples = isamples;
80 for (i = 0; i < 256 * 12; i++)
81 state->samples[i] = 0;
82
83 state->downmixed = 1;
84
85 state->lfsr_state = 1;
86
87 a52_imdct_init (mm_accel);
88
89 return state;
90}
91
92sample_t * a52_samples (a52_state_t * state)
93{
94 return state->samples;
95}
96
97int a52_syncinfo (uint8_t * buf, int * flags,
98 int * sample_rate, int * bit_rate)
99{
100 static int rate[] = { 32, 40, 48, 56, 64, 80, 96, 112,
101 128, 160, 192, 224, 256, 320, 384, 448,
102 512, 576, 640};
103 static uint8_t lfeon[8] = {0x10, 0x10, 0x04, 0x04, 0x04, 0x01, 0x04, 0x01};
104 int frmsizecod;
105 int bitrate;
106 int half;
107 int acmod;
108
109 if ((buf[0] != 0x0b) || (buf[1] != 0x77)) /* syncword */
110 return 0;
111
112 if (buf[5] >= 0x60) /* bsid >= 12 */
113 return 0;
114 half = halfrate[buf[5] >> 3];
115
116 /* acmod, dsurmod and lfeon */
117 acmod = buf[6] >> 5;
118 *flags = ((((buf[6] & 0xf8) == 0x50) ? A52_DOLBY : acmod) |
119 ((buf[6] & lfeon[acmod]) ? A52_LFE : 0));
120
121 frmsizecod = buf[4] & 63;
122 if (frmsizecod >= 38)
123 return 0;
124 bitrate = rate [frmsizecod >> 1];
125 *bit_rate = (bitrate * 1000) >> half;
126
127 switch (buf[4] & 0xc0) {
128 case 0:
129 *sample_rate = 48000 >> half;
130 return 4 * bitrate;
131 case 0x40:
132 *sample_rate = 44100 >> half;
133 return 2 * (320 * bitrate / 147 + (frmsizecod & 1));
134 case 0x80:
135 *sample_rate = 32000 >> half;
136 return 6 * bitrate;
137 default:
138 return 0;
139 }
140}
141
142int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
143 level_t * level, sample_t bias)
144{
145 static level_t clev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_45DB),
146 LEVEL (LEVEL_6DB), LEVEL (LEVEL_45DB) };
147 static level_t slev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_6DB),
148 0, LEVEL (LEVEL_6DB) };
149 int chaninfo;
150 int acmod;
151
152 state->fscod = buf[4] >> 6;
153 state->halfrate = halfrate[buf[5] >> 3];
154 state->acmod = acmod = buf[6] >> 5;
155
156 a52_bitstream_set_ptr (state, buf + 6);
157 bitstream_get (state, 3); /* skip acmod we already parsed */
158
159 if ((acmod == 2) && (bitstream_get (state, 2) == 2)) /* dsurmod */
160 acmod = A52_DOLBY;
161
162 state->clev = state->slev = 0;
163
164 if ((acmod & 1) && (acmod != 1))
165 state->clev = clev[bitstream_get (state, 2)]; /* cmixlev */
166
167 if (acmod & 4)
168 state->slev = slev[bitstream_get (state, 2)]; /* surmixlev */
169
170 state->lfeon = bitstream_get (state, 1);
171
172 state->output = a52_downmix_init (acmod, *flags, level,
173 state->clev, state->slev);
174 if (state->output < 0)
175 return 1;
176 if (state->lfeon && (*flags & A52_LFE))
177 state->output |= A52_LFE;
178 *flags = state->output;
179 /* the 2* compensates for differences in imdct */
180 state->dynrng = state->level = MUL_C (*level, 2);
181 state->bias = bias;
182 state->dynrnge = 1;
183 state->dynrngcall = NULL;
184 state->cplba.deltbae = DELTA_BIT_NONE;
185 state->ba[0].deltbae = state->ba[1].deltbae = state->ba[2].deltbae =
186 state->ba[3].deltbae = state->ba[4].deltbae = DELTA_BIT_NONE;
187
188 chaninfo = !acmod;
189 do {
190 bitstream_get (state, 5); /* dialnorm */
191 if (bitstream_get (state, 1)) /* compre */
192 bitstream_get (state, 8); /* compr */
193 if (bitstream_get (state, 1)) /* langcode */
194 bitstream_get (state, 8); /* langcod */
195 if (bitstream_get (state, 1)) /* audprodie */
196 bitstream_get (state, 7); /* mixlevel + roomtyp */
197 } while (chaninfo--);
198
199 bitstream_get (state, 2); /* copyrightb + origbs */
200
201 if (bitstream_get (state, 1)) /* timecod1e */
202 bitstream_get (state, 14); /* timecod1 */
203 if (bitstream_get (state, 1)) /* timecod2e */
204 bitstream_get (state, 14); /* timecod2 */
205
206 if (bitstream_get (state, 1)) { /* addbsie */
207 int addbsil;
208
209 addbsil = bitstream_get (state, 6);
210 do {
211 bitstream_get (state, 8); /* addbsi */
212 } while (addbsil--);
213 }
214
215 return 0;
216}
217
218void a52_dynrng (a52_state_t * state,
219 level_t (* call) (level_t, void *), void * data)
220{
221 state->dynrnge = 0;
222 if (call) {
223 state->dynrnge = 1;
224 state->dynrngcall = call;
225 state->dynrngdata = data;
226 }
227}
228
229static int parse_exponents (a52_state_t * state, int expstr, int ngrps,
230 uint8_t exponent, uint8_t * dest)
231{
232 int exps;
233
234 while (ngrps--) {
235 exps = bitstream_get (state, 7);
236
237 exponent += exp_1[exps];
238 if (exponent > 24)
239 return 1;
240
241 switch (expstr) {
242 case EXP_D45:
243 *(dest++) = exponent;
244 *(dest++) = exponent;
245 case EXP_D25:
246 *(dest++) = exponent;
247 case EXP_D15:
248 *(dest++) = exponent;
249 }
250
251 exponent += exp_2[exps];
252 if (exponent > 24)
253 return 1;
254
255 switch (expstr) {
256 case EXP_D45:
257 *(dest++) = exponent;
258 *(dest++) = exponent;
259 case EXP_D25:
260 *(dest++) = exponent;
261 case EXP_D15:
262 *(dest++) = exponent;
263 }
264
265 exponent += exp_3[exps];
266 if (exponent > 24)
267 return 1;
268
269 switch (expstr) {
270 case EXP_D45:
271 *(dest++) = exponent;
272 *(dest++) = exponent;
273 case EXP_D25:
274 *(dest++) = exponent;
275 case EXP_D15:
276 *(dest++) = exponent;
277 }
278 }
279
280 return 0;
281}
282
283static int parse_deltba (a52_state_t * state, int8_t * deltba)
284{
285 int deltnseg, deltlen, delta, j;
286
287 memset (deltba, 0, 50);
288
289 deltnseg = bitstream_get (state, 3);
290 j = 0;
291 do {
292 j += bitstream_get (state, 5);
293 deltlen = bitstream_get (state, 4);
294 delta = bitstream_get (state, 3);
295 delta -= (delta >= 4) ? 3 : 4;
296 if (!deltlen)
297 continue;
298 if (j + deltlen >= 50)
299 return 1;
300 while (deltlen--)
301 deltba[j++] = delta;
302 } while (deltnseg--);
303
304 return 0;
305}
306
307static inline int zero_snr_offsets (int nfchans, a52_state_t * state)
308{
309 int i;
310
311 if ((state->csnroffst) ||
312 (state->chincpl && state->cplba.bai >> 3) || /* cplinu, fsnroffst */
313 (state->lfeon && state->lfeba.bai >> 3)) /* fsnroffst */
314 return 0;
315 for (i = 0; i < nfchans; i++)
316 if (state->ba[i].bai >> 3) /* fsnroffst */
317 return 0;
318 return 1;
319}
320
321static inline int16_t dither_gen (a52_state_t * state)
322{
323 int16_t nstate;
324
325 nstate = dither_lut[state->lfsr_state >> 8] ^ (state->lfsr_state << 8);
326
327 state->lfsr_state = (uint16_t) nstate;
328
329 return (3 * nstate) >> 2;
330}
331
332#ifndef LIBA52_FIXED
333#define COEFF(c,t,l,s,e) (c) = (t) * (s)[e]
334#else
335#define COEFF(c,_t,_l,s,e) do { \
336 quantizer_t t = (_t); \
337 level_t l = (_l); \
338 int shift = e - 5; \
339 sample_t tmp = t * (l >> 16) + ((t * (l & 0xffff)) >> 16); \
340 if (shift >= 0) \
341 (c) = tmp >> shift; \
342 else \
343 (c) = tmp << -shift; \
344} while (0)
345#endif
346
347static void coeff_get (a52_state_t * state, sample_t * coeff,
348 expbap_t * expbap, quantizer_set_t * quant,
349 level_t level, int dither, int end)
350{
351 int i;
352 uint8_t * exp;
353 int8_t * bap;
354
355#ifndef LIBA52_FIXED
356 sample_t factor[25];
357
358 for (i = 0; i <= 24; i++)
359 factor[i] = scale_factor[i] * level;
360#endif
361
362 exp = expbap->exp;
363 bap = expbap->bap;
364
365 for (i = 0; i < end; i++) {
366 int bapi;
367
368 bapi = bap[i];
369 switch (bapi) {
370 case 0:
371 if (dither) {
372 COEFF (coeff[i], dither_gen (state), level, factor, exp[i]);
373 continue;
374 } else {
375 coeff[i] = 0;
376 continue;
377 }
378
379 case -1:
380 if (quant->q1_ptr >= 0) {
381 COEFF (coeff[i], quant->q1[quant->q1_ptr--], level,
382 factor, exp[i]);
383 continue;
384 } else {
385 int code;
386
387 code = bitstream_get (state, 5);
388
389 quant->q1_ptr = 1;
390 quant->q1[0] = q_1_2[code];
391 quant->q1[1] = q_1_1[code];
392 COEFF (coeff[i], q_1_0[code], level, factor, exp[i]);
393 continue;
394 }
395
396 case -2:
397 if (quant->q2_ptr >= 0) {
398 COEFF (coeff[i], quant->q2[quant->q2_ptr--], level,
399 factor, exp[i]);
400 continue;
401 } else {
402 int code;
403
404 code = bitstream_get (state, 7);
405
406 quant->q2_ptr = 1;
407 quant->q2[0] = q_2_2[code];
408 quant->q2[1] = q_2_1[code];
409 COEFF (coeff[i], q_2_0[code], level, factor, exp[i]);
410 continue;
411 }
412
413 case 3:
414 COEFF (coeff[i], q_3[bitstream_get (state, 3)], level,
415 factor, exp[i]);
416 continue;
417
418 case -3:
419 if (quant->q4_ptr == 0) {
420 quant->q4_ptr = -1;
421 COEFF (coeff[i], quant->q4, level, factor, exp[i]);
422 continue;
423 } else {
424 int code;
425
426 code = bitstream_get (state, 7);
427
428 quant->q4_ptr = 0;
429 quant->q4 = q_4_1[code];
430 COEFF (coeff[i], q_4_0[code], level, factor, exp[i]);
431 continue;
432 }
433
434 case 4:
435 COEFF (coeff[i], q_5[bitstream_get (state, 4)], level,
436 factor, exp[i]);
437 continue;
438
439 default:
440 COEFF (coeff[i], bitstream_get_2 (state, bapi) << (16 - bapi),
441 level, factor, exp[i]);
442 }
443 }
444}
445
446static void coeff_get_coupling (a52_state_t * state, int nfchans,
447 level_t * coeff, sample_t (* samples)[256],
448 quantizer_set_t * quant, uint8_t dithflag[5])
449{
450 int cplbndstrc, bnd, i, i_end, ch;
451 uint8_t * exp;
452 int8_t * bap;
453 level_t cplco[5];
454
455 exp = state->cpl_expbap.exp;
456 bap = state->cpl_expbap.bap;
457 bnd = 0;
458 cplbndstrc = state->cplbndstrc;
459 i = state->cplstrtmant;
460 while (i < state->cplendmant) {
461 i_end = i + 12;
462 while (cplbndstrc & 1) {
463 cplbndstrc >>= 1;
464 i_end += 12;
465 }
466 cplbndstrc >>= 1;
467 for (ch = 0; ch < nfchans; ch++)
468 cplco[ch] = MUL_L (state->cplco[ch][bnd], coeff[ch]);
469 bnd++;
470
471 while (i < i_end) {
472 quantizer_t cplcoeff;
473 int bapi;
474
475 bapi = bap[i];
476 switch (bapi) {
477 case 0:
478 for (ch = 0; ch < nfchans; ch++)
479 if ((state->chincpl >> ch) & 1) {
480 if (dithflag[ch])
481#ifndef LIBA52_FIXED
482 samples[ch][i] = (scale_factor[exp[i]] *
483 cplco[ch] * dither_gen (state));
484#else
485 COEFF (samples[ch][i], dither_gen (state),
486 cplco[ch], scale_factor, exp[i]);
487#endif
488 else
489 samples[ch][i] = 0;
490 }
491 i++;
492 continue;
493
494 case -1:
495 if (quant->q1_ptr >= 0) {
496 cplcoeff = quant->q1[quant->q1_ptr--];
497 break;
498 } else {
499 int code;
500
501 code = bitstream_get (state, 5);
502
503 quant->q1_ptr = 1;
504 quant->q1[0] = q_1_2[code];
505 quant->q1[1] = q_1_1[code];
506 cplcoeff = q_1_0[code];
507 break;
508 }
509
510 case -2:
511 if (quant->q2_ptr >= 0) {
512 cplcoeff = quant->q2[quant->q2_ptr--];
513 break;
514 } else {
515 int code;
516
517 code = bitstream_get (state, 7);
518
519 quant->q2_ptr = 1;
520 quant->q2[0] = q_2_2[code];
521 quant->q2[1] = q_2_1[code];
522 cplcoeff = q_2_0[code];
523 break;
524 }
525
526 case 3:
527 cplcoeff = q_3[bitstream_get (state, 3)];
528 break;
529
530 case -3:
531 if (quant->q4_ptr == 0) {
532 quant->q4_ptr = -1;
533 cplcoeff = quant->q4;
534 break;
535 } else {
536 int code;
537
538 code = bitstream_get (state, 7);
539
540 quant->q4_ptr = 0;
541 quant->q4 = q_4_1[code];
542 cplcoeff = q_4_0[code];
543 break;
544 }
545
546 case 4:
547 cplcoeff = q_5[bitstream_get (state, 4)];
548 break;
549
550 default:
551 cplcoeff = bitstream_get_2 (state, bapi) << (16 - bapi);
552 }
553#ifndef LIBA52_FIXED
554 cplcoeff *= scale_factor[exp[i]];
555#endif
556 for (ch = 0; ch < nfchans; ch++)
557 if ((state->chincpl >> ch) & 1)
558#ifndef LIBA52_FIXED
559 samples[ch][i] = cplcoeff * cplco[ch];
560#else
561 COEFF (samples[ch][i], cplcoeff, cplco[ch],
562 scale_factor, exp[i]);
563#endif
564 i++;
565 }
566 }
567}
568
569int a52_block (a52_state_t * state)
570{
571 static const uint8_t nfchans_tbl[] = {2, 1, 2, 3, 3, 4, 4, 5, 1, 1, 2};
572 static int rematrix_band[4] = {25, 37, 61, 253};
573 int i, nfchans, chaninfo;
574 uint8_t cplexpstr, chexpstr[5], lfeexpstr, do_bit_alloc, done_cpl;
575 uint8_t blksw[5], dithflag[5];
576 level_t coeff[5];
577 int chanbias;
578 quantizer_set_t quant;
579 sample_t * samples;
580
581 nfchans = nfchans_tbl[state->acmod];
582
583 for (i = 0; i < nfchans; i++)
584 blksw[i] = bitstream_get (state, 1);
585
586 for (i = 0; i < nfchans; i++)
587 dithflag[i] = bitstream_get (state, 1);
588
589 chaninfo = !state->acmod;
590 do {
591 if (bitstream_get (state, 1)) { /* dynrnge */
592 int dynrng;
593
594 dynrng = bitstream_get_2 (state, 8);
595 if (state->dynrnge) {
596 level_t range;
597
598#if !defined(LIBA52_FIXED)
599 range = ((((dynrng & 0x1f) | 0x20) << 13) *
600 scale_factor[3 - (dynrng >> 5)]);
601#else
602 range = ((dynrng & 0x1f) | 0x20) << (21 + (dynrng >> 5));
603#endif
604 if (state->dynrngcall)
605 range = state->dynrngcall (range, state->dynrngdata);
606 state->dynrng = MUL_L (state->level, range);
607 }
608 }
609 } while (chaninfo--);
610
611 if (bitstream_get (state, 1)) { /* cplstre */
612 state->chincpl = 0;
613 if (bitstream_get (state, 1)) { /* cplinu */
614 static uint8_t bndtab[16] = {31, 35, 37, 39, 41, 42, 43, 44,
615 45, 45, 46, 46, 47, 47, 48, 48};
616 int cplbegf;
617 int cplendf;
618 int ncplsubnd;
619
620 for (i = 0; i < nfchans; i++)
621 state->chincpl |= bitstream_get (state, 1) << i;
622 switch (state->acmod) {
623 case 0: case 1:
624 return 1;
625 case 2:
626 state->phsflginu = bitstream_get (state, 1);
627 }
628 cplbegf = bitstream_get (state, 4);
629 cplendf = bitstream_get (state, 4);
630
631 if (cplendf + 3 - cplbegf < 0)
632 return 1;
633 state->ncplbnd = ncplsubnd = cplendf + 3 - cplbegf;
634 state->cplstrtbnd = bndtab[cplbegf];
635 state->cplstrtmant = cplbegf * 12 + 37;
636 state->cplendmant = cplendf * 12 + 73;
637
638 state->cplbndstrc = 0;
639 for (i = 0; i < ncplsubnd - 1; i++)
640 if (bitstream_get (state, 1)) {
641 state->cplbndstrc |= 1 << i;
642 state->ncplbnd--;
643 }
644 }
645 }
646
647 if (state->chincpl) { /* cplinu */
648 int j, cplcoe;
649
650 cplcoe = 0;
651 for (i = 0; i < nfchans; i++)
652 if ((state->chincpl) >> i & 1)
653 if (bitstream_get (state, 1)) { /* cplcoe */
654 int mstrcplco, cplcoexp, cplcomant;
655
656 cplcoe = 1;
657 mstrcplco = 3 * bitstream_get (state, 2);
658 for (j = 0; j < state->ncplbnd; j++) {
659 cplcoexp = bitstream_get (state, 4);
660 cplcomant = bitstream_get (state, 4);
661 if (cplcoexp == 15)
662 cplcomant <<= 14;
663 else
664 cplcomant = (cplcomant | 0x10) << 13;
665#ifndef LIBA52_FIXED
666 state->cplco[i][j] =
667 cplcomant * scale_factor[cplcoexp + mstrcplco];
668#else
669 state->cplco[i][j] = (cplcomant << 11) >> (cplcoexp + mstrcplco);
670#endif
671
672 }
673 }
674 if ((state->acmod == 2) && state->phsflginu && cplcoe)
675 for (j = 0; j < state->ncplbnd; j++)
676 if (bitstream_get (state, 1)) /* phsflg */
677 state->cplco[1][j] = -state->cplco[1][j];
678 }
679
680 if ((state->acmod == 2) && (bitstream_get (state, 1))) { /* rematstr */
681 int end;
682
683 state->rematflg = 0;
684 end = (state->chincpl) ? state->cplstrtmant : 253; /* cplinu */
685 i = 0;
686 do
687 state->rematflg |= bitstream_get (state, 1) << i;
688 while (rematrix_band[i++] < end);
689 }
690
691 cplexpstr = EXP_REUSE;
692 lfeexpstr = EXP_REUSE;
693 if (state->chincpl) /* cplinu */
694 cplexpstr = bitstream_get (state, 2);
695 for (i = 0; i < nfchans; i++)
696 chexpstr[i] = bitstream_get (state, 2);
697 if (state->lfeon)
698 lfeexpstr = bitstream_get (state, 1);
699
700 for (i = 0; i < nfchans; i++)
701 if (chexpstr[i] != EXP_REUSE) {
702 if ((state->chincpl >> i) & 1)
703 state->endmant[i] = state->cplstrtmant;
704 else {
705 int chbwcod;
706
707 chbwcod = bitstream_get (state, 6);
708 if (chbwcod > 60)
709 return 1;
710 state->endmant[i] = chbwcod * 3 + 73;
711 }
712 }
713
714 do_bit_alloc = 0;
715
716 if (cplexpstr != EXP_REUSE) {
717 int cplabsexp, ncplgrps;
718
719 do_bit_alloc = 64;
720 ncplgrps = ((state->cplendmant - state->cplstrtmant) /
721 (3 << (cplexpstr - 1)));
722 cplabsexp = bitstream_get (state, 4) << 1;
723 if (parse_exponents (state, cplexpstr, ncplgrps, cplabsexp,
724 state->cpl_expbap.exp + state->cplstrtmant))
725 return 1;
726 }
727 for (i = 0; i < nfchans; i++)
728 if (chexpstr[i] != EXP_REUSE) {
729 int grp_size, nchgrps;
730
731 do_bit_alloc |= 1 << i;
732 grp_size = 3 << (chexpstr[i] - 1);
733 nchgrps = (state->endmant[i] + grp_size - 4) / grp_size;
734 state->fbw_expbap[i].exp[0] = bitstream_get (state, 4);
735 if (parse_exponents (state, chexpstr[i], nchgrps,
736 state->fbw_expbap[i].exp[0],
737 state->fbw_expbap[i].exp + 1))
738 return 1;
739 bitstream_get (state, 2); /* gainrng */
740 }
741 if (lfeexpstr != EXP_REUSE) {
742 do_bit_alloc |= 32;
743 state->lfe_expbap.exp[0] = bitstream_get (state, 4);
744 if (parse_exponents (state, lfeexpstr, 2, state->lfe_expbap.exp[0],
745 state->lfe_expbap.exp + 1))
746 return 1;
747 }
748
749 if (bitstream_get (state, 1)) { /* baie */
750 do_bit_alloc = 127;
751 state->bai = bitstream_get (state, 11);
752 }
753 if (bitstream_get (state, 1)) { /* snroffste */
754 do_bit_alloc = 127;
755 state->csnroffst = bitstream_get (state, 6);
756 if (state->chincpl) /* cplinu */
757 state->cplba.bai = bitstream_get (state, 7);
758 for (i = 0; i < nfchans; i++)
759 state->ba[i].bai = bitstream_get (state, 7);
760 if (state->lfeon)
761 state->lfeba.bai = bitstream_get (state, 7);
762 }
763 if ((state->chincpl) && (bitstream_get (state, 1))) { /* cplleake */
764 do_bit_alloc |= 64;
765 state->cplfleak = 9 - bitstream_get (state, 3);
766 state->cplsleak = 9 - bitstream_get (state, 3);
767 }
768
769 if (bitstream_get (state, 1)) { /* deltbaie */
770 do_bit_alloc = 127;
771 if (state->chincpl) /* cplinu */
772 state->cplba.deltbae = bitstream_get (state, 2);
773 for (i = 0; i < nfchans; i++)
774 state->ba[i].deltbae = bitstream_get (state, 2);
775 if (state->chincpl && /* cplinu */
776 (state->cplba.deltbae == DELTA_BIT_NEW) &&
777 parse_deltba (state, state->cplba.deltba))
778 return 1;
779 for (i = 0; i < nfchans; i++)
780 if ((state->ba[i].deltbae == DELTA_BIT_NEW) &&
781 parse_deltba (state, state->ba[i].deltba))
782 return 1;
783 }
784
785 if (do_bit_alloc) {
786 if (zero_snr_offsets (nfchans, state)) {
787 memset (state->cpl_expbap.bap, 0, sizeof (state->cpl_expbap.bap));
788 for (i = 0; i < nfchans; i++)
789 memset (state->fbw_expbap[i].bap, 0,
790 sizeof (state->fbw_expbap[i].bap));
791 memset (state->lfe_expbap.bap, 0, sizeof (state->lfe_expbap.bap));
792 } else {
793 if (state->chincpl && (do_bit_alloc & 64)) /* cplinu */
794 a52_bit_allocate (state, &state->cplba, state->cplstrtbnd,
795 state->cplstrtmant, state->cplendmant,
796 state->cplfleak << 8, state->cplsleak << 8,
797 &state->cpl_expbap);
798 for (i = 0; i < nfchans; i++)
799 if (do_bit_alloc & (1 << i))
800 a52_bit_allocate (state, state->ba + i, 0, 0,
801 state->endmant[i], 0, 0,
802 state->fbw_expbap +i);
803 if (state->lfeon && (do_bit_alloc & 32)) {
804 state->lfeba.deltbae = DELTA_BIT_NONE;
805 a52_bit_allocate (state, &state->lfeba, 0, 0, 7, 0, 0,
806 &state->lfe_expbap);
807 }
808 }
809 }
810
811 if (bitstream_get (state, 1)) { /* skiple */
812 i = bitstream_get (state, 9); /* skipl */
813 while (i--)
814 bitstream_get (state, 8);
815 }
816
817 samples = state->samples;
818 if (state->output & A52_LFE)
819 samples += 256; /* shift for LFE channel */
820
821 chanbias = a52_downmix_coeff (coeff, state->acmod, state->output,
822 state->dynrng, state->clev, state->slev);
823
824 quant.q1_ptr = quant.q2_ptr = quant.q4_ptr = -1;
825 done_cpl = 0;
826
827 for (i = 0; i < nfchans; i++) {
828 int j;
829
830 coeff_get (state, samples + 256 * i, state->fbw_expbap +i, &quant,
831 coeff[i], dithflag[i], state->endmant[i]);
832
833 if ((state->chincpl >> i) & 1) {
834 if (!done_cpl) {
835 done_cpl = 1;
836 coeff_get_coupling (state, nfchans, coeff,
837 (sample_t (*)[256])samples, &quant,
838 dithflag);
839 }
840 j = state->cplendmant;
841 } else
842 j = state->endmant[i];
843 do
844 (samples + 256 * i)[j] = 0;
845 while (++j < 256);
846 }
847
848 if (state->acmod == 2) {
849 int j, end, band, rematflg;
850
851 end = ((state->endmant[0] < state->endmant[1]) ?
852 state->endmant[0] : state->endmant[1]);
853
854 i = 0;
855 j = 13;
856 rematflg = state->rematflg;
857 do {
858 if (! (rematflg & 1)) {
859 rematflg >>= 1;
860 j = rematrix_band[i++];
861 continue;
862 }
863 rematflg >>= 1;
864 band = rematrix_band[i++];
865 if (band > end)
866 band = end;
867 do {
868 sample_t tmp0, tmp1;
869
870 tmp0 = samples[j];
871 tmp1 = (samples+256)[j];
872 samples[j] = tmp0 + tmp1;
873 (samples+256)[j] = tmp0 - tmp1;
874 } while (++j < band);
875 } while (j < end);
876 }
877
878 if (state->lfeon) {
879 if (state->output & A52_LFE) {
880 coeff_get (state, samples - 256, &state->lfe_expbap, &quant,
881 state->dynrng, 0, 7);
882 for (i = 7; i < 256; i++)
883 (samples-256)[i] = 0;
884 a52_imdct_512 (samples - 256, samples + 1536 - 256);
885 } else {
886 /* just skip the LFE coefficients */
887 coeff_get (state, samples + 1280, &state->lfe_expbap, &quant,
888 0, 0, 7);
889 }
890 }
891
892 i = 0;
893 if (nfchans_tbl[state->output & A52_CHANNEL_MASK] < nfchans)
894 for (i = 1; i < nfchans; i++)
895 if (blksw[i] != blksw[0])
896 break;
897
898 if (i < nfchans) {
899 if (state->downmixed) {
900 state->downmixed = 0;
901 a52_upmix (samples + 1536, state->acmod, state->output);
902 }
903
904 for (i = 0; i < nfchans; i++) {
905 sample_t bias;
906
907 bias = 0;
908 if (!(chanbias & (1 << i)))
909 bias = state->bias;
910
911 if (coeff[i]) {
912 if (blksw[i])
913 a52_imdct_256 (samples + 256 * i, samples + 1536 + 256 * i);
914 else
915 a52_imdct_512 (samples + 256 * i, samples + 1536 + 256 * i);
916 } else {
917 int j;
918
919 for (j = 0; j < 256; j++)
920 (samples + 256 * i)[j] = bias;
921 }
922 }
923
924 a52_downmix (samples, state->acmod, state->output,
925 state->clev, state->slev);
926 } else {
927 nfchans = nfchans_tbl[state->output & A52_CHANNEL_MASK];
928
929 a52_downmix (samples, state->acmod, state->output,
930 state->clev, state->slev);
931
932 if (!state->downmixed) {
933 state->downmixed = 1;
934 a52_downmix (samples + 1536, state->acmod, state->output,
935 state->clev, state->slev);
936 }
937
938 if (blksw[0])
939 for (i = 0; i < nfchans; i++)
940 a52_imdct_256 (samples + 256 * i, samples + 1536 + 256 * i);
941 else
942 for (i = 0; i < nfchans; i++)
943 a52_imdct_512 (samples + 256 * i, samples + 1536 + 256 * i);
944 }
945
946 return 0;
947}
948
949void a52_free (a52_state_t * state)
950{
951 (void)state;
952 /*
953 free (state->samples);
954 free (state);
955 */
956}
diff --git a/lib/rbcodec/codecs/liba52/tables.h b/lib/rbcodec/codecs/liba52/tables.h
new file mode 100644
index 0000000000..b067c63f69
--- /dev/null
+++ b/lib/rbcodec/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/lib/rbcodec/codecs/liba52/tendra.h b/lib/rbcodec/codecs/liba52/tendra.h
new file mode 100644
index 0000000000..cc740fceeb
--- /dev/null
+++ b/lib/rbcodec/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 */