From 52a7faa517bcf8485d3c627cc94427f780b68eb8 Mon Sep 17 00:00:00 2001 From: Lucas Eckels Date: Mon, 6 Aug 2012 15:08:56 -0700 Subject: Add faad source. Change-Id: Ibb19041b539d5ed22bb0e757bd957ee9ab8c92e6 --- .gitignore | 33 + COPYING | 482 ++++++++ Makefile | 48 + Makefile.am | 38 + README | 18 + all.h | 458 +++++++ bits.c | 123 ++ bits.h | 81 ++ block.c | 376 ++++++ block.h | 80 ++ config.c | 645 ++++++++++ decdata.c | 234 ++++ decoder.c | 608 ++++++++++ dolby_adapt.c | 537 +++++++++ fastfft.c | 2908 +++++++++++++++++++++++++++++++++++++++++++++ fastfft.h | 32 + huffdec.c | 967 +++++++++++++++ huffinit.c | 121 ++ hufftables.c | 1432 ++++++++++++++++++++++ intensity.c | 89 ++ interface.h | 236 ++++ kbd_win.h | 1198 +++++++++++++++++++ libfaad.sln | 20 + libfaad.vcproj | 634 ++++++++++ libfaad60.dsp | 235 ++++ monopred.c | 418 +++++++ monopred.h | 49 + mpeg4ip_config_Linux32.h | 245 ++++ nok_lt_prediction.c | 178 +++ nok_lt_prediction.h | 56 + nok_ltp_common.h | 88 ++ nok_ltp_common_internal.h | 117 ++ pns.c | 176 +++ port.h | 83 ++ stereo.c | 99 ++ tns.c | 245 ++++ tns.h | 59 + transfo.c | 461 +++++++ transfo.h | 58 + util.c | 89 ++ util.h | 43 + 41 files changed, 14097 insertions(+) create mode 100644 .gitignore create mode 100644 COPYING create mode 100644 Makefile create mode 100644 Makefile.am create mode 100644 README create mode 100644 all.h create mode 100644 bits.c create mode 100644 bits.h create mode 100644 block.c create mode 100644 block.h create mode 100755 config.c create mode 100644 decdata.c create mode 100644 decoder.c create mode 100644 dolby_adapt.c create mode 100644 fastfft.c create mode 100644 fastfft.h create mode 100644 huffdec.c create mode 100644 huffinit.c create mode 100644 hufftables.c create mode 100644 intensity.c create mode 100644 interface.h create mode 100644 kbd_win.h create mode 100644 libfaad.sln create mode 100644 libfaad.vcproj create mode 100644 libfaad60.dsp create mode 100644 monopred.c create mode 100644 monopred.h create mode 100644 mpeg4ip_config_Linux32.h create mode 100644 nok_lt_prediction.c create mode 100644 nok_lt_prediction.h create mode 100644 nok_ltp_common.h create mode 100644 nok_ltp_common_internal.h create mode 100644 pns.c create mode 100644 port.h create mode 100644 stereo.c create mode 100644 tns.c create mode 100644 tns.h create mode 100644 transfo.c create mode 100644 transfo.h create mode 100644 util.c create mode 100644 util.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5301a8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +/build +/source/build +*.mode1v3 +*.pbxuser +*.pbxindex/ +!user.pbxuser +/*.log +*.user +*.ncb +*.suo +*.pdb +*.pdf +*.html +*.idb +*.o +*.lo +*.a +*.so +*.so.0 +*.la +.deps +.libs +*.pyc +.DS_Store +# Emacs and other editor backup files +*~ + +# builds on Windows +Debug/ +Release/ +release/ + +/mpeg4ip_config.h \ No newline at end of file diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..bf50f20 --- /dev/null +++ b/COPYING @@ -0,0 +1,482 @@ + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307 USA. + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f5ef5da --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +################################################### +# +# Makefile for libaacdec.so +# +################################################### + +C_SRCS= \ + bits.c \ + block.c \ + config.c \ + decdata.c \ + decoder.c \ + dolby_adapt.c \ + fastfft.c \ + huffdec.c \ + huffinit.c \ + hufftables.c \ + intensity.c \ + monopred.c \ + nok_lt_prediction.c \ + pns.c \ + stereo.c \ + tns.c \ + transfo.c \ + util.c + +C_OPTIONS= -O2 -Wall -fexceptions -fno-strict-aliasing -shared -fPIC + +CPP_SRCS= + +CPP_OPTIONS= + +INCLUDE= . + +DYNLIB=libaacdec.so + +all: mpeg4ip_config.h libaacdec.so + +include ../../source/common.mak + +# +# setup the correct config.h file +# + +mpeg4ip_config.h: mpeg4ip_config_Linux32.h + cp mpeg4ip_config_Linux32.h mpeg4ip_config.h + + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..a8eefc9 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,38 @@ +lib_LTLIBRARIES = libmpeg4ip_faad.la +libmpeg4ip_faad_la_SOURCES = \ + bits.c \ + block.c \ + config.c \ + decdata.c \ + decoder.c \ + dolby_adapt.c \ + fastfft.c \ + huffdec.c \ + huffinit.c \ + hufftables.c \ + intensity.c \ + monopred.c \ + nok_lt_prediction.c \ + pns.c \ + stereo.c \ + tns.c \ + transfo.c \ + util.c \ + all.h \ + bits.h \ + block.h \ + fastfft.h \ + interface.h \ + kbd_win.h \ + monopred.h \ + nok_lt_prediction.h \ + nok_ltp_common.h \ + nok_ltp_common_internal.h \ + port.h \ + tns.h \ + transfo.h\ + util.h +INCLUDES = -I$(top_srcdir)/include +AM_CFLAGS = -O2 -Wall -fexceptions -fno-strict-aliasing + +EXTRA_DIST = COPYING libfaad60.dsp README libfaad.vcproj diff --git a/README b/README new file mode 100644 index 0000000..daf4fbd --- /dev/null +++ b/README @@ -0,0 +1,18 @@ +Freeware Advanced Audio Coder/Decoder +http://www.audiocoding.com/ + +Currently maintained by +M. Bakker (menno@audiocoding.com). + +Other contributors +Tony Lenox (len0x@mail.ru) +RageOMatic (rageamp@realedge.com) +thebard (wmilas@rarcoa.com) +Ivan Dimkovic (dim@psytel-research.co.yu) + +(If you feel your name should be here please mail me, I +can't remember everyone) + +The modifications to the ISO MPEG4-AAC reference source code +are distributed under the GNU General Public License +(see the file COPYING for details). diff --git a/all.h b/all.h new file mode 100644 index 0000000..e103c50 --- /dev/null +++ b/all.h @@ -0,0 +1,458 @@ +/************************* MPEG-2 NBC Audio Decoder ************************** + * * +"This software module was originally developed by +AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS and edited by +Yoshiaki Oikawa (Sony Corporation), +Mitsuyuki Hatanaka (Sony Corporation), +in the course of development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ + +#ifndef _all_h_ +#define _all_h_ + +//#include "mpeg4ip.h" +#ifdef _WIN32 +#include +#include +typedef unsigned __int32 uint32_t; +typedef unsigned __int32 u_int32_t; +#define WIN32_MEAN_AND_LEAN +#include +#else +#include +#include +#include +#include +typedef uint32_t u_int32_t; +#endif + +#include +#include "interface.h" +#include "tns.h" +#include "nok_ltp_common.h" +#include "monopred.h" +#include "bits.h" +#ifndef _POSIX_SOURCE +#define _POSIX_SOURCE /* stops repeat typdef of ulong */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef float Float; +typedef unsigned char byte; + + +enum +{ + /* + * channels for 5.1 main profile configuration + * (modify for any desired decoder configuration) + */ +#ifdef BIGDECODER + FChans = 15, /* front channels: left, center, right */ + FCenter = 1, /* 1 if decoder has front center channel */ + SChans = 18, /* side channels: */ + BChans = 15, /* back channels: left surround, right surround */ + BCenter = 1, /* 1 if decoder has back center channel */ + LChans = 1, /* LFE channels */ + XChans = 1, /* scratch space for parsing unused channels */ +#else + FChans = 3, /* front channels: left, center, right */ + FCenter = 0, /* 1 if decoder has front center channel */ + SChans = 2, /* side channels: */ + BChans = 1, /* back channels: left surround, right surround */ + BCenter = 0, /* 1 if decoder has back center channel */ + LChans = 1, /* LFE channels */ + XChans = 1, /* scratch space for parsing unused channels */ +#endif + + Chans = FChans + SChans + BChans + LChans + XChans +}; + +/* #define is required in order to use these args in #if () directive */ +#if 0 +#define ICChans 1 /* independently switched coupling channels */ +#define DCChans 2 /* dependently switched coupling channels */ +#define XCChans 1 /* scratch space for parsing unused coupling channels */ +#define CChans (ICChans + DCChans + XCChans) +#else +#define ICChans 0 +#define DCChans 0 +#define XCChans 0 +#define CChans 0 +#endif + +enum +{ + /* block switch windows for single channels or channel pairs */ + Winds = Chans, + + /* average channel block length, bytes */ + Avjframe = 341, + + TEXP = 128, /* size of exp cache table */ + MAX_IQ_TBL = 8192+15, /* size of inv quant table */ + MAXFFT = LN4, + + XXXXX +}; + + +typedef struct +{ + int islong; /* true if long block */ + int nsbk; /* sub-blocks (SB) per block */ + int bins_per_bk; /* coef's per block */ + int sfb_per_bk; /* sfb per block */ + int bins_per_sbk[MAX_SBK]; /* coef's per SB */ + int sfb_per_sbk[MAX_SBK]; /* sfb per SB */ + int sectbits[MAX_SBK]; + int *sbk_sfb_top[MAX_SBK]; /* top coef per sfb per SB */ + int *sfb_width_128; /* sfb width for short blocks */ + int bk_sfb_top[200]; /* cum version of above */ + int num_groups; + int group_len[8]; + int group_offs[8]; +} Info; + +typedef struct { + int samp_rate; + int nsfb1024; + int *SFbands1024; + int nsfb128; + int *SFbands128; +} SR_Info; + +typedef struct +{ + byte this_bk; + byte prev_bk; +} Wnd_Shape; + +typedef struct +{ + int len; + unsigned long cw; + char x, y, v, w; +} Huffman; + +typedef struct +{ + int len; + unsigned long cw; + int scl; +} Huffscl; + +typedef struct +{ + int dim; + int signed_cb; + Huffman *hcw; +} Hcb; + + +typedef struct +{ + int present; /* channel present */ + int tag; /* element tag */ + int cpe; /* 0 if single channel, 1 if channel pair */ + int common_window; /* 1 if common window for cpe */ + int ch_is_left; /* 1 if left channel of cpe */ + int paired_ch; /* index of paired channel in cpe */ + int widx; /* window element index for this channel */ + int is_present; /* intensity stereo is used */ + int ncch; /* number of coupling channels for this ch */ + char *fext; /* filename extension */ +} Ch_Info; + +typedef struct { + int nch; /* total number of audio channels */ + int nfsce; /* number of front SCE's pror to first front CPE */ + int nfch; /* number of front channels */ + int nsch; /* number of side channels */ + int nbch; /* number of back channels */ + int nlch; /* number of lfe channels */ + int ncch; /* number of valid coupling channels */ + int cch_tag[(1< +#include "all.h" +/* to mask the n least significant bits of an integer */ +unsigned int faad_bit_msk[33] = +{ + 0x00000000, 0x00000001, 0x00000003, 0x00000007, + 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, + 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff, + 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, + 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff, + 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff, + 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff, + 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, + 0xffffffff +}; + +/* initialize buffer, call once before first getbits or showbits */ +void faad_initbits(bitfile *ld, unsigned char *buffer, uint32_t buflen) +{ + ld->incnt = 0; + ld->framebits = 0; + ld->bitcnt = 0; + ld->buffer = buffer; + ld->rdptr = buffer; + ld->maxbits = buflen * 8; +} + + +/* return next n bits (right adjusted) */ +uint32_t faad_getbits(bitfile *ld, int n) +{ + long l; + + l = faad_showbits(ld, n); + faad_flushbits(ld, n); + + return l; +} + +uint32_t faad_getbits_fast(bitfile *ld, int n) +{ + unsigned int l; + + l = (unsigned char) (ld->rdptr[0] << ld->bitcnt); + l |= ((unsigned int) ld->rdptr[1] << ld->bitcnt)>>8; + l <<= n; + l >>= 8; + + ld->bitcnt += n; + ld->framebits += n; + + ld->rdptr += (ld->bitcnt>>3); + ld->bitcnt &= 7; + + return l; +} + +uint32_t faad_get1bit(bitfile *ld) +{ + unsigned char l; + l = *ld->rdptr << ld->bitcnt; + + ld->bitcnt++; + ld->framebits++; + ld->rdptr += (ld->bitcnt>>3); + ld->bitcnt &= 7; + + return l>>7; +} + + +int faad_get_processed_bits(bitfile *ld) +{ + return (ld->framebits); +} + +uint32_t faad_byte_align(bitfile *ld) +{ + int i; + + if (ld->bitcnt == 0) return 0; + i = 8 - ld->bitcnt; + + faad_flushbits(ld, i); + return i; +} + +void faad_bitdump (bitfile *ld) +{ + #if 0 + printf("processed %d %d bits left - %d\n", + ld->m_total / 8, + ld->m_total % 8, + ld->m_uNumOfBitsInBuffer); + #endif +} + +int faad_bits_done (bitfile *ld) +{ + if (ld->maxbits > ld->framebits) return 0; + return 1; +} diff --git a/bits.h b/bits.h new file mode 100644 index 0000000..324dc0e --- /dev/null +++ b/bits.h @@ -0,0 +1,81 @@ +/* + * FAAD - Freeware Advanced Audio Decoder + * Copyright (C) 2001 Menno Bakker + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: bits.h,v 1.5 2005/05/09 21:29:56 wmaycisco Exp $ + */ + +#ifndef __BITS_H__ +#define __BITS_H__ 1 +#include "all.h" +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _bitfile2 +{ + /* bit input */ + unsigned char *buffer; + unsigned char *rdptr; + int m_alignment_offset; + int incnt; + int bitcnt; + int framebits; + int maxbits; +} bitfile; + +void faad_initbits(bitfile *ld, unsigned char *buffer, uint32_t buflen); +uint32_t faad_getbits(bitfile *ld, int n); +uint32_t faad_getbits_fast(bitfile *ld, int n); +uint32_t faad_get1bit(bitfile *ld); +uint32_t faad_byte_align(bitfile *ld); +int faad_get_processed_bits(bitfile *ld); + int faad_bits_done(bitfile *ld); + + void faad_bitdump(bitfile *ld); + +extern unsigned int faad_bit_msk[33]; + +#define _SWAP(a) ((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]) + +static __inline uint32_t faad_showbits(bitfile *ld, int n) +{ + unsigned char *v; + int rbit = 32 - ld->bitcnt; + uint32_t b; + + v = ld->rdptr; + b = _SWAP(v); + return ((b & faad_bit_msk[rbit]) >> (rbit-n)); +} + +static __inline void faad_flushbits(bitfile *ld, int n) +{ + ld->bitcnt += n; + + if (ld->bitcnt >= 8) { + ld->rdptr += (ld->bitcnt>>3); + ld->bitcnt &= 7; + } + + ld->framebits += n; +} + +#ifdef __cplusplus +} +#endif +#endif diff --git a/block.c b/block.c new file mode 100644 index 0000000..779eea1 --- /dev/null +++ b/block.c @@ -0,0 +1,376 @@ +/************************* MPEG-2 NBC Audio Decoder ************************** + * * +"This software module was originally developed by +AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS in the course of +development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ +/* + * $Id: block.c,v 1.8 2003/05/23 18:55:19 wmaycisco Exp $ + */ + +#include "all.h" +#include "block.h" +#include "kbd_win.h" +#include "transfo.h" +#include "util.h" + +#ifndef PI +#define PI 3.14159265359f +#endif + + + +const int windowLeng[N_WINDOW_TYPES] = { + 1024, + 128, + 1024, + 1024 +}; + + +#ifndef WIN_TABLE +static float Izero(float x) +{ + float IzeroEPSILON = 1E-37f; /* Max error acceptable in Izero */ + float sum, u, halfx, temp; + int n; + + sum = u = 1.f; + n = 1; + halfx = x/2.0f; + do { + temp = halfx/(float)n; + n += 1; + temp *= temp; + u *= temp; + sum += u; + } while (u >= IzeroEPSILON*sum); + + return(sum); +} + +static void CalculateKBDWindow(float* win, float alpha, int length) +{ + int i; + float IBeta; + float tmp; + float sum = 0.0; + + alpha *= PI; + IBeta = 1.0f/Izero(alpha); + + /* calculate lower half of Kaiser Bessel window */ + for(i=0; i<(length>>1); i++) { + tmp = 4.0f*(float)i/(float)length - 1.0f; + win[i] = Izero(alpha*(float)sqrt(1.0f-tmp*tmp))*IBeta; + sum += win[i]; + } + + sum = 1.0f/sum; + tmp = 0.0f; + + /* calculate lower half of window */ + for(i=0; i<(length>>1); i++) { + tmp += win[i]; + win[i] = (float)sqrt(tmp*sum); + } +} +#endif + + +/***************************************************************************** +* +* InitBlock +* calculate windows for use by Window() +* input: none +* output: none +* local static: none +* globals: shortWindow[], longWindow[] +* +*****************************************************************************/ +void InitBlock (faacDecHandle hDecoder) +{ + + /* calc half-window data */ + int i, j; + float phaseInc; + + hDecoder->sin_long = AllocMemory(NWINLONG*sizeof(Float)); + hDecoder->sin_short = AllocMemory(NWINSHORT*sizeof(Float)); +#ifndef WIN_TABLE + hDecoder->kbd_long = AllocMemory(NWINLONG*sizeof(Float)); + hDecoder->kbd_short = AllocMemory(NWINSHORT*sizeof(Float)); +#endif + hDecoder->sin_edler = AllocMemory(NWINLONG*sizeof(Float)); + hDecoder->kbd_edler = AllocMemory(NWINLONG*sizeof(Float)); + hDecoder->sin_adv = AllocMemory(NWINADV*sizeof(Float)); + hDecoder->kbd_adv = AllocMemory(NWINADV*sizeof(Float)); + +/* +Float *windowPtr[N_WINDOW_TYPES][N_WINDOW_SHAPES] = { + {sin_long, kbd_long}, + {sin_short, kbd_short}, + {sin_edler, kbd_edler}, + {sin_adv, kbd_adv} +}; +*/ + hDecoder->windowPtr[0][0] = hDecoder->sin_long; + hDecoder->windowPtr[0][1] = hDecoder->kbd_long; + hDecoder->windowPtr[1][0] = hDecoder->sin_short; + hDecoder->windowPtr[1][1] = hDecoder->kbd_short; + hDecoder->windowPtr[2][0] = hDecoder->sin_edler; + hDecoder->windowPtr[2][1] = hDecoder->kbd_edler; + hDecoder->windowPtr[3][0] = hDecoder->sin_adv; + hDecoder->windowPtr[3][1] = hDecoder->kbd_adv; + + /* init half-windows */ + + /* sin long window */ + phaseInc = PI / (2.0f * NWINLONG); + for (i = 0; i < NWINLONG; i++) { + hDecoder->sin_long [i] = (float)sin(phaseInc * (i + 0.5)); + } + + /* sin short window */ + phaseInc = PI / (2.0f * NWINSHORT); + for (i = 0; i < NWINSHORT; i++) { + hDecoder->sin_short [i] = (float)sin(phaseInc * (i + 0.5)); + } + +#ifndef WIN_TABLE + CalculateKBDWindow(hDecoder->kbd_long, 4.f, NWINLONG*2); + CalculateKBDWindow(hDecoder->kbd_short, 6.f, NWINSHORT*2); +#endif + + /* Edler windows */ + for (i = 0, j = 0; i < NFLAT; i++, j++) { + hDecoder->sin_edler[j] = 0.0; + hDecoder->kbd_edler[j] = 0.0; + } + for (i = 0; i < NWINSHORT; i++, j++) { + hDecoder->sin_edler [j] = hDecoder->sin_short [i]; + hDecoder->kbd_edler [j] = hDecoder->kbd_short [i]; + } + for ( ; j < NWINFLAT; j++) { + hDecoder->sin_edler [j] = 1.0; + hDecoder->kbd_edler [j] = 1.0; + } + + /* Advanced Edler windows */ + for (i = 0, j = 0; i < NADV0; i++, j++) { + hDecoder->sin_adv [j] = 0.0; + hDecoder->kbd_adv [j] = 0.0; + } + for (i = 0; i < NWINSHORT; i++, j++) { + hDecoder->sin_adv[j] = hDecoder->sin_short[i]; + hDecoder->kbd_adv[j] = hDecoder->kbd_short[i]; + } + for ( ; j < NWINADV; j++) { + hDecoder->sin_adv[j] = 1.0; + hDecoder->kbd_adv[j] = 1.0; + } +} + +void EndBlock(faacDecHandle hDecoder) +{ + FreeMemory(hDecoder->sin_long); + FreeMemory(hDecoder->sin_short); +#ifndef WIN_TABLE + FreeMemory(hDecoder->kbd_long); + FreeMemory(hDecoder->kbd_short); +#endif + FreeMemory(hDecoder->sin_edler); + FreeMemory(hDecoder->kbd_edler); + FreeMemory(hDecoder->sin_adv); + FreeMemory(hDecoder->kbd_adv); +} + +/***************************************************************************** +* +* Window +* window input sequence based on window type +* input: see below +* output: see below +* local static: +* firstTime flag = need to initialize data structures +* globals: shortWindow[], longWindow[] +* +*****************************************************************************/ + +void ITransformBlock (faacDecHandle hDecoder, + Float* dataPtr, /* vector to be windowed in place */ + BLOCK_TYPE bT, /* input: window type */ + Wnd_Shape *wnd_shape, + Float *state /* input/output */ + ) +{ + int leng0, leng1; + int i,leng; + Float *windPtr; + WINDOW_TYPE beginWT, endWT; + + if((bT==LONG_BLOCK) || (bT==START_FLAT_BLOCK)) { + beginWT = WT_LONG; + } else if(bT==STOP_FLAT_BLOCK) { + beginWT = WT_FLAT; + } else + beginWT = WT_SHORT; + + if ((bT == LONG_BLOCK) || (bT == STOP_FLAT_BLOCK)) { + endWT = WT_LONG; + } else if (bT == START_FLAT_BLOCK) { + endWT = WT_FLAT; + } else + endWT = WT_SHORT; + + leng0 = windowLeng [beginWT]; + leng1 = windowLeng [endWT]; + + switch(leng0 + leng1) { + case 2048: IMDCT_Long(hDecoder, dataPtr); break; + case 256: IMDCT_Short(hDecoder, dataPtr); + } + + /* first half of window */ + /* windPtr = windowPtr [0] [0]; */ + windPtr = hDecoder->windowPtr [beginWT] [wnd_shape->prev_bk]; + + /* idimkovic: should be optimized with SSE memcpy() */ + for (i = windowLeng [beginWT]/16 - 1; i>=0; --i) { + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + } + + /* second half of window */ + leng = windowLeng [endWT]; + windPtr = hDecoder->windowPtr [endWT] [wnd_shape->this_bk] + leng - 1; + for (i = leng/16-1; i>=0; --i) { + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + } + + wnd_shape->prev_bk = wnd_shape->this_bk; +} + +/***************************************************************************** +* +* MDCT +* window input sequence based on window type and perform MDCT +* This is adapted from ITransformBlock(). +* (long term prediction needs this routine) +* input: see below +* output: see below +* local static: +* firstTime flag = need to initialize data structures +* globals: - +* +*****************************************************************************/ +void TransformBlock(faacDecHandle hDecoder, + Float* dataPtr, /* time domain signal */ + BLOCK_TYPE bT, /* input: window type */ + Wnd_Shape *wnd_shape + ) +{ + int leng0, leng1; + int i,leng; + Float *windPtr; + WINDOW_TYPE beginWT, endWT; + + if((bT==LONG_BLOCK) || (bT==START_BLOCK) || (bT==START_FLAT_BLOCK) + || (bT==START_ADV_BLOCK)) { + beginWT = WT_LONG; + } + else if(bT==STOP_FLAT_BLOCK) { + beginWT = WT_FLAT; + } + else if(bT==STOP_ADV_BLOCK) { + beginWT = WT_ADV; + } + else + beginWT = WT_SHORT; + + if ((bT == LONG_BLOCK) || (bT == STOP_BLOCK) || (bT == STOP_FLAT_BLOCK) + || (bT == STOP_ADV_BLOCK)) { + endWT = WT_LONG; + } + else if (bT == START_FLAT_BLOCK) { + endWT = WT_FLAT; + } + else if (bT == START_ADV_BLOCK) { + endWT = WT_ADV; + } + else + endWT = WT_SHORT; + + leng0 = windowLeng[beginWT]; + leng1 = windowLeng[endWT]; + +/* first half of window */ +/* windPtr = windowPtr [0] [0]; */ + windPtr = hDecoder->windowPtr [beginWT] [wnd_shape->prev_bk]; + + for (i = windowLeng [beginWT]/16 - 1; i>=0; --i) { + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + *dataPtr++ *= *windPtr++; *dataPtr++ *= *windPtr++; + } + + +/* second half of window */ + leng = windowLeng[endWT]; + windPtr = hDecoder->windowPtr[endWT][wnd_shape->this_bk] + leng - 1; + + for (i = leng/16-1; i>=0; --i) { + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + *dataPtr++ *= *windPtr--; *dataPtr++ *= *windPtr--; + } + + dataPtr -= (windowLeng [beginWT] + leng); + + switch(leng0 + leng1) { + case 2048: MDCT_Long(hDecoder, dataPtr); break; + case 256: MDCT_Short(hDecoder, dataPtr); + } + wnd_shape->prev_bk = wnd_shape->this_bk; +} + diff --git a/block.h b/block.h new file mode 100644 index 0000000..8858e17 --- /dev/null +++ b/block.h @@ -0,0 +1,80 @@ +/************************* MPEG-2 NBC Audio Decoder ************************** + * * +"This software module was originally developed by +AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS in the course of +development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ +/* + * $Id: block.h,v 1.6 2003/05/23 18:55:19 wmaycisco Exp $ + */ + +#ifndef BLOCK_H +#define BLOCK_H 1 + +#define IN_DATATYPE double +#define OUT_DATATYPE double + +#ifndef BLOCK_LEN_LONG +#define BLOCK_LEN_LONG 1024 +#endif +#define BLOCK_LEN_SHORT 128 + + +#define NWINLONG (BLOCK_LEN_LONG) +#define ALFALONG 4.0 +#define NWINSHORT (BLOCK_LEN_SHORT) +#define ALFASHORT 7.0 + +#define NWINFLAT (NWINLONG) /* flat params */ +#define NWINADV (NWINLONG-NWINSHORT) /* Advanced flat params */ +#define NFLAT ((NWINFLAT-NWINSHORT)/2) +#define NADV0 ((NWINADV-NWINSHORT)/2) + +#define START_OFFSET 0 +#define SHORT_IN_START_OFFSET 5 +#define STOP_OFFSET 3 +#define SHORT_IN_STOP_OFFSET 0 + +#define WEAVE_START 0 /* type parameter for start blocks */ +#define WEAVE_STOP 1 /* type paremeter for stop blocks */ + + + +typedef enum { /* ADVanced transform types */ + LONG_BLOCK, + START_BLOCK, + SHORT_BLOCK, + STOP_BLOCK, + START_ADV_BLOCK, + STOP_ADV_BLOCK, + START_FLAT_BLOCK, + STOP_FLAT_BLOCK, + N_BLOCK_TYPES +} +BLOCK_TYPE; + + +void unfold (Float *data_in, Float *data_out, int inLeng); +void InitBlock(faacDecHandle hDecoder); +void EndBlock(faacDecHandle hDecoder); +void ITransformBlock(faacDecHandle hDecoder,Float* dataPtr, BLOCK_TYPE wT, Wnd_Shape *ws, Float *state); +void TransformBlock(faacDecHandle hDecoder,Float* dataPtr, BLOCK_TYPE bT, Wnd_Shape *wnd_shape); + +#endif /* BLOCK_H */ diff --git a/config.c b/config.c new file mode 100755 index 0000000..a1a29dd --- /dev/null +++ b/config.c @@ -0,0 +1,645 @@ +/************************* MPEG-2 NBC Audio Decoder ************************** + * * +"This software module was originally developed by +AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS in the course of +development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ +/* + * $Id: config.c,v 1.11 2003/04/09 00:44:38 wmaycisco Exp $ + */ + +#include "all.h" +#include "bits.h" +#include "util.h" + +static int ch_index(MC_Info *mip, int cpe, int tag); +static int enter_chn(int cpe, int tag, char position, int common_window, MC_Info *mip); + +/* + * adts_header + */ +int get_adts_header(faacDecHandle hDecoder) +{ + int sync = 0; + ADTS_Header *p = &hDecoder->adts_header; + + faad_byte_align(&hDecoder->ld); + + sync = faad_showbits(&hDecoder->ld, 12); + while (sync != 4096 - 1) { + faad_flushbits(&hDecoder->ld, 8); + if (faad_bits_done(&hDecoder->ld) != 0) { + return -1; + } + sync = faad_showbits(&hDecoder->ld, 12); + } + faad_flushbits(&hDecoder->ld, 12); + + if (hDecoder->frameNum) { + faad_getbits(&hDecoder->ld, 16); +#if 0 + if (p->fixed.ID == 0) /* MPEG2 AAC doesn't have this */ + faad_getbits(&hDecoder->ld, 2); +#endif + } else { + /* Syncword found, proceed to read in the fixed ADTS header */ + p->fixed.ID = faad_get1bit(&hDecoder->ld); /* 0 -> MPEG4, 1 -> MPEG2 */ + hDecoder->isMpeg4 = !p->fixed.ID; + p->fixed.layer = faad_getbits(&hDecoder->ld, 2); + p->fixed.protection_absent = faad_get1bit(&hDecoder->ld); + hDecoder->mc_info.object_type = p->fixed.object_type = faad_getbits(&hDecoder->ld, 2); + hDecoder->mc_info.sampling_rate_idx = p->fixed.sampling_rate_idx = faad_getbits(&hDecoder->ld, 4); + p->fixed.private_bit = faad_get1bit(&hDecoder->ld); + p->fixed.channel_configuration = faad_getbits(&hDecoder->ld, 3); + p->fixed.original_copy = faad_get1bit(&hDecoder->ld); + p->fixed.home = faad_get1bit(&hDecoder->ld); +#if 0 + if (p->fixed.ID == 0) /* MPEG2 AAC doesn't have this */ + p->fixed.emphasis = faad_getbits(&hDecoder->ld, 2); +#endif + } + + /* ...and the variable ADTS header */ + p->variable.copy_id_bit = faad_get1bit(&hDecoder->ld); + p->variable.copy_id_start = faad_get1bit(&hDecoder->ld); + p->variable.frame_length = faad_getbits(&hDecoder->ld, 13); + p->variable.buffer_fullness = faad_getbits(&hDecoder->ld, 11); + p->variable.raw_blocks = faad_getbits(&hDecoder->ld, 2); + + /* ADTS error check (ignored) */ + if(!p->fixed.protection_absent) + faad_getbits(&hDecoder->ld, 16); + + return 0; +} + +/* + * adif_header + */ +int get_adif_header(faacDecHandle hDecoder) +{ + int i, n, tag, select_status; + ProgConfig tmp_config; + ADIF_Header *p = &hDecoder->adif_header; + + /* adif header */ + for (i=0; iadif_id[i] = (char)faad_getbits(&hDecoder->ld, LEN_BYTE); + p->adif_id[i] = 0; /* null terminated string */ + /* copyright string */ + if ((p->copy_id_present = faad_getbits(&hDecoder->ld, LEN_COPYRT_PRES)) == 1) { + for (i=0; icopy_id[i] = (char)faad_getbits(&hDecoder->ld, LEN_BYTE); + p->copy_id[i] = 0; /* null terminated string */ + } + p->original_copy = faad_getbits(&hDecoder->ld, LEN_ORIG); + p->home = faad_getbits(&hDecoder->ld, LEN_HOME); + p->bitstream_type = faad_getbits(&hDecoder->ld, LEN_BS_TYPE); + p->bitrate = faad_getbits(&hDecoder->ld, LEN_BIT_RATE); + + /* program config elements */ + select_status = -1; + n = faad_getbits(&hDecoder->ld, LEN_NUM_PCE) + 1; + for (i=0; ibitstream_type == 0) ? faad_getbits(&hDecoder->ld, LEN_ADIF_BF) : 0; + tag = get_prog_config(hDecoder, &tmp_config); + if (hDecoder->current_program < 0) + hDecoder->current_program = tag; /* default is first prog */ + if (hDecoder->current_program == tag) { + CopyMemory(&hDecoder->prog_config, &tmp_config, sizeof(hDecoder->prog_config)); + select_status = 1; + } + } + + return select_status; +} + + +/* + * program configuration element + */ +static void get_ele_list(faacDecHandle hDecoder, EleList *p, int enable_cpe) +{ + int i, j; + for (i=0, j=p->num_ele; iele_is_cpe[i] = faad_getbits(&hDecoder->ld, LEN_ELE_IS_CPE); + else + p->ele_is_cpe[i] = 0; /* sdb */ + p->ele_tag[i] = faad_getbits(&hDecoder->ld, LEN_TAG); + } +} + +int get_prog_config(faacDecHandle hDecoder, ProgConfig *p) +{ + int i, j, tag; + + tag = faad_getbits(&hDecoder->ld, LEN_TAG); + + p->object_type = faad_getbits(&hDecoder->ld, LEN_OBJECTTYPE); + p->sampling_rate_idx = faad_getbits(&hDecoder->ld, LEN_SAMP_IDX); + p->front.num_ele = faad_getbits(&hDecoder->ld, LEN_NUM_ELE); + p->side.num_ele = faad_getbits(&hDecoder->ld, LEN_NUM_ELE); + p->back.num_ele = faad_getbits(&hDecoder->ld, LEN_NUM_ELE); + p->lfe.num_ele = faad_getbits(&hDecoder->ld, LEN_NUM_LFE); + p->data.num_ele = faad_getbits(&hDecoder->ld, LEN_NUM_DAT); + p->coupling.num_ele = faad_getbits(&hDecoder->ld, LEN_NUM_CCE); + if ((p->mono_mix.present = faad_getbits(&hDecoder->ld, LEN_MIX_PRES)) == 1) + p->mono_mix.ele_tag = faad_getbits(&hDecoder->ld, LEN_TAG); + if ((p->stereo_mix.present = faad_getbits(&hDecoder->ld, LEN_MIX_PRES)) == 1) + p->stereo_mix.ele_tag = faad_getbits(&hDecoder->ld, LEN_TAG); + if ((p->matrix_mix.present = faad_getbits(&hDecoder->ld, LEN_MIX_PRES)) == 1) { + p->matrix_mix.ele_tag = faad_getbits(&hDecoder->ld, LEN_MMIX_IDX); + p->matrix_mix.pseudo_enab = faad_getbits(&hDecoder->ld, LEN_PSUR_ENAB); + } + get_ele_list(hDecoder, &p->front, 1); + get_ele_list(hDecoder, &p->side, 1); + get_ele_list(hDecoder, &p->back, 1); + get_ele_list(hDecoder, &p->lfe, 0); + get_ele_list(hDecoder, &p->data, 0); + get_ele_list(hDecoder, &p->coupling, 1); + + /* + * if this is a MPEG4 file and the PCE is inside a raw_data_block() + * this should be aligned to beginning of raw_data_block() boundary, + * not byte boundary (FIXME!!!) + */ + faad_byte_align(&hDecoder->ld); + + j = faad_getbits(&hDecoder->ld, LEN_COMMENT_BYTES); + for (i=0; icomments[i] = (char)faad_getbits(&hDecoder->ld, LEN_BYTE); + p->comments[i] = 0; /* null terminator for string */ + + /* activate new program configuration if appropriate */ + if (hDecoder->current_program < 0) + hDecoder->current_program = tag; /* always select new program */ + if (tag == hDecoder->current_program) { + /* enter configuration into MC_Info structure */ + if ((hDecoder->pceChannels = enter_mc_info(hDecoder, &hDecoder->mc_info, p)) < 0) + return -1; + /* inhibit default configuration */ + hDecoder->default_config = 0; + } + + return tag; +} + +/* enter program configuration into MC_Info structure + * only configures for channels specified in all.h + */ +int enter_mc_info(faacDecHandle hDecoder, MC_Info *mip, ProgConfig *pcp) +{ + int i, j, cpe, tag, cw; + EleList *elp; + MIXdown *mxp; + int channels = 0; + + /* reset channel counts */ + mip->nch = 0; + mip->nfch = 0; + mip->nfsce = 0; + mip->nsch = 0; + mip->nbch = 0; + mip->nlch = 0; + mip->ncch = 0; + + /* object type and sampling rate + * re-configure if new sampling rate + */ + mip->object_type = pcp->object_type; + if (mip->sampling_rate_idx != pcp->sampling_rate_idx) { + mip->sampling_rate_idx = pcp->sampling_rate_idx; + infoinit(hDecoder, &samp_rate_info[mip->sampling_rate_idx]); + } + + cw = 0; /* changed later */ + + /* front elements, center out */ + elp = &pcp->front; + /* count number of leading SCE's */ + for (i=0, j=elp->num_ele; iele_is_cpe[i]) + break; + mip->nfsce++; + } + for (i=0, j=elp->num_ele; iele_is_cpe[i]; + tag = elp->ele_tag[i]; + if (enter_chn(cpe, tag, 'f', cw, mip) < 0) + return(-1); + if (cpe) channels+=2; + else channels++; + } + + /* side elements, left to right then front to back */ + elp = &pcp->side; + for (i=0, j=elp->num_ele; iele_is_cpe[i]; + tag = elp->ele_tag[i]; + if (enter_chn(cpe, tag, 's', cw, mip) < 0) + return(-1); + if (cpe) channels+=2; + else channels++; + } + + /* back elements, outside to center */ + elp = &pcp->back; + for (i=0, j=elp->num_ele; iele_is_cpe[i]; + tag = elp->ele_tag[i]; + if (enter_chn(cpe, tag, 'b', cw, mip) < 0) + return(-1); + if (cpe) channels+=2; + else channels++; + } + + /* lfe elements */ + elp = &pcp->lfe; + for (i=0, j=elp->num_ele; iele_is_cpe[i]; + tag = elp->ele_tag[i]; + if (enter_chn(cpe, tag, 'l', cw, mip) < 0) + return(-1); + if (cpe) channels+=2; + else channels++; + } + + /* coupling channel elements */ + elp = &pcp->coupling; + for (i=0, j=elp->num_ele; icch_tag[i] = elp->ele_tag[i]; + mip->ncch = j; + channels += j; + + /* mono mixdown elements */ + mxp = &pcp->mono_mix; + if (mxp->present) { +/* CommonWarning("Unanticipated mono mixdown channel"); */ + return(-1); + } + + /* stereo mixdown elements */ + mxp = &pcp->stereo_mix; + if (mxp->present) { +/* CommonWarning("Unanticipated stereo mixdown channel"); */ + return(-1); + } + + /* matrix mixdown elements */ + mxp = &pcp->matrix_mix; + if (mxp->present) { +/* CommonWarning("Unanticipated matrix mixdown channel"); */ + return(-1); + } + + /* save to check future consistency */ + if (!check_mc_info(hDecoder, mip, 1)) + return -1; + + return channels; +} + +/* translate prog config or default config + * into to multi-channel info structure + * returns index of channel in MC_Info + */ +static int enter_chn(int cpe, int tag, char position, int common_window, MC_Info *mip) +{ + int nch, cidx=0; + Ch_Info *cip; + + nch = (cpe == 1) ? 2 : 1; + + switch (position) { + /* use configuration already in MC_Info, but now common_window is valid */ + case 0: + cidx = ch_index(mip, cpe, tag); + if (common_window) { + mip->ch_info[cidx].widx = cidx; /* window info is left */ + mip->ch_info[cidx+1].widx = cidx; + } else { + mip->ch_info[cidx].widx = cidx; /* each has window info */ + mip->ch_info[cidx+1].widx = cidx+1; + } + return cidx; + + /* build configuration */ + case 'f': + if (mip->nfch + nch > FChans) { +/* CommonWarning("Unanticipated front channel"); */ + return -1; + } + if (mip->nfch == 0) { + /* consider case of center channel */ + if (FCenter) { + if (cpe) { + /* has center speaker but center channel missing */ + cidx = 0 + 1; + mip->nfch = 1 + nch; + } + else { + if (mip->nfsce & 1) { + /* has center speaker and this is center channel */ + /* odd number of leading SCE's */ + cidx = 0; + mip->nfch = nch; + } + else { + /* has center speaker but center channel missing */ + /* even number of leading SCE's */ + /* (Note that in implicit congiguration + * channel to speaker mapping may be wrong + * for first block while count of SCE's prior + * to first CPE is being make. However first block + * is not written so it doesn't matter. + * Second block will be correct. + */ + cidx = 0 + 1; + mip->nfch = 1 + nch; + } + } + } + else { + if (cpe) { + /* no center speaker and center channel missing */ + cidx = 0; + mip->nfch = nch; + } + else { + /* no center speaker so this is left channel */ + cidx = 0; + mip->nfch = nch; + } + } + } + else { + cidx = mip->nfch; + mip->nfch += nch; + } + break; + case 's': + if (mip->nsch + nch > SChans) { +/* CommonWarning("Unanticipated side channel"); */ + return -1; + } + cidx = FChans + mip->nsch; + mip->nsch += nch; + break; + case 'b': + if (mip->nbch + nch > BChans) { +/* CommonWarning("Unanticipated back channel"); */ + return -1; + } + cidx = FChans + SChans + mip->nbch; + mip->nbch += nch; + break; + case 'l': + if (mip->nlch + nch > LChans) { +/* CommonWarning("Unanticipated LFE channel"); */ + return -1; + } + cidx = FChans + SChans + BChans + mip->nlch; /* sdb */ + mip->nlch += nch; + break; + default: +/* CommonExit(1,"2020: Error in channel configuration"); */ + return -1; + } + mip->nch += nch; + + if (cpe == 0) { + /* SCE */ + cip = &mip->ch_info[cidx]; + cip->present = 1; + cip->tag = tag; + cip->cpe = 0; + cip->common_window = common_window; + cip->widx = cidx; + mip->nch = cidx + 1; + } + else { + /* CPE */ + /* left */ + cip = &mip->ch_info[cidx]; + cip->present = 1; + cip->tag = tag; + cip->cpe = 1; + cip->common_window = common_window; + cip->ch_is_left = 1; + cip->paired_ch = cidx+1; + /* right */ + cip = &mip->ch_info[cidx+1]; + cip->present = 1; + cip->tag = tag; + cip->cpe = 1; + cip->common_window = common_window; + cip->ch_is_left = 0; + cip->paired_ch = cidx; + if (common_window) { + mip->ch_info[cidx].widx = cidx; /* window info is left */ + mip->ch_info[cidx+1].widx = cidx; + } + else { + mip->ch_info[cidx].widx = cidx; /* each has window info */ + mip->ch_info[cidx+1].widx = cidx+1; + } + mip->nch = cidx + 2; + } + + return cidx; +} + +static char default_position(faacDecHandle hDecoder, MC_Info *mip, int id) +{ + if (mip->nch < FChans) + { + if (id == ID_CPE) /* first CPE */ + hDecoder->first_cpe = 1; + else if ((hDecoder->frameNum==0) && !hDecoder->first_cpe) + /* count number of SCE prior to first CPE in first block */ + mip->nfsce++; + + return('f'); /* front */ + } + else if (mip->nch < FChans+SChans) + return('s'); /* side */ + else if (mip->nch < FChans+SChans+BChans) + return('b'); /* back */ + + return 0; +} + +/* retrieve appropriate channel index for the program + * and decoder configuration + */ +int chn_config(faacDecHandle hDecoder, int id, int tag, int common_window, MC_Info *mip) +{ + int cpe, cidx=0; + char position; + + /* channel index to position mapping for 5.1 configuration is + * 0 center + * 1 left front + * 2 right front + * 3 left surround + * 4 right surround + * 5 lfe + */ + + cpe = (id == ID_CPE) ? 1 : 0; + + if (hDecoder->default_config) + { + switch (id) + { + case ID_SCE: + case ID_CPE: + if ((position = default_position(hDecoder, mip, id)) == 0) + { +/* CommonExit(1,"2021: Unanticipated channel"); */ + return (-1); + } + cidx = enter_chn(cpe, tag, position, common_window, mip); + break; + } + } + else + cidx = enter_chn(cpe, tag, 0, common_window, mip); + + + return cidx; /* index of chn in mc_info */ +} + +/* + * check continuity of configuration from one + * block to next + */ +void reset_mc_info(faacDecHandle hDecoder, MC_Info *mip) +{ + int i; + Ch_Info *p; + + /* only reset for implicit configuration */ + if (hDecoder->default_config) + { + /* reset channel counts */ + mip->nch = 0; + mip->nfch = 0; + mip->nsch = 0; + mip->nbch = 0; + mip->nlch = 0; + mip->ncch = 0; + + if (hDecoder->frameNum == 0) + /* reset prior to first block scan only! */ + mip->nfsce = 0; + + for (i=0; ich_info[i]; + p->present = 0; + p->cpe = 0; + p->ch_is_left = 0; + p->paired_ch = 0; + p->is_present = 0; + p->widx = 0; + p->ncch = 0; + } + } +} + + +int check_mc_info(faacDecHandle hDecoder, MC_Info *mip, int new_config) +{ + int i, nch, err; + Ch_Info *s, *p; + + nch = mip->nch; + if (new_config) { + /* enter valid configuration */ + for (i=0; isave_mc_info.ch_info[i]; + p = &mip->ch_info[i]; + s->present = p->present; + s->cpe = p->cpe; + s->ch_is_left = p->ch_is_left; + s->paired_ch = p->paired_ch; + } + } else { + /* check this block's configuration */ + err = 0; + for (i=0; isave_mc_info.ch_info[i]; + p = &mip->ch_info[i]; + if (s->present != p->present) err=1; + if (!s->present) continue; /* sdb */ + if (s->cpe != p->cpe) err=1; + if (s->ch_is_left != p->ch_is_left) err=1; + if (s->paired_ch != p->paired_ch) err=1; + } + if (err) { + /* CommonExit(1,"Channel configuration inconsistency"); */ + return 0; + } + } + + return 1; +} + + +/* given cpe and tag, + * returns channel index of SCE or left chn in CPE + */ +static int ch_index(MC_Info *mip, int cpe, int tag) +{ + int ch; + + for (ch=0; chnch; ch++) { + + if (!(mip->ch_info[ch].present)) + continue; + + if ( (mip->ch_info[ch].cpe == cpe) && + (mip->ch_info[ch].tag == tag) ) + return ch; + } + + /* no match, so channel is not in this program + * dummy up the ch_info structure so rest of chn will parse + */ + if (XChans > 0) { + ch = Chans - XChans; /* left scratch channel */ + mip->ch_info[ch].cpe = cpe; + mip->ch_info[ch].ch_is_left = 1; + mip->ch_info[ch].widx = ch; + if (cpe) { + mip->ch_info[ch].paired_ch = ch+1; + mip->ch_info[ch+1].ch_is_left = 0; + mip->ch_info[ch+1].paired_ch = ch; + } + } + else { + ch = -1; /* error, no scratch space */ + } + + return ch; +} diff --git a/decdata.c b/decdata.c new file mode 100644 index 0000000..79f360d --- /dev/null +++ b/decdata.c @@ -0,0 +1,234 @@ +/************************* MPEG-2 NBC Audio Decoder ************************** + * * +"This software module was originally developed by +AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS and edited by +Yoshiaki Oikawa (Sony Corporation) +,Mitsuyuki Hatanaka (Sony Corporation), +in the course of development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ + +#include "all.h" + +Hcb book[NSPECBOOKS+2]; +int sfbwidth128[(1<>31)^0x7FFF);} +#define BYTE_NUMBIT 8 /* bits in byte (char) */ +#define bit2byte(a) ((a)/BYTE_NUMBIT) /* (((a)+BYTE_NUMBIT-1)/BYTE_NUMBIT) */ + +static unsigned long ObjectTypesTable[32] = {0, 1, 1, 1, 1, }; + + +int parse_audio_decoder_specific_info(faacDecHandle hDecoder,unsigned long *samplerate,unsigned long *channels) +{ + unsigned long ObjectTypeIndex, SamplingFrequencyIndex, ChannelsConfiguration; + + faad_byte_align(&hDecoder->ld); + ObjectTypeIndex = faad_getbits(&hDecoder->ld, 5); + SamplingFrequencyIndex = faad_getbits(&hDecoder->ld, 4); + ChannelsConfiguration = faad_getbits(&hDecoder->ld, 4); + + if(ObjectTypesTable[ObjectTypeIndex] != 1){ + return -1; + } + + *samplerate = SampleRates[SamplingFrequencyIndex]; + if(*samplerate == 0){ + return -2; + } + + hDecoder->numChannels = *channels = ChannelsConfiguration; + + hDecoder->mc_info.object_type = ObjectTypeIndex - 1; + hDecoder->mc_info.sampling_rate_idx = SamplingFrequencyIndex; + + if((ChannelsConfiguration != 1) && (ChannelsConfiguration != 2)){ + + return -3; + + } + + return 0; + +} + +int FAADAPI faacDecInit2(faacDecHandle hDecoder, + unsigned char* pBuffer,unsigned long SizeOfDecoderSpecificInfo, + unsigned long *samplerate, unsigned long *channels) +{ + int rc; + + hDecoder->adif_header_present = 0; + hDecoder->adts_header_present = 0; + + if((hDecoder == NULL) + || (pBuffer == NULL) + || (SizeOfDecoderSpecificInfo < 2) + || (samplerate == NULL) + || (channels == NULL)){ + return -1; + } + + /* get adif header */ + + faad_initbits(&hDecoder->ld, pBuffer, 0); + + rc = parse_audio_decoder_specific_info(hDecoder,samplerate,channels); + + if(rc != 0){ + return rc; + } + + huffbookinit(hDecoder); + nok_init_lt_pred(hDecoder->nok_lt_status, Chans); + init_pred(hDecoder, hDecoder->sp_status, Chans); + MakeFFTOrder(hDecoder); + InitBlock(hDecoder); /* calculate windows */ + + hDecoder->winmap[0] = hDecoder->win_seq_info[ONLY_LONG_WINDOW]; + hDecoder->winmap[1] = hDecoder->win_seq_info[ONLY_LONG_WINDOW]; + hDecoder->winmap[2] = hDecoder->win_seq_info[EIGHT_SHORT_WINDOW]; + hDecoder->winmap[3] = hDecoder->win_seq_info[ONLY_LONG_WINDOW]; + + return 0; +} + + +faacDecHandle FAADAPI faacDecOpen(void) +{ + int i; + faacDecHandle hDecoder = NULL; + + hDecoder = (faacDecHandle)AllocMemory(sizeof(faacDecStruct)); +#ifndef _WIN32 + SetMemory(hDecoder, 0, sizeof(faacDecStruct)); +#endif + + hDecoder->frameNum = 0; + hDecoder->isMpeg4 = 1; + + /* set defaults */ + hDecoder->current_program = -1; + hDecoder->default_config = 1; + hDecoder->dolbyShortOffset_f2t = 1; + hDecoder->dolbyShortOffset_t2f = 1; + hDecoder->first_cpe = 0; + hDecoder->warn_flag = 1; + + hDecoder->config.defObjectType = AACMAIN; + hDecoder->config.defSampleRate = 44100; + + for(i=0; i < Chans; i++) + { + hDecoder->coef[i] = (Float*)AllocMemory(LN2*sizeof(Float)); + hDecoder->data[i] = (Float*)AllocMemory(LN2*sizeof(Float)); + hDecoder->state[i] = (Float*)AllocMemory(LN*sizeof(Float)); + hDecoder->factors[i] = (int*)AllocMemory(MAXBANDS*sizeof(int)); + hDecoder->cb_map[i] = (byte*)AllocMemory(MAXBANDS*sizeof(byte)); + hDecoder->group[i] = (byte*)AllocMemory(NSHORT*sizeof(byte)); + hDecoder->lpflag[i] = (int*)AllocMemory(MAXBANDS*sizeof(int)); + hDecoder->prstflag[i] = (int*)AllocMemory((LEN_PRED_RSTGRP+1)*sizeof(int)); + hDecoder->tns[i] = (TNS_frame_info*)AllocMemory(sizeof(TNS_frame_info)); + hDecoder->nok_lt_status[i] = (NOK_LT_PRED_STATUS*)AllocMemory(sizeof(NOK_LT_PRED_STATUS)); + hDecoder->sp_status[i] = (PRED_STATUS*)AllocMemory(LN*sizeof(PRED_STATUS)); + + hDecoder->last_rstgrp_num[i] = 0; + hDecoder->wnd_shape[i].prev_bk = 0; + +#ifndef _WIN32 /* WIN32 API sets memory to 0 in allocation */ + SetMemory(hDecoder->coef[i],0,LN2*sizeof(Float)); + SetMemory(hDecoder->data[i],0,LN2*sizeof(Float)); + SetMemory(hDecoder->state[i],0,LN*sizeof(Float)); + SetMemory(hDecoder->factors[i],0,MAXBANDS*sizeof(int)); + SetMemory(hDecoder->cb_map[i],0,MAXBANDS*sizeof(byte)); + SetMemory(hDecoder->group[i],0,NSHORT*sizeof(byte)); + SetMemory(hDecoder->lpflag[i],0,MAXBANDS*sizeof(int)); + SetMemory(hDecoder->prstflag[i],0,(LEN_PRED_RSTGRP+1)*sizeof(int)); + SetMemory(hDecoder->tns[i],0,sizeof(TNS_frame_info)); + SetMemory(hDecoder->nok_lt_status[i],0,sizeof(NOK_LT_PRED_STATUS)); + SetMemory(hDecoder->sp_status[i],0,LN*sizeof(PRED_STATUS)); +#endif + } + + hDecoder->mnt_table = AllocMemory(128*sizeof(float)); + hDecoder->exp_table = AllocMemory(256*sizeof(float)); + hDecoder->iq_exp_tbl = AllocMemory(MAX_IQ_TBL*sizeof(Float)); + hDecoder->exptable = AllocMemory(TEXP*sizeof(Float)); + hDecoder->unscambled64 = AllocMemory(64*sizeof(int)); + hDecoder->unscambled512 = AllocMemory(512*sizeof(int)); + + SetMemory(hDecoder->lp_store, 0, MAXBANDS*sizeof(int)); + SetMemory(hDecoder->noise_state_save, 0, MAXBANDS*sizeof(long)); + + for(i=0; imask[i] = (byte*)AllocMemory(MAXBANDS*sizeof(byte)); + SetMemory(hDecoder->mask[i],0,MAXBANDS*sizeof(byte)); + } + + for (i = 0; i < NUM_WIN_SEQ; i++) + hDecoder->win_seq_info[i] = NULL; + + return hDecoder; +} + +faacDecConfigurationPtr FAADAPI faacDecGetCurrentConfiguration(faacDecHandle hDecoder) +{ + faacDecConfigurationPtr config = &(hDecoder->config); + + return config; +} + +int FAADAPI faacDecSetConfiguration(faacDecHandle hDecoder, + faacDecConfigurationPtr config) +{ + hDecoder->config.defObjectType = config->defObjectType; + hDecoder->config.defSampleRate = config->defSampleRate; + + /* OK */ + return 1; +} + +int FAADAPI faacDecInit(faacDecHandle hDecoder, + unsigned char *buffer, + unsigned long *samplerate, + unsigned long *channels) +{ + int i, bits = 0; + char chk_header[4]; + + faad_initbits(&hDecoder->ld, buffer, 4); +#if 0 + faad_bookmark(&hDecoder->ld, 1); +#endif + for (i = 0; i < 4; i++) { + chk_header[i] = buffer[i]; + } + + /* Check if an ADIF header is present */ + if (stringcmp(chk_header, "ADIF", 4) == 0) + hDecoder->adif_header_present = 1; + else + hDecoder->adif_header_present = 0; + + /* Check if an ADTS header is present */ + if (hDecoder->adif_header_present == 0) + { + if (((int) ( chk_header[0] == (char) 0xFF)) && + ((int) ( (chk_header[1] & (char) 0xF0) == (char) 0xF0))) + { + hDecoder->adts_header_present = 1; + } else { + hDecoder->adts_header_present = 0; + } + } + + /* get adif header */ + if (hDecoder->adif_header_present) { + hDecoder->pceChannels = 2; +#if 0 + faad_bookmark(&hDecoder->ld, 0); + faad_bookmark(&hDecoder->ld, 1); +#else + faad_initbits(&hDecoder->ld, buffer, 4); +#endif + get_adif_header(hDecoder); + /* only MPEG2 ADIF header uses byte_alignment */ + /* but the PCE already byte aligns the data */ + /* + if (!hDecoder->isMpeg4) + byte_align(&hDecoder->ld); + */ + bits = faad_get_processed_bits(&hDecoder->ld); + } else if (hDecoder->adts_header_present) { +#if 0 + faad_bookmark(&hDecoder->ld, 0); + faad_bookmark(&hDecoder->ld, 1); +#else + faad_initbits(&hDecoder->ld, buffer, 4); +#endif + get_adts_header(hDecoder); + /* only MPEG2 ADTS header uses byte_alignment */ + /* but it already is a multiple of 8 bits */ + /* + if (!hDecoder->isMpeg4) + byte_align(&hDecoder->ld); + */ + bits = 0; + } else { + hDecoder->mc_info.object_type = hDecoder->config.defObjectType; + hDecoder->mc_info.sampling_rate_idx = get_sr_index(hDecoder->config.defSampleRate); + } + + *samplerate = hDecoder->config.defSampleRate; + hDecoder->numChannels = *channels = 2; + hDecoder->chans_inited = 0; + if (hDecoder->adif_header_present) { + hDecoder->chans_inited = 1; + *samplerate = SampleRates[hDecoder->prog_config.sampling_rate_idx]; + hDecoder->numChannels = *channels = hDecoder->pceChannels; + } else if (hDecoder->adts_header_present) { + hDecoder->chans_inited = 1; + *samplerate = SampleRates[hDecoder->adts_header.fixed.sampling_rate_idx]; + hDecoder->numChannels = *channels = hDecoder->adts_header.fixed.channel_configuration; /* This works up to 6 channels */ + } + + huffbookinit(hDecoder); + nok_init_lt_pred(hDecoder->nok_lt_status, Chans); + init_pred(hDecoder, hDecoder->sp_status, Chans); + MakeFFTOrder(hDecoder); + InitBlock(hDecoder); /* calculate windows */ + + hDecoder->winmap[0] = hDecoder->win_seq_info[ONLY_LONG_WINDOW]; + hDecoder->winmap[1] = hDecoder->win_seq_info[ONLY_LONG_WINDOW]; + hDecoder->winmap[2] = hDecoder->win_seq_info[EIGHT_SHORT_WINDOW]; + hDecoder->winmap[3] = hDecoder->win_seq_info[ONLY_LONG_WINDOW]; + +#if 0 + faad_bookmark(&hDecoder->ld, 0); +#endif + + return bit2byte(bits); +} + +void FAADAPI faacDecClose(faacDecHandle hDecoder) +{ + int i; + + EndBlock(hDecoder); + nok_end_lt_pred(hDecoder->nok_lt_status, Chans); + + for(i=0; i < Chans; i++) + { + if (hDecoder->coef[i]) FreeMemory(hDecoder->coef[i]); + if (hDecoder->data[i]) FreeMemory(hDecoder->data[i]); + if (hDecoder->state[i]) FreeMemory(hDecoder->state[i]); + if (hDecoder->factors[i]) FreeMemory(hDecoder->factors[i]); + if (hDecoder->cb_map[i]) FreeMemory(hDecoder->cb_map[i]); + if (hDecoder->group[i]) FreeMemory(hDecoder->group[i]); + if (hDecoder->lpflag[i]) FreeMemory(hDecoder->lpflag[i]); + if (hDecoder->prstflag[i]) FreeMemory(hDecoder->prstflag[i]); + if (hDecoder->tns[i]) FreeMemory(hDecoder->tns[i]); + if (hDecoder->nok_lt_status[i]) FreeMemory(hDecoder->nok_lt_status[i]); + if (hDecoder->sp_status[i]) FreeMemory(hDecoder->sp_status[i]); + } + + if (hDecoder->mnt_table) FreeMemory(hDecoder->mnt_table); + if (hDecoder->exp_table) FreeMemory(hDecoder->exp_table); + if (hDecoder->iq_exp_tbl) FreeMemory(hDecoder->iq_exp_tbl); + if (hDecoder->exptable) FreeMemory(hDecoder->exptable); + if (hDecoder->unscambled64) FreeMemory(hDecoder->unscambled64); + if (hDecoder->unscambled512) FreeMemory(hDecoder->unscambled512); + + for(i=0; imask[i]) FreeMemory(hDecoder->mask[i]); + } + + if (hDecoder) FreeMemory(hDecoder); +} + +int FAADAPI faacDecGetProgConfig(faacDecHandle hDecoder, + faacProgConfig *progConfig) +{ + return hDecoder->numChannels; +} + +int FAADAPI faacDecDecode(faacDecHandle hDecoder, + unsigned char *buffer, + unsigned long *bytesconsumed, + short *sample_buffer, + unsigned long *samples) +{ + unsigned char d_bytes[MAX_DBYTES]; + int i, j, ch, wn, ele_id; + int left, right, tmp; + int d_tag, d_cnt; + int channels = 0; + Info *info; + MC_Info *mip = &(hDecoder->mc_info); + Ch_Info *cip; + int retCode = FAAD_OK; + + faad_initbits(&hDecoder->ld, buffer, *bytesconsumed); + + if (hDecoder->adts_header_present) + { + if (get_adts_header(hDecoder)) + { + goto error; + } + /* MPEG2 does byte_alignment() here + * but ADTS header is always multiple of 8 bits in MPEG2 + * so not needed + */ + } + + reset_mc_info(hDecoder, mip); + while ((ele_id=faad_getbits(&hDecoder->ld, LEN_SE_ID)) != ID_END) + { + /* get audio syntactic element */ + switch (ele_id) { + case ID_SCE: /* single channel */ + case ID_CPE: /* channel pair */ + case ID_LFE: /* low freq effects channel */ + if (huffdecode(hDecoder, ele_id, mip, hDecoder->wnd, hDecoder->wnd_shape, + hDecoder->cb_map, hDecoder->factors, hDecoder->group, hDecoder->hasmask, + hDecoder->mask, hDecoder->max_sfb, + hDecoder->lpflag, hDecoder->prstflag, hDecoder->nok_lt_status, + hDecoder->tns, hDecoder->coef) < 0) + goto error; + /* CommonExit(1,"2022: Error in huffman decoder"); */ + if (ele_id == ID_CPE) + channels += 2; + else + channels++; + break; + case ID_DSE: /* data element */ + if (getdata(hDecoder, &d_tag, &d_cnt, d_bytes) < 0) + goto error; + break; + case ID_PCE: /* program config element */ + get_prog_config(hDecoder, &hDecoder->prog_config); + break; + case ID_FIL: /* fill element */ + getfill(hDecoder, d_bytes); + break; + default: + /* CommonWarning("Element not supported"); */ + goto error; + } + } + + if ((channels != hDecoder->numChannels) && + (hDecoder->chans_inited == 0)) { + hDecoder->numChannels = channels; + retCode = FAAD_OK_CHUPDATE; + *bytesconsumed = 0; + +#if 0 + // wmay = fall through... + /* no errors, but channel update */ + return retCode; +#endif + } + + if (!check_mc_info(hDecoder, mip, (hDecoder->frameNum==0 && hDecoder->default_config))) { + goto error; + } + + /* m/s stereo */ + for (ch=0; chch_info[ch]; + if ((cip->present) && (cip->cpe) && (cip->ch_is_left)) { + wn = cip->widx; + if(hDecoder->hasmask[wn]) { + left = ch; + right = cip->paired_ch; + info = hDecoder->winmap[hDecoder->wnd[wn]]; + if (hDecoder->hasmask[wn] == 1) + map_mask(info, hDecoder->group[wn], hDecoder->mask[wn], + hDecoder->cb_map[right]); + synt(info, hDecoder->group[wn], hDecoder->mask[wn], + hDecoder->coef[right], hDecoder->coef[left]); + } + } + } + + /* intensity stereo and prediction */ + for (ch=0; chch_info[ch].present)) + continue; + + wn = mip->ch_info[ch].widx; + info = hDecoder->winmap[hDecoder->wnd[wn]]; + + pns(hDecoder, mip, info, wn, ch, + hDecoder->group[wn], hDecoder->cb_map[ch], hDecoder->factors[ch], + hDecoder->lpflag[wn], hDecoder->coef); + + intensity(mip, info, wn, ch, + hDecoder->group[wn], hDecoder->cb_map[ch], hDecoder->factors[ch], + hDecoder->lpflag[wn], hDecoder->coef); + + if (mip->object_type == AACLTP) { + nok_lt_predict(hDecoder, info, hDecoder->wnd[wn], &hDecoder->wnd_shape[wn], + hDecoder->nok_lt_status[ch]->sbk_prediction_used, + hDecoder->nok_lt_status[ch]->sfb_prediction_used, + hDecoder->nok_lt_status[ch], hDecoder->nok_lt_status[ch]->weight, + hDecoder->nok_lt_status[ch]->delay, hDecoder->coef[ch], + BLOCK_LEN_LONG, 0, BLOCK_LEN_SHORT, hDecoder->tns[ch]); + } else if (mip->object_type == AACMAIN) { + predict(hDecoder, info, mip->object_type, hDecoder->lpflag[wn], + hDecoder->sp_status[ch], hDecoder->coef[ch]); + } + } + + for (ch = 0; ch < Chans; ch++) { + if (!(mip->ch_info[ch].present)) + continue; + + wn = mip->ch_info[ch].widx; + info = hDecoder->winmap[hDecoder->wnd[wn]]; + + /* predictor reset */ + if (mip->object_type == AACMAIN) { + left = ch; + right = left; + if ((mip->ch_info[ch].cpe) && (mip->ch_info[ch].common_window)) + /* prstflag's shared by channel pair */ + right = mip->ch_info[ch].paired_ch; + predict_reset(hDecoder, info, hDecoder->prstflag[wn], hDecoder->sp_status, + left, right, hDecoder->last_rstgrp_num); + + /* PNS predictor reset */ + predict_pns_reset(info, hDecoder->sp_status[ch], hDecoder->cb_map[ch]); + } + + /* tns */ + for (i=j=0; i < hDecoder->tns[ch]->n_subblocks; i++) { + + tns_decode_subblock(hDecoder, &hDecoder->coef[ch][j], + hDecoder->max_sfb[wn], + info->sbk_sfb_top[i], + info->islong, + &(hDecoder->tns[ch]->info[i]) ); + + j += info->bins_per_sbk[i]; + } + + /* inverse transform */ + freq2time_adapt(hDecoder, hDecoder->wnd[wn], &hDecoder->wnd_shape[wn], + hDecoder->coef[ch], hDecoder->state[ch], hDecoder->data[ch]); + + if (mip->object_type == AACLTP) { + nok_lt_update(hDecoder->nok_lt_status[ch], hDecoder->data[ch], + hDecoder->state[ch], BLOCK_LEN_LONG); + } + } + + /* Copy output to a standard PCM buffer */ + for(i=0; i < 1024; i++) /* prkoat */ + { + + for (ch=0; ch < mip->nch; ch++) + { +/* much faster FTOL */ +#ifndef ENDIAN_SAFE + float ftemp; + /* ftemp = truncate(data[ch][i]) + 0xff8000; */ + ftemp = hDecoder->data[ch][i] + 0xff8000; + ftol(ftemp, sample_buffer[(i*mip->nch)+ch]); +#else + sample_buffer[(i*mip->nch)+ch] = (short)truncate(data[ch][i]); +#endif + + } + } + + hDecoder->frameNum++; + faad_byte_align(&hDecoder->ld); + + //printf("processed %d bits\n", faad_get_processed_bits(&hDecoder->ld)); + *bytesconsumed = bit2byte(faad_get_processed_bits(&hDecoder->ld)); + if (hDecoder->frameNum > 2) + *samples = 1024*mip->nch; + else + *samples = 0; + + /* no errors */ + return retCode; + +error: +#if 0 + // + // wmay - remove this error recovery, and let calling app handle this - + // with mpeg4ip, we can get better recovery, especially with RTP. + // + /* search for next ADTS header first, so decoding can be continued */ + /* ADIF and RAW AAC files will not be able to continue playing */ + if (hDecoder->adts_header_present) { + int k, sync = 0; + + faad_byte_align(&hDecoder->ld); + + for(k = 0; sync != 4096 - 1; k++) + { + sync = faad_getbits(&hDecoder->ld, 12); /* 12 bit SYNCWORD */ + faad_getbits(&hDecoder->ld, 4); + + /* Bail out if no syncword found */ + if(k >= (6144 / 16)) + { + SetMemory(sample_buffer, 0, sizeof(short)*mip->nch*1024); + + /* unrecoverable error */ + return FAAD_FATAL_ERROR; + } + } + + *bytesconsumed = bit2byte(hDecoder->ld.framebits - 16); + SetMemory(sample_buffer, 0, sizeof(short)*mip->nch*1024); + + /* error, but recoverable */ + return FAAD_ERROR; + } else { + SetMemory(sample_buffer, 0, sizeof(short)*mip->nch*1024); + + /* unrecoverable error */ + return FAAD_FATAL_ERROR; + } +#else + *bytesconsumed = bit2byte(faad_get_processed_bits(&hDecoder->ld)); + return FAAD_ERROR; +#endif +} + diff --git a/dolby_adapt.c b/dolby_adapt.c new file mode 100644 index 0000000..5f4ebe6 --- /dev/null +++ b/dolby_adapt.c @@ -0,0 +1,537 @@ +/************************* MPEG-2 NBC Audio Decoder ************************** + * * +"This software module was originally developed by +AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS in the course of +development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ +/* + * $Id: dolby_adapt.c,v 1.7 2003/02/18 18:51:30 wmaycisco Exp $ + */ + +#include "all.h" +#include "block.h" +#include "util.h" + +#define NORM_TYPE 0 +#define START_TYPE 1 +#define SHORT_TYPE 2 +#define STOP_TYPE 3 + +/* +* Interleave Definitions for start and stop blocks +* +* Start block contains 1 576-pt spectrum (A) and 4 128-pt spectra (B-E) +* Input spectra are interleaved in repeating segements of 17 bins, +* 9 bins from A (A0-A8), and 2 bins from each of the shorts. +* Within the segments the bins are interleaved as: +* A0 A1 A2 A3 A4 B0 C0 D0 E0 A5 A6 A7 A8 B1 C1 D1 E1 +* +* Stop block contains 3 128-pt spectra (A-C) and 1 576-pt spectrum (D) +* Input spectra are interleaved in repeating segements of 15 bins, +* 2 bins from each of the shorts, and 9 bins from D (D0-D8). +* Within the segments the bins are interleaved as: +* A0 B0 C0 D0 D1 D2 D3 D4 A1 B1 C1 D5 D6 D7 D8 +* The last 64 bins are (should be) set to 0. +*/ + +#define N_SHORT_IN_START 4 +#define START_OFFSET 0 +#define SHORT_IN_START_OFFSET 5 +#define N_SHORT_IN_STOP 3 +#define STOP_OFFSET 3 +#define SHORT_IN_STOP_OFFSET 0 +#define N_SHORT_IN_4STOP 4 + +/***************************************************************************** +* +* unfold +* create full spectrum by reflecting-inverting first half over to second +* input: see below +* output: see below +* local static: none +* globals: none +* +*****************************************************************************/ +void unfold ( + Float *data_in, /* input: 1/2 spectrum */ + Float *data_out, /* output: full spectrum */ + int inLeng) /* input: length of input vector */ +{ + register int i; + + /* fill transBuff w/ full MDCT sequence from freqInPtr */ + i=0; + do + { + + data_out[i] = *data_in; + data_out[2*inLeng-i-1] = -(*data_in); + data_in++; + i++; + + data_out[i] = *data_in; + data_out[2*inLeng-i-1] = -(*data_in); + data_in++; + i++; + + data_out[i] = *data_in; + data_out[2*inLeng-i-1] = -(*data_in); + data_in++; + i++; + + data_out[i] = *data_in; + data_out[2*inLeng-i-1] = -(*data_in); + data_in++; + i++; + + }while (i= 0; --i) + { + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + + } + + /* Save second half as old data */ + timeBuffPtr = timeBuff; /* [ch]; */ + for (i = BLOCK_LEN_LONG/16 - 1; i >= 0; --i) { + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + } + } + + else if (blockType == SHORT_TYPE) + { + /* Do 8 SHORT transforms */ + + if (hDecoder->dolbyShortOffset_f2t) + destPtr = timeBuff + 4 * BLOCK_LEN_SHORT; /* DBS */ + else + destPtr = timeBuff + (BLOCK_LEN_LONG - BLOCK_LEN_SHORT) / 2; /* 448 */ + + for (i = 0; i < 8; i++) { + unfold (freqInPtr, transBuff, BLOCK_LEN_SHORT ); + /*was freqinPtr++, 8 .. mfd */ + freqInPtr += BLOCK_LEN_SHORT; /* added mfd */ + ITransformBlock (hDecoder, transBuff, SHORT_BLOCK, wnd_shape, timeBuff); + + /* Add first half of short window and old data */ + transBuffPtr = transBuff; + + for (j = BLOCK_LEN_SHORT/16-1; j >= 0; --j) { + *destPtr++ += *transBuffPtr++; *destPtr++ += *transBuffPtr++; + *destPtr++ += *transBuffPtr++; *destPtr++ += *transBuffPtr++; + *destPtr++ += *transBuffPtr++; *destPtr++ += *transBuffPtr++; + *destPtr++ += *transBuffPtr++; *destPtr++ += *transBuffPtr++; + *destPtr++ += *transBuffPtr++; *destPtr++ += *transBuffPtr++; + *destPtr++ += *transBuffPtr++; *destPtr++ += *transBuffPtr++; + *destPtr++ += *transBuffPtr++; *destPtr++ += *transBuffPtr++; + *destPtr++ += *transBuffPtr++; *destPtr++ += *transBuffPtr++; + } + + /* Save second half of short window */ + for (j = BLOCK_LEN_SHORT/16-1; j >= 0; --j) { + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + } + destPtr -= BLOCK_LEN_SHORT; + } + /* Copy data to output buffer */ + destPtr = timeOutPtr; + timeBuffPtr = timeBuff; /* [ch]; */ + + for (i = BLOCK_LEN_LONG/16 - 1; i >= 0; --i) { + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + } + /* Update timeBuff fifo */ + destPtr = timeBuff; /* [ch]; */ + for (i = BLOCK_LEN_LONG/16 - 1; i >= 0; --i) { + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + *destPtr++ = *timeBuffPtr++; *destPtr++ = *timeBuffPtr++; + } + } + + else if (blockType == START_TYPE) { + unfold(freqInPtr, transBuff, BLOCK_LEN_LONG); + ITransformBlock (hDecoder, transBuff, START_FLAT_BLOCK, wnd_shape, timeBuff); + /* Add first half and old data */ + transBuffPtr = transBuff; + timeBuffPtr = timeBuff; + destPtr = timeOutPtr; + for (i = BLOCK_LEN_LONG/16 - 1; i >= 0; --i) { + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + } + /* Save second half as old data */ + timeBuffPtr = timeBuff; + for (i = BLOCK_LEN_LONG/16 - 1; i >= 0; --i) { + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + } + hDecoder->dolbyShortOffset_f2t = 0; + } + + else if (blockType == STOP_TYPE) { + unfold (freqInPtr, transBuff, BLOCK_LEN_LONG); + /* Do 1 LONG transforms */ + ITransformBlock (hDecoder, transBuff, STOP_FLAT_BLOCK, wnd_shape, timeBuff); + /* Add first half and old data */ + transBuffPtr = transBuff; + timeBuffPtr = timeBuff; + destPtr = timeOutPtr; + for (i = (BLOCK_LEN_LONG - NFLAT)/16 - 1; i>=0;--i) + { + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + *destPtr++ = *transBuffPtr++ + *timeBuffPtr++; + } + for ( i = NFLAT/16-1; i>=0;--i) { + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + } + + /* Save second half as old data */ + timeBuffPtr = timeBuff; + + for (i = BLOCK_LEN_LONG/16 - 1; i >= 0; --i ) { + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + *timeBuffPtr++ = *transBuffPtr++; *timeBuffPtr++ = *transBuffPtr++; + } + } + + i=0; + do + { + *(ftimeOutPtr++) = (timeOutPtr[i]); i++; + *(ftimeOutPtr++) = (timeOutPtr[i]); i++; + *(ftimeOutPtr++) = (timeOutPtr[i]); i++; + *(ftimeOutPtr++) = (timeOutPtr[i]); i++; + *(ftimeOutPtr++) = (timeOutPtr[i]); i++; + *(ftimeOutPtr++) = (timeOutPtr[i]); i++; + *(ftimeOutPtr++) = (timeOutPtr[i]); i++; + *(ftimeOutPtr++) = (timeOutPtr[i]); i++; + } while(i= 0; --i) + { + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + } + /* Do 1 LONG transform */ + TransformBlock (hDecoder, transBuff, LONG_BLOCK, wnd_shape); + + srcPtr = transBuff; + destPtr = freqOutPtr; + for (i = BLOCK_LEN_LONG/16-1; i>=0; --i) + { + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + } + } + + else if (blockType == SHORT_TYPE) { + /* Do 8 SHORT transforms */ + + srcPtr = timeInPtr + (BLOCK_LEN_LONG - BLOCK_LEN_SHORT) / 2; + destPtr = freqOutPtr; + + for (i = 0; i < 8; i++) { + transBuffPtr = transBuff; + for (i = 2 * BLOCK_LEN_SHORT/16-1; i>=0; --i) { + *transBuffPtr++ = *srcPtr++; *transBuffPtr++ = *srcPtr++; + *transBuffPtr++ = *srcPtr++; *transBuffPtr++ = *srcPtr++; + *transBuffPtr++ = *srcPtr++; *transBuffPtr++ = *srcPtr++; + *transBuffPtr++ = *srcPtr++; *transBuffPtr++ = *srcPtr++; + *transBuffPtr++ = *srcPtr++; *transBuffPtr++ = *srcPtr++; + *transBuffPtr++ = *srcPtr++; *transBuffPtr++ = *srcPtr++; + *transBuffPtr++ = *srcPtr++; *transBuffPtr++ = *srcPtr++; + *transBuffPtr++ = *srcPtr++; *transBuffPtr++ = *srcPtr++; + } + srcPtr -= BLOCK_LEN_SHORT; + TransformBlock (hDecoder, transBuff, SHORT_BLOCK, wnd_shape); + + /* Copy data to output buffer */ + transBuffPtr = transBuff; + for (j = BLOCK_LEN_SHORT/16-1; j>=0;--j) { + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + *destPtr++ = *transBuffPtr++; *destPtr++ = *transBuffPtr++; + + } + } + } + + else if (blockType == START_TYPE) { + srcPtr = timeInPtr; + destPtr = transBuff; + for (i = 2 * BLOCK_LEN_LONG/16-1; i>=0;--i) { + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + + } + TransformBlock (hDecoder, transBuff, START_FLAT_BLOCK, wnd_shape); + + srcPtr = transBuff; + destPtr = freqOutPtr; + for (i = BLOCK_LEN_LONG/16-1; i>=0;--i) { + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + } + hDecoder->dolbyShortOffset_t2f = 0; + } + + else if (blockType == STOP_TYPE) { + srcPtr = timeInPtr; + destPtr = transBuff; + for (i = 2 * BLOCK_LEN_LONG/16-1; i>=0;--i) { + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + } + TransformBlock (hDecoder, transBuff, STOP_FLAT_BLOCK, wnd_shape); + + srcPtr = transBuff; + destPtr = freqOutPtr; + for (i = BLOCK_LEN_LONG/16-1; i>=0;--i) { + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + + } + } + + srcPtr = freqOutPtr; + destPtr = ffreqOutPtr; + for (i = BLOCK_LEN_LONG/16-1; i>=0;--i) { + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + *destPtr++ = *srcPtr++; *destPtr++ = *srcPtr++; + } + + FreeMemory(freqOutPtr); + FreeMemory(transBuff); +} diff --git a/fastfft.c b/fastfft.c new file mode 100644 index 0000000..3a00e49 --- /dev/null +++ b/fastfft.c @@ -0,0 +1,2908 @@ +/* + * FAAD - Freeware Advanced Audio Decoder + * Copyright (C) 2001 Menno Bakker + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: fastfft.c,v 1.4 2002/01/11 00:55:17 wmaycisco Exp $ + */ + +#include "fastfft.h" +#include "all.h" + +#ifdef _MSC_VER +#pragma warning(disable:4305) +#endif + + +static fftw_real K980785280[1] = +{FFTW_KONST(+0.980785280403230449126182236134239036973933731)}; +static fftw_real K195090322[1] = +{FFTW_KONST(+0.195090322016128267848284868477022240927691618)}; +static fftw_real K555570233[1] = +{FFTW_KONST(+0.555570233019602224742830813948532874374937191)}; +static fftw_real K831469612[1] = +{FFTW_KONST(+0.831469612302545237078788377617905756738560812)}; +static fftw_real K923879532[1] = +{FFTW_KONST(+0.923879532511286756128183189396788286822416626)}; +static fftw_real K382683432[1] = +{FFTW_KONST(+0.382683432365089771728459984030398866761344562)}; +static fftw_real K707106781[1] = +{FFTW_KONST(+0.707106781186547524400844362104849039284835938)}; + +static fftw_complex PFFTW(W_64)[30] = { +{ 0.995184726672197, 0.0980171403295606 }, +{ 0.98078528040323, 0.195090322016128 }, +{ 0.98078528040323, 0.195090322016128 }, +{ 0.923879532511287, 0.38268343236509 }, +{ 0.956940335732209, 0.290284677254462 }, +{ 0.831469612302545, 0.555570233019602 }, +{ 0.923879532511287, 0.38268343236509 }, +{ 0.707106781186548, 0.707106781186547 }, +{ 0.881921264348355, 0.471396736825998 }, +{ 0.555570233019602, 0.831469612302545 }, +{ 0.831469612302545, 0.555570233019602 }, +{ 0.38268343236509, 0.923879532511287 }, +{ 0.773010453362737, 0.634393284163645 }, +{ 0.195090322016128, 0.98078528040323 }, +{ 0.707106781186548, 0.707106781186547 }, +{ 6.12303176911189e-17, 1 }, +{ 0.634393284163645, 0.773010453362737 }, +{ -0.195090322016128, 0.98078528040323 }, +{ 0.555570233019602, 0.831469612302545 }, +{ -0.38268343236509, 0.923879532511287 }, +{ 0.471396736825998, 0.881921264348355 }, +{ -0.555570233019602, 0.831469612302545 }, +{ 0.38268343236509, 0.923879532511287 }, +{ -0.707106781186547, 0.707106781186548 }, +{ 0.290284677254462, 0.956940335732209 }, +{ -0.831469612302545, 0.555570233019602 }, +{ 0.195090322016128, 0.98078528040323 }, +{ -0.923879532511287, 0.38268343236509 }, +{ 0.0980171403295608, 0.995184726672197 }, +{ -0.98078528040323, 0.195090322016129 }, +}; + +static fftw_complex PFFTW(W_128)[62] = { +{ 0.998795456205172, 0.049067674327418 }, +{ 0.995184726672197, 0.0980171403295606 }, +{ 0.995184726672197, 0.0980171403295606 }, +{ 0.98078528040323, 0.195090322016128 }, +{ 0.989176509964781, 0.146730474455362 }, +{ 0.956940335732209, 0.290284677254462 }, +{ 0.98078528040323, 0.195090322016128 }, +{ 0.923879532511287, 0.38268343236509 }, +{ 0.970031253194544, 0.242980179903264 }, +{ 0.881921264348355, 0.471396736825998 }, +{ 0.956940335732209, 0.290284677254462 }, +{ 0.831469612302545, 0.555570233019602 }, +{ 0.941544065183021, 0.33688985339222 }, +{ 0.773010453362737, 0.634393284163645 }, +{ 0.923879532511287, 0.38268343236509 }, +{ 0.707106781186548, 0.707106781186547 }, +{ 0.903989293123443, 0.427555093430282 }, +{ 0.634393284163645, 0.773010453362737 }, +{ 0.881921264348355, 0.471396736825998 }, +{ 0.555570233019602, 0.831469612302545 }, +{ 0.857728610000272, 0.514102744193222 }, +{ 0.471396736825998, 0.881921264348355 }, +{ 0.831469612302545, 0.555570233019602 }, +{ 0.38268343236509, 0.923879532511287 }, +{ 0.803207531480645, 0.595699304492433 }, +{ 0.290284677254462, 0.956940335732209 }, +{ 0.773010453362737, 0.634393284163645 }, +{ 0.195090322016128, 0.98078528040323 }, +{ 0.740951125354959, 0.671558954847018 }, +{ 0.0980171403295608, 0.995184726672197 }, +{ 0.707106781186548, 0.707106781186547 }, +{ 6.12303176911189e-17, 1 }, +{ 0.671558954847018, 0.740951125354959 }, +{ -0.0980171403295606, 0.995184726672197 }, +{ 0.634393284163645, 0.773010453362737 }, +{ -0.195090322016128, 0.98078528040323 }, +{ 0.595699304492433, 0.803207531480645 }, +{ -0.290284677254462, 0.956940335732209 }, +{ 0.555570233019602, 0.831469612302545 }, +{ -0.38268343236509, 0.923879532511287 }, +{ 0.514102744193222, 0.857728610000272 }, +{ -0.471396736825998, 0.881921264348355 }, +{ 0.471396736825998, 0.881921264348355 }, +{ -0.555570233019602, 0.831469612302545 }, +{ 0.427555093430282, 0.903989293123443 }, +{ -0.634393284163645, 0.773010453362737 }, +{ 0.38268343236509, 0.923879532511287 }, +{ -0.707106781186547, 0.707106781186548 }, +{ 0.33688985339222, 0.941544065183021 }, +{ -0.773010453362737, 0.634393284163645 }, +{ 0.290284677254462, 0.956940335732209 }, +{ -0.831469612302545, 0.555570233019602 }, +{ 0.242980179903264, 0.970031253194544 }, +{ -0.881921264348355, 0.471396736825998 }, +{ 0.195090322016128, 0.98078528040323 }, +{ -0.923879532511287, 0.38268343236509 }, +{ 0.146730474455362, 0.989176509964781 }, +{ -0.956940335732209, 0.290284677254462 }, +{ 0.0980171403295608, 0.995184726672197 }, +{ -0.98078528040323, 0.195090322016129 }, +{ 0.0490676743274181, 0.998795456205172 }, +{ -0.995184726672197, 0.0980171403295608 }, +}; + +static fftw_complex PFFTW(W_512)[254] = { +{ 0.999924701839145, 0.0122715382857199 }, +{ 0.999698818696204, 0.0245412285229123 }, +{ 0.999698818696204, 0.0245412285229123 }, +{ 0.998795456205172, 0.049067674327418 }, +{ 0.99932238458835, 0.0368072229413588 }, +{ 0.99729045667869, 0.0735645635996674 }, +{ 0.998795456205172, 0.049067674327418 }, +{ 0.995184726672197, 0.0980171403295606 }, +{ 0.998118112900149, 0.0613207363022086 }, +{ 0.99247953459871, 0.122410675199216 }, +{ 0.99729045667869, 0.0735645635996674 }, +{ 0.989176509964781, 0.146730474455362 }, +{ 0.996312612182778, 0.0857973123444399 }, +{ 0.985277642388941, 0.170961888760301 }, +{ 0.995184726672197, 0.0980171403295606 }, +{ 0.98078528040323, 0.195090322016128 }, +{ 0.993906970002356, 0.110222207293883 }, +{ 0.975702130038529, 0.21910124015687 }, +{ 0.99247953459871, 0.122410675199216 }, +{ 0.970031253194544, 0.242980179903264 }, +{ 0.99090263542778, 0.134580708507126 }, +{ 0.96377606579544, 0.266712757474898 }, +{ 0.989176509964781, 0.146730474455362 }, +{ 0.956940335732209, 0.290284677254462 }, +{ 0.987301418157858, 0.158858143333861 }, +{ 0.949528180593037, 0.313681740398892 }, +{ 0.985277642388941, 0.170961888760301 }, +{ 0.941544065183021, 0.33688985339222 }, +{ 0.983105487431216, 0.183039887955141 }, +{ 0.932992798834739, 0.359895036534988 }, +{ 0.98078528040323, 0.195090322016128 }, +{ 0.923879532511287, 0.38268343236509 }, +{ 0.978317370719628, 0.207111376192219 }, +{ 0.914209755703531, 0.40524131400499 }, +{ 0.975702130038529, 0.21910124015687 }, +{ 0.903989293123443, 0.427555093430282 }, +{ 0.97293995220556, 0.231058108280671 }, +{ 0.893224301195515, 0.449611329654607 }, +{ 0.970031253194544, 0.242980179903264 }, +{ 0.881921264348355, 0.471396736825998 }, +{ 0.966976471044852, 0.254865659604515 }, +{ 0.870086991108711, 0.492898192229784 }, +{ 0.96377606579544, 0.266712757474898 }, +{ 0.857728610000272, 0.514102744193222 }, +{ 0.960430519415566, 0.278519689385053 }, +{ 0.844853565249707, 0.534997619887097 }, +{ 0.956940335732209, 0.290284677254462 }, +{ 0.831469612302545, 0.555570233019602 }, +{ 0.953306040354194, 0.302005949319228 }, +{ 0.817584813151584, 0.575808191417845 }, +{ 0.949528180593037, 0.313681740398892 }, +{ 0.803207531480645, 0.595699304492433 }, +{ 0.945607325380521, 0.325310292162263 }, +{ 0.788346427626606, 0.615231590580627 }, +{ 0.941544065183021, 0.33688985339222 }, +{ 0.773010453362737, 0.634393284163645 }, +{ 0.937339011912575, 0.348418680249435 }, +{ 0.757208846506485, 0.653172842953777 }, +{ 0.932992798834739, 0.359895036534988 }, +{ 0.740951125354959, 0.671558954847018 }, +{ 0.928506080473216, 0.371317193951838 }, +{ 0.724247082951467, 0.689540544737067 }, +{ 0.923879532511287, 0.38268343236509 }, +{ 0.707106781186548, 0.707106781186547 }, +{ 0.919113851690058, 0.393992040061048 }, +{ 0.689540544737067, 0.724247082951467 }, +{ 0.914209755703531, 0.40524131400499 }, +{ 0.671558954847018, 0.740951125354959 }, +{ 0.909167983090522, 0.416429560097637 }, +{ 0.653172842953777, 0.757208846506484 }, +{ 0.903989293123443, 0.427555093430282 }, +{ 0.634393284163645, 0.773010453362737 }, +{ 0.898674465693954, 0.438616238538528 }, +{ 0.615231590580627, 0.788346427626606 }, +{ 0.893224301195515, 0.449611329654607 }, +{ 0.595699304492433, 0.803207531480645 }, +{ 0.887639620402854, 0.46053871095824 }, +{ 0.575808191417845, 0.817584813151584 }, +{ 0.881921264348355, 0.471396736825998 }, +{ 0.555570233019602, 0.831469612302545 }, +{ 0.876070094195407, 0.482183772079123 }, +{ 0.534997619887097, 0.844853565249707 }, +{ 0.870086991108711, 0.492898192229784 }, +{ 0.514102744193222, 0.857728610000272 }, +{ 0.863972856121587, 0.503538383725718 }, +{ 0.492898192229784, 0.870086991108711 }, +{ 0.857728610000272, 0.514102744193222 }, +{ 0.471396736825998, 0.881921264348355 }, +{ 0.851355193105265, 0.524589682678469 }, +{ 0.449611329654607, 0.893224301195515 }, +{ 0.844853565249707, 0.534997619887097 }, +{ 0.427555093430282, 0.903989293123443 }, +{ 0.838224705554838, 0.545324988422046 }, +{ 0.40524131400499, 0.914209755703531 }, +{ 0.831469612302545, 0.555570233019602 }, +{ 0.38268343236509, 0.923879532511287 }, +{ 0.824589302785025, 0.565731810783613 }, +{ 0.359895036534988, 0.932992798834739 }, +{ 0.817584813151584, 0.575808191417845 }, +{ 0.33688985339222, 0.941544065183021 }, +{ 0.810457198252595, 0.585797857456439 }, +{ 0.313681740398892, 0.949528180593037 }, +{ 0.803207531480645, 0.595699304492433 }, +{ 0.290284677254462, 0.956940335732209 }, +{ 0.795836904608884, 0.605511041404326 }, +{ 0.266712757474898, 0.96377606579544 }, +{ 0.788346427626606, 0.615231590580627 }, +{ 0.242980179903264, 0.970031253194544 }, +{ 0.780737228572094, 0.624859488142386 }, +{ 0.21910124015687, 0.975702130038529 }, +{ 0.773010453362737, 0.634393284163645 }, +{ 0.195090322016128, 0.98078528040323 }, +{ 0.765167265622459, 0.643831542889791 }, +{ 0.170961888760301, 0.985277642388941 }, +{ 0.757208846506485, 0.653172842953777 }, +{ 0.146730474455362, 0.989176509964781 }, +{ 0.749136394523459, 0.662415777590172 }, +{ 0.122410675199216, 0.99247953459871 }, +{ 0.740951125354959, 0.671558954847018 }, +{ 0.0980171403295608, 0.995184726672197 }, +{ 0.732654271672413, 0.680600997795453 }, +{ 0.0735645635996675, 0.99729045667869 }, +{ 0.724247082951467, 0.689540544737067 }, +{ 0.0490676743274181, 0.998795456205172 }, +{ 0.715730825283819, 0.698376249408973 }, +{ 0.0245412285229123, 0.999698818696204 }, +{ 0.707106781186548, 0.707106781186547 }, +{ 6.12303176911189e-17, 1 }, +{ 0.698376249408973, 0.715730825283819 }, +{ -0.0245412285229121, 0.999698818696204 }, +{ 0.689540544737067, 0.724247082951467 }, +{ -0.049067674327418, 0.998795456205172 }, +{ 0.680600997795453, 0.732654271672413 }, +{ -0.0735645635996673, 0.99729045667869 }, +{ 0.671558954847018, 0.740951125354959 }, +{ -0.0980171403295606, 0.995184726672197 }, +{ 0.662415777590172, 0.749136394523459 }, +{ -0.122410675199216, 0.99247953459871 }, +{ 0.653172842953777, 0.757208846506484 }, +{ -0.146730474455362, 0.989176509964781 }, +{ 0.643831542889791, 0.765167265622459 }, +{ -0.170961888760301, 0.985277642388941 }, +{ 0.634393284163645, 0.773010453362737 }, +{ -0.195090322016128, 0.98078528040323 }, +{ 0.624859488142386, 0.780737228572094 }, +{ -0.21910124015687, 0.975702130038529 }, +{ 0.615231590580627, 0.788346427626606 }, +{ -0.242980179903264, 0.970031253194544 }, +{ 0.605511041404326, 0.795836904608883 }, +{ -0.266712757474898, 0.96377606579544 }, +{ 0.595699304492433, 0.803207531480645 }, +{ -0.290284677254462, 0.956940335732209 }, +{ 0.585797857456439, 0.810457198252595 }, +{ -0.313681740398891, 0.949528180593037 }, +{ 0.575808191417845, 0.817584813151584 }, +{ -0.33688985339222, 0.941544065183021 }, +{ 0.565731810783613, 0.824589302785025 }, +{ -0.359895036534988, 0.932992798834739 }, +{ 0.555570233019602, 0.831469612302545 }, +{ -0.38268343236509, 0.923879532511287 }, +{ 0.545324988422046, 0.838224705554838 }, +{ -0.40524131400499, 0.914209755703531 }, +{ 0.534997619887097, 0.844853565249707 }, +{ -0.427555093430282, 0.903989293123443 }, +{ 0.524589682678469, 0.851355193105265 }, +{ -0.449611329654607, 0.893224301195515 }, +{ 0.514102744193222, 0.857728610000272 }, +{ -0.471396736825998, 0.881921264348355 }, +{ 0.503538383725718, 0.863972856121587 }, +{ -0.492898192229784, 0.870086991108711 }, +{ 0.492898192229784, 0.870086991108711 }, +{ -0.514102744193222, 0.857728610000272 }, +{ 0.482183772079123, 0.876070094195407 }, +{ -0.534997619887097, 0.844853565249707 }, +{ 0.471396736825998, 0.881921264348355 }, +{ -0.555570233019602, 0.831469612302545 }, +{ 0.46053871095824, 0.887639620402854 }, +{ -0.575808191417845, 0.817584813151584 }, +{ 0.449611329654607, 0.893224301195515 }, +{ -0.595699304492433, 0.803207531480645 }, +{ 0.438616238538528, 0.898674465693954 }, +{ -0.615231590580627, 0.788346427626606 }, +{ 0.427555093430282, 0.903989293123443 }, +{ -0.634393284163645, 0.773010453362737 }, +{ 0.416429560097637, 0.909167983090522 }, +{ -0.653172842953777, 0.757208846506485 }, +{ 0.40524131400499, 0.914209755703531 }, +{ -0.671558954847018, 0.740951125354959 }, +{ 0.393992040061048, 0.919113851690058 }, +{ -0.689540544737067, 0.724247082951467 }, +{ 0.38268343236509, 0.923879532511287 }, +{ -0.707106781186547, 0.707106781186548 }, +{ 0.371317193951838, 0.928506080473215 }, +{ -0.724247082951467, 0.689540544737067 }, +{ 0.359895036534988, 0.932992798834739 }, +{ -0.740951125354959, 0.671558954847019 }, +{ 0.348418680249435, 0.937339011912575 }, +{ -0.757208846506485, 0.653172842953777 }, +{ 0.33688985339222, 0.941544065183021 }, +{ -0.773010453362737, 0.634393284163645 }, +{ 0.325310292162263, 0.945607325380521 }, +{ -0.788346427626606, 0.615231590580627 }, +{ 0.313681740398892, 0.949528180593037 }, +{ -0.803207531480645, 0.595699304492433 }, +{ 0.302005949319228, 0.953306040354194 }, +{ -0.817584813151584, 0.575808191417845 }, +{ 0.290284677254462, 0.956940335732209 }, +{ -0.831469612302545, 0.555570233019602 }, +{ 0.278519689385053, 0.960430519415566 }, +{ -0.844853565249707, 0.534997619887097 }, +{ 0.266712757474898, 0.96377606579544 }, +{ -0.857728610000272, 0.514102744193222 }, +{ 0.254865659604515, 0.966976471044852 }, +{ -0.870086991108711, 0.492898192229784 }, +{ 0.242980179903264, 0.970031253194544 }, +{ -0.881921264348355, 0.471396736825998 }, +{ 0.231058108280671, 0.97293995220556 }, +{ -0.893224301195515, 0.449611329654607 }, +{ 0.21910124015687, 0.975702130038529 }, +{ -0.903989293123443, 0.427555093430282 }, +{ 0.207111376192219, 0.978317370719628 }, +{ -0.914209755703531, 0.40524131400499 }, +{ 0.195090322016128, 0.98078528040323 }, +{ -0.923879532511287, 0.38268343236509 }, +{ 0.183039887955141, 0.983105487431216 }, +{ -0.932992798834739, 0.359895036534988 }, +{ 0.170961888760301, 0.985277642388941 }, +{ -0.941544065183021, 0.33688985339222 }, +{ 0.158858143333861, 0.987301418157858 }, +{ -0.949528180593037, 0.313681740398891 }, +{ 0.146730474455362, 0.989176509964781 }, +{ -0.956940335732209, 0.290284677254462 }, +{ 0.134580708507126, 0.99090263542778 }, +{ -0.96377606579544, 0.266712757474898 }, +{ 0.122410675199216, 0.99247953459871 }, +{ -0.970031253194544, 0.242980179903264 }, +{ 0.110222207293883, 0.993906970002356 }, +{ -0.975702130038528, 0.21910124015687 }, +{ 0.0980171403295608, 0.995184726672197 }, +{ -0.98078528040323, 0.195090322016129 }, +{ 0.0857973123444399, 0.996312612182778 }, +{ -0.985277642388941, 0.170961888760301 }, +{ 0.0735645635996675, 0.99729045667869 }, +{ -0.989176509964781, 0.146730474455362 }, +{ 0.0613207363022086, 0.998118112900149 }, +{ -0.99247953459871, 0.122410675199216 }, +{ 0.0490676743274181, 0.998795456205172 }, +{ -0.995184726672197, 0.0980171403295608 }, +{ 0.036807222941359, 0.99932238458835 }, +{ -0.99729045667869, 0.0735645635996677 }, +{ 0.0245412285229123, 0.999698818696204 }, +{ -0.998795456205172, 0.049067674327418 }, +{ 0.0122715382857199, 0.999924701839145 }, +{ -0.999698818696204, 0.0245412285229123 }, +}; +/////////////////////////////////////////////////////////////// + +void PFFTW(16) (fftw_complex * input) { + fftw_real tmp332; + fftw_real tmp331; + fftw_real tmp330; + fftw_real tmp329; + fftw_real tmp328; + fftw_real tmp327; + fftw_real tmp326; + fftw_real tmp325; + fftw_real tmp324; + fftw_real tmp323; + fftw_real tmp322; + fftw_real tmp321; + fftw_real tmp320; + fftw_real tmp319; + fftw_real tmp318; + fftw_real tmp317; + fftw_real tmp316; + fftw_real tmp315; + fftw_real tmp314; + fftw_real tmp313; + fftw_real tmp312; + fftw_real tmp311; + fftw_real tmp310; + fftw_real tmp309; + fftw_real tmp308; + fftw_real tmp307; + fftw_real tmp306; + fftw_real tmp305; + fftw_real tmp304; + fftw_real tmp303; + fftw_real tmp302; + fftw_real tmp301; + fftw_real st1; + fftw_real st2; + fftw_real st3; + fftw_real st4; + fftw_real st5; + fftw_real st6; + fftw_real st7; + fftw_real st8; + st8 = c_re(input[0]); + st8 = st8 - c_re(input[8]); + st7 = c_im(input[4]); + st7 = st7 - c_im(input[12]); + st6 = c_re(input[4]); + st5 = st8 - st7; + st8 = st8 + st7; + st6 = st6 - c_re(input[12]); + st4 = c_im(input[0]); + st4 = st4 - c_im(input[8]); + st3 = c_re(input[0]); + st2 = st6 + st4; + st4 = st4 - st6; + st3 = st3 + c_re(input[8]); + st1 = c_re(input[4]); + st1 = st1 + c_re(input[12]); + st7 = c_im(input[0]); + st6 = st3 + st1; + st3 = st3 - st1; + st7 = st7 + c_im(input[8]); + st1 = c_im(input[4]); + st1 = st1 + c_im(input[12]); + tmp301 = st4; + st4 = c_re(input[2]); + tmp302 = st8; + st8 = st7 + st1; + st7 = st7 - st1; + st4 = st4 + c_re(input[10]); + st1 = c_re(input[6]); + st1 = st1 + c_re(input[14]); + tmp303 = st2; + st2 = c_im(input[2]); + tmp304 = st5; + st5 = st4 + st1; + st4 = st4 - st1; + st2 = st2 + c_im(input[10]); + st1 = st6 + st5; + st6 = st6 - st5; + st5 = st4 + st7; + st7 = st7 - st4; + st4 = c_im(input[6]); + st4 = st4 + c_im(input[14]); + tmp305 = st5; + st5 = c_re(input[6]); + tmp306 = st7; + st7 = st2 + st4; + st2 = st2 - st4; + st4 = st8 - st7; + st8 = st8 + st7; + st7 = st3 - st2; + st3 = st3 + st2; + st5 = st5 - c_re(input[14]); + st2 = c_im(input[2]); + st2 = st2 - c_im(input[10]); + tmp307 = st3; + st3 = c_re(input[2]); + tmp308 = st6; + st6 = st5 + st2; + st2 = st2 - st5; + st3 = st3 - c_re(input[10]); + st5 = c_im(input[6]); + st5 = st5 - c_im(input[14]); + tmp309 = st7; + st7 = c_re(input[5]); + tmp310 = st8; + st8 = st3 - st5; + st3 = st3 + st5; + st5 = st6 - st8; + st6 = st6 + st8; + st5 = st5 * K707106781[0]; + st8 = st2 + st3; + st6 = st6 * K707106781[0]; + st2 = st2 - st3; + st8 = st8 * K707106781[0]; + st7 = st7 - c_re(input[13]); + st2 = st2 * K707106781[0]; + st3 = tmp304 + st5; + tmp311 = st4; + st4 = tmp303 + st6; + st6 = tmp303 - st6; + st5 = tmp304 - st5; + tmp312 = st1; + st1 = tmp302 - st8; + st8 = tmp302 + st8; + tmp313 = st8; + st8 = tmp301 + st2; + st2 = tmp301 - st2; + tmp314 = st2; + st2 = c_im(input[1]); + st2 = st2 - c_im(input[9]); + tmp315 = st8; + st8 = c_re(input[1]); + tmp316 = st1; + st1 = st7 + st2; + st2 = st2 - st7; + st7 = st1 * K923879532[0]; + st8 = st8 - c_re(input[9]); + st1 = st1 * K382683432[0]; + tmp317 = st5; + st5 = c_im(input[5]); + tmp318 = st6; + st6 = st2 * K923879532[0]; + st5 = st5 - c_im(input[13]); + st2 = st2 * K382683432[0]; + tmp319 = st4; + st4 = st8 - st5; + st8 = st8 + st5; + st5 = st4 * K382683432[0]; + tmp320 = st3; + st3 = c_re(input[7]); + st4 = st4 * K923879532[0]; + st7 = st7 + st5; + st5 = st8 * K382683432[0]; + st1 = st1 - st4; + st8 = st8 * K923879532[0]; + st6 = st6 - st5; + st2 = st2 + st8; + st3 = st3 - c_re(input[15]); + st4 = c_im(input[3]); + st4 = st4 - c_im(input[11]); + st5 = c_re(input[3]); + st8 = st3 + st4; + st4 = st4 - st3; + st3 = st8 * K382683432[0]; + st5 = st5 - c_re(input[11]); + st8 = st8 * K923879532[0]; + tmp321 = st2; + st2 = c_im(input[7]); + tmp322 = st6; + st6 = st4 * K382683432[0]; + st2 = st2 - c_im(input[15]); + st4 = st4 * K923879532[0]; + tmp323 = st1; + st1 = st5 - st2; + st5 = st5 + st2; + st2 = st1 * K923879532[0]; + tmp324 = st7; + st7 = c_re(input[1]); + st1 = st1 * K382683432[0]; + st3 = st3 + st2; + st2 = st5 * K923879532[0]; + st1 = st1 - st8; + st5 = st5 * K382683432[0]; + st6 = st6 - st2; + st4 = st4 + st5; + st7 = st7 + c_re(input[9]); + st8 = tmp324 - st3; + st3 = tmp324 + st3; + st2 = tmp320 - st8; + st8 = tmp320 + st8; + st5 = tmp319 - st3; + st3 = tmp319 + st3; + tmp325 = st3; + st3 = tmp323 + st1; + st1 = tmp323 - st1; + tmp326 = st5; + st5 = tmp318 - st3; + st3 = tmp318 + st3; + tmp327 = st5; + st5 = tmp317 - st1; + st1 = tmp317 + st1; + tmp328 = st3; + st3 = tmp322 - st6; + tmp329 = st5; + st5 = tmp321 + st4; + tmp330 = st1; + st1 = tmp316 - st3; + st3 = tmp316 + st3; + tmp331 = st2; + st2 = tmp313 - st5; + st5 = tmp313 + st5; + st6 = tmp322 + st6; + c_re(input[9]) = st2; + c_re(input[1]) = st5; + st2 = tmp315 - st6; + st6 = tmp315 + st6; + st4 = tmp321 - st4; + st5 = c_re(input[5]); + c_re(input[5]) = st3; + st5 = st5 + c_re(input[13]); + c_re(input[13]) = st1; + st1 = st7 + st5; + st7 = st7 - st5; + st3 = tmp314 - st4; + st4 = tmp314 + st4; + st5 = c_im(input[1]); + c_im(input[1]) = st6; + st5 = st5 + c_im(input[9]); + c_im(input[9]) = st2; + st2 = c_im(input[5]); + c_im(input[5]) = st3; + st2 = st2 + c_im(input[13]); + c_im(input[13]) = st4; + st6 = st5 - st2; + st5 = st5 + st2; + st3 = c_re(input[3]); + c_re(input[3]) = st8; + st3 = st3 + c_re(input[11]); + c_re(input[11]) = tmp331; + st8 = c_re(input[7]); + c_re(input[7]) = tmp330; + st8 = st8 + c_re(input[15]); + c_re(input[15]) = tmp329; + st4 = st3 + st8; + st3 = st3 - st8; + st2 = st1 + st4; + st1 = st1 - st4; + st8 = st3 + st6; + st6 = st6 - st3; + st4 = tmp312 - st2; + st2 = tmp312 + st2; + st3 = tmp311 - st1; + c_re(input[8]) = st4; + c_re(input[0]) = st2; + c_im(input[4]) = st3; + st1 = st1 + tmp311; + st4 = c_im(input[3]); + c_im(input[3]) = tmp328; + c_im(input[12]) = st1; + st4 = st4 + c_im(input[11]); + c_im(input[11]) = tmp327; + st2 = c_im(input[7]); + c_im(input[7]) = tmp326; + st2 = st2 + c_im(input[15]); + c_im(input[15]) = tmp325; + st3 = st4 - st2; + st4 = st4 + st2; + st1 = st7 - st3; + st2 = st5 - st4; + tmp332 = st2; + st2 = st8 - st1; + st8 = st8 + st1; + st2 = st2 * K707106781[0]; + st5 = st5 + st4; + st8 = st8 * K707106781[0]; + st7 = st7 + st3; + st3 = tmp310 + st5; + st4 = st6 - st7; + st6 = st6 + st7; + c_im(input[0]) = st3; + st4 = st4 * K707106781[0]; + st5 = tmp310 - st5; + st6 = st6 * K707106781[0]; + st1 = tmp309 - st2; + c_im(input[8]) = st5; + c_re(input[14]) = st1; + st2 = tmp309 + st2; + st7 = tmp308 + tmp332; + st3 = tmp308 - tmp332; + c_re(input[6]) = st2; + c_re(input[4]) = st7; + c_re(input[12]) = st3; + st5 = tmp306 - st4; + st4 = tmp306 + st4; + st1 = tmp307 - st6; + c_im(input[10]) = st5; + c_im(input[2]) = st4; + c_re(input[10]) = st1; + st6 = tmp307 + st6; + st2 = tmp305 - st8; + st8 = tmp305 + st8; + c_re(input[2]) = st6; + c_im(input[6]) = st2; + c_im(input[14]) = st8; +} + +void PFFTW(32) (fftw_complex * input) { + fftw_real tmp714; + fftw_real tmp713; + fftw_real tmp712; + fftw_real tmp711; + fftw_real tmp710; + fftw_real tmp709; + fftw_real tmp708; + fftw_real tmp707; + fftw_real tmp706; + fftw_real tmp705; + fftw_real tmp704; + fftw_real tmp703; + fftw_real tmp702; + fftw_real tmp701; + fftw_real tmp700; + fftw_real tmp699; + fftw_real tmp698; + fftw_real tmp697; + fftw_real tmp696; + fftw_real tmp695; + fftw_real tmp694; + fftw_real tmp693; + fftw_real tmp692; + fftw_real tmp691; + fftw_real tmp690; + fftw_real tmp689; + fftw_real tmp688; + fftw_real tmp687; + fftw_real tmp686; + fftw_real tmp685; + fftw_real tmp684; + fftw_real tmp683; + fftw_real tmp682; + fftw_real tmp681; + fftw_real tmp680; + fftw_real tmp679; + fftw_real tmp678; + fftw_real tmp677; + fftw_real tmp676; + fftw_real tmp675; + fftw_real tmp674; + fftw_real tmp673; + fftw_real tmp672; + fftw_real tmp671; + fftw_real tmp670; + fftw_real tmp669; + fftw_real tmp668; + fftw_real tmp667; + fftw_real tmp666; + fftw_real tmp665; + fftw_real tmp664; + fftw_real tmp663; + fftw_real tmp662; + fftw_real tmp661; + fftw_real tmp660; + fftw_real tmp659; + fftw_real tmp658; + fftw_real tmp657; + fftw_real tmp656; + fftw_real tmp655; + fftw_real tmp654; + fftw_real tmp653; + fftw_real tmp652; + fftw_real tmp651; + fftw_real tmp650; + fftw_real tmp649; + fftw_real tmp648; + fftw_real tmp647; + fftw_real tmp646; + fftw_real tmp645; + fftw_real tmp644; + fftw_real tmp643; + fftw_real tmp642; + fftw_real tmp641; + fftw_real tmp640; + fftw_real tmp639; + fftw_real tmp638; + fftw_real tmp637; + fftw_real tmp636; + fftw_real tmp635; + fftw_real tmp634; + fftw_real tmp633; + fftw_real tmp632; + fftw_real tmp631; + fftw_real tmp630; + fftw_real tmp629; + fftw_real tmp628; + fftw_real tmp627; + fftw_real tmp626; + fftw_real tmp625; + fftw_real tmp624; + fftw_real tmp623; + fftw_real tmp622; + fftw_real tmp621; + fftw_real st1; + fftw_real st2; + fftw_real st3; + fftw_real st4; + fftw_real st5; + fftw_real st6; + fftw_real st7; + fftw_real st8; + st8 = c_re(input[0]); + st8 = st8 - c_re(input[16]); + st7 = c_im(input[8]); + st7 = st7 - c_im(input[24]); + st6 = st8 - st7; + st8 = st8 + st7; + st5 = c_re(input[0]); + st5 = st5 + c_re(input[16]); + st4 = c_re(input[8]); + st4 = st4 + c_re(input[24]); + st3 = st5 + st4; + st5 = st5 - st4; + st2 = c_im(input[0]); + st2 = st2 + c_im(input[16]); + st1 = c_im(input[8]); + st1 = st1 + c_im(input[24]); + st7 = st2 + st1; + st2 = st2 - st1; + st4 = c_re(input[4]); + st4 = st4 + c_re(input[20]); + st1 = c_re(input[28]); + st1 = st1 + c_re(input[12]); + tmp621 = st6; + st6 = st4 + st1; + st1 = st1 - st4; + st4 = st3 + st6; + st3 = st3 - st6; + st6 = st2 - st1; + st1 = st1 + st2; + st2 = c_im(input[4]); + st2 = st2 + c_im(input[20]); + tmp622 = st1; + st1 = c_im(input[28]); + st1 = st1 + c_im(input[12]); + tmp623 = st6; + st6 = st2 + st1; + st2 = st2 - st1; + st1 = st7 + st6; + st7 = st7 - st6; + st6 = st5 - st2; + st5 = st5 + st2; + st2 = c_re(input[8]); + st2 = st2 - c_re(input[24]); + tmp624 = st5; + st5 = c_im(input[0]); + st5 = st5 - c_im(input[16]); + tmp625 = st6; + st6 = st2 + st5; + st5 = st5 - st2; + st2 = c_im(input[4]); + st2 = st2 - c_im(input[20]); + tmp626 = st3; + st3 = c_re(input[4]); + st3 = st3 - c_re(input[20]); + tmp627 = st1; + st1 = st2 - st3; + st3 = st3 + st2; + st2 = c_re(input[28]); + st2 = st2 - c_re(input[12]); + tmp628 = st7; + st7 = c_im(input[28]); + st7 = st7 - c_im(input[12]); + tmp629 = st4; + st4 = st2 + st7; + st2 = st2 - st7; + st7 = st1 - st4; + st7 = st7 * K707106781[0]; + st1 = st1 + st4; + st1 = st1 * K707106781[0]; + st4 = st2 - st3; + st4 = st4 * K707106781[0]; + st3 = st3 + st2; + st3 = st3 * K707106781[0]; + st2 = st8 - st3; + tmp630 = st2; + st2 = st5 - st1; + tmp631 = st2; + st2 = tmp621 - st7; + tmp632 = st2; + st2 = st6 - st4; + st7 = tmp621 + st7; + st6 = st6 + st4; + st8 = st8 + st3; + st5 = st5 + st1; + st1 = c_re(input[2]); + st1 = st1 + c_re(input[18]); + st4 = c_re(input[10]); + st4 = st4 + c_re(input[26]); + st3 = st1 + st4; + st1 = st1 - st4; + st4 = c_im(input[2]); + st4 = st4 + c_im(input[18]); + tmp633 = st5; + st5 = c_im(input[10]); + st5 = st5 + c_im(input[26]); + tmp634 = st8; + st8 = st4 + st5; + st4 = st4 - st5; + st5 = st1 + st4; + st4 = st4 - st1; + st1 = c_re(input[30]); + st1 = st1 + c_re(input[14]); + tmp635 = st6; + st6 = c_re(input[6]); + st6 = st6 + c_re(input[22]); + tmp636 = st7; + st7 = st1 + st6; + st1 = st1 - st6; + st6 = st3 + st7; + st7 = st7 - st3; + st3 = tmp629 + st6; + st6 = tmp629 - st6; + tmp637 = st6; + st6 = st7 + tmp628; + st7 = tmp628 - st7; + tmp638 = st7; + st7 = c_im(input[30]); + st7 = st7 + c_im(input[14]); + tmp639 = st6; + st6 = c_im(input[6]); + st6 = st6 + c_im(input[22]); + tmp640 = st3; + st3 = st7 + st6; + st7 = st7 - st6; + st6 = st8 + st3; + st8 = st8 - st3; + st3 = st1 - st7; + tmp641 = st2; + st2 = st3 - st5; + st2 = st2 * K707106781[0]; + st5 = st5 + st3; + st5 = st5 * K707106781[0]; + st1 = st1 + st7; + st7 = st4 - st1; + st7 = st7 * K707106781[0]; + st4 = st4 + st1; + st4 = st4 * K707106781[0]; + st3 = tmp627 - st6; + st6 = tmp627 + st6; + st1 = tmp626 - st8; + st8 = tmp626 + st8; + tmp642 = st8; + st8 = tmp625 + st7; + st7 = tmp625 - st7; + tmp643 = st7; + st7 = tmp623 - st2; + st2 = tmp623 + st2; + tmp644 = st2; + st2 = tmp624 + st5; + st5 = tmp624 - st5; + tmp645 = st5; + st5 = tmp622 - st4; + st4 = tmp622 + st4; + tmp646 = st4; + st4 = c_re(input[6]); + st4 = st4 - c_re(input[22]); + tmp647 = st5; + st5 = c_im(input[30]); + st5 = st5 - c_im(input[14]); + tmp648 = st2; + st2 = st4 + st5; + tmp649 = st7; + st7 = st2 * K382683432[0]; + st5 = st5 - st4; + st2 = st2 * K923879532[0]; + st4 = c_re(input[30]); + tmp650 = st8; + st8 = st5 * K923879532[0]; + st4 = st4 - c_re(input[14]); + st5 = st5 * K382683432[0]; + tmp651 = st1; + st1 = c_im(input[6]); + st1 = st1 - c_im(input[22]); + tmp652 = st6; + st6 = st4 - st1; + tmp653 = st3; + st3 = st6 * K923879532[0]; + st4 = st4 + st1; + st6 = st6 * K382683432[0]; + st7 = st7 + st3; + st1 = st4 * K382683432[0]; + st6 = st6 - st2; + st4 = st4 * K923879532[0]; + st8 = st8 + st1; + st4 = st4 - st5; + st2 = c_re(input[10]); + st2 = st2 - c_re(input[26]); + st5 = c_im(input[2]); + st5 = st5 - c_im(input[18]); + st3 = st2 + st5; + st1 = st3 * K382683432[0]; + st5 = st5 - st2; + st3 = st3 * K923879532[0]; + st2 = c_re(input[2]); + tmp654 = st6; + st6 = st5 * K923879532[0]; + st2 = st2 - c_re(input[18]); + st5 = st5 * K382683432[0]; + tmp655 = st7; + st7 = c_im(input[10]); + st7 = st7 - c_im(input[26]); + tmp656 = st4; + st4 = st2 - st7; + tmp657 = st8; + st8 = st4 * K923879532[0]; + st2 = st2 + st7; + st4 = st4 * K382683432[0]; + st1 = st1 - st8; + st7 = st2 * K382683432[0]; + st3 = st3 + st4; + st2 = st2 * K923879532[0]; + st6 = st6 - st7; + st5 = st5 + st2; + st8 = st6 - tmp657; + st4 = tmp630 + st8; + st8 = tmp630 - st8; + st7 = tmp656 - st5; + st2 = tmp631 - st7; + st7 = tmp631 + st7; + tmp658 = st7; + st7 = st1 - tmp655; + tmp659 = st8; + st8 = tmp632 + st7; + st7 = tmp632 - st7; + tmp660 = st7; + st7 = tmp654 - st3; + tmp661 = st8; + st8 = tmp641 - st7; + st7 = tmp641 + st7; + st3 = st3 + tmp654; + tmp662 = st7; + st7 = tmp636 + st3; + st3 = tmp636 - st3; + st1 = st1 + tmp655; + tmp663 = st3; + st3 = tmp635 - st1; + st1 = tmp635 + st1; + st5 = st5 + tmp656; + tmp664 = st1; + st1 = tmp634 + st5; + st5 = tmp634 - st5; + st6 = st6 + tmp657; + tmp665 = st5; + st5 = tmp633 - st6; + st6 = tmp633 + st6; + tmp666 = st6; + st6 = c_re(input[1]); + st6 = st6 + c_re(input[17]); + tmp667 = st5; + st5 = c_re(input[9]); + st5 = st5 + c_re(input[25]); + tmp668 = st1; + st1 = st6 + st5; + st6 = st6 - st5; + st5 = c_im(input[1]); + st5 = st5 + c_im(input[17]); + tmp669 = st3; + st3 = c_im(input[9]); + st3 = st3 + c_im(input[25]); + tmp670 = st7; + st7 = st5 - st3; + st5 = st5 + st3; + st3 = c_re(input[5]); + st3 = st3 + c_re(input[21]); + tmp671 = st8; + st8 = c_re(input[29]); + st8 = st8 + c_re(input[13]); + tmp672 = st2; + st2 = st3 + st8; + st8 = st8 - st3; + st3 = st1 + st2; + st1 = st1 - st2; + st2 = st8 + st7; + tmp673 = st4; + st4 = st2 * K382683432[0]; + st7 = st7 - st8; + st2 = st2 * K923879532[0]; + st8 = c_im(input[5]); + tmp674 = st3; + st3 = st7 * K923879532[0]; + st8 = st8 + c_im(input[21]); + st7 = st7 * K382683432[0]; + tmp675 = st4; + st4 = c_im(input[29]); + st4 = st4 + c_im(input[13]); + tmp676 = st7; + st7 = st8 - st4; + st8 = st8 + st4; + st4 = st5 + st8; + st5 = st5 - st8; + st8 = st1 + st5; + st5 = st5 - st1; + st1 = st6 + st7; + tmp677 = st8; + st8 = st1 * K923879532[0]; + st6 = st6 - st7; + st1 = st1 * K382683432[0]; + st2 = st2 - st1; + st7 = st6 * K382683432[0]; + st3 = st3 + st7; + st6 = st6 * K923879532[0]; + st6 = tmp676 - st6; + st8 = tmp675 + st8; + st1 = c_re(input[31]); + st1 = st1 + c_re(input[15]); + st7 = c_re(input[7]); + st7 = st7 + c_re(input[23]); + tmp678 = st8; + st8 = st1 + st7; + st1 = st1 - st7; + st7 = c_im(input[31]); + st7 = st7 + c_im(input[15]); + tmp679 = st2; + st2 = c_im(input[7]); + st2 = st2 + c_im(input[23]); + tmp680 = st3; + st3 = st7 - st2; + st7 = st7 + st2; + st2 = c_re(input[3]); + st2 = st2 + c_re(input[19]); + tmp681 = st6; + st6 = c_re(input[27]); + st6 = st6 + c_re(input[11]); + tmp682 = st5; + st5 = st2 + st6; + st6 = st6 - st2; + st2 = st8 + st5; + st8 = st8 - st5; + st5 = st6 + st3; + tmp683 = st4; + st4 = st5 * K382683432[0]; + st3 = st3 - st6; + st5 = st5 * K923879532[0]; + st6 = tmp674 + st2; + tmp684 = st4; + st4 = st3 * K923879532[0]; + tmp685 = st5; + st5 = tmp640 - st6; + st3 = st3 * K382683432[0]; + st6 = tmp640 + st6; + st2 = st2 - tmp674; + c_re(input[16]) = st5; + st5 = st2 + tmp653; + st2 = tmp653 - st2; + c_re(input[0]) = st6; + st6 = c_im(input[3]); + st6 = st6 + c_im(input[19]); + c_im(input[8]) = st5; + st5 = c_im(input[27]); + st5 = st5 + c_im(input[11]); + c_im(input[24]) = st2; + st2 = st6 - st5; + st6 = st6 + st5; + st5 = st7 + st6; + st7 = st7 - st6; + st6 = st8 - st7; + st8 = st8 + st7; + st7 = st1 + st2; + tmp686 = st4; + st4 = st7 * K923879532[0]; + st1 = st1 - st2; + st7 = st7 * K382683432[0]; + st2 = tmp683 + st5; + tmp687 = st4; + st4 = st1 * K382683432[0]; + tmp688 = st7; + st7 = tmp652 - st2; + st1 = st1 * K923879532[0]; + st2 = tmp652 + st2; + st5 = tmp683 - st5; + c_im(input[16]) = st7; + st7 = tmp637 - st5; + st5 = tmp637 + st5; + c_im(input[0]) = st2; + st2 = tmp682 + st8; + st2 = st2 * K707106781[0]; + c_re(input[24]) = st7; + st7 = tmp639 - st2; + st2 = tmp639 + st2; + st8 = tmp682 - st8; + st8 = st8 * K707106781[0]; + c_re(input[8]) = st5; + st5 = tmp651 - st8; + st8 = tmp651 + st8; + c_im(input[20]) = st7; + st7 = tmp677 + st6; + st7 = st7 * K707106781[0]; + c_im(input[4]) = st2; + st2 = tmp642 - st7; + st7 = tmp642 + st7; + st6 = st6 - tmp677; + st6 = st6 * K707106781[0]; + c_re(input[28]) = st5; + st5 = tmp638 - st6; + st6 = tmp638 + st6; + st3 = st3 + st1; + st1 = tmp681 - st3; + st3 = tmp681 + st3; + st4 = st4 - tmp686; + c_re(input[12]) = st8; + st8 = tmp680 + st4; + st4 = st4 - tmp680; + c_re(input[20]) = st2; + st2 = tmp650 - st8; + st8 = tmp650 + st8; + c_re(input[4]) = st7; + st7 = tmp649 - st4; + st4 = tmp649 + st4; + c_im(input[28]) = st5; + st5 = tmp643 - st1; + st1 = tmp643 + st1; + c_im(input[12]) = st6; + st6 = tmp644 - st3; + st3 = tmp644 + st3; + c_re(input[22]) = st2; + st2 = tmp685 + tmp688; + c_re(input[6]) = st8; + st8 = tmp679 - st2; + st2 = tmp679 + st2; + c_im(input[30]) = st7; + st7 = tmp687 - tmp684; + c_im(input[14]) = st4; + st4 = tmp678 + st7; + st7 = st7 - tmp678; + c_re(input[30]) = st5; + st5 = tmp648 - st4; + st4 = tmp648 + st4; + c_re(input[14]) = st1; + st1 = tmp647 - st7; + st7 = tmp647 + st7; + c_im(input[22]) = st6; + st6 = tmp645 - st8; + st8 = tmp645 + st8; + c_im(input[6]) = st3; + st3 = tmp646 - st2; + st2 = tmp646 + st2; + c_re(input[18]) = st5; + st5 = c_re(input[31]); + st5 = st5 - c_re(input[15]); + c_re(input[2]) = st4; + st4 = c_im(input[7]); + st4 = st4 - c_im(input[23]); + c_im(input[26]) = st1; + st1 = st5 - st4; + st5 = st5 + st4; + c_im(input[10]) = st7; + st7 = c_re(input[7]); + st7 = st7 - c_re(input[23]); + c_re(input[26]) = st6; + st6 = c_im(input[31]); + st6 = st6 - c_im(input[15]); + c_re(input[10]) = st8; + st8 = st7 + st6; + st6 = st6 - st7; + c_im(input[18]) = st3; + st3 = c_im(input[3]); + st3 = st3 - c_im(input[19]); + c_im(input[2]) = st2; + st2 = c_re(input[3]); + st2 = st2 - c_re(input[19]); + st4 = st3 - st2; + st2 = st2 + st3; + st7 = c_re(input[27]); + st7 = st7 - c_re(input[11]); + st3 = c_im(input[27]); + st3 = st3 - c_im(input[11]); + tmp689 = st5; + st5 = st7 + st3; + st7 = st7 - st3; + st3 = st4 - st5; + st3 = st3 * K707106781[0]; + st4 = st4 + st5; + st4 = st4 * K707106781[0]; + st5 = st7 - st2; + st5 = st5 * K707106781[0]; + st2 = st2 + st7; + st2 = st2 * K707106781[0]; + st7 = st1 - st3; + tmp690 = st2; + st2 = st7 * K980785280[0]; + st1 = st1 + st3; + st7 = st7 * K195090322[0]; + st3 = st6 - st4; + tmp691 = st7; + st7 = st3 * K555570233[0]; + st6 = st6 + st4; + st3 = st3 * K831469612[0]; + st4 = st8 - st5; + tmp692 = st6; + st6 = st4 * K195090322[0]; + st8 = st8 + st5; + st4 = st4 * K980785280[0]; + st5 = tmp689 - tmp690; + tmp693 = st4; + st4 = st5 * K831469612[0]; + tmp694 = st2; + st2 = tmp689 + tmp690; + st5 = st5 * K555570233[0]; + st4 = st4 + st7; + st7 = st8 * K831469612[0]; + st5 = st5 - st3; + st3 = st1 * K555570233[0]; + st6 = st6 + tmp694; + st1 = st1 * K831469612[0]; + tmp695 = st6; + st6 = tmp691 - tmp693; + st8 = st8 * K555570233[0]; + st7 = st7 + st3; + st3 = st2 * K195090322[0]; + st1 = st1 - st8; + st8 = tmp692 * K980785280[0]; + st3 = st3 + st8; + st2 = st2 * K980785280[0]; + st8 = c_re(input[9]); + tmp696 = st3; + st3 = tmp692 * K195090322[0]; + st8 = st8 - c_re(input[25]); + st2 = st2 - st3; + st3 = c_im(input[1]); + st3 = st3 - c_im(input[17]); + tmp697 = st2; + st2 = st8 + st3; + st3 = st3 - st8; + st8 = c_re(input[1]); + st8 = st8 - c_re(input[17]); + tmp698 = st1; + st1 = c_im(input[9]); + st1 = st1 - c_im(input[25]); + tmp699 = st7; + st7 = st8 - st1; + st8 = st8 + st1; + st1 = c_re(input[29]); + st1 = st1 - c_re(input[13]); + tmp700 = st6; + st6 = c_im(input[29]); + st6 = st6 - c_im(input[13]); + tmp701 = st5; + st5 = st1 - st6; + st1 = st1 + st6; + st6 = c_re(input[5]); + st6 = st6 - c_re(input[21]); + tmp702 = st4; + st4 = c_im(input[5]); + st4 = st4 - c_im(input[21]); + tmp703 = st8; + st8 = st6 + st4; + st4 = st4 - st6; + st6 = st5 - st8; + st6 = st6 * K707106781[0]; + st8 = st8 + st5; + st8 = st8 * K707106781[0]; + st5 = st4 - st1; + st5 = st5 * K707106781[0]; + st4 = st4 + st1; + st4 = st4 * K707106781[0]; + st1 = st2 - st6; + tmp704 = st8; + st8 = st1 * K195090322[0]; + st2 = st2 + st6; + st1 = st1 * K980785280[0]; + st6 = st3 - st4; + tmp705 = st1; + st1 = st6 * K555570233[0]; + st3 = st3 + st4; + st6 = st6 * K831469612[0]; + st4 = st7 - st5; + tmp706 = st8; + st8 = st4 * K980785280[0]; + st7 = st7 + st5; + st4 = st4 * K195090322[0]; + st5 = tmp703 - tmp704; + tmp707 = st4; + st4 = st5 * K831469612[0]; + tmp708 = st8; + st8 = tmp703 + tmp704; + st5 = st5 * K555570233[0]; + st1 = st1 - st4; + st4 = st2 * K831469612[0]; + tmp709 = st4; + st4 = st1 - tmp702; + tmp710 = st4; + st4 = st7 * K555570233[0]; + st1 = st1 + tmp702; + st2 = st2 * K555570233[0]; + st5 = st5 + st6; + st7 = st7 * K831469612[0]; + st6 = st5 + tmp701; + tmp711 = st2; + st2 = st3 * K980785280[0]; + st5 = tmp701 - st5; + tmp712 = st2; + st2 = st8 * K195090322[0]; + tmp713 = st2; + st2 = tmp673 - st6; + st8 = st8 * K980785280[0]; + st3 = st3 * K195090322[0]; + st6 = tmp673 + st6; + c_re(input[21]) = st2; + st2 = tmp672 - st5; + st5 = tmp672 + st5; + c_re(input[5]) = st6; + st6 = tmp659 - tmp710; + c_im(input[29]) = st2; + st2 = tmp659 + tmp710; + c_im(input[13]) = st5; + st5 = tmp658 - st1; + st1 = tmp658 + st1; + c_re(input[29]) = st6; + st6 = tmp706 - tmp708; + c_re(input[13]) = st2; + st2 = st6 - tmp695; + st6 = st6 + tmp695; + c_im(input[21]) = st5; + st5 = tmp705 + tmp707; + c_im(input[5]) = st1; + st1 = st5 + tmp700; + st5 = tmp700 - st5; + tmp714 = st8; + st8 = tmp661 - st1; + st1 = tmp661 + st1; + c_re(input[23]) = st8; + st8 = tmp671 - st5; + st5 = tmp671 + st5; + c_re(input[7]) = st1; + st1 = tmp660 - st2; + st2 = tmp660 + st2; + c_im(input[31]) = st8; + st8 = tmp662 - st6; + st6 = tmp662 + st6; + st4 = tmp709 - st4; + c_im(input[15]) = st5; + st5 = st4 - tmp699; + st4 = st4 + tmp699; + st7 = tmp711 + st7; + c_re(input[31]) = st1; + st1 = st7 + tmp698; + st7 = tmp698 - st7; + c_re(input[15]) = st2; + st2 = tmp670 - st1; + st1 = tmp670 + st1; + c_im(input[23]) = st8; + st8 = tmp669 - st7; + st7 = tmp669 + st7; + c_im(input[7]) = st6; + st6 = tmp663 - st5; + st5 = tmp663 + st5; + c_re(input[19]) = st2; + st2 = tmp664 - st4; + st4 = tmp664 + st4; + c_re(input[3]) = st1; + st1 = tmp712 - tmp713; + c_im(input[27]) = st8; + st8 = st1 - tmp696; + st1 = st1 + tmp696; + st3 = tmp714 + st3; + c_im(input[11]) = st7; + st7 = st3 + tmp697; + st3 = tmp697 - st3; + c_re(input[27]) = st6; + st6 = tmp668 - st7; + st7 = tmp668 + st7; + c_re(input[11]) = st5; + st5 = tmp667 - st3; + st3 = tmp667 + st3; + c_im(input[19]) = st2; + st2 = tmp665 - st8; + st8 = tmp665 + st8; + c_im(input[3]) = st4; + st4 = tmp666 - st1; + st1 = tmp666 + st1; + c_re(input[17]) = st6; + c_re(input[1]) = st7; + c_im(input[25]) = st5; + c_im(input[9]) = st3; + c_re(input[25]) = st2; + c_re(input[9]) = st8; + c_im(input[17]) = st4; + c_im(input[1]) = st1; +} + +void PFFTW(64)(fftw_complex *input) +{ + PFFTW(twiddle_4)(input, PFFTW(W_64), 16); + PFFTW(16)(input ); + PFFTW(16)(input + 16); + PFFTW(16)(input + 32); + PFFTW(16)(input + 48); +} + +void PFFTW(128)(fftw_complex *input) +{ + PFFTW(twiddle_4)(input, PFFTW(W_128), 32); + PFFTW(32)(input ); + PFFTW(32)(input + 32); + PFFTW(32)(input + 64); + PFFTW(32)(input + 96); +} + +void PFFTW(512)(fftw_complex *input) +{ + PFFTW(twiddle_4)(input, PFFTW(W_512), 128); + PFFTW(128)(input ); + PFFTW(128)(input + 128); + PFFTW(128)(input + 256); + PFFTW(128)(input + 384); +} +/////////////////////////////////////////////////////////////// +void PFFTWI(16) (fftw_complex * input) { + fftw_real tmp333; + fftw_real tmp332; + fftw_real tmp331; + fftw_real tmp330; + fftw_real tmp329; + fftw_real tmp328; + fftw_real tmp327; + fftw_real tmp326; + fftw_real tmp325; + fftw_real tmp324; + fftw_real tmp323; + fftw_real tmp322; + fftw_real tmp321; + fftw_real tmp320; + fftw_real tmp319; + fftw_real tmp318; + fftw_real tmp317; + fftw_real tmp316; + fftw_real tmp315; + fftw_real tmp314; + fftw_real tmp313; + fftw_real tmp312; + fftw_real tmp311; + fftw_real tmp310; + fftw_real tmp309; + fftw_real tmp308; + fftw_real tmp307; + fftw_real tmp306; + fftw_real tmp305; + fftw_real tmp304; + fftw_real tmp303; + fftw_real tmp302; + fftw_real tmp301; + fftw_real st1; + fftw_real st2; + fftw_real st3; + fftw_real st4; + fftw_real st5; + fftw_real st6; + fftw_real st7; + fftw_real st8; + st8 = c_re(input[4]); + st8 = st8 - c_re(input[12]); + st7 = c_im(input[0]); + st7 = st7 - c_im(input[8]); + st6 = c_re(input[0]); + st6 = st6 - c_re(input[8]); + st5 = st8 + st7; + st7 = st7 - st8; + st4 = c_im(input[4]); + st4 = st4 - c_im(input[12]); + st3 = c_re(input[0]); + st3 = st3 + c_re(input[8]); + st2 = st6 - st4; + st6 = st6 + st4; + st1 = c_re(input[4]); + st1 = st1 + c_re(input[12]); + st8 = c_im(input[0]); + st8 = st8 + c_im(input[8]); + st4 = st3 + st1; + st3 = st3 - st1; + st1 = c_im(input[4]); + st1 = st1 + c_im(input[12]); + tmp301 = st6; + st6 = c_re(input[2]); + st6 = st6 + c_re(input[10]); + tmp302 = st7; + st7 = st8 + st1; + st8 = st8 - st1; + st1 = c_re(input[6]); + st1 = st1 + c_re(input[14]); + tmp303 = st2; + st2 = c_im(input[2]); + st2 = st2 + c_im(input[10]); + tmp304 = st5; + st5 = st6 + st1; + st6 = st6 - st1; + st1 = c_im(input[6]); + st1 = st1 + c_im(input[14]); + tmp305 = st3; + st3 = st4 + st5; + st4 = st4 - st5; + st5 = st2 + st1; + st2 = st2 - st1; + st1 = st6 + st8; + tmp306 = st1; + st1 = st7 - st5; + st7 = st7 + st5; + st5 = tmp305 - st2; + st2 = tmp305 + st2; + st8 = st8 - st6; + st6 = c_re(input[6]); + st6 = st6 - c_re(input[14]); + tmp307 = st8; + st8 = c_im(input[2]); + st8 = st8 - c_im(input[10]); + tmp308 = st2; + st2 = c_re(input[2]); + st2 = st2 - c_re(input[10]); + tmp309 = st4; + st4 = st6 + st8; + st8 = st8 - st6; + st6 = c_im(input[6]); + st6 = st6 - c_im(input[14]); + tmp310 = st5; + st5 = c_re(input[1]); + st5 = st5 - c_re(input[9]); + tmp311 = st7; + st7 = st2 - st6; + st2 = st2 + st6; + st6 = c_im(input[5]); + tmp312 = st1; + st1 = st4 + st7; + st7 = st7 - st4; + st4 = st2 - st8; + st1 = st1 * K707106781[0]; + st8 = st8 + st2; + st7 = st7 * K707106781[0]; + st6 = st6 - c_im(input[13]); + st4 = st4 * K707106781[0]; + st2 = tmp304 - st1; + st8 = st8 * K707106781[0]; + tmp313 = st3; + st3 = st5 - st6; + st5 = st5 + st6; + st6 = tmp303 + st7; + tmp314 = st6; + st6 = st3 * K923879532[0]; + st7 = tmp303 - st7; + st3 = st3 * K382683432[0]; + st1 = tmp304 + st1; + tmp315 = st1; + st1 = st5 * K382683432[0]; + tmp316 = st7; + st7 = tmp302 - st4; + st5 = st5 * K923879532[0]; + st4 = tmp302 + st4; + tmp317 = st4; + st4 = tmp301 - st8; + st8 = tmp301 + st8; + tmp318 = st8; + st8 = c_re(input[5]); + st8 = st8 - c_re(input[13]); + tmp319 = st4; + st4 = c_im(input[1]); + st4 = st4 - c_im(input[9]); + tmp320 = st7; + st7 = c_re(input[3]); + st7 = st7 - c_re(input[11]); + tmp321 = st2; + st2 = st8 + st4; + st4 = st4 - st8; + st8 = c_im(input[7]); + tmp322 = st5; + st5 = st2 * K382683432[0]; + st8 = st8 - c_im(input[15]); + st2 = st2 * K923879532[0]; + st6 = st6 - st5; + st5 = st4 * K923879532[0]; + st2 = st2 + st3; + st4 = st4 * K382683432[0]; + st1 = st1 - st5; + st3 = st7 - st8; + st4 = st4 + tmp322; + st7 = st7 + st8; + st8 = st3 * K382683432[0]; + st5 = c_re(input[7]); + st3 = st3 * K923879532[0]; + st5 = st5 - c_re(input[15]); + tmp323 = st4; + st4 = st7 * K923879532[0]; + tmp324 = st1; + st1 = c_im(input[3]); + st7 = st7 * K382683432[0]; + st1 = st1 - c_im(input[11]); + tmp325 = st2; + st2 = c_re(input[1]); + st2 = st2 + c_re(input[9]); + tmp326 = st6; + st6 = st5 + st1; + st1 = st1 - st5; + st5 = c_re(input[5]); + tmp327 = st7; + st7 = st6 * K923879532[0]; + st5 = st5 + c_re(input[13]); + st6 = st6 * K382683432[0]; + st8 = st8 - st7; + st7 = st1 * K382683432[0]; + st6 = st6 + st3; + st1 = st1 * K923879532[0]; + st7 = st7 - st4; + st3 = st2 + st5; + st1 = st1 + tmp327; + st2 = st2 - st5; + st4 = tmp326 - st8; + st8 = tmp326 + st8; + st5 = tmp325 - st6; + tmp328 = st2; + st2 = tmp321 - st4; + st4 = tmp321 + st4; + tmp329 = st3; + st3 = tmp314 - st8; + st8 = tmp314 + st8; + tmp330 = st2; + st2 = tmp316 - st5; + st5 = tmp316 + st5; + c_re(input[9]) = st3; + c_re(input[1]) = st8; + c_re(input[5]) = st2; + c_re(input[13]) = st5; + st6 = tmp325 + st6; + st3 = tmp324 - st7; + st8 = tmp323 - st1; + st2 = tmp315 - st6; + st6 = tmp315 + st6; + st5 = tmp320 - st3; + st3 = tmp320 + st3; + tmp331 = st5; + st5 = tmp317 - st8; + st8 = tmp317 + st8; + st7 = tmp324 + st7; + st1 = tmp323 + st1; + tmp332 = st3; + st3 = c_im(input[1]); + c_im(input[1]) = st6; + st3 = st3 + c_im(input[9]); + c_im(input[9]) = st2; + st2 = tmp319 - st7; + st7 = tmp319 + st7; + st6 = tmp318 - st1; + st1 = tmp318 + st1; + tmp333 = st5; + st5 = c_im(input[5]); + c_im(input[5]) = st4; + st5 = st5 + c_im(input[13]); + c_im(input[13]) = tmp330; + st4 = st3 - st5; + st3 = st3 + st5; + st5 = c_re(input[3]); + c_re(input[3]) = st7; + st5 = st5 + c_re(input[11]); + c_re(input[11]) = st2; + st2 = c_re(input[7]); + c_re(input[7]) = st6; + st2 = st2 + c_re(input[15]); + c_re(input[15]) = st1; + st7 = st5 + st2; + st5 = st5 - st2; + st6 = c_im(input[3]); + c_im(input[3]) = st8; + st6 = st6 + c_im(input[11]); + c_im(input[11]) = tmp333; + st8 = tmp329 + st7; + st7 = tmp329 - st7; + st1 = st5 + st4; + st4 = st4 - st5; + st2 = tmp313 - st8; + st8 = tmp313 + st8; + st5 = st7 + tmp312; + st7 = tmp312 - st7; + c_re(input[8]) = st2; + c_re(input[0]) = st8; + c_im(input[4]) = st5; + c_im(input[12]) = st7; + st2 = c_im(input[7]); + c_im(input[7]) = tmp332; + st2 = st2 + c_im(input[15]); + c_im(input[15]) = tmp331; + st8 = st6 - st2; + st6 = st6 + st2; + st5 = tmp328 - st8; + st8 = tmp328 + st8; + st7 = st3 - st6; + st2 = st5 - st1; + st1 = st1 + st5; + st3 = st3 + st6; + st2 = st2 * K707106781[0]; + st6 = st4 + st8; + st1 = st1 * K707106781[0]; + st8 = st8 - st4; + st6 = st6 * K707106781[0]; + st4 = tmp311 + st3; + st8 = st8 * K707106781[0]; + st3 = tmp311 - st3; + st5 = tmp310 - st2; + c_im(input[0]) = st4; + c_im(input[8]) = st3; + c_re(input[10]) = st5; + st2 = tmp310 + st2; + st4 = tmp309 + st7; + st7 = tmp309 - st7; + st3 = tmp308 - st6; + c_re(input[2]) = st2; + c_re(input[12]) = st4; + c_re(input[4]) = st7; + c_re(input[6]) = st3; + st6 = tmp308 + st6; + st5 = tmp307 - st8; + st8 = tmp307 + st8; + st2 = tmp306 - st1; + c_re(input[14]) = st6; + c_im(input[14]) = st5; + c_im(input[6]) = st8; + c_im(input[10]) = st2; + st1 = tmp306 + st1; + c_im(input[2]) = st1; +} + +void PFFTWI(32) (fftw_complex * input) { + fftw_real tmp714; + fftw_real tmp713; + fftw_real tmp712; + fftw_real tmp711; + fftw_real tmp710; + fftw_real tmp709; + fftw_real tmp708; + fftw_real tmp707; + fftw_real tmp706; + fftw_real tmp705; + fftw_real tmp704; + fftw_real tmp703; + fftw_real tmp702; + fftw_real tmp701; + fftw_real tmp700; + fftw_real tmp699; + fftw_real tmp698; + fftw_real tmp697; + fftw_real tmp696; + fftw_real tmp695; + fftw_real tmp694; + fftw_real tmp693; + fftw_real tmp692; + fftw_real tmp691; + fftw_real tmp690; + fftw_real tmp689; + fftw_real tmp688; + fftw_real tmp687; + fftw_real tmp686; + fftw_real tmp685; + fftw_real tmp684; + fftw_real tmp683; + fftw_real tmp682; + fftw_real tmp681; + fftw_real tmp680; + fftw_real tmp679; + fftw_real tmp678; + fftw_real tmp677; + fftw_real tmp676; + fftw_real tmp675; + fftw_real tmp674; + fftw_real tmp673; + fftw_real tmp672; + fftw_real tmp671; + fftw_real tmp670; + fftw_real tmp669; + fftw_real tmp668; + fftw_real tmp667; + fftw_real tmp666; + fftw_real tmp665; + fftw_real tmp664; + fftw_real tmp663; + fftw_real tmp662; + fftw_real tmp661; + fftw_real tmp660; + fftw_real tmp659; + fftw_real tmp658; + fftw_real tmp657; + fftw_real tmp656; + fftw_real tmp655; + fftw_real tmp654; + fftw_real tmp653; + fftw_real tmp652; + fftw_real tmp651; + fftw_real tmp650; + fftw_real tmp649; + fftw_real tmp648; + fftw_real tmp647; + fftw_real tmp646; + fftw_real tmp645; + fftw_real tmp644; + fftw_real tmp643; + fftw_real tmp642; + fftw_real tmp641; + fftw_real tmp640; + fftw_real tmp639; + fftw_real tmp638; + fftw_real tmp637; + fftw_real tmp636; + fftw_real tmp635; + fftw_real tmp634; + fftw_real tmp633; + fftw_real tmp632; + fftw_real tmp631; + fftw_real tmp630; + fftw_real tmp629; + fftw_real tmp628; + fftw_real tmp627; + fftw_real tmp626; + fftw_real tmp625; + fftw_real tmp624; + fftw_real tmp623; + fftw_real tmp622; + fftw_real tmp621; + fftw_real st1; + fftw_real st2; + fftw_real st3; + fftw_real st4; + fftw_real st5; + fftw_real st6; + fftw_real st7; + fftw_real st8; + st8 = c_re(input[8]); + st8 = st8 - c_re(input[24]); + st7 = c_im(input[0]); + st7 = st7 - c_im(input[16]); + st6 = st8 + st7; + st7 = st7 - st8; + st5 = c_re(input[0]); + st5 = st5 + c_re(input[16]); + st4 = c_re(input[8]); + st4 = st4 + c_re(input[24]); + st3 = st5 + st4; + st5 = st5 - st4; + st2 = c_im(input[0]); + st2 = st2 + c_im(input[16]); + st1 = c_im(input[8]); + st1 = st1 + c_im(input[24]); + st8 = st2 + st1; + st2 = st2 - st1; + st4 = c_re(input[4]); + st4 = st4 + c_re(input[20]); + st1 = c_re(input[28]); + st1 = st1 + c_re(input[12]); + tmp621 = st6; + st6 = st4 + st1; + st4 = st4 - st1; + st1 = st3 + st6; + st3 = st3 - st6; + st6 = st2 - st4; + st4 = st4 + st2; + st2 = c_im(input[4]); + st2 = st2 + c_im(input[20]); + tmp622 = st4; + st4 = c_im(input[28]); + st4 = st4 + c_im(input[12]); + tmp623 = st6; + st6 = st2 + st4; + st4 = st4 - st2; + st2 = st8 + st6; + st8 = st8 - st6; + st6 = st5 - st4; + st5 = st5 + st4; + st4 = c_re(input[0]); + st4 = st4 - c_re(input[16]); + tmp624 = st5; + st5 = c_im(input[8]); + st5 = st5 - c_im(input[24]); + tmp625 = st6; + st6 = st4 - st5; + st4 = st4 + st5; + st5 = c_re(input[4]); + st5 = st5 - c_re(input[20]); + tmp626 = st3; + st3 = c_im(input[4]); + st3 = st3 - c_im(input[20]); + tmp627 = st2; + st2 = st5 + st3; + st5 = st5 - st3; + st3 = c_im(input[28]); + st3 = st3 - c_im(input[12]); + tmp628 = st8; + st8 = c_re(input[28]); + st8 = st8 - c_re(input[12]); + tmp629 = st1; + st1 = st3 - st8; + st8 = st8 + st3; + st3 = st2 + st1; + st3 = st3 * K707106781[0]; + st1 = st1 - st2; + st1 = st1 * K707106781[0]; + st2 = st5 + st8; + st2 = st2 * K707106781[0]; + st5 = st5 - st8; + st5 = st5 * K707106781[0]; + st8 = st7 - st5; + tmp630 = st8; + st8 = st4 - st1; + tmp631 = st8; + st8 = tmp621 - st3; + tmp632 = st8; + st8 = st6 - st2; + st3 = tmp621 + st3; + st6 = st6 + st2; + st7 = st7 + st5; + st4 = st4 + st1; + st1 = c_re(input[2]); + st1 = st1 + c_re(input[18]); + st2 = c_re(input[10]); + st2 = st2 + c_re(input[26]); + st5 = st1 + st2; + st1 = st1 - st2; + st2 = c_im(input[2]); + st2 = st2 + c_im(input[18]); + tmp633 = st4; + st4 = c_im(input[10]); + st4 = st4 + c_im(input[26]); + tmp634 = st7; + st7 = st2 + st4; + st2 = st2 - st4; + st4 = st1 + st2; + st1 = st1 - st2; + st2 = c_re(input[30]); + st2 = st2 + c_re(input[14]); + tmp635 = st6; + st6 = c_re(input[6]); + st6 = st6 + c_re(input[22]); + tmp636 = st3; + st3 = st2 + st6; + st2 = st2 - st6; + st6 = st5 + st3; + st5 = st5 - st3; + st3 = tmp629 + st6; + st6 = tmp629 - st6; + tmp637 = st6; + st6 = tmp628 - st5; + st5 = st5 + tmp628; + tmp638 = st5; + st5 = c_im(input[30]); + st5 = st5 + c_im(input[14]); + tmp639 = st6; + st6 = c_im(input[6]); + st6 = st6 + c_im(input[22]); + tmp640 = st3; + st3 = st5 + st6; + st5 = st5 - st6; + st6 = st7 + st3; + st3 = st3 - st7; + st7 = st5 - st2; + tmp641 = st8; + st8 = st7 - st4; + st8 = st8 * K707106781[0]; + st4 = st4 + st7; + st4 = st4 * K707106781[0]; + st2 = st2 + st5; + st5 = st1 - st2; + st5 = st5 * K707106781[0]; + st1 = st1 + st2; + st1 = st1 * K707106781[0]; + st7 = tmp627 - st6; + st6 = tmp627 + st6; + st2 = tmp626 + st3; + st3 = tmp626 - st3; + tmp642 = st3; + st3 = tmp623 + st5; + st5 = tmp623 - st5; + tmp643 = st5; + st5 = tmp625 - st8; + st8 = tmp625 + st8; + tmp644 = st8; + st8 = tmp622 + st4; + st4 = tmp622 - st4; + tmp645 = st4; + st4 = tmp624 - st1; + st1 = tmp624 + st1; + tmp646 = st1; + st1 = c_re(input[6]); + st1 = st1 - c_re(input[22]); + tmp647 = st4; + st4 = c_im(input[30]); + st4 = st4 - c_im(input[14]); + tmp648 = st8; + st8 = st1 + st4; + tmp649 = st5; + st5 = st8 * K382683432[0]; + st4 = st4 - st1; + st8 = st8 * K923879532[0]; + st1 = c_re(input[30]); + tmp650 = st3; + st3 = st4 * K923879532[0]; + st1 = st1 - c_re(input[14]); + st4 = st4 * K382683432[0]; + tmp651 = st2; + st2 = c_im(input[6]); + st2 = st2 - c_im(input[22]); + tmp652 = st6; + st6 = st1 - st2; + tmp653 = st7; + st7 = st6 * K923879532[0]; + st1 = st1 + st2; + st6 = st6 * K382683432[0]; + st5 = st5 + st7; + st2 = st1 * K382683432[0]; + st8 = st8 - st6; + st1 = st1 * K923879532[0]; + st3 = st3 + st2; + st4 = st4 - st1; + st7 = c_re(input[2]); + st7 = st7 - c_re(input[18]); + st6 = c_im(input[10]); + st6 = st6 - c_im(input[26]); + st2 = st7 - st6; + st1 = st2 * K923879532[0]; + st7 = st7 + st6; + st2 = st2 * K382683432[0]; + st6 = c_re(input[10]); + tmp654 = st8; + st8 = st7 * K382683432[0]; + st6 = st6 - c_re(input[26]); + st7 = st7 * K923879532[0]; + tmp655 = st5; + st5 = c_im(input[2]); + st5 = st5 - c_im(input[18]); + tmp656 = st4; + st4 = st6 + st5; + tmp657 = st3; + st3 = st4 * K382683432[0]; + st5 = st5 - st6; + st4 = st4 * K923879532[0]; + st1 = st1 - st3; + st6 = st5 * K923879532[0]; + st4 = st4 + st2; + st5 = st5 * K382683432[0]; + st8 = st8 - st6; + st5 = st5 + st7; + st2 = st8 - tmp657; + st7 = tmp630 + st2; + st2 = tmp630 - st2; + st3 = tmp656 - st5; + st6 = tmp631 - st3; + st3 = tmp631 + st3; + tmp658 = st3; + st3 = st1 - tmp655; + tmp659 = st2; + st2 = tmp632 - st3; + st3 = tmp632 + st3; + tmp660 = st3; + st3 = tmp654 - st4; + tmp661 = st2; + st2 = tmp641 + st3; + st3 = tmp641 - st3; + st4 = st4 + tmp654; + tmp662 = st3; + st3 = tmp636 - st4; + st4 = tmp636 + st4; + st1 = st1 + tmp655; + tmp663 = st4; + st4 = tmp635 + st1; + st1 = tmp635 - st1; + st5 = st5 + tmp656; + tmp664 = st1; + st1 = tmp634 + st5; + st5 = tmp634 - st5; + st8 = st8 + tmp657; + tmp665 = st5; + st5 = tmp633 - st8; + st8 = tmp633 + st8; + tmp666 = st8; + st8 = c_re(input[1]); + st8 = st8 + c_re(input[17]); + tmp667 = st5; + st5 = c_re(input[9]); + st5 = st5 + c_re(input[25]); + tmp668 = st1; + st1 = st8 + st5; + st8 = st8 - st5; + st5 = c_im(input[1]); + st5 = st5 + c_im(input[17]); + tmp669 = st4; + st4 = c_im(input[9]); + st4 = st4 + c_im(input[25]); + tmp670 = st3; + st3 = st5 + st4; + st5 = st5 - st4; + st4 = c_re(input[5]); + st4 = st4 + c_re(input[21]); + tmp671 = st2; + st2 = c_re(input[29]); + st2 = st2 + c_re(input[13]); + tmp672 = st6; + st6 = st4 + st2; + st4 = st4 - st2; + st2 = st1 + st6; + st1 = st1 - st6; + st6 = st4 + st5; + tmp673 = st7; + st7 = st6 * K923879532[0]; + st5 = st5 - st4; + st6 = st6 * K382683432[0]; + st4 = c_im(input[5]); + tmp674 = st2; + st2 = st5 * K382683432[0]; + st4 = st4 + c_im(input[21]); + st5 = st5 * K923879532[0]; + tmp675 = st7; + st7 = c_im(input[29]); + st7 = st7 + c_im(input[13]); + tmp676 = st5; + st5 = st4 + st7; + st7 = st7 - st4; + st4 = st3 + st5; + st3 = st3 - st5; + st5 = st1 - st3; + st1 = st1 + st3; + st3 = st8 + st7; + tmp677 = st1; + st1 = st3 * K382683432[0]; + st8 = st8 - st7; + st3 = st3 * K923879532[0]; + st3 = st3 - st6; + st6 = st8 * K923879532[0]; + st2 = st2 + st6; + st8 = st8 * K382683432[0]; + st8 = st8 - tmp676; + st1 = tmp675 + st1; + st7 = c_re(input[31]); + st7 = st7 + c_re(input[15]); + st6 = c_re(input[7]); + st6 = st6 + c_re(input[23]); + tmp678 = st1; + st1 = st7 + st6; + st7 = st7 - st6; + st6 = c_im(input[31]); + st6 = st6 + c_im(input[15]); + tmp679 = st3; + st3 = c_im(input[7]); + st3 = st3 + c_im(input[23]); + tmp680 = st2; + st2 = st6 + st3; + st6 = st6 - st3; + st3 = c_re(input[3]); + st3 = st3 + c_re(input[19]); + tmp681 = st8; + st8 = c_re(input[27]); + st8 = st8 + c_re(input[11]); + tmp682 = st5; + st5 = st3 + st8; + st3 = st3 - st8; + st8 = st1 + st5; + st1 = st1 - st5; + st5 = st3 + st6; + tmp683 = st4; + st4 = st5 * K923879532[0]; + st6 = st6 - st3; + st5 = st5 * K382683432[0]; + st3 = tmp674 + st8; + tmp684 = st4; + st4 = st6 * K382683432[0]; + tmp685 = st5; + st5 = tmp640 - st3; + st6 = st6 * K923879532[0]; + st3 = tmp640 + st3; + st8 = tmp674 - st8; + c_re(input[16]) = st5; + st5 = st8 + tmp653; + st8 = tmp653 - st8; + c_re(input[0]) = st3; + st3 = c_im(input[3]); + st3 = st3 + c_im(input[19]); + c_im(input[8]) = st5; + st5 = c_im(input[27]); + st5 = st5 + c_im(input[11]); + c_im(input[24]) = st8; + st8 = st3 + st5; + st5 = st5 - st3; + st3 = st2 + st8; + st2 = st2 - st8; + st8 = st1 + st2; + st2 = st2 - st1; + st1 = st7 + st5; + tmp686 = st4; + st4 = st1 * K382683432[0]; + st7 = st7 - st5; + st1 = st1 * K923879532[0]; + st5 = tmp683 + st3; + tmp687 = st4; + st4 = st7 * K923879532[0]; + tmp688 = st1; + st1 = tmp652 - st5; + st7 = st7 * K382683432[0]; + st5 = tmp652 + st5; + st3 = st3 - tmp683; + c_im(input[16]) = st1; + st1 = tmp637 - st3; + st3 = tmp637 + st3; + c_im(input[0]) = st5; + st5 = tmp682 - st8; + st5 = st5 * K707106781[0]; + c_re(input[24]) = st1; + st1 = tmp639 - st5; + st5 = tmp639 + st5; + st8 = tmp682 + st8; + st8 = st8 * K707106781[0]; + c_re(input[8]) = st3; + st3 = tmp651 - st8; + st8 = tmp651 + st8; + c_im(input[28]) = st1; + st1 = st2 - tmp677; + st1 = st1 * K707106781[0]; + c_im(input[12]) = st5; + st5 = tmp642 - st1; + st1 = tmp642 + st1; + st2 = tmp677 + st2; + st2 = st2 * K707106781[0]; + c_re(input[20]) = st3; + st3 = tmp638 - st2; + st2 = tmp638 + st2; + st6 = st6 + st7; + st7 = tmp681 - st6; + st6 = tmp681 + st6; + st4 = tmp686 - st4; + c_re(input[4]) = st8; + st8 = tmp680 + st4; + st4 = st4 - tmp680; + c_re(input[28]) = st5; + st5 = tmp650 - st8; + st8 = tmp650 + st8; + c_re(input[12]) = st1; + st1 = tmp649 - st4; + st4 = tmp649 + st4; + c_im(input[20]) = st3; + st3 = tmp643 - st7; + st7 = tmp643 + st7; + c_im(input[4]) = st2; + st2 = tmp644 - st6; + st6 = tmp644 + st6; + c_im(input[22]) = st5; + st5 = tmp685 + tmp688; + c_im(input[6]) = st8; + st8 = tmp679 - st5; + st5 = tmp679 + st5; + c_re(input[30]) = st1; + st1 = tmp684 - tmp687; + c_re(input[14]) = st4; + st4 = tmp678 + st1; + st1 = st1 - tmp678; + c_im(input[30]) = st3; + st3 = tmp648 - st4; + st4 = tmp648 + st4; + c_im(input[14]) = st7; + st7 = tmp647 - st1; + st1 = tmp647 + st1; + c_re(input[22]) = st2; + st2 = tmp645 - st8; + st8 = tmp645 + st8; + c_re(input[6]) = st6; + st6 = tmp646 - st5; + st5 = tmp646 + st5; + c_im(input[18]) = st3; + st3 = c_re(input[31]); + st3 = st3 - c_re(input[15]); + c_im(input[2]) = st4; + st4 = c_im(input[7]); + st4 = st4 - c_im(input[23]); + c_re(input[26]) = st7; + st7 = st3 - st4; + st3 = st3 + st4; + c_re(input[10]) = st1; + st1 = c_re(input[7]); + st1 = st1 - c_re(input[23]); + c_im(input[26]) = st2; + st2 = c_im(input[31]); + st2 = st2 - c_im(input[15]); + c_im(input[10]) = st8; + st8 = st1 + st2; + st2 = st2 - st1; + c_re(input[18]) = st6; + st6 = c_re(input[3]); + st6 = st6 - c_re(input[19]); + c_re(input[2]) = st5; + st5 = c_im(input[3]); + st5 = st5 - c_im(input[19]); + st4 = st6 - st5; + st6 = st6 + st5; + st1 = c_re(input[27]); + st1 = st1 - c_re(input[11]); + st5 = c_im(input[27]); + st5 = st5 - c_im(input[11]); + tmp689 = st2; + st2 = st1 + st5; + st5 = st5 - st1; + st1 = st4 + st2; + st1 = st1 * K707106781[0]; + st4 = st4 - st2; + st4 = st4 * K707106781[0]; + st2 = st6 + st5; + st2 = st2 * K707106781[0]; + st5 = st5 - st6; + st5 = st5 * K707106781[0]; + st6 = st7 - st1; + tmp690 = st4; + st4 = st6 * K831469612[0]; + st7 = st7 + st1; + st6 = st6 * K555570233[0]; + st1 = st3 - st5; + tmp691 = st6; + st6 = st1 * K195090322[0]; + st3 = st3 + st5; + st1 = st1 * K980785280[0]; + st5 = st8 - st2; + tmp692 = st3; + st3 = st5 * K555570233[0]; + st8 = st8 + st2; + st5 = st5 * K831469612[0]; + st2 = tmp689 - tmp690; + tmp693 = st5; + st5 = st2 * K980785280[0]; + tmp694 = st4; + st4 = tmp689 + tmp690; + st2 = st2 * K195090322[0]; + st5 = st5 + st6; + st6 = st8 * K980785280[0]; + st2 = st2 - st1; + st1 = st7 * K195090322[0]; + st3 = st3 - tmp694; + st7 = st7 * K980785280[0]; + tmp695 = st3; + st3 = tmp691 + tmp693; + st8 = st8 * K195090322[0]; + st6 = st6 - st1; + st1 = st4 * K555570233[0]; + st7 = st7 + st8; + st8 = tmp692 * K831469612[0]; + st1 = st1 + st8; + st4 = st4 * K831469612[0]; + st8 = c_re(input[1]); + tmp696 = st1; + st1 = tmp692 * K555570233[0]; + st8 = st8 - c_re(input[17]); + st4 = st4 - st1; + st1 = c_im(input[9]); + st1 = st1 - c_im(input[25]); + tmp697 = st4; + st4 = st8 - st1; + st8 = st8 + st1; + st1 = c_re(input[9]); + st1 = st1 - c_re(input[25]); + tmp698 = st7; + st7 = c_im(input[1]); + st7 = st7 - c_im(input[17]); + tmp699 = st6; + st6 = st1 + st7; + st7 = st7 - st1; + st1 = c_re(input[5]); + st1 = st1 - c_re(input[21]); + tmp700 = st3; + st3 = c_im(input[5]); + st3 = st3 - c_im(input[21]); + tmp701 = st2; + st2 = st1 - st3; + st1 = st1 + st3; + st3 = c_re(input[29]); + st3 = st3 - c_re(input[13]); + tmp702 = st5; + st5 = c_im(input[29]); + st5 = st5 - c_im(input[13]); + tmp703 = st7; + st7 = st3 + st5; + st5 = st5 - st3; + st3 = st2 + st7; + st3 = st3 * K707106781[0]; + st2 = st2 - st7; + st2 = st2 * K707106781[0]; + st7 = st1 + st5; + st7 = st7 * K707106781[0]; + st5 = st5 - st1; + st5 = st5 * K707106781[0]; + st1 = st4 - st3; + tmp704 = st2; + st2 = st1 * K831469612[0]; + st4 = st4 + st3; + st1 = st1 * K555570233[0]; + st3 = st8 - st5; + tmp705 = st1; + st1 = st3 * K195090322[0]; + st8 = st8 + st5; + st3 = st3 * K980785280[0]; + st5 = st6 - st7; + tmp706 = st2; + st2 = st5 * K555570233[0]; + st6 = st6 + st7; + st5 = st5 * K831469612[0]; + st7 = tmp703 - tmp704; + tmp707 = st5; + st5 = st7 * K980785280[0]; + tmp708 = st2; + st2 = tmp703 + tmp704; + st7 = st7 * K195090322[0]; + st1 = st1 - st5; + st5 = st4 * K195090322[0]; + tmp709 = st5; + st5 = st1 - tmp702; + tmp710 = st5; + st5 = st6 * K980785280[0]; + st1 = st1 + tmp702; + st4 = st4 * K980785280[0]; + st7 = st7 + st3; + st6 = st6 * K195090322[0]; + st3 = st7 + tmp701; + tmp711 = st4; + st4 = st8 * K831469612[0]; + st7 = tmp701 - st7; + tmp712 = st4; + st4 = st2 * K555570233[0]; + tmp713 = st4; + st4 = tmp673 - st3; + st2 = st2 * K831469612[0]; + st8 = st8 * K555570233[0]; + st3 = tmp673 + st3; + c_im(input[23]) = st4; + st4 = tmp672 - st7; + st7 = tmp672 + st7; + c_im(input[7]) = st3; + st3 = tmp659 - tmp710; + c_re(input[31]) = st4; + st4 = tmp659 + tmp710; + c_re(input[15]) = st7; + st7 = tmp658 - st1; + st1 = tmp658 + st1; + c_im(input[31]) = st3; + st3 = tmp706 + tmp708; + c_im(input[15]) = st4; + st4 = st3 + tmp695; + st3 = tmp695 - st3; + c_re(input[23]) = st7; + st7 = tmp705 - tmp707; + c_re(input[7]) = st1; + st1 = st7 - tmp700; + st7 = st7 + tmp700; + tmp714 = st2; + st2 = tmp661 - st1; + st1 = tmp661 + st1; + c_im(input[29]) = st2; + st2 = tmp671 - st7; + st7 = tmp671 + st7; + c_im(input[13]) = st1; + st1 = tmp660 - st4; + st4 = tmp660 + st4; + c_re(input[21]) = st2; + st2 = tmp662 - st3; + st3 = tmp662 + st3; + st5 = tmp709 + st5; + c_re(input[5]) = st7; + st7 = st5 + tmp699; + st5 = tmp699 - st5; + st6 = tmp711 - st6; + c_im(input[21]) = st1; + st1 = st6 - tmp698; + st6 = st6 + tmp698; + c_im(input[5]) = st4; + st4 = tmp670 - st1; + st1 = tmp670 + st1; + c_re(input[29]) = st2; + st2 = tmp669 - st6; + st6 = tmp669 + st6; + c_re(input[13]) = st3; + st3 = tmp663 - st7; + st7 = tmp663 + st7; + c_im(input[25]) = st4; + st4 = tmp664 - st5; + st5 = tmp664 + st5; + c_im(input[9]) = st1; + st1 = tmp712 - tmp713; + c_re(input[17]) = st2; + st2 = st1 - tmp696; + st1 = st1 + tmp696; + st8 = tmp714 + st8; + c_re(input[1]) = st6; + st6 = st8 + tmp697; + st8 = tmp697 - st8; + c_im(input[17]) = st3; + st3 = tmp668 - st6; + st6 = tmp668 + st6; + c_im(input[1]) = st7; + st7 = tmp667 - st8; + st8 = tmp667 + st8; + c_re(input[25]) = st4; + st4 = tmp665 - st2; + st2 = tmp665 + st2; + c_re(input[9]) = st5; + st5 = tmp666 - st1; + st1 = tmp666 + st1; + c_im(input[19]) = st3; + c_im(input[3]) = st6; + c_re(input[27]) = st7; + c_re(input[11]) = st8; + c_im(input[27]) = st4; + c_im(input[11]) = st2; + c_re(input[19]) = st5; + c_re(input[3]) = st1; +} + +void PFFTWI(64)(fftw_complex *input) +{ + PFFTWI(16)(input ); + PFFTWI(16)(input + 16); + PFFTWI(16)(input + 32); + PFFTWI(16)(input + 48); + PFFTWI(twiddle_4)(input, PFFTW(W_64), 16); +} + +void PFFTWI(128)(fftw_complex *input) +{ + PFFTWI(32)(input ); + PFFTWI(32)(input + 32); + PFFTWI(32)(input + 64); + PFFTWI(32)(input + 96); + PFFTWI(twiddle_4)(input, PFFTW(W_128), 32); +} + +void PFFTWI(512)(fftw_complex *input) +{ + PFFTWI(128)(input ); + PFFTWI(128)(input + 128); + PFFTWI(128)(input + 256); + PFFTWI(128)(input + 384); + PFFTWI(twiddle_4)(input, PFFTW(W_512), 128); +} + +/////////////////////////////////////////////////////////////////////////// +void PFFTW(twiddle_4) (fftw_complex * A, const fftw_complex * W, int iostride) { + int i; + fftw_complex *inout; + inout = A; + { + fftw_real st1; + fftw_real st2; + fftw_real st3; + fftw_real st4; + fftw_real st5; + fftw_real st6; + fftw_real st7; + fftw_real st8; + st8 = c_re(inout[0]); + st8 = st8 + c_re(inout[2 * iostride]); + st7 = c_re(inout[iostride]); + st7 = st7 + c_re(inout[3 * iostride]); + st6 = st8 - st7; + st8 = st8 + st7; + st5 = c_im(inout[0]); + st5 = st5 + c_im(inout[2 * iostride]); + st4 = c_im(inout[iostride]); + st4 = st4 + c_im(inout[3 * iostride]); + st3 = st5 - st4; + st5 = st5 + st4; + st2 = c_im(inout[0]); + st2 = st2 - c_im(inout[2 * iostride]); + st1 = c_re(inout[iostride]); + st1 = st1 - c_re(inout[3 * iostride]); + st7 = st2 - st1; + st1 = st1 + st2; + st4 = c_re(inout[0]); + st4 = st4 - c_re(inout[2 * iostride]); + c_re(inout[2 * iostride]) = st6; + st6 = c_im(inout[iostride]); + st6 = st6 - c_im(inout[3 * iostride]); + c_re(inout[0]) = st8; + st8 = st4 - st6; + st4 = st4 + st6; + c_im(inout[0]) = st5; + c_im(inout[2 * iostride]) = st3; + c_im(inout[iostride]) = st7; + c_im(inout[3 * iostride]) = st1; + c_re(inout[3 * iostride]) = st8; + c_re(inout[iostride]) = st4; + } + inout = inout + 1; + i = iostride - 1; + do { + { + fftw_real st1; + fftw_real st2; + fftw_real st3; + fftw_real st4; + fftw_real st5; + fftw_real st6; + fftw_real st7; + fftw_real st8; + st8 = c_re(inout[0]); + st8 = st8 + c_re(inout[2 * iostride]); + st7 = c_re(inout[iostride]); + st7 = st7 + c_re(inout[3 * iostride]); + st6 = st8 - st7; + st5 = st6 * c_im(W[1]); + st8 = st8 + st7; + st6 = st6 * c_re(W[1]); + st4 = c_im(inout[0]); + st4 = st4 + c_im(inout[2 * iostride]); + st3 = c_im(inout[iostride]); + st3 = st3 + c_im(inout[3 * iostride]); + st2 = st4 - st3; + st1 = st2 * c_im(W[1]); + st4 = st4 + st3; + st2 = st2 * c_re(W[1]); + st2 = st2 - st5; + st6 = st6 + st1; + st7 = c_re(inout[0]); + st7 = st7 - c_re(inout[2 * iostride]); + st5 = c_im(inout[iostride]); + st5 = st5 - c_im(inout[3 * iostride]); + c_re(inout[0]) = st8; + st8 = st7 - st5; + st3 = st8 * c_re(W[0]); + st7 = st7 + st5; + st8 = st8 * c_im(W[0]); + st1 = c_re(inout[iostride]); + c_re(inout[2 * iostride]) = st6; + st6 = st7 * c_im(W[0]); + st1 = st1 - c_re(inout[3 * iostride]); + st7 = st7 * c_re(W[0]); + st5 = c_im(inout[0]); + st5 = st5 - c_im(inout[2 * iostride]); + c_im(inout[0]) = st4; + st4 = st1 + st5; + c_im(inout[2 * iostride]) = st2; + st2 = st4 * c_im(W[0]); + st5 = st5 - st1; + st4 = st4 * c_re(W[0]); + st3 = st3 - st2; + st1 = st5 * c_re(W[0]); + st5 = st5 * c_im(W[0]); + st4 = st4 + st8; + st5 = st5 + st7; + st1 = st1 - st6; + c_re(inout[3 * iostride]) = st3; + c_im(inout[3 * iostride]) = st4; + c_re(inout[iostride]) = st5; + c_im(inout[iostride]) = st1; + } + i = i - 1, inout = inout + 1, W = W + 2; + } while (i > 0); +} + +void PFFTWI(twiddle_4) (fftw_complex * A, const fftw_complex * W, int iostride) { + int i; + fftw_complex *inout; + inout = A; + { + fftw_real st1; + fftw_real st2; + fftw_real st3; + fftw_real st4; + fftw_real st5; + fftw_real st6; + fftw_real st7; + fftw_real st8; + st8 = c_re(inout[0]); + st8 = st8 + c_re(inout[2 * iostride]); + st7 = c_re(inout[iostride]); + st7 = st7 + c_re(inout[3 * iostride]); + st6 = st8 - st7; + st8 = st8 + st7; + st5 = c_im(inout[0]); + st5 = st5 + c_im(inout[2 * iostride]); + st4 = c_im(inout[iostride]); + st4 = st4 + c_im(inout[3 * iostride]); + st3 = st5 - st4; + st5 = st5 + st4; + st2 = c_re(inout[iostride]); + st2 = st2 - c_re(inout[3 * iostride]); + st1 = c_im(inout[0]); + st1 = st1 - c_im(inout[2 * iostride]); + st7 = st2 + st1; + st1 = st1 - st2; + st4 = c_re(inout[0]); + st4 = st4 - c_re(inout[2 * iostride]); + c_re(inout[2 * iostride]) = st6; + st6 = c_im(inout[iostride]); + st6 = st6 - c_im(inout[3 * iostride]); + c_re(inout[0]) = st8; + st8 = st4 - st6; + st4 = st4 + st6; + c_im(inout[0]) = st5; + c_im(inout[2 * iostride]) = st3; + c_im(inout[iostride]) = st7; + c_im(inout[3 * iostride]) = st1; + c_re(inout[iostride]) = st8; + c_re(inout[3 * iostride]) = st4; + } + inout = inout + 1; + i = iostride - 1; + do { + { + fftw_real st1; + fftw_real st2; + fftw_real st3; + fftw_real st4; + fftw_real st5; + fftw_real st6; + fftw_real st7; + fftw_real st8; + st8 = c_re(inout[2 * iostride]); + st8 = st8 * c_re(W[1]); + st7 = c_im(inout[2 * iostride]); + st7 = st7 * c_im(W[1]); + st8 = st8 - st7; + st6 = st8 + c_re(inout[0]); + st8 = c_re(inout[0]) - st8; + st5 = c_re(inout[2 * iostride]); + st5 = st5 * c_im(W[1]); + st4 = c_im(inout[2 * iostride]); + st4 = st4 * c_re(W[1]); + st5 = st5 + st4; + st3 = st5 + c_im(inout[0]); + st5 = c_im(inout[0]) - st5; + st2 = c_re(inout[iostride]); + st2 = st2 * c_re(W[0]); + st1 = c_im(inout[iostride]); + st1 = st1 * c_im(W[0]); + st2 = st2 - st1; + st7 = c_re(inout[3 * iostride]); + st7 = st7 * c_re(W[0]); + st4 = c_im(inout[3 * iostride]); + st4 = st4 * c_im(W[0]); + st7 = st7 + st4; + st1 = st2 + st7; + st2 = st2 - st7; + st4 = st6 - st1; + st6 = st6 + st1; + st7 = st2 + st5; + st5 = st5 - st2; + st1 = c_re(inout[iostride]); + st1 = st1 * c_im(W[0]); + st2 = c_im(inout[iostride]); + st2 = st2 * c_re(W[0]); + st1 = st1 + st2; + c_re(inout[2 * iostride]) = st4; + st4 = c_im(inout[3 * iostride]); + st4 = st4 * c_re(W[0]); + c_re(inout[0]) = st6; + st6 = c_re(inout[3 * iostride]); + st6 = st6 * c_im(W[0]); + st4 = st4 - st6; + c_im(inout[iostride]) = st7; + st7 = st1 - st4; + st1 = st1 + st4; + c_im(inout[3 * iostride]) = st5; + st5 = st8 - st7; + st8 = st8 + st7; + st2 = st1 + st3; + st3 = st3 - st1; + c_re(inout[iostride]) = st5; + c_re(inout[3 * iostride]) = st8; + c_im(inout[0]) = st2; + c_im(inout[2 * iostride]) = st3; + } + i = i - 1, inout = inout + 1, W = W + 2; + } while (i > 0); +} +////////////////////////////////////////////////////////////////////// +int PFFTW(permutation_64)(int i) +{ + int i1 = i % 4; + int i2 = i / 4; + if (i1 <= 2) + return (i1 * 16 + i2); + else + return (i1 * 16 + ((i2 + 1) % 16)); +} + +int PFFTW(permutation_128)(int i) +{ + int i1 = i % 4; + int i2 = i / 4; + if (i1 <= 2) + return (i1 * 32 + i2); + else + return (i1 * 32 + ((i2 + 1) % 32)); +} + +int PFFTW(permutation_512)(int i) +{ + int i1 = i % 4; + int i2 = i / 4; + if (i1 <= 2) + return (i1 * 128 + PFFTW(permutation_128)(i2)); + else + return (i1 * 128 + PFFTW(permutation_128)((i2 + 1) % 128)); +} +///////////////////////////////////////////////////////////////// +void MakeFFTOrder(faacDecHandle hDecoder) +{ + int i; + + for (i=0 ; i < 512 ; i++) + { + if (i < 64) + hDecoder->unscambled64[i] = PFFTW(permutation_64)(i); + hDecoder->unscambled512[i] = PFFTW(permutation_512)(i); + } +} diff --git a/fastfft.h b/fastfft.h new file mode 100644 index 0000000..8ed5eae --- /dev/null +++ b/fastfft.h @@ -0,0 +1,32 @@ +/* + * FAAD - Freeware Advanced Audio Decoder + * Copyright (C) 2001 Menno Bakker + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: fastfft.h,v 1.3 2001/06/28 23:54:22 wmaycisco Exp $ + */ + +#include "transfo.h" + +#define PFFTW(name) CONCAT(pfftw_, name) +#define PFFTWI(name) CONCAT(pfftwi_, name) +#define CONCAT_AUX(a, b) a ## b +#define CONCAT(a, b) CONCAT_AUX(a,b) +#define FFTW_KONST(x) ((fftw_real) x) + +void PFFTW(twiddle_4)(fftw_complex *A, const fftw_complex *W, int iostride); +void PFFTWI(twiddle_4)(fftw_complex *A, const fftw_complex *W, int iostride); + diff --git a/huffdec.c b/huffdec.c new file mode 100644 index 0000000..40346e3 --- /dev/null +++ b/huffdec.c @@ -0,0 +1,967 @@ +/************************* MPEG-2 NBC Audio Decoder ************************** + * * +"This software module was originally developed by +AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS and edited by +Yoshiaki Oikawa (Sony Corporation), +Mitsuyuki Hatanaka (Sony Corporation) +in the course of development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ +/* + * $Id: huffdec.c,v 1.7 2003/02/18 18:51:31 wmaycisco Exp $ + */ + +#include "all.h" +#include "port.h" +#include "bits.h" +#include "util.h" + + +// wmay - add statics +static int extension_payload(faacDecHandle hDecoder, int cnt, byte *data); +static int getescape(faacDecHandle hDecoder, int q); +static void getgroup(faacDecHandle hDecoder, Info *info, byte *group); +static int getics(faacDecHandle hDecoder, Info *info, int common_window, byte *win, byte *wshape, + byte *group, byte *max_sfb, int *lpflag, int *prstflag, + byte *cb_map, Float *coef, int *global_gain, + int *factors, + NOK_LT_PRED_STATUS *nok_ltp_status, + TNS_frame_info *tns); +static int get_ics_info(faacDecHandle hDecoder, byte *win, byte *wshape, +byte *group, byte *max_sfb, +int *lpflag, int *prstflag, +NOK_LT_PRED_STATUS *nok_ltp_status, +NOK_LT_PRED_STATUS *nok_ltp_status_right, +int stereo_flag); +static int getmask(faacDecHandle hDecoder, Info *info, byte *group, byte max_sfb, byte *mask); +static void get_sign_bits(faacDecHandle hDecoder, int *q, int n); +static int huffcb(faacDecHandle hDecoder, byte *sect, int *sectbits, + int tot_sfb, int sfb_per_sbk, byte max_sfb); +static int hufffac(faacDecHandle hDecoder, Info *info, byte *group, int nsect, byte *sect, + int global_gain, int *factors); +static int huffspec(faacDecHandle hDecoder, Info *info, int nsect, byte *sect, + int *factors, Float *coef); + +void getfill(faacDecHandle hDecoder, byte *data) +{ + int cnt; + + if ((cnt = faad_getbits(&hDecoder->ld, LEN_F_CNT)) == (1<ld, LEN_F_ESC) - 1; + + while (cnt > 0) + cnt -= extension_payload(hDecoder, cnt, data); +} + +int getdata(faacDecHandle hDecoder, int *tag, int *dt_cnt, byte *data_bytes) +{ + int i, align_flag, cnt; + + *tag = faad_getbits(&hDecoder->ld, LEN_TAG); + align_flag = faad_getbits(&hDecoder->ld, LEN_D_ALIGN); + + if ((cnt = faad_getbits(&hDecoder->ld, LEN_D_CNT)) == (1<ld, LEN_D_ESC); + + *dt_cnt = cnt; + + if (align_flag) + faad_byte_align(&hDecoder->ld); + + for (i=0; ild, LEN_BYTE); + + return 0; +} + +static int extension_payload(faacDecHandle hDecoder, int cnt, byte *data) +{ + int type, i; + + /* fill bytes should not emulate any EX types below! */ + type = faad_getbits(&hDecoder->ld, LEN_EX_TYPE); + + switch(type) { + case EX_FILL_DATA: + faad_getbits(&hDecoder->ld, LEN_NIBBLE); + for (i=0; ild, LEN_BYTE); + return cnt; + default: + faad_getbits(&hDecoder->ld, LEN_NIBBLE); + for (i=0; ild, LEN_BYTE); + return cnt; + } +} + +/* + * read and decode the data for the next 1024 output samples + * return -1 if there was an error + */ +int huffdecode(faacDecHandle hDecoder, int id, MC_Info *mip, byte *win, + Wnd_Shape *wshape, + byte **cb_map, int **factors, + byte **group, byte *hasmask, byte **mask, byte *max_sfb, + int **lpflag, int **prstflag, + NOK_LT_PRED_STATUS **nok_ltp_status, + TNS_frame_info **tns, Float **coef) +{ + int i, tag, common_window, ch, widx, first=0, last=0; + + int global_gain; /* not used in this routine */ + Info info; + + tag = faad_getbits(&hDecoder->ld, LEN_TAG); + + switch(id) { + case ID_SCE: + common_window = 0; + break; + case ID_CPE: + common_window = faad_get1bit(&hDecoder->ld); /* common_window */ + break; + default: + /* CommonWarning("Unknown id"); */ + return(-1); + } + + if ((ch = chn_config(hDecoder, id, tag, common_window, mip)) < 0) + return -1; + + switch(id) { + case ID_SCE: + widx = mip->ch_info[ch].widx; + first = ch; + last = ch; + hasmask[widx] = 0; + break; + case ID_CPE: + first = ch; + last = mip->ch_info[ch].paired_ch; + if (common_window) { + widx = mip->ch_info[ch].widx; + if (!get_ics_info(hDecoder, &win[widx], &wshape[widx].this_bk, group[widx], + &max_sfb[widx], lpflag[widx], prstflag[widx], + nok_ltp_status[widx],nok_ltp_status[mip->ch_info[ch].paired_ch], common_window)) + return -1; + + hasmask[widx] = getmask(hDecoder, hDecoder->winmap[win[widx]], group[widx], + max_sfb[widx], mask[widx]); + } + else { + hasmask[mip->ch_info[first].widx] = 0; + hasmask[mip->ch_info[last].widx] = 0; + } + break; + } + + for (i=first; i<=last; i++) { + widx = mip->ch_info[i].widx; + SetMemory(coef[i], 0, LN2*sizeof(Float)); + + if(!getics(hDecoder, &info, common_window, &win[widx], &wshape[widx].this_bk, + group[widx], &max_sfb[widx], lpflag[widx], prstflag[widx], + cb_map[i], coef[i], &global_gain, factors[i], nok_ltp_status[widx], + tns[i])) + return -1; + } + + return 0; +} + +static int get_ics_info(faacDecHandle hDecoder, byte *win, byte *wshape, byte *group, byte *max_sfb, + int *lpflag, int *prstflag, NOK_LT_PRED_STATUS *nok_ltp_status, + NOK_LT_PRED_STATUS *nok_ltp_status_right, int stereo_flag) +{ + Info *info; + int i, j; + + int max_pred_sfb = pred_max_bands(hDecoder); + + faad_get1bit(&hDecoder->ld); /* reserved bit */ + *win = (unsigned char)faad_getbits(&hDecoder->ld, LEN_WIN_SEQ); + *wshape = (unsigned char)faad_get1bit(&hDecoder->ld); /* window shape */ + if ((info = hDecoder->winmap[*win]) == NULL) + /* CommonExit(1, "bad window code"); */ + return 0; + + /* + * max scale factor, scale factor grouping and prediction flags + */ + prstflag[0] = 0; + if (info->islong) { + *max_sfb = (unsigned char)faad_getbits(&hDecoder->ld, LEN_MAX_SFBL); + group[0] = 1; + + if (hDecoder->mc_info.object_type != AACLTP) { + if ((lpflag[0] = faad_getbits(&hDecoder->ld, LEN_PRED_PRES))) { + if ((prstflag[0] = faad_getbits(&hDecoder->ld, LEN_PRED_RST))) { + for(i=1; ild, LEN_PRED_RST); + } + j = ( (*max_sfb < max_pred_sfb) ? + *max_sfb : max_pred_sfb ) + 1; + for (i = 1; i < j; i++) + lpflag[i] = faad_getbits(&hDecoder->ld, LEN_PRED_ENAB); + for ( ; i < max_pred_sfb+1; i++) + lpflag[i] = 0; + } + } else { /* AAC LTP */ + if(faad_get1bit(&hDecoder->ld)) + { + nok_lt_decode(hDecoder, *max_sfb, nok_ltp_status->sbk_prediction_used, + nok_ltp_status->sfb_prediction_used, + &nok_ltp_status->weight, + nok_ltp_status->delay); + + if(stereo_flag) + nok_lt_decode(hDecoder, *max_sfb, nok_ltp_status_right->sbk_prediction_used, + nok_ltp_status_right->sfb_prediction_used, + &nok_ltp_status_right->weight, + nok_ltp_status_right->delay); + } else { + nok_ltp_status->sbk_prediction_used[0] = 0; + if(stereo_flag) + nok_ltp_status_right->sbk_prediction_used[0] = 0; + } + } + } else { + *max_sfb = (unsigned char)faad_getbits(&hDecoder->ld, LEN_MAX_SFBS); + getgroup(hDecoder, info, group); + lpflag[0] = 0; + nok_ltp_status->sbk_prediction_used[0] = 0; + if(stereo_flag) + nok_ltp_status_right->sbk_prediction_used[0] = 0; + } + + return 1; +} + +static void deinterleave(int inptr[], int outptr[], int ngroups, + int nsubgroups[], int ncells[], int cellsize[]) +{ + int i, j, k, l; + int *start_inptr, *start_subgroup_ptr, *subgroup_ptr; + int cell_inc, subgroup_inc; + + start_subgroup_ptr = outptr; + + for (i = 0; i < ngroups; i++) + { + cell_inc = 0; + start_inptr = inptr; + + /* Compute the increment size for the subgroup pointer */ + subgroup_inc = 0; + for (j = 0; j < ncells[i]; j++) { + subgroup_inc += cellsize[j]; + } + + /* Perform the deinterleaving across all subgroups in a group */ + for (j = 0; j < ncells[i]; j++) + { + subgroup_ptr = start_subgroup_ptr; + + for (k = 0; k < nsubgroups[i]; k++) { + outptr = subgroup_ptr + cell_inc; + for (l = 0; l < cellsize[j]; l++) { + *outptr++ = *inptr++; + } + subgroup_ptr += subgroup_inc; + } + cell_inc += cellsize[j]; + } + start_subgroup_ptr += (inptr - start_inptr); + } +} + +static void calc_gsfb_table(Info *info, byte *group) +{ + int group_offset; + int group_idx; + int offset; + int *group_offset_p; + int sfb,len; + + /* first calc the group length*/ + if (info->islong){ + return; + } else { + group_offset = 0; + group_idx =0; + do { + info->group_len[group_idx] = group[group_idx]-group_offset; + group_offset=group[group_idx]; + group_idx++; + } while (group_offset<8); + + info->num_groups=group_idx; + group_offset_p = info->bk_sfb_top; + offset=0; + + for (group_idx=0;group_idxnum_groups;group_idx++){ + len = info->group_len[group_idx]; + for (sfb=0;sfbsfb_per_sbk[group_idx];sfb++){ + offset += info->sfb_width_128[sfb] * len; + *group_offset_p++ = offset; + } + } + } +} + +static void getgroup(faacDecHandle hDecoder, Info *info, byte *group) +{ + int i, j, first_short; + + first_short=1; + for (i = 0; i < info->nsbk; i++) { + if (info->bins_per_sbk[i] > SN2) { + /* non-short windows are always their own group */ + *group++ = i+1; + } else { + /* only short-window sequences are grouped! */ + if (first_short) { + /* first short window is always a new group */ + first_short=0; + } else { + if((j = faad_get1bit(&hDecoder->ld)) == 0) { + *group++ = i; + } + } + } + } + *group = i; +} + +/* + * read a synthesis mask + * uses EXTENDED_MS_MASK + * and grouped mask + */ +static int getmask(faacDecHandle hDecoder, Info *info, byte *group, byte max_sfb, byte *mask) +{ + int b, i, mp; + + mp = faad_getbits(&hDecoder->ld, LEN_MASK_PRES); + + /* special EXTENDED_MS_MASK cases */ + if(mp == 0) { /* no ms at all */ + return 0; + } + if(mp == 2) {/* MS for whole spectrum on, mask bits set to 1 */ + for(b = 0; b < info->nsbk; b = *group++) + for(i = 0; i < info->sfb_per_sbk[b]; i ++) + *mask++ = 1; + return 2; + } + + /* otherwise get mask */ + for(b = 0; b < info->nsbk; b = *group++){ + for(i = 0; i < max_sfb; i ++) { + *mask = (byte)faad_get1bit(&hDecoder->ld); + mask++; + } + for( ; i < info->sfb_per_sbk[b]; i++){ + *mask = 0; + mask++; + } + } + return 1; +} + +static void clr_tns( Info *info, TNS_frame_info *tns_frame_info ) +{ + int s; + + tns_frame_info->n_subblocks = info->nsbk; + for (s=0; sn_subblocks; s++) + tns_frame_info->info[s].n_filt = 0; +} + +static int get_tns(faacDecHandle hDecoder, Info *info, TNS_frame_info *tns_frame_info) +{ + int f, t, top, res, res2, compress; + int short_flag, s; + int *sp, tmp, s_mask, n_mask; + TNSfilt *tns_filt; + TNSinfo *tns_info; + static int sgn_mask[] = { 0x2, 0x4, 0x8 }; + static int neg_mask[] = { 0xfffc, 0xfff8, 0xfff0 }; + + + short_flag = (!info->islong); + tns_frame_info->n_subblocks = info->nsbk; + + for (s=0; sn_subblocks; s++) { + tns_info = &tns_frame_info->info[s]; + + if (!(tns_info->n_filt = faad_getbits(&hDecoder->ld, short_flag ? 1 : 2))) + continue; + + tns_info -> coef_res = res = faad_get1bit(&hDecoder->ld) + 3; + top = info->sfb_per_sbk[s]; + tns_filt = &tns_info->filt[ 0 ]; + for (f=tns_info->n_filt; f>0; f--) { + tns_filt->stop_band = top; + top = tns_filt->start_band = top - faad_getbits(&hDecoder->ld, short_flag ? 4 : 6); + tns_filt->order = faad_getbits(&hDecoder->ld, short_flag ? 3 : 5); + + if (tns_filt->order) { + tns_filt->direction = faad_get1bit(&hDecoder->ld); + compress = faad_get1bit(&hDecoder->ld); + + res2 = res - compress; + s_mask = sgn_mask[ res2 - 2 ]; + n_mask = neg_mask[ res2 - 2 ]; + + sp = tns_filt->coef; + for (t=tns_filt->order; t>0; t--) { + tmp = (short)faad_getbits(&hDecoder->ld, res2); + *sp++ = (tmp & s_mask) ? (short)(tmp | n_mask) : (short)tmp; + } + } + tns_filt++; + } + } /* subblock loop */ + + return 1; +} + +static void get_pulse_nc(faacDecHandle hDecoder, struct Pulse_Info *pulse_info) +{ + int i; + + pulse_info->number_pulse = faad_getbits(&hDecoder->ld, LEN_NPULSE); + pulse_info->pulse_start_sfb = faad_getbits(&hDecoder->ld, LEN_PULSE_ST_SFB); + + for(i = 0; i < pulse_info->number_pulse + 1; i++) { + pulse_info->pulse_offset[i] = faad_getbits(&hDecoder->ld, LEN_POFF); + pulse_info->pulse_amp[i] = faad_getbits(&hDecoder->ld, LEN_PAMP); + } +} + +static void pulse_nc(faacDecHandle hDecoder, int *coef, struct Pulse_Info *pulse_info) +{ + int i, k; + + k = hDecoder->only_long_info.sbk_sfb_top[0][pulse_info->pulse_start_sfb]; + + for(i = 0; i <= pulse_info->number_pulse; i++) { + k += pulse_info->pulse_offset[i]; + if (coef[k]>0) + coef[k] += pulse_info->pulse_amp[i]; + else + coef[k] -= pulse_info->pulse_amp[i]; + } +} + +static int getics(faacDecHandle hDecoder, Info *info, int common_window, byte *win, byte *wshape, + byte *group, byte *max_sfb, int *lpflag, int *prstflag, + byte *cb_map, Float *coef, int *global_gain, + int *factors, + NOK_LT_PRED_STATUS *nok_ltp_status, + TNS_frame_info *tns) +{ + int nsect, i, cb, top, bot, tot_sfb; + byte sect[ 2*(MAXBANDS+1) ]; + + memset(sect, 0, sizeof(sect)); + + /* + * global gain + */ + *global_gain = (short)faad_getbits(&hDecoder->ld, LEN_SCL_PCM); + + if (!common_window) { + if (!get_ics_info(hDecoder, win, wshape, group, max_sfb, lpflag, prstflag, + nok_ltp_status, NULL, 0)) + return 0; + } + + CopyMemory(info, hDecoder->winmap[*win], sizeof(Info)); + + /* calculate total number of sfb for this grouping */ + if (*max_sfb == 0) { + tot_sfb = 0; + } + else { + i=0; + tot_sfb = info->sfb_per_sbk[0]; + while (group[i++] < info->nsbk) { + tot_sfb += info->sfb_per_sbk[0]; + } + } + + /* + * section data + */ + nsect = huffcb(hDecoder, sect, info->sectbits, tot_sfb, info->sfb_per_sbk[0], *max_sfb); + if(nsect==0 && *max_sfb>0) + return 0; + + /* generate "linear" description from section info + * stored as codebook for each scalefactor band and group + */ + if (nsect) { + bot = 0; + for (i=0; ipulse_info.pulse_data_present = faad_get1bit(&hDecoder->ld))) { /* pulse data present */ + if (info->islong) { + get_pulse_nc(hDecoder, &hDecoder->pulse_info); + } else { + /* CommonExit(1,"Pulse data not allowed for short blocks"); */ + return 0; + } + } + + /* + * tns data + */ + if (faad_get1bit(&hDecoder->ld)) { /* tns present */ + get_tns(hDecoder, info, tns); + } + else { + clr_tns(info, tns); + } + + if (faad_get1bit(&hDecoder->ld)) { /* gain control present */ + /* CommonExit(1, "Gain control not implemented"); */ + return 0; + } + + return huffspec(hDecoder, info, nsect, sect, factors, coef); +} + +/* + * read the codebook and boundaries + */ +static int huffcb(faacDecHandle hDecoder, byte *sect, int *sectbits, + int tot_sfb, int sfb_per_sbk, byte max_sfb) +{ + int nsect, n, base, bits, len; + + bits = sectbits[0]; + len = (1 << bits) - 1; + nsect = 0; + + for(base = 0; base < tot_sfb && nsect < tot_sfb; ) { + *sect++ = (byte)faad_getbits(&hDecoder->ld, LEN_CB); + + n = faad_getbits(&hDecoder->ld, bits); + while(n == len && base < tot_sfb) { + base += len; + n = faad_getbits(&hDecoder->ld, bits); + } + base += n; + *sect++ = base; + nsect++; + + /* insert a zero section for regions above max_sfb for each group */ + if ((sect[-1] % sfb_per_sbk) == max_sfb) { + base += (sfb_per_sbk - max_sfb); + *sect++ = 0; + *sect++ = base; + nsect++; + } + } + + if(base != tot_sfb || nsect > tot_sfb) + return 0; + + return nsect; +} + +/* + * get scale factors + */ +static int hufffac(faacDecHandle hDecoder, Info *info, byte *group, int nsect, byte *sect, + int global_gain, int *factors) +{ + Huffscl *hcw; + int i, b, bb, t, n, sfb, top, fac, is_pos; + int factor_transmitted[MAXBANDS], *fac_trans; + int noise_pcm_flag = 1; + int noise_nrg; + + /* clear array for the case of max_sfb == 0 */ + SetMemory(factor_transmitted, 0, MAXBANDS*sizeof(int)); + SetMemory(factors, 0, MAXBANDS*sizeof(int)); + + sfb = 0; + fac_trans = factor_transmitted; + for(i = 0; i < nsect; i++){ + top = sect[1]; /* top of section in sfb */ + t = sect[0]; /* codebook for this section */ + sect += 2; + for(; sfb < top; sfb++) { + fac_trans[sfb] = t; + } + } + + /* scale factors are dpcm relative to global gain + * intensity positions are dpcm relative to zero + */ + fac = global_gain; + is_pos = 0; + noise_nrg = global_gain - NOISE_OFFSET; + + /* get scale factors */ + hcw = bookscl; + bb = 0; + for(b = 0; b < info->nsbk; ){ + n = info->sfb_per_sbk[b]; + b = *group++; + for(i = 0; i < n; i++){ + switch (fac_trans[i]) { + case ZERO_HCB: /* zero book */ + break; + default: /* spectral books */ + /* decode scale factor */ + t = decode_huff_cw_scl(hDecoder, hcw); + fac += t - MIDFAC; /* 1.5 dB */ + if(fac >= 2*TEXP || fac < 0) + return 0; + factors[i] = fac; + break; + case BOOKSCL: /* invalid books */ + return 0; + case INTENSITY_HCB: /* intensity books */ + case INTENSITY_HCB2: + /* decode intensity position */ + t = decode_huff_cw_scl(hDecoder, hcw); + is_pos += t - MIDFAC; + factors[i] = is_pos; + break; + case NOISE_HCB: /* noise books */ + /* decode noise energy */ + if (noise_pcm_flag) { + noise_pcm_flag = 0; + t = faad_getbits(&hDecoder->ld, NOISE_PCM_BITS) - NOISE_PCM_OFFSET; + } else + t = decode_huff_cw_scl(hDecoder, hcw) - MIDFAC; + noise_nrg += t; + factors[i] = noise_nrg; + break; + } + } + + /* expand short block grouping */ + if (!(info->islong)) { + for(bb++; bb < b; bb++) { + for (i=0; i 0) { + if (q < MAX_IQ_TBL) { + return((float)hDecoder->iq_exp_tbl[q]); + } else { + return((float)pow(q, 4./3.)); + } + } else { + q = -q; + if (q < MAX_IQ_TBL) { + return((float)(-hDecoder->iq_exp_tbl[q])); + } else { + return((float)(-pow(q, 4./3.))); + } + } +} + +static int huffspec(faacDecHandle hDecoder, Info *info, int nsect, byte *sect, + int *factors, Float *coef) +{ + Hcb *hcb; + Huffman *hcw; + int i, j, k, table, step, stop, bottom, top; + int *bands, *bandp; + int *quant, *qp; + int *tmp_spec; + int *quantPtr; + int *tmp_specPtr; + + quant = AllocMemory(LN2*sizeof(int)); + tmp_spec = AllocMemory(LN2*sizeof(int)); + + quantPtr = quant; + tmp_specPtr = tmp_spec; + +#ifndef _WIN32 + SetMemory(quant, 0, LN2*sizeof(int)); +#endif + + bands = info->bk_sfb_top; + bottom = 0; + k = 0; + bandp = bands; + for(i = nsect; i; i--) { + table = sect[0]; + top = sect[1]; + sect += 2; + if( (table == 0) || (table == NOISE_HCB) || + (table == INTENSITY_HCB) || (table == INTENSITY_HCB2) ) { + bandp = bands+top; + k = bandp[-1]; + bottom = top; + continue; + } + if(table < BY4BOOKS+1) { + step = 4; + } else { + step = 2; + } + hcb = &book[table]; + hcw = hcb->hcw; + qp = quant+k; + for(j = bottom; j < top; j++) { + stop = *bandp++; + while(k < stop) { + decode_huff_cw(hDecoder, hcw, qp, hcb); + + if (!hcb->signed_cb) + get_sign_bits(hDecoder, qp, step); + if(table == ESCBOOK){ + qp[0] = getescape(hDecoder, qp[0]); + qp[1] = getescape(hDecoder, qp[1]); + } + qp += step; + k += step; + } + } + bottom = top; + } + + /* pulse coding reconstruction */ + if ((info->islong) && (hDecoder->pulse_info.pulse_data_present)) + pulse_nc(hDecoder, quant, &hDecoder->pulse_info); + + if (!info->islong) { + deinterleave (quant,tmp_spec, + (short)info->num_groups, + info->group_len, + info->sfb_per_sbk, + info->sfb_width_128); + + for (i = LN2/16 - 1; i >= 0; --i) + { + *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++; + *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++; + *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++; + *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++; + *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++; + *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++; + *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++; + *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++; + } + } + + /* inverse quantization */ + for (i=0; ibins_per_bk; i++) { + coef[i] = esc_iquant(hDecoder, quant[i]); + } + + /* rescaling */ + { + int sbk, nsbk, sfb, nsfb, fac, top; + Float *fp, scale; + + i = 0; + fp = coef; + nsbk = info->nsbk; + for (sbk=0; sbksfb_per_sbk[sbk]; + k=0; + for (sfb=0; sfbsbk_sfb_top[sbk][sfb]; + fac = factors[i++]-SF_OFFSET; + + if (fac >= 0 && fac < TEXP) { + scale = hDecoder->exptable[fac]; + } + else { + if (fac == -SF_OFFSET) { + scale = 0; + } + else { + scale = (float)pow(2.0, 0.25*fac); + } + } + for ( ; kdim = dim; + hcb->signed_cb = signed_cb; + hcb->hcw = hcw; +} + +__inline void decode_huff_cw(faacDecHandle hDecoder, Huffman *h, int *qp, Hcb *hcb) +{ + int i, j; + unsigned long cw; + + i = h->len; + cw = faad_getbits_fast(&hDecoder->ld, i); + + while (cw != h->cw) + { + h++; + j = h->len-i; + if (j!=0) { + i += j; + while (j--) + cw = (cw<<1)|faad_get1bit(&hDecoder->ld); + } + } + + if(hcb->dim == 4) + { + qp[0] = h->x; + qp[1] = h->y; + qp[2] = h->v; + qp[3] = h->w; + } else { + qp[0] = h->x; + qp[1] = h->y; + } +} + +__inline int decode_huff_cw_scl(faacDecHandle hDecoder, Huffscl *h) +{ + int i, j; + long cw; + + i = h->len; + cw = faad_getbits_fast(&hDecoder->ld, i); + + while ((unsigned long)cw != h->cw) + { + h++; + j = h->len-i; + if (j!=0) { + i += j; + while (j--) + cw = (cw<<1)|faad_get1bit(&hDecoder->ld); + } + } + + return h->scl; +} + +/* get sign bits */ +static void get_sign_bits(faacDecHandle hDecoder, int *q, int n) +{ + int i; + + for(i=0; i < n; i++) + { + if(q[i]) + { + if(faad_get1bit(&hDecoder->ld) & 1) + { + /* 1 signals negative, as in 2's complement */ + q[i] = -q[i]; + } + } + } +} + +static int getescape(faacDecHandle hDecoder, int q) +{ + int i, off, neg; + + if(q < 0){ + if(q != -16) + return q; + neg = 1; + } else{ + if(q != +16) + return q; + neg = 0; + } + + for(i=4;; i++){ + if(faad_get1bit(&hDecoder->ld) == 0) + break; + } + + if(i > 16){ + off = faad_getbits(&hDecoder->ld, i-16) << 16; + off |= faad_getbits(&hDecoder->ld, 16); + } else + off = faad_getbits(&hDecoder->ld, i); + + i = off + (1< +#include "all.h" + +void huffbookinit(faacDecHandle hDecoder) +{ + int i; + + hufftab(&book[1], book1, 4, HUF1SGN); + hufftab(&book[2], book2, 4, HUF2SGN); + hufftab(&book[3], book3, 4, HUF3SGN); + hufftab(&book[4], book4, 4, HUF4SGN); + hufftab(&book[5], book5, 2, HUF5SGN); + hufftab(&book[6], book6, 2, HUF6SGN); + hufftab(&book[7], book7, 2, HUF7SGN); + hufftab(&book[8], book8, 2, HUF8SGN); + hufftab(&book[9], book9, 2, HUF9SGN); + hufftab(&book[10], book10, 2, HUF10SGN); + hufftab(&book[11], book11, 2, HUF11SGN); + + for(i = 0; i < TEXP; i++) + { + hDecoder->exptable[i] = (float)pow( 2.0, 0.25*i); + } + + for(i = 0; i < MAX_IQ_TBL; i++) + { + hDecoder->iq_exp_tbl[i] = (float)pow(i, 4./3.); + } + + infoinit(hDecoder, &samp_rate_info[hDecoder->mc_info.sampling_rate_idx]); +} + +void infoinit(faacDecHandle hDecoder, SR_Info *sip) +{ + int i, j, k, n, ws; + int *sfbands; + Info *ip; + + /* long block info */ + ip = &hDecoder->only_long_info; + hDecoder->win_seq_info[ONLY_LONG_WINDOW] = ip; + ip->islong = 1; + ip->nsbk = 1; + ip->bins_per_bk = LN2; + for (i=0; insbk; i++) { + ip->sfb_per_sbk[i] = sip->nsfb1024; + ip->sectbits[i] = LONG_SECT_BITS; + ip->sbk_sfb_top[i] = sip->SFbands1024; + } + ip->sfb_width_128 = NULL; + ip->num_groups = 1; + ip->group_len[0] = 1; + ip->group_offs[0] = 0; + + /* short block info */ + ip = &hDecoder->eight_short_info; + hDecoder->win_seq_info[EIGHT_SHORT_WINDOW] = ip; + ip->islong = 0; + ip->nsbk = NSHORT; + ip->bins_per_bk = LN2; + for (i=0; insbk; i++) { + ip->sfb_per_sbk[i] = sip->nsfb128; + ip->sectbits[i] = SHORT_SECT_BITS; + ip->sbk_sfb_top[i] = sip->SFbands128; + } + /* construct sfb width table */ + ip->sfb_width_128 = sfbwidth128; + for (i=0, j=0, n=sip->nsfb128; iSFbands128[i]; + sfbwidth128[i] = k - j; + j = k; + } + + /* common to long and short */ + for (ws=0; wswin_seq_info[ws]) == NULL) + continue; + + ip->sfb_per_bk = 0; + k = 0; + n = 0; + for (i=0; insbk; i++) { + /* compute bins_per_sbk */ + ip->bins_per_sbk[i] = ip->bins_per_bk / ip->nsbk; + + /* compute sfb_per_bk */ + ip->sfb_per_bk += ip->sfb_per_sbk[i]; + + /* construct default (non-interleaved) bk_sfb_top[] */ + sfbands = ip->sbk_sfb_top[i]; + for (j=0; j < ip->sfb_per_sbk[i]; j++) + ip->bk_sfb_top[j+k] = sfbands[j] + n; + + n += ip->bins_per_sbk[i]; + k += ip->sfb_per_sbk[i]; + } + } +} diff --git a/hufftables.c b/hufftables.c new file mode 100644 index 0000000..50ade32 --- /dev/null +++ b/hufftables.c @@ -0,0 +1,1432 @@ +/* + * FAAD - Freeware Advanced Audio Decoder + * Copyright (C) 2001 Menno Bakker + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: hufftables.c,v 1.6 2002/01/11 00:55:17 wmaycisco Exp $ + */ + +#include "all.h" + +Huffman book1[] = { + /* idx codeword len codew x y v w */ + { /* 0: 0 */ 1, 0, 0, 0, 0, 0 }, + { /* 1: 1 0000 */ 5, 16, 1, 0, 0, 0 }, + { /* 2: 1 0001 */ 5, 17, -1, 0, 0, 0 }, + { /* 3: 1 0010 */ 5, 18, 0, 0, 0, -1 }, + { /* 4: 1 0011 */ 5, 19, 0, 1, 0, 0 }, + { /* 5: 1 0100 */ 5, 20, 0, 0, 0, 1 }, + { /* 6: 1 0101 */ 5, 21, 0, 0, -1, 0 }, + { /* 7: 1 0110 */ 5, 22, 0, 0, 1, 0 }, + { /* 8: 1 0111 */ 5, 23, 0, -1, 0, 0 }, + { /* 9: 110 0000 */ 7, 96, 1, -1, 0, 0 }, + { /* 10: 110 0001 */ 7, 97, -1, 1, 0, 0 }, + { /* 11: 110 0010 */ 7, 98, 0, 0, -1, 1 }, + { /* 12: 110 0011 */ 7, 99, 0, 1, -1, 0 }, + { /* 13: 110 0100 */ 7, 100, 0, -1, 1, 0 }, + { /* 14: 110 0101 */ 7, 101, 0, 0, 1, -1 }, + { /* 15: 110 0110 */ 7, 102, 1, 1, 0, 0 }, + { /* 16: 110 0111 */ 7, 103, 0, 0, -1, -1 }, + { /* 17: 110 1000 */ 7, 104, -1, -1, 0, 0 }, + { /* 18: 110 1001 */ 7, 105, 0, -1, -1, 0 }, + { /* 19: 110 1010 */ 7, 106, 1, 0, -1, 0 }, + { /* 20: 110 1011 */ 7, 107, 0, 1, 0, -1 }, + { /* 21: 110 1100 */ 7, 108, -1, 0, 1, 0 }, + { /* 22: 110 1101 */ 7, 109, 0, 0, 1, 1 }, + { /* 23: 110 1110 */ 7, 110, 1, 0, 1, 0 }, + { /* 24: 110 1111 */ 7, 111, 0, -1, 0, 1 }, + { /* 25: 111 0000 */ 7, 112, 0, 1, 1, 0 }, + { /* 26: 111 0001 */ 7, 113, 0, 1, 0, 1 }, + { /* 27: 111 0010 */ 7, 114, -1, 0, -1, 0 }, + { /* 28: 111 0011 */ 7, 115, 1, 0, 0, 1 }, + { /* 29: 111 0100 */ 7, 116, -1, 0, 0, -1 }, + { /* 30: 111 0101 */ 7, 117, 1, 0, 0, -1 }, + { /* 31: 111 0110 */ 7, 118, -1, 0, 0, 1 }, + { /* 32: 111 0111 */ 7, 119, 0, -1, 0, -1 }, + { /* 33: 1 1110 0000 */ 9, 480, 1, 1, -1, 0 }, + { /* 34: 1 1110 0001 */ 9, 481, -1, 1, -1, 0 }, + { /* 35: 1 1110 0010 */ 9, 482, 1, -1, 1, 0 }, + { /* 36: 1 1110 0011 */ 9, 483, 0, 1, 1, -1 }, + { /* 37: 1 1110 0100 */ 9, 484, 0, 1, -1, 1 }, + { /* 38: 1 1110 0101 */ 9, 485, 0, -1, 1, 1 }, + { /* 39: 1 1110 0110 */ 9, 486, 0, -1, 1, -1 }, + { /* 40: 1 1110 0111 */ 9, 487, 1, -1, -1, 0 }, + { /* 41: 1 1110 1000 */ 9, 488, 1, 0, -1, 1 }, + { /* 42: 1 1110 1001 */ 9, 489, 0, 1, -1, -1 }, + { /* 43: 1 1110 1010 */ 9, 490, -1, 1, 1, 0 }, + { /* 44: 1 1110 1011 */ 9, 491, -1, 0, 1, -1 }, + { /* 45: 1 1110 1100 */ 9, 492, -1, -1, 1, 0 }, + { /* 46: 1 1110 1101 */ 9, 493, 0, -1, -1, 1 }, + { /* 47: 1 1110 1110 */ 9, 494, 1, -1, 0, 1 }, + { /* 48: 1 1110 1111 */ 9, 495, 1, -1, 0, -1 }, + { /* 49: 1 1111 0000 */ 9, 496, -1, 1, 0, -1 }, + { /* 50: 1 1111 0001 */ 9, 497, -1, -1, -1, 0 }, + { /* 51: 1 1111 0010 */ 9, 498, 0, -1, -1, -1 }, + { /* 52: 1 1111 0011 */ 9, 499, 0, 1, 1, 1 }, + { /* 53: 1 1111 0100 */ 9, 500, 1, 0, 1, -1 }, + { /* 54: 1 1111 0101 */ 9, 501, 1, 1, 0, 1 }, + { /* 55: 1 1111 0110 */ 9, 502, -1, 1, 0, 1 }, + { /* 56: 1 1111 0111 */ 9, 503, 1, 1, 1, 0 }, + { /* 57: 11 1111 0000 */ 10, 1008, -1, -1, 0, 1 }, + { /* 58: 11 1111 0001 */ 10, 1009, -1, 0, -1, -1 }, + { /* 59: 11 1111 0010 */ 10, 1010, 1, 1, 0, -1 }, + { /* 60: 11 1111 0011 */ 10, 1011, 1, 0, -1, -1 }, + { /* 61: 11 1111 0100 */ 10, 1012, -1, 0, -1, 1 }, + { /* 62: 11 1111 0101 */ 10, 1013, -1, -1, 0, -1 }, + { /* 63: 11 1111 0110 */ 10, 1014, -1, 0, 1, 1 }, + { /* 64: 11 1111 0111 */ 10, 1015, 1, 0, 1, 1 }, + { /* 65: 111 1111 0000 */ 11, 2032, 1, -1, 1, -1 }, + { /* 66: 111 1111 0001 */ 11, 2033, -1, 1, -1, 1 }, + { /* 67: 111 1111 0010 */ 11, 2034, -1, 1, 1, -1 }, + { /* 68: 111 1111 0011 */ 11, 2035, 1, -1, -1, 1 }, + { /* 69: 111 1111 0100 */ 11, 2036, 1, 1, 1, 1 }, + { /* 70: 111 1111 0101 */ 11, 2037, -1, -1, 1, 1 }, + { /* 71: 111 1111 0110 */ 11, 2038, 1, 1, -1, -1 }, + { /* 72: 111 1111 0111 */ 11, 2039, -1, -1, 1, -1 }, + { /* 73: 111 1111 1000 */ 11, 2040, -1, -1, -1, -1 }, + { /* 74: 111 1111 1001 */ 11, 2041, 1, 1, -1, 1 }, + { /* 75: 111 1111 1010 */ 11, 2042, 1, -1, 1, 1 }, + { /* 76: 111 1111 1011 */ 11, 2043, -1, 1, 1, 1 }, + { /* 77: 111 1111 1100 */ 11, 2044, -1, 1, -1, -1 }, + { /* 78: 111 1111 1101 */ 11, 2045, -1, -1, -1, 1 }, + { /* 79: 111 1111 1110 */ 11, 2046, 1, -1, -1, -1 }, + { /* 80: 111 1111 1111 */ 11, 2047, 1, 1, 1, -1 } +}; + +Huffman book2[] = { + /* idx codeword len codew x y v w */ + { /* 0: 000 */ 3, 0, 0, 0, 0, 0 }, + { /* 1: 0010 */ 4, 2, 1, 0, 0, 0 }, + { /* 2: 0 0110 */ 5, 6, -1, 0, 0, 0 }, + { /* 3: 0 0111 */ 5, 7, 0, 0, 0, 1 }, + { /* 4: 0 1000 */ 5, 8, 0, 0, -1, 0 }, + { /* 5: 0 1001 */ 5, 9, 0, 0, 0, -1 }, + { /* 6: 0 1010 */ 5, 10, 0, -1, 0, 0 }, + { /* 7: 0 1011 */ 5, 11, 0, 0, 1, 0 }, + { /* 8: 0 1100 */ 5, 12, 0, 1, 0, 0 }, + { /* 9: 01 1010 */ 6, 26, 0, -1, 1, 0 }, + { /* 10: 01 1011 */ 6, 27, -1, 1, 0, 0 }, + { /* 11: 01 1100 */ 6, 28, 0, 1, -1, 0 }, + { /* 12: 01 1101 */ 6, 29, 0, 0, 1, -1 }, + { /* 13: 01 1110 */ 6, 30, 0, 1, 0, -1 }, + { /* 14: 01 1111 */ 6, 31, 0, 0, -1, 1 }, + { /* 15: 10 0000 */ 6, 32, -1, 0, 0, -1 }, + { /* 16: 10 0001 */ 6, 33, 1, -1, 0, 0 }, + { /* 17: 10 0010 */ 6, 34, 1, 0, -1, 0 }, + { /* 18: 10 0011 */ 6, 35, -1, -1, 0, 0 }, + { /* 19: 10 0100 */ 6, 36, 0, 0, -1, -1 }, + { /* 20: 10 0101 */ 6, 37, 1, 0, 1, 0 }, + { /* 21: 10 0110 */ 6, 38, 1, 0, 0, 1 }, + { /* 22: 10 0111 */ 6, 39, 0, -1, 0, 1 }, + { /* 23: 10 1000 */ 6, 40, -1, 0, 1, 0 }, + { /* 24: 10 1001 */ 6, 41, 0, 1, 0, 1 }, + { /* 25: 10 1010 */ 6, 42, 0, -1, -1, 0 }, + { /* 26: 10 1011 */ 6, 43, -1, 0, 0, 1 }, + { /* 27: 10 1100 */ 6, 44, 0, -1, 0, -1 }, + { /* 28: 10 1101 */ 6, 45, -1, 0, -1, 0 }, + { /* 29: 10 1110 */ 6, 46, 1, 1, 0, 0 }, + { /* 30: 10 1111 */ 6, 47, 0, 1, 1, 0 }, + { /* 31: 11 0000 */ 6, 48, 0, 0, 1, 1 }, + { /* 32: 11 0001 */ 6, 49, 1, 0, 0, -1 }, + { /* 33: 110 0100 */ 7, 100, 0, 1, -1, 1 }, + { /* 34: 110 0101 */ 7, 101, 1, 0, -1, 1 }, + { /* 35: 110 0110 */ 7, 102, -1, 1, -1, 0 }, + { /* 36: 110 0111 */ 7, 103, 0, -1, 1, -1 }, + { /* 37: 110 1000 */ 7, 104, 1, -1, 1, 0 }, + { /* 38: 110 1001 */ 7, 105, 1, 1, 0, -1 }, + { /* 39: 110 1010 */ 7, 106, 1, 0, 1, 1 }, + { /* 40: 110 1011 */ 7, 107, -1, 1, 1, 0 }, + { /* 41: 110 1100 */ 7, 108, 0, -1, -1, 1 }, + { /* 42: 110 1101 */ 7, 109, 1, 1, 1, 0 }, + { /* 43: 110 1110 */ 7, 110, -1, 0, 1, -1 }, + { /* 44: 110 1111 */ 7, 111, -1, -1, -1, 0 }, + { /* 45: 111 0000 */ 7, 112, -1, 0, -1, 1 }, + { /* 46: 111 0001 */ 7, 113, 1, -1, -1, 0 }, + { /* 47: 111 0010 */ 7, 114, 1, 1, -1, 0 }, + { /* 48: 1110 0110 */ 8, 230, 1, -1, 0, 1 }, + { /* 49: 1110 0111 */ 8, 231, -1, 1, 0, -1 }, + { /* 50: 1110 1000 */ 8, 232, -1, -1, 1, 0 }, + { /* 51: 1110 1001 */ 8, 233, -1, 0, 1, 1 }, + { /* 52: 1110 1010 */ 8, 234, -1, -1, 0, 1 }, + { /* 53: 1110 1011 */ 8, 235, -1, -1, 0, -1 }, + { /* 54: 1110 1100 */ 8, 236, 0, -1, -1, -1 }, + { /* 55: 1110 1101 */ 8, 237, 1, 0, 1, -1 }, + { /* 56: 1110 1110 */ 8, 238, 1, 0, -1, -1 }, + { /* 57: 1110 1111 */ 8, 239, 0, 1, -1, -1 }, + { /* 58: 1111 0000 */ 8, 240, 0, 1, 1, 1 }, + { /* 59: 1111 0001 */ 8, 241, -1, 1, 0, 1 }, + { /* 60: 1111 0010 */ 8, 242, -1, 0, -1, -1 }, + { /* 61: 1111 0011 */ 8, 243, 0, 1, 1, -1 }, + { /* 62: 1111 0100 */ 8, 244, 1, -1, 0, -1 }, + { /* 63: 1111 0101 */ 8, 245, 0, -1, 1, 1 }, + { /* 64: 1111 0110 */ 8, 246, 1, 1, 0, 1 }, + { /* 65: 1111 0111 */ 8, 247, 1, -1, 1, -1 }, + { /* 66: 1111 1000 */ 8, 248, -1, 1, -1, 1 }, + { /* 67: 1 1111 0010 */ 9, 498, 1, -1, -1, 1 }, + { /* 68: 1 1111 0011 */ 9, 499, -1, -1, -1, -1 }, + { /* 69: 1 1111 0100 */ 9, 500, -1, 1, 1, -1 }, + { /* 70: 1 1111 0101 */ 9, 501, -1, 1, 1, 1 }, + { /* 71: 1 1111 0110 */ 9, 502, 1, 1, 1, 1 }, + { /* 72: 1 1111 0111 */ 9, 503, -1, -1, 1, -1 }, + { /* 73: 1 1111 1000 */ 9, 504, 1, -1, 1, 1 }, + { /* 74: 1 1111 1001 */ 9, 505, -1, 1, -1, -1 }, + { /* 75: 1 1111 1010 */ 9, 506, -1, -1, 1, 1 }, + { /* 76: 1 1111 1011 */ 9, 507, 1, 1, -1, -1 }, + { /* 77: 1 1111 1100 */ 9, 508, 1, -1, -1, -1 }, + { /* 78: 1 1111 1101 */ 9, 509, -1, -1, -1, 1 }, + { /* 79: 1 1111 1110 */ 9, 510, 1, 1, -1, 1 }, + { /* 80: 1 1111 1111 */ 9, 511, 1, 1, 1, -1 } +}; + +Huffman book3[] = { + /* idx codeword len codew x y v w */ + { /* 0: 0 */ 1, 0, 0, 0, 0, 0 }, + { /* 1: 1000 */ 4, 8, 1, 0, 0, 0 }, + { /* 2: 1001 */ 4, 9, 0, 0, 0, 1 }, + { /* 3: 1010 */ 4, 10, 0, 1, 0, 0 }, + { /* 4: 1011 */ 4, 11, 0, 0, 1, 0 }, + { /* 5: 1 1000 */ 5, 24, 1, 1, 0, 0 }, + { /* 6: 1 1001 */ 5, 25, 0, 0, 1, 1 }, + { /* 7: 11 0100 */ 6, 52, 0, 1, 1, 0 }, + { /* 8: 11 0101 */ 6, 53, 0, 1, 0, 1 }, + { /* 9: 11 0110 */ 6, 54, 1, 0, 1, 0 }, + { /* 10: 11 0111 */ 6, 55, 0, 1, 1, 1 }, + { /* 11: 11 1000 */ 6, 56, 1, 0, 0, 1 }, + { /* 12: 11 1001 */ 6, 57, 1, 1, 1, 0 }, + { /* 13: 111 0100 */ 7, 116, 1, 1, 1, 1 }, + { /* 14: 111 0101 */ 7, 117, 1, 0, 1, 1 }, + { /* 15: 111 0110 */ 7, 118, 1, 1, 0, 1 }, + { /* 16: 1110 1110 */ 8, 238, 2, 0, 0, 0 }, + { /* 17: 1110 1111 */ 8, 239, 0, 0, 0, 2 }, + { /* 18: 1111 0000 */ 8, 240, 0, 0, 1, 2 }, + { /* 19: 1111 0001 */ 8, 241, 2, 1, 0, 0 }, + { /* 20: 1111 0010 */ 8, 242, 1, 2, 1, 0 }, + { /* 21: 1 1110 0110 */ 9, 486, 0, 0, 2, 1 }, + { /* 22: 1 1110 0111 */ 9, 487, 0, 1, 2, 1 }, + { /* 23: 1 1110 1000 */ 9, 488, 1, 2, 0, 0 }, + { /* 24: 1 1110 1001 */ 9, 489, 0, 1, 1, 2 }, + { /* 25: 1 1110 1010 */ 9, 490, 2, 1, 1, 0 }, + { /* 26: 1 1110 1011 */ 9, 491, 0, 0, 2, 0 }, + { /* 27: 1 1110 1100 */ 9, 492, 0, 2, 1, 0 }, + { /* 28: 1 1110 1101 */ 9, 493, 0, 1, 2, 0 }, + { /* 29: 1 1110 1110 */ 9, 494, 0, 2, 0, 0 }, + { /* 30: 1 1110 1111 */ 9, 495, 0, 1, 0, 2 }, + { /* 31: 1 1111 0000 */ 9, 496, 2, 0, 1, 0 }, + { /* 32: 1 1111 0001 */ 9, 497, 1, 2, 1, 1 }, + { /* 33: 1 1111 0010 */ 9, 498, 0, 2, 1, 1 }, + { /* 34: 1 1111 0011 */ 9, 499, 1, 1, 2, 0 }, + { /* 35: 1 1111 0100 */ 9, 500, 1, 1, 2, 1 }, + { /* 36: 11 1110 1010 */ 10, 1002, 1, 2, 0, 1 }, + { /* 37: 11 1110 1011 */ 10, 1003, 1, 0, 2, 0 }, + { /* 38: 11 1110 1100 */ 10, 1004, 1, 0, 2, 1 }, + { /* 39: 11 1110 1101 */ 10, 1005, 0, 2, 0, 1 }, + { /* 40: 11 1110 1110 */ 10, 1006, 2, 1, 1, 1 }, + { /* 41: 11 1110 1111 */ 10, 1007, 1, 1, 1, 2 }, + { /* 42: 11 1111 0000 */ 10, 1008, 2, 1, 0, 1 }, + { /* 43: 11 1111 0001 */ 10, 1009, 1, 0, 1, 2 }, + { /* 44: 11 1111 0010 */ 10, 1010, 0, 0, 2, 2 }, + { /* 45: 11 1111 0011 */ 10, 1011, 0, 1, 2, 2 }, + { /* 46: 11 1111 0100 */ 10, 1012, 2, 2, 1, 0 }, + { /* 47: 11 1111 0101 */ 10, 1013, 1, 2, 2, 0 }, + { /* 48: 11 1111 0110 */ 10, 1014, 1, 0, 0, 2 }, + { /* 49: 11 1111 0111 */ 10, 1015, 2, 0, 0, 1 }, + { /* 50: 11 1111 1000 */ 10, 1016, 0, 2, 2, 1 }, + { /* 51: 111 1111 0010 */ 11, 2034, 2, 2, 0, 0 }, + { /* 52: 111 1111 0011 */ 11, 2035, 1, 2, 2, 1 }, + { /* 53: 111 1111 0100 */ 11, 2036, 1, 1, 0, 2 }, + { /* 54: 111 1111 0101 */ 11, 2037, 2, 0, 1, 1 }, + { /* 55: 111 1111 0110 */ 11, 2038, 1, 1, 2, 2 }, + { /* 56: 111 1111 0111 */ 11, 2039, 2, 2, 1, 1 }, + { /* 57: 111 1111 1000 */ 11, 2040, 0, 2, 2, 0 }, + { /* 58: 111 1111 1001 */ 11, 2041, 0, 2, 1, 2 }, + { /* 59: 1111 1111 0100 */ 12, 4084, 1, 0, 2, 2 }, + { /* 60: 1111 1111 0101 */ 12, 4085, 2, 2, 0, 1 }, + { /* 61: 1111 1111 0110 */ 12, 4086, 2, 1, 2, 0 }, + { /* 62: 1111 1111 0111 */ 12, 4087, 2, 2, 2, 0 }, + { /* 63: 1111 1111 1000 */ 12, 4088, 0, 2, 2, 2 }, + { /* 64: 1111 1111 1001 */ 12, 4089, 2, 2, 2, 1 }, + { /* 65: 1111 1111 1010 */ 12, 4090, 2, 1, 2, 1 }, + { /* 66: 1111 1111 1011 */ 12, 4091, 1, 2, 1, 2 }, + { /* 67: 1111 1111 1100 */ 12, 4092, 1, 2, 2, 2 }, + { /* 68: 1 1111 1111 1010 */ 13, 8186, 0, 2, 0, 2 }, + { /* 69: 1 1111 1111 1011 */ 13, 8187, 2, 0, 2, 0 }, + { /* 70: 1 1111 1111 1100 */ 13, 8188, 1, 2, 0, 2 }, + { /* 71: 11 1111 1111 1010 */ 14, 16378, 2, 0, 2, 1 }, + { /* 72: 11 1111 1111 1011 */ 14, 16379, 2, 1, 1, 2 }, + { /* 73: 11 1111 1111 1100 */ 14, 16380, 2, 1, 0, 2 }, + { /* 74: 111 1111 1111 1010 */ 15, 32762, 2, 2, 2, 2 }, + { /* 75: 111 1111 1111 1011 */ 15, 32763, 2, 2, 1, 2 }, + { /* 76: 111 1111 1111 1100 */ 15, 32764, 2, 1, 2, 2 }, + { /* 77: 111 1111 1111 1101 */ 15, 32765, 2, 0, 1, 2 }, + { /* 78: 111 1111 1111 1110 */ 15, 32766, 2, 0, 0, 2 }, + { /* 79: 1111 1111 1111 1110 */ 16, 65534, 2, 2, 0, 2 }, + { /* 80: 1111 1111 1111 1111 */ 16, 65535, 2, 0, 2, 2 } +}; + +Huffman book4[] = { + /* idx codeword len codew x y v w */ + { /* 0: 0000 */ 4, 0, 1, 1, 1, 1 }, + { /* 1: 0001 */ 4, 1, 0, 1, 1, 1 }, + { /* 2: 0010 */ 4, 2, 1, 1, 0, 1 }, + { /* 3: 0011 */ 4, 3, 1, 1, 1, 0 }, + { /* 4: 0100 */ 4, 4, 1, 0, 1, 1 }, + { /* 5: 0101 */ 4, 5, 1, 0, 0, 0 }, + { /* 6: 0110 */ 4, 6, 1, 1, 0, 0 }, + { /* 7: 0111 */ 4, 7, 0, 0, 0, 0 }, + { /* 8: 1000 */ 4, 8, 0, 0, 1, 1 }, + { /* 9: 1001 */ 4, 9, 1, 0, 1, 0 }, + { /* 10: 1 0100 */ 5, 20, 1, 0, 0, 1 }, + { /* 11: 1 0101 */ 5, 21, 0, 1, 1, 0 }, + { /* 12: 1 0110 */ 5, 22, 0, 0, 0, 1 }, + { /* 13: 1 0111 */ 5, 23, 0, 1, 0, 1 }, + { /* 14: 1 1000 */ 5, 24, 0, 0, 1, 0 }, + { /* 15: 1 1001 */ 5, 25, 0, 1, 0, 0 }, + { /* 16: 110 1000 */ 7, 104, 2, 1, 1, 1 }, + { /* 17: 110 1001 */ 7, 105, 1, 1, 2, 1 }, + { /* 18: 110 1010 */ 7, 106, 1, 2, 1, 1 }, + { /* 19: 110 1011 */ 7, 107, 1, 1, 1, 2 }, + { /* 20: 110 1100 */ 7, 108, 2, 1, 1, 0 }, + { /* 21: 110 1101 */ 7, 109, 2, 1, 0, 1 }, + { /* 22: 110 1110 */ 7, 110, 1, 2, 1, 0 }, + { /* 23: 110 1111 */ 7, 111, 2, 0, 1, 1 }, + { /* 24: 111 0000 */ 7, 112, 0, 1, 2, 1 }, + { /* 25: 1110 0010 */ 8, 226, 0, 1, 1, 2 }, + { /* 26: 1110 0011 */ 8, 227, 1, 1, 2, 0 }, + { /* 27: 1110 0100 */ 8, 228, 0, 2, 1, 1 }, + { /* 28: 1110 0101 */ 8, 229, 1, 0, 1, 2 }, + { /* 29: 1110 0110 */ 8, 230, 1, 2, 0, 1 }, + { /* 30: 1110 0111 */ 8, 231, 1, 1, 0, 2 }, + { /* 31: 1110 1000 */ 8, 232, 1, 0, 2, 1 }, + { /* 32: 1110 1001 */ 8, 233, 2, 1, 0, 0 }, + { /* 33: 1110 1010 */ 8, 234, 2, 0, 1, 0 }, + { /* 34: 1110 1011 */ 8, 235, 1, 2, 0, 0 }, + { /* 35: 1110 1100 */ 8, 236, 2, 0, 0, 1 }, + { /* 36: 1110 1101 */ 8, 237, 0, 1, 0, 2 }, + { /* 37: 1110 1110 */ 8, 238, 0, 2, 1, 0 }, + { /* 38: 1110 1111 */ 8, 239, 0, 0, 1, 2 }, + { /* 39: 1111 0000 */ 8, 240, 0, 1, 2, 0 }, + { /* 40: 1111 0001 */ 8, 241, 0, 2, 0, 1 }, + { /* 41: 1111 0010 */ 8, 242, 1, 0, 0, 2 }, + { /* 42: 1111 0011 */ 8, 243, 0, 0, 2, 1 }, + { /* 43: 1111 0100 */ 8, 244, 1, 0, 2, 0 }, + { /* 44: 1111 0101 */ 8, 245, 2, 0, 0, 0 }, + { /* 45: 1111 0110 */ 8, 246, 0, 0, 0, 2 }, + { /* 46: 1 1110 1110 */ 9, 494, 0, 2, 0, 0 }, + { /* 47: 1 1110 1111 */ 9, 495, 0, 0, 2, 0 }, + { /* 48: 1 1111 0000 */ 9, 496, 1, 2, 2, 1 }, + { /* 49: 1 1111 0001 */ 9, 497, 2, 2, 1, 1 }, + { /* 50: 1 1111 0010 */ 9, 498, 2, 1, 2, 1 }, + { /* 51: 1 1111 0011 */ 9, 499, 1, 1, 2, 2 }, + { /* 52: 1 1111 0100 */ 9, 500, 1, 2, 1, 2 }, + { /* 53: 1 1111 0101 */ 9, 501, 2, 1, 1, 2 }, + { /* 54: 11 1110 1100 */ 10, 1004, 1, 2, 2, 0 }, + { /* 55: 11 1110 1101 */ 10, 1005, 2, 2, 1, 0 }, + { /* 56: 11 1110 1110 */ 10, 1006, 2, 1, 2, 0 }, + { /* 57: 11 1110 1111 */ 10, 1007, 0, 2, 2, 1 }, + { /* 58: 11 1111 0000 */ 10, 1008, 0, 1, 2, 2 }, + { /* 59: 11 1111 0001 */ 10, 1009, 2, 2, 0, 1 }, + { /* 60: 11 1111 0010 */ 10, 1010, 0, 2, 1, 2 }, + { /* 61: 11 1111 0011 */ 10, 1011, 2, 0, 2, 1 }, + { /* 62: 11 1111 0100 */ 10, 1012, 1, 0, 2, 2 }, + { /* 63: 11 1111 0101 */ 10, 1013, 2, 2, 2, 1 }, + { /* 64: 11 1111 0110 */ 10, 1014, 1, 2, 0, 2 }, + { /* 65: 11 1111 0111 */ 10, 1015, 2, 0, 1, 2 }, + { /* 66: 11 1111 1000 */ 10, 1016, 2, 1, 0, 2 }, + { /* 67: 11 1111 1001 */ 10, 1017, 1, 2, 2, 2 }, + { /* 68: 111 1111 0100 */ 11, 2036, 2, 1, 2, 2 }, + { /* 69: 111 1111 0101 */ 11, 2037, 2, 2, 1, 2 }, + { /* 70: 111 1111 0110 */ 11, 2038, 0, 2, 2, 0 }, + { /* 71: 111 1111 0111 */ 11, 2039, 2, 2, 0, 0 }, + { /* 72: 111 1111 1000 */ 11, 2040, 0, 0, 2, 2 }, + { /* 73: 111 1111 1001 */ 11, 2041, 2, 0, 2, 0 }, + { /* 74: 111 1111 1010 */ 11, 2042, 0, 2, 0, 2 }, + { /* 75: 111 1111 1011 */ 11, 2043, 2, 0, 0, 2 }, + { /* 76: 111 1111 1100 */ 11, 2044, 2, 2, 2, 2 }, + { /* 77: 111 1111 1101 */ 11, 2045, 0, 2, 2, 2 }, + { /* 78: 111 1111 1110 */ 11, 2046, 2, 2, 2, 0 }, + { /* 79: 1111 1111 1110 */ 12, 4094, 2, 2, 0, 2 }, + { /* 80: 1111 1111 1111 */ 12, 4095, 2, 0, 2, 2 } +}; + +Huffman book5[] = { + /* idx codeword len codew x y v w */ + { /* 0: 0 */ 1, 0, 0, 0, 0, 0 }, + { /* 1: 1000 */ 4, 8, -1, 0, 0, 0 }, + { /* 2: 1001 */ 4, 9, 1, 0, 0, 0 }, + { /* 3: 1010 */ 4, 10, 0, 1, 0, 0 }, + { /* 4: 1011 */ 4, 11, 0, -1, 0, 0 }, + { /* 5: 1 1000 */ 5, 24, 1, -1, 0, 0 }, + { /* 6: 1 1001 */ 5, 25, -1, 1, 0, 0 }, + { /* 7: 1 1010 */ 5, 26, -1, -1, 0, 0 }, + { /* 8: 1 1011 */ 5, 27, 1, 1, 0, 0 }, + { /* 9: 111 0000 */ 7, 112, -2, 0, 0, 0 }, + { /* 10: 111 0001 */ 7, 113, 0, 2, 0, 0 }, + { /* 11: 111 0010 */ 7, 114, 2, 0, 0, 0 }, + { /* 12: 111 0011 */ 7, 115, 0, -2, 0, 0 }, + { /* 13: 1110 1000 */ 8, 232, -2, -1, 0, 0 }, + { /* 14: 1110 1001 */ 8, 233, 2, 1, 0, 0 }, + { /* 15: 1110 1010 */ 8, 234, -1, -2, 0, 0 }, + { /* 16: 1110 1011 */ 8, 235, 1, 2, 0, 0 }, + { /* 17: 1110 1100 */ 8, 236, -2, 1, 0, 0 }, + { /* 18: 1110 1101 */ 8, 237, 2, -1, 0, 0 }, + { /* 19: 1110 1110 */ 8, 238, -1, 2, 0, 0 }, + { /* 20: 1110 1111 */ 8, 239, 1, -2, 0, 0 }, + { /* 21: 1111 0000 */ 8, 240, -3, 0, 0, 0 }, + { /* 22: 1111 0001 */ 8, 241, 3, 0, 0, 0 }, + { /* 23: 1111 0010 */ 8, 242, 0, -3, 0, 0 }, + { /* 24: 1111 0011 */ 8, 243, 0, 3, 0, 0 }, + { /* 25: 1 1110 1000 */ 9, 488, -3, -1, 0, 0 }, + { /* 26: 1 1110 1001 */ 9, 489, 1, 3, 0, 0 }, + { /* 27: 1 1110 1010 */ 9, 490, 3, 1, 0, 0 }, + { /* 28: 1 1110 1011 */ 9, 491, -1, -3, 0, 0 }, + { /* 29: 1 1110 1100 */ 9, 492, -3, 1, 0, 0 }, + { /* 30: 1 1110 1101 */ 9, 493, 3, -1, 0, 0 }, + { /* 31: 1 1110 1110 */ 9, 494, 1, -3, 0, 0 }, + { /* 32: 1 1110 1111 */ 9, 495, -1, 3, 0, 0 }, + { /* 33: 1 1111 0000 */ 9, 496, -2, 2, 0, 0 }, + { /* 34: 1 1111 0001 */ 9, 497, 2, 2, 0, 0 }, + { /* 35: 1 1111 0010 */ 9, 498, -2, -2, 0, 0 }, + { /* 36: 1 1111 0011 */ 9, 499, 2, -2, 0, 0 }, + { /* 37: 11 1110 1000 */ 10, 1000, -3, -2, 0, 0 }, + { /* 38: 11 1110 1001 */ 10, 1001, 3, -2, 0, 0 }, + { /* 39: 11 1110 1010 */ 10, 1002, -2, 3, 0, 0 }, + { /* 40: 11 1110 1011 */ 10, 1003, 2, -3, 0, 0 }, + { /* 41: 11 1110 1100 */ 10, 1004, 3, 2, 0, 0 }, + { /* 42: 11 1110 1101 */ 10, 1005, 2, 3, 0, 0 }, + { /* 43: 11 1110 1110 */ 10, 1006, -3, 2, 0, 0 }, + { /* 44: 11 1110 1111 */ 10, 1007, -2, -3, 0, 0 }, + { /* 45: 11 1111 0000 */ 10, 1008, 0, -4, 0, 0 }, + { /* 46: 11 1111 0001 */ 10, 1009, -4, 0, 0, 0 }, + { /* 47: 11 1111 0010 */ 10, 1010, 4, 1, 0, 0 }, + { /* 48: 11 1111 0011 */ 10, 1011, 4, 0, 0, 0 }, + { /* 49: 111 1110 1000 */ 11, 2024, -4, -1, 0, 0 }, + { /* 50: 111 1110 1001 */ 11, 2025, 0, 4, 0, 0 }, + { /* 51: 111 1110 1010 */ 11, 2026, 4, -1, 0, 0 }, + { /* 52: 111 1110 1011 */ 11, 2027, -1, -4, 0, 0 }, + { /* 53: 111 1110 1100 */ 11, 2028, 1, 4, 0, 0 }, + { /* 54: 111 1110 1101 */ 11, 2029, -1, 4, 0, 0 }, + { /* 55: 111 1110 1110 */ 11, 2030, -4, 1, 0, 0 }, + { /* 56: 111 1110 1111 */ 11, 2031, 1, -4, 0, 0 }, + { /* 57: 111 1111 0000 */ 11, 2032, 3, -3, 0, 0 }, + { /* 58: 111 1111 0001 */ 11, 2033, -3, -3, 0, 0 }, + { /* 59: 111 1111 0010 */ 11, 2034, -3, 3, 0, 0 }, + { /* 60: 111 1111 0011 */ 11, 2035, -2, 4, 0, 0 }, + { /* 61: 111 1111 0100 */ 11, 2036, -4, -2, 0, 0 }, + { /* 62: 111 1111 0101 */ 11, 2037, 4, 2, 0, 0 }, + { /* 63: 111 1111 0110 */ 11, 2038, 2, -4, 0, 0 }, + { /* 64: 111 1111 0111 */ 11, 2039, 2, 4, 0, 0 }, + { /* 65: 111 1111 1000 */ 11, 2040, 3, 3, 0, 0 }, + { /* 66: 111 1111 1001 */ 11, 2041, -4, 2, 0, 0 }, + { /* 67: 1111 1111 0100 */ 12, 4084, -2, -4, 0, 0 }, + { /* 68: 1111 1111 0101 */ 12, 4085, 4, -2, 0, 0 }, + { /* 69: 1111 1111 0110 */ 12, 4086, 3, -4, 0, 0 }, + { /* 70: 1111 1111 0111 */ 12, 4087, -4, -3, 0, 0 }, + { /* 71: 1111 1111 1000 */ 12, 4088, -4, 3, 0, 0 }, + { /* 72: 1111 1111 1001 */ 12, 4089, 3, 4, 0, 0 }, + { /* 73: 1111 1111 1010 */ 12, 4090, -3, 4, 0, 0 }, + { /* 74: 1111 1111 1011 */ 12, 4091, 4, 3, 0, 0 }, + { /* 75: 1111 1111 1100 */ 12, 4092, 4, -3, 0, 0 }, + { /* 76: 1111 1111 1101 */ 12, 4093, -3, -4, 0, 0 }, + { /* 77: 1 1111 1111 1100 */ 13, 8188, 4, -4, 0, 0 }, + { /* 78: 1 1111 1111 1101 */ 13, 8189, -4, 4, 0, 0 }, + { /* 79: 1 1111 1111 1110 */ 13, 8190, 4, 4, 0, 0 }, + { /* 80: 1 1111 1111 1111 */ 13, 8191, -4, -4, 0, 0 } +}; + +Huffman book6[] = { + /* idx codeword len codew x y v w */ + { /* 0: 0000 */ 4, 0, 0, 0, 0, 0 }, + { /* 1: 0001 */ 4, 1, 1, 0, 0, 0 }, + { /* 2: 0010 */ 4, 2, 0, -1, 0, 0 }, + { /* 3: 0011 */ 4, 3, 0, 1, 0, 0 }, + { /* 4: 0100 */ 4, 4, -1, 0, 0, 0 }, + { /* 5: 0101 */ 4, 5, 1, 1, 0, 0 }, + { /* 6: 0110 */ 4, 6, -1, 1, 0, 0 }, + { /* 7: 0111 */ 4, 7, 1, -1, 0, 0 }, + { /* 8: 1000 */ 4, 8, -1, -1, 0, 0 }, + { /* 9: 10 0100 */ 6, 36, 2, -1, 0, 0 }, + { /* 10: 10 0101 */ 6, 37, 2, 1, 0, 0 }, + { /* 11: 10 0110 */ 6, 38, -2, 1, 0, 0 }, + { /* 12: 10 0111 */ 6, 39, -2, -1, 0, 0 }, + { /* 13: 10 1000 */ 6, 40, -2, 0, 0, 0 }, + { /* 14: 10 1001 */ 6, 41, -1, 2, 0, 0 }, + { /* 15: 10 1010 */ 6, 42, 2, 0, 0, 0 }, + { /* 16: 10 1011 */ 6, 43, 1, -2, 0, 0 }, + { /* 17: 10 1100 */ 6, 44, 1, 2, 0, 0 }, + { /* 18: 10 1101 */ 6, 45, 0, -2, 0, 0 }, + { /* 19: 10 1110 */ 6, 46, -1, -2, 0, 0 }, + { /* 20: 10 1111 */ 6, 47, 0, 2, 0, 0 }, + { /* 21: 11 0000 */ 6, 48, 2, -2, 0, 0 }, + { /* 22: 11 0001 */ 6, 49, -2, 2, 0, 0 }, + { /* 23: 11 0010 */ 6, 50, -2, -2, 0, 0 }, + { /* 24: 11 0011 */ 6, 51, 2, 2, 0, 0 }, + { /* 25: 110 1000 */ 7, 104, -3, 1, 0, 0 }, + { /* 26: 110 1001 */ 7, 105, 3, 1, 0, 0 }, + { /* 27: 110 1010 */ 7, 106, 3, -1, 0, 0 }, + { /* 28: 110 1011 */ 7, 107, -1, 3, 0, 0 }, + { /* 29: 110 1100 */ 7, 108, -3, -1, 0, 0 }, + { /* 30: 110 1101 */ 7, 109, 1, 3, 0, 0 }, + { /* 31: 110 1110 */ 7, 110, 1, -3, 0, 0 }, + { /* 32: 110 1111 */ 7, 111, -1, -3, 0, 0 }, + { /* 33: 111 0000 */ 7, 112, 3, 0, 0, 0 }, + { /* 34: 111 0001 */ 7, 113, -3, 0, 0, 0 }, + { /* 35: 111 0010 */ 7, 114, 0, -3, 0, 0 }, + { /* 36: 111 0011 */ 7, 115, 0, 3, 0, 0 }, + { /* 37: 111 0100 */ 7, 116, 3, 2, 0, 0 }, + { /* 38: 1110 1010 */ 8, 234, -3, -2, 0, 0 }, + { /* 39: 1110 1011 */ 8, 235, -2, 3, 0, 0 }, + { /* 40: 1110 1100 */ 8, 236, 2, 3, 0, 0 }, + { /* 41: 1110 1101 */ 8, 237, 3, -2, 0, 0 }, + { /* 42: 1110 1110 */ 8, 238, 2, -3, 0, 0 }, + { /* 43: 1110 1111 */ 8, 239, -2, -3, 0, 0 }, + { /* 44: 1111 0000 */ 8, 240, -3, 2, 0, 0 }, + { /* 45: 1111 0001 */ 8, 241, 3, 3, 0, 0 }, + { /* 46: 1 1110 0100 */ 9, 484, 3, -3, 0, 0 }, + { /* 47: 1 1110 0101 */ 9, 485, -3, -3, 0, 0 }, + { /* 48: 1 1110 0110 */ 9, 486, -3, 3, 0, 0 }, + { /* 49: 1 1110 0111 */ 9, 487, 1, -4, 0, 0 }, + { /* 50: 1 1110 1000 */ 9, 488, -1, -4, 0, 0 }, + { /* 51: 1 1110 1001 */ 9, 489, 4, 1, 0, 0 }, + { /* 52: 1 1110 1010 */ 9, 490, -4, 1, 0, 0 }, + { /* 53: 1 1110 1011 */ 9, 491, -4, -1, 0, 0 }, + { /* 54: 1 1110 1100 */ 9, 492, 1, 4, 0, 0 }, + { /* 55: 1 1110 1101 */ 9, 493, 4, -1, 0, 0 }, + { /* 56: 1 1110 1110 */ 9, 494, -1, 4, 0, 0 }, + { /* 57: 1 1110 1111 */ 9, 495, 0, -4, 0, 0 }, + { /* 58: 1 1111 0000 */ 9, 496, -4, 2, 0, 0 }, + { /* 59: 1 1111 0001 */ 9, 497, -4, -2, 0, 0 }, + { /* 60: 1 1111 0010 */ 9, 498, 2, 4, 0, 0 }, + { /* 61: 1 1111 0011 */ 9, 499, -2, -4, 0, 0 }, + { /* 62: 1 1111 0100 */ 9, 500, -4, 0, 0, 0 }, + { /* 63: 1 1111 0101 */ 9, 501, 4, 2, 0, 0 }, + { /* 64: 1 1111 0110 */ 9, 502, 4, -2, 0, 0 }, + { /* 65: 1 1111 0111 */ 9, 503, -2, 4, 0, 0 }, + { /* 66: 1 1111 1000 */ 9, 504, 4, 0, 0, 0 }, + { /* 67: 1 1111 1001 */ 9, 505, 2, -4, 0, 0 }, + { /* 68: 1 1111 1010 */ 9, 506, 0, 4, 0, 0 }, + { /* 69: 11 1111 0110 */ 10, 1014, -3, -4, 0, 0 }, + { /* 70: 11 1111 0111 */ 10, 1015, -3, 4, 0, 0 }, + { /* 71: 11 1111 1000 */ 10, 1016, 3, -4, 0, 0 }, + { /* 72: 11 1111 1001 */ 10, 1017, 4, -3, 0, 0 }, + { /* 73: 11 1111 1010 */ 10, 1018, 3, 4, 0, 0 }, + { /* 74: 11 1111 1011 */ 10, 1019, 4, 3, 0, 0 }, + { /* 75: 11 1111 1100 */ 10, 1020, -4, 3, 0, 0 }, + { /* 76: 11 1111 1101 */ 10, 1021, -4, -3, 0, 0 }, + { /* 77: 111 1111 1100 */ 11, 2044, 4, 4, 0, 0 }, + { /* 78: 111 1111 1101 */ 11, 2045, -4, 4, 0, 0 }, + { /* 79: 111 1111 1110 */ 11, 2046, -4, -4, 0, 0 }, + { /* 80: 111 1111 1111 */ 11, 2047, 4, -4, 0, 0 } +}; + +Huffman book7[] = { + /* idx codeword len codew x y v w */ + { /* 0: 0 */ 1, 0, 0, 0, 0, 0 }, + { /* 1: 100 */ 3, 4, 1, 0, 0, 0 }, + { /* 2: 101 */ 3, 5, 0, 1, 0, 0 }, + { /* 3: 1100 */ 4, 12, 1, 1, 0, 0 }, + { /* 4: 11 0100 */ 6, 52, 2, 1, 0, 0 }, + { /* 5: 11 0101 */ 6, 53, 1, 2, 0, 0 }, + { /* 6: 11 0110 */ 6, 54, 2, 0, 0, 0 }, + { /* 7: 11 0111 */ 6, 55, 0, 2, 0, 0 }, + { /* 8: 111 0000 */ 7, 112, 3, 1, 0, 0 }, + { /* 9: 111 0001 */ 7, 113, 1, 3, 0, 0 }, + { /* 10: 111 0010 */ 7, 114, 2, 2, 0, 0 }, + { /* 11: 111 0011 */ 7, 115, 3, 0, 0, 0 }, + { /* 12: 111 0100 */ 7, 116, 0, 3, 0, 0 }, + { /* 13: 1110 1010 */ 8, 234, 2, 3, 0, 0 }, + { /* 14: 1110 1011 */ 8, 235, 3, 2, 0, 0 }, + { /* 15: 1110 1100 */ 8, 236, 1, 4, 0, 0 }, + { /* 16: 1110 1101 */ 8, 237, 4, 1, 0, 0 }, + { /* 17: 1110 1110 */ 8, 238, 1, 5, 0, 0 }, + { /* 18: 1110 1111 */ 8, 239, 5, 1, 0, 0 }, + { /* 19: 1111 0000 */ 8, 240, 3, 3, 0, 0 }, + { /* 20: 1111 0001 */ 8, 241, 2, 4, 0, 0 }, + { /* 21: 1111 0010 */ 8, 242, 0, 4, 0, 0 }, + { /* 22: 1111 0011 */ 8, 243, 4, 0, 0, 0 }, + { /* 23: 1 1110 1000 */ 9, 488, 4, 2, 0, 0 }, + { /* 24: 1 1110 1001 */ 9, 489, 2, 5, 0, 0 }, + { /* 25: 1 1110 1010 */ 9, 490, 5, 2, 0, 0 }, + { /* 26: 1 1110 1011 */ 9, 491, 0, 5, 0, 0 }, + { /* 27: 1 1110 1100 */ 9, 492, 6, 1, 0, 0 }, + { /* 28: 1 1110 1101 */ 9, 493, 5, 0, 0, 0 }, + { /* 29: 1 1110 1110 */ 9, 494, 1, 6, 0, 0 }, + { /* 30: 1 1110 1111 */ 9, 495, 4, 3, 0, 0 }, + { /* 31: 1 1111 0000 */ 9, 496, 3, 5, 0, 0 }, + { /* 32: 1 1111 0001 */ 9, 497, 3, 4, 0, 0 }, + { /* 33: 1 1111 0010 */ 9, 498, 5, 3, 0, 0 }, + { /* 34: 1 1111 0011 */ 9, 499, 2, 6, 0, 0 }, + { /* 35: 1 1111 0100 */ 9, 500, 6, 2, 0, 0 }, + { /* 36: 1 1111 0101 */ 9, 501, 1, 7, 0, 0 }, + { /* 37: 11 1110 1100 */ 10, 1004, 3, 6, 0, 0 }, + { /* 38: 11 1110 1101 */ 10, 1005, 0, 6, 0, 0 }, + { /* 39: 11 1110 1110 */ 10, 1006, 6, 0, 0, 0 }, + { /* 40: 11 1110 1111 */ 10, 1007, 4, 4, 0, 0 }, + { /* 41: 11 1111 0000 */ 10, 1008, 7, 1, 0, 0 }, + { /* 42: 11 1111 0001 */ 10, 1009, 4, 5, 0, 0 }, + { /* 43: 11 1111 0010 */ 10, 1010, 7, 2, 0, 0 }, + { /* 44: 11 1111 0011 */ 10, 1011, 5, 4, 0, 0 }, + { /* 45: 11 1111 0100 */ 10, 1012, 6, 3, 0, 0 }, + { /* 46: 11 1111 0101 */ 10, 1013, 2, 7, 0, 0 }, + { /* 47: 11 1111 0110 */ 10, 1014, 7, 3, 0, 0 }, + { /* 48: 11 1111 0111 */ 10, 1015, 6, 4, 0, 0 }, + { /* 49: 11 1111 1000 */ 10, 1016, 5, 5, 0, 0 }, + { /* 50: 11 1111 1001 */ 10, 1017, 4, 6, 0, 0 }, + { /* 51: 11 1111 1010 */ 10, 1018, 3, 7, 0, 0 }, + { /* 52: 111 1111 0110 */ 11, 2038, 7, 0, 0, 0 }, + { /* 53: 111 1111 0111 */ 11, 2039, 0, 7, 0, 0 }, + { /* 54: 111 1111 1000 */ 11, 2040, 6, 5, 0, 0 }, + { /* 55: 111 1111 1001 */ 11, 2041, 5, 6, 0, 0 }, + { /* 56: 111 1111 1010 */ 11, 2042, 7, 4, 0, 0 }, + { /* 57: 111 1111 1011 */ 11, 2043, 4, 7, 0, 0 }, + { /* 58: 111 1111 1100 */ 11, 2044, 5, 7, 0, 0 }, + { /* 59: 111 1111 1101 */ 11, 2045, 7, 5, 0, 0 }, + { /* 60: 1111 1111 1100 */ 12, 4092, 7, 6, 0, 0 }, + { /* 61: 1111 1111 1101 */ 12, 4093, 6, 6, 0, 0 }, + { /* 62: 1111 1111 1110 */ 12, 4094, 6, 7, 0, 0 }, + { /* 63: 1111 1111 1111 */ 12, 4095, 7, 7, 0, 0 } +}; + +Huffman book8[] = { + /* idx codeword len codew x y v w */ + { /* 0: 000 */ 3, 0, 1, 1, 0, 0 }, + { /* 1: 0010 */ 4, 2, 2, 1, 0, 0 }, + { /* 2: 0011 */ 4, 3, 1, 0, 0, 0 }, + { /* 3: 0100 */ 4, 4, 1, 2, 0, 0 }, + { /* 4: 0101 */ 4, 5, 0, 1, 0, 0 }, + { /* 5: 0110 */ 4, 6, 2, 2, 0, 0 }, + { /* 6: 0 1110 */ 5, 14, 0, 0, 0, 0 }, + { /* 7: 0 1111 */ 5, 15, 2, 0, 0, 0 }, + { /* 8: 1 0000 */ 5, 16, 0, 2, 0, 0 }, + { /* 9: 1 0001 */ 5, 17, 3, 1, 0, 0 }, + { /* 10: 1 0010 */ 5, 18, 1, 3, 0, 0 }, + { /* 11: 1 0011 */ 5, 19, 3, 2, 0, 0 }, + { /* 12: 1 0100 */ 5, 20, 2, 3, 0, 0 }, + { /* 13: 10 1010 */ 6, 42, 3, 3, 0, 0 }, + { /* 14: 10 1011 */ 6, 43, 4, 1, 0, 0 }, + { /* 15: 10 1100 */ 6, 44, 1, 4, 0, 0 }, + { /* 16: 10 1101 */ 6, 45, 4, 2, 0, 0 }, + { /* 17: 10 1110 */ 6, 46, 2, 4, 0, 0 }, + { /* 18: 10 1111 */ 6, 47, 3, 0, 0, 0 }, + { /* 19: 11 0000 */ 6, 48, 0, 3, 0, 0 }, + { /* 20: 11 0001 */ 6, 49, 4, 3, 0, 0 }, + { /* 21: 11 0010 */ 6, 50, 3, 4, 0, 0 }, + { /* 22: 11 0011 */ 6, 51, 5, 2, 0, 0 }, + { /* 23: 110 1000 */ 7, 104, 5, 1, 0, 0 }, + { /* 24: 110 1001 */ 7, 105, 2, 5, 0, 0 }, + { /* 25: 110 1010 */ 7, 106, 1, 5, 0, 0 }, + { /* 26: 110 1011 */ 7, 107, 5, 3, 0, 0 }, + { /* 27: 110 1100 */ 7, 108, 3, 5, 0, 0 }, + { /* 28: 110 1101 */ 7, 109, 4, 4, 0, 0 }, + { /* 29: 110 1110 */ 7, 110, 5, 4, 0, 0 }, + { /* 30: 110 1111 */ 7, 111, 0, 4, 0, 0 }, + { /* 31: 111 0000 */ 7, 112, 4, 5, 0, 0 }, + { /* 32: 111 0001 */ 7, 113, 4, 0, 0, 0 }, + { /* 33: 111 0010 */ 7, 114, 2, 6, 0, 0 }, + { /* 34: 111 0011 */ 7, 115, 6, 2, 0, 0 }, + { /* 35: 111 0100 */ 7, 116, 6, 1, 0, 0 }, + { /* 36: 111 0101 */ 7, 117, 1, 6, 0, 0 }, + { /* 37: 1110 1100 */ 8, 236, 3, 6, 0, 0 }, + { /* 38: 1110 1101 */ 8, 237, 6, 3, 0, 0 }, + { /* 39: 1110 1110 */ 8, 238, 5, 5, 0, 0 }, + { /* 40: 1110 1111 */ 8, 239, 5, 0, 0, 0 }, + { /* 41: 1111 0000 */ 8, 240, 6, 4, 0, 0 }, + { /* 42: 1111 0001 */ 8, 241, 0, 5, 0, 0 }, + { /* 43: 1111 0010 */ 8, 242, 4, 6, 0, 0 }, + { /* 44: 1111 0011 */ 8, 243, 7, 1, 0, 0 }, + { /* 45: 1111 0100 */ 8, 244, 7, 2, 0, 0 }, + { /* 46: 1111 0101 */ 8, 245, 2, 7, 0, 0 }, + { /* 47: 1111 0110 */ 8, 246, 6, 5, 0, 0 }, + { /* 48: 1111 0111 */ 8, 247, 7, 3, 0, 0 }, + { /* 49: 1111 1000 */ 8, 248, 1, 7, 0, 0 }, + { /* 50: 1111 1001 */ 8, 249, 5, 6, 0, 0 }, + { /* 51: 1111 1010 */ 8, 250, 3, 7, 0, 0 }, + { /* 52: 1 1111 0110 */ 9, 502, 6, 6, 0, 0 }, + { /* 53: 1 1111 0111 */ 9, 503, 7, 4, 0, 0 }, + { /* 54: 1 1111 1000 */ 9, 504, 6, 0, 0, 0 }, + { /* 55: 1 1111 1001 */ 9, 505, 4, 7, 0, 0 }, + { /* 56: 1 1111 1010 */ 9, 506, 0, 6, 0, 0 }, + { /* 57: 1 1111 1011 */ 9, 507, 7, 5, 0, 0 }, + { /* 58: 1 1111 1100 */ 9, 508, 7, 6, 0, 0 }, + { /* 59: 1 1111 1101 */ 9, 509, 6, 7, 0, 0 }, + { /* 60: 11 1111 1100 */ 10, 1020, 5, 7, 0, 0 }, + { /* 61: 11 1111 1101 */ 10, 1021, 7, 0, 0, 0 }, + { /* 62: 11 1111 1110 */ 10, 1022, 0, 7, 0, 0 }, + { /* 63: 11 1111 1111 */ 10, 1023, 7, 7, 0, 0 } +}; + +Huffman book9[] = { + /* idx codeword len codew x y v w */ + { /* 0: 0 */ 1, 0, 0, 0, 0, 0 }, + { /* 1: 100 */ 3, 4, 1, 0, 0, 0 }, + { /* 2: 101 */ 3, 5, 0, 1, 0, 0 }, + { /* 3: 1100 */ 4, 12, 1, 1, 0, 0 }, + { /* 4: 11 0100 */ 6, 52, 2, 1, 0, 0 }, + { /* 5: 11 0101 */ 6, 53, 1, 2, 0, 0 }, + { /* 6: 11 0110 */ 6, 54, 2, 0, 0, 0 }, + { /* 7: 11 0111 */ 6, 55, 0, 2, 0, 0 }, + { /* 8: 111 0000 */ 7, 112, 3, 1, 0, 0 }, + { /* 9: 111 0001 */ 7, 113, 2, 2, 0, 0 }, + { /* 10: 111 0010 */ 7, 114, 1, 3, 0, 0 }, + { /* 11: 1110 0110 */ 8, 230, 3, 0, 0, 0 }, + { /* 12: 1110 0111 */ 8, 231, 0, 3, 0, 0 }, + { /* 13: 1110 1000 */ 8, 232, 2, 3, 0, 0 }, + { /* 14: 1110 1001 */ 8, 233, 3, 2, 0, 0 }, + { /* 15: 1110 1010 */ 8, 234, 1, 4, 0, 0 }, + { /* 16: 1110 1011 */ 8, 235, 4, 1, 0, 0 }, + { /* 17: 1110 1100 */ 8, 236, 2, 4, 0, 0 }, + { /* 18: 1110 1101 */ 8, 237, 1, 5, 0, 0 }, + { /* 19: 1 1101 1100 */ 9, 476, 4, 2, 0, 0 }, + { /* 20: 1 1101 1101 */ 9, 477, 3, 3, 0, 0 }, + { /* 21: 1 1101 1110 */ 9, 478, 0, 4, 0, 0 }, + { /* 22: 1 1101 1111 */ 9, 479, 4, 0, 0, 0 }, + { /* 23: 1 1110 0000 */ 9, 480, 5, 1, 0, 0 }, + { /* 24: 1 1110 0001 */ 9, 481, 2, 5, 0, 0 }, + { /* 25: 1 1110 0010 */ 9, 482, 1, 6, 0, 0 }, + { /* 26: 1 1110 0011 */ 9, 483, 3, 4, 0, 0 }, + { /* 27: 1 1110 0100 */ 9, 484, 5, 2, 0, 0 }, + { /* 28: 1 1110 0101 */ 9, 485, 6, 1, 0, 0 }, + { /* 29: 1 1110 0110 */ 9, 486, 4, 3, 0, 0 }, + { /* 30: 11 1100 1110 */ 10, 974, 0, 5, 0, 0 }, + { /* 31: 11 1100 1111 */ 10, 975, 2, 6, 0, 0 }, + { /* 32: 11 1101 0000 */ 10, 976, 5, 0, 0, 0 }, + { /* 33: 11 1101 0001 */ 10, 977, 1, 7, 0, 0 }, + { /* 34: 11 1101 0010 */ 10, 978, 3, 5, 0, 0 }, + { /* 35: 11 1101 0011 */ 10, 979, 1, 8, 0, 0 }, + { /* 36: 11 1101 0100 */ 10, 980, 8, 1, 0, 0 }, + { /* 37: 11 1101 0101 */ 10, 981, 4, 4, 0, 0 }, + { /* 38: 11 1101 0110 */ 10, 982, 5, 3, 0, 0 }, + { /* 39: 11 1101 0111 */ 10, 983, 6, 2, 0, 0 }, + { /* 40: 11 1101 1000 */ 10, 984, 7, 1, 0, 0 }, + { /* 41: 11 1101 1001 */ 10, 985, 0, 6, 0, 0 }, + { /* 42: 11 1101 1010 */ 10, 986, 8, 2, 0, 0 }, + { /* 43: 11 1101 1011 */ 10, 987, 2, 8, 0, 0 }, + { /* 44: 11 1101 1100 */ 10, 988, 3, 6, 0, 0 }, + { /* 45: 11 1101 1101 */ 10, 989, 2, 7, 0, 0 }, + { /* 46: 11 1101 1110 */ 10, 990, 4, 5, 0, 0 }, + { /* 47: 11 1101 1111 */ 10, 991, 9, 1, 0, 0 }, + { /* 48: 11 1110 0000 */ 10, 992, 1, 9, 0, 0 }, + { /* 49: 11 1110 0001 */ 10, 993, 7, 2, 0, 0 }, + { /* 50: 111 1100 0100 */ 11, 1988, 6, 0, 0, 0 }, + { /* 51: 111 1100 0101 */ 11, 1989, 5, 4, 0, 0 }, + { /* 52: 111 1100 0110 */ 11, 1990, 6, 3, 0, 0 }, + { /* 53: 111 1100 0111 */ 11, 1991, 8, 3, 0, 0 }, + { /* 54: 111 1100 1000 */ 11, 1992, 0, 7, 0, 0 }, + { /* 55: 111 1100 1001 */ 11, 1993, 9, 2, 0, 0 }, + { /* 56: 111 1100 1010 */ 11, 1994, 3, 8, 0, 0 }, + { /* 57: 111 1100 1011 */ 11, 1995, 4, 6, 0, 0 }, + { /* 58: 111 1100 1100 */ 11, 1996, 3, 7, 0, 0 }, + { /* 59: 111 1100 1101 */ 11, 1997, 0, 8, 0, 0 }, + { /* 60: 111 1100 1110 */ 11, 1998, 10, 1, 0, 0 }, + { /* 61: 111 1100 1111 */ 11, 1999, 6, 4, 0, 0 }, + { /* 62: 111 1101 0000 */ 11, 2000, 2, 9, 0, 0 }, + { /* 63: 111 1101 0001 */ 11, 2001, 5, 5, 0, 0 }, + { /* 64: 111 1101 0010 */ 11, 2002, 8, 0, 0, 0 }, + { /* 65: 111 1101 0011 */ 11, 2003, 7, 0, 0, 0 }, + { /* 66: 111 1101 0100 */ 11, 2004, 7, 3, 0, 0 }, + { /* 67: 111 1101 0101 */ 11, 2005, 10, 2, 0, 0 }, + { /* 68: 111 1101 0110 */ 11, 2006, 9, 3, 0, 0 }, + { /* 69: 111 1101 0111 */ 11, 2007, 8, 4, 0, 0 }, + { /* 70: 111 1101 1000 */ 11, 2008, 1, 10, 0, 0 }, + { /* 71: 111 1101 1001 */ 11, 2009, 7, 4, 0, 0 }, + { /* 72: 111 1101 1010 */ 11, 2010, 6, 5, 0, 0 }, + { /* 73: 111 1101 1011 */ 11, 2011, 5, 6, 0, 0 }, + { /* 74: 111 1101 1100 */ 11, 2012, 4, 8, 0, 0 }, + { /* 75: 111 1101 1101 */ 11, 2013, 4, 7, 0, 0 }, + { /* 76: 111 1101 1110 */ 11, 2014, 3, 9, 0, 0 }, + { /* 77: 111 1101 1111 */ 11, 2015, 11, 1, 0, 0 }, + { /* 78: 111 1110 0000 */ 11, 2016, 5, 8, 0, 0 }, + { /* 79: 111 1110 0001 */ 11, 2017, 9, 0, 0, 0 }, + { /* 80: 111 1110 0010 */ 11, 2018, 8, 5, 0, 0 }, + { /* 81: 1111 1100 0110 */ 12, 4038, 10, 3, 0, 0 }, + { /* 82: 1111 1100 0111 */ 12, 4039, 2, 10, 0, 0 }, + { /* 83: 1111 1100 1000 */ 12, 4040, 0, 9, 0, 0 }, + { /* 84: 1111 1100 1001 */ 12, 4041, 11, 2, 0, 0 }, + { /* 85: 1111 1100 1010 */ 12, 4042, 9, 4, 0, 0 }, + { /* 86: 1111 1100 1011 */ 12, 4043, 6, 6, 0, 0 }, + { /* 87: 1111 1100 1100 */ 12, 4044, 12, 1, 0, 0 }, + { /* 88: 1111 1100 1101 */ 12, 4045, 4, 9, 0, 0 }, + { /* 89: 1111 1100 1110 */ 12, 4046, 8, 6, 0, 0 }, + { /* 90: 1111 1100 1111 */ 12, 4047, 1, 11, 0, 0 }, + { /* 91: 1111 1101 0000 */ 12, 4048, 9, 5, 0, 0 }, + { /* 92: 1111 1101 0001 */ 12, 4049, 10, 4, 0, 0 }, + { /* 93: 1111 1101 0010 */ 12, 4050, 5, 7, 0, 0 }, + { /* 94: 1111 1101 0011 */ 12, 4051, 7, 5, 0, 0 }, + { /* 95: 1111 1101 0100 */ 12, 4052, 2, 11, 0, 0 }, + { /* 96: 1111 1101 0101 */ 12, 4053, 1, 12, 0, 0 }, + { /* 97: 1111 1101 0110 */ 12, 4054, 12, 2, 0, 0 }, + { /* 98: 1111 1101 0111 */ 12, 4055, 11, 3, 0, 0 }, + { /* 99: 1111 1101 1000 */ 12, 4056, 3, 10, 0, 0 }, + { /* 100: 1111 1101 1001 */ 12, 4057, 5, 9, 0, 0 }, + { /* 101: 1111 1101 1010 */ 12, 4058, 6, 7, 0, 0 }, + { /* 102: 1111 1101 1011 */ 12, 4059, 8, 7, 0, 0 }, + { /* 103: 1111 1101 1100 */ 12, 4060, 11, 4, 0, 0 }, + { /* 104: 1111 1101 1101 */ 12, 4061, 0, 10, 0, 0 }, + { /* 105: 1111 1101 1110 */ 12, 4062, 7, 6, 0, 0 }, + { /* 106: 1111 1101 1111 */ 12, 4063, 12, 3, 0, 0 }, + { /* 107: 1111 1110 0000 */ 12, 4064, 10, 0, 0, 0 }, + { /* 108: 1111 1110 0001 */ 12, 4065, 10, 5, 0, 0 }, + { /* 109: 1111 1110 0010 */ 12, 4066, 4, 10, 0, 0 }, + { /* 110: 1111 1110 0011 */ 12, 4067, 6, 8, 0, 0 }, + { /* 111: 1111 1110 0100 */ 12, 4068, 2, 12, 0, 0 }, + { /* 112: 1111 1110 0101 */ 12, 4069, 9, 6, 0, 0 }, + { /* 113: 1111 1110 0110 */ 12, 4070, 9, 7, 0, 0 }, + { /* 114: 1111 1110 0111 */ 12, 4071, 4, 11, 0, 0 }, + { /* 115: 1111 1110 1000 */ 12, 4072, 11, 0, 0, 0 }, + { /* 116: 1111 1110 1001 */ 12, 4073, 6, 9, 0, 0 }, + { /* 117: 1111 1110 1010 */ 12, 4074, 3, 11, 0, 0 }, + { /* 118: 1111 1110 1011 */ 12, 4075, 5, 10, 0, 0 }, + { /* 119: 1 1111 1101 1000 */ 13, 8152, 8, 8, 0, 0 }, + { /* 120: 1 1111 1101 1001 */ 13, 8153, 7, 8, 0, 0 }, + { /* 121: 1 1111 1101 1010 */ 13, 8154, 12, 5, 0, 0 }, + { /* 122: 1 1111 1101 1011 */ 13, 8155, 3, 12, 0, 0 }, + { /* 123: 1 1111 1101 1100 */ 13, 8156, 11, 5, 0, 0 }, + { /* 124: 1 1111 1101 1101 */ 13, 8157, 7, 7, 0, 0 }, + { /* 125: 1 1111 1101 1110 */ 13, 8158, 12, 4, 0, 0 }, + { /* 126: 1 1111 1101 1111 */ 13, 8159, 11, 6, 0, 0 }, + { /* 127: 1 1111 1110 0000 */ 13, 8160, 10, 6, 0, 0 }, + { /* 128: 1 1111 1110 0001 */ 13, 8161, 4, 12, 0, 0 }, + { /* 129: 1 1111 1110 0010 */ 13, 8162, 7, 9, 0, 0 }, + { /* 130: 1 1111 1110 0011 */ 13, 8163, 5, 11, 0, 0 }, + { /* 131: 1 1111 1110 0100 */ 13, 8164, 0, 11, 0, 0 }, + { /* 132: 1 1111 1110 0101 */ 13, 8165, 12, 6, 0, 0 }, + { /* 133: 1 1111 1110 0110 */ 13, 8166, 6, 10, 0, 0 }, + { /* 134: 1 1111 1110 0111 */ 13, 8167, 12, 0, 0, 0 }, + { /* 135: 1 1111 1110 1000 */ 13, 8168, 10, 7, 0, 0 }, + { /* 136: 1 1111 1110 1001 */ 13, 8169, 5, 12, 0, 0 }, + { /* 137: 1 1111 1110 1010 */ 13, 8170, 7, 10, 0, 0 }, + { /* 138: 1 1111 1110 1011 */ 13, 8171, 9, 8, 0, 0 }, + { /* 139: 1 1111 1110 1100 */ 13, 8172, 0, 12, 0, 0 }, + { /* 140: 1 1111 1110 1101 */ 13, 8173, 11, 7, 0, 0 }, + { /* 141: 1 1111 1110 1110 */ 13, 8174, 8, 9, 0, 0 }, + { /* 142: 1 1111 1110 1111 */ 13, 8175, 9, 9, 0, 0 }, + { /* 143: 1 1111 1111 0000 */ 13, 8176, 10, 8, 0, 0 }, + { /* 144: 1 1111 1111 0001 */ 13, 8177, 7, 11, 0, 0 }, + { /* 145: 1 1111 1111 0010 */ 13, 8178, 12, 7, 0, 0 }, + { /* 146: 1 1111 1111 0011 */ 13, 8179, 6, 11, 0, 0 }, + { /* 147: 1 1111 1111 0100 */ 13, 8180, 8, 11, 0, 0 }, + { /* 148: 1 1111 1111 0101 */ 13, 8181, 11, 8, 0, 0 }, + { /* 149: 1 1111 1111 0110 */ 13, 8182, 7, 12, 0, 0 }, + { /* 150: 1 1111 1111 0111 */ 13, 8183, 6, 12, 0, 0 }, + { /* 151: 11 1111 1111 0000 */ 14, 16368, 8, 10, 0, 0 }, + { /* 152: 11 1111 1111 0001 */ 14, 16369, 10, 9, 0, 0 }, + { /* 153: 11 1111 1111 0010 */ 14, 16370, 8, 12, 0, 0 }, + { /* 154: 11 1111 1111 0011 */ 14, 16371, 9, 10, 0, 0 }, + { /* 155: 11 1111 1111 0100 */ 14, 16372, 9, 11, 0, 0 }, + { /* 156: 11 1111 1111 0101 */ 14, 16373, 9, 12, 0, 0 }, + { /* 157: 11 1111 1111 0110 */ 14, 16374, 10, 11, 0, 0 }, + { /* 158: 11 1111 1111 0111 */ 14, 16375, 12, 9, 0, 0 }, + { /* 159: 11 1111 1111 1000 */ 14, 16376, 10, 10, 0, 0 }, + { /* 160: 11 1111 1111 1001 */ 14, 16377, 11, 9, 0, 0 }, + { /* 161: 11 1111 1111 1010 */ 14, 16378, 12, 8, 0, 0 }, + { /* 162: 11 1111 1111 1011 */ 14, 16379, 11, 10, 0, 0 }, + { /* 163: 11 1111 1111 1100 */ 14, 16380, 12, 10, 0, 0 }, + { /* 164: 11 1111 1111 1101 */ 14, 16381, 12, 11, 0, 0 }, + { /* 165: 111 1111 1111 1100 */ 15, 32764, 10, 12, 0, 0 }, + { /* 166: 111 1111 1111 1101 */ 15, 32765, 11, 11, 0, 0 }, + { /* 167: 111 1111 1111 1110 */ 15, 32766, 11, 12, 0, 0 }, + { /* 168: 111 1111 1111 1111 */ 15, 32767, 12, 12, 0, 0 } +}; + +Huffman book10[] = { + /* idx codeword len codew x y v w */ + { /* 0: 0000 */ 4, 0, 1, 1, 0, 0 }, + { /* 1: 0001 */ 4, 1, 1, 2, 0, 0 }, + { /* 2: 0010 */ 4, 2, 2, 1, 0, 0 }, + { /* 3: 0 0110 */ 5, 6, 2, 2, 0, 0 }, + { /* 4: 0 0111 */ 5, 7, 1, 0, 0, 0 }, + { /* 5: 0 1000 */ 5, 8, 0, 1, 0, 0 }, + { /* 6: 0 1001 */ 5, 9, 1, 3, 0, 0 }, + { /* 7: 0 1010 */ 5, 10, 3, 2, 0, 0 }, + { /* 8: 0 1011 */ 5, 11, 3, 1, 0, 0 }, + { /* 9: 0 1100 */ 5, 12, 2, 3, 0, 0 }, + { /* 10: 0 1101 */ 5, 13, 3, 3, 0, 0 }, + { /* 11: 01 1100 */ 6, 28, 2, 0, 0, 0 }, + { /* 12: 01 1101 */ 6, 29, 0, 2, 0, 0 }, + { /* 13: 01 1110 */ 6, 30, 2, 4, 0, 0 }, + { /* 14: 01 1111 */ 6, 31, 4, 2, 0, 0 }, + { /* 15: 10 0000 */ 6, 32, 1, 4, 0, 0 }, + { /* 16: 10 0001 */ 6, 33, 4, 1, 0, 0 }, + { /* 17: 10 0010 */ 6, 34, 0, 0, 0, 0 }, + { /* 18: 10 0011 */ 6, 35, 4, 3, 0, 0 }, + { /* 19: 10 0100 */ 6, 36, 3, 4, 0, 0 }, + { /* 20: 10 0101 */ 6, 37, 3, 0, 0, 0 }, + { /* 21: 10 0110 */ 6, 38, 0, 3, 0, 0 }, + { /* 22: 10 0111 */ 6, 39, 4, 4, 0, 0 }, + { /* 23: 10 1000 */ 6, 40, 2, 5, 0, 0 }, + { /* 24: 10 1001 */ 6, 41, 5, 2, 0, 0 }, + { /* 25: 101 0100 */ 7, 84, 1, 5, 0, 0 }, + { /* 26: 101 0101 */ 7, 85, 5, 1, 0, 0 }, + { /* 27: 101 0110 */ 7, 86, 5, 3, 0, 0 }, + { /* 28: 101 0111 */ 7, 87, 3, 5, 0, 0 }, + { /* 29: 101 1000 */ 7, 88, 5, 4, 0, 0 }, + { /* 30: 101 1001 */ 7, 89, 4, 5, 0, 0 }, + { /* 31: 101 1010 */ 7, 90, 6, 2, 0, 0 }, + { /* 32: 101 1011 */ 7, 91, 2, 6, 0, 0 }, + { /* 33: 101 1100 */ 7, 92, 6, 3, 0, 0 }, + { /* 34: 101 1101 */ 7, 93, 4, 0, 0, 0 }, + { /* 35: 101 1110 */ 7, 94, 6, 1, 0, 0 }, + { /* 36: 101 1111 */ 7, 95, 0, 4, 0, 0 }, + { /* 37: 110 0000 */ 7, 96, 1, 6, 0, 0 }, + { /* 38: 110 0001 */ 7, 97, 3, 6, 0, 0 }, + { /* 39: 110 0010 */ 7, 98, 5, 5, 0, 0 }, + { /* 40: 110 0011 */ 7, 99, 6, 4, 0, 0 }, + { /* 41: 110 0100 */ 7, 100, 4, 6, 0, 0 }, + { /* 42: 1100 1010 */ 8, 202, 6, 5, 0, 0 }, + { /* 43: 1100 1011 */ 8, 203, 7, 2, 0, 0 }, + { /* 44: 1100 1100 */ 8, 204, 3, 7, 0, 0 }, + { /* 45: 1100 1101 */ 8, 205, 2, 7, 0, 0 }, + { /* 46: 1100 1110 */ 8, 206, 5, 6, 0, 0 }, + { /* 47: 1100 1111 */ 8, 207, 8, 2, 0, 0 }, + { /* 48: 1101 0000 */ 8, 208, 7, 3, 0, 0 }, + { /* 49: 1101 0001 */ 8, 209, 5, 0, 0, 0 }, + { /* 50: 1101 0010 */ 8, 210, 7, 1, 0, 0 }, + { /* 51: 1101 0011 */ 8, 211, 0, 5, 0, 0 }, + { /* 52: 1101 0100 */ 8, 212, 8, 1, 0, 0 }, + { /* 53: 1101 0101 */ 8, 213, 1, 7, 0, 0 }, + { /* 54: 1101 0110 */ 8, 214, 8, 3, 0, 0 }, + { /* 55: 1101 0111 */ 8, 215, 7, 4, 0, 0 }, + { /* 56: 1101 1000 */ 8, 216, 4, 7, 0, 0 }, + { /* 57: 1101 1001 */ 8, 217, 2, 8, 0, 0 }, + { /* 58: 1101 1010 */ 8, 218, 6, 6, 0, 0 }, + { /* 59: 1101 1011 */ 8, 219, 7, 5, 0, 0 }, + { /* 60: 1101 1100 */ 8, 220, 1, 8, 0, 0 }, + { /* 61: 1101 1101 */ 8, 221, 3, 8, 0, 0 }, + { /* 62: 1101 1110 */ 8, 222, 8, 4, 0, 0 }, + { /* 63: 1101 1111 */ 8, 223, 4, 8, 0, 0 }, + { /* 64: 1110 0000 */ 8, 224, 5, 7, 0, 0 }, + { /* 65: 1110 0001 */ 8, 225, 8, 5, 0, 0 }, + { /* 66: 1110 0010 */ 8, 226, 5, 8, 0, 0 }, + { /* 67: 1 1100 0110 */ 9, 454, 7, 6, 0, 0 }, + { /* 68: 1 1100 0111 */ 9, 455, 6, 7, 0, 0 }, + { /* 69: 1 1100 1000 */ 9, 456, 9, 2, 0, 0 }, + { /* 70: 1 1100 1001 */ 9, 457, 6, 0, 0, 0 }, + { /* 71: 1 1100 1010 */ 9, 458, 6, 8, 0, 0 }, + { /* 72: 1 1100 1011 */ 9, 459, 9, 3, 0, 0 }, + { /* 73: 1 1100 1100 */ 9, 460, 3, 9, 0, 0 }, + { /* 74: 1 1100 1101 */ 9, 461, 9, 1, 0, 0 }, + { /* 75: 1 1100 1110 */ 9, 462, 2, 9, 0, 0 }, + { /* 76: 1 1100 1111 */ 9, 463, 0, 6, 0, 0 }, + { /* 77: 1 1101 0000 */ 9, 464, 8, 6, 0, 0 }, + { /* 78: 1 1101 0001 */ 9, 465, 9, 4, 0, 0 }, + { /* 79: 1 1101 0010 */ 9, 466, 4, 9, 0, 0 }, + { /* 80: 1 1101 0011 */ 9, 467, 10, 2, 0, 0 }, + { /* 81: 1 1101 0100 */ 9, 468, 1, 9, 0, 0 }, + { /* 82: 1 1101 0101 */ 9, 469, 7, 7, 0, 0 }, + { /* 83: 1 1101 0110 */ 9, 470, 8, 7, 0, 0 }, + { /* 84: 1 1101 0111 */ 9, 471, 9, 5, 0, 0 }, + { /* 85: 1 1101 1000 */ 9, 472, 7, 8, 0, 0 }, + { /* 86: 1 1101 1001 */ 9, 473, 10, 3, 0, 0 }, + { /* 87: 1 1101 1010 */ 9, 474, 5, 9, 0, 0 }, + { /* 88: 1 1101 1011 */ 9, 475, 10, 4, 0, 0 }, + { /* 89: 1 1101 1100 */ 9, 476, 2, 10, 0, 0 }, + { /* 90: 1 1101 1101 */ 9, 477, 10, 1, 0, 0 }, + { /* 91: 1 1101 1110 */ 9, 478, 3, 10, 0, 0 }, + { /* 92: 1 1101 1111 */ 9, 479, 9, 6, 0, 0 }, + { /* 93: 1 1110 0000 */ 9, 480, 6, 9, 0, 0 }, + { /* 94: 1 1110 0001 */ 9, 481, 8, 0, 0, 0 }, + { /* 95: 1 1110 0010 */ 9, 482, 4, 10, 0, 0 }, + { /* 96: 1 1110 0011 */ 9, 483, 7, 0, 0, 0 }, + { /* 97: 1 1110 0100 */ 9, 484, 11, 2, 0, 0 }, + { /* 98: 11 1100 1010 */ 10, 970, 7, 9, 0, 0 }, + { /* 99: 11 1100 1011 */ 10, 971, 11, 3, 0, 0 }, + { /* 100: 11 1100 1100 */ 10, 972, 10, 6, 0, 0 }, + { /* 101: 11 1100 1101 */ 10, 973, 1, 10, 0, 0 }, + { /* 102: 11 1100 1110 */ 10, 974, 11, 1, 0, 0 }, + { /* 103: 11 1100 1111 */ 10, 975, 9, 7, 0, 0 }, + { /* 104: 11 1101 0000 */ 10, 976, 0, 7, 0, 0 }, + { /* 105: 11 1101 0001 */ 10, 977, 8, 8, 0, 0 }, + { /* 106: 11 1101 0010 */ 10, 978, 10, 5, 0, 0 }, + { /* 107: 11 1101 0011 */ 10, 979, 3, 11, 0, 0 }, + { /* 108: 11 1101 0100 */ 10, 980, 5, 10, 0, 0 }, + { /* 109: 11 1101 0101 */ 10, 981, 8, 9, 0, 0 }, + { /* 110: 11 1101 0110 */ 10, 982, 11, 5, 0, 0 }, + { /* 111: 11 1101 0111 */ 10, 983, 0, 8, 0, 0 }, + { /* 112: 11 1101 1000 */ 10, 984, 11, 4, 0, 0 }, + { /* 113: 11 1101 1001 */ 10, 985, 2, 11, 0, 0 }, + { /* 114: 11 1101 1010 */ 10, 986, 7, 10, 0, 0 }, + { /* 115: 11 1101 1011 */ 10, 987, 6, 10, 0, 0 }, + { /* 116: 11 1101 1100 */ 10, 988, 10, 7, 0, 0 }, + { /* 117: 11 1101 1101 */ 10, 989, 4, 11, 0, 0 }, + { /* 118: 11 1101 1110 */ 10, 990, 1, 11, 0, 0 }, + { /* 119: 11 1101 1111 */ 10, 991, 12, 2, 0, 0 }, + { /* 120: 11 1110 0000 */ 10, 992, 9, 8, 0, 0 }, + { /* 121: 11 1110 0001 */ 10, 993, 12, 3, 0, 0 }, + { /* 122: 11 1110 0010 */ 10, 994, 11, 6, 0, 0 }, + { /* 123: 11 1110 0011 */ 10, 995, 5, 11, 0, 0 }, + { /* 124: 11 1110 0100 */ 10, 996, 12, 4, 0, 0 }, + { /* 125: 11 1110 0101 */ 10, 997, 11, 7, 0, 0 }, + { /* 126: 11 1110 0110 */ 10, 998, 12, 5, 0, 0 }, + { /* 127: 11 1110 0111 */ 10, 999, 3, 12, 0, 0 }, + { /* 128: 11 1110 1000 */ 10, 1000, 6, 11, 0, 0 }, + { /* 129: 11 1110 1001 */ 10, 1001, 9, 0, 0, 0 }, + { /* 130: 11 1110 1010 */ 10, 1002, 10, 8, 0, 0 }, + { /* 131: 11 1110 1011 */ 10, 1003, 10, 0, 0, 0 }, + { /* 132: 11 1110 1100 */ 10, 1004, 12, 1, 0, 0 }, + { /* 133: 11 1110 1101 */ 10, 1005, 0, 9, 0, 0 }, + { /* 134: 11 1110 1110 */ 10, 1006, 4, 12, 0, 0 }, + { /* 135: 11 1110 1111 */ 10, 1007, 9, 9, 0, 0 }, + { /* 136: 11 1111 0000 */ 10, 1008, 12, 6, 0, 0 }, + { /* 137: 11 1111 0001 */ 10, 1009, 2, 12, 0, 0 }, + { /* 138: 11 1111 0010 */ 10, 1010, 8, 10, 0, 0 }, + { /* 139: 111 1110 0110 */ 11, 2022, 9, 10, 0, 0 }, + { /* 140: 111 1110 0111 */ 11, 2023, 1, 12, 0, 0 }, + { /* 141: 111 1110 1000 */ 11, 2024, 11, 8, 0, 0 }, + { /* 142: 111 1110 1001 */ 11, 2025, 12, 7, 0, 0 }, + { /* 143: 111 1110 1010 */ 11, 2026, 7, 11, 0, 0 }, + { /* 144: 111 1110 1011 */ 11, 2027, 5, 12, 0, 0 }, + { /* 145: 111 1110 1100 */ 11, 2028, 6, 12, 0, 0 }, + { /* 146: 111 1110 1101 */ 11, 2029, 10, 9, 0, 0 }, + { /* 147: 111 1110 1110 */ 11, 2030, 8, 11, 0, 0 }, + { /* 148: 111 1110 1111 */ 11, 2031, 12, 8, 0, 0 }, + { /* 149: 111 1111 0000 */ 11, 2032, 0, 10, 0, 0 }, + { /* 150: 111 1111 0001 */ 11, 2033, 7, 12, 0, 0 }, + { /* 151: 111 1111 0010 */ 11, 2034, 11, 0, 0, 0 }, + { /* 152: 111 1111 0011 */ 11, 2035, 10, 10, 0, 0 }, + { /* 153: 111 1111 0100 */ 11, 2036, 11, 9, 0, 0 }, + { /* 154: 111 1111 0101 */ 11, 2037, 11, 10, 0, 0 }, + { /* 155: 111 1111 0110 */ 11, 2038, 0, 11, 0, 0 }, + { /* 156: 111 1111 0111 */ 11, 2039, 11, 11, 0, 0 }, + { /* 157: 111 1111 1000 */ 11, 2040, 9, 11, 0, 0 }, + { /* 158: 111 1111 1001 */ 11, 2041, 10, 11, 0, 0 }, + { /* 159: 111 1111 1010 */ 11, 2042, 12, 0, 0, 0 }, + { /* 160: 111 1111 1011 */ 11, 2043, 8, 12, 0, 0 }, + { /* 161: 1111 1111 1000 */ 12, 4088, 12, 9, 0, 0 }, + { /* 162: 1111 1111 1001 */ 12, 4089, 10, 12, 0, 0 }, + { /* 163: 1111 1111 1010 */ 12, 4090, 9, 12, 0, 0 }, + { /* 164: 1111 1111 1011 */ 12, 4091, 11, 12, 0, 0 }, + { /* 165: 1111 1111 1100 */ 12, 4092, 12, 11, 0, 0 }, + { /* 166: 1111 1111 1101 */ 12, 4093, 0, 12, 0, 0 }, + { /* 167: 1111 1111 1110 */ 12, 4094, 12, 10, 0, 0 }, + { /* 168: 1111 1111 1111 */ 12, 4095, 12, 12, 0, 0 } +}; + +Huffman book11[] = { + /* idx codeword len codew x y v w */ + { /* 0: 0000 */ 4, 0, 0, 0, 0, 0 }, + { /* 1: 0001 */ 4, 1, 1, 1, 0, 0 }, + { /* 2: 0 0100 */ 5, 4, 16, 16, 0, 0 }, + { /* 3: 0 0101 */ 5, 5, 1, 0, 0, 0 }, + { /* 4: 0 0110 */ 5, 6, 0, 1, 0, 0 }, + { /* 5: 0 0111 */ 5, 7, 2, 1, 0, 0 }, + { /* 6: 0 1000 */ 5, 8, 1, 2, 0, 0 }, + { /* 7: 0 1001 */ 5, 9, 2, 2, 0, 0 }, + { /* 8: 01 0100 */ 6, 20, 1, 3, 0, 0 }, + { /* 9: 01 0101 */ 6, 21, 3, 1, 0, 0 }, + { /* 10: 01 0110 */ 6, 22, 3, 2, 0, 0 }, + { /* 11: 01 0111 */ 6, 23, 2, 0, 0, 0 }, + { /* 12: 01 1000 */ 6, 24, 2, 3, 0, 0 }, + { /* 13: 01 1001 */ 6, 25, 0, 2, 0, 0 }, + { /* 14: 01 1010 */ 6, 26, 3, 3, 0, 0 }, + { /* 15: 011 0110 */ 7, 54, 4, 1, 0, 0 }, + { /* 16: 011 0111 */ 7, 55, 1, 4, 0, 0 }, + { /* 17: 011 1000 */ 7, 56, 4, 2, 0, 0 }, + { /* 18: 011 1001 */ 7, 57, 2, 4, 0, 0 }, + { /* 19: 011 1010 */ 7, 58, 4, 3, 0, 0 }, + { /* 20: 011 1011 */ 7, 59, 3, 4, 0, 0 }, + { /* 21: 011 1100 */ 7, 60, 3, 0, 0, 0 }, + { /* 22: 011 1101 */ 7, 61, 0, 3, 0, 0 }, + { /* 23: 011 1110 */ 7, 62, 5, 1, 0, 0 }, + { /* 24: 011 1111 */ 7, 63, 5, 2, 0, 0 }, + { /* 25: 100 0000 */ 7, 64, 2, 5, 0, 0 }, + { /* 26: 100 0001 */ 7, 65, 4, 4, 0, 0 }, + { /* 27: 100 0010 */ 7, 66, 1, 5, 0, 0 }, + { /* 28: 100 0011 */ 7, 67, 5, 3, 0, 0 }, + { /* 29: 100 0100 */ 7, 68, 3, 5, 0, 0 }, + { /* 30: 100 0101 */ 7, 69, 5, 4, 0, 0 }, + { /* 31: 1000 1100 */ 8, 140, 4, 5, 0, 0 }, + { /* 32: 1000 1101 */ 8, 141, 6, 2, 0, 0 }, + { /* 33: 1000 1110 */ 8, 142, 2, 6, 0, 0 }, + { /* 34: 1000 1111 */ 8, 143, 6, 1, 0, 0 }, + { /* 35: 1001 0000 */ 8, 144, 6, 3, 0, 0 }, + { /* 36: 1001 0001 */ 8, 145, 3, 6, 0, 0 }, + { /* 37: 1001 0010 */ 8, 146, 1, 6, 0, 0 }, + { /* 38: 1001 0011 */ 8, 147, 4, 16, 0, 0 }, + { /* 39: 1001 0100 */ 8, 148, 3, 16, 0, 0 }, + { /* 40: 1001 0101 */ 8, 149, 16, 5, 0, 0 }, + { /* 41: 1001 0110 */ 8, 150, 16, 3, 0, 0 }, + { /* 42: 1001 0111 */ 8, 151, 16, 4, 0, 0 }, + { /* 43: 1001 1000 */ 8, 152, 6, 4, 0, 0 }, + { /* 44: 1001 1001 */ 8, 153, 16, 6, 0, 0 }, + { /* 45: 1001 1010 */ 8, 154, 4, 0, 0, 0 }, + { /* 46: 1001 1011 */ 8, 155, 4, 6, 0, 0 }, + { /* 47: 1001 1100 */ 8, 156, 0, 4, 0, 0 }, + { /* 48: 1001 1101 */ 8, 157, 2, 16, 0, 0 }, + { /* 49: 1001 1110 */ 8, 158, 5, 5, 0, 0 }, + { /* 50: 1001 1111 */ 8, 159, 5, 16, 0, 0 }, + { /* 51: 1010 0000 */ 8, 160, 16, 7, 0, 0 }, + { /* 52: 1010 0001 */ 8, 161, 16, 2, 0, 0 }, + { /* 53: 1010 0010 */ 8, 162, 16, 8, 0, 0 }, + { /* 54: 1010 0011 */ 8, 163, 2, 7, 0, 0 }, + { /* 55: 1010 0100 */ 8, 164, 7, 2, 0, 0 }, + { /* 56: 1010 0101 */ 8, 165, 3, 7, 0, 0 }, + { /* 57: 1010 0110 */ 8, 166, 6, 5, 0, 0 }, + { /* 58: 1010 0111 */ 8, 167, 5, 6, 0, 0 }, + { /* 59: 1010 1000 */ 8, 168, 6, 16, 0, 0 }, + { /* 60: 1010 1001 */ 8, 169, 16, 10, 0, 0 }, + { /* 61: 1010 1010 */ 8, 170, 7, 3, 0, 0 }, + { /* 62: 1010 1011 */ 8, 171, 7, 1, 0, 0 }, + { /* 63: 1010 1100 */ 8, 172, 16, 9, 0, 0 }, + { /* 64: 1010 1101 */ 8, 173, 7, 16, 0, 0 }, + { /* 65: 1010 1110 */ 8, 174, 1, 16, 0, 0 }, + { /* 66: 1010 1111 */ 8, 175, 1, 7, 0, 0 }, + { /* 67: 1011 0000 */ 8, 176, 4, 7, 0, 0 }, + { /* 68: 1011 0001 */ 8, 177, 16, 11, 0, 0 }, + { /* 69: 1011 0010 */ 8, 178, 7, 4, 0, 0 }, + { /* 70: 1011 0011 */ 8, 179, 16, 12, 0, 0 }, + { /* 71: 1011 0100 */ 8, 180, 8, 16, 0, 0 }, + { /* 72: 1011 0101 */ 8, 181, 16, 1, 0, 0 }, + { /* 73: 1011 0110 */ 8, 182, 6, 6, 0, 0 }, + { /* 74: 1011 0111 */ 8, 183, 9, 16, 0, 0 }, + { /* 75: 1011 1000 */ 8, 184, 2, 8, 0, 0 }, + { /* 76: 1011 1001 */ 8, 185, 5, 7, 0, 0 }, + { /* 77: 1011 1010 */ 8, 186, 10, 16, 0, 0 }, + { /* 78: 1011 1011 */ 8, 187, 16, 13, 0, 0 }, + { /* 79: 1011 1100 */ 8, 188, 8, 3, 0, 0 }, + { /* 80: 1011 1101 */ 8, 189, 8, 2, 0, 0 }, + { /* 81: 1011 1110 */ 8, 190, 3, 8, 0, 0 }, + { /* 82: 1011 1111 */ 8, 191, 5, 0, 0, 0 }, + { /* 83: 1100 0000 */ 8, 192, 16, 14, 0, 0 }, + { /* 84: 1100 0001 */ 8, 193, 11, 16, 0, 0 }, + { /* 85: 1100 0010 */ 8, 194, 7, 5, 0, 0 }, + { /* 86: 1100 0011 */ 8, 195, 4, 8, 0, 0 }, + { /* 87: 1100 0100 */ 8, 196, 6, 7, 0, 0 }, + { /* 88: 1100 0101 */ 8, 197, 7, 6, 0, 0 }, + { /* 89: 1100 0110 */ 8, 198, 0, 5, 0, 0 }, + { /* 90: 1 1000 1110 */ 9, 398, 8, 4, 0, 0 }, + { /* 91: 1 1000 1111 */ 9, 399, 16, 15, 0, 0 }, + { /* 92: 1 1001 0000 */ 9, 400, 12, 16, 0, 0 }, + { /* 93: 1 1001 0001 */ 9, 401, 1, 8, 0, 0 }, + { /* 94: 1 1001 0010 */ 9, 402, 8, 1, 0, 0 }, + { /* 95: 1 1001 0011 */ 9, 403, 14, 16, 0, 0 }, + { /* 96: 1 1001 0100 */ 9, 404, 5, 8, 0, 0 }, + { /* 97: 1 1001 0101 */ 9, 405, 13, 16, 0, 0 }, + { /* 98: 1 1001 0110 */ 9, 406, 3, 9, 0, 0 }, + { /* 99: 1 1001 0111 */ 9, 407, 8, 5, 0, 0 }, + { /* 100: 1 1001 1000 */ 9, 408, 7, 7, 0, 0 }, + { /* 101: 1 1001 1001 */ 9, 409, 2, 9, 0, 0 }, + { /* 102: 1 1001 1010 */ 9, 410, 8, 6, 0, 0 }, + { /* 103: 1 1001 1011 */ 9, 411, 9, 2, 0, 0 }, + { /* 104: 1 1001 1100 */ 9, 412, 9, 3, 0, 0 }, + { /* 105: 1 1001 1101 */ 9, 413, 15, 16, 0, 0 }, + { /* 106: 1 1001 1110 */ 9, 414, 4, 9, 0, 0 }, + { /* 107: 1 1001 1111 */ 9, 415, 6, 8, 0, 0 }, + { /* 108: 1 1010 0000 */ 9, 416, 6, 0, 0, 0 }, + { /* 109: 1 1010 0001 */ 9, 417, 9, 4, 0, 0 }, + { /* 110: 1 1010 0010 */ 9, 418, 5, 9, 0, 0 }, + { /* 111: 1 1010 0011 */ 9, 419, 8, 7, 0, 0 }, + { /* 112: 1 1010 0100 */ 9, 420, 7, 8, 0, 0 }, + { /* 113: 1 1010 0101 */ 9, 421, 1, 9, 0, 0 }, + { /* 114: 1 1010 0110 */ 9, 422, 10, 3, 0, 0 }, + { /* 115: 1 1010 0111 */ 9, 423, 0, 6, 0, 0 }, + { /* 116: 1 1010 1000 */ 9, 424, 10, 2, 0, 0 }, + { /* 117: 1 1010 1001 */ 9, 425, 9, 1, 0, 0 }, + { /* 118: 1 1010 1010 */ 9, 426, 9, 5, 0, 0 }, + { /* 119: 1 1010 1011 */ 9, 427, 4, 10, 0, 0 }, + { /* 120: 1 1010 1100 */ 9, 428, 2, 10, 0, 0 }, + { /* 121: 1 1010 1101 */ 9, 429, 9, 6, 0, 0 }, + { /* 122: 1 1010 1110 */ 9, 430, 3, 10, 0, 0 }, + { /* 123: 1 1010 1111 */ 9, 431, 6, 9, 0, 0 }, + { /* 124: 1 1011 0000 */ 9, 432, 10, 4, 0, 0 }, + { /* 125: 1 1011 0001 */ 9, 433, 8, 8, 0, 0 }, + { /* 126: 1 1011 0010 */ 9, 434, 10, 5, 0, 0 }, + { /* 127: 1 1011 0011 */ 9, 435, 9, 7, 0, 0 }, + { /* 128: 1 1011 0100 */ 9, 436, 11, 3, 0, 0 }, + { /* 129: 1 1011 0101 */ 9, 437, 1, 10, 0, 0 }, + { /* 130: 1 1011 0110 */ 9, 438, 7, 0, 0, 0 }, + { /* 131: 1 1011 0111 */ 9, 439, 10, 6, 0, 0 }, + { /* 132: 1 1011 1000 */ 9, 440, 7, 9, 0, 0 }, + { /* 133: 1 1011 1001 */ 9, 441, 3, 11, 0, 0 }, + { /* 134: 1 1011 1010 */ 9, 442, 5, 10, 0, 0 }, + { /* 135: 1 1011 1011 */ 9, 443, 10, 1, 0, 0 }, + { /* 136: 1 1011 1100 */ 9, 444, 4, 11, 0, 0 }, + { /* 137: 1 1011 1101 */ 9, 445, 11, 2, 0, 0 }, + { /* 138: 1 1011 1110 */ 9, 446, 13, 2, 0, 0 }, + { /* 139: 1 1011 1111 */ 9, 447, 6, 10, 0, 0 }, + { /* 140: 1 1100 0000 */ 9, 448, 13, 3, 0, 0 }, + { /* 141: 1 1100 0001 */ 9, 449, 2, 11, 0, 0 }, + { /* 142: 1 1100 0010 */ 9, 450, 16, 0, 0, 0 }, + { /* 143: 1 1100 0011 */ 9, 451, 5, 11, 0, 0 }, + { /* 144: 1 1100 0100 */ 9, 452, 11, 5, 0, 0 }, + { /* 145: 11 1000 1010 */ 10, 906, 11, 4, 0, 0 }, + { /* 146: 11 1000 1011 */ 10, 907, 9, 8, 0, 0 }, + { /* 147: 11 1000 1100 */ 10, 908, 7, 10, 0, 0 }, + { /* 148: 11 1000 1101 */ 10, 909, 8, 9, 0, 0 }, + { /* 149: 11 1000 1110 */ 10, 910, 0, 16, 0, 0 }, + { /* 150: 11 1000 1111 */ 10, 911, 4, 13, 0, 0 }, + { /* 151: 11 1001 0000 */ 10, 912, 0, 7, 0, 0 }, + { /* 152: 11 1001 0001 */ 10, 913, 3, 13, 0, 0 }, + { /* 153: 11 1001 0010 */ 10, 914, 11, 6, 0, 0 }, + { /* 154: 11 1001 0011 */ 10, 915, 13, 1, 0, 0 }, + { /* 155: 11 1001 0100 */ 10, 916, 13, 4, 0, 0 }, + { /* 156: 11 1001 0101 */ 10, 917, 12, 3, 0, 0 }, + { /* 157: 11 1001 0110 */ 10, 918, 2, 13, 0, 0 }, + { /* 158: 11 1001 0111 */ 10, 919, 13, 5, 0, 0 }, + { /* 159: 11 1001 1000 */ 10, 920, 8, 10, 0, 0 }, + { /* 160: 11 1001 1001 */ 10, 921, 6, 11, 0, 0 }, + { /* 161: 11 1001 1010 */ 10, 922, 10, 8, 0, 0 }, + { /* 162: 11 1001 1011 */ 10, 923, 10, 7, 0, 0 }, + { /* 163: 11 1001 1100 */ 10, 924, 14, 2, 0, 0 }, + { /* 164: 11 1001 1101 */ 10, 925, 12, 4, 0, 0 }, + { /* 165: 11 1001 1110 */ 10, 926, 1, 11, 0, 0 }, + { /* 166: 11 1001 1111 */ 10, 927, 4, 12, 0, 0 }, + { /* 167: 11 1010 0000 */ 10, 928, 11, 1, 0, 0 }, + { /* 168: 11 1010 0001 */ 10, 929, 3, 12, 0, 0 }, + { /* 169: 11 1010 0010 */ 10, 930, 1, 13, 0, 0 }, + { /* 170: 11 1010 0011 */ 10, 931, 12, 2, 0, 0 }, + { /* 171: 11 1010 0100 */ 10, 932, 7, 11, 0, 0 }, + { /* 172: 11 1010 0101 */ 10, 933, 3, 14, 0, 0 }, + { /* 173: 11 1010 0110 */ 10, 934, 5, 12, 0, 0 }, + { /* 174: 11 1010 0111 */ 10, 935, 5, 13, 0, 0 }, + { /* 175: 11 1010 1000 */ 10, 936, 14, 4, 0, 0 }, + { /* 176: 11 1010 1001 */ 10, 937, 4, 14, 0, 0 }, + { /* 177: 11 1010 1010 */ 10, 938, 11, 7, 0, 0 }, + { /* 178: 11 1010 1011 */ 10, 939, 14, 3, 0, 0 }, + { /* 179: 11 1010 1100 */ 10, 940, 12, 5, 0, 0 }, + { /* 180: 11 1010 1101 */ 10, 941, 13, 6, 0, 0 }, + { /* 181: 11 1010 1110 */ 10, 942, 12, 6, 0, 0 }, + { /* 182: 11 1010 1111 */ 10, 943, 8, 0, 0, 0 }, + { /* 183: 11 1011 0000 */ 10, 944, 11, 8, 0, 0 }, + { /* 184: 11 1011 0001 */ 10, 945, 2, 12, 0, 0 }, + { /* 185: 11 1011 0010 */ 10, 946, 9, 9, 0, 0 }, + { /* 186: 11 1011 0011 */ 10, 947, 14, 5, 0, 0 }, + { /* 187: 11 1011 0100 */ 10, 948, 6, 13, 0, 0 }, + { /* 188: 11 1011 0101 */ 10, 949, 10, 10, 0, 0 }, + { /* 189: 11 1011 0110 */ 10, 950, 15, 2, 0, 0 }, + { /* 190: 11 1011 0111 */ 10, 951, 8, 11, 0, 0 }, + { /* 191: 11 1011 1000 */ 10, 952, 9, 10, 0, 0 }, + { /* 192: 11 1011 1001 */ 10, 953, 14, 6, 0, 0 }, + { /* 193: 11 1011 1010 */ 10, 954, 10, 9, 0, 0 }, + { /* 194: 11 1011 1011 */ 10, 955, 5, 14, 0, 0 }, + { /* 195: 11 1011 1100 */ 10, 956, 11, 9, 0, 0 }, + { /* 196: 11 1011 1101 */ 10, 957, 14, 1, 0, 0 }, + { /* 197: 11 1011 1110 */ 10, 958, 2, 14, 0, 0 }, + { /* 198: 11 1011 1111 */ 10, 959, 6, 12, 0, 0 }, + { /* 199: 11 1100 0000 */ 10, 960, 1, 12, 0, 0 }, + { /* 200: 11 1100 0001 */ 10, 961, 13, 8, 0, 0 }, + { /* 201: 11 1100 0010 */ 10, 962, 0, 8, 0, 0 }, + { /* 202: 11 1100 0011 */ 10, 963, 13, 7, 0, 0 }, + { /* 203: 11 1100 0100 */ 10, 964, 7, 12, 0, 0 }, + { /* 204: 11 1100 0101 */ 10, 965, 12, 7, 0, 0 }, + { /* 205: 11 1100 0110 */ 10, 966, 7, 13, 0, 0 }, + { /* 206: 11 1100 0111 */ 10, 967, 15, 3, 0, 0 }, + { /* 207: 11 1100 1000 */ 10, 968, 12, 1, 0, 0 }, + { /* 208: 11 1100 1001 */ 10, 969, 6, 14, 0, 0 }, + { /* 209: 11 1100 1010 */ 10, 970, 2, 15, 0, 0 }, + { /* 210: 11 1100 1011 */ 10, 971, 15, 5, 0, 0 }, + { /* 211: 11 1100 1100 */ 10, 972, 15, 4, 0, 0 }, + { /* 212: 11 1100 1101 */ 10, 973, 1, 14, 0, 0 }, + { /* 213: 11 1100 1110 */ 10, 974, 9, 11, 0, 0 }, + { /* 214: 11 1100 1111 */ 10, 975, 4, 15, 0, 0 }, + { /* 215: 11 1101 0000 */ 10, 976, 14, 7, 0, 0 }, + { /* 216: 11 1101 0001 */ 10, 977, 8, 13, 0, 0 }, + { /* 217: 11 1101 0010 */ 10, 978, 13, 9, 0, 0 }, + { /* 218: 11 1101 0011 */ 10, 979, 8, 12, 0, 0 }, + { /* 219: 11 1101 0100 */ 10, 980, 5, 15, 0, 0 }, + { /* 220: 11 1101 0101 */ 10, 981, 3, 15, 0, 0 }, + { /* 221: 11 1101 0110 */ 10, 982, 10, 11, 0, 0 }, + { /* 222: 11 1101 0111 */ 10, 983, 11, 10, 0, 0 }, + { /* 223: 11 1101 1000 */ 10, 984, 12, 8, 0, 0 }, + { /* 224: 11 1101 1001 */ 10, 985, 15, 6, 0, 0 }, + { /* 225: 11 1101 1010 */ 10, 986, 15, 7, 0, 0 }, + { /* 226: 11 1101 1011 */ 10, 987, 8, 14, 0, 0 }, + { /* 227: 11 1101 1100 */ 10, 988, 15, 1, 0, 0 }, + { /* 228: 11 1101 1101 */ 10, 989, 7, 14, 0, 0 }, + { /* 229: 11 1101 1110 */ 10, 990, 9, 0, 0, 0 }, + { /* 230: 11 1101 1111 */ 10, 991, 0, 9, 0, 0 }, + { /* 231: 11 1110 0000 */ 10, 992, 9, 13, 0, 0 }, + { /* 232: 11 1110 0001 */ 10, 993, 9, 12, 0, 0 }, + { /* 233: 11 1110 0010 */ 10, 994, 12, 9, 0, 0 }, + { /* 234: 11 1110 0011 */ 10, 995, 14, 8, 0, 0 }, + { /* 235: 11 1110 0100 */ 10, 996, 10, 13, 0, 0 }, + { /* 236: 11 1110 0101 */ 10, 997, 14, 9, 0, 0 }, + { /* 237: 11 1110 0110 */ 10, 998, 12, 10, 0, 0 }, + { /* 238: 11 1110 0111 */ 10, 999, 6, 15, 0, 0 }, + { /* 239: 11 1110 1000 */ 10, 1000, 7, 15, 0, 0 }, + { /* 240: 111 1101 0010 */ 11, 2002, 9, 14, 0, 0 }, + { /* 241: 111 1101 0011 */ 11, 2003, 15, 8, 0, 0 }, + { /* 242: 111 1101 0100 */ 11, 2004, 11, 11, 0, 0 }, + { /* 243: 111 1101 0101 */ 11, 2005, 11, 14, 0, 0 }, + { /* 244: 111 1101 0110 */ 11, 2006, 1, 15, 0, 0 }, + { /* 245: 111 1101 0111 */ 11, 2007, 10, 12, 0, 0 }, + { /* 246: 111 1101 1000 */ 11, 2008, 10, 14, 0, 0 }, + { /* 247: 111 1101 1001 */ 11, 2009, 13, 11, 0, 0 }, + { /* 248: 111 1101 1010 */ 11, 2010, 13, 10, 0, 0 }, + { /* 249: 111 1101 1011 */ 11, 2011, 11, 13, 0, 0 }, + { /* 250: 111 1101 1100 */ 11, 2012, 11, 12, 0, 0 }, + { /* 251: 111 1101 1101 */ 11, 2013, 8, 15, 0, 0 }, + { /* 252: 111 1101 1110 */ 11, 2014, 14, 11, 0, 0 }, + { /* 253: 111 1101 1111 */ 11, 2015, 13, 12, 0, 0 }, + { /* 254: 111 1110 0000 */ 11, 2016, 12, 13, 0, 0 }, + { /* 255: 111 1110 0001 */ 11, 2017, 15, 9, 0, 0 }, + { /* 256: 111 1110 0010 */ 11, 2018, 14, 10, 0, 0 }, + { /* 257: 111 1110 0011 */ 11, 2019, 10, 0, 0, 0 }, + { /* 258: 111 1110 0100 */ 11, 2020, 12, 11, 0, 0 }, + { /* 259: 111 1110 0101 */ 11, 2021, 9, 15, 0, 0 }, + { /* 260: 111 1110 0110 */ 11, 2022, 0, 10, 0, 0 }, + { /* 261: 111 1110 0111 */ 11, 2023, 12, 12, 0, 0 }, + { /* 262: 111 1110 1000 */ 11, 2024, 11, 0, 0, 0 }, + { /* 263: 111 1110 1001 */ 11, 2025, 12, 14, 0, 0 }, + { /* 264: 111 1110 1010 */ 11, 2026, 10, 15, 0, 0 }, + { /* 265: 111 1110 1011 */ 11, 2027, 13, 13, 0, 0 }, + { /* 266: 111 1110 1100 */ 11, 2028, 0, 13, 0, 0 }, + { /* 267: 111 1110 1101 */ 11, 2029, 14, 12, 0, 0 }, + { /* 268: 111 1110 1110 */ 11, 2030, 15, 10, 0, 0 }, + { /* 269: 111 1110 1111 */ 11, 2031, 15, 11, 0, 0 }, + { /* 270: 111 1111 0000 */ 11, 2032, 11, 15, 0, 0 }, + { /* 271: 111 1111 0001 */ 11, 2033, 14, 13, 0, 0 }, + { /* 272: 111 1111 0010 */ 11, 2034, 13, 0, 0, 0 }, + { /* 273: 111 1111 0011 */ 11, 2035, 0, 11, 0, 0 }, + { /* 274: 111 1111 0100 */ 11, 2036, 13, 14, 0, 0 }, + { /* 275: 111 1111 0101 */ 11, 2037, 15, 12, 0, 0 }, + { /* 276: 111 1111 0110 */ 11, 2038, 15, 13, 0, 0 }, + { /* 277: 111 1111 0111 */ 11, 2039, 12, 15, 0, 0 }, + { /* 278: 111 1111 1000 */ 11, 2040, 14, 0, 0, 0 }, + { /* 279: 111 1111 1001 */ 11, 2041, 14, 14, 0, 0 }, + { /* 280: 111 1111 1010 */ 11, 2042, 13, 15, 0, 0 }, + { /* 281: 111 1111 1011 */ 11, 2043, 12, 0, 0, 0 }, + { /* 282: 111 1111 1100 */ 11, 2044, 14, 15, 0, 0 }, + { /* 283: 1111 1111 1010 */ 12, 4090, 0, 14, 0, 0 }, + { /* 284: 1111 1111 1011 */ 12, 4091, 0, 12, 0, 0 }, + { /* 285: 1111 1111 1100 */ 12, 4092, 15, 14, 0, 0 }, + { /* 286: 1111 1111 1101 */ 12, 4093, 15, 0, 0, 0 }, + { /* 287: 1111 1111 1110 */ 12, 4094, 0, 15, 0, 0 }, + { /* 288: 1111 1111 1111 */ 12, 4095, 15, 15, 0, 0 } +}; + +Huffscl bookscl[] = { + /* idx codeword len codew idx */ + { /* 0: 0 */ 1, 0, 60 }, + { /* 1: 100 */ 3, 4, 59 }, + { /* 2: 1010 */ 4, 10, 61 }, + { /* 3: 1011 */ 4, 11, 58 }, + { /* 4: 1100 */ 4, 12, 62 }, + { /* 5: 1 1010 */ 5, 26, 57 }, + { /* 6: 1 1011 */ 5, 27, 63 }, + { /* 7: 11 1000 */ 6, 56, 56 }, + { /* 8: 11 1001 */ 6, 57, 64 }, + { /* 9: 11 1010 */ 6, 58, 55 }, + { /* 10: 11 1011 */ 6, 59, 65 }, + { /* 11: 111 1000 */ 7, 120, 66 }, + { /* 12: 111 1001 */ 7, 121, 54 }, + { /* 13: 111 1010 */ 7, 122, 67 }, + { /* 14: 1111 0110 */ 8, 246, 53 }, + { /* 15: 1111 0111 */ 8, 247, 68 }, + { /* 16: 1111 1000 */ 8, 248, 52 }, + { /* 17: 1111 1001 */ 8, 249, 69 }, + { /* 18: 1111 1010 */ 8, 250, 51 }, + { /* 19: 1 1111 0110 */ 9, 502, 70 }, + { /* 20: 1 1111 0111 */ 9, 503, 50 }, + { /* 21: 1 1111 1000 */ 9, 504, 49 }, + { /* 22: 1 1111 1001 */ 9, 505, 71 }, + { /* 23: 11 1111 0100 */ 10, 1012, 72 }, + { /* 24: 11 1111 0101 */ 10, 1013, 48 }, + { /* 25: 11 1111 0110 */ 10, 1014, 73 }, + { /* 26: 11 1111 0111 */ 10, 1015, 47 }, + { /* 27: 11 1111 1000 */ 10, 1016, 74 }, + { /* 28: 11 1111 1001 */ 10, 1017, 46 }, + { /* 29: 111 1111 0100 */ 11, 2036, 76 }, + { /* 30: 111 1111 0101 */ 11, 2037, 75 }, + { /* 31: 111 1111 0110 */ 11, 2038, 77 }, + { /* 32: 111 1111 0111 */ 11, 2039, 78 }, + { /* 33: 111 1111 1000 */ 11, 2040, 45 }, + { /* 34: 111 1111 1001 */ 11, 2041, 43 }, + { /* 35: 1111 1111 0100 */ 12, 4084, 44 }, + { /* 36: 1111 1111 0101 */ 12, 4085, 79 }, + { /* 37: 1111 1111 0110 */ 12, 4086, 42 }, + { /* 38: 1111 1111 0111 */ 12, 4087, 41 }, + { /* 39: 1111 1111 1000 */ 12, 4088, 80 }, + { /* 40: 1111 1111 1001 */ 12, 4089, 40 }, + { /* 41: 1 1111 1111 0100 */ 13, 8180, 81 }, + { /* 42: 1 1111 1111 0101 */ 13, 8181, 39 }, + { /* 43: 1 1111 1111 0110 */ 13, 8182, 82 }, + { /* 44: 1 1111 1111 0111 */ 13, 8183, 38 }, + { /* 45: 1 1111 1111 1000 */ 13, 8184, 83 }, + { /* 46: 11 1111 1111 0010 */ 14, 16370, 37 }, + { /* 47: 11 1111 1111 0011 */ 14, 16371, 35 }, + { /* 48: 11 1111 1111 0100 */ 14, 16372, 85 }, + { /* 49: 11 1111 1111 0101 */ 14, 16373, 33 }, + { /* 50: 11 1111 1111 0110 */ 14, 16374, 36 }, + { /* 51: 11 1111 1111 0111 */ 14, 16375, 34 }, + { /* 52: 11 1111 1111 1000 */ 14, 16376, 84 }, + { /* 53: 11 1111 1111 1001 */ 14, 16377, 32 }, + { /* 54: 111 1111 1111 0100 */ 15, 32756, 87 }, + { /* 55: 111 1111 1111 0101 */ 15, 32757, 89 }, + { /* 56: 111 1111 1111 0110 */ 15, 32758, 30 }, + { /* 57: 111 1111 1111 0111 */ 15, 32759, 31 }, + { /* 58: 1111 1111 1111 0000 */ 16, 65520, 86 }, + { /* 59: 1111 1111 1111 0001 */ 16, 65521, 29 }, + { /* 60: 1111 1111 1111 0010 */ 16, 65522, 26 }, + { /* 61: 1111 1111 1111 0011 */ 16, 65523, 27 }, + { /* 62: 1111 1111 1111 0100 */ 16, 65524, 28 }, + { /* 63: 1111 1111 1111 0101 */ 16, 65525, 24 }, + { /* 64: 1111 1111 1111 0110 */ 16, 65526, 88 }, + { /* 65: 1 1111 1111 1110 1110 */ 17, 131054, 25 }, + { /* 66: 1 1111 1111 1110 1111 */ 17, 131055, 22 }, + { /* 67: 1 1111 1111 1111 0000 */ 17, 131056, 23 }, + { /* 68: 11 1111 1111 1110 0010 */ 18, 262114, 90 }, + { /* 69: 11 1111 1111 1110 0011 */ 18, 262115, 21 }, + { /* 70: 11 1111 1111 1110 0100 */ 18, 262116, 19 }, + { /* 71: 11 1111 1111 1110 0101 */ 18, 262117, 3 }, + { /* 72: 11 1111 1111 1110 0110 */ 18, 262118, 1 }, + { /* 73: 11 1111 1111 1110 0111 */ 18, 262119, 2 }, + { /* 74: 11 1111 1111 1110 1000 */ 18, 262120, 0 }, + { /* 75: 111 1111 1111 1101 0010 */ 19, 524242, 98 }, + { /* 76: 111 1111 1111 1101 0011 */ 19, 524243, 99 }, + { /* 77: 111 1111 1111 1101 0100 */ 19, 524244, 100 }, + { /* 78: 111 1111 1111 1101 0101 */ 19, 524245, 101 }, + { /* 79: 111 1111 1111 1101 0110 */ 19, 524246, 102 }, + { /* 80: 111 1111 1111 1101 0111 */ 19, 524247, 117 }, + { /* 81: 111 1111 1111 1101 1000 */ 19, 524248, 97 }, + { /* 82: 111 1111 1111 1101 1001 */ 19, 524249, 91 }, + { /* 83: 111 1111 1111 1101 1010 */ 19, 524250, 92 }, + { /* 84: 111 1111 1111 1101 1011 */ 19, 524251, 93 }, + { /* 85: 111 1111 1111 1101 1100 */ 19, 524252, 94 }, + { /* 86: 111 1111 1111 1101 1101 */ 19, 524253, 95 }, + { /* 87: 111 1111 1111 1101 1110 */ 19, 524254, 96 }, + { /* 88: 111 1111 1111 1101 1111 */ 19, 524255, 104 }, + { /* 89: 111 1111 1111 1110 0000 */ 19, 524256, 111 }, + { /* 90: 111 1111 1111 1110 0001 */ 19, 524257, 112 }, + { /* 91: 111 1111 1111 1110 0010 */ 19, 524258, 113 }, + { /* 92: 111 1111 1111 1110 0011 */ 19, 524259, 114 }, + { /* 93: 111 1111 1111 1110 0100 */ 19, 524260, 115 }, + { /* 94: 111 1111 1111 1110 0101 */ 19, 524261, 116 }, + { /* 95: 111 1111 1111 1110 0110 */ 19, 524262, 110 }, + { /* 96: 111 1111 1111 1110 0111 */ 19, 524263, 105 }, + { /* 97: 111 1111 1111 1110 1000 */ 19, 524264, 106 }, + { /* 98: 111 1111 1111 1110 1001 */ 19, 524265, 107 }, + { /* 99: 111 1111 1111 1110 1010 */ 19, 524266, 108 }, + { /* 100: 111 1111 1111 1110 1011 */ 19, 524267, 109 }, + { /* 101: 111 1111 1111 1110 1100 */ 19, 524268, 118 }, + { /* 102: 111 1111 1111 1110 1101 */ 19, 524269, 6 }, + { /* 103: 111 1111 1111 1110 1110 */ 19, 524270, 8 }, + { /* 104: 111 1111 1111 1110 1111 */ 19, 524271, 9 }, + { /* 105: 111 1111 1111 1111 0000 */ 19, 524272, 10 }, + { /* 106: 111 1111 1111 1111 0001 */ 19, 524273, 5 }, + { /* 107: 111 1111 1111 1111 0010 */ 19, 524274, 103 }, + { /* 108: 111 1111 1111 1111 0011 */ 19, 524275, 120 }, + { /* 109: 111 1111 1111 1111 0100 */ 19, 524276, 119 }, + { /* 110: 111 1111 1111 1111 0101 */ 19, 524277, 4 }, + { /* 111: 111 1111 1111 1111 0110 */ 19, 524278, 7 }, + { /* 112: 111 1111 1111 1111 0111 */ 19, 524279, 15 }, + { /* 113: 111 1111 1111 1111 1000 */ 19, 524280, 16 }, + { /* 114: 111 1111 1111 1111 1001 */ 19, 524281, 18 }, + { /* 115: 111 1111 1111 1111 1010 */ 19, 524282, 20 }, + { /* 116: 111 1111 1111 1111 1011 */ 19, 524283, 17 }, + { /* 117: 111 1111 1111 1111 1100 */ 19, 524284, 11 }, + { /* 118: 111 1111 1111 1111 1101 */ 19, 524285, 12 }, + { /* 119: 111 1111 1111 1111 1110 */ 19, 524286, 14 }, + { /* 120: 111 1111 1111 1111 1111 */ 19, 524287, 13 } +}; diff --git a/intensity.c b/intensity.c new file mode 100644 index 0000000..93b0f85 --- /dev/null +++ b/intensity.c @@ -0,0 +1,89 @@ +/************************* MPEG-2 NBC Audio Decoder ************************** + * * +"This software module was originally developed by +AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS in the course of +development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ +/* + * $Id: intensity.c,v 1.6 2002/01/11 00:55:17 wmaycisco Exp $ + */ + +#include +#include "all.h" + +/* + * if (chan==RIGHT) { + * do IS decoding for this channel (scale left ch. values with + * factor(SFr-SFl) ) + * reset all lpflags for which IS is on + * pass decoded IS values to predict + * } + */ +void intensity( MC_Info *mip, Info *info, int widx, int ch, + byte *group, byte *cb_map, int *factors, + int *lpflag, Float *coef[Chans] ) +{ + Ch_Info *cip = &mip->ch_info[ch]; + Float *left, *right, *r, *l, scale; + int cb, sign_sfb, sfb, n, nn, b, bb, nband; + int *band; + + if (!(cip->cpe && !cip->ch_is_left)) + return; + + right = coef[ ch ]; + left = coef[ cip->paired_ch ]; + + /* Intensity goes by group */ + bb = 0; + for (b = 0; b < info->nsbk; ) { + nband = info->sfb_per_sbk[b]; + band = info->sbk_sfb_top[b]; + + b = *group++; /* b = index of last sbk in group */ + for (; bb < b; bb++) { /* bb = sbk index */ + n = 0; + for (sfb = 0; sfb < nband; sfb++){ + nn = band[sfb]; /* band is offset table, nn is last coef in band */ + cb = cb_map[sfb]; + if (cb == INTENSITY_HCB || cb == INTENSITY_HCB2) { + /* found intensity code book */ + /* disable prediction (only important for long blocks) */ + lpflag[1+sfb] = 0; + + sign_sfb = (cb == INTENSITY_HCB) ? 1 : -1; + scale = sign_sfb * (float)pow( 0.5, 0.25*(factors[sfb]) ); + + /* reconstruct right intensity values */ + r = right + n; + l = left + n; + for (; n < nn; n++) { /* n is coef index */ + *r++ = *l++ * scale; + } + } + n = nn; + } + right += info->bins_per_sbk[bb]; + left += info->bins_per_sbk[bb]; + factors += nband; + } + cb_map += info->sfb_per_sbk[bb-1]; + } +} diff --git a/interface.h b/interface.h new file mode 100644 index 0000000..334f45d --- /dev/null +++ b/interface.h @@ -0,0 +1,236 @@ +/************************* MPEG-2 NBC Audio Decoder ************************** + * * +"This software module was originally developed by +AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS in the course of +development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ +/* + * $Id: interface.h,v 1.6 2002/01/11 00:55:17 wmaycisco Exp $ + */ + +#ifndef _interface_h_ +#define _interface_h_ + +/* + * interface between the encoder and decoder + */ + +#define C_LN10 2.30258509299404568402 /* ln(10) */ +#define C_PI 3.14159265358979323846f /* pi */ +#define C_SQRT2 1.41421356237309504880 /* sqrt(2) */ + +#define MINTHR .5 +#define SF_C1 (13.33333/1.333333) + +/* prediction */ +#define PRED_ORDER 2 +#define PRED_ALPHA 0.90625f +#define PRED_A 0.953125f +#define PRED_B 0.953125f + +enum +{ + /* + * block switching + */ + LN = 2048, + SN = 256, + LN2 = LN/2, + SN2 = SN/2, + LN4 = LN/4, + SN4 = SN/4, + NSHORT = LN/SN, + MAX_SBK = NSHORT, + + ONLY_LONG_WINDOW = 0, + LONG_START_WINDOW, + EIGHT_SHORT_WINDOW, + LONG_STOP_WINDOW, + NUM_WIN_SEQ, + + WLONG = ONLY_LONG_WINDOW, + WSTART, + WSHORT, + WSTOP, + + MAXBANDS = 16*NSHORT, /* max number of scale factor bands */ + MAXFAC = 121, /* maximum scale factor */ + MIDFAC = (MAXFAC-1)/2, + SF_OFFSET = 100, /* global gain must be positive */ + + /* + * specify huffman tables as signed (1) or unsigned (0) + */ + HUF1SGN = 1, + HUF2SGN = 1, + HUF3SGN = 0, + HUF4SGN = 0, + HUF5SGN = 1, + HUF6SGN = 1, + HUF7SGN = 0, + HUF8SGN = 0, + HUF9SGN = 0, + HUF10SGN = 0, + HUF11SGN = 0, + + ZERO_HCB = 0, + BY4BOOKS = 4, + ESCBOOK = 11, + NSPECBOOKS = ESCBOOK + 1, + BOOKSCL = NSPECBOOKS, + NBOOKS = NSPECBOOKS+1, + INTENSITY_HCB2 = 14, + INTENSITY_HCB = 15, + NOISE_HCB = 13, + + NOISE_PCM_BITS = 9, + NOISE_PCM_OFFSET = (1 << (NOISE_PCM_BITS-1)), + + NOISE_OFFSET = 90, + + LONG_SECT_BITS = 5, + SHORT_SECT_BITS = 3, + + /* + * Program Configuration + */ + AACMAIN = 0, + AACLC = 1, + AACSSR = 2, + AACLTP = 3, + + Fs_48 = 3, + Fs_44 = 4, + Fs_32 = 5, + + /* + * Misc constants + */ + CC_DOM = 0, /* before TNS */ + CC_IND = 1, + + /* + * Raw bitstream constants + */ + LEN_SE_ID = 3, + LEN_TAG = 4, + LEN_COM_WIN = 1, + LEN_ICS_RESERV = 1, + LEN_WIN_SEQ = 2, + LEN_WIN_SH = 1, + LEN_MAX_SFBL = 6, + LEN_MAX_SFBS = 4, + LEN_CB = 4, + LEN_SCL_PCM = 8, + LEN_PRED_PRES = 1, + LEN_PRED_RST = 1, + LEN_PRED_RSTGRP = 5, + LEN_PRED_ENAB = 1, + LEN_MASK_PRES = 2, + LEN_MASK = 1, + LEN_PULSE_PRES = 1, + LEN_TNS_PRES = 1, + LEN_GAIN_PRES = 1, + + LEN_NPULSE = 2, + LEN_PULSE_ST_SFB = 6, + LEN_POFF = 5, + LEN_PAMP = 4, + NUM_PULSE_LINES = 4, + PULSE_OFFSET_AMP = 4, + + LEN_IND_CCE_FLG = 1, + LEN_NCC = 3, + LEN_IS_CPE = 1, + LEN_CC_LR = 1, + LEN_CC_DOM = 1, + LEN_CC_SGN = 1, + LEN_CCH_GES = 2, + LEN_CCH_CGP = 1, + + LEN_D_ALIGN = 1, + LEN_D_CNT = 8, + LEN_D_ESC = 8, + LEN_F_CNT = 4, + LEN_F_ESC = 8, + LEN_NIBBLE = 4, + LEN_BYTE = 8, + LEN_PAD_DATA = 8, + MAX_DBYTES = ((1< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libfaad60.dsp b/libfaad60.dsp new file mode 100644 index 0000000..21cb38d --- /dev/null +++ b/libfaad60.dsp @@ -0,0 +1,235 @@ +# Microsoft Developer Studio Project File - Name="libfaad" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=libfaad - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "libfaad60.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "libfaad60.mak" CFG="libfaad - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "libfaad - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE "libfaad - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "libfaad - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\..\..\include" /D "_MBCS" /D "_LIB" /D "WIN32" /D "NDEBUG" /YX /FD /c +# SUBTRACT CPP /Fr +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "libfaad - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /GX /Zi /Od /I "..\\" /I "..\..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /YX /FD /GZ /c +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ENDIF + +# Begin Target + +# Name "libfaad - Win32 Release" +# Name "libfaad - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\bits.c +# End Source File +# Begin Source File + +SOURCE=.\block.c +# End Source File +# Begin Source File + +SOURCE=.\config.c +# End Source File +# Begin Source File + +SOURCE=.\decdata.c +# End Source File +# Begin Source File + +SOURCE=.\decoder.c +# End Source File +# Begin Source File + +SOURCE=.\dolby_adapt.c +# End Source File +# Begin Source File + +SOURCE=.\fastfft.c + +!IF "$(CFG)" == "libfaad - Win32 Release" + +# ADD CPP /GX- +# SUBTRACT CPP /O + +!ELSEIF "$(CFG)" == "libfaad - Win32 Debug" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\huffdec.c +# End Source File +# Begin Source File + +SOURCE=.\huffinit.c +# End Source File +# Begin Source File + +SOURCE=.\hufftables.c +# End Source File +# Begin Source File + +SOURCE=.\intensity.c +# End Source File +# Begin Source File + +SOURCE=.\monopred.c +# End Source File +# Begin Source File + +SOURCE=.\nok_lt_prediction.c +# End Source File +# Begin Source File + +SOURCE=.\pns.c +# End Source File +# Begin Source File + +SOURCE=.\stereo.c +# End Source File +# Begin Source File + +SOURCE=.\tns.c +# End Source File +# Begin Source File + +SOURCE=.\transfo.c +# End Source File +# Begin Source File + +SOURCE=.\util.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\All.h +# End Source File +# Begin Source File + +SOURCE=.\bits.h +# End Source File +# Begin Source File + +SOURCE=.\Block.h +# End Source File +# Begin Source File + +SOURCE=.\Fastfft.h +# End Source File +# Begin Source File + +SOURCE=.\interface.h +# End Source File +# Begin Source File + +SOURCE=.\kbd_win.h +# End Source File +# Begin Source File + +SOURCE=.\monopred.h +# End Source File +# Begin Source File + +SOURCE=.\mpeg4ip_bits.h +# End Source File +# Begin Source File + +SOURCE=.\nok_lt_prediction.h +# End Source File +# Begin Source File + +SOURCE=.\nok_ltp_common.h +# End Source File +# Begin Source File + +SOURCE=.\nok_ltp_common_internal.h +# End Source File +# Begin Source File + +SOURCE=.\Port.h +# End Source File +# Begin Source File + +SOURCE=.\Tns.h +# End Source File +# Begin Source File + +SOURCE=.\Transfo.h +# End Source File +# Begin Source File + +SOURCE=.\util.h +# End Source File +# End Group +# End Target +# End Project diff --git a/monopred.c b/monopred.c new file mode 100644 index 0000000..92c91cf --- /dev/null +++ b/monopred.c @@ -0,0 +1,418 @@ +/************************* MPEG-2 NBC Audio Decoder ************************** + * * +"This software module was originally developed by +Bernd Edler and Hendrik Fuchs, University of Hannover in the course of +development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ +/* + * $Id: monopred.c,v 1.4 2002/01/11 00:55:17 wmaycisco Exp $ + */ + +/*********************************************************************************** + * MONOPRED * + * * + * Contains the core functions for an intra channel (or mono) predictor * + * using a backward adaptive lattice predictor. * + * * + * init_pred_stat(): initialisation of all predictor parameters * + * monopred(): calculation of a predicted value from * + * preceeding (quantised) samples * + * predict(): carry out prediction for all spectral lines * + * predict_reset(): carry out cyclic predictor reset mechanism * + * (long blocks) resp. full reset (short blocks) * + * * + * Internal Functions: * + * reset_pred_state(): reset the predictor state variables * + * * + **********************************************************************************/ + +#include "all.h" +#include "util.h" + +#define GRAD PRED_ORDER +#define ALPHA PRED_ALPHA +#define A PRED_A +#define B PRED_B + + +/* this works for all float values, + * but does not conform to IEEE conventions of + * round to nearest, even + */ + +/* Schuyler's bug fix */ +static void flt_round(float *pf) +{ + int flg; + u_int32_t tmp; + float *pt = (float *)&tmp; + *pt = *pf; + flg = tmp & (u_int32_t)0x00008000; + tmp &= (u_int32_t)0xffff0000; + *pf = *pt; + /* round 1/2 lsb toward infinity */ + if (flg) { + tmp &= (u_int32_t)0xff800000; /* extract exponent and sign */ + tmp |= (u_int32_t)0x00010000; /* insert 1 lsb */ + *pf += *pt; /* add 1 lsb and elided one */ + tmp &= (u_int32_t)0xff800000; /* extract exponent and sign */ + *pf -= *pt; /* subtract elided one */ + } +} + + +/* This only works for 1.0 < float < 2.0 - 2^-24 ! + * + * Comparison of the performance of the two rounding routines: + * old (above) new (below) + * Max error 0.00385171 0.00179992 + * RMS error 0.00194603 0.00109221 + */ + +/* New bug fixed version */ +static void inv_table_flt_round(float *ftmp) +{ + int exp; + double mnt; + float descale; + + mnt = frexp((double)*ftmp, &exp); + descale = (float)ldexp(1.0, exp + 15); + *ftmp += descale; + *ftmp -= descale; +} + +static void make_inv_tables(faacDecHandle hDecoder) +{ + int i; + u_int32_t tmp1, tmp; + float *pf = (float *)&tmp; + float ftmp; + + *pf = 1.0; + tmp1 = tmp; /* float 1.0 */ + for (i=0; i<128; i++) { + tmp = tmp1 + (i<<16); /* float 1.m, 7 msb only */ + ftmp = B / *pf; + inv_table_flt_round(&ftmp); /* round to 16 bits */ + hDecoder->mnt_table[i] = ftmp; + /* printf("%3d %08x %f\n", i, tmp, ftmp); */ + } + for (i=0; i<256; i++) { + tmp = (i<<23); /* float 1.0 * 2^exp */ + if (*pf > MINVAR) { + ftmp = 1.0f / *pf; + } else { + ftmp = 0; + } + hDecoder->exp_table[i] = ftmp; + /* printf("%3d %08x %g\n", i, tmp, ftmp); */ + } +} + +/* Bug-fixed version (big-little endian problem) */ +static void inv_quant_pred_state(TMP_PRED_STATUS *tmp_psp, PRED_STATUS *psp) +{ + int i; + short *p2; + u_int32_t *p1_tmp; + + p1_tmp = (u_int32_t *)tmp_psp; + p2 = (short *) psp; + + for (i=0; i>16); + +#else + int j; + for (i=0; i>16); + } +#endif +} + +/******************************************************************************** + *** FUNCTION: reset_pred_state() * + *** * + *** reset predictor state variables * + *** * + ********************************************************************************/ +void reset_pred_state(PRED_STATUS *psp) +{ + psp->r[0] = Q_ZERO; + psp->r[1] = Q_ZERO; + psp->kor[0] = Q_ZERO; + psp->kor[1] = Q_ZERO; + psp->var[0] = Q_ONE; + psp->var[1] = Q_ONE; +} + +/******************************************************************************** + *** FUNCTION: init_pred_stat() * + *** * + *** initialisation of all predictor parameter * + *** * + ********************************************************************************/ +void init_pred_stat(faacDecHandle hDecoder, PRED_STATUS *psp, int first_time) +{ + /* Initialisation */ + if (first_time) { + make_inv_tables(hDecoder); + } + + reset_pred_state(psp); +} + +void init_pred(faacDecHandle hDecoder, PRED_STATUS **sp_status, int channels) +{ + int i, ch; + + for (ch = 0; ch < channels; ch++) { + for (i = 0; i < LN2; i++) { + init_pred_stat(hDecoder, &sp_status[ch][i], ((ch==0)&&(i==0))); + } + } +} + +/******************************************************************************** + *** FUNCTION: monopred() * + *** * + *** calculation of a predicted value from preceeding (quantised) samples * + *** using a second order backward adaptive lattice predictor with full * + *** LMS adaption algorithm for calculation of predictor coefficients * + *** * + *** parameters: pc: pointer to this quantised sample * + *** psp: pointer to structure with predictor status * + *** pred_flag: 1 if prediction is used * + *** * + ********************************************************************************/ + +static void monopred(faacDecHandle hDecoder, Float *pc, PRED_STATUS *psp, TMP_PRED_STATUS *pst, int pred_flag) +{ + float qc = *pc; /* quantized coef */ + float pv; /* predicted value */ + float dr1; /* difference in the R-branch */ + float e0,e1; /* "partial" prediction errors (E-branch) */ + float r0,r1; /* content of delay elements */ + float k1,k2; /* predictor coefficients */ + + float *R = pst->r; /* content of delay elements */ + float *KOR = pst->kor; /* estimates of correlations */ + float *VAR = pst->var; /* estimates of variances */ + u_int32_t tmp; + int i, j; + + r0=R[0]; + r1=R[1]; + + /* Calculation of predictor coefficients to be used for the + * calculation of the current predicted value based on previous + * block's state + */ + + /* the test, division and rounding is be pre-computed in the tables + * equivalent calculation is: + * k1 = (VAR[1-1]>MINVAR) ? KOR[1-1]/VAR[1-1]*B : 0.0F; + * k2 = (VAR[2-1]>MINVAR) ? KOR[2-1]/VAR[2-1]*B : 0.0F; + */ + tmp = psp->var[1-1]; + j = (tmp >> 7); + i = tmp & 0x7f; + k1 = KOR[1-1] * hDecoder->exp_table[j] * hDecoder->mnt_table[i]; + + tmp = psp->var[2-1]; + j = (tmp >> 7); + i = tmp & 0x7f; + k2 = KOR[2-1] * hDecoder->exp_table[j] * hDecoder->mnt_table[i]; + + /* Predicted value */ + pv = k1*r0 + k2*r1; + flt_round(&pv); + if (pred_flag) + *pc = qc + pv; +/* printf("P1: %8.2f %8.2f\n", pv, *pc); */ + + /* Calculate state for use in next block */ + + /* E-Branch: + * Calculate the partial prediction errors using the old predictor coefficients + * and the old r-values in order to reconstruct the predictor status of the + * previous step + */ + + e0 = *pc; + e1 = e0-k1*r0; + + /* Difference in the R-Branch: + * Calculate the difference in the R-Branch using the old predictor coefficients and + * the old partial prediction errors as calculated above in order to reconstruct the + * predictor status of the previous step + */ + + dr1 = k1*e0; + + /* Adaption of variances and correlations for predictor coefficients: + * These calculations are based on the predictor status of the previous step and give + * the new estimates of variances and correlations used for the calculations of the + * new predictor coefficients to be used for calculating the current predicted value + */ + + VAR[1-1] = ALPHA*VAR[1-1]+(0.5F)*(r0*r0 + e0*e0); /* float const */ + KOR[1-1] = ALPHA*KOR[1-1] + r0*e0; + VAR[2-1] = ALPHA*VAR[2-1]+(0.5F)*(r1*r1 + e1*e1); /* float const */ + KOR[2-1] = ALPHA*KOR[2-1] + r1*e1; + + /* Summation and delay in the R-Branch => new R-values */ + + r1 = A*(r0-dr1); + r0 = A*e0; + + R[0]=r0; + R[1]=r1; +} + + + + +/******************************************************************************** + *** FUNCTION: predict() * + *** * + *** carry out prediction for all allowed spectral lines * + *** * + ********************************************************************************/ + + +int predict(faacDecHandle hDecoder, Info* info, int profile, int *lpflag, PRED_STATUS *psp, Float *coef) +{ + int j, k, b, to, flag0; + int *top; + + if (hDecoder->mc_info.object_type != AACMAIN) { + if (*lpflag == 0) { + /* prediction calculations not required */ + return 0; + } + else { + return -1; + } + } + + if (info->islong) { + TMP_PRED_STATUS tmp_ps[MAX_PRED_BINS]; + inv_quant_pred_state(tmp_ps, psp); + b = 0; + k = 0; + top = info->sbk_sfb_top[b]; + flag0 = *lpflag++; + for (j = 0; j < pred_max_bands(hDecoder); j++) { + to = *top++; + if (flag0 && *lpflag++) { + for ( ; k < to; k++) { + monopred(hDecoder, &coef[k], &psp[k], &tmp_ps[k], 1); + } + } else { + for ( ; k < to; k++) { + monopred(hDecoder, &coef[k], &psp[k], &tmp_ps[k], 0); + } + } + } + quant_pred_state(psp, tmp_ps); + } + return 0; +} + + + + + +/******************************************************************************** + *** FUNCTION: predict_reset() * + *** * + *** carry out cyclic predictor reset mechanism (long blocks) * + *** resp. full reset (short blocks) * + *** * + ********************************************************************************/ +int predict_reset(faacDecHandle hDecoder, Info* info, int *prstflag, PRED_STATUS **psp, + int firstCh, int lastCh, int *last_rstgrp_num) +{ + int j, prstflag0, prstgrp, ch; + + prstgrp = 0; + if (info->islong) { + prstflag0 = *prstflag++; + if (prstflag0) { + + /* for loop modified because of bit-reversed group number */ + for (j=0; j30) ) { + return -1; + } + + for (ch=firstCh; ch<=lastCh; ch++) { + /* check if two consecutive reset group numbers are incremented by one + (this is a poor check, but we don't have much alternatives) */ + if ((hDecoder->warn_flag) && (last_rstgrp_num[ch] < 30) && (last_rstgrp_num[ch] != 0)) { + if ((last_rstgrp_num[ch] + 1) != prstgrp) { + hDecoder->warn_flag = 0; + } + } + last_rstgrp_num[ch] = prstgrp; + for (j=prstgrp-1; j header file. */ +#define HAVE_BYTESWAP_H 1 + +/* Define to 1 if you have the declaration of `avcodec_decode_audio2', and to + 0 if you don't. */ +/* #undef HAVE_DECL_AVCODEC_DECODE_AUDIO2 */ + +/* have /dev/urandom */ +#define HAVE_DEV_URANDOM 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* enable faac for mp4live */ +/* #undef HAVE_FAAC */ + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* enable ffmpeg for mp4live */ +/* #undef HAVE_FFMPEG */ + +/* defined if ffmpeg is installed */ +/* #undef HAVE_FFMPEG_INSTALLED */ + +/* Define to 1 if `__pos' is member of `fpos_t'. */ +#define HAVE_FPOS_T___POS 1 + +/* have getipnodebyname */ +/* #undef HAVE_GETIPNODEBYNAME */ + +/* Define to 1 if you have the `getopt' function. */ +#define HAVE_GETOPT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_GETOPT_H 1 + +/* Define to 1 if you have the `getopt_long' function. */ +#define HAVE_GETOPT_LONG 1 + +/* Define to 1 if you have the `getopt_long_only' function. */ +#define HAVE_GETOPT_LONG_ONLY 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_GLIB_H */ + +/* Have GTK on system */ +/* #undef HAVE_GTK */ + +/* Have GTK 2.0 on system */ +/* #undef HAVE_GTK_2_0 */ + +/* have id3/tag.h */ +/* #undef HAVE_ID3_TAG_H */ + +/* IGMPv3 definition */ +/* #undef HAVE_IGMP_V3 */ + +/* Define to 1 if you have the `inet_aton' function. */ +#define HAVE_INET_ATON 1 + +/* Define to 1 if you have the `inet_ntoa' function. */ +#define HAVE_INET_NTOA 1 + +/* Define to 1 if you have the `inet_ntop' function. */ +#define HAVE_INET_NTOP 1 + +/* Define to 1 if you have the `inet_pton' function. */ +#define HAVE_INET_PTON 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if the system has the type `in_port_t'. */ +#define HAVE_IN_PORT_T 1 + +/* enable IPv6 architecture */ +/* #undef HAVE_IPv6 */ + +/* enable lame for mp4live */ +/* #undef HAVE_LAME */ + +/* Define to 1 if you have the `asound' library (-lasound). */ +/* #undef HAVE_LIBASOUND */ + +/* Define to 1 if you have the `gnugetopt' library (-lgnugetopt). */ +/* #undef HAVE_LIBGNUGETOPT */ + +/* have libmpeg2 decoder library */ +/* #undef HAVE_LIBMPEG2 */ + +/* Define to 1 if you have the `socket' library (-lsocket). */ +/* #undef HAVE_LIBSOCKET */ + +/* have mac */ +/* #undef HAVE_MACOSX */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* mp4live can be used */ +#define HAVE_MP4LIVE 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_NETINET6_IN6_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_NETINET_IP6_H */ + +/* Define to 1 if you have the `poll' function. */ +#define HAVE_POLL 1 + +/* have sin6_len */ +/* #undef HAVE_SIN6_LEN */ + +/* Define to 1 if you have the `snd_pcm_hw_params_set_rate_resample' function. + */ +/* #undef HAVE_SND_PCM_HW_PARAMS_SET_RATE_RESAMPLE */ + +/* Define to 1 if you have the `socketpair' function. */ +#define HAVE_SOCKETPAIR 1 + +/* Define to 1 if the system has the type `socklen_t'. */ +#define HAVE_SOCKLEN_T 1 + +/* enable use of srtp library */ +/* #undef HAVE_SRTP */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strcasestr' function. */ +#define HAVE_STRCASESTR 1 + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strsep' function. */ +#define HAVE_STRSEP 1 + +/* Define to 1 if the system has the type `struct iovec'. */ +#define HAVE_STRUCT_IOVEC 1 + +/* Define to 1 if the system has the type `struct ip_mreq_source'. */ +/* #undef HAVE_STRUCT_IP_MREQ_SOURCE */ + +/* Define to 1 if the system has the type `struct sockaddr_storage'. */ +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* enable twolame for mp4live */ +/* #undef HAVE_TWOLAME */ + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `vsnprintf' function. */ +#define HAVE_VSNPRINTF 1 + +/* enable x264 for mp4live */ +/* #undef HAVE_X264 */ + +/* Define to 1 if `rc.i_rc_method' is member of `x264_param_t'. */ +/* #undef HAVE_X264_PARAM_T_RC_I_RC_METHOD */ + +/* have xvid.h with 1.0 API */ +/* #undef HAVE_XVID10 */ + +/* have xvid.h */ +/* #undef HAVE_XVID_H */ + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "mpeg4ip" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "mpeg4ip 1.6.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "mpeg4ip" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.6.1" + +/* The size of a `bool', as computed by sizeof. */ +#define SIZEOF_BOOL 1 + +/* The size of a `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if you can safely include both and . */ +#define TIME_WITH_SYS_TIME 1 + +/* Define to 1 if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). */ +/* #undef WORDS_BIGENDIAN */ + +/* Define to 1 if the X Window System is missing or not being used. */ +#define X_DISPLAY_MISSING 1 + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif diff --git a/nok_lt_prediction.c b/nok_lt_prediction.c new file mode 100644 index 0000000..3b415e4 --- /dev/null +++ b/nok_lt_prediction.c @@ -0,0 +1,178 @@ +/************************************************************************** + +This software module was originally developed by +Nokia in the course of development of the MPEG-2 AAC/MPEG-4 +Audio standard ISO/IEC13818-7, 14496-1, 2 and 3. +This software module is an implementation of a part +of one or more MPEG-2 AAC/MPEG-4 Audio tools as specified by the +MPEG-2 aac/MPEG-4 Audio standard. ISO/IEC gives users of the +MPEG-2aac/MPEG-4 Audio standards free license to this software module +or modifications thereof for use in hardware or software products +claiming conformance to the MPEG-2 aac/MPEG-4 Audio standards. Those +intending to use this software module in hardware or software products +are advised that this use may infringe existing patents. The original +developer of this software module, the subsequent +editors and their companies, and ISO/IEC have no liability for use of +this software module or modifications thereof in an +implementation. Copyright is not released for non MPEG-2 aac/MPEG-4 +Audio conforming products. The original developer retains full right to +use the code for the developer's own purpose, assign or donate the code to a +third party and to inhibit third party from using the code for non +MPEG-2 aac/MPEG-4 Audio conforming products. This copyright notice +must be included in all copies or derivative works. +Copyright (c)1997. + +***************************************************************************/ +/* + * $Id: nok_lt_prediction.c,v 1.9 2003/02/18 18:51:31 wmaycisco Exp $ + */ + +#include "all.h" +#include "tns.h" +#include "block.h" +#include "nok_ltp_common.h" +#include "nok_lt_prediction.h" +#include "nok_ltp_common_internal.h" +#include "port.h" +#include "bits.h" +#include "util.h" + +/* + Initialize the history buffer for long term prediction + */ + +void nok_init_lt_pred(NOK_LT_PRED_STATUS **lt_status, int channels) +{ + int ch; + + for (ch = 0; ch < channels; ch++) { + lt_status[ch]->buffer = AllocMemory(NOK_LT_BLEN*sizeof(float)); +#ifndef _WIN32 + SetMemory(lt_status[ch]->buffer, 0, NOK_LT_BLEN*sizeof(float)); +#endif + } +} + +void nok_end_lt_pred(NOK_LT_PRED_STATUS **lt_status, int channels) +{ + int ch; + + for (ch = 0; ch < channels; ch++) { + if (lt_status[ch]->buffer) FreeMemory(lt_status[ch]->buffer); + } +} + + +/************************************************************************** + nok_lt_prediction + *************************************************************************/ + +void nok_lt_predict(faacDecHandle hDecoder, Info *info, WINDOW_TYPE win_type, Wnd_Shape *win_shape, + int *sbk_prediction_used, int *sfb_prediction_used, + NOK_LT_PRED_STATUS *lt_status, Float weight, int *delay, + Float *current_frame, int block_size_long, int block_size_medium, + int block_size_short, TNS_frame_info *tns_frame_info) +{ + int i, j, num_samples; + float_ext *mdct_predicted; + float_ext *predicted_samples; + + mdct_predicted = AllocMemory(2*NOK_MAX_BLOCK_LEN_LONG*sizeof(float_ext)); + predicted_samples = AllocMemory(2*NOK_MAX_BLOCK_LEN_LONG*sizeof(float_ext)); + + + switch(win_type) { + + case ONLY_LONG_WINDOW: + case LONG_START_WINDOW: + case LONG_STOP_WINDOW: + if (sbk_prediction_used[0]) + { + /* Prediction for time domain signal */ + num_samples = 2 * block_size_long; + j = NOK_LT_BLEN - 2 * block_size_long - (delay[0] - MAX_LTP_DELAY / 2); + if(NOK_LT_BLEN - j < 2 * block_size_long) + num_samples = NOK_LT_BLEN - j; + + for(i = 0; i < num_samples; i++) + predicted_samples[i] = weight * lt_status->buffer[i + j]; + for( ; i < 2 * block_size_long; i++) + predicted_samples[i] = 0.0f; + + /* Transform prediction to frequency domain. */ + time2freq_adapt(hDecoder, win_type, win_shape, predicted_samples, mdct_predicted); + + /* Apply the TNS analysis filter to the predicted spectrum. */ + if(tns_frame_info != NULL) + tns_filter_subblock(hDecoder, mdct_predicted, info->sfb_per_bk, info->sbk_sfb_top[0], + 1, &tns_frame_info->info[0]); + + /* Clean those sfb's where prediction is not used. */ + for (i = 0, j = 0; i < info->sfb_per_bk; i++) { + if (sfb_prediction_used[i + 1] == 0) { + for (; j < info->sbk_sfb_top[0][i]; j++) + mdct_predicted[j] = 0.0; + } else { + j = info->sbk_sfb_top[0][i]; + } + } + + /* Add the prediction to dequantized spectrum. */ + for (i = 0; i < block_size_long; i++) + current_frame[i] = current_frame[i] + mdct_predicted[i]; + } + break; + + default: + break; + } + + FreeMemory(mdct_predicted); + FreeMemory(predicted_samples); +} + +/************************************************************************** + nok_lt_update + *************************************************************************/ + +void nok_lt_update(NOK_LT_PRED_STATUS *lt_status, Float *time_signal, + Float *overlap_signal, int block_size_long) +{ + int i; + + for(i = 0; i < NOK_LT_BLEN - 2 * block_size_long; i++) + lt_status->buffer[i] = lt_status->buffer[i + block_size_long]; + + for(i = 0; i < block_size_long; i++) + { + lt_status->buffer[NOK_LT_BLEN - 2 * block_size_long + i] = + time_signal[i]; + + lt_status->buffer[NOK_LT_BLEN - block_size_long + i] = + overlap_signal[i]; + } +} + +/************************************************************************** + nok_lt_decode + *************************************************************************/ +void nok_lt_decode(faacDecHandle hDecoder, int max_sfb, int *sbk_prediction_used, + int *sfb_prediction_used, Float *weight, int *delay) +{ + int i, last_band; + + if ((sbk_prediction_used[0] = faad_getbits(&hDecoder->ld, LEN_LTP_DATA_PRESENT))) + { + delay[0] = faad_getbits(&hDecoder->ld, 11); + *weight = codebook[faad_getbits(&hDecoder->ld, 3)]; + + last_band = (max_sfb < NOK_MAX_LT_PRED_LONG_SFB + ? max_sfb : NOK_MAX_LT_PRED_LONG_SFB) + 1; + + sfb_prediction_used[0] = sbk_prediction_used[0]; + for (i = 1; i < last_band; i++) + sfb_prediction_used[i] = faad_getbits(&hDecoder->ld, LEN_LTP_LONG_USED); + for (; i < max_sfb + 1; i++) + sfb_prediction_used[i] = 0; + } +} diff --git a/nok_lt_prediction.h b/nok_lt_prediction.h new file mode 100644 index 0000000..00fae12 --- /dev/null +++ b/nok_lt_prediction.h @@ -0,0 +1,56 @@ +/************************************************************************ + +This software module was originally developed by +Nokia in the course of development of the MPEG-2 AAC/MPEG-4 +Audio standard ISO/IEC13818-7, 14496-1, 2 and 3. +This software module is an implementation of a part +of one or more MPEG-2 AAC/MPEG-4 Audio tools as specified by the +MPEG-2 aac/MPEG-4 Audio standard. ISO/IEC gives users of the +MPEG-2aac/MPEG-4 Audio standards free license to this software module +or modifications thereof for use in hardware or software products +claiming conformance to the MPEG-2 aac/MPEG-4 Audio standards. Those +intending to use this software module in hardware or software products +are advised that this use may infringe existing patents. The original +developer of this software module, the subsequent +editors and their companies, and ISO/IEC have no liability for use of +this software module or modifications thereof in an +implementation. Copyright is not released for non MPEG-2 aac/MPEG-4 +Audio conforming products. The original developer retains full right to +use the code for the developer's own purpose, assign or donate the code to a +third party and to inhibit third party from using the code for non +MPEG-2 aac/MPEG-4 Audio conforming products. This copyright notice +must be included in all copies or derivative works. +Copyright (c)1997. + +***************************************************************************/ + +#ifndef _NOK_LT_PREDICTION_H +#define _NOK_LT_PREDICTION_H + +#include "all.h" +#include "block.h" +#include "nok_ltp_common.h" + +#define truncate(sig_in) \ + ((sig_in) > 32767 ? 32767 : ( \ + (sig_in) < -32768 ? -32768 : ( \ + (sig_in) > 0.0 ? (sig_in)+0.5 : ( \ + (sig_in) <= 0.0 ? (sig_in)-0.5 : 0)))) + + +extern void nok_init_lt_pred(NOK_LT_PRED_STATUS **lt_status, int channels); +extern void nok_end_lt_pred(NOK_LT_PRED_STATUS **lt_status, int channels); + +extern void nok_lt_predict(faacDecHandle hDecoder, Info *info, WINDOW_TYPE win_type, Wnd_Shape *win_shape, + int *sbk_prediction_used, int *sfb_prediction_used, + NOK_LT_PRED_STATUS *lt_status, Float weight, int *delay, + Float *current_frame, int block_size_long, int block_size_medium, + int block_size_short, TNS_frame_info *tns_frame_info); + +extern void nok_lt_update(NOK_LT_PRED_STATUS *lt_status, Float *time_signal, + Float *overlap_signal, int block_size_long); + +extern void nok_lt_decode(faacDecHandle hDecoder, int max_sfb, int *sbk_prediction_used, + int *sfb_prediction_used, Float *weight, int *delay); + +#endif /* not defined _NOK_LT_PREDICTION_H */ diff --git a/nok_ltp_common.h b/nok_ltp_common.h new file mode 100644 index 0000000..e20ba02 --- /dev/null +++ b/nok_ltp_common.h @@ -0,0 +1,88 @@ +/************************************************************************** + +This software module was originally developed by + +Mikko Suonio (Nokia) + +in the course of development of the MPEG-2 NBC/MPEG-4 Audio standard +ISO/IEC 13818-7, 14496-1,2 and 3. This software module is an +implementation of a part of one or more MPEG-2 NBC/MPEG-4 Audio tools +as specified by the MPEG-2 NBC/MPEG-4 Audio standard. ISO/IEC gives +users of the MPEG-2 NBC/MPEG-4 Audio standards free license to this +software module or modifications thereof for use in hardware or +software products claiming conformance to the MPEG-2 NBC/ MPEG-4 Audio +standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing +patents. The original developer of this software module and his/her +company, the subsequent editors and their companies, and ISO/IEC have +no liability for use of this software module or modifications thereof +in an implementation. Copyright is not released for non MPEG-2 +NBC/MPEG-4 Audio conforming products. The original developer retains +full right to use the code for his/her own purpose, assign or donate +the code to a third party and to inhibit third party from using the +code for non MPEG-2 NBC/MPEG-4 Audio conforming products. This +copyright notice must be included in all copies or derivative works. + +Copyright (c) 1997. + +***************************************************************************/ +#ifndef _NOK_LTP_COMMON_H +#define _NOK_LTP_COMMON_H + +/* + Macro: MAX_SHORT_WINDOWS + Purpose: Number of short windows in one long window. + Explanation: - */ +#ifndef MAX_SHORT_WINDOWS +#define MAX_SHORT_WINDOWS NSHORT +#endif + +/* + Macro: MAX_SCFAC_BANDS + Purpose: Maximum number of scalefactor bands in one frame. + Explanation: - */ +#ifndef MAX_SCFAC_BANDS +#define MAX_SCFAC_BANDS MAXBANDS +#endif + +/* + Macro: BLOCK_LEN_LONG + Purpose: Length of one long window + Explanation: - */ +#ifndef BLOCK_LEN_LONG +#define BLOCK_LEN_LONG LN2 +#endif + +/* + Macro: NOK_MAX_BLOCK_LEN_LONG + Purpose: Informs the routine of the maximum block size used. + Explanation: - */ +#define NOK_MAX_BLOCK_LEN_LONG (BLOCK_LEN_LONG) + +/* + Macro: NOK_LT_BLEN + Purpose: Length of the history buffer. + Explanation: Has to hold 1.5 long windows of time domain data. */ +#ifndef NOK_LT_BLEN +#define NOK_LT_BLEN (3 * NOK_MAX_BLOCK_LEN_LONG) +#endif + +/* + Type: NOK_LT_PRED_STATUS + Purpose: Type of the struct holding the LTP encoding parameters. + Explanation: - */ +typedef struct + { + int weight_idx; + float weight; + int sbk_prediction_used[MAX_SHORT_WINDOWS]; + int sfb_prediction_used[MAX_SCFAC_BANDS]; + int delay[MAX_SHORT_WINDOWS]; + int global_pred_flag; + int side_info; + float *buffer; + } +NOK_LT_PRED_STATUS; + + +#endif /* _NOK_LTP_COMMON_H */ diff --git a/nok_ltp_common_internal.h b/nok_ltp_common_internal.h new file mode 100644 index 0000000..540dcb1 --- /dev/null +++ b/nok_ltp_common_internal.h @@ -0,0 +1,117 @@ +/************************************************************************** + +This software module was originally developed by + +Mikko Suonio (Nokia) + +in the course of development of the MPEG-2 NBC/MPEG-4 Audio standard +ISO/IEC 13818-7, 14496-1,2 and 3. This software module is an +implementation of a part of one or more MPEG-2 NBC/MPEG-4 Audio tools +as specified by the MPEG-2 NBC/MPEG-4 Audio standard. ISO/IEC gives +users of the MPEG-2 NBC/MPEG-4 Audio standards free license to this +software module or modifications thereof for use in hardware or +software products claiming conformance to the MPEG-2 NBC/ MPEG-4 Audio +standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing +patents. The original developer of this software module and his/her +company, the subsequent editors and their companies, and ISO/IEC have +no liability for use of this software module or modifications thereof +in an implementation. Copyright is not released for non MPEG-2 +NBC/MPEG-4 Audio conforming products. The original developer retains +full right to use the code for his/her own purpose, assign or donate +the code to a third party and to inhibit third party from using the +code for non MPEG-2 NBC/MPEG-4 Audio conforming products. This +copyright notice must be included in all copies or derivative works. + +Copyright (c) 1997. + +***************************************************************************/ +/* + * $Id: nok_ltp_common_internal.h,v 1.5 2002/01/11 00:55:17 wmaycisco Exp $ + */ + +#ifndef _NOK_LTP_COMMON_INTERNAL_H +#define _NOK_LTP_COMMON_INTERNAL_H + + +/* + Purpose: Number of LTP coefficients. */ +#define LPC 1 + +/* + Purpose: Maximum LTP lag. */ +#define MAX_LTP_DELAY 2048 + +/* + Purpose: Length of the bitstream element ltp_data_present. */ +#define LEN_LTP_DATA_PRESENT 1 + +/* + Purpose: Length of the bitstream element ltp_lag. */ +#define LEN_LTP_LAG 11 + +/* + Purpose: Length of the bitstream element ltp_coef. */ +#define LEN_LTP_COEF 3 + +/* + Purpose: Length of the bitstream element ltp_short_used. */ +#define LEN_LTP_SHORT_USED 1 + +/* + Purpose: Length of the bitstream element ltp_short_lag_present. */ +#define LEN_LTP_SHORT_LAG_PRESENT 1 + +/* + Purpose: Length of the bitstream element ltp_short_lag. */ +#define LEN_LTP_SHORT_LAG 5 + +/* + Purpose: Offset of the lags written in the bitstream. */ +#define NOK_LTP_LAG_OFFSET 16 + +/* + Purpose: Length of the bitstream element ltp_long_used. */ +#define LEN_LTP_LONG_USED 1 + +/* + Purpose: Upper limit for the number of scalefactor bands + which can use lt prediction with long windows. + Explanation: Bands 0..NOK_MAX_LT_PRED_SFB-1 can use lt prediction. */ +#define NOK_MAX_LT_PRED_LONG_SFB 40 + +/* + Purpose: Upper limit for the number of scalefactor bands + which can use lt prediction with short windows. + Explanation: Bands 0..NOK_MAX_LT_PRED_SFB-1 can use lt prediction. */ +#define NOK_MAX_LT_PRED_SHORT_SFB 8 + +/* + Purpose: Buffer offset to maintain block alignment. + Explanation: This is only used for a short window sequence. */ +#define SHORT_SQ_OFFSET (BLOCK_LEN_LONG-(BLOCK_LEN_SHORT*4+BLOCK_LEN_SHORT/2)) + +/* + Purpose: Number of codes for LTP weight. */ +#define CODESIZE 8 + +/* + Purpose: Float type for external data. + Explanation: - */ +typedef Float float_ext; + +/* + Purpose: Codebook for LTP weight coefficients. */ +static Float codebook[CODESIZE] = +{ + 0.570829f, + 0.696616f, + 0.813004f, + 0.911304f, + 0.984900f, + 1.067894f, + 1.194601f, + 1.369533f +}; + +#endif /* _NOK_LTP_COMMON_INTERNAL_H */ diff --git a/pns.c b/pns.c new file mode 100644 index 0000000..ccf5bb0 --- /dev/null +++ b/pns.c @@ -0,0 +1,176 @@ +/************************* MPEG-4 AAC Audio Decoder ************************** + * * +"This software module was originally developed by +AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS in the course of +development of the MPEG-2 AAC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 AAC/MPEG-4 Audio tools as specified by the MPEG-2 AAC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 AAC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 AAC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 AAC/MPEG-4 Audio conforming products. The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 AAC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ +/* + * $Id: pns.c,v 1.6 2002/01/11 00:55:17 wmaycisco Exp $ + */ + +#include "all.h" + + +#define MEAN_NRG 1.5625e+18 /* Theory: (2^31)^2 / 3 = 1.537228e+18 */ + +static void random2(long *seed) +{ + *seed = (1664525L * *seed) + 1013904223L; /* Numerical recipes */ +} + + +static void gen_rand_vector(float *spec, int size, long *state) +/* Noise generator, generating vector with unity energy */ +{ + int i; + float s, norm, nrg= 0.0; + + norm = 1.0f / (float)sqrt( size * MEAN_NRG ); + + for (i=0; ich_info[ch]; + Float *spec, *fp, scale; + int cb, corr_flag, sfb, n, nn, b, bb, nband; + int *band; + long *nsp; + + /* store original predictor flags when left channel of a channel pair */ + if ((cip->cpe && cip->ch_is_left && info->islong)) + for (sfb=0; sfbsfb_per_sbk[0]; sfb++) + hDecoder->lp_store[sfb+1] = lpflag[sfb+1]; + + /* restore original predictor flags when right channel of a channel pair */ + if ((cip->cpe && !cip->ch_is_left && info->islong)) + for (sfb=0; sfbsfb_per_sbk[0]; sfb++) + lpflag[sfb+1] = hDecoder->lp_store[sfb+1]; + + spec = coef[ ch ]; + nsp = hDecoder->noise_state_save; + + /* PNS goes by group */ + bb = 0; + for (b = 0; b < info->nsbk; ) { + nband = info->sfb_per_sbk[b]; + band = info->sbk_sfb_top[b]; + + b = *group++; /* b = index of last sbk in group */ + for (; bb < b; bb++) { /* bb = sbk index */ + n = 0; + for (sfb = 0; sfb < nband; sfb++){ + nn = band[sfb]; /* band is offset table, nn is last coef in band */ + cb = cb_map[sfb]; + if (cb == NOISE_HCB || cb == NOISE_HCB+100) { + /* found noise substitution code book */ + + /* disable prediction (only important for long blocks) */ + if (info->islong) lpflag[1+sfb] = 0; + + /* determine left/right correlation */ + corr_flag = (cb != NOISE_HCB); + + /* reconstruct noise substituted values */ + /* generate random noise */ + fp = spec + n; + if (corr_flag) { + /* Start with stored state */ + gen_rand_vector( fp, nn-n, nsp+sfb ); + } else { + /* Store current state and go */ + nsp[sfb] = hDecoder->cur_noise_state; + gen_rand_vector( fp, nn-n, &hDecoder->cur_noise_state ); + } + + /* scale to target energy */ + scale = (float)pow( 2.0, 0.25*(factors[sfb]) ); + for (; n < nn; n++) { /* n is coef index */ + *fp++ *= scale; + } + } + n = nn; + } + spec += info->bins_per_sbk[bb]; + factors += nband; + } + nsp += info->sfb_per_sbk[bb-1]; + cb_map += info->sfb_per_sbk[bb-1]; + } +} + + +/******************************************************************************** + *** FUNCTION: predict_pns_reset() * + *** * + *** carry out predictor reset for PNS scalefactor bands (long blocks) * + *** * + ********************************************************************************/ +void predict_pns_reset(Info* info, PRED_STATUS *psp, byte *cb_map) +{ + int nband, sfb, i, top; + int *band; + + if (info->islong) { + + nband = info->sfb_per_sbk[0]; + band = info->sbk_sfb_top[0]; + + for (i=0,sfb=0; sfbnsbk; ){ + nband = info->sfb_per_sbk[b]; + band = info->sbk_sfb_top[b]; + + b = *group++; /*b = index of last sbk in group */ + for(; bb < b; bb++){ /* bb = sbk index */ + n = 0; + for(i = 0; i < nband; i++){ + nn = band[i]; /* band is offset table, nn is last coef in band */ + if(mask[i]){ + r = right + n; + l = left + n; + for(; n < nn; n++){ /* n is coef index */ + vrr = *r; + vrl = *l; + *l = vrr + vrl; + *r = vrl - vrr; + r++; + l++; + } + } + n = nn; + } + right += info->bins_per_sbk[bb]; + left += info->bins_per_sbk[bb]; + + } + mask += info->sfb_per_sbk[bb-1]; + } +} + + +/* Map mask to intensity stereo signalling */ +void map_mask(Info *info, byte *group, byte *mask, byte *cb_map) +{ + int sfb, b, nband; + + /* mask goes by group */ + for (b = 0; b < info->nsbk; ) { + nband = info->sfb_per_sbk[b]; + + for (sfb = 0; sfbsfb_per_sbk[b]; + cb_map += info->sfb_per_sbk[b]; + b = *group++; /* b = index of last sbk in group */ + } +} + diff --git a/tns.c b/tns.c new file mode 100644 index 0000000..dcbc220 --- /dev/null +++ b/tns.c @@ -0,0 +1,245 @@ +/************************* MPEG-2 NBC Audio Decoder ************************** + * * +"This software module was originally developed by +AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS in the course of +development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ +/* + * $Id: tns.c,v 1.8 2003/02/18 18:51:31 wmaycisco Exp $ + */ + +#include "all.h" +#include "util.h" + +#define sfb_offset(x) ( ((x) > 0) ? sfb_top[(x)-1] : 0 ) + +/* Decoder transmitted coefficients for one TNS filter */ +static void tns_decode_coef( int order, int coef_res, int *coef, Float *a ) +{ + int i, m; + Float iqfac, iqfac_m; + Float tmp[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1]; + + /* Inverse quantization */ + iqfac = ((1 << (coef_res-1)) - 0.5f) / (C_PI/2.0f); + iqfac_m = ((1 << (coef_res-1)) + 0.5f) / (C_PI/2.0f); + for (i=0; i= 0) ? iqfac : iqfac_m) ); + } + /* Conversion to LPC coefficients + * Markel and Gray, pg. 95 + */ + a[0] = 1; + for (m=1; m<=order; m++) { + b[0] = a[0]; + for (i=1; i0; j--) + state[j] = state[j-1]; + state[0] = y; + *spec = y; + spec += inc; + } +} + +/* TNS decoding for one channel and frame */ +void tns_decode_subblock(faacDecHandle hDecoder, Float *spec, int nbands, + int *sfb_top, int islong, TNSinfo *tns_info) +{ + int f, m, start, stop, size, inc; + int n_filt, coef_res, order, direction; + int *coef; + Float lpc[TNS_MAX_ORDER+1]; + TNSfilt *filt; + + n_filt = tns_info->n_filt; + for (f=0; fcoef_res; + filt = &tns_info->filt[f]; + order = filt->order; + direction = filt->direction; + coef = filt->coef; + start = filt->start_band; + stop = filt->stop_band; + + m = tns_max_order(hDecoder, islong); + if (order > m) { + order = m; + } + if (!order) continue; + + tns_decode_coef(order, coef_res, coef, lpc); + + start = min(start, tns_max_bands(hDecoder, islong)); + start = min(start, nbands); + start = sfb_offset( start ); + + stop = min(stop, tns_max_bands(hDecoder, islong)); + stop = min(stop, nbands); + stop = sfb_offset( stop ); + if ((size = stop - start) <= 0) continue; + + if (direction) { + inc = -1; + } else { + inc = 1; + } + + tns_ar_filter( &spec[start], size, inc, lpc, order ); + } +} + + +/********************************************************/ +/* TnsInvFilter: */ +/* Inverse filter the given spec with specified */ +/* length using the coefficients specified in filter. */ +/* Not that the order and direction are specified */ +/* withing the TNS_FILTER_DATA structure. */ +/********************************************************/ +static void TnsInvFilter(int length, Float *spec, TNSfilt *filter, Float *coef) +{ + int i,j,k = 0; + int order = filter->order; + Float *a = coef; + Float *temp; + + temp = (Float *)AllocMemory(length * sizeof (Float)); + + /* Determine loop parameters for given direction */ + if (filter->direction) + { + /* Startup, initial state is zero */ + temp[length-1]=spec[length-1]; + for (i=length-2;i>(length-1-order);i--) { + temp[i]=spec[i]; + k++; + for (j=1;j<=k;j++) { + spec[i]+=temp[i+j]*a[j]; + } + } + + /* Now filter the rest */ + for (i=length-1-order;i>=0;i--) { + temp[i]=spec[i]; + for (j=1;j<=order;j++) { + spec[i]+=temp[i+j]*a[j]; + } + } + + } else { + /* Startup, initial state is zero */ + temp[0]=spec[0]; + for (i=1;in_filt; + for (f=0; fcoef_res; + filt = &tns_info->filt[f]; + order = filt->order; + coef = filt->coef; + start = filt->start_band; + stop = filt->stop_band; + + m = tns_max_order(hDecoder, islong); + if (order > m) + order = m; + + if (!order) continue; + + tns_decode_coef(order, coef_res, coef, lpc); + + start = min(start, tns_max_bands(hDecoder, islong)); + start = min(start, nbands); + start = sfb_offset( start ); + + stop = min(stop, tns_max_bands(hDecoder, islong)); + stop = min(stop, nbands); + stop = sfb_offset( stop ); + if ((size = stop - start) <= 0) + continue; + + TnsInvFilter(size, spec + start, filt, lpc); + } +} + diff --git a/tns.h b/tns.h new file mode 100644 index 0000000..4428613 --- /dev/null +++ b/tns.h @@ -0,0 +1,59 @@ +/************************* MPEG-2 NBC Audio Decoder ************************** + * * +"This software module was originally developed by +AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS in the course of +development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ +/* + * $Id: tns.h,v 1.5 2002/01/11 00:55:17 wmaycisco Exp $ + */ + +#ifndef _tns_h_ +#define _tns_h_ + +#define TNS_MAX_BANDS 49 +#define TNS_MAX_ORDER 31 +#define TNS_MAX_WIN 8 +#define TNS_MAX_FILT 3 + +typedef struct +{ + int start_band; + int stop_band; + int order; + int direction; + int coef_compress; + int coef[TNS_MAX_ORDER]; +} TNSfilt; + +typedef struct +{ + int n_filt; + int coef_res; + TNSfilt filt[TNS_MAX_FILT]; +} TNSinfo; + +typedef struct +{ + int n_subblocks; + TNSinfo info[TNS_MAX_WIN]; +} TNS_frame_info; + +#endif /* _tns_h_ */ diff --git a/transfo.c b/transfo.c new file mode 100644 index 0000000..8ef6241 --- /dev/null +++ b/transfo.c @@ -0,0 +1,461 @@ +/************************* MPEG-2 NBC Audio Decoder ************************** + * * +"This software module was originally developed by +AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS in the course of +development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, +14496-1,2 and 3. This software module is an implementation of a part of one or more +MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 +Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio +standards free license to this software module or modifications thereof for use in +hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4 +Audio standards. Those intending to use this software module in hardware or +software products are advised that this use may infringe existing patents. +The original developer of this software module and his/her company, the subsequent +editors and their companies, and ISO/IEC have no liability for use of this software +module or modifications thereof in an implementation. Copyright is not released for +non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer +retains full right to use the code for his/her own purpose, assign or donate the +code to a third party and to inhibit third party from using the code for non +MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must +be included in all copies or derivative works." +Copyright(c)1996. + * * + ****************************************************************************/ +/* + * $Id: transfo.c,v 1.5 2002/01/11 00:55:17 wmaycisco Exp $ + */ + +#include +#include "all.h" +#include "transfo.h" +#include "fastfft.h" + +/* +#define INTEL_SPL +*/ + +#ifdef INTEL_SPL +#define nsp_UsesAll +#include +#include + +/* choose the library that best fits your processor */ +#pragma comment (lib, "nsppxl.lib") +#endif + + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#ifndef M_PI_2 +#define M_PI_2 1.57079632679489661923 +#endif + +void MDCT_Long(faacDecHandle hDecoder, fftw_real *data) +{ +#ifdef INTEL_SPL + SCplx FFT_data[512]; +#else + fftw_complex FFTarray[512]; /* the array for in-place FFT */ +#endif + fftw_real tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */ +/* fftw_real freq = 0.0030679616611450911f; */ + fftw_real fac,cosfreq8,sinfreq8; + int i, n; + int b = 2048 >> 1; + int N4 = 2048 >> 2; + int N2 = 2048 >> 1; + int a = 2048 - b; + int a2 = a >> 1; + int a4 = a >> 2; + int b4 = b >> 2; + int unscambled; + + + /* Choosing to allocate 2/N factor to Inverse Xform! */ + fac = 2.; /* 2 from MDCT inverse to forward */ + + /* prepare for recurrence relation in pre-twiddle */ + cfreq = 0.99999529123306274f; + sfreq = 0.0030679567717015743f; + cosfreq8 = 0.99999994039535522f; + sinfreq8 = 0.00038349519824312089f; + + c = cosfreq8; + s = sinfreq8; + + for (i = 0; i < N4; i++) + { + /* calculate real and imaginary parts of g(n) or G(p) */ + + n = 2048 / 2 - 1 - 2 * i; + if (i < b4) { + tempr = data [a2 + n] + data [2048 + a2 - 1 - n]; /* use second form of e(n) for n = N / 2 - 1 - 2i */ + } else { + tempr = data [a2 + n] - data [a2 - 1 - n]; /* use first form of e(n) for n = N / 2 - 1 - 2i */ + } + n = 2 * i; + if (i < a4) { + tempi = data [a2 + n] - data [a2 - 1 - n]; /* use first form of e(n) for n=2i */ + } else { + tempi = data [a2 + n] + data [2048 + a2 - 1 - n]; /* use second form of e(n) for n=2i*/ + } + + /* calculate pre-twiddled FFT input */ +#ifdef INTEL_SPL + FFT_data[i].re = tempr * c + tempi * s; + FFT_data[i].im = tempi * c - tempr * s; +#else + FFTarray [i].re = tempr * c + tempi * s; + FFTarray [i].im = tempi * c - tempr * s; +#endif + + /* use recurrence to prepare cosine and sine for next value of i */ + cold = c; + c = c * cfreq - s * sfreq; + s = s * cfreq + cold * sfreq; + } + + /* Perform in-place complex FFT of length N/4 */ +#ifdef INTEL_SPL + nspcFft(FFT_data, 9, NSP_Forw); +#else + pfftw_512(FFTarray); +#endif + + + /* prepare for recurrence relations in post-twiddle */ + c = cosfreq8; + s = sinfreq8; + + /* post-twiddle FFT output and then get output data */ + for (i = 0; i < N4; i++) + { + + /* get post-twiddled FFT output */ + /* Note: fac allocates 4/N factor from IFFT to forward and inverse */ +#ifdef INTEL_SPL + tempr = fac * (FFT_data[i].re * c + FFT_data[i].im * s); + tempi = fac * (FFT_data[i].im * c - FFT_data[i].re * s); +#else + unscambled = hDecoder->unscambled512[i]; + + tempr = fac * (FFTarray [unscambled].re * c + FFTarray [unscambled].im * s); + tempi = fac * (FFTarray [unscambled].im * c - FFTarray [unscambled].re * s); +#endif + + /* fill in output values */ + data [2 * i] = -tempr; /* first half even */ + data [N2 - 1 - 2 * i] = tempi; /* first half odd */ + data [N2 + 2 * i] = -tempi; /* second half even */ + data [2048 - 1 - 2 * i] = tempr; /* second half odd */ + + /* use recurrence to prepare cosine and sine for next value of i */ + cold = c; + c = c * cfreq - s * sfreq; + s = s * cfreq + cold * sfreq; + } +} + +void MDCT_Short(faacDecHandle hDecoder, fftw_real *data) +{ +#ifdef INTEL_SPL + SCplx FFT_data[64]; +#else + fftw_complex FFTarray[64]; /* the array for in-place FFT */ +#endif + fftw_real tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */ +/* fftw_real freq = 0.024543693289160728f; */ + fftw_real fac,cosfreq8,sinfreq8; + int i, n; + int b = 256 >> 1; + int N4 = 256 >> 2; + int N2 = 256 >> 1; + int a = 256 - b; + int a2 = a >> 1; + int a4 = a >> 2; + int b4 = b >> 2; + int unscambled; + + + /* Choosing to allocate 2/N factor to Inverse Xform! */ + fac = 2.; /* 2 from MDCT inverse to forward */ + + /* prepare for recurrence relation in pre-twiddle */ + cfreq = 0.99969881772994995f; + sfreq = 0.024541229009628296f; + cosfreq8 = 0.99999529123306274f; + sinfreq8 = 0.0030679568483393833f; + + c = cosfreq8; + s = sinfreq8; + + for (i = 0; i < N4; i++) + { + /* calculate real and imaginary parts of g(n) or G(p) */ + + n = 256 / 2 - 1 - 2 * i; + if (i < b4) { + tempr = data [a2 + n] + data [256 + a2 - 1 - n]; /* use second form of e(n) for n = N / 2 - 1 - 2i */ + } else { + tempr = data [a2 + n] - data [a2 - 1 - n]; /* use first form of e(n) for n = N / 2 - 1 - 2i */ + } + n = 2 * i; + if (i < a4) { + tempi = data [a2 + n] - data [a2 - 1 - n]; /* use first form of e(n) for n=2i */ + } else { + tempi = data [a2 + n] + data [256 + a2 - 1 - n]; /* use second form of e(n) for n=2i*/ + } + + /* calculate pre-twiddled FFT input */ +#ifdef INTEL_SPL + FFT_data[i].re = tempr * c + tempi * s; + FFT_data[i].im = tempi * c - tempr * s; +#else + FFTarray [i].re = tempr * c + tempi * s; + FFTarray [i].im = tempi * c - tempr * s; +#endif + + /* use recurrence to prepare cosine and sine for next value of i */ + cold = c; + c = c * cfreq - s * sfreq; + s = s * cfreq + cold * sfreq; + } + + /* Perform in-place complex FFT of length N/4 */ +#ifdef INTEL_SPL + nspcFft(FFT_data, 6, NSP_Forw); +#else + pfftw_64(FFTarray); +#endif + + /* prepare for recurrence relations in post-twiddle */ + c = cosfreq8; + s = sinfreq8; + + /* post-twiddle FFT output and then get output data */ + for (i = 0; i < N4; i++) { + + /* get post-twiddled FFT output */ + /* Note: fac allocates 4/N factor from IFFT to forward and inverse */ +#ifdef INTEL_SPL + tempr = fac * (FFT_data[i].re * c + FFT_data[i].im * s); + tempi = fac * (FFT_data[i].im * c - FFT_data[i].re * s); +#else + unscambled = hDecoder->unscambled64[i]; + + tempr = fac * (FFTarray [unscambled].re * c + FFTarray [unscambled].im * s); + tempi = fac * (FFTarray [unscambled].im * c - FFTarray [unscambled].re * s); +#endif + + /* fill in output values */ + data [2 * i] = -tempr; /* first half even */ + data [N2 - 1 - 2 * i] = tempi; /* first half odd */ + data [N2 + 2 * i] = -tempi; /* second half even */ + data [256 - 1 - 2 * i] = tempr; /* second half odd */ + + /* use recurrence to prepare cosine and sine for next value of i */ + cold = c; + c = c * cfreq - s * sfreq; + s = s * cfreq + cold * sfreq; + } +} + + +void IMDCT_Long(faacDecHandle hDecoder, fftw_real *data) +{ +#ifdef INTEL_SPL + SCplx FFT_data[512]; /* the array for in-place FFT */ +#else + fftw_complex FFTarray[512]; /* the array for in-place FFT */ +#endif + fftw_real tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */ + +/* fftw_real freq = 0.0030679616611450911f; */ + fftw_real fac, cosfreq8, sinfreq8; + int i; + int Nd2 = 2048 >> 1; + int Nd4 = 2048 >> 2; + int Nd8 = 2048 >> 3; + int unscambled; + + /* Choosing to allocate 2/N factor to Inverse Xform! */ + fac = 0.0009765625f; + + /* prepare for recurrence relation in pre-twiddle */ + cfreq = 0.99999529123306274f; + sfreq = 0.0030679567717015743f; + cosfreq8 = 0.99999994039535522f; + sinfreq8 = 0.00038349519824312089f; + + c = cosfreq8; + s = sinfreq8; + + + for (i = 0; i < Nd4; i++) { + + /* calculate real and imaginary parts of g(n) or G(p) */ + tempr = -data [2 * i]; + tempi = data [Nd2 - 1 - 2 * i]; + + /* calculate pre-twiddled FFT input */ +#ifdef INTEL_SPL + FFT_data[i].re = tempr * c - tempi * s; + FFT_data[i].im = tempi * c + tempr * s; +#else + unscambled = hDecoder->unscambled512[i]; + + FFTarray [unscambled].re = tempr * c - tempi * s; + FFTarray [unscambled].im = tempi * c + tempr * s; +#endif + + /* use recurrence to prepare cosine and sine for next value of i */ + cold = c; + c = c * cfreq - s * sfreq; + s = s * cfreq + cold * sfreq; + } + + /* Perform in-place complex IFFT of length N/4 */ +#ifdef INTEL_SPL + nspcFft(FFT_data, 9, NSP_Inv | NSP_NoScale); +#else + pfftwi_512(FFTarray); +#endif + + /* prepare for recurrence relations in post-twiddle */ + c = cosfreq8; + s = sinfreq8; + + /* post-twiddle FFT output and then get output data */ + for (i = 0; i < Nd4; i++) { + + /* get post-twiddled FFT output */ +#ifdef INTEL_SPL + tempr = fac * (FFT_data[i].re * c - FFT_data[i].im * s); + tempi = fac * (FFT_data[i].im * c + FFT_data[i].re * s); +#else + tempr = fac * (FFTarray[i].re * c - FFTarray[i].im * s); + tempi = fac * (FFTarray[i].im * c + FFTarray[i].re * s); +#endif + + /* fill in output values */ + data [Nd2 + Nd4 - 1 - 2 * i] = tempr; + if (i < Nd8) { + data [Nd2 + Nd4 + 2 * i] = tempr; + } else { + data [2 * i - Nd4] = -tempr; + } + data [Nd4 + 2 * i] = tempi; + if (i < Nd8) { + data [Nd4 - 1 - 2 * i] = -tempi; + } else { + data [Nd4 + 2048 - 1 - 2*i] = tempi; + } + + /* use recurrence to prepare cosine and sine for next value of i */ + cold = c; + c = c * cfreq - s * sfreq; + s = s * cfreq + cold * sfreq; + } +} + + +void IMDCT_Short(faacDecHandle hDecoder, fftw_real *data) +{ +#ifdef INTEL_SPL + SCplx FFT_data[64]; /* the array for in-place FFT */ +#else + fftw_complex FFTarray[64]; /* the array for in-place FFT */ +#endif + fftw_real tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */ +/* fftw_real freq = 0.024543693289160728f; */ + fftw_real fac, cosfreq8, sinfreq8; + int i; + int Nd2 = 256 >> 1; + int Nd4 = 256 >> 2; + int Nd8 = 256 >> 3; + int unscambled; + + /* Choosing to allocate 2/N factor to Inverse Xform! */ + fac = 0.0078125f; /* remaining 2/N from 4/N IFFT factor */ + + /* prepare for recurrence relation in pre-twiddle */ + cfreq = 0.99969881772994995f; + sfreq = 0.024541229009628296f; + cosfreq8 = 0.99999529123306274f; + sinfreq8 = 0.0030679568483393833f; + + c = cosfreq8; + s = sinfreq8; + + for (i = 0; i < Nd4; i++) + { + + /* calculate real and imaginary parts of g(n) or G(p) */ + tempr = -data [2 * i]; + tempi = data [Nd2 - 1 - 2 * i]; + + /* calculate pre-twiddled FFT input */ +#ifdef INTEL_SPL + FFT_data[i].re = tempr * c - tempi * s; + FFT_data[i].im = tempi * c + tempr * s; +#else + unscambled = hDecoder->unscambled64[i]; + + FFTarray [unscambled].re = tempr * c - tempi * s; + FFTarray [unscambled].im = tempi * c + tempr * s; +#endif + + /* use recurrence to prepare cosine and sine for next value of i */ + cold = c; + c = c * cfreq - s * sfreq; + s = s * cfreq + cold * sfreq; + } + + /* Perform in-place complex IFFT of length N/4 */ + +#ifdef INTEL_SPL + nspcFft(FFT_data, 6, NSP_Inv | NSP_NoScale); +#else + pfftwi_64(FFTarray); +#endif + + /* prepare for recurrence relations in post-twiddle */ + c = cosfreq8; + s = sinfreq8; + + /* post-twiddle FFT output and then get output data */ + for (i = 0; i < Nd4; i++) { + + /* get post-twiddled FFT output */ +#ifdef INTEL_SPL + tempr = fac * (FFT_data[i].re * c - FFT_data[i].im * s); + tempi = fac * (FFT_data[i].im * c + FFT_data[i].re * s); +#else + tempr = fac * (FFTarray[i].re * c - FFTarray[i].im * s); + tempi = fac * (FFTarray[i].im * c + FFTarray[i].re * s); +#endif + + /* fill in output values */ + data [Nd2 + Nd4 - 1 - 2 * i] = tempr; + if (i < Nd8) { + data [Nd2 + Nd4 + 2 * i] = tempr; + } else { + data [2 * i - Nd4] = -tempr; + } + data [Nd4 + 2 * i] = tempi; + if (i < Nd8) { + data [Nd4 - 1 - 2 * i] = -tempi; + } else { + data [Nd4 + 256 - 1 - 2*i] = tempi; + } + + /* use recurrence to prepare cosine and sine for next value of i */ + cold = c; + c = c * cfreq - s * sfreq; + s = s * cfreq + cold * sfreq; + } +} + + diff --git a/transfo.h b/transfo.h new file mode 100644 index 0000000..fb27f12 --- /dev/null +++ b/transfo.h @@ -0,0 +1,58 @@ +/* + * FAAD - Freeware Advanced Audio Decoder + * Copyright (C) 2001 Menno Bakker + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: transfo.h,v 1.4 2002/01/11 00:55:17 wmaycisco Exp $ + */ + +#ifndef TRANSFORM_H +#define TRANSFORM_H + +/* Use this for decoder - single precision */ +typedef float fftw_real; + +/* Use this for encoder - double precision */ +/* typedef double fftw_real; */ + +typedef struct { + fftw_real re, im; +} fftw_complex; + +#include "all.h" + +#define c_re(c) ((c).re) +#define c_im(c) ((c).im) + +#define DEFINE_PFFTW(size) \ + void pfftwi_##size(fftw_complex *input); \ + void pfftw_##size(fftw_complex *input); \ + int pfftw_permutation_##size(int i); + +DEFINE_PFFTW(16) +DEFINE_PFFTW(32) +DEFINE_PFFTW(64) +DEFINE_PFFTW(128) +DEFINE_PFFTW(512) + +void MakeFFTOrder(faacDecHandle hDecoder); +void IMDCT_Long(faacDecHandle hDecoder, fftw_real *data); +void IMDCT_Short(faacDecHandle hDecoder, fftw_real *data); + +void MDCT_Long(faacDecHandle hDecoder, fftw_real *data); +void MDCT_Short(faacDecHandle hDecoder, fftw_real *data); + +#endif /* TRANSFORM_H */ diff --git a/util.c b/util.c new file mode 100644 index 0000000..40c07a3 --- /dev/null +++ b/util.c @@ -0,0 +1,89 @@ +/* + * FAAD - Freeware Advanced Audio Decoder + * Copyright (C) 2001 Menno Bakker + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: util.c,v 1.1 2001/06/28 23:54:22 wmaycisco Exp $ + */ + +#include "all.h" + +/* + * object_type dependent parameters + */ +int tns_max_bands(faacDecHandle hDecoder, int islong) +{ + int i; + + /* construct second index */ + i = islong ? 0 : 1; + + return tns_max_bands_tbl[hDecoder->mc_info.sampling_rate_idx][i]; +} + +int tns_max_order(faacDecHandle hDecoder, int islong) +{ + if (hDecoder->isMpeg4) { + switch (hDecoder->mc_info.object_type) { + case AACMAIN: + case AACLC: + case AACLTP: + if (islong) { + if (hDecoder->mc_info.sampling_rate_idx <= 5) /* sr > 32000Hz */ + return 12; + else + return 20; + } else + return 7; + case AACSSR: + return 12; + } + } else { + if (islong) { + switch (hDecoder->mc_info.object_type) { + case AACMAIN: + return 20; + case AACLC: + case AACSSR: + return 12; + } + } else { /* MPEG2 short window */ + return 7; + } + } + + return 0; +} + +int pred_max_bands(faacDecHandle hDecoder) +{ + return pred_max_bands_tbl[hDecoder->mc_info.sampling_rate_idx]; +} + +int stringcmp(char const *str1, char const *str2, unsigned long len) +{ + signed int c1 = 0, c2 = 0; + + while (len--) { + c1 = *str1++; + c2 = *str2++; + + if (c1 == 0 || c1 != c2) + break; + } + + return c1 - c2; +} diff --git a/util.h b/util.h new file mode 100644 index 0000000..7d060ff --- /dev/null +++ b/util.h @@ -0,0 +1,43 @@ +/* + * FAAD - Freeware Advanced Audio Decoder + * Copyright (C) 2001 Menno Bakker + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: util.h,v 1.3 2003/01/23 22:33:51 wmaycisco Exp $ + */ + +#ifndef _UTIL_H_ +#define _UTIL_H_ + +int tns_max_bands(faacDecHandle hDecoder, int islong); +int tns_max_order(faacDecHandle hDecoder, int islong); +int pred_max_bands(faacDecHandle hDecoder); +int stringcmp(char const *str1, char const *str2, unsigned long len); + +/* Memory functions */ +#ifdef _WIN32 +#define AllocMemory(size) LocalAlloc(LPTR, size) +#define FreeMemory(block) LocalFree(block) +//#define SetMemory(block, value, size) FillMemory(block, size, value) +#define SetMemory(block, value, size) memset(block, value, size) +#else +#define AllocMemory(size) malloc(size) +#define FreeMemory(block) free(block) +#define SetMemory(block, value, size) memset(block, value, size) +#define CopyMemory(dest, source, len) memcpy(dest, source, len) +#endif + +#endif -- cgit v1.2.3