Initial community commit
This commit is contained in:
@@ -0,0 +1,481 @@
|
||||
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.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
@@ -0,0 +1,7 @@
|
||||
lame library version 3.100.
|
||||
The following changes have been made:
|
||||
* Obviously, unnecessary folders and files have been removed.
|
||||
* Forced library name in lame.def has been removed.
|
||||
* All modifications have been marked with /* OpenMPT */.
|
||||
* For building, premake is used to generate Visual Studio project files.
|
||||
See ../build/premake/ for details.
|
||||
@@ -0,0 +1,120 @@
|
||||
#ifndef CONFIGMS_H_INCLUDED
|
||||
#define CONFIGMS_H_INCLUDED
|
||||
|
||||
/* The number of bytes in a double. */
|
||||
#define SIZEOF_DOUBLE 8
|
||||
|
||||
/* The number of bytes in a float. */
|
||||
#define SIZEOF_FLOAT 4
|
||||
|
||||
/* The number of bytes in a int. */
|
||||
#define SIZEOF_INT 4
|
||||
|
||||
/* The number of bytes in a long. */
|
||||
#define SIZEOF_LONG 4
|
||||
|
||||
/* The number of bytes in a long double. */
|
||||
#define SIZEOF_LONG_DOUBLE 12
|
||||
|
||||
/* The number of bytes in a short. */
|
||||
#define SIZEOF_SHORT 2
|
||||
|
||||
/* The number of bytes in a unsigned int. */
|
||||
#define SIZEOF_UNSIGNED_INT 4
|
||||
|
||||
/* The number of bytes in a unsigned long. */
|
||||
#define SIZEOF_UNSIGNED_LONG 4
|
||||
|
||||
/* The number of bytes in a unsigned short. */
|
||||
#define SIZEOF_UNSIGNED_SHORT 2
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS
|
||||
|
||||
/* Define if you have the <errno.h> header file. */
|
||||
#define HAVE_ERRNO_H
|
||||
|
||||
/* Define if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H
|
||||
|
||||
/* Define if you have the <limits.h> header file. */
|
||||
#define HAVE_LIMITS_H
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "lame"
|
||||
|
||||
/* Define if compiler has function prototypes */
|
||||
#define PROTOTYPES 1
|
||||
|
||||
/* faster log implementation with less but enough precission */
|
||||
#define USE_FAST_LOG 1
|
||||
|
||||
#define HAVE_STRCHR
|
||||
#define HAVE_MEMCPY
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
#pragma warning( disable : 4305 )
|
||||
typedef __int8 int8_t;
|
||||
typedef __int16 int16_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef __int64 int64_t;
|
||||
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
typedef float float32_t;
|
||||
typedef double float64_t;
|
||||
#elif defined (__GNUC__)
|
||||
#define __int8_t_defined
|
||||
#define uint8_t unsigned char
|
||||
#define uint16_t unsigned short
|
||||
#define uint32_t unsigned int
|
||||
#define uint64_t unsigned long long
|
||||
|
||||
#define int8_t signed char
|
||||
#define int16_t signed short
|
||||
#define int32_t signed int
|
||||
#define int64_t signed long long
|
||||
#endif
|
||||
|
||||
typedef long double ieee854_float80_t;
|
||||
typedef double ieee754_float64_t;
|
||||
typedef float ieee754_float32_t;
|
||||
|
||||
#ifdef HAVE_MPGLIB
|
||||
# define DECODE_ON_THE_FLY 1
|
||||
#endif
|
||||
|
||||
#ifdef LAME_ACM
|
||||
/* memory hacking for driver purposes */
|
||||
#define calloc(x,y) acm_Calloc(x,y)
|
||||
#define free(x) acm_Free(x)
|
||||
#define malloc(x) acm_Malloc(x)
|
||||
|
||||
#include <stddef.h>
|
||||
void *acm_Calloc( size_t num, size_t size );
|
||||
void *acm_Malloc( size_t size );
|
||||
void acm_Free( void * mem);
|
||||
#endif /* LAME_ACM */
|
||||
|
||||
#define LAME_LIBRARY_BUILD
|
||||
|
||||
|
||||
#ifdef HAVE_NASM
|
||||
#if (defined(__ICL) && (__ICL >= 450))
|
||||
#define HAVE_XMMINTRIN_H
|
||||
#elif defined(_MSC_VER)
|
||||
#include <malloc.h>
|
||||
#ifdef _mm_malloc
|
||||
#define HAVE_XMMINTRIN_H
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_M_X64) && !defined(HAVE_XMMINTRIN_H)
|
||||
#define HAVE_XMMINTRIN_H
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,304 @@
|
||||
;OpenMPT
|
||||
;LIBRARY libmp3lame.DLL
|
||||
LIBRARY
|
||||
EXPORTS
|
||||
|
||||
lame_init @1
|
||||
|
||||
lame_set_num_samples @2
|
||||
lame_get_num_samples @3
|
||||
|
||||
lame_set_in_samplerate @4
|
||||
lame_get_in_samplerate @5
|
||||
|
||||
lame_set_num_channels @6
|
||||
lame_get_num_channels @7
|
||||
|
||||
lame_set_scale @8
|
||||
lame_get_scale @9
|
||||
|
||||
lame_set_scale_left @10
|
||||
lame_get_scale_left @11
|
||||
|
||||
lame_set_scale_right @12
|
||||
lame_get_scale_right @13
|
||||
|
||||
lame_set_out_samplerate @14
|
||||
lame_get_out_samplerate @15
|
||||
|
||||
lame_set_analysis @16
|
||||
lame_get_analysis @17
|
||||
|
||||
lame_set_bWriteVbrTag @18
|
||||
lame_get_bWriteVbrTag @19
|
||||
|
||||
lame_set_decode_only @20
|
||||
lame_get_decode_only @21
|
||||
|
||||
lame_set_quality @22
|
||||
lame_get_quality @23
|
||||
|
||||
lame_set_mode @24
|
||||
lame_get_mode @25
|
||||
|
||||
lame_set_force_ms @26
|
||||
lame_get_force_ms @27
|
||||
|
||||
lame_set_free_format @28
|
||||
lame_get_free_format @29
|
||||
|
||||
|
||||
lame_set_findReplayGain @30
|
||||
lame_get_findReplayGain @31
|
||||
|
||||
lame_set_decode_on_the_fly @32
|
||||
lame_get_decode_on_the_fly @33
|
||||
|
||||
lame_set_nogap_total @34
|
||||
lame_get_nogap_total @35
|
||||
|
||||
lame_set_nogap_currentindex @36
|
||||
lame_get_nogap_currentindex @37
|
||||
|
||||
|
||||
lame_set_errorf @38
|
||||
lame_set_debugf @39
|
||||
lame_set_msgf @40
|
||||
|
||||
lame_set_brate @41
|
||||
lame_get_brate @42
|
||||
|
||||
lame_set_compression_ratio @43
|
||||
lame_get_compression_ratio @44
|
||||
|
||||
lame_set_preset @45
|
||||
|
||||
lame_set_asm_optimizations @46
|
||||
|
||||
|
||||
lame_set_copyright @47
|
||||
lame_get_copyright @48
|
||||
|
||||
lame_set_original @49
|
||||
lame_get_original @50
|
||||
|
||||
lame_set_error_protection @51
|
||||
lame_get_error_protection @52
|
||||
|
||||
lame_set_padding_type @53
|
||||
lame_get_padding_type @54
|
||||
|
||||
lame_set_extension @55
|
||||
lame_get_extension @56
|
||||
|
||||
lame_set_strict_ISO @57
|
||||
lame_get_strict_ISO @58
|
||||
|
||||
lame_set_disable_reservoir @59
|
||||
lame_get_disable_reservoir @60
|
||||
|
||||
lame_set_quant_comp @61
|
||||
lame_get_quant_comp @62
|
||||
lame_set_quant_comp_short @63
|
||||
lame_get_quant_comp_short @64
|
||||
|
||||
lame_set_experimentalX @65
|
||||
lame_get_experimentalX @66
|
||||
|
||||
lame_set_experimentalY @67
|
||||
lame_get_experimentalY @68
|
||||
|
||||
lame_set_experimentalZ @69
|
||||
lame_get_experimentalZ @70
|
||||
|
||||
lame_set_exp_nspsytune @71
|
||||
lame_get_exp_nspsytune @72
|
||||
|
||||
lame_set_msfix @73
|
||||
lame_get_msfix @74
|
||||
|
||||
lame_set_VBR @75
|
||||
lame_get_VBR @76
|
||||
|
||||
lame_set_VBR_q @77
|
||||
lame_get_VBR_q @78
|
||||
|
||||
lame_set_VBR_mean_bitrate_kbps @79
|
||||
lame_get_VBR_mean_bitrate_kbps @80
|
||||
|
||||
lame_set_VBR_min_bitrate_kbps @81
|
||||
lame_get_VBR_min_bitrate_kbps @82
|
||||
|
||||
lame_set_VBR_max_bitrate_kbps @83
|
||||
lame_get_VBR_max_bitrate_kbps @84
|
||||
|
||||
lame_set_VBR_hard_min @85
|
||||
lame_get_VBR_hard_min @86
|
||||
|
||||
lame_set_preset_expopts @87
|
||||
|
||||
lame_set_lowpassfreq @88
|
||||
lame_get_lowpassfreq @89
|
||||
|
||||
lame_set_lowpasswidth @90
|
||||
lame_get_lowpasswidth @91
|
||||
|
||||
lame_set_highpassfreq @92
|
||||
lame_get_highpassfreq @93
|
||||
|
||||
lame_set_highpasswidth @94
|
||||
lame_get_highpasswidth @95
|
||||
|
||||
lame_set_ATHonly @96
|
||||
lame_get_ATHonly @97
|
||||
|
||||
lame_set_ATHshort @98
|
||||
lame_get_ATHshort @99
|
||||
|
||||
lame_set_noATH @100
|
||||
lame_get_noATH @101
|
||||
|
||||
lame_set_ATHtype @102
|
||||
lame_get_ATHtype @103
|
||||
|
||||
lame_set_ATHlower @104
|
||||
lame_get_ATHlower @105
|
||||
|
||||
lame_set_athaa_type @106
|
||||
lame_get_athaa_type @107
|
||||
|
||||
lame_set_athaa_loudapprox @108
|
||||
lame_get_athaa_loudapprox @109
|
||||
|
||||
lame_set_athaa_sensitivity @110
|
||||
lame_get_athaa_sensitivity @111
|
||||
|
||||
lame_set_cwlimit @112
|
||||
lame_get_cwlimit @113
|
||||
|
||||
lame_set_useTemporal @114
|
||||
lame_get_useTemporal @115
|
||||
|
||||
lame_set_interChRatio @116
|
||||
lame_get_interChRatio @117
|
||||
|
||||
lame_set_no_short_blocks @118
|
||||
lame_get_no_short_blocks @119
|
||||
lame_set_force_short_blocks @120
|
||||
lame_get_force_short_blocks @121
|
||||
lame_set_allow_diff_short @122
|
||||
lame_get_allow_diff_short @123
|
||||
|
||||
lame_set_emphasis @124
|
||||
lame_get_emphasis @125
|
||||
|
||||
lame_get_version @126
|
||||
lame_get_encoder_delay @127
|
||||
lame_get_encoder_padding @128
|
||||
lame_get_framesize @129
|
||||
|
||||
lame_get_mf_samples_to_encode @130
|
||||
lame_get_size_mp3buffer @131
|
||||
lame_get_frameNum @132
|
||||
lame_get_totalframes @133
|
||||
|
||||
lame_get_RadioGain @134
|
||||
lame_get_AudiophileGain @135
|
||||
lame_get_PeakSample @136
|
||||
lame_get_noclipGainChange @137
|
||||
lame_get_noclipScale @138
|
||||
|
||||
lame_init_params @139
|
||||
|
||||
get_lame_version @140
|
||||
get_lame_short_version @141
|
||||
get_lame_very_short_version @142
|
||||
get_psy_version @143
|
||||
get_lame_url @144
|
||||
|
||||
get_lame_version_numerical @145
|
||||
|
||||
lame_print_config @146
|
||||
lame_print_internals @147
|
||||
|
||||
lame_encode_buffer @148
|
||||
lame_encode_buffer_interleaved @149
|
||||
lame_encode_buffer_float @150
|
||||
lame_encode_buffer_long @151
|
||||
lame_encode_buffer_long2 @152
|
||||
lame_encode_buffer_int @153
|
||||
lame_encode_flush @154
|
||||
lame_encode_flush_nogap @155
|
||||
|
||||
lame_init_bitstream @156
|
||||
|
||||
lame_bitrate_hist @157
|
||||
lame_bitrate_kbps @158
|
||||
lame_stereo_mode_hist @159
|
||||
lame_bitrate_stereo_mode_hist @160
|
||||
lame_block_type_hist @161
|
||||
lame_bitrate_block_type_hist @162
|
||||
lame_mp3_tags_fid @163
|
||||
lame_close @164
|
||||
lame_get_lametag_frame @165
|
||||
get_lame_os_bitness @166
|
||||
lame_set_VBR_quality @167
|
||||
lame_get_VBR_quality @168
|
||||
|
||||
lame_encode_buffer_ieee_float @169
|
||||
lame_encode_buffer_interleaved_ieee_float @170
|
||||
lame_encode_buffer_ieee_double @171
|
||||
lame_encode_buffer_interleaved_ieee_double @172
|
||||
lame_encode_buffer_interleaved_int @173
|
||||
|
||||
lame_get_bitrate @502
|
||||
lame_get_samplerate @503
|
||||
lame_get_maximum_number_of_samples @504
|
||||
|
||||
lame_decode_init @1000
|
||||
lame_decode @1001
|
||||
lame_decode_headers @1002
|
||||
lame_decode1 @1003
|
||||
lame_decode1_headers @1004
|
||||
lame_decode1_headersB @1005
|
||||
lame_decode_exit @1006
|
||||
|
||||
hip_decode_init @1100
|
||||
hip_decode_exit @1101
|
||||
hip_decode @1102
|
||||
hip_decode_headers @1103
|
||||
hip_decode1 @1104
|
||||
hip_decode1_headers @1105
|
||||
hip_decode1_headersB @1106
|
||||
hip_set_debugf @1107
|
||||
hip_set_errorf @1108
|
||||
hip_set_msgf @1109
|
||||
|
||||
id3tag_genre_list @2000
|
||||
id3tag_init @2001
|
||||
id3tag_add_v2 @2002
|
||||
id3tag_v1_only @2003
|
||||
id3tag_v2_only @2004
|
||||
id3tag_space_v1 @2005
|
||||
id3tag_pad_v2 @2006
|
||||
id3tag_set_title @2007
|
||||
id3tag_set_artist @2008
|
||||
id3tag_set_album @2009
|
||||
id3tag_set_year @2010
|
||||
id3tag_set_comment @2011
|
||||
id3tag_set_track @2012
|
||||
id3tag_set_genre @2013
|
||||
id3tag_set_fieldvalue @2014
|
||||
id3tag_set_albumart @2015
|
||||
lame_get_id3v1_tag @2016
|
||||
lame_get_id3v2_tag @2017
|
||||
lame_set_write_id3tag_automatic @2018
|
||||
lame_get_write_id3tag_automatic @2019
|
||||
id3tag_set_pad @2020
|
||||
id3tag_set_comment_ucs2 @2021
|
||||
id3tag_set_textinfo_ucs2 @2022
|
||||
id3tag_set_fieldvalue_ucs2 @2023
|
||||
id3tag_set_comment_utf16 @2024
|
||||
id3tag_set_textinfo_utf16 @2025
|
||||
id3tag_set_fieldvalue_utf16 @2026
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Xing VBR tagging for LAME.
|
||||
*
|
||||
* Copyright (c) 1999 A.L. Faber
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_VRBTAG_H
|
||||
#define LAME_VRBTAG_H
|
||||
|
||||
|
||||
/* -----------------------------------------------------------
|
||||
* A Vbr header may be present in the ancillary
|
||||
* data field of the first frame of an mp3 bitstream
|
||||
* The Vbr header (optionally) contains
|
||||
* frames total number of audio frames in the bitstream
|
||||
* bytes total number of bytes in the bitstream
|
||||
* toc table of contents
|
||||
|
||||
* toc (table of contents) gives seek points
|
||||
* for random access
|
||||
* the ith entry determines the seek point for
|
||||
* i-percent duration
|
||||
* seek point in bytes = (toc[i]/256.0) * total_bitstream_bytes
|
||||
* e.g. half duration seek point = (toc[50]/256.0) * total_bitstream_bytes
|
||||
*/
|
||||
|
||||
|
||||
#define FRAMES_FLAG 0x0001
|
||||
#define BYTES_FLAG 0x0002
|
||||
#define TOC_FLAG 0x0004
|
||||
#define VBR_SCALE_FLAG 0x0008
|
||||
|
||||
#define NUMTOCENTRIES 100
|
||||
|
||||
#ifndef lame_internal_flags_defined
|
||||
#define lame_internal_flags_defined
|
||||
struct lame_internal_flags;
|
||||
typedef struct lame_internal_flags lame_internal_flags;
|
||||
#endif
|
||||
|
||||
|
||||
/*structure to receive extracted header */
|
||||
/* toc may be NULL*/
|
||||
typedef struct {
|
||||
int h_id; /* from MPEG header, 0=MPEG2, 1=MPEG1 */
|
||||
int samprate; /* determined from MPEG header */
|
||||
int flags; /* from Vbr header data */
|
||||
int frames; /* total bit stream frames from Vbr header data */
|
||||
int bytes; /* total bit stream bytes from Vbr header data */
|
||||
int vbr_scale; /* encoded vbr scale from Vbr header data */
|
||||
unsigned char toc[NUMTOCENTRIES]; /* may be NULL if toc not desired */
|
||||
int headersize; /* size of VBR header, in bytes */
|
||||
int enc_delay; /* encoder delay */
|
||||
int enc_padding; /* encoder paddign added at end of stream */
|
||||
} VBRTAGDATA;
|
||||
|
||||
int GetVbrTag(VBRTAGDATA * pTagData, const unsigned char *buf);
|
||||
|
||||
int InitVbrTag(lame_global_flags * gfp);
|
||||
int PutVbrTag(lame_global_flags const *gfp, FILE * fid);
|
||||
void AddVbrFrame(lame_internal_flags * gfc);
|
||||
void UpdateMusicCRC(uint16_t * crc, const unsigned char *buffer, int size);
|
||||
|
||||
#endif
|
||||
+1111
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* MP3 bitstream Output interface for LAME
|
||||
*
|
||||
* Copyright (c) 1999 Takehiro TOMINAGA
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_BITSTREAM_H
|
||||
#define LAME_BITSTREAM_H
|
||||
|
||||
int getframebits(const lame_internal_flags * gfc);
|
||||
|
||||
int format_bitstream(lame_internal_flags * gfc);
|
||||
|
||||
void flush_bitstream(lame_internal_flags * gfc);
|
||||
void add_dummy_byte(lame_internal_flags * gfc, unsigned char val, unsigned int n);
|
||||
|
||||
int copy_buffer(lame_internal_flags * gfc, unsigned char *buffer, int buffer_size,
|
||||
int update_crc);
|
||||
void init_bit_stream_w(lame_internal_flags * gfc);
|
||||
void CRC_writeheader(lame_internal_flags const *gfc, char *buffer);
|
||||
int compute_flushbits(const lame_internal_flags * gfp, int *nbytes);
|
||||
|
||||
int get_max_frame_buffer_size_by_constraint(SessionConfig_t const * cfg, int constraint);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,574 @@
|
||||
/*
|
||||
* LAME MP3 encoding engine
|
||||
*
|
||||
* Copyright (c) 1999 Mark Taylor
|
||||
* Copyright (c) 2000-2002 Takehiro Tominaga
|
||||
* Copyright (c) 2000-2011 Robert Hegemann
|
||||
* Copyright (c) 2001 Gabriel Bouvigne
|
||||
* Copyright (c) 2001 John Dahlstrom
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* $Id: encoder.c,v 1.114 2017/08/26 10:54:57 robert Exp $ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "lame.h"
|
||||
#include "machine.h"
|
||||
#include "encoder.h"
|
||||
#include "util.h"
|
||||
#include "lame_global_flags.h"
|
||||
#include "newmdct.h"
|
||||
#include "psymodel.h"
|
||||
#include "lame-analysis.h"
|
||||
#include "bitstream.h"
|
||||
#include "VbrTag.h"
|
||||
#include "quantize.h"
|
||||
#include "quantize_pvt.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* auto-adjust of ATH, useful for low volume
|
||||
* Gabriel Bouvigne 3 feb 2001
|
||||
*
|
||||
* modifies some values in
|
||||
* gfp->internal_flags->ATH
|
||||
* (gfc->ATH)
|
||||
*/
|
||||
static void
|
||||
adjust_ATH(lame_internal_flags const *const gfc)
|
||||
{
|
||||
SessionConfig_t const *const cfg = &gfc->cfg;
|
||||
FLOAT gr2_max, max_pow;
|
||||
|
||||
if (gfc->ATH->use_adjust == 0) {
|
||||
gfc->ATH->adjust_factor = 1.0; /* no adjustment */
|
||||
return;
|
||||
}
|
||||
|
||||
/* jd - 2001 mar 12, 27, jun 30 */
|
||||
/* loudness based on equal loudness curve; */
|
||||
/* use granule with maximum combined loudness */
|
||||
max_pow = gfc->ov_psy.loudness_sq[0][0];
|
||||
gr2_max = gfc->ov_psy.loudness_sq[1][0];
|
||||
if (cfg->channels_out == 2) {
|
||||
max_pow += gfc->ov_psy.loudness_sq[0][1];
|
||||
gr2_max += gfc->ov_psy.loudness_sq[1][1];
|
||||
}
|
||||
else {
|
||||
max_pow += max_pow;
|
||||
gr2_max += gr2_max;
|
||||
}
|
||||
if (cfg->mode_gr == 2) {
|
||||
max_pow = Max(max_pow, gr2_max);
|
||||
}
|
||||
max_pow *= 0.5; /* max_pow approaches 1.0 for full band noise */
|
||||
|
||||
/* jd - 2001 mar 31, jun 30 */
|
||||
/* user tuning of ATH adjustment region */
|
||||
max_pow *= gfc->ATH->aa_sensitivity_p;
|
||||
|
||||
/* adjust ATH depending on range of maximum value
|
||||
*/
|
||||
|
||||
/* jd - 2001 feb27, mar12,20, jun30, jul22 */
|
||||
/* continuous curves based on approximation */
|
||||
/* to GB's original values. */
|
||||
/* For an increase in approximate loudness, */
|
||||
/* set ATH adjust to adjust_limit immediately */
|
||||
/* after a delay of one frame. */
|
||||
/* For a loudness decrease, reduce ATH adjust */
|
||||
/* towards adjust_limit gradually. */
|
||||
/* max_pow is a loudness squared or a power. */
|
||||
if (max_pow > 0.03125) { /* ((1 - 0.000625)/ 31.98) from curve below */
|
||||
if (gfc->ATH->adjust_factor >= 1.0) {
|
||||
gfc->ATH->adjust_factor = 1.0;
|
||||
}
|
||||
else {
|
||||
/* preceding frame has lower ATH adjust; */
|
||||
/* ascend only to the preceding adjust_limit */
|
||||
/* in case there is leading low volume */
|
||||
if (gfc->ATH->adjust_factor < gfc->ATH->adjust_limit) {
|
||||
gfc->ATH->adjust_factor = gfc->ATH->adjust_limit;
|
||||
}
|
||||
}
|
||||
gfc->ATH->adjust_limit = 1.0;
|
||||
}
|
||||
else { /* adjustment curve */
|
||||
/* about 32 dB maximum adjust (0.000625) */
|
||||
FLOAT const adj_lim_new = 31.98 * max_pow + 0.000625;
|
||||
if (gfc->ATH->adjust_factor >= adj_lim_new) { /* descend gradually */
|
||||
gfc->ATH->adjust_factor *= adj_lim_new * 0.075 + 0.925;
|
||||
if (gfc->ATH->adjust_factor < adj_lim_new) { /* stop descent */
|
||||
gfc->ATH->adjust_factor = adj_lim_new;
|
||||
}
|
||||
}
|
||||
else { /* ascend */
|
||||
if (gfc->ATH->adjust_limit >= adj_lim_new) {
|
||||
gfc->ATH->adjust_factor = adj_lim_new;
|
||||
}
|
||||
else { /* preceding frame has lower ATH adjust; */
|
||||
/* ascend only to the preceding adjust_limit */
|
||||
if (gfc->ATH->adjust_factor < gfc->ATH->adjust_limit) {
|
||||
gfc->ATH->adjust_factor = gfc->ATH->adjust_limit;
|
||||
}
|
||||
}
|
||||
}
|
||||
gfc->ATH->adjust_limit = adj_lim_new;
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* some simple statistics
|
||||
*
|
||||
* bitrate index 0: free bitrate -> not allowed in VBR mode
|
||||
* : bitrates, kbps depending on MPEG version
|
||||
* bitrate index 15: forbidden
|
||||
*
|
||||
* mode_ext:
|
||||
* 0: LR
|
||||
* 1: LR-i
|
||||
* 2: MS
|
||||
* 3: MS-i
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
static void
|
||||
updateStats(lame_internal_flags * const gfc)
|
||||
{
|
||||
SessionConfig_t const *const cfg = &gfc->cfg;
|
||||
EncResult_t *eov = &gfc->ov_enc;
|
||||
int gr, ch;
|
||||
assert(0 <= eov->bitrate_index && eov->bitrate_index < 16);
|
||||
assert(0 <= eov->mode_ext && eov->mode_ext < 4);
|
||||
|
||||
/* count bitrate indices */
|
||||
eov->bitrate_channelmode_hist[eov->bitrate_index][4]++;
|
||||
eov->bitrate_channelmode_hist[15][4]++;
|
||||
|
||||
/* count 'em for every mode extension in case of 2 channel encoding */
|
||||
if (cfg->channels_out == 2) {
|
||||
eov->bitrate_channelmode_hist[eov->bitrate_index][eov->mode_ext]++;
|
||||
eov->bitrate_channelmode_hist[15][eov->mode_ext]++;
|
||||
}
|
||||
for (gr = 0; gr < cfg->mode_gr; ++gr) {
|
||||
for (ch = 0; ch < cfg->channels_out; ++ch) {
|
||||
int bt = gfc->l3_side.tt[gr][ch].block_type;
|
||||
if (gfc->l3_side.tt[gr][ch].mixed_block_flag)
|
||||
bt = 4;
|
||||
eov->bitrate_blocktype_hist[eov->bitrate_index][bt]++;
|
||||
eov->bitrate_blocktype_hist[eov->bitrate_index][5]++;
|
||||
eov->bitrate_blocktype_hist[15][bt]++;
|
||||
eov->bitrate_blocktype_hist[15][5]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
lame_encode_frame_init(lame_internal_flags * gfc, const sample_t *const inbuf[2])
|
||||
{
|
||||
SessionConfig_t const *const cfg = &gfc->cfg;
|
||||
|
||||
int ch, gr;
|
||||
|
||||
if (gfc->lame_encode_frame_init == 0) {
|
||||
sample_t primebuff0[286 + 1152 + 576];
|
||||
sample_t primebuff1[286 + 1152 + 576];
|
||||
int const framesize = 576 * cfg->mode_gr;
|
||||
/* prime the MDCT/polyphase filterbank with a short block */
|
||||
int i, j;
|
||||
gfc->lame_encode_frame_init = 1;
|
||||
memset(primebuff0, 0, sizeof(primebuff0));
|
||||
memset(primebuff1, 0, sizeof(primebuff1));
|
||||
for (i = 0, j = 0; i < 286 + 576 * (1 + cfg->mode_gr); ++i) {
|
||||
if (i < framesize) {
|
||||
primebuff0[i] = 0;
|
||||
if (cfg->channels_out == 2)
|
||||
primebuff1[i] = 0;
|
||||
}
|
||||
else {
|
||||
primebuff0[i] = inbuf[0][j];
|
||||
if (cfg->channels_out == 2)
|
||||
primebuff1[i] = inbuf[1][j];
|
||||
++j;
|
||||
}
|
||||
}
|
||||
/* polyphase filtering / mdct */
|
||||
for (gr = 0; gr < cfg->mode_gr; gr++) {
|
||||
for (ch = 0; ch < cfg->channels_out; ch++) {
|
||||
gfc->l3_side.tt[gr][ch].block_type = SHORT_TYPE;
|
||||
}
|
||||
}
|
||||
mdct_sub48(gfc, primebuff0, primebuff1);
|
||||
|
||||
/* check FFT will not use a negative starting offset */
|
||||
#if 576 < FFTOFFSET
|
||||
# error FFTOFFSET greater than 576: FFT uses a negative offset
|
||||
#endif
|
||||
/* check if we have enough data for FFT */
|
||||
assert(gfc->sv_enc.mf_size >= (BLKSIZE + framesize - FFTOFFSET));
|
||||
/* check if we have enough data for polyphase filterbank */
|
||||
assert(gfc->sv_enc.mf_size >= (512 + framesize - 32));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* encodeframe() Layer 3
|
||||
*
|
||||
* encode a single frame
|
||||
*
|
||||
************************************************************************
|
||||
lame_encode_frame()
|
||||
|
||||
|
||||
gr 0 gr 1
|
||||
inbuf: |--------------|--------------|--------------|
|
||||
|
||||
|
||||
Polyphase (18 windows, each shifted 32)
|
||||
gr 0:
|
||||
window1 <----512---->
|
||||
window18 <----512---->
|
||||
|
||||
gr 1:
|
||||
window1 <----512---->
|
||||
window18 <----512---->
|
||||
|
||||
|
||||
|
||||
MDCT output: |--------------|--------------|--------------|
|
||||
|
||||
FFT's <---------1024---------->
|
||||
<---------1024-------->
|
||||
|
||||
|
||||
|
||||
inbuf = buffer of PCM data size=MP3 framesize
|
||||
encoder acts on inbuf[ch][0], but output is delayed by MDCTDELAY
|
||||
so the MDCT coefficints are from inbuf[ch][-MDCTDELAY]
|
||||
|
||||
psy-model FFT has a 1 granule delay, so we feed it data for the
|
||||
next granule.
|
||||
FFT is centered over granule: 224+576+224
|
||||
So FFT starts at: 576-224-MDCTDELAY
|
||||
|
||||
MPEG2: FFT ends at: BLKSIZE+576-224-MDCTDELAY (1328)
|
||||
MPEG1: FFT ends at: BLKSIZE+2*576-224-MDCTDELAY (1904)
|
||||
|
||||
MPEG2: polyphase first window: [0..511]
|
||||
18th window: [544..1055] (1056)
|
||||
MPEG1: 36th window: [1120..1631] (1632)
|
||||
data needed: 512+framesize-32
|
||||
|
||||
A close look newmdct.c shows that the polyphase filterbank
|
||||
only uses data from [0..510] for each window. Perhaps because the window
|
||||
used by the filterbank is zero for the last point, so Takehiro's
|
||||
code doesn't bother to compute with it.
|
||||
|
||||
FFT starts at 576-224-MDCTDELAY (304) = 576-FFTOFFSET
|
||||
|
||||
*/
|
||||
|
||||
typedef FLOAT chgrdata[2][2];
|
||||
|
||||
|
||||
int
|
||||
lame_encode_mp3_frame( /* Output */
|
||||
lame_internal_flags * gfc, /* Context */
|
||||
sample_t const *inbuf_l, /* Input */
|
||||
sample_t const *inbuf_r, /* Input */
|
||||
unsigned char *mp3buf, /* Output */
|
||||
int mp3buf_size)
|
||||
{ /* Output */
|
||||
SessionConfig_t const *const cfg = &gfc->cfg;
|
||||
int mp3count;
|
||||
III_psy_ratio masking_LR[2][2]; /*LR masking & energy */
|
||||
III_psy_ratio masking_MS[2][2]; /*MS masking & energy */
|
||||
const III_psy_ratio (*masking)[2]; /*pointer to selected maskings */
|
||||
const sample_t *inbuf[2];
|
||||
|
||||
FLOAT tot_ener[2][4];
|
||||
FLOAT ms_ener_ratio[2] = { .5, .5 };
|
||||
FLOAT pe[2][2] = { {0., 0.}, {0., 0.} }, pe_MS[2][2] = { {
|
||||
0., 0.}, {
|
||||
0., 0.}};
|
||||
FLOAT (*pe_use)[2];
|
||||
|
||||
int ch, gr;
|
||||
|
||||
inbuf[0] = inbuf_l;
|
||||
inbuf[1] = inbuf_r;
|
||||
|
||||
if (gfc->lame_encode_frame_init == 0) {
|
||||
/*first run? */
|
||||
lame_encode_frame_init(gfc, inbuf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/********************** padding *****************************/
|
||||
/* padding method as described in
|
||||
* "MPEG-Layer3 / Bitstream Syntax and Decoding"
|
||||
* by Martin Sieler, Ralph Sperschneider
|
||||
*
|
||||
* note: there is no padding for the very first frame
|
||||
*
|
||||
* Robert Hegemann 2000-06-22
|
||||
*/
|
||||
gfc->ov_enc.padding = FALSE;
|
||||
if ((gfc->sv_enc.slot_lag -= gfc->sv_enc.frac_SpF) < 0) {
|
||||
gfc->sv_enc.slot_lag += cfg->samplerate_out;
|
||||
gfc->ov_enc.padding = TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****************************************
|
||||
* Stage 1: psychoacoustic model *
|
||||
****************************************/
|
||||
|
||||
{
|
||||
/* psychoacoustic model
|
||||
* psy model has a 1 granule (576) delay that we must compensate for
|
||||
* (mt 6/99).
|
||||
*/
|
||||
int ret;
|
||||
const sample_t *bufp[2] = {0, 0}; /* address of beginning of left & right granule */
|
||||
int blocktype[2];
|
||||
|
||||
for (gr = 0; gr < cfg->mode_gr; gr++) {
|
||||
|
||||
for (ch = 0; ch < cfg->channels_out; ch++) {
|
||||
bufp[ch] = &inbuf[ch][576 + gr * 576 - FFTOFFSET];
|
||||
}
|
||||
ret = L3psycho_anal_vbr(gfc, bufp, gr,
|
||||
masking_LR, masking_MS,
|
||||
pe[gr], pe_MS[gr], tot_ener[gr], blocktype);
|
||||
if (ret != 0)
|
||||
return -4;
|
||||
|
||||
if (cfg->mode == JOINT_STEREO) {
|
||||
ms_ener_ratio[gr] = tot_ener[gr][2] + tot_ener[gr][3];
|
||||
if (ms_ener_ratio[gr] > 0)
|
||||
ms_ener_ratio[gr] = tot_ener[gr][3] / ms_ener_ratio[gr];
|
||||
}
|
||||
|
||||
/* block type flags */
|
||||
for (ch = 0; ch < cfg->channels_out; ch++) {
|
||||
gr_info *const cod_info = &gfc->l3_side.tt[gr][ch];
|
||||
cod_info->block_type = blocktype[ch];
|
||||
cod_info->mixed_block_flag = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* auto-adjust of ATH, useful for low volume */
|
||||
adjust_ATH(gfc);
|
||||
|
||||
|
||||
/****************************************
|
||||
* Stage 2: MDCT *
|
||||
****************************************/
|
||||
|
||||
/* polyphase filtering / mdct */
|
||||
mdct_sub48(gfc, inbuf[0], inbuf[1]);
|
||||
|
||||
|
||||
/****************************************
|
||||
* Stage 3: MS/LR decision *
|
||||
****************************************/
|
||||
|
||||
/* Here will be selected MS or LR coding of the 2 stereo channels */
|
||||
gfc->ov_enc.mode_ext = MPG_MD_LR_LR;
|
||||
|
||||
if (cfg->force_ms) {
|
||||
gfc->ov_enc.mode_ext = MPG_MD_MS_LR;
|
||||
}
|
||||
else if (cfg->mode == JOINT_STEREO) {
|
||||
/* ms_ratio = is scaled, for historical reasons, to look like
|
||||
a ratio of side_channel / total.
|
||||
0 = signal is 100% mono
|
||||
.5 = L & R uncorrelated
|
||||
*/
|
||||
|
||||
/* [0] and [1] are the results for the two granules in MPEG-1,
|
||||
* in MPEG-2 it's only a faked averaging of the same value
|
||||
* _prev is the value of the last granule of the previous frame
|
||||
* _next is the value of the first granule of the next frame
|
||||
*/
|
||||
|
||||
FLOAT sum_pe_MS = 0;
|
||||
FLOAT sum_pe_LR = 0;
|
||||
for (gr = 0; gr < cfg->mode_gr; gr++) {
|
||||
for (ch = 0; ch < cfg->channels_out; ch++) {
|
||||
sum_pe_MS += pe_MS[gr][ch];
|
||||
sum_pe_LR += pe[gr][ch];
|
||||
}
|
||||
}
|
||||
|
||||
/* based on PE: M/S coding would not use much more bits than L/R */
|
||||
if (sum_pe_MS <= 1.00 * sum_pe_LR) {
|
||||
|
||||
gr_info const *const gi0 = &gfc->l3_side.tt[0][0];
|
||||
gr_info const *const gi1 = &gfc->l3_side.tt[cfg->mode_gr - 1][0];
|
||||
|
||||
if (gi0[0].block_type == gi0[1].block_type && gi1[0].block_type == gi1[1].block_type) {
|
||||
|
||||
gfc->ov_enc.mode_ext = MPG_MD_MS_LR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* bit and noise allocation */
|
||||
if (gfc->ov_enc.mode_ext == MPG_MD_MS_LR) {
|
||||
masking = (const III_psy_ratio (*)[2])masking_MS; /* use MS masking */
|
||||
pe_use = pe_MS;
|
||||
}
|
||||
else {
|
||||
masking = (const III_psy_ratio (*)[2])masking_LR; /* use LR masking */
|
||||
pe_use = pe;
|
||||
}
|
||||
|
||||
|
||||
/* copy data for MP3 frame analyzer */
|
||||
if (cfg->analysis && gfc->pinfo != NULL) {
|
||||
for (gr = 0; gr < cfg->mode_gr; gr++) {
|
||||
for (ch = 0; ch < cfg->channels_out; ch++) {
|
||||
gfc->pinfo->ms_ratio[gr] = 0;
|
||||
gfc->pinfo->ms_ener_ratio[gr] = ms_ener_ratio[gr];
|
||||
gfc->pinfo->blocktype[gr][ch] = gfc->l3_side.tt[gr][ch].block_type;
|
||||
gfc->pinfo->pe[gr][ch] = pe_use[gr][ch];
|
||||
memcpy(gfc->pinfo->xr[gr][ch], &gfc->l3_side.tt[gr][ch].xr[0], sizeof(FLOAT) * 576);
|
||||
/* in psymodel, LR and MS data was stored in pinfo.
|
||||
switch to MS data: */
|
||||
if (gfc->ov_enc.mode_ext == MPG_MD_MS_LR) {
|
||||
gfc->pinfo->ers[gr][ch] = gfc->pinfo->ers[gr][ch + 2];
|
||||
memcpy(gfc->pinfo->energy[gr][ch], gfc->pinfo->energy[gr][ch + 2],
|
||||
sizeof(gfc->pinfo->energy[gr][ch]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************
|
||||
* Stage 4: quantization loop *
|
||||
****************************************/
|
||||
|
||||
if (cfg->vbr == vbr_off || cfg->vbr == vbr_abr) {
|
||||
static FLOAT const fircoef[9] = {
|
||||
-0.0207887 * 5, -0.0378413 * 5, -0.0432472 * 5, -0.031183 * 5,
|
||||
7.79609e-18 * 5, 0.0467745 * 5, 0.10091 * 5, 0.151365 * 5,
|
||||
0.187098 * 5
|
||||
};
|
||||
|
||||
int i;
|
||||
FLOAT f;
|
||||
|
||||
for (i = 0; i < 18; i++)
|
||||
gfc->sv_enc.pefirbuf[i] = gfc->sv_enc.pefirbuf[i + 1];
|
||||
|
||||
f = 0.0;
|
||||
for (gr = 0; gr < cfg->mode_gr; gr++)
|
||||
for (ch = 0; ch < cfg->channels_out; ch++)
|
||||
f += pe_use[gr][ch];
|
||||
gfc->sv_enc.pefirbuf[18] = f;
|
||||
|
||||
f = gfc->sv_enc.pefirbuf[9];
|
||||
for (i = 0; i < 9; i++)
|
||||
f += (gfc->sv_enc.pefirbuf[i] + gfc->sv_enc.pefirbuf[18 - i]) * fircoef[i];
|
||||
|
||||
f = (670 * 5 * cfg->mode_gr * cfg->channels_out) / f;
|
||||
for (gr = 0; gr < cfg->mode_gr; gr++) {
|
||||
for (ch = 0; ch < cfg->channels_out; ch++) {
|
||||
pe_use[gr][ch] *= f;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (cfg->vbr)
|
||||
{
|
||||
default:
|
||||
case vbr_off:
|
||||
CBR_iteration_loop(gfc, (const FLOAT (*)[2])pe_use, ms_ener_ratio, masking);
|
||||
break;
|
||||
case vbr_abr:
|
||||
ABR_iteration_loop(gfc, (const FLOAT (*)[2])pe_use, ms_ener_ratio, masking);
|
||||
break;
|
||||
case vbr_rh:
|
||||
VBR_old_iteration_loop(gfc, (const FLOAT (*)[2])pe_use, ms_ener_ratio, masking);
|
||||
break;
|
||||
case vbr_mt:
|
||||
case vbr_mtrh:
|
||||
VBR_new_iteration_loop(gfc, (const FLOAT (*)[2])pe_use, ms_ener_ratio, masking);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/****************************************
|
||||
* Stage 5: bitstream formatting *
|
||||
****************************************/
|
||||
|
||||
|
||||
/* write the frame to the bitstream */
|
||||
(void) format_bitstream(gfc);
|
||||
|
||||
/* copy mp3 bit buffer into array */
|
||||
mp3count = copy_buffer(gfc, mp3buf, mp3buf_size, 1);
|
||||
|
||||
|
||||
if (cfg->write_lame_tag) {
|
||||
AddVbrFrame(gfc);
|
||||
}
|
||||
|
||||
if (cfg->analysis && gfc->pinfo != NULL) {
|
||||
int framesize = 576 * cfg->mode_gr;
|
||||
for (ch = 0; ch < cfg->channels_out; ch++) {
|
||||
int j;
|
||||
for (j = 0; j < FFTOFFSET; j++)
|
||||
gfc->pinfo->pcmdata[ch][j] = gfc->pinfo->pcmdata[ch][j + framesize];
|
||||
for (j = FFTOFFSET; j < 1600; j++) {
|
||||
gfc->pinfo->pcmdata[ch][j] = inbuf[ch][j - FFTOFFSET];
|
||||
}
|
||||
}
|
||||
gfc->sv_qnt.masking_lower = 1.0;
|
||||
|
||||
set_frame_pinfo(gfc, masking);
|
||||
}
|
||||
|
||||
++gfc->ov_enc.frame_number;
|
||||
|
||||
updateStats(gfc);
|
||||
|
||||
return mp3count;
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* encoder.h include file
|
||||
*
|
||||
* Copyright (c) 2000 Mark Taylor
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LAME_ENCODER_H
|
||||
#define LAME_ENCODER_H
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* encoder and decoder delays
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
/*
|
||||
* layer III enc->dec delay: 1056 (1057?) (observed)
|
||||
* layer II enc->dec delay: 480 (481?) (observed)
|
||||
*
|
||||
* polyphase 256-16 (dec or enc) = 240
|
||||
* mdct 256+32 (9*32) (dec or enc) = 288
|
||||
* total: 512+16
|
||||
*
|
||||
* My guess is that delay of polyphase filterbank is actualy 240.5
|
||||
* (there are technical reasons for this, see postings in mp3encoder).
|
||||
* So total Encode+Decode delay = ENCDELAY + 528 + 1
|
||||
*/
|
||||
|
||||
/*
|
||||
* ENCDELAY The encoder delay.
|
||||
*
|
||||
* Minimum allowed is MDCTDELAY (see below)
|
||||
*
|
||||
* The first 96 samples will be attenuated, so using a value less than 96
|
||||
* will result in corrupt data for the first 96-ENCDELAY samples.
|
||||
*
|
||||
* suggested: 576
|
||||
* set to 1160 to sync with FhG.
|
||||
*/
|
||||
|
||||
#define ENCDELAY 576
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* make sure there is at least one complete frame after the
|
||||
* last frame containing real data
|
||||
*
|
||||
* Using a value of 288 would be sufficient for a
|
||||
* a very sophisticated decoder that can decode granule-by-granule instead
|
||||
* of frame by frame. But lets not assume this, and assume the decoder
|
||||
* will not decode frame N unless it also has data for frame N+1
|
||||
*
|
||||
*/
|
||||
/*#define POSTDELAY 288*/
|
||||
#define POSTDELAY 1152
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* delay of the MDCT used in mdct.c
|
||||
* original ISO routines had a delay of 528!
|
||||
* Takehiro's routines:
|
||||
*/
|
||||
|
||||
#define MDCTDELAY 48
|
||||
#define FFTOFFSET (224+MDCTDELAY)
|
||||
|
||||
/*
|
||||
* Most decoders, including the one we use, have a delay of 528 samples.
|
||||
*/
|
||||
|
||||
#define DECDELAY 528
|
||||
|
||||
|
||||
/* number of subbands */
|
||||
#define SBLIMIT 32
|
||||
|
||||
/* parition bands bands */
|
||||
#define CBANDS 64
|
||||
|
||||
/* number of critical bands/scale factor bands where masking is computed*/
|
||||
#define SBPSY_l 21
|
||||
#define SBPSY_s 12
|
||||
|
||||
/* total number of scalefactor bands encoded */
|
||||
#define SBMAX_l 22
|
||||
#define SBMAX_s 13
|
||||
#define PSFB21 6
|
||||
#define PSFB12 6
|
||||
|
||||
|
||||
|
||||
/* FFT sizes */
|
||||
#define BLKSIZE 1024
|
||||
#define HBLKSIZE (BLKSIZE/2 + 1)
|
||||
#define BLKSIZE_s 256
|
||||
#define HBLKSIZE_s (BLKSIZE_s/2 + 1)
|
||||
|
||||
|
||||
/* #define switch_pe 1800 */
|
||||
#define NORM_TYPE 0
|
||||
#define START_TYPE 1
|
||||
#define SHORT_TYPE 2
|
||||
#define STOP_TYPE 3
|
||||
|
||||
/*
|
||||
* Mode Extention:
|
||||
* When we are in stereo mode, there are 4 possible methods to store these
|
||||
* two channels. The stereo modes -m? are using a subset of them.
|
||||
*
|
||||
* -ms: MPG_MD_LR_LR
|
||||
* -mj: MPG_MD_LR_LR and MPG_MD_MS_LR
|
||||
* -mf: MPG_MD_MS_LR
|
||||
* -mi: all
|
||||
*/
|
||||
#if 0
|
||||
#define MPG_MD_LR_LR 0
|
||||
#define MPG_MD_LR_I 1
|
||||
#define MPG_MD_MS_LR 2
|
||||
#define MPG_MD_MS_I 3
|
||||
#endif
|
||||
enum MPEGChannelMode
|
||||
{ MPG_MD_LR_LR = 0
|
||||
, MPG_MD_LR_I = 1
|
||||
, MPG_MD_MS_LR = 2
|
||||
, MPG_MD_MS_I = 3
|
||||
};
|
||||
|
||||
#ifndef lame_internal_flags_defined
|
||||
#define lame_internal_flags_defined
|
||||
struct lame_internal_flags;
|
||||
typedef struct lame_internal_flags lame_internal_flags;
|
||||
#endif
|
||||
|
||||
int lame_encode_mp3_frame(lame_internal_flags * gfc,
|
||||
sample_t const *inbuf_l,
|
||||
sample_t const *inbuf_r, unsigned char *mp3buf, int mp3buf_size);
|
||||
|
||||
#endif /* LAME_ENCODER_H */
|
||||
@@ -0,0 +1,339 @@
|
||||
/*
|
||||
** FFT and FHT routines
|
||||
** Copyright 1988, 1993; Ron Mayer
|
||||
** Copyright (c) 1999-2000 Takehiro Tominaga
|
||||
**
|
||||
** fht(fz,n);
|
||||
** Does a hartley transform of "n" points in the array "fz".
|
||||
**
|
||||
** NOTE: This routine uses at least 2 patented algorithms, and may be
|
||||
** under the restrictions of a bunch of different organizations.
|
||||
** Although I wrote it completely myself; it is kind of a derivative
|
||||
** of a routine I once authored and released under the GPL, so it
|
||||
** may fall under the free software foundation's restrictions;
|
||||
** it was worked on as a Stanford Univ project, so they claim
|
||||
** some rights to it; it was further optimized at work here, so
|
||||
** I think this company claims parts of it. The patents are
|
||||
** held by R. Bracewell (the FHT algorithm) and O. Buneman (the
|
||||
** trig generator), both at Stanford Univ.
|
||||
** If it were up to me, I'd say go do whatever you want with it;
|
||||
** but it would be polite to give credit to the following people
|
||||
** if you use this anywhere:
|
||||
** Euler - probable inventor of the fourier transform.
|
||||
** Gauss - probable inventor of the FFT.
|
||||
** Hartley - probable inventor of the hartley transform.
|
||||
** Buneman - for a really cool trig generator
|
||||
** Mayer(me) - for authoring this particular version and
|
||||
** including all the optimizations in one package.
|
||||
** Thanks,
|
||||
** Ron Mayer; mayer@acuson.com
|
||||
** and added some optimization by
|
||||
** Mather - idea of using lookup table
|
||||
** Takehiro - some dirty hack for speed up
|
||||
*/
|
||||
|
||||
/* $Id: fft.c,v 1.39 2017/09/06 15:07:29 robert Exp $ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "lame.h"
|
||||
#include "machine.h"
|
||||
#include "encoder.h"
|
||||
#include "util.h"
|
||||
#include "fft.h"
|
||||
|
||||
#include "vector/lame_intrin.h"
|
||||
|
||||
|
||||
|
||||
#define TRI_SIZE (5-1) /* 1024 = 4**5 */
|
||||
|
||||
/* fft.c */
|
||||
|
||||
static const FLOAT costab[TRI_SIZE * 2] = {
|
||||
9.238795325112867e-01, 3.826834323650898e-01,
|
||||
9.951847266721969e-01, 9.801714032956060e-02,
|
||||
9.996988186962042e-01, 2.454122852291229e-02,
|
||||
9.999811752826011e-01, 6.135884649154475e-03
|
||||
};
|
||||
|
||||
static void
|
||||
fht(FLOAT * fz, int n)
|
||||
{
|
||||
const FLOAT *tri = costab;
|
||||
int k4;
|
||||
FLOAT *fi, *gi;
|
||||
FLOAT const *fn;
|
||||
|
||||
n <<= 1; /* to get BLKSIZE, because of 3DNow! ASM routine */
|
||||
fn = fz + n;
|
||||
k4 = 4;
|
||||
do {
|
||||
FLOAT s1, c1;
|
||||
int i, k1, k2, k3, kx;
|
||||
kx = k4 >> 1;
|
||||
k1 = k4;
|
||||
k2 = k4 << 1;
|
||||
k3 = k2 + k1;
|
||||
k4 = k2 << 1;
|
||||
fi = fz;
|
||||
gi = fi + kx;
|
||||
do {
|
||||
FLOAT f0, f1, f2, f3;
|
||||
f1 = fi[0] - fi[k1];
|
||||
f0 = fi[0] + fi[k1];
|
||||
f3 = fi[k2] - fi[k3];
|
||||
f2 = fi[k2] + fi[k3];
|
||||
fi[k2] = f0 - f2;
|
||||
fi[0] = f0 + f2;
|
||||
fi[k3] = f1 - f3;
|
||||
fi[k1] = f1 + f3;
|
||||
f1 = gi[0] - gi[k1];
|
||||
f0 = gi[0] + gi[k1];
|
||||
f3 = SQRT2 * gi[k3];
|
||||
f2 = SQRT2 * gi[k2];
|
||||
gi[k2] = f0 - f2;
|
||||
gi[0] = f0 + f2;
|
||||
gi[k3] = f1 - f3;
|
||||
gi[k1] = f1 + f3;
|
||||
gi += k4;
|
||||
fi += k4;
|
||||
} while (fi < fn);
|
||||
c1 = tri[0];
|
||||
s1 = tri[1];
|
||||
for (i = 1; i < kx; i++) {
|
||||
FLOAT c2, s2;
|
||||
c2 = 1 - (2 * s1) * s1;
|
||||
s2 = (2 * s1) * c1;
|
||||
fi = fz + i;
|
||||
gi = fz + k1 - i;
|
||||
do {
|
||||
FLOAT a, b, g0, f0, f1, g1, f2, g2, f3, g3;
|
||||
b = s2 * fi[k1] - c2 * gi[k1];
|
||||
a = c2 * fi[k1] + s2 * gi[k1];
|
||||
f1 = fi[0] - a;
|
||||
f0 = fi[0] + a;
|
||||
g1 = gi[0] - b;
|
||||
g0 = gi[0] + b;
|
||||
b = s2 * fi[k3] - c2 * gi[k3];
|
||||
a = c2 * fi[k3] + s2 * gi[k3];
|
||||
f3 = fi[k2] - a;
|
||||
f2 = fi[k2] + a;
|
||||
g3 = gi[k2] - b;
|
||||
g2 = gi[k2] + b;
|
||||
b = s1 * f2 - c1 * g3;
|
||||
a = c1 * f2 + s1 * g3;
|
||||
fi[k2] = f0 - a;
|
||||
fi[0] = f0 + a;
|
||||
gi[k3] = g1 - b;
|
||||
gi[k1] = g1 + b;
|
||||
b = c1 * g2 - s1 * f3;
|
||||
a = s1 * g2 + c1 * f3;
|
||||
gi[k2] = g0 - a;
|
||||
gi[0] = g0 + a;
|
||||
fi[k3] = f1 - b;
|
||||
fi[k1] = f1 + b;
|
||||
gi += k4;
|
||||
fi += k4;
|
||||
} while (fi < fn);
|
||||
c2 = c1;
|
||||
c1 = c2 * tri[0] - s1 * tri[1];
|
||||
s1 = c2 * tri[1] + s1 * tri[0];
|
||||
}
|
||||
tri += 2;
|
||||
} while (k4 < n);
|
||||
}
|
||||
|
||||
|
||||
static const unsigned char rv_tbl[] = {
|
||||
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
|
||||
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
|
||||
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
|
||||
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
|
||||
0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
|
||||
0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
|
||||
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
|
||||
0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
|
||||
0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
|
||||
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
|
||||
0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
|
||||
0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
|
||||
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
|
||||
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
|
||||
0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
|
||||
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe
|
||||
};
|
||||
|
||||
#define ch01(index) (buffer[chn][index])
|
||||
|
||||
#define ml00(f) (window[i ] * f(i))
|
||||
#define ml10(f) (window[i + 0x200] * f(i + 0x200))
|
||||
#define ml20(f) (window[i + 0x100] * f(i + 0x100))
|
||||
#define ml30(f) (window[i + 0x300] * f(i + 0x300))
|
||||
|
||||
#define ml01(f) (window[i + 0x001] * f(i + 0x001))
|
||||
#define ml11(f) (window[i + 0x201] * f(i + 0x201))
|
||||
#define ml21(f) (window[i + 0x101] * f(i + 0x101))
|
||||
#define ml31(f) (window[i + 0x301] * f(i + 0x301))
|
||||
|
||||
#define ms00(f) (window_s[i ] * f(i + k))
|
||||
#define ms10(f) (window_s[0x7f - i] * f(i + k + 0x80))
|
||||
#define ms20(f) (window_s[i + 0x40] * f(i + k + 0x40))
|
||||
#define ms30(f) (window_s[0x3f - i] * f(i + k + 0xc0))
|
||||
|
||||
#define ms01(f) (window_s[i + 0x01] * f(i + k + 0x01))
|
||||
#define ms11(f) (window_s[0x7e - i] * f(i + k + 0x81))
|
||||
#define ms21(f) (window_s[i + 0x41] * f(i + k + 0x41))
|
||||
#define ms31(f) (window_s[0x3e - i] * f(i + k + 0xc1))
|
||||
|
||||
void
|
||||
fft_short(lame_internal_flags const *const gfc,
|
||||
FLOAT x_real[3][BLKSIZE_s], int chn, const sample_t *const buffer[2])
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int b;
|
||||
|
||||
#define window_s gfc->cd_psy->window_s
|
||||
#define window gfc->cd_psy->window
|
||||
|
||||
for (b = 0; b < 3; b++) {
|
||||
FLOAT *x = &x_real[b][BLKSIZE_s / 2];
|
||||
short const k = (576 / 3) * (b + 1);
|
||||
j = BLKSIZE_s / 8 - 1;
|
||||
do {
|
||||
FLOAT f0, f1, f2, f3, w;
|
||||
|
||||
i = rv_tbl[j << 2];
|
||||
|
||||
f0 = ms00(ch01);
|
||||
w = ms10(ch01);
|
||||
f1 = f0 - w;
|
||||
f0 = f0 + w;
|
||||
f2 = ms20(ch01);
|
||||
w = ms30(ch01);
|
||||
f3 = f2 - w;
|
||||
f2 = f2 + w;
|
||||
|
||||
x -= 4;
|
||||
x[0] = f0 + f2;
|
||||
x[2] = f0 - f2;
|
||||
x[1] = f1 + f3;
|
||||
x[3] = f1 - f3;
|
||||
|
||||
f0 = ms01(ch01);
|
||||
w = ms11(ch01);
|
||||
f1 = f0 - w;
|
||||
f0 = f0 + w;
|
||||
f2 = ms21(ch01);
|
||||
w = ms31(ch01);
|
||||
f3 = f2 - w;
|
||||
f2 = f2 + w;
|
||||
|
||||
x[BLKSIZE_s / 2 + 0] = f0 + f2;
|
||||
x[BLKSIZE_s / 2 + 2] = f0 - f2;
|
||||
x[BLKSIZE_s / 2 + 1] = f1 + f3;
|
||||
x[BLKSIZE_s / 2 + 3] = f1 - f3;
|
||||
} while (--j >= 0);
|
||||
|
||||
#undef window
|
||||
#undef window_s
|
||||
|
||||
gfc->fft_fht(x, BLKSIZE_s / 2);
|
||||
/* BLKSIZE_s/2 because of 3DNow! ASM routine */
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
fft_long(lame_internal_flags const *const gfc,
|
||||
FLOAT x[BLKSIZE], int chn, const sample_t *const buffer[2])
|
||||
{
|
||||
int i;
|
||||
int jj = BLKSIZE / 8 - 1;
|
||||
x += BLKSIZE / 2;
|
||||
|
||||
#define window_s gfc->cd_psy->window_s
|
||||
#define window gfc->cd_psy->window
|
||||
|
||||
do {
|
||||
FLOAT f0, f1, f2, f3, w;
|
||||
|
||||
i = rv_tbl[jj];
|
||||
f0 = ml00(ch01);
|
||||
w = ml10(ch01);
|
||||
f1 = f0 - w;
|
||||
f0 = f0 + w;
|
||||
f2 = ml20(ch01);
|
||||
w = ml30(ch01);
|
||||
f3 = f2 - w;
|
||||
f2 = f2 + w;
|
||||
|
||||
x -= 4;
|
||||
x[0] = f0 + f2;
|
||||
x[2] = f0 - f2;
|
||||
x[1] = f1 + f3;
|
||||
x[3] = f1 - f3;
|
||||
|
||||
f0 = ml01(ch01);
|
||||
w = ml11(ch01);
|
||||
f1 = f0 - w;
|
||||
f0 = f0 + w;
|
||||
f2 = ml21(ch01);
|
||||
w = ml31(ch01);
|
||||
f3 = f2 - w;
|
||||
f2 = f2 + w;
|
||||
|
||||
x[BLKSIZE / 2 + 0] = f0 + f2;
|
||||
x[BLKSIZE / 2 + 2] = f0 - f2;
|
||||
x[BLKSIZE / 2 + 1] = f1 + f3;
|
||||
x[BLKSIZE / 2 + 3] = f1 - f3;
|
||||
} while (--jj >= 0);
|
||||
|
||||
#undef window
|
||||
#undef window_s
|
||||
|
||||
gfc->fft_fht(x, BLKSIZE / 2);
|
||||
/* BLKSIZE/2 because of 3DNow! ASM routine */
|
||||
}
|
||||
|
||||
#ifdef HAVE_NASM
|
||||
extern void fht_3DN(FLOAT * fz, int n);
|
||||
extern void fht_SSE(FLOAT * fz, int n);
|
||||
#endif
|
||||
|
||||
void
|
||||
init_fft(lame_internal_flags * const gfc)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* The type of window used here will make no real difference, but */
|
||||
/* in the interest of merging nspsytune stuff - switch to blackman window */
|
||||
for (i = 0; i < BLKSIZE; i++)
|
||||
/* blackman window */
|
||||
gfc->cd_psy->window[i] = 0.42 - 0.5 * cos(2 * PI * (i + .5) / BLKSIZE) +
|
||||
0.08 * cos(4 * PI * (i + .5) / BLKSIZE);
|
||||
|
||||
for (i = 0; i < BLKSIZE_s / 2; i++)
|
||||
gfc->cd_psy->window_s[i] = 0.5 * (1.0 - cos(2.0 * PI * (i + 0.5) / BLKSIZE_s));
|
||||
|
||||
gfc->fft_fht = fht;
|
||||
#ifdef HAVE_NASM
|
||||
if (gfc->CPU_features.AMD_3DNow) {
|
||||
gfc->fft_fht = fht_3DN;
|
||||
}
|
||||
else if (gfc->CPU_features.SSE) {
|
||||
gfc->fft_fht = fht_SSE;
|
||||
}
|
||||
else {
|
||||
gfc->fft_fht = fht;
|
||||
}
|
||||
#else
|
||||
#ifdef HAVE_XMMINTRIN_H
|
||||
#ifdef MIN_ARCH_SSE
|
||||
gfc->fft_fht = fht_SSE2;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Fast Fourier Transform include file
|
||||
*
|
||||
* Copyright (c) 2000 Mark Taylor
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_FFT_H
|
||||
#define LAME_FFT_H
|
||||
|
||||
void fft_long(lame_internal_flags const *const gfc, FLOAT x_real[BLKSIZE],
|
||||
int chn, const sample_t *const data[2]);
|
||||
|
||||
void fft_short(lame_internal_flags const *const gfc, FLOAT x_real[3][BLKSIZE_s],
|
||||
int chn, const sample_t *const data[2]);
|
||||
|
||||
void init_fft(lame_internal_flags * const gfc);
|
||||
|
||||
#endif
|
||||
|
||||
/* End of fft.h */
|
||||
+476
@@ -0,0 +1,476 @@
|
||||
/*
|
||||
* ReplayGainAnalysis - analyzes input samples and give the recommended dB change
|
||||
* Copyright (C) 2001 David Robinson and Glen Sawyer
|
||||
* Improvements and optimizations added by Frank Klemm, and by Marcel Muller
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* concept and filter values by David Robinson (David@Robinson.org)
|
||||
* -- blame him if you think the idea is flawed
|
||||
* original coding by Glen Sawyer (mp3gain@hotmail.com)
|
||||
* -- blame him if you think this runs too slowly, or the coding is otherwise flawed
|
||||
*
|
||||
* lots of code improvements by Frank Klemm ( http://www.uni-jena.de/~pfk/mpp/ )
|
||||
* -- credit him for all the _good_ programming ;)
|
||||
*
|
||||
*
|
||||
* For an explanation of the concepts and the basic algorithms involved, go to:
|
||||
* http://www.replaygain.org/
|
||||
*/
|
||||
|
||||
/*
|
||||
* Here's the deal. Call
|
||||
*
|
||||
* InitGainAnalysis ( long samplefreq );
|
||||
*
|
||||
* to initialize everything. Call
|
||||
*
|
||||
* AnalyzeSamples ( const Float_t* left_samples,
|
||||
* const Float_t* right_samples,
|
||||
* size_t num_samples,
|
||||
* int num_channels );
|
||||
*
|
||||
* as many times as you want, with as many or as few samples as you want.
|
||||
* If mono, pass the sample buffer in through left_samples, leave
|
||||
* right_samples NULL, and make sure num_channels = 1.
|
||||
*
|
||||
* GetTitleGain()
|
||||
*
|
||||
* will return the recommended dB level change for all samples analyzed
|
||||
* SINCE THE LAST TIME you called GetTitleGain() OR InitGainAnalysis().
|
||||
*
|
||||
* GetAlbumGain()
|
||||
*
|
||||
* will return the recommended dB level change for all samples analyzed
|
||||
* since InitGainAnalysis() was called and finalized with GetTitleGain().
|
||||
*
|
||||
* Pseudo-code to process an album:
|
||||
*
|
||||
* Float_t l_samples [4096];
|
||||
* Float_t r_samples [4096];
|
||||
* size_t num_samples;
|
||||
* unsigned int num_songs;
|
||||
* unsigned int i;
|
||||
*
|
||||
* InitGainAnalysis ( 44100 );
|
||||
* for ( i = 1; i <= num_songs; i++ ) {
|
||||
* while ( ( num_samples = getSongSamples ( song[i], left_samples, right_samples ) ) > 0 )
|
||||
* AnalyzeSamples ( left_samples, right_samples, num_samples, 2 );
|
||||
* fprintf ("Recommended dB change for song %2d: %+6.2f dB\n", i, GetTitleGain() );
|
||||
* }
|
||||
* fprintf ("Recommended dB change for whole album: %+6.2f dB\n", GetAlbumGain() );
|
||||
*/
|
||||
|
||||
/*
|
||||
* So here's the main source of potential code confusion:
|
||||
*
|
||||
* The filters applied to the incoming samples are IIR filters,
|
||||
* meaning they rely on up to <filter order> number of previous samples
|
||||
* AND up to <filter order> number of previous filtered samples.
|
||||
*
|
||||
* I set up the AnalyzeSamples routine to minimize memory usage and interface
|
||||
* complexity. The speed isn't compromised too much (I don't think), but the
|
||||
* internal complexity is higher than it should be for such a relatively
|
||||
* simple routine.
|
||||
*
|
||||
* Optimization/clarity suggestions are welcome.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lame.h"
|
||||
#include "machine.h"
|
||||
#include "gain_analysis.h"
|
||||
|
||||
/* for each filter: */
|
||||
/* [0] 48 kHz, [1] 44.1 kHz, [2] 32 kHz, [3] 24 kHz, [4] 22050 Hz, [5] 16 kHz, [6] 12 kHz, [7] is 11025 Hz, [8] 8 kHz */
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning ( disable : 4305 )
|
||||
#endif
|
||||
|
||||
|
||||
/*lint -save -e736 loss of precision */
|
||||
static const Float_t ABYule[9][multiple_of(4, 2 * YULE_ORDER + 1)] = {
|
||||
/* 20 18 16 14 12 10 8 6 4 2 0 19 17 15 13 11 9 7 5 3 1 */
|
||||
{ 0.00288463683916, 0.00012025322027, 0.00306428023191, 0.00594298065125, -0.02074045215285, 0.02161526843274, -0.01655260341619, -0.00009291677959, -0.00123395316851, -0.02160367184185, 0.03857599435200, 0.13919314567432, -0.86984376593551, 2.75465861874613, -5.87257861775999, 9.48293806319790,-12.28759895145294, 13.05504219327545,-11.34170355132042, 7.81501653005538, -3.84664617118067},
|
||||
{-0.00187763777362, 0.00674613682247, -0.00240879051584, 0.01624864962975, -0.02596338512915, 0.02245293253339, -0.00834990904936, -0.00851165645469, -0.00848709379851, -0.02911007808948, 0.05418656406430, 0.13149317958808, -0.75104302451432, 2.19611684890774, -4.39470996079559, 6.85401540936998, -8.81498681370155, 9.47693607801280, -8.54751527471874, 6.36317777566148, -3.47845948550071},
|
||||
{-0.00881362733839, 0.00651420667831, -0.01390589421898, 0.03174092540049, 0.00222312597743, 0.04781476674921, -0.05588393329856, 0.02163541888798, -0.06247880153653, -0.09331049056315, 0.15457299681924, 0.02347897407020, -0.05032077717131, 0.16378164858596, -0.45953458054983, 1.00595954808547, -1.67148153367602, 2.23697657451713, -2.64577170229825, 2.84868151156327, -2.37898834973084},
|
||||
{-0.02950134983287, 0.00205861885564, -0.00000828086748, 0.06276101321749, -0.00584456039913, -0.02364141202522, -0.00915702933434, 0.03282930172664, -0.08587323730772, -0.22613988682123, 0.30296907319327, 0.00302439095741, 0.02005851806501, 0.04500235387352, -0.22138138954925, 0.39120800788284, -0.22638893773906, -0.16276719120440, -0.25656257754070, 1.07977492259970, -1.61273165137247},
|
||||
{-0.01760176568150, -0.01635381384540, 0.00832043980773, 0.05724228140351, -0.00589500224440, -0.00469977914380, -0.07834489609479, 0.11921148675203, -0.11828570177555, -0.25572241425570, 0.33642304856132, 0.02977207319925, -0.04237348025746, 0.08333755284107, -0.04067510197014, -0.12453458140019, 0.47854794562326, -0.80774944671438, 0.12205022308084, 0.87350271418188, -1.49858979367799},
|
||||
{ 0.00541907748707, -0.03193428438915, -0.01863887810927, 0.10478503600251, 0.04097565135648, -0.12398163381748, 0.04078262797139, -0.01419140100551, -0.22784394429749, -0.14351757464547, 0.44915256608450, 0.03222754072173, 0.05784820375801, 0.06747620744683, 0.00613424350682, 0.22199650564824, -0.42029820170918, 0.00213767857124, -0.37256372942400, 0.29661783706366, -0.62820619233671},
|
||||
{-0.00588215443421, -0.03788984554840, 0.08647503780351, 0.00647310677246, -0.27562961986224, 0.30931782841830, -0.18901604199609, 0.16744243493672, 0.16242137742230, -0.75464456939302, 0.56619470757641, 0.01807364323573, 0.01639907836189, -0.04784254229033, 0.06739368333110, -0.33032403314006, 0.45054734505008, 0.00819999645858, -0.26806001042947, 0.29156311971249, -1.04800335126349},
|
||||
{-0.00749618797172, -0.03721611395801, 0.06920467763959, 0.01628462406333, -0.25344790059353, 0.15558449135573, 0.02377945217615, 0.17520704835522, -0.14289799034253, -0.53174909058578, 0.58100494960553, 0.01818801111503, 0.02442357316099, -0.02505961724053, -0.05246019024463, -0.23313271880868, 0.38952639978999, 0.14728154134330, -0.20256413484477, -0.31863563325245, -0.51035327095184},
|
||||
{-0.02217936801134, 0.04788665548180, -0.04060034127000, -0.11202315195388, -0.02459864859345, 0.14590772289388, -0.10214864179676, 0.04267842219415, -0.00275953611929, -0.42163034350696, 0.53648789255105, 0.04704409688120, 0.05477720428674, -0.18823009262115, -0.17556493366449, 0.15113130533216, 0.26408300200955, -0.04678328784242, -0.03424681017675, -0.43193942311114, -0.25049871956020}
|
||||
};
|
||||
|
||||
static const Float_t ABButter[9][multiple_of(4, 2 * BUTTER_ORDER + 1)] = {
|
||||
/* 5 4 3 2 1 */
|
||||
{0.98621192462708, 0.97261396931306, -1.97242384925416, -1.97223372919527, 0.98621192462708},
|
||||
{0.98500175787242, 0.97022847566350, -1.97000351574484, -1.96977855582618, 0.98500175787242},
|
||||
{0.97938932735214, 0.95920349965459, -1.95877865470428, -1.95835380975398, 0.97938932735214},
|
||||
{0.97531843204928, 0.95124613669835, -1.95063686409857, -1.95002759149878, 0.97531843204928},
|
||||
{0.97316523498161, 0.94705070426118, -1.94633046996323, -1.94561023566527, 0.97316523498161},
|
||||
{0.96454515552826, 0.93034775234268, -1.92909031105652, -1.92783286977036, 0.96454515552826},
|
||||
{0.96009142950541, 0.92177618768381, -1.92018285901082, -1.91858953033784, 0.96009142950541},
|
||||
{0.95856916599601, 0.91885558323625, -1.91713833199203, -1.91542108074780, 0.95856916599601},
|
||||
{0.94597685600279, 0.89487434461664, -1.89195371200558, -1.88903307939452, 0.94597685600279}
|
||||
};
|
||||
|
||||
/*lint -restore */
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning ( default : 4305 )
|
||||
#endif
|
||||
|
||||
/* When calling this procedure, make sure that ip[-order] and op[-order] point to real data! */
|
||||
|
||||
static void
|
||||
filterYule(const Float_t * input, Float_t * output, size_t nSamples, const Float_t * const kernel)
|
||||
{
|
||||
while (nSamples--) {
|
||||
Float_t y0 = input[-10] * kernel[ 0];
|
||||
Float_t y2 = input[ -9] * kernel[ 1];
|
||||
Float_t y4 = input[ -8] * kernel[ 2];
|
||||
Float_t y6 = input[ -7] * kernel[ 3];
|
||||
Float_t s00 = y0 + y2 + y4 + y6;
|
||||
Float_t y8 = input[ -6] * kernel[ 4];
|
||||
Float_t yA = input[ -5] * kernel[ 5];
|
||||
Float_t yC = input[ -4] * kernel[ 6];
|
||||
Float_t yE = input[ -3] * kernel[ 7];
|
||||
Float_t s01 = y8 + yA + yC + yE;
|
||||
Float_t yG = input[ -2] * kernel[ 8] + input[ -1] * kernel[ 9];
|
||||
Float_t yK = input[ 0] * kernel[10];
|
||||
|
||||
Float_t s1 = s00 + s01 + yG + yK;
|
||||
|
||||
Float_t x1 = output[-10] * kernel[11] + output[ -9] * kernel[12];
|
||||
Float_t x5 = output[ -8] * kernel[13] + output[ -7] * kernel[14];
|
||||
Float_t x9 = output[ -6] * kernel[15] + output[ -5] * kernel[16];
|
||||
Float_t xD = output[ -4] * kernel[17] + output[ -3] * kernel[18];
|
||||
Float_t xH = output[ -2] * kernel[19] + output[ -1] * kernel[20];
|
||||
|
||||
Float_t s2 = x1 + x5 + x9 + xD + xH;
|
||||
|
||||
output[0] = (Float_t)(s1 - s2);
|
||||
|
||||
++output;
|
||||
++input;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
filterButter(const Float_t * input, Float_t * output, size_t nSamples, const Float_t * const kernel)
|
||||
{
|
||||
while (nSamples--) {
|
||||
Float_t s1 = input[-2] * kernel[0] + input[-1] * kernel[2] + input[ 0] * kernel[4];
|
||||
Float_t s2 = output[-2] * kernel[1] + output[-1] * kernel[3];
|
||||
output[0] = (Float_t)(s1 - s2);
|
||||
++output;
|
||||
++input;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int ResetSampleFrequency(replaygain_t * rgData, long samplefreq);
|
||||
|
||||
/* returns a INIT_GAIN_ANALYSIS_OK if successful, INIT_GAIN_ANALYSIS_ERROR if not */
|
||||
|
||||
int
|
||||
ResetSampleFrequency(replaygain_t * rgData, long samplefreq)
|
||||
{
|
||||
/* zero out initial values, only first MAX_ORDER values */
|
||||
memset(rgData->linprebuf, 0, MAX_ORDER * sizeof(*rgData->linprebuf));
|
||||
memset(rgData->rinprebuf, 0, MAX_ORDER * sizeof(*rgData->rinprebuf));
|
||||
memset(rgData->lstepbuf, 0, MAX_ORDER * sizeof(*rgData->lstepbuf));
|
||||
memset(rgData->rstepbuf, 0, MAX_ORDER * sizeof(*rgData->rstepbuf));
|
||||
memset(rgData->loutbuf, 0, MAX_ORDER * sizeof(*rgData->loutbuf));
|
||||
memset(rgData->routbuf, 0, MAX_ORDER * sizeof(*rgData->routbuf));
|
||||
|
||||
switch ((int) (samplefreq)) {
|
||||
case 48000:
|
||||
rgData->freqindex = 0;
|
||||
break;
|
||||
case 44100:
|
||||
rgData->freqindex = 1;
|
||||
break;
|
||||
case 32000:
|
||||
rgData->freqindex = 2;
|
||||
break;
|
||||
case 24000:
|
||||
rgData->freqindex = 3;
|
||||
break;
|
||||
case 22050:
|
||||
rgData->freqindex = 4;
|
||||
break;
|
||||
case 16000:
|
||||
rgData->freqindex = 5;
|
||||
break;
|
||||
case 12000:
|
||||
rgData->freqindex = 6;
|
||||
break;
|
||||
case 11025:
|
||||
rgData->freqindex = 7;
|
||||
break;
|
||||
case 8000:
|
||||
rgData->freqindex = 8;
|
||||
break;
|
||||
default:
|
||||
return INIT_GAIN_ANALYSIS_ERROR;
|
||||
}
|
||||
|
||||
rgData->sampleWindow =
|
||||
(samplefreq * RMS_WINDOW_TIME_NUMERATOR + RMS_WINDOW_TIME_DENOMINATOR -
|
||||
1) / RMS_WINDOW_TIME_DENOMINATOR;
|
||||
|
||||
rgData->lsum = 0.;
|
||||
rgData->rsum = 0.;
|
||||
rgData->totsamp = 0;
|
||||
|
||||
memset(rgData->A, 0, sizeof(rgData->A));
|
||||
|
||||
return INIT_GAIN_ANALYSIS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
InitGainAnalysis(replaygain_t * rgData, long samplefreq)
|
||||
{
|
||||
if (ResetSampleFrequency(rgData, samplefreq) != INIT_GAIN_ANALYSIS_OK) {
|
||||
return INIT_GAIN_ANALYSIS_ERROR;
|
||||
}
|
||||
|
||||
rgData->linpre = rgData->linprebuf + MAX_ORDER;
|
||||
rgData->rinpre = rgData->rinprebuf + MAX_ORDER;
|
||||
rgData->lstep = rgData->lstepbuf + MAX_ORDER;
|
||||
rgData->rstep = rgData->rstepbuf + MAX_ORDER;
|
||||
rgData->lout = rgData->loutbuf + MAX_ORDER;
|
||||
rgData->rout = rgData->routbuf + MAX_ORDER;
|
||||
|
||||
memset(rgData->B, 0, sizeof(rgData->B));
|
||||
|
||||
return INIT_GAIN_ANALYSIS_OK;
|
||||
}
|
||||
|
||||
/* returns GAIN_ANALYSIS_OK if successful, GAIN_ANALYSIS_ERROR if not */
|
||||
|
||||
int
|
||||
AnalyzeSamples(replaygain_t * rgData, const Float_t * left_samples, const Float_t * right_samples,
|
||||
size_t num_samples, int num_channels)
|
||||
{
|
||||
const Float_t *curleft;
|
||||
const Float_t *curright;
|
||||
long batchsamples;
|
||||
long cursamples;
|
||||
long cursamplepos;
|
||||
int i;
|
||||
Float_t sum_l, sum_r;
|
||||
|
||||
if (num_samples == 0)
|
||||
return GAIN_ANALYSIS_OK;
|
||||
|
||||
cursamplepos = 0;
|
||||
batchsamples = (long) num_samples;
|
||||
|
||||
switch (num_channels) {
|
||||
case 1:
|
||||
right_samples = left_samples;
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
default:
|
||||
return GAIN_ANALYSIS_ERROR;
|
||||
}
|
||||
|
||||
if (num_samples < MAX_ORDER) {
|
||||
memcpy(rgData->linprebuf + MAX_ORDER, left_samples, num_samples * sizeof(Float_t));
|
||||
memcpy(rgData->rinprebuf + MAX_ORDER, right_samples, num_samples * sizeof(Float_t));
|
||||
}
|
||||
else {
|
||||
memcpy(rgData->linprebuf + MAX_ORDER, left_samples, MAX_ORDER * sizeof(Float_t));
|
||||
memcpy(rgData->rinprebuf + MAX_ORDER, right_samples, MAX_ORDER * sizeof(Float_t));
|
||||
}
|
||||
|
||||
while (batchsamples > 0) {
|
||||
cursamples = batchsamples > rgData->sampleWindow - rgData->totsamp ?
|
||||
rgData->sampleWindow - rgData->totsamp : batchsamples;
|
||||
if (cursamplepos < MAX_ORDER) {
|
||||
curleft = rgData->linpre + cursamplepos;
|
||||
curright = rgData->rinpre + cursamplepos;
|
||||
if (cursamples > MAX_ORDER - cursamplepos)
|
||||
cursamples = MAX_ORDER - cursamplepos;
|
||||
}
|
||||
else {
|
||||
curleft = left_samples + cursamplepos;
|
||||
curright = right_samples + cursamplepos;
|
||||
}
|
||||
|
||||
YULE_FILTER(curleft, rgData->lstep + rgData->totsamp, cursamples,
|
||||
ABYule[rgData->freqindex]);
|
||||
YULE_FILTER(curright, rgData->rstep + rgData->totsamp, cursamples,
|
||||
ABYule[rgData->freqindex]);
|
||||
|
||||
BUTTER_FILTER(rgData->lstep + rgData->totsamp, rgData->lout + rgData->totsamp, cursamples,
|
||||
ABButter[rgData->freqindex]);
|
||||
BUTTER_FILTER(rgData->rstep + rgData->totsamp, rgData->rout + rgData->totsamp, cursamples,
|
||||
ABButter[rgData->freqindex]);
|
||||
|
||||
curleft = rgData->lout + rgData->totsamp; /* Get the squared values */
|
||||
curright = rgData->rout + rgData->totsamp;
|
||||
|
||||
sum_l = 0;
|
||||
sum_r = 0;
|
||||
i = cursamples & 0x03;
|
||||
while (i--) {
|
||||
Float_t const l = *curleft++;
|
||||
Float_t const r = *curright++;
|
||||
sum_l += l * l;
|
||||
sum_r += r * r;
|
||||
}
|
||||
i = cursamples / 4;
|
||||
while (i--) {
|
||||
Float_t l0 = curleft[0] * curleft[0];
|
||||
Float_t l1 = curleft[1] * curleft[1];
|
||||
Float_t l2 = curleft[2] * curleft[2];
|
||||
Float_t l3 = curleft[3] * curleft[3];
|
||||
Float_t sl = l0 + l1 + l2 + l3;
|
||||
Float_t r0 = curright[0] * curright[0];
|
||||
Float_t r1 = curright[1] * curright[1];
|
||||
Float_t r2 = curright[2] * curright[2];
|
||||
Float_t r3 = curright[3] * curright[3];
|
||||
Float_t sr = r0 + r1 + r2 + r3;
|
||||
sum_l += sl;
|
||||
curleft += 4;
|
||||
sum_r += sr;
|
||||
curright += 4;
|
||||
}
|
||||
rgData->lsum += sum_l;
|
||||
rgData->rsum += sum_r;
|
||||
|
||||
batchsamples -= cursamples;
|
||||
cursamplepos += cursamples;
|
||||
rgData->totsamp += cursamples;
|
||||
if (rgData->totsamp == rgData->sampleWindow) { /* Get the Root Mean Square (RMS) for this set of samples */
|
||||
double const val =
|
||||
STEPS_per_dB * 10. * log10((rgData->lsum + rgData->rsum) / rgData->totsamp * 0.5 +
|
||||
1.e-37);
|
||||
size_t ival = (val <= 0) ? 0 : (size_t) val;
|
||||
if (ival >= sizeof(rgData->A) / sizeof(*(rgData->A)))
|
||||
ival = sizeof(rgData->A) / sizeof(*(rgData->A)) - 1;
|
||||
rgData->A[ival]++;
|
||||
rgData->lsum = rgData->rsum = 0.;
|
||||
memmove(rgData->loutbuf, rgData->loutbuf + rgData->totsamp,
|
||||
MAX_ORDER * sizeof(Float_t));
|
||||
memmove(rgData->routbuf, rgData->routbuf + rgData->totsamp,
|
||||
MAX_ORDER * sizeof(Float_t));
|
||||
memmove(rgData->lstepbuf, rgData->lstepbuf + rgData->totsamp,
|
||||
MAX_ORDER * sizeof(Float_t));
|
||||
memmove(rgData->rstepbuf, rgData->rstepbuf + rgData->totsamp,
|
||||
MAX_ORDER * sizeof(Float_t));
|
||||
rgData->totsamp = 0;
|
||||
}
|
||||
if (rgData->totsamp > rgData->sampleWindow) /* somehow I really screwed up: Error in programming! Contact author about totsamp > sampleWindow */
|
||||
return GAIN_ANALYSIS_ERROR;
|
||||
}
|
||||
if (num_samples < MAX_ORDER) {
|
||||
memmove(rgData->linprebuf, rgData->linprebuf + num_samples,
|
||||
(MAX_ORDER - num_samples) * sizeof(Float_t));
|
||||
memmove(rgData->rinprebuf, rgData->rinprebuf + num_samples,
|
||||
(MAX_ORDER - num_samples) * sizeof(Float_t));
|
||||
memcpy(rgData->linprebuf + MAX_ORDER - num_samples, left_samples,
|
||||
num_samples * sizeof(Float_t));
|
||||
memcpy(rgData->rinprebuf + MAX_ORDER - num_samples, right_samples,
|
||||
num_samples * sizeof(Float_t));
|
||||
}
|
||||
else {
|
||||
memcpy(rgData->linprebuf, left_samples + num_samples - MAX_ORDER,
|
||||
MAX_ORDER * sizeof(Float_t));
|
||||
memcpy(rgData->rinprebuf, right_samples + num_samples - MAX_ORDER,
|
||||
MAX_ORDER * sizeof(Float_t));
|
||||
}
|
||||
|
||||
return GAIN_ANALYSIS_OK;
|
||||
}
|
||||
|
||||
|
||||
static Float_t
|
||||
analyzeResult(uint32_t const *Array, size_t len)
|
||||
{
|
||||
uint32_t elems;
|
||||
uint32_t upper;
|
||||
uint32_t sum;
|
||||
size_t i;
|
||||
|
||||
elems = 0;
|
||||
for (i = 0; i < len; i++)
|
||||
elems += Array[i];
|
||||
if (elems == 0)
|
||||
return GAIN_NOT_ENOUGH_SAMPLES;
|
||||
|
||||
upper = (uint32_t) ceil(elems * (1. - RMS_PERCENTILE));
|
||||
sum = 0;
|
||||
for (i = len; i-- > 0;) {
|
||||
sum += Array[i];
|
||||
if (sum >= upper) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (Float_t) ((Float_t) PINK_REF - (Float_t) i / (Float_t) STEPS_per_dB);
|
||||
}
|
||||
|
||||
|
||||
Float_t
|
||||
GetTitleGain(replaygain_t * rgData)
|
||||
{
|
||||
Float_t retval;
|
||||
unsigned int i;
|
||||
|
||||
retval = analyzeResult(rgData->A, sizeof(rgData->A) / sizeof(*(rgData->A)));
|
||||
|
||||
for (i = 0; i < sizeof(rgData->A) / sizeof(*(rgData->A)); i++) {
|
||||
rgData->B[i] += rgData->A[i];
|
||||
rgData->A[i] = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_ORDER; i++)
|
||||
rgData->linprebuf[i] = rgData->lstepbuf[i]
|
||||
= rgData->loutbuf[i]
|
||||
= rgData->rinprebuf[i]
|
||||
= rgData->rstepbuf[i]
|
||||
= rgData->routbuf[i] = 0.f;
|
||||
|
||||
rgData->totsamp = 0;
|
||||
rgData->lsum = rgData->rsum = 0.;
|
||||
return retval;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static Float_t GetAlbumGain(replaygain_t const* rgData);
|
||||
|
||||
Float_t
|
||||
GetAlbumGain(replaygain_t const* rgData)
|
||||
{
|
||||
return analyzeResult(rgData->B, sizeof(rgData->B) / sizeof(*(rgData->B)));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* end of gain_analysis.c */
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* ReplayGainAnalysis - analyzes input samples and give the recommended dB change
|
||||
* Copyright (C) 2001 David Robinson and Glen Sawyer
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* concept and filter values by David Robinson (David@Robinson.org)
|
||||
* -- blame him if you think the idea is flawed
|
||||
* coding by Glen Sawyer (mp3gain@hotmail.com) 735 W 255 N, Orem, UT 84057-4505 USA
|
||||
* -- blame him if you think this runs too slowly, or the coding is otherwise flawed
|
||||
*
|
||||
* For an explanation of the concepts and the basic algorithms involved, go to:
|
||||
* http://www.replaygain.org/
|
||||
*/
|
||||
|
||||
#ifndef GAIN_ANALYSIS_H
|
||||
#define GAIN_ANALYSIS_H
|
||||
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#else
|
||||
# ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef sample_t Float_t; /* Type used for filtering */
|
||||
|
||||
|
||||
#define PINK_REF 64.82 /* 298640883795 */ /* calibration value for 89dB */
|
||||
|
||||
|
||||
#define YULE_ORDER 10
|
||||
#define BUTTER_ORDER 2
|
||||
#define YULE_FILTER filterYule
|
||||
#define BUTTER_FILTER filterButter
|
||||
#define RMS_PERCENTILE 0.95 /* percentile which is louder than the proposed level */
|
||||
#define MAX_SAMP_FREQ 48000L /* maximum allowed sample frequency [Hz] */
|
||||
#define RMS_WINDOW_TIME_NUMERATOR 1L
|
||||
#define RMS_WINDOW_TIME_DENOMINATOR 20L /* numerator / denominator = time slice size [s] */
|
||||
#define STEPS_per_dB 100 /* Table entries per dB */
|
||||
#define MAX_dB 120 /* Table entries for 0...MAX_dB (normal max. values are 70...80 dB) */
|
||||
|
||||
enum { GAIN_NOT_ENOUGH_SAMPLES = -24601, GAIN_ANALYSIS_ERROR = 0, GAIN_ANALYSIS_OK =
|
||||
1, INIT_GAIN_ANALYSIS_ERROR = 0, INIT_GAIN_ANALYSIS_OK = 1
|
||||
};
|
||||
|
||||
enum { MAX_ORDER = (BUTTER_ORDER > YULE_ORDER ? BUTTER_ORDER : YULE_ORDER)
|
||||
, MAX_SAMPLES_PER_WINDOW = ((MAX_SAMP_FREQ * RMS_WINDOW_TIME_NUMERATOR) / RMS_WINDOW_TIME_DENOMINATOR + 1) /* max. Samples per Time slice */
|
||||
};
|
||||
|
||||
struct replaygain_data {
|
||||
Float_t linprebuf[MAX_ORDER * 2];
|
||||
Float_t *linpre; /* left input samples, with pre-buffer */
|
||||
Float_t lstepbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
|
||||
Float_t *lstep; /* left "first step" (i.e. post first filter) samples */
|
||||
Float_t loutbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
|
||||
Float_t *lout; /* left "out" (i.e. post second filter) samples */
|
||||
Float_t rinprebuf[MAX_ORDER * 2];
|
||||
Float_t *rinpre; /* right input samples ... */
|
||||
Float_t rstepbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
|
||||
Float_t *rstep;
|
||||
Float_t routbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
|
||||
Float_t *rout;
|
||||
long sampleWindow; /* number of samples required to reach number of milliseconds required for RMS window */
|
||||
long totsamp;
|
||||
double lsum;
|
||||
double rsum;
|
||||
int freqindex;
|
||||
int first;
|
||||
uint32_t A[STEPS_per_dB * MAX_dB];
|
||||
uint32_t B[STEPS_per_dB * MAX_dB];
|
||||
|
||||
};
|
||||
#ifndef replaygain_data_defined
|
||||
#define replaygain_data_defined
|
||||
typedef struct replaygain_data replaygain_t;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
int InitGainAnalysis(replaygain_t * rgData, long samplefreq);
|
||||
int AnalyzeSamples(replaygain_t * rgData, const Float_t * left_samples,
|
||||
const Float_t * right_samples, size_t num_samples, int num_channels);
|
||||
Float_t GetTitleGain(replaygain_t * rgData);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* GAIN_ANALYSIS_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,64 @@
|
||||
|
||||
#ifndef LAME_ID3_H
|
||||
#define LAME_ID3_H
|
||||
|
||||
|
||||
#define CHANGED_FLAG (1U << 0)
|
||||
#define ADD_V2_FLAG (1U << 1)
|
||||
#define V1_ONLY_FLAG (1U << 2)
|
||||
#define V2_ONLY_FLAG (1U << 3)
|
||||
#define SPACE_V1_FLAG (1U << 4)
|
||||
#define PAD_V2_FLAG (1U << 5)
|
||||
|
||||
enum {
|
||||
MIMETYPE_NONE = 0,
|
||||
MIMETYPE_JPEG,
|
||||
MIMETYPE_PNG,
|
||||
MIMETYPE_GIF
|
||||
};
|
||||
|
||||
typedef struct FrameDataNode {
|
||||
struct FrameDataNode *nxt;
|
||||
uint32_t fid; /* Frame Identifier */
|
||||
char lng[4]; /* 3-character language descriptor */
|
||||
struct {
|
||||
union {
|
||||
char *l; /* ptr to Latin-1 chars */
|
||||
unsigned short *u; /* ptr to UCS-2 text */
|
||||
unsigned char *b; /* ptr to raw bytes */
|
||||
} ptr;
|
||||
size_t dim;
|
||||
int enc; /* 0:Latin-1, 1:UCS-2, 2:RAW */
|
||||
} dsc , txt;
|
||||
} FrameDataNode;
|
||||
|
||||
|
||||
typedef struct id3tag_spec {
|
||||
/* private data members */
|
||||
unsigned int flags;
|
||||
int year;
|
||||
char *title;
|
||||
char *artist;
|
||||
char *album;
|
||||
char *comment;
|
||||
int track_id3v1;
|
||||
int genre_id3v1;
|
||||
unsigned char *albumart;
|
||||
unsigned int albumart_size;
|
||||
unsigned int padding_size;
|
||||
int albumart_mimetype;
|
||||
char language[4]; /* the language of the frame's content, according to ISO-639-2 */
|
||||
FrameDataNode *v2_head, *v2_tail;
|
||||
} id3tag_spec;
|
||||
|
||||
|
||||
/* write tag into stream at current position */
|
||||
extern int id3tag_write_v2(lame_global_flags * gfp);
|
||||
extern int id3tag_write_v1(lame_global_flags * gfp);
|
||||
/*
|
||||
* NOTE: A version 2 tag will NOT be added unless one of the text fields won't
|
||||
* fit in a version 1 tag (e.g. the title string is longer than 30 characters),
|
||||
* or the "id3tag_add_v2" or "id3tag_v2_only" functions are used.
|
||||
*/
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Layer 3 side include file
|
||||
*
|
||||
* Copyright (c) 1999 Mark Taylor
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_L3SIDE_H
|
||||
#define LAME_L3SIDE_H
|
||||
|
||||
/* max scalefactor band, max(SBMAX_l, SBMAX_s*3, (SBMAX_s-3)*3+8) */
|
||||
#define SFBMAX (SBMAX_s*3)
|
||||
|
||||
/* Layer III side information. */
|
||||
typedef struct {
|
||||
int l[1 + SBMAX_l];
|
||||
int s[1 + SBMAX_s];
|
||||
int psfb21[1 + PSFB21];
|
||||
int psfb12[1 + PSFB12];
|
||||
} scalefac_struct;
|
||||
|
||||
|
||||
typedef struct {
|
||||
FLOAT l[SBMAX_l];
|
||||
FLOAT s[SBMAX_s][3];
|
||||
} III_psy_xmin;
|
||||
|
||||
typedef struct {
|
||||
III_psy_xmin thm;
|
||||
III_psy_xmin en;
|
||||
} III_psy_ratio;
|
||||
|
||||
typedef struct {
|
||||
FLOAT xr[576];
|
||||
int l3_enc[576];
|
||||
int scalefac[SFBMAX];
|
||||
FLOAT xrpow_max;
|
||||
|
||||
int part2_3_length;
|
||||
int big_values;
|
||||
int count1;
|
||||
int global_gain;
|
||||
int scalefac_compress;
|
||||
int block_type;
|
||||
int mixed_block_flag;
|
||||
int table_select[3];
|
||||
int subblock_gain[3 + 1];
|
||||
int region0_count;
|
||||
int region1_count;
|
||||
int preflag;
|
||||
int scalefac_scale;
|
||||
int count1table_select;
|
||||
|
||||
int part2_length;
|
||||
int sfb_lmax;
|
||||
int sfb_smin;
|
||||
int psy_lmax;
|
||||
int sfbmax;
|
||||
int psymax;
|
||||
int sfbdivide;
|
||||
int width[SFBMAX];
|
||||
int window[SFBMAX];
|
||||
int count1bits;
|
||||
/* added for LSF */
|
||||
const int *sfb_partition_table;
|
||||
int slen[4];
|
||||
|
||||
int max_nonzero_coeff;
|
||||
char energy_above_cutoff[SFBMAX];
|
||||
} gr_info;
|
||||
|
||||
typedef struct {
|
||||
gr_info tt[2][2];
|
||||
int main_data_begin;
|
||||
int private_bits;
|
||||
int resvDrain_pre;
|
||||
int resvDrain_post;
|
||||
int scfsi[2][4];
|
||||
} III_side_info_t;
|
||||
|
||||
#endif
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* GTK plotting routines source file
|
||||
*
|
||||
* Copyright (c) 1999 Mark Taylor
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_GTKANAL_H
|
||||
#define LAME_GTKANAL_H
|
||||
|
||||
|
||||
#define READ_AHEAD 40 /* number of frames to read ahead */
|
||||
#define MAXMPGLAG READ_AHEAD /* if the mpg123 lag becomes bigger than this
|
||||
we have to stop */
|
||||
#define NUMBACK 6 /* number of frames we can back up */
|
||||
#define NUMPINFO (NUMBACK+READ_AHEAD+1)
|
||||
|
||||
|
||||
|
||||
struct plotting_data {
|
||||
int frameNum; /* current frame number */
|
||||
int frameNum123;
|
||||
int num_samples; /* number of pcm samples read for this frame */
|
||||
double frametime; /* starting time of frame, in seconds */
|
||||
double pcmdata[2][1600];
|
||||
double pcmdata2[2][1152 + 1152 - DECDELAY];
|
||||
double xr[2][2][576];
|
||||
double mpg123xr[2][2][576];
|
||||
double ms_ratio[2];
|
||||
double ms_ener_ratio[2];
|
||||
|
||||
/* L,R, M and S values */
|
||||
double energy_save[4][BLKSIZE]; /* psymodel is one ahead */
|
||||
double energy[2][4][BLKSIZE];
|
||||
double pe[2][4];
|
||||
double thr[2][4][SBMAX_l];
|
||||
double en[2][4][SBMAX_l];
|
||||
double thr_s[2][4][3 * SBMAX_s];
|
||||
double en_s[2][4][3 * SBMAX_s];
|
||||
double ers_save[4]; /* psymodel is one ahead */
|
||||
double ers[2][4];
|
||||
|
||||
double sfb[2][2][SBMAX_l];
|
||||
double sfb_s[2][2][3 * SBMAX_s];
|
||||
double LAMEsfb[2][2][SBMAX_l];
|
||||
double LAMEsfb_s[2][2][3 * SBMAX_s];
|
||||
|
||||
int LAMEqss[2][2];
|
||||
int qss[2][2];
|
||||
int big_values[2][2];
|
||||
int sub_gain[2][2][3];
|
||||
|
||||
double xfsf[2][2][SBMAX_l];
|
||||
double xfsf_s[2][2][3 * SBMAX_s];
|
||||
|
||||
int over[2][2];
|
||||
double tot_noise[2][2];
|
||||
double max_noise[2][2];
|
||||
double over_noise[2][2];
|
||||
int over_SSD[2][2];
|
||||
int blocktype[2][2];
|
||||
int scalefac_scale[2][2];
|
||||
int preflag[2][2];
|
||||
int mpg123blocktype[2][2];
|
||||
int mixed[2][2];
|
||||
int mainbits[2][2];
|
||||
int sfbits[2][2];
|
||||
int LAMEmainbits[2][2];
|
||||
int LAMEsfbits[2][2];
|
||||
int framesize, stereo, js, ms_stereo, i_stereo, emph, bitrate, sampfreq, maindata;
|
||||
int crc, padding;
|
||||
int scfsi[2], mean_bits, resvsize;
|
||||
int totbits;
|
||||
};
|
||||
#ifndef plotting_data_defined
|
||||
#define plotting_data_defined
|
||||
typedef struct plotting_data plotting_data;
|
||||
#endif
|
||||
#if 0
|
||||
extern plotting_data *pinfo;
|
||||
#endif
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,50 @@
|
||||
#include <winver.h>
|
||||
#include "version.h"
|
||||
|
||||
#ifdef _DLL
|
||||
IDI_ICON1 ICON DISCARDABLE "logoe.ico"
|
||||
#else
|
||||
IDI_ICON1 ICON DISCARDABLE "logoe.ico"
|
||||
#endif
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION LAME_MAJOR_VERSION,LAME_MINOR_VERSION,LAME_TYPE_VERSION,LAME_PATCH_VERSION
|
||||
PRODUCTVERSION LAME_MAJOR_VERSION,LAME_MINOR_VERSION,LAME_TYPE_VERSION,LAME_PATCH_VERSION
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS VS_FF_DEBUG
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS VOS__WINDOWS32
|
||||
#ifdef _DLL
|
||||
FILETYPE VFT_DLL
|
||||
#else
|
||||
FILETYPE VFT_APP
|
||||
#endif
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904E4" // Lang=US English, CharSet=Windows Multilingual
|
||||
BEGIN
|
||||
VALUE "CompanyName", LAME_URL "\0"
|
||||
VALUE "FileDescription", "MP3 Encoder.\0"
|
||||
VALUE "FileVersion", LAME_VERSION_STRING "\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1999-2011 The L.A.M.E. Team\0"
|
||||
#ifdef _DLL
|
||||
VALUE "OriginalFilename", STR(_DLL) "\0"
|
||||
#else
|
||||
VALUE "OriginalFilename", STR(_APP) "\0"
|
||||
#endif
|
||||
VALUE "ProductName", "L.A.M.E.\0"
|
||||
VALUE "ProductVersion", LAME_VERSION_STRING "\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1252 // mandatory by convention
|
||||
END
|
||||
END
|
||||
/* End of Version info */
|
||||
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
#ifndef LAME_GLOBAL_FLAGS_H
|
||||
#define LAME_GLOBAL_FLAGS_H
|
||||
|
||||
#ifndef lame_internal_flags_defined
|
||||
#define lame_internal_flags_defined
|
||||
struct lame_internal_flags;
|
||||
typedef struct lame_internal_flags lame_internal_flags;
|
||||
#endif
|
||||
|
||||
|
||||
typedef enum short_block_e {
|
||||
short_block_not_set = -1, /* allow LAME to decide */
|
||||
short_block_allowed = 0, /* LAME may use them, even different block types for L/R */
|
||||
short_block_coupled, /* LAME may use them, but always same block types in L/R */
|
||||
short_block_dispensed, /* LAME will not use short blocks, long blocks only */
|
||||
short_block_forced /* LAME will not use long blocks, short blocks only */
|
||||
} short_block_t;
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Control Parameters set by User. These parameters are here for
|
||||
* backwards compatibility with the old, non-shared lib API.
|
||||
* Please use the lame_set_variablename() functions below
|
||||
*
|
||||
*
|
||||
***********************************************************************/
|
||||
struct lame_global_struct {
|
||||
unsigned int class_id;
|
||||
|
||||
/* input description */
|
||||
unsigned long num_samples; /* number of samples. default=2^32-1 */
|
||||
int num_channels; /* input number of channels. default=2 */
|
||||
int samplerate_in; /* input_samp_rate in Hz. default=44.1 kHz */
|
||||
int samplerate_out; /* output_samp_rate.
|
||||
default: LAME picks best value
|
||||
at least not used for MP3 decoding:
|
||||
Remember 44.1 kHz MP3s and AC97 */
|
||||
float scale; /* scale input by this amount before encoding
|
||||
at least not used for MP3 decoding */
|
||||
float scale_left; /* scale input of channel 0 (left) by this
|
||||
amount before encoding */
|
||||
float scale_right; /* scale input of channel 1 (right) by this
|
||||
amount before encoding */
|
||||
|
||||
/* general control params */
|
||||
int analysis; /* collect data for a MP3 frame analyzer? */
|
||||
int write_lame_tag; /* add Xing VBR tag? */
|
||||
int decode_only; /* use lame/mpglib to convert mp3 to wav */
|
||||
int quality; /* quality setting 0=best, 9=worst default=5 */
|
||||
MPEG_mode mode; /* see enum in lame.h
|
||||
default = LAME picks best value */
|
||||
int force_ms; /* force M/S mode. requires mode=1 */
|
||||
int free_format; /* use free format? default=0 */
|
||||
int findReplayGain; /* find the RG value? default=0 */
|
||||
int decode_on_the_fly; /* decode on the fly? default=0 */
|
||||
int write_id3tag_automatic; /* 1 (default) writes ID3 tags, 0 not */
|
||||
|
||||
int nogap_total;
|
||||
int nogap_current;
|
||||
|
||||
int substep_shaping;
|
||||
int noise_shaping;
|
||||
int subblock_gain; /* 0 = no, 1 = yes */
|
||||
int use_best_huffman; /* 0 = no. 1=outside loop 2=inside loop(slow) */
|
||||
|
||||
/*
|
||||
* set either brate>0 or compression_ratio>0, LAME will compute
|
||||
* the value of the variable not set.
|
||||
* Default is compression_ratio = 11.025
|
||||
*/
|
||||
int brate; /* bitrate */
|
||||
float compression_ratio; /* sizeof(wav file)/sizeof(mp3 file) */
|
||||
|
||||
|
||||
/* frame params */
|
||||
int copyright; /* mark as copyright. default=0 */
|
||||
int original; /* mark as original. default=1 */
|
||||
int extension; /* the MP3 'private extension' bit.
|
||||
Meaningless */
|
||||
int emphasis; /* Input PCM is emphased PCM (for
|
||||
instance from one of the rarely
|
||||
emphased CDs), it is STRONGLY not
|
||||
recommended to use this, because
|
||||
psycho does not take it into account,
|
||||
and last but not least many decoders
|
||||
don't care about these bits */
|
||||
int error_protection; /* use 2 bytes per frame for a CRC
|
||||
checksum. default=0 */
|
||||
int strict_ISO; /* enforce ISO spec as much as possible */
|
||||
|
||||
int disable_reservoir; /* use bit reservoir? */
|
||||
|
||||
/* quantization/noise shaping */
|
||||
int quant_comp;
|
||||
int quant_comp_short;
|
||||
int experimentalY;
|
||||
int experimentalZ;
|
||||
int exp_nspsytune;
|
||||
|
||||
int preset;
|
||||
|
||||
/* VBR control */
|
||||
vbr_mode VBR;
|
||||
float VBR_q_frac; /* Range [0,...,1[ */
|
||||
int VBR_q; /* Range [0,...,9] */
|
||||
int VBR_mean_bitrate_kbps;
|
||||
int VBR_min_bitrate_kbps;
|
||||
int VBR_max_bitrate_kbps;
|
||||
int VBR_hard_min; /* strictly enforce VBR_min_bitrate
|
||||
normaly, it will be violated for analog
|
||||
silence */
|
||||
|
||||
|
||||
/* resampling and filtering */
|
||||
int lowpassfreq; /* freq in Hz. 0=lame choses.
|
||||
-1=no filter */
|
||||
int highpassfreq; /* freq in Hz. 0=lame choses.
|
||||
-1=no filter */
|
||||
int lowpasswidth; /* freq width of filter, in Hz
|
||||
(default=15%) */
|
||||
int highpasswidth; /* freq width of filter, in Hz
|
||||
(default=15%) */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* psycho acoustics and other arguments which you should not change
|
||||
* unless you know what you are doing
|
||||
*/
|
||||
float maskingadjust;
|
||||
float maskingadjust_short;
|
||||
int ATHonly; /* only use ATH */
|
||||
int ATHshort; /* only use ATH for short blocks */
|
||||
int noATH; /* disable ATH */
|
||||
int ATHtype; /* select ATH formula */
|
||||
float ATHcurve; /* change ATH formula 4 shape */
|
||||
float ATH_lower_db; /* lower ATH by this many db */
|
||||
int athaa_type; /* select ATH auto-adjust scheme */
|
||||
float athaa_sensitivity; /* dB, tune active region of auto-level */
|
||||
short_block_t short_blocks;
|
||||
int useTemporal; /* use temporal masking effect */
|
||||
float interChRatio;
|
||||
float msfix; /* Naoki's adjustment of Mid/Side maskings */
|
||||
|
||||
int tune; /* 0 off, 1 on */
|
||||
float tune_value_a; /* used to pass values for debugging and stuff */
|
||||
|
||||
float attackthre; /* attack threshold for L/R/M channel */
|
||||
float attackthre_s; /* attack threshold for S channel */
|
||||
|
||||
|
||||
struct {
|
||||
void (*msgf) (const char *format, va_list ap);
|
||||
void (*debugf) (const char *format, va_list ap);
|
||||
void (*errorf) (const char *format, va_list ap);
|
||||
} report;
|
||||
|
||||
/************************************************************************/
|
||||
/* internal variables, do not set... */
|
||||
/* provided because they may be of use to calling application */
|
||||
/************************************************************************/
|
||||
|
||||
int lame_allocated_gfp; /* is this struct owned by calling
|
||||
program or lame? */
|
||||
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* more internal variables are stored in this structure: */
|
||||
/**************************************************************************/
|
||||
lame_internal_flags *internal_flags;
|
||||
|
||||
|
||||
struct {
|
||||
int mmx;
|
||||
int amd3dnow;
|
||||
int sse;
|
||||
|
||||
} asm_optimizations;
|
||||
};
|
||||
|
||||
int is_lame_global_flags_valid(const lame_global_flags * gfp);
|
||||
|
||||
#endif /* LAME_GLOBAL_FLAGS_H */
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* A collection of LAME Error Codes
|
||||
*
|
||||
* Please use the constants defined here instead of some arbitrary
|
||||
* values. Currently the values starting at -10 to avoid intersection
|
||||
* with the -1, -2, -3 and -4 used in the current code.
|
||||
*
|
||||
* May be this should be a part of the include/lame.h.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
LAME_OKAY = 0,
|
||||
LAME_NOERROR = 0,
|
||||
LAME_GENERICERROR = -1,
|
||||
LAME_NOMEM = -10,
|
||||
LAME_BADBITRATE = -11,
|
||||
LAME_BADSAMPFREQ = -12,
|
||||
LAME_INTERNALERROR = -13,
|
||||
|
||||
FRONTEND_READERROR = -80,
|
||||
FRONTEND_WRITEERROR = -81,
|
||||
FRONTEND_FILETOOLARGE = -82,
|
||||
|
||||
} lame_errorcodes_t;
|
||||
|
||||
/* end of lameerror.h */
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Machine dependent defines/includes for LAME.
|
||||
*
|
||||
* Copyright (c) 1999 A.L. Faber
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_MACHINE_H
|
||||
#define LAME_MACHINE_H
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
#else
|
||||
# ifndef HAVE_STRCHR
|
||||
# define strchr index
|
||||
# define strrchr rindex
|
||||
# endif
|
||||
char *strchr(), *strrchr();
|
||||
# ifndef HAVE_MEMCPY
|
||||
# define memcpy(d, s, n) bcopy ((s), (d), (n))
|
||||
# define memmove(d, s, n) bcopy ((s), (d), (n))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__riscos__) && defined(FPA10)
|
||||
# include "ymath.h"
|
||||
#else
|
||||
# include <math.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef HAVE_ERRNO_H
|
||||
# include <errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_FCNTL_H
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#if defined(macintosh)
|
||||
# include <types.h>
|
||||
# include <stat.h>
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#else
|
||||
# ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 3 different types of pow() functions:
|
||||
* - table lookup
|
||||
* - pow()
|
||||
* - exp() on some machines this is claimed to be faster than pow()
|
||||
*/
|
||||
|
||||
#define POW20(x) (assert(0 <= (x+Q_MAX2) && x < Q_MAX), pow20[x+Q_MAX2])
|
||||
/*#define POW20(x) pow(2.0,((double)(x)-210)*.25) */
|
||||
/*#define POW20(x) exp( ((double)(x)-210)*(.25*LOG2) ) */
|
||||
|
||||
#define IPOW20(x) (assert(0 <= x && x < Q_MAX), ipow20[x])
|
||||
/*#define IPOW20(x) exp( -((double)(x)-210)*.1875*LOG2 ) */
|
||||
/*#define IPOW20(x) pow(2.0,-((double)(x)-210)*.1875) */
|
||||
|
||||
/* in case this is used without configure */
|
||||
#ifndef inline
|
||||
# define inline
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# undef inline
|
||||
# define inline _inline
|
||||
#elif defined(__SASC) || defined(__GNUC__) || defined(__ICC) || defined(__ECC)
|
||||
/* if __GNUC__ we always want to inline, not only if the user requests it */
|
||||
# undef inline
|
||||
# define inline __inline
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning( disable : 4244 )
|
||||
/*# pragma warning( disable : 4305 ) */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* FLOAT for variables which require at least 32 bits
|
||||
* FLOAT8 for variables which require at least 64 bits
|
||||
*
|
||||
* On some machines, 64 bit will be faster than 32 bit. Also, some math
|
||||
* routines require 64 bit float, so setting FLOAT=float will result in a
|
||||
* lot of conversions.
|
||||
*/
|
||||
|
||||
#if ( defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) )
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
# include <float.h>
|
||||
# define FLOAT_MAX FLT_MAX
|
||||
#else
|
||||
# ifndef FLOAT
|
||||
typedef float FLOAT;
|
||||
# ifdef FLT_MAX
|
||||
# define FLOAT_MAX FLT_MAX
|
||||
# else
|
||||
# define FLOAT_MAX 1e37 /* approx */
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef FLOAT8
|
||||
typedef double FLOAT8;
|
||||
# ifdef DBL_MAX
|
||||
# define FLOAT8_MAX DBL_MAX
|
||||
# else
|
||||
# define FLOAT8_MAX 1e99 /* approx */
|
||||
# endif
|
||||
#else
|
||||
# ifdef FLT_MAX
|
||||
# define FLOAT8_MAX FLT_MAX
|
||||
# else
|
||||
# define FLOAT8_MAX 1e37 /* approx */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* sample_t must be floating point, at least 32 bits */
|
||||
typedef FLOAT sample_t;
|
||||
|
||||
#define dimension_of(array) (sizeof(array)/sizeof(array[0]))
|
||||
#define beyond(array) (array+dimension_of(array))
|
||||
#define compiletime_assert(expression) enum{static_assert_##FILE##_##LINE = 1/((expression)?1:0)}
|
||||
#define lame_calloc(TYPE, COUNT) ((TYPE*)calloc(COUNT, sizeof(TYPE)))
|
||||
#define multiple_of(CHUNK, COUNT) (\
|
||||
( (COUNT) < 1 || (CHUNK) < 1 || (COUNT) % (CHUNK) == 0 ) \
|
||||
? (COUNT) \
|
||||
: ((COUNT) + (CHUNK) - (COUNT) % (CHUNK)) \
|
||||
)
|
||||
|
||||
#if 1
|
||||
#define EQ(a,b) (\
|
||||
(fabs(a) > fabs(b)) \
|
||||
? (fabs((a)-(b)) <= (fabs(a) * 1e-6f)) \
|
||||
: (fabs((a)-(b)) <= (fabs(b) * 1e-6f)))
|
||||
#else
|
||||
#define EQ(a,b) (fabs((a)-(b))<1E-37)
|
||||
#endif
|
||||
|
||||
#define NEQ(a,b) (!EQ(a,b))
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# if _MSC_VER < 1400
|
||||
# define fabsf fabs
|
||||
# define powf pow
|
||||
# define log10f log10
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* end of machine.h */
|
||||
+477
@@ -0,0 +1,477 @@
|
||||
/* -*- mode: C; mode: fold -*- */
|
||||
/*
|
||||
* LAME MP3 encoding engine
|
||||
*
|
||||
* Copyright (c) 1999-2000 Mark Taylor
|
||||
* Copyright (c) 2003 Olcios
|
||||
* Copyright (c) 2008 Robert Hegemann
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* $Id: mpglib_interface.c,v 1.44 2012/02/18 13:09:00 robert Exp $ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MPGLIB
|
||||
#define hip_global_struct mpstr_tag
|
||||
#include "lame.h"
|
||||
#include "machine.h"
|
||||
#include "encoder.h"
|
||||
#include "interface.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
|
||||
|
||||
#if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
|
||||
/*
|
||||
* OBSOLETE:
|
||||
* - kept to let it link
|
||||
* - forward declaration to silence compiler
|
||||
*/
|
||||
int CDECL lame_decode_init(void);
|
||||
int CDECL lame_decode(
|
||||
unsigned char * mp3buf,
|
||||
int len,
|
||||
short pcm_l[],
|
||||
short pcm_r[] );
|
||||
int CDECL lame_decode_headers(
|
||||
unsigned char* mp3buf,
|
||||
int len,
|
||||
short pcm_l[],
|
||||
short pcm_r[],
|
||||
mp3data_struct* mp3data );
|
||||
int CDECL lame_decode1(
|
||||
unsigned char* mp3buf,
|
||||
int len,
|
||||
short pcm_l[],
|
||||
short pcm_r[] );
|
||||
int CDECL lame_decode1_headers(
|
||||
unsigned char* mp3buf,
|
||||
int len,
|
||||
short pcm_l[],
|
||||
short pcm_r[],
|
||||
mp3data_struct* mp3data );
|
||||
int CDECL lame_decode1_headersB(
|
||||
unsigned char* mp3buf,
|
||||
int len,
|
||||
short pcm_l[],
|
||||
short pcm_r[],
|
||||
mp3data_struct* mp3data,
|
||||
int *enc_delay,
|
||||
int *enc_padding );
|
||||
int CDECL lame_decode_exit(void);
|
||||
#endif
|
||||
|
||||
|
||||
static MPSTR mp;
|
||||
|
||||
int
|
||||
lame_decode_exit(void)
|
||||
{
|
||||
ExitMP3(&mp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
lame_decode_init(void)
|
||||
{
|
||||
(void) InitMP3(&mp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* copy mono samples */
|
||||
#define COPY_MONO(DST_TYPE, SRC_TYPE) \
|
||||
DST_TYPE *pcm_l = (DST_TYPE *)pcm_l_raw; \
|
||||
SRC_TYPE const *p_samples = (SRC_TYPE const *)p; \
|
||||
for (i = 0; i < processed_samples; i++) \
|
||||
*pcm_l++ = (DST_TYPE)(*p_samples++);
|
||||
|
||||
/* copy stereo samples */
|
||||
#define COPY_STEREO(DST_TYPE, SRC_TYPE) \
|
||||
DST_TYPE *pcm_l = (DST_TYPE *)pcm_l_raw, *pcm_r = (DST_TYPE *)pcm_r_raw; \
|
||||
SRC_TYPE const *p_samples = (SRC_TYPE const *)p; \
|
||||
for (i = 0; i < processed_samples; i++) { \
|
||||
*pcm_l++ = (DST_TYPE)(*p_samples++); \
|
||||
*pcm_r++ = (DST_TYPE)(*p_samples++); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* For lame_decode: return code
|
||||
* -1 error
|
||||
* 0 ok, but need more data before outputing any samples
|
||||
* n number of samples output. either 576 or 1152 depending on MP3 file.
|
||||
*/
|
||||
|
||||
static int
|
||||
decode1_headersB_clipchoice(PMPSTR pmp, unsigned char *buffer, size_t len,
|
||||
char pcm_l_raw[], char pcm_r_raw[], mp3data_struct * mp3data,
|
||||
int *enc_delay, int *enc_padding,
|
||||
char *p, size_t psize, int decoded_sample_size,
|
||||
int (*decodeMP3_ptr) (PMPSTR, unsigned char *, int, char *, int,
|
||||
int *))
|
||||
{
|
||||
static const int smpls[2][4] = {
|
||||
/* Layer I II III */
|
||||
{0, 384, 1152, 1152}, /* MPEG-1 */
|
||||
{0, 384, 1152, 576} /* MPEG-2(.5) */
|
||||
};
|
||||
|
||||
int processed_bytes;
|
||||
int processed_samples; /* processed samples per channel */
|
||||
int ret;
|
||||
int i;
|
||||
int const len_l = len < INT_MAX ? (int) len : INT_MAX;
|
||||
int const psize_l = psize < INT_MAX ? (int) psize : INT_MAX;
|
||||
|
||||
mp3data->header_parsed = 0;
|
||||
ret = (*decodeMP3_ptr) (pmp, buffer, len_l, p, psize_l, &processed_bytes);
|
||||
/* three cases:
|
||||
* 1. headers parsed, but data not complete
|
||||
* pmp->header_parsed==1
|
||||
* pmp->framesize=0
|
||||
* pmp->fsizeold=size of last frame, or 0 if this is first frame
|
||||
*
|
||||
* 2. headers, data parsed, but ancillary data not complete
|
||||
* pmp->header_parsed==1
|
||||
* pmp->framesize=size of frame
|
||||
* pmp->fsizeold=size of last frame, or 0 if this is first frame
|
||||
*
|
||||
* 3. frame fully decoded:
|
||||
* pmp->header_parsed==0
|
||||
* pmp->framesize=0
|
||||
* pmp->fsizeold=size of frame (which is now the last frame)
|
||||
*
|
||||
*/
|
||||
if (pmp->header_parsed || pmp->fsizeold > 0 || pmp->framesize > 0) {
|
||||
mp3data->header_parsed = 1;
|
||||
mp3data->stereo = pmp->fr.stereo;
|
||||
mp3data->samplerate = freqs[pmp->fr.sampling_frequency];
|
||||
mp3data->mode = pmp->fr.mode;
|
||||
mp3data->mode_ext = pmp->fr.mode_ext;
|
||||
mp3data->framesize = smpls[pmp->fr.lsf][pmp->fr.lay];
|
||||
|
||||
/* free format, we need the entire frame before we can determine
|
||||
* the bitrate. If we haven't gotten the entire frame, bitrate=0 */
|
||||
if (pmp->fsizeold > 0) /* works for free format and fixed, no overrun, temporal results are < 400.e6 */
|
||||
mp3data->bitrate = 8 * (4 + pmp->fsizeold) * mp3data->samplerate /
|
||||
(1.e3 * mp3data->framesize) + 0.5;
|
||||
else if (pmp->framesize > 0)
|
||||
mp3data->bitrate = 8 * (4 + pmp->framesize) * mp3data->samplerate /
|
||||
(1.e3 * mp3data->framesize) + 0.5;
|
||||
else
|
||||
mp3data->bitrate = tabsel_123[pmp->fr.lsf][pmp->fr.lay - 1][pmp->fr.bitrate_index];
|
||||
|
||||
|
||||
|
||||
if (pmp->num_frames > 0) {
|
||||
/* Xing VBR header found and num_frames was set */
|
||||
mp3data->totalframes = pmp->num_frames;
|
||||
mp3data->nsamp = mp3data->framesize * pmp->num_frames;
|
||||
*enc_delay = pmp->enc_delay;
|
||||
*enc_padding = pmp->enc_padding;
|
||||
}
|
||||
}
|
||||
|
||||
switch (ret) {
|
||||
case MP3_OK:
|
||||
switch (pmp->fr.stereo) {
|
||||
case 1:
|
||||
processed_samples = processed_bytes / decoded_sample_size;
|
||||
if (decoded_sample_size == sizeof(short)) {
|
||||
COPY_MONO(short, short)
|
||||
}
|
||||
else {
|
||||
COPY_MONO(sample_t, FLOAT)
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
processed_samples = (processed_bytes / decoded_sample_size) >> 1;
|
||||
if (decoded_sample_size == sizeof(short)) {
|
||||
COPY_STEREO(short, short)
|
||||
}
|
||||
else {
|
||||
COPY_STEREO(sample_t, FLOAT)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
processed_samples = -1;
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case MP3_NEED_MORE:
|
||||
processed_samples = 0;
|
||||
break;
|
||||
|
||||
case MP3_ERR:
|
||||
processed_samples = -1;
|
||||
break;
|
||||
|
||||
default:
|
||||
processed_samples = -1;
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
|
||||
/*fprintf(stderr,"ok, more, err: %i %i %i\n", MP3_OK, MP3_NEED_MORE, MP3_ERR ); */
|
||||
/*fprintf(stderr,"ret = %i out=%i\n", ret, processed_samples ); */
|
||||
return processed_samples;
|
||||
}
|
||||
|
||||
|
||||
#define OUTSIZE_CLIPPED (4096*sizeof(short))
|
||||
|
||||
int
|
||||
lame_decode1_headersB(unsigned char *buffer,
|
||||
int len,
|
||||
short pcm_l[], short pcm_r[], mp3data_struct * mp3data,
|
||||
int *enc_delay, int *enc_padding)
|
||||
{
|
||||
static char out[OUTSIZE_CLIPPED];
|
||||
|
||||
return decode1_headersB_clipchoice(&mp, buffer, len, (char *) pcm_l, (char *) pcm_r, mp3data,
|
||||
enc_delay, enc_padding, out, OUTSIZE_CLIPPED,
|
||||
sizeof(short), decodeMP3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* For lame_decode: return code
|
||||
* -1 error
|
||||
* 0 ok, but need more data before outputing any samples
|
||||
* n number of samples output. Will be at most one frame of
|
||||
* MPEG data.
|
||||
*/
|
||||
|
||||
int
|
||||
lame_decode1_headers(unsigned char *buffer,
|
||||
int len, short pcm_l[], short pcm_r[], mp3data_struct * mp3data)
|
||||
{
|
||||
int enc_delay, enc_padding;
|
||||
return lame_decode1_headersB(buffer, len, pcm_l, pcm_r, mp3data, &enc_delay, &enc_padding);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
lame_decode1(unsigned char *buffer, int len, short pcm_l[], short pcm_r[])
|
||||
{
|
||||
mp3data_struct mp3data;
|
||||
|
||||
return lame_decode1_headers(buffer, len, pcm_l, pcm_r, &mp3data);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* For lame_decode: return code
|
||||
* -1 error
|
||||
* 0 ok, but need more data before outputing any samples
|
||||
* n number of samples output. a multiple of 576 or 1152 depending on MP3 file.
|
||||
*/
|
||||
|
||||
int
|
||||
lame_decode_headers(unsigned char *buffer,
|
||||
int len, short pcm_l[], short pcm_r[], mp3data_struct * mp3data)
|
||||
{
|
||||
int ret;
|
||||
int totsize = 0; /* number of decoded samples per channel */
|
||||
|
||||
for (;;) {
|
||||
switch (ret = lame_decode1_headers(buffer, len, pcm_l + totsize, pcm_r + totsize, mp3data)) {
|
||||
case -1:
|
||||
return ret;
|
||||
case 0:
|
||||
return totsize;
|
||||
default:
|
||||
totsize += ret;
|
||||
len = 0; /* future calls to decodeMP3 are just to flush buffers */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
lame_decode(unsigned char *buffer, int len, short pcm_l[], short pcm_r[])
|
||||
{
|
||||
mp3data_struct mp3data;
|
||||
|
||||
return lame_decode_headers(buffer, len, pcm_l, pcm_r, &mp3data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
hip_t hip_decode_init(void)
|
||||
{
|
||||
hip_t hip = lame_calloc(hip_global_flags, 1);
|
||||
InitMP3(hip);
|
||||
return hip;
|
||||
}
|
||||
|
||||
|
||||
int hip_decode_exit(hip_t hip)
|
||||
{
|
||||
if (hip) {
|
||||
ExitMP3(hip);
|
||||
free(hip);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* we forbid input with more than 1152 samples per channel for output in the unclipped mode */
|
||||
#define OUTSIZE_UNCLIPPED (1152*2*sizeof(FLOAT))
|
||||
|
||||
int
|
||||
hip_decode1_unclipped(hip_t hip, unsigned char *buffer, size_t len, sample_t pcm_l[], sample_t pcm_r[])
|
||||
{
|
||||
static char out[OUTSIZE_UNCLIPPED];
|
||||
mp3data_struct mp3data;
|
||||
int enc_delay, enc_padding;
|
||||
|
||||
if (hip) {
|
||||
return decode1_headersB_clipchoice(hip, buffer, len, (char *) pcm_l, (char *) pcm_r, &mp3data,
|
||||
&enc_delay, &enc_padding, out, OUTSIZE_UNCLIPPED,
|
||||
sizeof(FLOAT), decodeMP3_unclipped);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* For hip_decode: return code
|
||||
* -1 error
|
||||
* 0 ok, but need more data before outputing any samples
|
||||
* n number of samples output. Will be at most one frame of
|
||||
* MPEG data.
|
||||
*/
|
||||
|
||||
int
|
||||
hip_decode1_headers(hip_t hip, unsigned char *buffer,
|
||||
size_t len, short pcm_l[], short pcm_r[], mp3data_struct * mp3data)
|
||||
{
|
||||
int enc_delay, enc_padding;
|
||||
return hip_decode1_headersB(hip, buffer, len, pcm_l, pcm_r, mp3data, &enc_delay, &enc_padding);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
hip_decode1(hip_t hip, unsigned char *buffer, size_t len, short pcm_l[], short pcm_r[])
|
||||
{
|
||||
mp3data_struct mp3data;
|
||||
return hip_decode1_headers(hip, buffer, len, pcm_l, pcm_r, &mp3data);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* For hip_decode: return code
|
||||
* -1 error
|
||||
* 0 ok, but need more data before outputing any samples
|
||||
* n number of samples output. a multiple of 576 or 1152 depending on MP3 file.
|
||||
*/
|
||||
|
||||
int
|
||||
hip_decode_headers(hip_t hip, unsigned char *buffer,
|
||||
size_t len, short pcm_l[], short pcm_r[], mp3data_struct * mp3data)
|
||||
{
|
||||
int ret;
|
||||
int totsize = 0; /* number of decoded samples per channel */
|
||||
|
||||
for (;;) {
|
||||
switch (ret = hip_decode1_headers(hip, buffer, len, pcm_l + totsize, pcm_r + totsize, mp3data)) {
|
||||
case -1:
|
||||
return ret;
|
||||
case 0:
|
||||
return totsize;
|
||||
default:
|
||||
totsize += ret;
|
||||
len = 0; /* future calls to decodeMP3 are just to flush buffers */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
hip_decode(hip_t hip, unsigned char *buffer, size_t len, short pcm_l[], short pcm_r[])
|
||||
{
|
||||
mp3data_struct mp3data;
|
||||
return hip_decode_headers(hip, buffer, len, pcm_l, pcm_r, &mp3data);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
hip_decode1_headersB(hip_t hip, unsigned char *buffer,
|
||||
size_t len,
|
||||
short pcm_l[], short pcm_r[], mp3data_struct * mp3data,
|
||||
int *enc_delay, int *enc_padding)
|
||||
{
|
||||
static char out[OUTSIZE_CLIPPED];
|
||||
if (hip) {
|
||||
return decode1_headersB_clipchoice(hip, buffer, len, (char *) pcm_l, (char *) pcm_r, mp3data,
|
||||
enc_delay, enc_padding, out, OUTSIZE_CLIPPED,
|
||||
sizeof(short), decodeMP3);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void hip_set_pinfo(hip_t hip, plotting_data* pinfo)
|
||||
{
|
||||
if (hip) {
|
||||
hip->pinfo = pinfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void hip_set_errorf(hip_t hip, lame_report_function func)
|
||||
{
|
||||
if (hip) {
|
||||
hip->report_err = func;
|
||||
}
|
||||
}
|
||||
|
||||
void hip_set_debugf(hip_t hip, lame_report_function func)
|
||||
{
|
||||
if (hip) {
|
||||
hip->report_dbg = func;
|
||||
}
|
||||
}
|
||||
|
||||
void hip_set_msgf (hip_t hip, lame_report_function func)
|
||||
{
|
||||
if (hip) {
|
||||
hip->report_msg = func;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* end of mpglib_interface.c */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* New Modified DCT include file
|
||||
*
|
||||
* Copyright (c) 1999 Takehiro TOMINAGA
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_NEWMDCT_H
|
||||
#define LAME_NEWMDCT_H
|
||||
|
||||
void mdct_sub48(lame_internal_flags * gfc, const sample_t * w0, const sample_t * w1);
|
||||
|
||||
#endif /* LAME_NEWMDCT_H */
|
||||
@@ -0,0 +1,404 @@
|
||||
/*
|
||||
* presets.c -- Apply presets
|
||||
*
|
||||
* Copyright (c) 2002-2008 Gabriel Bouvigne
|
||||
* Copyright (c) 2007-2012 Robert Hegemann
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "lame.h"
|
||||
#include "machine.h"
|
||||
#include "set_get.h"
|
||||
#include "encoder.h"
|
||||
#include "util.h"
|
||||
#include "lame_global_flags.h"
|
||||
|
||||
#define SET_OPTION(opt, val, def) if (enforce) \
|
||||
(void) lame_set_##opt(gfp, val); \
|
||||
else if (!(fabs(lame_get_##opt(gfp) - def) > 0)) \
|
||||
(void) lame_set_##opt(gfp, val);
|
||||
|
||||
#define SET__OPTION(opt, val, def) if (enforce) \
|
||||
lame_set_##opt(gfp, val); \
|
||||
else if (!(fabs(lame_get_##opt(gfp) - def) > 0)) \
|
||||
lame_set_##opt(gfp, val);
|
||||
|
||||
#undef Min
|
||||
#undef Max
|
||||
|
||||
static inline int
|
||||
min_int(int a, int b)
|
||||
{
|
||||
if (a < b) {
|
||||
return a;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
static inline int
|
||||
max_int(int a, int b)
|
||||
{
|
||||
if (a > b) {
|
||||
return a;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
int vbr_q;
|
||||
int quant_comp;
|
||||
int quant_comp_s;
|
||||
int expY;
|
||||
FLOAT st_lrm; /*short threshold */
|
||||
FLOAT st_s;
|
||||
FLOAT masking_adj;
|
||||
FLOAT masking_adj_short;
|
||||
FLOAT ath_lower;
|
||||
FLOAT ath_curve;
|
||||
FLOAT ath_sensitivity;
|
||||
FLOAT interch;
|
||||
int safejoint;
|
||||
int sfb21mod;
|
||||
FLOAT msfix;
|
||||
FLOAT minval;
|
||||
FLOAT ath_fixpoint;
|
||||
} vbr_presets_t;
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
|
||||
/* Switch mappings for VBR mode VBR_RH */
|
||||
static const vbr_presets_t vbr_old_switch_map[] = {
|
||||
/*vbr_q qcomp_l qcomp_s expY st_lrm st_s mask adj_l adj_s ath_lower ath_curve ath_sens interChR safejoint sfb21mod msfix */
|
||||
{0, 9, 9, 0, 5.20, 125.0, -4.2, -6.3, 4.8, 1, 0, 0, 2, 21, 0.97, 5, 100},
|
||||
{1, 9, 9, 0, 5.30, 125.0, -3.6, -5.6, 4.5, 1.5, 0, 0, 2, 21, 1.35, 5, 100},
|
||||
{2, 9, 9, 0, 5.60, 125.0, -2.2, -3.5, 2.8, 2, 0, 0, 2, 21, 1.49, 5, 100},
|
||||
{3, 9, 9, 1, 5.80, 130.0, -1.8, -2.8, 2.6, 3, -4, 0, 2, 20, 1.64, 5, 100},
|
||||
{4, 9, 9, 1, 6.00, 135.0, -0.7, -1.1, 1.1, 3.5, -8, 0, 2, 0, 1.79, 5, 100},
|
||||
{5, 9, 9, 1, 6.40, 140.0, 0.5, 0.4, -7.5, 4, -12, 0.0002, 0, 0, 1.95, 5, 100},
|
||||
{6, 9, 9, 1, 6.60, 145.0, 0.67, 0.65, -14.7, 6.5, -19, 0.0004, 0, 0, 2.30, 5, 100},
|
||||
{7, 9, 9, 1, 6.60, 145.0, 0.8, 0.75, -19.7, 8, -22, 0.0006, 0, 0, 2.70, 5, 100},
|
||||
{8, 9, 9, 1, 6.60, 145.0, 1.2, 1.15, -27.5, 10, -23, 0.0007, 0, 0, 0, 5, 100},
|
||||
{9, 9, 9, 1, 6.60, 145.0, 1.6, 1.6, -36, 11, -25, 0.0008, 0, 0, 0, 5, 100},
|
||||
{10, 9, 9, 1, 6.60, 145.0, 2.0, 2.0, -36, 12, -25, 0.0008, 0, 0, 0, 5, 100}
|
||||
};
|
||||
|
||||
static const vbr_presets_t vbr_mt_psy_switch_map[] = {
|
||||
/*vbr_q qcomp_l qcomp_s expY st_lrm st_s mask adj_l adj_s ath_lower ath_curve ath_sens --- safejoint sfb21mod msfix */
|
||||
{0, 9, 9, 0, 4.20, 25.0, -6.8, -6.8, 7.1, 1, 0, 0, 2, 31, 1.000, 5, 100},
|
||||
{1, 9, 9, 0, 4.20, 25.0, -4.8, -4.8, 5.4, 1.4, -1, 0, 2, 27, 1.122, 5, 98},
|
||||
{2, 9, 9, 0, 4.20, 25.0, -2.6, -2.6, 3.7, 2.0, -3, 0, 2, 23, 1.288, 5, 97},
|
||||
{3, 9, 9, 1, 4.20, 25.0, -1.6, -1.6, 2.0, 2.0, -5, 0, 2, 18, 1.479, 5, 96},
|
||||
{4, 9, 9, 1, 4.20, 25.0, -0.0, -0.0, 0.0, 2.0, -8, 0, 2, 12, 1.698, 5, 95},
|
||||
{5, 9, 9, 1, 4.20, 25.0, 1.3, 1.3, -6, 3.5, -11, 0, 2, 8, 1.950, 5, 94.2},
|
||||
#if 0
|
||||
{6, 9, 9, 1, 4.50, 100.0, 1.5, 1.5, -24.0, 6.0, -14, 0, 2, 4, 2.239, 3, 93.9},
|
||||
{7, 9, 9, 1, 4.80, 200.0, 1.7, 1.7, -28.0, 9.0, -20, 0, 2, 0, 2.570, 1, 93.6},
|
||||
#else
|
||||
{6, 9, 9, 1, 4.50, 100.0, 2.2, 2.3, -12.0, 6.0, -14, 0, 2, 4, 2.239, 3, 93.9},
|
||||
{7, 9, 9, 1, 4.80, 200.0, 2.7, 2.7, -18.0, 9.0, -17, 0, 2, 0, 2.570, 1, 93.6},
|
||||
#endif
|
||||
{8, 9, 9, 1, 5.30, 300.0, 2.8, 2.8, -21.0, 10.0, -23, 0.0002, 0, 0, 2.951, 0, 93.3},
|
||||
{9, 9, 9, 1, 6.60, 300.0, 2.8, 2.8, -23.0, 11.0, -25, 0.0006, 0, 0, 3.388, 0, 93.3},
|
||||
{10, 9, 9, 1, 25.00, 300.0, 2.8, 2.8, -25.0, 12.0, -27, 0.0025, 0, 0, 3.500, 0, 93.3}
|
||||
};
|
||||
|
||||
/* *INDENT-ON* */
|
||||
|
||||
static vbr_presets_t const*
|
||||
get_vbr_preset(int v)
|
||||
{
|
||||
switch (v) {
|
||||
case vbr_mtrh:
|
||||
case vbr_mt:
|
||||
return &vbr_mt_psy_switch_map[0];
|
||||
default:
|
||||
return &vbr_old_switch_map[0];
|
||||
}
|
||||
}
|
||||
|
||||
#define NOOP(m) (void)p.m
|
||||
#define LERP(m) (p.m = p.m + x * (q.m - p.m))
|
||||
|
||||
static void
|
||||
apply_vbr_preset(lame_global_flags * gfp, int a, int enforce)
|
||||
{
|
||||
vbr_presets_t const *vbr_preset = get_vbr_preset(lame_get_VBR(gfp));
|
||||
float x = gfp->VBR_q_frac;
|
||||
vbr_presets_t p = vbr_preset[a];
|
||||
vbr_presets_t q = vbr_preset[a + 1];
|
||||
vbr_presets_t const *set = &p;
|
||||
|
||||
NOOP(vbr_q);
|
||||
NOOP(quant_comp);
|
||||
NOOP(quant_comp_s);
|
||||
NOOP(expY);
|
||||
LERP(st_lrm);
|
||||
LERP(st_s);
|
||||
LERP(masking_adj);
|
||||
LERP(masking_adj_short);
|
||||
LERP(ath_lower);
|
||||
LERP(ath_curve);
|
||||
LERP(ath_sensitivity);
|
||||
LERP(interch);
|
||||
NOOP(safejoint);
|
||||
LERP(sfb21mod);
|
||||
LERP(msfix);
|
||||
LERP(minval);
|
||||
LERP(ath_fixpoint);
|
||||
|
||||
(void) lame_set_VBR_q(gfp, set->vbr_q);
|
||||
SET_OPTION(quant_comp, set->quant_comp, -1);
|
||||
SET_OPTION(quant_comp_short, set->quant_comp_s, -1);
|
||||
if (set->expY) {
|
||||
(void) lame_set_experimentalY(gfp, set->expY);
|
||||
}
|
||||
SET_OPTION(short_threshold_lrm, set->st_lrm, -1);
|
||||
SET_OPTION(short_threshold_s, set->st_s, -1);
|
||||
SET_OPTION(maskingadjust, set->masking_adj, 0);
|
||||
SET_OPTION(maskingadjust_short, set->masking_adj_short, 0);
|
||||
if (lame_get_VBR(gfp) == vbr_mt || lame_get_VBR(gfp) == vbr_mtrh) {
|
||||
lame_set_ATHtype(gfp, 5);
|
||||
}
|
||||
SET_OPTION(ATHlower, set->ath_lower, 0);
|
||||
SET_OPTION(ATHcurve, set->ath_curve, -1);
|
||||
SET_OPTION(athaa_sensitivity, set->ath_sensitivity, 0);
|
||||
if (set->interch > 0) {
|
||||
SET_OPTION(interChRatio, set->interch, -1);
|
||||
}
|
||||
|
||||
/* parameters for which there is no proper set/get interface */
|
||||
if (set->safejoint > 0) {
|
||||
(void) lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 2);
|
||||
}
|
||||
if (set->sfb21mod > 0) {
|
||||
int const nsp = lame_get_exp_nspsytune(gfp);
|
||||
int const val = (nsp >> 20) & 63;
|
||||
if (val == 0) {
|
||||
int const sf21mod = (set->sfb21mod << 20) | nsp;
|
||||
(void) lame_set_exp_nspsytune(gfp, sf21mod);
|
||||
}
|
||||
}
|
||||
SET__OPTION(msfix, set->msfix, -1);
|
||||
|
||||
if (enforce == 0) {
|
||||
gfp->VBR_q = a;
|
||||
gfp->VBR_q_frac = x;
|
||||
}
|
||||
gfp->internal_flags->cfg.minval = set->minval;
|
||||
{ /* take care of gain adjustments */
|
||||
double const x = fabs(gfp->scale);
|
||||
double const y = (x > 0.f) ? (10.f * log10(x)) : 0.f;
|
||||
gfp->internal_flags->cfg.ATHfixpoint = set->ath_fixpoint - y;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
apply_abr_preset(lame_global_flags * gfp, int preset, int enforce)
|
||||
{
|
||||
typedef struct {
|
||||
int abr_kbps;
|
||||
int quant_comp;
|
||||
int quant_comp_s;
|
||||
int safejoint;
|
||||
FLOAT nsmsfix;
|
||||
FLOAT st_lrm; /*short threshold */
|
||||
FLOAT st_s;
|
||||
FLOAT scale;
|
||||
FLOAT masking_adj;
|
||||
FLOAT ath_lower;
|
||||
FLOAT ath_curve;
|
||||
FLOAT interch;
|
||||
int sfscale;
|
||||
} abr_presets_t;
|
||||
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
|
||||
/*
|
||||
* Switch mappings for ABR mode
|
||||
*/
|
||||
const abr_presets_t abr_switch_map[] = {
|
||||
/* kbps quant q_s safejoint nsmsfix st_lrm st_s scale msk ath_lwr ath_curve interch , sfscale */
|
||||
{ 8, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -30.0, 11, 0.0012, 1}, /* 8, impossible to use in stereo */
|
||||
{ 16, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -25.0, 11, 0.0010, 1}, /* 16 */
|
||||
{ 24, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -20.0, 11, 0.0010, 1}, /* 24 */
|
||||
{ 32, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -15.0, 11, 0.0010, 1}, /* 32 */
|
||||
{ 40, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -10.0, 11, 0.0009, 1}, /* 40 */
|
||||
{ 48, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -10.0, 11, 0.0009, 1}, /* 48 */
|
||||
{ 56, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -6.0, 11, 0.0008, 1}, /* 56 */
|
||||
{ 64, 9, 9, 0, 0, 6.60, 145, 0.95, 0, -2.0, 11, 0.0008, 1}, /* 64 */
|
||||
{ 80, 9, 9, 0, 0, 6.60, 145, 0.95, 0, .0, 8, 0.0007, 1}, /* 80 */
|
||||
{ 96, 9, 9, 0, 2.50, 6.60, 145, 0.95, 0, 1.0, 5.5, 0.0006, 1}, /* 96 */
|
||||
{112, 9, 9, 0, 2.25, 6.60, 145, 0.95, 0, 2.0, 4.5, 0.0005, 1}, /* 112 */
|
||||
{128, 9, 9, 0, 1.95, 6.40, 140, 0.95, 0, 3.0, 4, 0.0002, 1}, /* 128 */
|
||||
{160, 9, 9, 1, 1.79, 6.00, 135, 0.95, -2, 5.0, 3.5, 0, 1}, /* 160 */
|
||||
{192, 9, 9, 1, 1.49, 5.60, 125, 0.97, -4, 7.0, 3, 0, 0}, /* 192 */
|
||||
{224, 9, 9, 1, 1.25, 5.20, 125, 0.98, -6, 9.0, 2, 0, 0}, /* 224 */
|
||||
{256, 9, 9, 1, 0.97, 5.20, 125, 1.00, -8, 10.0, 1, 0, 0}, /* 256 */
|
||||
{320, 9, 9, 1, 0.90, 5.20, 125, 1.00, -10, 12.0, 0, 0, 0} /* 320 */
|
||||
};
|
||||
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* Variables for the ABR stuff */
|
||||
int r;
|
||||
int actual_bitrate = preset;
|
||||
|
||||
r = nearestBitrateFullIndex(preset);
|
||||
|
||||
(void) lame_set_VBR(gfp, vbr_abr);
|
||||
(void) lame_set_VBR_mean_bitrate_kbps(gfp, (actual_bitrate));
|
||||
(void) lame_set_VBR_mean_bitrate_kbps(gfp, min_int(lame_get_VBR_mean_bitrate_kbps(gfp), 320));
|
||||
(void) lame_set_VBR_mean_bitrate_kbps(gfp, max_int(lame_get_VBR_mean_bitrate_kbps(gfp), 8));
|
||||
(void) lame_set_brate(gfp, lame_get_VBR_mean_bitrate_kbps(gfp));
|
||||
|
||||
|
||||
/* parameters for which there is no proper set/get interface */
|
||||
if (abr_switch_map[r].safejoint > 0)
|
||||
(void) lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 2); /* safejoint */
|
||||
|
||||
if (abr_switch_map[r].sfscale > 0)
|
||||
(void) lame_set_sfscale(gfp, 1);
|
||||
|
||||
|
||||
SET_OPTION(quant_comp, abr_switch_map[r].quant_comp, -1);
|
||||
SET_OPTION(quant_comp_short, abr_switch_map[r].quant_comp_s, -1);
|
||||
|
||||
SET__OPTION(msfix, abr_switch_map[r].nsmsfix, -1);
|
||||
|
||||
SET_OPTION(short_threshold_lrm, abr_switch_map[r].st_lrm, -1);
|
||||
SET_OPTION(short_threshold_s, abr_switch_map[r].st_s, -1);
|
||||
|
||||
/* ABR seems to have big problems with clipping, especially at low bitrates */
|
||||
/* so we compensate for that here by using a scale value depending on bitrate */
|
||||
lame_set_scale(gfp, lame_get_scale(gfp) * abr_switch_map[r].scale);
|
||||
|
||||
SET_OPTION(maskingadjust, abr_switch_map[r].masking_adj, 0);
|
||||
if (abr_switch_map[r].masking_adj > 0) {
|
||||
SET_OPTION(maskingadjust_short, abr_switch_map[r].masking_adj * .9, 0);
|
||||
}
|
||||
else {
|
||||
SET_OPTION(maskingadjust_short, abr_switch_map[r].masking_adj * 1.1, 0);
|
||||
}
|
||||
|
||||
|
||||
SET_OPTION(ATHlower, abr_switch_map[r].ath_lower, 0);
|
||||
SET_OPTION(ATHcurve, abr_switch_map[r].ath_curve, -1);
|
||||
|
||||
SET_OPTION(interChRatio, abr_switch_map[r].interch, -1);
|
||||
|
||||
(void) abr_switch_map[r].abr_kbps;
|
||||
|
||||
gfp->internal_flags->cfg.minval = 5. * (abr_switch_map[r].abr_kbps / 320.);
|
||||
|
||||
return preset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
apply_preset(lame_global_flags * gfp, int preset, int enforce)
|
||||
{
|
||||
/*translate legacy presets */
|
||||
switch (preset) {
|
||||
case R3MIX:
|
||||
{
|
||||
preset = V3;
|
||||
(void) lame_set_VBR(gfp, vbr_mtrh);
|
||||
break;
|
||||
}
|
||||
case MEDIUM:
|
||||
case MEDIUM_FAST:
|
||||
{
|
||||
preset = V4;
|
||||
(void) lame_set_VBR(gfp, vbr_mtrh);
|
||||
break;
|
||||
}
|
||||
case STANDARD:
|
||||
case STANDARD_FAST:
|
||||
{
|
||||
preset = V2;
|
||||
(void) lame_set_VBR(gfp, vbr_mtrh);
|
||||
break;
|
||||
}
|
||||
case EXTREME:
|
||||
case EXTREME_FAST:
|
||||
{
|
||||
preset = V0;
|
||||
(void) lame_set_VBR(gfp, vbr_mtrh);
|
||||
break;
|
||||
}
|
||||
case INSANE:
|
||||
{
|
||||
preset = 320;
|
||||
gfp->preset = preset;
|
||||
(void) apply_abr_preset(gfp, preset, enforce);
|
||||
lame_set_VBR(gfp, vbr_off);
|
||||
return preset;
|
||||
}
|
||||
}
|
||||
|
||||
gfp->preset = preset;
|
||||
{
|
||||
switch (preset) {
|
||||
case V9:
|
||||
apply_vbr_preset(gfp, 9, enforce);
|
||||
return preset;
|
||||
case V8:
|
||||
apply_vbr_preset(gfp, 8, enforce);
|
||||
return preset;
|
||||
case V7:
|
||||
apply_vbr_preset(gfp, 7, enforce);
|
||||
return preset;
|
||||
case V6:
|
||||
apply_vbr_preset(gfp, 6, enforce);
|
||||
return preset;
|
||||
case V5:
|
||||
apply_vbr_preset(gfp, 5, enforce);
|
||||
return preset;
|
||||
case V4:
|
||||
apply_vbr_preset(gfp, 4, enforce);
|
||||
return preset;
|
||||
case V3:
|
||||
apply_vbr_preset(gfp, 3, enforce);
|
||||
return preset;
|
||||
case V2:
|
||||
apply_vbr_preset(gfp, 2, enforce);
|
||||
return preset;
|
||||
case V1:
|
||||
apply_vbr_preset(gfp, 1, enforce);
|
||||
return preset;
|
||||
case V0:
|
||||
apply_vbr_preset(gfp, 0, enforce);
|
||||
return preset;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (8 <= preset && preset <= 320) {
|
||||
return apply_abr_preset(gfp, preset, enforce);
|
||||
}
|
||||
|
||||
gfp->preset = 0; /*no corresponding preset found */
|
||||
return preset;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* psymodel.h
|
||||
*
|
||||
* Copyright (c) 1999 Mark Taylor
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_PSYMODEL_H
|
||||
#define LAME_PSYMODEL_H
|
||||
|
||||
|
||||
int L3psycho_anal_ns(lame_internal_flags * gfc,
|
||||
const sample_t *const buffer[2], int gr,
|
||||
III_psy_ratio ratio[2][2],
|
||||
III_psy_ratio MS_ratio[2][2],
|
||||
FLOAT pe[2], FLOAT pe_MS[2], FLOAT ener[2], int blocktype_d[2]);
|
||||
|
||||
int L3psycho_anal_vbr(lame_internal_flags * gfc,
|
||||
const sample_t *const buffer[2], int gr,
|
||||
III_psy_ratio ratio[2][2],
|
||||
III_psy_ratio MS_ratio[2][2],
|
||||
FLOAT pe[2], FLOAT pe_MS[2], FLOAT ener[2], int blocktype_d[2]);
|
||||
|
||||
|
||||
int psymodel_init(lame_global_flags const* gfp);
|
||||
|
||||
|
||||
#define rpelev 2
|
||||
#define rpelev2 16
|
||||
#define rpelev_s 2
|
||||
#define rpelev2_s 16
|
||||
|
||||
/* size of each partition band, in barks: */
|
||||
#define DELBARK .34
|
||||
|
||||
|
||||
/* tuned for output level (sensitive to energy scale) */
|
||||
#define VO_SCALE (1./( 14752*14752 )/(BLKSIZE/2))
|
||||
|
||||
#define temporalmask_sustain_sec 0.01
|
||||
|
||||
#define NS_PREECHO_ATT0 0.8
|
||||
#define NS_PREECHO_ATT1 0.6
|
||||
#define NS_PREECHO_ATT2 0.3
|
||||
|
||||
#define NS_MSFIX 3.5
|
||||
#define NSATTACKTHRE 4.4
|
||||
#define NSATTACKTHRE_S 25
|
||||
|
||||
#endif /* LAME_PSYMODEL_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* MP3 quantization
|
||||
*
|
||||
* Copyright (c) 1999 Mark Taylor
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_QUANTIZE_H
|
||||
#define LAME_QUANTIZE_H
|
||||
|
||||
void CBR_iteration_loop(lame_internal_flags * gfc, const FLOAT pe[2][2],
|
||||
const FLOAT ms_ratio[2], const III_psy_ratio ratio[2][2]);
|
||||
|
||||
void VBR_old_iteration_loop(lame_internal_flags * gfc, const FLOAT pe[2][2],
|
||||
const FLOAT ms_ratio[2], const III_psy_ratio ratio[2][2]);
|
||||
|
||||
void VBR_new_iteration_loop(lame_internal_flags * gfc, const FLOAT pe[2][2],
|
||||
const FLOAT ms_ratio[2], const III_psy_ratio ratio[2][2]);
|
||||
|
||||
void ABR_iteration_loop(lame_internal_flags * gfc, const FLOAT pe[2][2],
|
||||
const FLOAT ms_ratio[2], const III_psy_ratio ratio[2][2]);
|
||||
|
||||
|
||||
#endif /* LAME_QUANTIZE_H */
|
||||
+1074
File diff suppressed because it is too large
Load Diff
+128
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* quantize_pvt include file
|
||||
*
|
||||
* Copyright (c) 1999 Takehiro TOMINAGA
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_QUANTIZE_PVT_H
|
||||
#define LAME_QUANTIZE_PVT_H
|
||||
|
||||
#define IXMAX_VAL 8206 /* ix always <= 8191+15. see count_bits() */
|
||||
|
||||
/* buggy Winamp decoder cannot handle values > 8191 */
|
||||
/* #define IXMAX_VAL 8191 */
|
||||
|
||||
#define PRECALC_SIZE (IXMAX_VAL+2)
|
||||
|
||||
|
||||
extern const int nr_of_sfb_block[6][3][4];
|
||||
extern const int pretab[SBMAX_l];
|
||||
extern const int slen1_tab[16];
|
||||
extern const int slen2_tab[16];
|
||||
|
||||
extern const scalefac_struct sfBandIndex[9];
|
||||
|
||||
extern FLOAT pow43[PRECALC_SIZE];
|
||||
#ifdef TAKEHIRO_IEEE754_HACK
|
||||
extern FLOAT adj43asm[PRECALC_SIZE];
|
||||
#else
|
||||
extern FLOAT adj43[PRECALC_SIZE];
|
||||
#endif
|
||||
|
||||
#define Q_MAX (256+1)
|
||||
#define Q_MAX2 116 /* minimum possible number of
|
||||
-cod_info->global_gain
|
||||
+ ((scalefac[] + (cod_info->preflag ? pretab[sfb] : 0))
|
||||
<< (cod_info->scalefac_scale + 1))
|
||||
+ cod_info->subblock_gain[cod_info->window[sfb]] * 8;
|
||||
|
||||
for long block, 0+((15+3)<<2) = 18*4 = 72
|
||||
for short block, 0+(15<<2)+7*8 = 15*4+56 = 116
|
||||
*/
|
||||
|
||||
extern FLOAT pow20[Q_MAX + Q_MAX2 + 1];
|
||||
extern FLOAT ipow20[Q_MAX];
|
||||
|
||||
typedef struct calc_noise_result_t {
|
||||
FLOAT over_noise; /* sum of quantization noise > masking */
|
||||
FLOAT tot_noise; /* sum of all quantization noise */
|
||||
FLOAT max_noise; /* max quantization noise */
|
||||
int over_count; /* number of quantization noise > masking */
|
||||
int over_SSD; /* SSD-like cost of distorted bands */
|
||||
int bits;
|
||||
} calc_noise_result;
|
||||
|
||||
|
||||
/**
|
||||
* allows re-use of previously
|
||||
* computed noise values
|
||||
*/
|
||||
typedef struct calc_noise_data_t {
|
||||
int global_gain;
|
||||
int sfb_count1;
|
||||
int step[39];
|
||||
FLOAT noise[39];
|
||||
FLOAT noise_log[39];
|
||||
} calc_noise_data;
|
||||
|
||||
|
||||
int on_pe(lame_internal_flags * gfc, const FLOAT pe[2][2],
|
||||
int targ_bits[2], int mean_bits, int gr, int cbr);
|
||||
|
||||
void reduce_side(int targ_bits[2], FLOAT ms_ener_ratio, int mean_bits, int max_bits);
|
||||
|
||||
|
||||
void iteration_init(lame_internal_flags * gfc);
|
||||
|
||||
|
||||
int calc_xmin(lame_internal_flags const *gfc,
|
||||
III_psy_ratio const *const ratio, gr_info * const cod_info, FLOAT * l3_xmin);
|
||||
|
||||
int calc_noise(const gr_info * const cod_info,
|
||||
const FLOAT * l3_xmin,
|
||||
FLOAT * distort, calc_noise_result * const res, calc_noise_data * prev_noise);
|
||||
|
||||
void set_frame_pinfo(lame_internal_flags * gfc, const III_psy_ratio ratio[2][2]);
|
||||
|
||||
|
||||
|
||||
|
||||
/* takehiro.c */
|
||||
|
||||
int count_bits(lame_internal_flags const *const gfc, const FLOAT * const xr,
|
||||
gr_info * const cod_info, calc_noise_data * prev_noise);
|
||||
int noquant_count_bits(lame_internal_flags const *const gfc,
|
||||
gr_info * const cod_info, calc_noise_data * prev_noise);
|
||||
|
||||
|
||||
void best_huffman_divide(const lame_internal_flags * const gfc, gr_info * const cod_info);
|
||||
|
||||
void best_scalefac_store(const lame_internal_flags * gfc, const int gr, const int ch,
|
||||
III_side_info_t * const l3_side);
|
||||
|
||||
int scale_bitcount(const lame_internal_flags * gfc, gr_info * cod_info);
|
||||
|
||||
void huffman_init(lame_internal_flags * const gfc);
|
||||
|
||||
void init_xrpow_core_init(lame_internal_flags * const gfc);
|
||||
|
||||
FLOAT athAdjust(FLOAT a, FLOAT x, FLOAT athFloor, float ATHfixpoint);
|
||||
|
||||
#define LARGE_BITS 100000
|
||||
|
||||
#endif /* LAME_QUANTIZE_PVT_H */
|
||||
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
* bit reservoir source file
|
||||
*
|
||||
* Copyright (c) 1999-2000 Mark Taylor
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* $Id: reservoir.c,v 1.45 2011/05/07 16:05:17 rbrito Exp $ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "lame.h"
|
||||
#include "machine.h"
|
||||
#include "encoder.h"
|
||||
#include "util.h"
|
||||
#include "reservoir.h"
|
||||
|
||||
#include "bitstream.h"
|
||||
#include "lame-analysis.h"
|
||||
#include "lame_global_flags.h"
|
||||
|
||||
|
||||
/*
|
||||
ResvFrameBegin:
|
||||
Called (repeatedly) at the beginning of a frame. Updates the maximum
|
||||
size of the reservoir, and checks to make sure main_data_begin
|
||||
was set properly by the formatter
|
||||
*/
|
||||
|
||||
/*
|
||||
* Background information:
|
||||
*
|
||||
* This is the original text from the ISO standard. Because of
|
||||
* sooo many bugs and irritations correcting comments are added
|
||||
* in brackets []. A '^W' means you should remove the last word.
|
||||
*
|
||||
* 1) The following rule can be used to calculate the maximum
|
||||
* number of bits used for one granule [^W frame]:
|
||||
* At the highest possible bitrate of Layer III (320 kbps
|
||||
* per stereo signal [^W^W^W], 48 kHz) the frames must be of
|
||||
* [^W^W^W are designed to have] constant length, i.e.
|
||||
* one buffer [^W^W the frame] length is:
|
||||
*
|
||||
* 320 kbps * 1152/48 kHz = 7680 bit = 960 byte
|
||||
*
|
||||
* This value is used as the maximum buffer per channel [^W^W] at
|
||||
* lower bitrates [than 320 kbps]. At 64 kbps mono or 128 kbps
|
||||
* stereo the main granule length is 64 kbps * 576/48 kHz = 768 bit
|
||||
* [per granule and channel] at 48 kHz sampling frequency.
|
||||
* This means that there is a maximum deviation (short time buffer
|
||||
* [= reservoir]) of 7680 - 2*2*768 = 4608 bits is allowed at 64 kbps.
|
||||
* The actual deviation is equal to the number of bytes [with the
|
||||
* meaning of octets] denoted by the main_data_end offset pointer.
|
||||
* The actual maximum deviation is (2^9-1)*8 bit = 4088 bits
|
||||
* [for MPEG-1 and (2^8-1)*8 bit for MPEG-2, both are hard limits].
|
||||
* ... The xchange of buffer bits between the left and right channel
|
||||
* is allowed without restrictions [exception: dual channel].
|
||||
* Because of the [constructed] constraint on the buffer size
|
||||
* main_data_end is always set to 0 in the case of bit_rate_index==14,
|
||||
* i.e. data rate 320 kbps per stereo signal [^W^W^W]. In this case
|
||||
* all data are allocated between adjacent header [^W sync] words
|
||||
* [, i.e. there is no buffering at all].
|
||||
*/
|
||||
|
||||
int
|
||||
ResvFrameBegin(lame_internal_flags * gfc, int *mean_bits)
|
||||
{
|
||||
SessionConfig_t const *const cfg = &gfc->cfg;
|
||||
EncStateVar_t *const esv = &gfc->sv_enc;
|
||||
int fullFrameBits;
|
||||
int resvLimit;
|
||||
int maxmp3buf;
|
||||
III_side_info_t *const l3_side = &gfc->l3_side;
|
||||
int frameLength;
|
||||
int meanBits;
|
||||
|
||||
frameLength = getframebits(gfc);
|
||||
meanBits = (frameLength - cfg->sideinfo_len * 8) / cfg->mode_gr;
|
||||
|
||||
/*
|
||||
* Meaning of the variables:
|
||||
* resvLimit: (0, 8, ..., 8*255 (MPEG-2), 8*511 (MPEG-1))
|
||||
* Number of bits can be stored in previous frame(s) due to
|
||||
* counter size constaints
|
||||
* maxmp3buf: ( ??? ... 8*1951 (MPEG-1 and 2), 8*2047 (MPEG-2.5))
|
||||
* Number of bits allowed to encode one frame (you can take 8*511 bit
|
||||
* from the bit reservoir and at most 8*1440 bit from the current
|
||||
* frame (320 kbps, 32 kHz), so 8*1951 bit is the largest possible
|
||||
* value for MPEG-1 and -2)
|
||||
*
|
||||
* maximum allowed granule/channel size times 4 = 8*2047 bits.,
|
||||
* so this is the absolute maximum supported by the format.
|
||||
*
|
||||
*
|
||||
* fullFrameBits: maximum number of bits available for encoding
|
||||
* the current frame.
|
||||
*
|
||||
* mean_bits: target number of bits per granule.
|
||||
*
|
||||
* frameLength:
|
||||
*
|
||||
* gfc->ResvMax: maximum allowed reservoir
|
||||
*
|
||||
* gfc->ResvSize: current reservoir size
|
||||
*
|
||||
* l3_side->resvDrain_pre:
|
||||
* ancillary data to be added to previous frame:
|
||||
* (only usefull in VBR modes if it is possible to have
|
||||
* maxmp3buf < fullFrameBits)). Currently disabled,
|
||||
* see #define NEW_DRAIN
|
||||
* 2010-02-13: RH now enabled, it seems to be needed for CBR too,
|
||||
* as there exists one example, where the FhG decoder
|
||||
* can't decode a -b320 CBR file anymore.
|
||||
*
|
||||
* l3_side->resvDrain_post:
|
||||
* ancillary data to be added to this frame:
|
||||
*
|
||||
*/
|
||||
|
||||
/* main_data_begin has 9 bits in MPEG-1, 8 bits MPEG-2 */
|
||||
resvLimit = (8 * 256) * cfg->mode_gr - 8;
|
||||
|
||||
/* maximum allowed frame size. dont use more than this number of
|
||||
bits, even if the frame has the space for them: */
|
||||
maxmp3buf = cfg->buffer_constraint;
|
||||
esv->ResvMax = maxmp3buf - frameLength;
|
||||
if (esv->ResvMax > resvLimit)
|
||||
esv->ResvMax = resvLimit;
|
||||
if (esv->ResvMax < 0 || cfg->disable_reservoir)
|
||||
esv->ResvMax = 0;
|
||||
|
||||
fullFrameBits = meanBits * cfg->mode_gr + Min(esv->ResvSize, esv->ResvMax);
|
||||
|
||||
if (fullFrameBits > maxmp3buf)
|
||||
fullFrameBits = maxmp3buf;
|
||||
|
||||
assert(0 == esv->ResvMax % 8);
|
||||
assert(esv->ResvMax >= 0);
|
||||
|
||||
l3_side->resvDrain_pre = 0;
|
||||
|
||||
if (gfc->pinfo != NULL) {
|
||||
gfc->pinfo->mean_bits = meanBits / 2; /* expected bits per channel per granule [is this also right for mono/stereo, MPEG-1/2 ?] */
|
||||
gfc->pinfo->resvsize = esv->ResvSize;
|
||||
}
|
||||
*mean_bits = meanBits;
|
||||
return fullFrameBits;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
ResvMaxBits
|
||||
returns targ_bits: target number of bits to use for 1 granule
|
||||
extra_bits: amount extra available from reservoir
|
||||
Mark Taylor 4/99
|
||||
*/
|
||||
void
|
||||
ResvMaxBits(lame_internal_flags * gfc, int mean_bits, int *targ_bits, int *extra_bits, int cbr)
|
||||
{
|
||||
SessionConfig_t const *const cfg = &gfc->cfg;
|
||||
EncStateVar_t *const esv = &gfc->sv_enc;
|
||||
int add_bits, targBits, extraBits;
|
||||
int ResvSize = esv->ResvSize, ResvMax = esv->ResvMax;
|
||||
|
||||
/* conpensate the saved bits used in the 1st granule */
|
||||
if (cbr)
|
||||
ResvSize += mean_bits;
|
||||
|
||||
if (gfc->sv_qnt.substep_shaping & 1)
|
||||
ResvMax *= 0.9;
|
||||
|
||||
targBits = mean_bits;
|
||||
|
||||
/* extra bits if the reservoir is almost full */
|
||||
if (ResvSize * 10 > ResvMax * 9) {
|
||||
add_bits = ResvSize - (ResvMax * 9) / 10;
|
||||
targBits += add_bits;
|
||||
gfc->sv_qnt.substep_shaping |= 0x80;
|
||||
}
|
||||
else {
|
||||
add_bits = 0;
|
||||
gfc->sv_qnt.substep_shaping &= 0x7f;
|
||||
/* build up reservoir. this builds the reservoir a little slower
|
||||
* than FhG. It could simple be mean_bits/15, but this was rigged
|
||||
* to always produce 100 (the old value) at 128kbs */
|
||||
/* *targ_bits -= (int) (mean_bits/15.2); */
|
||||
if (!cfg->disable_reservoir && !(gfc->sv_qnt.substep_shaping & 1))
|
||||
targBits -= .1 * mean_bits;
|
||||
}
|
||||
|
||||
|
||||
/* amount from the reservoir we are allowed to use. ISO says 6/10 */
|
||||
extraBits = (ResvSize < (esv->ResvMax * 6) / 10 ? ResvSize : (esv->ResvMax * 6) / 10);
|
||||
extraBits -= add_bits;
|
||||
|
||||
if (extraBits < 0)
|
||||
extraBits = 0;
|
||||
|
||||
*targ_bits = targBits;
|
||||
*extra_bits = extraBits;
|
||||
}
|
||||
|
||||
/*
|
||||
ResvAdjust:
|
||||
Called after a granule's bit allocation. Readjusts the size of
|
||||
the reservoir to reflect the granule's usage.
|
||||
*/
|
||||
void
|
||||
ResvAdjust(lame_internal_flags * gfc, gr_info const *gi)
|
||||
{
|
||||
gfc->sv_enc.ResvSize -= gi->part2_3_length + gi->part2_length;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
ResvFrameEnd:
|
||||
Called after all granules in a frame have been allocated. Makes sure
|
||||
that the reservoir size is within limits, possibly by adding stuffing
|
||||
bits.
|
||||
*/
|
||||
void
|
||||
ResvFrameEnd(lame_internal_flags * gfc, int mean_bits)
|
||||
{
|
||||
SessionConfig_t const *const cfg = &gfc->cfg;
|
||||
EncStateVar_t *const esv = &gfc->sv_enc;
|
||||
III_side_info_t *const l3_side = &gfc->l3_side;
|
||||
int stuffingBits;
|
||||
int over_bits;
|
||||
|
||||
esv->ResvSize += mean_bits * cfg->mode_gr;
|
||||
stuffingBits = 0;
|
||||
l3_side->resvDrain_post = 0;
|
||||
l3_side->resvDrain_pre = 0;
|
||||
|
||||
/* we must be byte aligned */
|
||||
if ((over_bits = esv->ResvSize % 8) != 0)
|
||||
stuffingBits += over_bits;
|
||||
|
||||
|
||||
over_bits = (esv->ResvSize - stuffingBits) - esv->ResvMax;
|
||||
if (over_bits > 0) {
|
||||
assert(0 == over_bits % 8);
|
||||
assert(over_bits >= 0);
|
||||
stuffingBits += over_bits;
|
||||
}
|
||||
|
||||
|
||||
/* NOTE: enabling the NEW_DRAIN code fixes some problems with FhG decoder
|
||||
shipped with MS Windows operating systems. Using this, it is even
|
||||
possible to use Gabriel's lax buffer consideration again, which
|
||||
assumes, any decoder should have a buffer large enough
|
||||
for a 320 kbps frame at 32 kHz sample rate.
|
||||
|
||||
old drain code:
|
||||
lame -b320 BlackBird.wav ---> does not play with GraphEdit.exe using FhG decoder V1.5 Build 50
|
||||
|
||||
new drain code:
|
||||
lame -b320 BlackBird.wav ---> plays fine with GraphEdit.exe using FhG decoder V1.5 Build 50
|
||||
|
||||
Robert Hegemann, 2010-02-13.
|
||||
*/
|
||||
/* drain as many bits as possible into previous frame ancillary data
|
||||
* In particular, in VBR mode ResvMax may have changed, and we have
|
||||
* to make sure main_data_begin does not create a reservoir bigger
|
||||
* than ResvMax mt 4/00*/
|
||||
{
|
||||
int mdb_bytes = Min(l3_side->main_data_begin * 8, stuffingBits) / 8;
|
||||
l3_side->resvDrain_pre += 8 * mdb_bytes;
|
||||
stuffingBits -= 8 * mdb_bytes;
|
||||
esv->ResvSize -= 8 * mdb_bytes;
|
||||
l3_side->main_data_begin -= mdb_bytes;
|
||||
}
|
||||
/* drain the rest into this frames ancillary data */
|
||||
l3_side->resvDrain_post += stuffingBits;
|
||||
esv->ResvSize -= stuffingBits;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* bit reservoir include file
|
||||
*
|
||||
* Copyright (c) 1999 Mark Taylor
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_RESERVOIR_H
|
||||
#define LAME_RESERVOIR_H
|
||||
|
||||
int ResvFrameBegin(lame_internal_flags * gfc, int *mean_bits);
|
||||
void ResvMaxBits(lame_internal_flags * gfc, int mean_bits, int *targ_bits, int *max_bits,
|
||||
int cbr);
|
||||
void ResvAdjust(lame_internal_flags * gfc, gr_info const *gi);
|
||||
void ResvFrameEnd(lame_internal_flags * gfc, int mean_bits);
|
||||
|
||||
#endif /* LAME_RESERVOIR_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* set_get.h -- Internal set/get definitions
|
||||
*
|
||||
* Copyright (C) 2003 Gabriel Bouvigne / Lame project
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __SET_GET_H__
|
||||
#define __SET_GET_H__
|
||||
|
||||
#include <lame.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* select psychoacoustic model */
|
||||
|
||||
/* manage short blocks */
|
||||
int CDECL lame_set_short_threshold(lame_global_flags *, float, float);
|
||||
int CDECL lame_set_short_threshold_lrm(lame_global_flags *, float);
|
||||
float CDECL lame_get_short_threshold_lrm(const lame_global_flags *);
|
||||
int CDECL lame_set_short_threshold_s(lame_global_flags *, float);
|
||||
float CDECL lame_get_short_threshold_s(const lame_global_flags *);
|
||||
|
||||
|
||||
int CDECL lame_set_maskingadjust(lame_global_flags *, float);
|
||||
float CDECL lame_get_maskingadjust(const lame_global_flags *);
|
||||
|
||||
int CDECL lame_set_maskingadjust_short(lame_global_flags *, float);
|
||||
float CDECL lame_get_maskingadjust_short(const lame_global_flags *);
|
||||
|
||||
/* select ATH formula 4 shape */
|
||||
int CDECL lame_set_ATHcurve(lame_global_flags *, float);
|
||||
float CDECL lame_get_ATHcurve(const lame_global_flags *);
|
||||
|
||||
int CDECL lame_set_preset_notune(lame_global_flags *, int);
|
||||
|
||||
/* substep shaping method */
|
||||
int CDECL lame_set_substep(lame_global_flags *, int);
|
||||
int CDECL lame_get_substep(const lame_global_flags *);
|
||||
|
||||
/* scalefactors scale */
|
||||
int CDECL lame_set_sfscale(lame_global_flags *, int);
|
||||
int CDECL lame_get_sfscale(const lame_global_flags *);
|
||||
|
||||
/* subblock gain */
|
||||
int CDECL lame_set_subblock_gain(lame_global_flags *, int);
|
||||
int CDECL lame_get_subblock_gain(const lame_global_flags *);
|
||||
|
||||
|
||||
|
||||
/*presets*/
|
||||
int apply_preset(lame_global_flags *, int preset, int enforce);
|
||||
|
||||
void CDECL lame_set_tune(lame_t, float); /* FOR INTERNAL USE ONLY */
|
||||
void CDECL lame_set_msfix(lame_t gfp, double msfix);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,564 @@
|
||||
/*
|
||||
* MPEG layer 3 tables source file
|
||||
*
|
||||
* Copyright (c) 1999 Albert L Faber
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* $Id: tables.c,v 1.29 2011/05/07 16:05:17 rbrito Exp $ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "machine.h"
|
||||
|
||||
#include "lame.h"
|
||||
#include "tables.h"
|
||||
|
||||
|
||||
static const uint16_t t1HB[] = {
|
||||
1, 1,
|
||||
1, 0
|
||||
};
|
||||
|
||||
static const uint16_t t2HB[] = {
|
||||
1, 2, 1,
|
||||
3, 1, 1,
|
||||
3, 2, 0
|
||||
};
|
||||
|
||||
static const uint16_t t3HB[] = {
|
||||
3, 2, 1,
|
||||
1, 1, 1,
|
||||
3, 2, 0
|
||||
};
|
||||
|
||||
static const uint16_t t5HB[] = {
|
||||
1, 2, 6, 5,
|
||||
3, 1, 4, 4,
|
||||
7, 5, 7, 1,
|
||||
6, 1, 1, 0
|
||||
};
|
||||
|
||||
static const uint16_t t6HB[] = {
|
||||
7, 3, 5, 1,
|
||||
6, 2, 3, 2,
|
||||
5, 4, 4, 1,
|
||||
3, 3, 2, 0
|
||||
};
|
||||
|
||||
static const uint16_t t7HB[] = {
|
||||
1, 2, 10, 19, 16, 10,
|
||||
3, 3, 7, 10, 5, 3,
|
||||
11, 4, 13, 17, 8, 4,
|
||||
12, 11, 18, 15, 11, 2,
|
||||
7, 6, 9, 14, 3, 1,
|
||||
6, 4, 5, 3, 2, 0
|
||||
};
|
||||
|
||||
static const uint16_t t8HB[] = {
|
||||
3, 4, 6, 18, 12, 5,
|
||||
5, 1, 2, 16, 9, 3,
|
||||
7, 3, 5, 14, 7, 3,
|
||||
19, 17, 15, 13, 10, 4,
|
||||
13, 5, 8, 11, 5, 1,
|
||||
12, 4, 4, 1, 1, 0
|
||||
};
|
||||
|
||||
static const uint16_t t9HB[] = {
|
||||
7, 5, 9, 14, 15, 7,
|
||||
6, 4, 5, 5, 6, 7,
|
||||
7, 6, 8, 8, 8, 5,
|
||||
15, 6, 9, 10, 5, 1,
|
||||
11, 7, 9, 6, 4, 1,
|
||||
14, 4, 6, 2, 6, 0
|
||||
};
|
||||
|
||||
static const uint16_t t10HB[] = {
|
||||
1, 2, 10, 23, 35, 30, 12, 17,
|
||||
3, 3, 8, 12, 18, 21, 12, 7,
|
||||
11, 9, 15, 21, 32, 40, 19, 6,
|
||||
14, 13, 22, 34, 46, 23, 18, 7,
|
||||
20, 19, 33, 47, 27, 22, 9, 3,
|
||||
31, 22, 41, 26, 21, 20, 5, 3,
|
||||
14, 13, 10, 11, 16, 6, 5, 1,
|
||||
9, 8, 7, 8, 4, 4, 2, 0
|
||||
};
|
||||
|
||||
static const uint16_t t11HB[] = {
|
||||
3, 4, 10, 24, 34, 33, 21, 15,
|
||||
5, 3, 4, 10, 32, 17, 11, 10,
|
||||
11, 7, 13, 18, 30, 31, 20, 5,
|
||||
25, 11, 19, 59, 27, 18, 12, 5,
|
||||
35, 33, 31, 58, 30, 16, 7, 5,
|
||||
28, 26, 32, 19, 17, 15, 8, 14,
|
||||
14, 12, 9, 13, 14, 9, 4, 1,
|
||||
11, 4, 6, 6, 6, 3, 2, 0
|
||||
};
|
||||
|
||||
static const uint16_t t12HB[] = {
|
||||
9, 6, 16, 33, 41, 39, 38, 26,
|
||||
7, 5, 6, 9, 23, 16, 26, 11,
|
||||
17, 7, 11, 14, 21, 30, 10, 7,
|
||||
17, 10, 15, 12, 18, 28, 14, 5,
|
||||
32, 13, 22, 19, 18, 16, 9, 5,
|
||||
40, 17, 31, 29, 17, 13, 4, 2,
|
||||
27, 12, 11, 15, 10, 7, 4, 1,
|
||||
27, 12, 8, 12, 6, 3, 1, 0
|
||||
};
|
||||
|
||||
static const uint16_t t13HB[] = {
|
||||
1, 5, 14, 21, 34, 51, 46, 71, 42, 52, 68, 52, 67, 44, 43, 19,
|
||||
3, 4, 12, 19, 31, 26, 44, 33, 31, 24, 32, 24, 31, 35, 22, 14,
|
||||
15, 13, 23, 36, 59, 49, 77, 65, 29, 40, 30, 40, 27, 33, 42, 16,
|
||||
22, 20, 37, 61, 56, 79, 73, 64, 43, 76, 56, 37, 26, 31, 25, 14,
|
||||
35, 16, 60, 57, 97, 75, 114, 91, 54, 73, 55, 41, 48, 53, 23, 24,
|
||||
58, 27, 50, 96, 76, 70, 93, 84, 77, 58, 79, 29, 74, 49, 41, 17,
|
||||
47, 45, 78, 74, 115, 94, 90, 79, 69, 83, 71, 50, 59, 38, 36, 15,
|
||||
72, 34, 56, 95, 92, 85, 91, 90, 86, 73, 77, 65, 51, 44, 43, 42,
|
||||
43, 20, 30, 44, 55, 78, 72, 87, 78, 61, 46, 54, 37, 30, 20, 16,
|
||||
53, 25, 41, 37, 44, 59, 54, 81, 66, 76, 57, 54, 37, 18, 39, 11,
|
||||
35, 33, 31, 57, 42, 82, 72, 80, 47, 58, 55, 21, 22, 26, 38, 22,
|
||||
53, 25, 23, 38, 70, 60, 51, 36, 55, 26, 34, 23, 27, 14, 9, 7,
|
||||
34, 32, 28, 39, 49, 75, 30, 52, 48, 40, 52, 28, 18, 17, 9, 5,
|
||||
45, 21, 34, 64, 56, 50, 49, 45, 31, 19, 12, 15, 10, 7, 6, 3,
|
||||
48, 23, 20, 39, 36, 35, 53, 21, 16, 23, 13, 10, 6, 1, 4, 2,
|
||||
16, 15, 17, 27, 25, 20, 29, 11, 17, 12, 16, 8, 1, 1, 0, 1
|
||||
};
|
||||
|
||||
static const uint16_t t15HB[] = {
|
||||
7, 12, 18, 53, 47, 76, 124, 108, 89, 123, 108, 119, 107, 81, 122, 63,
|
||||
13, 5, 16, 27, 46, 36, 61, 51, 42, 70, 52, 83, 65, 41, 59, 36,
|
||||
19, 17, 15, 24, 41, 34, 59, 48, 40, 64, 50, 78, 62, 80, 56, 33,
|
||||
29, 28, 25, 43, 39, 63, 55, 93, 76, 59, 93, 72, 54, 75, 50, 29,
|
||||
52, 22, 42, 40, 67, 57, 95, 79, 72, 57, 89, 69, 49, 66, 46, 27,
|
||||
77, 37, 35, 66, 58, 52, 91, 74, 62, 48, 79, 63, 90, 62, 40, 38,
|
||||
125, 32, 60, 56, 50, 92, 78, 65, 55, 87, 71, 51, 73, 51, 70, 30,
|
||||
109, 53, 49, 94, 88, 75, 66, 122, 91, 73, 56, 42, 64, 44, 21, 25,
|
||||
90, 43, 41, 77, 73, 63, 56, 92, 77, 66, 47, 67, 48, 53, 36, 20,
|
||||
71, 34, 67, 60, 58, 49, 88, 76, 67, 106, 71, 54, 38, 39, 23, 15,
|
||||
109, 53, 51, 47, 90, 82, 58, 57, 48, 72, 57, 41, 23, 27, 62, 9,
|
||||
86, 42, 40, 37, 70, 64, 52, 43, 70, 55, 42, 25, 29, 18, 11, 11,
|
||||
118, 68, 30, 55, 50, 46, 74, 65, 49, 39, 24, 16, 22, 13, 14, 7,
|
||||
91, 44, 39, 38, 34, 63, 52, 45, 31, 52, 28, 19, 14, 8, 9, 3,
|
||||
123, 60, 58, 53, 47, 43, 32, 22, 37, 24, 17, 12, 15, 10, 2, 1,
|
||||
71, 37, 34, 30, 28, 20, 17, 26, 21, 16, 10, 6, 8, 6, 2, 0
|
||||
};
|
||||
|
||||
static const uint16_t t16HB[] = {
|
||||
1, 5, 14, 44, 74, 63, 110, 93, 172, 149, 138, 242, 225, 195, 376, 17,
|
||||
3, 4, 12, 20, 35, 62, 53, 47, 83, 75, 68, 119, 201, 107, 207, 9,
|
||||
15, 13, 23, 38, 67, 58, 103, 90, 161, 72, 127, 117, 110, 209, 206, 16,
|
||||
45, 21, 39, 69, 64, 114, 99, 87, 158, 140, 252, 212, 199, 387, 365, 26,
|
||||
75, 36, 68, 65, 115, 101, 179, 164, 155, 264, 246, 226, 395, 382, 362, 9,
|
||||
66, 30, 59, 56, 102, 185, 173, 265, 142, 253, 232, 400, 388, 378, 445, 16,
|
||||
111, 54, 52, 100, 184, 178, 160, 133, 257, 244, 228, 217, 385, 366, 715, 10,
|
||||
98, 48, 91, 88, 165, 157, 148, 261, 248, 407, 397, 372, 380, 889, 884, 8,
|
||||
85, 84, 81, 159, 156, 143, 260, 249, 427, 401, 392, 383, 727, 713, 708, 7,
|
||||
154, 76, 73, 141, 131, 256, 245, 426, 406, 394, 384, 735, 359, 710, 352, 11,
|
||||
139, 129, 67, 125, 247, 233, 229, 219, 393, 743, 737, 720, 885, 882, 439, 4,
|
||||
243, 120, 118, 115, 227, 223, 396, 746, 742, 736, 721, 712, 706, 223, 436, 6,
|
||||
202, 224, 222, 218, 216, 389, 386, 381, 364, 888, 443, 707, 440, 437, 1728, 4,
|
||||
747, 211, 210, 208, 370, 379, 734, 723, 714, 1735, 883, 877, 876, 3459, 865, 2,
|
||||
377, 369, 102, 187, 726, 722, 358, 711, 709, 866, 1734, 871, 3458, 870, 434, 0,
|
||||
12, 10, 7, 11, 10, 17, 11, 9, 13, 12, 10, 7, 5, 3, 1, 3
|
||||
};
|
||||
|
||||
static const uint16_t t24HB[] = {
|
||||
15, 13, 46, 80, 146, 262, 248, 434, 426, 669, 653, 649, 621, 517, 1032, 88,
|
||||
14, 12, 21, 38, 71, 130, 122, 216, 209, 198, 327, 345, 319, 297, 279, 42,
|
||||
47, 22, 41, 74, 68, 128, 120, 221, 207, 194, 182, 340, 315, 295, 541, 18,
|
||||
81, 39, 75, 70, 134, 125, 116, 220, 204, 190, 178, 325, 311, 293, 271, 16,
|
||||
147, 72, 69, 135, 127, 118, 112, 210, 200, 188, 352, 323, 306, 285, 540, 14,
|
||||
263, 66, 129, 126, 119, 114, 214, 202, 192, 180, 341, 317, 301, 281, 262, 12,
|
||||
249, 123, 121, 117, 113, 215, 206, 195, 185, 347, 330, 308, 291, 272, 520, 10,
|
||||
435, 115, 111, 109, 211, 203, 196, 187, 353, 332, 313, 298, 283, 531, 381, 17,
|
||||
427, 212, 208, 205, 201, 193, 186, 177, 169, 320, 303, 286, 268, 514, 377, 16,
|
||||
335, 199, 197, 191, 189, 181, 174, 333, 321, 305, 289, 275, 521, 379, 371, 11,
|
||||
668, 184, 183, 179, 175, 344, 331, 314, 304, 290, 277, 530, 383, 373, 366, 10,
|
||||
652, 346, 171, 168, 164, 318, 309, 299, 287, 276, 263, 513, 375, 368, 362, 6,
|
||||
648, 322, 316, 312, 307, 302, 292, 284, 269, 261, 512, 376, 370, 364, 359, 4,
|
||||
620, 300, 296, 294, 288, 282, 273, 266, 515, 380, 374, 369, 365, 361, 357, 2,
|
||||
1033, 280, 278, 274, 267, 264, 259, 382, 378, 372, 367, 363, 360, 358, 356, 0,
|
||||
43, 20, 19, 17, 15, 13, 11, 9, 7, 6, 4, 7, 5, 3, 1, 3
|
||||
};
|
||||
|
||||
static const uint16_t t32HB[] = {
|
||||
1 << 0, 5 << 1, 4 << 1, 5 << 2, 6 << 1, 5 << 2, 4 << 2, 4 << 3,
|
||||
7 << 1, 3 << 2, 6 << 2, 0 << 3, 7 << 2, 2 << 3, 3 << 3, 1 << 4
|
||||
};
|
||||
|
||||
static const uint16_t t33HB[] = {
|
||||
15 << 0, 14 << 1, 13 << 1, 12 << 2, 11 << 1, 10 << 2, 9 << 2, 8 << 3,
|
||||
7 << 1, 6 << 2, 5 << 2, 4 << 3, 3 << 2, 2 << 3, 1 << 3, 0 << 4
|
||||
};
|
||||
|
||||
|
||||
const uint8_t t1l[] = {
|
||||
1, 4,
|
||||
3, 5
|
||||
};
|
||||
|
||||
static const uint8_t t2l[] = {
|
||||
1, 4, 7,
|
||||
4, 5, 7,
|
||||
6, 7, 8
|
||||
};
|
||||
|
||||
static const uint8_t t3l[] = {
|
||||
2, 3, 7,
|
||||
4, 4, 7,
|
||||
6, 7, 8
|
||||
};
|
||||
|
||||
static const uint8_t t5l[] = {
|
||||
1, 4, 7, 8,
|
||||
4, 5, 8, 9,
|
||||
7, 8, 9, 10,
|
||||
8, 8, 9, 10
|
||||
};
|
||||
|
||||
static const uint8_t t6l[] = {
|
||||
3, 4, 6, 8,
|
||||
4, 4, 6, 7,
|
||||
5, 6, 7, 8,
|
||||
7, 7, 8, 9
|
||||
};
|
||||
|
||||
static const uint8_t t7l[] = {
|
||||
1, 4, 7, 9, 9, 10,
|
||||
4, 6, 8, 9, 9, 10,
|
||||
7, 7, 9, 10, 10, 11,
|
||||
8, 9, 10, 11, 11, 11,
|
||||
8, 9, 10, 11, 11, 12,
|
||||
9, 10, 11, 12, 12, 12
|
||||
};
|
||||
|
||||
static const uint8_t t8l[] = {
|
||||
2, 4, 7, 9, 9, 10,
|
||||
4, 4, 6, 10, 10, 10,
|
||||
7, 6, 8, 10, 10, 11,
|
||||
9, 10, 10, 11, 11, 12,
|
||||
9, 9, 10, 11, 12, 12,
|
||||
10, 10, 11, 11, 13, 13
|
||||
};
|
||||
|
||||
static const uint8_t t9l[] = {
|
||||
3, 4, 6, 7, 9, 10,
|
||||
4, 5, 6, 7, 8, 10,
|
||||
5, 6, 7, 8, 9, 10,
|
||||
7, 7, 8, 9, 9, 10,
|
||||
8, 8, 9, 9, 10, 11,
|
||||
9, 9, 10, 10, 11, 11
|
||||
};
|
||||
|
||||
static const uint8_t t10l[] = {
|
||||
1, 4, 7, 9, 10, 10, 10, 11,
|
||||
4, 6, 8, 9, 10, 11, 10, 10,
|
||||
7, 8, 9, 10, 11, 12, 11, 11,
|
||||
8, 9, 10, 11, 12, 12, 11, 12,
|
||||
9, 10, 11, 12, 12, 12, 12, 12,
|
||||
10, 11, 12, 12, 13, 13, 12, 13,
|
||||
9, 10, 11, 12, 12, 12, 13, 13,
|
||||
10, 10, 11, 12, 12, 13, 13, 13
|
||||
};
|
||||
|
||||
static const uint8_t t11l[] = {
|
||||
2, 4, 6, 8, 9, 10, 9, 10,
|
||||
4, 5, 6, 8, 10, 10, 9, 10,
|
||||
6, 7, 8, 9, 10, 11, 10, 10,
|
||||
8, 8, 9, 11, 10, 12, 10, 11,
|
||||
9, 10, 10, 11, 11, 12, 11, 12,
|
||||
9, 10, 11, 12, 12, 13, 12, 13,
|
||||
9, 9, 9, 10, 11, 12, 12, 12,
|
||||
9, 9, 10, 11, 12, 12, 12, 12
|
||||
};
|
||||
|
||||
static const uint8_t t12l[] = {
|
||||
4, 4, 6, 8, 9, 10, 10, 10,
|
||||
4, 5, 6, 7, 9, 9, 10, 10,
|
||||
6, 6, 7, 8, 9, 10, 9, 10,
|
||||
7, 7, 8, 8, 9, 10, 10, 10,
|
||||
8, 8, 9, 9, 10, 10, 10, 11,
|
||||
9, 9, 10, 10, 10, 11, 10, 11,
|
||||
9, 9, 9, 10, 10, 11, 11, 12,
|
||||
10, 10, 10, 11, 11, 11, 11, 12
|
||||
};
|
||||
|
||||
static const uint8_t t13l[] = {
|
||||
1, 5, 7, 8, 9, 10, 10, 11, 10, 11, 12, 12, 13, 13, 14, 14,
|
||||
4, 6, 8, 9, 10, 10, 11, 11, 11, 11, 12, 12, 13, 14, 14, 14,
|
||||
7, 8, 9, 10, 11, 11, 12, 12, 11, 12, 12, 13, 13, 14, 15, 15,
|
||||
8, 9, 10, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 15, 15,
|
||||
9, 9, 11, 11, 12, 12, 13, 13, 12, 13, 13, 14, 14, 15, 15, 16,
|
||||
10, 10, 11, 12, 12, 12, 13, 13, 13, 13, 14, 13, 15, 15, 16, 16,
|
||||
10, 11, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16,
|
||||
11, 11, 12, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 16, 18, 18,
|
||||
10, 10, 11, 12, 12, 13, 13, 14, 14, 14, 14, 15, 15, 16, 17, 17,
|
||||
11, 11, 12, 12, 13, 13, 13, 15, 14, 15, 15, 16, 16, 16, 18, 17,
|
||||
11, 12, 12, 13, 13, 14, 14, 15, 14, 15, 16, 15, 16, 17, 18, 19,
|
||||
12, 12, 12, 13, 14, 14, 14, 14, 15, 15, 15, 16, 17, 17, 17, 18,
|
||||
12, 13, 13, 14, 14, 15, 14, 15, 16, 16, 17, 17, 17, 18, 18, 18,
|
||||
13, 13, 14, 15, 15, 15, 16, 16, 16, 16, 16, 17, 18, 17, 18, 18,
|
||||
14, 14, 14, 15, 15, 15, 17, 16, 16, 19, 17, 17, 17, 19, 18, 18,
|
||||
13, 14, 15, 16, 16, 16, 17, 16, 17, 17, 18, 18, 21, 20, 21, 18
|
||||
};
|
||||
|
||||
static const uint8_t t15l[] = {
|
||||
3, 5, 6, 8, 8, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 14,
|
||||
5, 5, 7, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13,
|
||||
6, 7, 7, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 13,
|
||||
7, 8, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13,
|
||||
8, 8, 9, 9, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 13,
|
||||
9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 13, 13, 13, 14,
|
||||
10, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 14, 14,
|
||||
10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 14,
|
||||
10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 14, 14, 14,
|
||||
10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14,
|
||||
11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 15, 14,
|
||||
11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 15,
|
||||
12, 12, 11, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 15, 15,
|
||||
12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 14, 15, 15,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 14, 15,
|
||||
13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 15, 15, 15, 15
|
||||
};
|
||||
|
||||
static const uint8_t t16_5l[] = {
|
||||
1, 5, 7, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 11,
|
||||
4, 6, 8, 9, 10, 11, 11, 11, 12, 12, 12, 13, 14, 13, 14, 11,
|
||||
7, 8, 9, 10, 11, 11, 12, 12, 13, 12, 13, 13, 13, 14, 14, 12,
|
||||
9, 9, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15, 13,
|
||||
10, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 12,
|
||||
10, 10, 11, 11, 12, 13, 13, 14, 13, 14, 14, 15, 15, 15, 16, 13,
|
||||
11, 11, 11, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 16, 13,
|
||||
11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 15, 17, 17, 13,
|
||||
11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 13,
|
||||
12, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 15, 16, 15, 14,
|
||||
12, 13, 12, 13, 14, 14, 14, 14, 15, 16, 16, 16, 17, 17, 16, 13,
|
||||
13, 13, 13, 13, 14, 14, 15, 16, 16, 16, 16, 16, 16, 15, 16, 14,
|
||||
13, 14, 14, 14, 14, 15, 15, 15, 15, 17, 16, 16, 16, 16, 18, 14,
|
||||
15, 14, 14, 14, 15, 15, 16, 16, 16, 18, 17, 17, 17, 19, 17, 14,
|
||||
14, 15, 13, 14, 16, 16, 15, 16, 16, 17, 18, 17, 19, 17, 16, 14,
|
||||
11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 12
|
||||
};
|
||||
|
||||
static const uint8_t t16l[] = {
|
||||
1, 5, 7, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 10,
|
||||
4, 6, 8, 9, 10, 11, 11, 11, 12, 12, 12, 13, 14, 13, 14, 10,
|
||||
7, 8, 9, 10, 11, 11, 12, 12, 13, 12, 13, 13, 13, 14, 14, 11,
|
||||
9, 9, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15, 12,
|
||||
10, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 11,
|
||||
10, 10, 11, 11, 12, 13, 13, 14, 13, 14, 14, 15, 15, 15, 16, 12,
|
||||
11, 11, 11, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 16, 12,
|
||||
11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 15, 17, 17, 12,
|
||||
11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 12,
|
||||
12, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 15, 16, 15, 13,
|
||||
12, 13, 12, 13, 14, 14, 14, 14, 15, 16, 16, 16, 17, 17, 16, 12,
|
||||
13, 13, 13, 13, 14, 14, 15, 16, 16, 16, 16, 16, 16, 15, 16, 13,
|
||||
13, 14, 14, 14, 14, 15, 15, 15, 15, 17, 16, 16, 16, 16, 18, 13,
|
||||
15, 14, 14, 14, 15, 15, 16, 16, 16, 18, 17, 17, 17, 19, 17, 13,
|
||||
14, 15, 13, 14, 16, 16, 15, 16, 16, 17, 18, 17, 19, 17, 16, 13,
|
||||
10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 10
|
||||
};
|
||||
|
||||
static const uint8_t t24l[] = {
|
||||
4, 5, 7, 8, 9, 10, 10, 11, 11, 12, 12, 12, 12, 12, 13, 10,
|
||||
5, 6, 7, 8, 9, 10, 10, 11, 11, 11, 12, 12, 12, 12, 12, 10,
|
||||
7, 7, 8, 9, 9, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 9,
|
||||
8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 9,
|
||||
9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 9,
|
||||
10, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 9,
|
||||
10, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 9,
|
||||
11, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 10,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 10,
|
||||
11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 10,
|
||||
12, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 10,
|
||||
12, 12, 11, 11, 11, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 10,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 10,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 10,
|
||||
13, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 10,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 6
|
||||
};
|
||||
|
||||
const uint8_t t32l[] = {
|
||||
1 + 0, 4 + 1, 4 + 1, 5 + 2, 4 + 1, 6 + 2, 5 + 2, 6 + 3,
|
||||
4 + 1, 5 + 2, 5 + 2, 6 + 3, 5 + 2, 6 + 3, 6 + 3, 6 + 4
|
||||
};
|
||||
|
||||
const uint8_t t33l[] = {
|
||||
4 + 0, 4 + 1, 4 + 1, 4 + 2, 4 + 1, 4 + 2, 4 + 2, 4 + 3,
|
||||
4 + 1, 4 + 2, 4 + 2, 4 + 3, 4 + 2, 4 + 3, 4 + 3, 4 + 4
|
||||
};
|
||||
|
||||
|
||||
const struct huffcodetab ht[HTN] = {
|
||||
/* xlen, linmax, table, hlen */
|
||||
{0, 0, NULL, NULL},
|
||||
{2, 0, t1HB, t1l},
|
||||
{3, 0, t2HB, t2l},
|
||||
{3, 0, t3HB, t3l},
|
||||
{0, 0, NULL, NULL}, /* Apparently not used */
|
||||
{4, 0, t5HB, t5l},
|
||||
{4, 0, t6HB, t6l},
|
||||
{6, 0, t7HB, t7l},
|
||||
{6, 0, t8HB, t8l},
|
||||
{6, 0, t9HB, t9l},
|
||||
{8, 0, t10HB, t10l},
|
||||
{8, 0, t11HB, t11l},
|
||||
{8, 0, t12HB, t12l},
|
||||
{16, 0, t13HB, t13l},
|
||||
{0, 0, NULL, t16_5l}, /* Apparently not used */
|
||||
{16, 0, t15HB, t15l},
|
||||
|
||||
{1, 1, t16HB, t16l},
|
||||
{2, 3, t16HB, t16l},
|
||||
{3, 7, t16HB, t16l},
|
||||
{4, 15, t16HB, t16l},
|
||||
{6, 63, t16HB, t16l},
|
||||
{8, 255, t16HB, t16l},
|
||||
{10, 1023, t16HB, t16l},
|
||||
{13, 8191, t16HB, t16l},
|
||||
|
||||
{4, 15, t24HB, t24l},
|
||||
{5, 31, t24HB, t24l},
|
||||
{6, 63, t24HB, t24l},
|
||||
{7, 127, t24HB, t24l},
|
||||
{8, 255, t24HB, t24l},
|
||||
{9, 511, t24HB, t24l},
|
||||
{11, 2047, t24HB, t24l},
|
||||
{13, 8191, t24HB, t24l},
|
||||
|
||||
{0, 0, t32HB, t32l},
|
||||
{0, 0, t33HB, t33l},
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* for (i = 0; i < 16*16; i++) {
|
||||
* largetbl[i] = ((ht[16].hlen[i]) << 16) + ht[24].hlen[i];
|
||||
* }
|
||||
*/
|
||||
const uint32_t largetbl[16 * 16] = {
|
||||
0x010004, 0x050005, 0x070007, 0x090008, 0x0a0009, 0x0a000a, 0x0b000a, 0x0b000b,
|
||||
0x0c000b, 0x0c000c, 0x0c000c, 0x0d000c, 0x0d000c, 0x0d000c, 0x0e000d, 0x0a000a,
|
||||
0x040005, 0x060006, 0x080007, 0x090008, 0x0a0009, 0x0b000a, 0x0b000a, 0x0b000b,
|
||||
0x0c000b, 0x0c000b, 0x0c000c, 0x0d000c, 0x0e000c, 0x0d000c, 0x0e000c, 0x0a000a,
|
||||
0x070007, 0x080007, 0x090008, 0x0a0009, 0x0b0009, 0x0b000a, 0x0c000a, 0x0c000b,
|
||||
0x0d000b, 0x0c000b, 0x0d000b, 0x0d000c, 0x0d000c, 0x0e000c, 0x0e000d, 0x0b0009,
|
||||
0x090008, 0x090008, 0x0a0009, 0x0b0009, 0x0b000a, 0x0c000a, 0x0c000a, 0x0c000b,
|
||||
0x0d000b, 0x0d000b, 0x0e000b, 0x0e000c, 0x0e000c, 0x0f000c, 0x0f000c, 0x0c0009,
|
||||
0x0a0009, 0x0a0009, 0x0b0009, 0x0b000a, 0x0c000a, 0x0c000a, 0x0d000a, 0x0d000b,
|
||||
0x0d000b, 0x0e000b, 0x0e000c, 0x0e000c, 0x0f000c, 0x0f000c, 0x0f000d, 0x0b0009,
|
||||
0x0a000a, 0x0a0009, 0x0b000a, 0x0b000a, 0x0c000a, 0x0d000a, 0x0d000b, 0x0e000b,
|
||||
0x0d000b, 0x0e000b, 0x0e000c, 0x0f000c, 0x0f000c, 0x0f000c, 0x10000c, 0x0c0009,
|
||||
0x0b000a, 0x0b000a, 0x0b000a, 0x0c000a, 0x0d000a, 0x0d000b, 0x0d000b, 0x0d000b,
|
||||
0x0e000b, 0x0e000c, 0x0e000c, 0x0e000c, 0x0f000c, 0x0f000c, 0x10000d, 0x0c0009,
|
||||
0x0b000b, 0x0b000a, 0x0c000a, 0x0c000a, 0x0d000b, 0x0d000b, 0x0d000b, 0x0e000b,
|
||||
0x0e000c, 0x0f000c, 0x0f000c, 0x0f000c, 0x0f000c, 0x11000d, 0x11000d, 0x0c000a,
|
||||
0x0b000b, 0x0c000b, 0x0c000b, 0x0d000b, 0x0d000b, 0x0d000b, 0x0e000b, 0x0e000b,
|
||||
0x0f000b, 0x0f000c, 0x0f000c, 0x0f000c, 0x10000c, 0x10000d, 0x10000d, 0x0c000a,
|
||||
0x0c000b, 0x0c000b, 0x0c000b, 0x0d000b, 0x0d000b, 0x0e000b, 0x0e000b, 0x0f000c,
|
||||
0x0f000c, 0x0f000c, 0x0f000c, 0x10000c, 0x0f000d, 0x10000d, 0x0f000d, 0x0d000a,
|
||||
0x0c000c, 0x0d000b, 0x0c000b, 0x0d000b, 0x0e000b, 0x0e000c, 0x0e000c, 0x0e000c,
|
||||
0x0f000c, 0x10000c, 0x10000c, 0x10000d, 0x11000d, 0x11000d, 0x10000d, 0x0c000a,
|
||||
0x0d000c, 0x0d000c, 0x0d000b, 0x0d000b, 0x0e000b, 0x0e000c, 0x0f000c, 0x10000c,
|
||||
0x10000c, 0x10000c, 0x10000c, 0x10000d, 0x10000d, 0x0f000d, 0x10000d, 0x0d000a,
|
||||
0x0d000c, 0x0e000c, 0x0e000c, 0x0e000c, 0x0e000c, 0x0f000c, 0x0f000c, 0x0f000c,
|
||||
0x0f000c, 0x11000c, 0x10000d, 0x10000d, 0x10000d, 0x10000d, 0x12000d, 0x0d000a,
|
||||
0x0f000c, 0x0e000c, 0x0e000c, 0x0e000c, 0x0f000c, 0x0f000c, 0x10000c, 0x10000c,
|
||||
0x10000d, 0x12000d, 0x11000d, 0x11000d, 0x11000d, 0x13000d, 0x11000d, 0x0d000a,
|
||||
0x0e000d, 0x0f000c, 0x0d000c, 0x0e000c, 0x10000c, 0x10000c, 0x0f000c, 0x10000d,
|
||||
0x10000d, 0x11000d, 0x12000d, 0x11000d, 0x13000d, 0x11000d, 0x10000d, 0x0d000a,
|
||||
0x0a0009, 0x0a0009, 0x0a0009, 0x0b0009, 0x0b0009, 0x0c0009, 0x0c0009, 0x0c0009,
|
||||
0x0d0009, 0x0d0009, 0x0d0009, 0x0d000a, 0x0d000a, 0x0d000a, 0x0d000a, 0x0a0006
|
||||
};
|
||||
|
||||
/* for (i = 0; i < 3*3; i++) {
|
||||
* table23[i] = ((ht[2].hlen[i]) << 16) + ht[3].hlen[i];
|
||||
* }
|
||||
*/
|
||||
const uint32_t table23[3 * 3] = {
|
||||
0x010002, 0x040003, 0x070007,
|
||||
0x040004, 0x050004, 0x070007,
|
||||
0x060006, 0x070007, 0x080008
|
||||
};
|
||||
|
||||
/* for (i = 0; i < 4*4; i++) {
|
||||
* table56[i] = ((ht[5].hlen[i]) << 16) + ht[6].hlen[i];
|
||||
* }
|
||||
*/
|
||||
const uint32_t table56[4 * 4] = {
|
||||
0x010003, 0x040004, 0x070006, 0x080008, 0x040004, 0x050004, 0x080006, 0x090007,
|
||||
0x070005, 0x080006, 0x090007, 0x0a0008, 0x080007, 0x080007, 0x090008, 0x0a0009
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 0: MPEG-2 LSF
|
||||
* 1: MPEG-1
|
||||
* 2: MPEG-2.5 LSF FhG extention (1995-07-11 shn)
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
MPEG_2 = 0,
|
||||
MPEG_1 = 1,
|
||||
MPEG_25 = 2
|
||||
} MPEG_t;
|
||||
|
||||
const int bitrate_table[3][16] = {
|
||||
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, -1}, /* MPEG 2 */
|
||||
{0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1}, /* MPEG 1 */
|
||||
{0, 8, 16, 24, 32, 40, 48, 56, 64, -1, -1, -1, -1, -1, -1, -1}, /* MPEG 2.5 */
|
||||
};
|
||||
|
||||
const int samplerate_table[3][4] = {
|
||||
{22050, 24000, 16000, -1}, /* MPEG 2 */
|
||||
{44100, 48000, 32000, -1}, /* MPEG 1 */
|
||||
{11025, 12000, 8000, -1}, /* MPEG 2.5 */
|
||||
};
|
||||
|
||||
int
|
||||
lame_get_bitrate(int mpeg_version, int table_index)
|
||||
{
|
||||
if (0 <= mpeg_version && mpeg_version <= 2) {
|
||||
if (0 <= table_index && table_index <= 15) {
|
||||
return bitrate_table[mpeg_version][table_index];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
lame_get_samplerate(int mpeg_version, int table_index)
|
||||
{
|
||||
if (0 <= mpeg_version && mpeg_version <= 2) {
|
||||
if (0 <= table_index && table_index <= 3) {
|
||||
return samplerate_table[mpeg_version][table_index];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* This is the scfsi_band table from 2.4.2.7 of the IS */
|
||||
const int scfsi_band[5] = { 0, 6, 11, 16, 21 };
|
||||
|
||||
/* end of tables.c */
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* MPEG layer 3 tables include file
|
||||
*
|
||||
* Copyright (c) 1999 Albert L Faber
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_TABLES_H
|
||||
#define LAME_TABLES_H
|
||||
|
||||
#if 0
|
||||
typedef struct {
|
||||
unsigned char no;
|
||||
unsigned char width;
|
||||
unsigned char minval_2;
|
||||
float quiet_thr;
|
||||
float norm;
|
||||
float bark;
|
||||
} type1_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned char no;
|
||||
unsigned char width;
|
||||
float quiet_thr;
|
||||
float norm;
|
||||
float SNR;
|
||||
float bark;
|
||||
} type2_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int no:5;
|
||||
unsigned int cbw:3;
|
||||
unsigned int bu:6;
|
||||
unsigned int bo:6;
|
||||
unsigned int w1_576:10;
|
||||
unsigned int w2_576:10;
|
||||
} type34_t;
|
||||
|
||||
typedef struct {
|
||||
size_t len1;
|
||||
const type1_t *const tab1;
|
||||
size_t len2;
|
||||
const type2_t *const tab2;
|
||||
size_t len3;
|
||||
const type34_t *const tab3;
|
||||
size_t len4;
|
||||
const type34_t *const tab4;
|
||||
} type5_t;
|
||||
|
||||
extern const type5_t table5[6];
|
||||
|
||||
#endif
|
||||
|
||||
#define HTN 34
|
||||
|
||||
struct huffcodetab {
|
||||
const unsigned int xlen; /* max. x-index+ */
|
||||
const unsigned int linmax; /* max number to be stored in linbits */
|
||||
const uint16_t *table; /* pointer to array[xlen][ylen] */
|
||||
const uint8_t *hlen; /* pointer to array[xlen][ylen] */
|
||||
};
|
||||
|
||||
extern const struct huffcodetab ht[HTN];
|
||||
/* global memory block */
|
||||
/* array of all huffcodtable headers */
|
||||
/* 0..31 Huffman code table 0..31 */
|
||||
/* 32,33 count1-tables */
|
||||
|
||||
extern const uint8_t t32l[];
|
||||
extern const uint8_t t33l[];
|
||||
|
||||
extern const uint32_t largetbl[16 * 16];
|
||||
extern const uint32_t table23[3 * 3];
|
||||
extern const uint32_t table56[4 * 4];
|
||||
|
||||
extern const int scfsi_band[5];
|
||||
|
||||
extern const int bitrate_table [3][16];
|
||||
extern const int samplerate_table [3][ 4];
|
||||
|
||||
#endif /* LAME_TABLES_H */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,616 @@
|
||||
/*
|
||||
* lame utility library include file
|
||||
*
|
||||
* Copyright (c) 1999 Albert L Faber
|
||||
* Copyright (c) 2008 Robert Hegemann
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_UTIL_H
|
||||
#define LAME_UTIL_H
|
||||
|
||||
#include "l3side.h"
|
||||
#include "id3tag.h"
|
||||
#include "lame_global_flags.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Global Definitions
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE (!FALSE)
|
||||
#endif
|
||||
|
||||
#ifdef UINT_MAX
|
||||
# define MAX_U_32_NUM UINT_MAX
|
||||
#else
|
||||
# define MAX_U_32_NUM 0xFFFFFFFF
|
||||
#endif
|
||||
|
||||
#ifndef PI
|
||||
# ifdef M_PI
|
||||
# define PI M_PI
|
||||
# else
|
||||
# define PI 3.14159265358979323846
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef M_LN2
|
||||
# define LOG2 M_LN2
|
||||
#else
|
||||
# define LOG2 0.69314718055994530942
|
||||
#endif
|
||||
|
||||
#ifdef M_LN10
|
||||
# define LOG10 M_LN10
|
||||
#else
|
||||
# define LOG10 2.30258509299404568402
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef M_SQRT2
|
||||
# define SQRT2 M_SQRT2
|
||||
#else
|
||||
# define SQRT2 1.41421356237309504880
|
||||
#endif
|
||||
|
||||
|
||||
#define CRC16_POLYNOMIAL 0x8005
|
||||
|
||||
#define MAX_BITS_PER_CHANNEL 4095
|
||||
#define MAX_BITS_PER_GRANULE 7680
|
||||
|
||||
/* "bit_stream.h" Definitions */
|
||||
#define BUFFER_SIZE LAME_MAXMP3BUFFER
|
||||
|
||||
#define Min(A, B) ((A) < (B) ? (A) : (B))
|
||||
#define Max(A, B) ((A) > (B) ? (A) : (B))
|
||||
|
||||
/* log/log10 approximations */
|
||||
#ifdef USE_FAST_LOG
|
||||
#define FAST_LOG10(x) (fast_log2(x)*(LOG2/LOG10))
|
||||
#define FAST_LOG(x) (fast_log2(x)*LOG2)
|
||||
#define FAST_LOG10_X(x,y) (fast_log2(x)*(LOG2/LOG10*(y)))
|
||||
#define FAST_LOG_X(x,y) (fast_log2(x)*(LOG2*(y)))
|
||||
#else
|
||||
#define FAST_LOG10(x) log10(x)
|
||||
#define FAST_LOG(x) log(x)
|
||||
#define FAST_LOG10_X(x,y) (log10(x)*(y))
|
||||
#define FAST_LOG_X(x,y) (log(x)*(y))
|
||||
#endif
|
||||
|
||||
|
||||
struct replaygain_data;
|
||||
#ifndef replaygain_data_defined
|
||||
#define replaygain_data_defined
|
||||
typedef struct replaygain_data replaygain_t;
|
||||
#endif
|
||||
struct plotting_data;
|
||||
#ifndef plotting_data_defined
|
||||
#define plotting_data_defined
|
||||
typedef struct plotting_data plotting_data;
|
||||
#endif
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Global Type Definitions
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
typedef struct {
|
||||
void *aligned; /* pointer to ie. 128 bit aligned memory */
|
||||
void *pointer; /* to use with malloc/free */
|
||||
} aligned_pointer_t;
|
||||
|
||||
void calloc_aligned(aligned_pointer_t * ptr, unsigned int size, unsigned int bytes);
|
||||
void free_aligned(aligned_pointer_t * ptr);
|
||||
|
||||
|
||||
/* "bit_stream.h" Type Definitions */
|
||||
|
||||
typedef struct bit_stream_struc {
|
||||
unsigned char *buf; /* bit stream buffer */
|
||||
int buf_size; /* size of buffer (in number of bytes) */
|
||||
int totbit; /* bit counter of bit stream */
|
||||
int buf_byte_idx; /* pointer to top byte in buffer */
|
||||
int buf_bit_idx; /* pointer to top bit of top byte in buffer */
|
||||
|
||||
/* format of file in rd mode (BINARY/ASCII) */
|
||||
} Bit_stream_struc;
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
int sum; /* what we have seen so far */
|
||||
int seen; /* how many frames we have seen in this chunk */
|
||||
int want; /* how many frames we want to collect into one chunk */
|
||||
int pos; /* actual position in our bag */
|
||||
int size; /* size of our bag */
|
||||
int *bag; /* pointer to our bag */
|
||||
unsigned int nVbrNumFrames;
|
||||
unsigned long nBytesWritten;
|
||||
/* VBR tag data */
|
||||
unsigned int TotalFrameSize;
|
||||
} VBR_seek_info_t;
|
||||
|
||||
|
||||
/**
|
||||
* ATH related stuff, if something new ATH related has to be added,
|
||||
* please plugg it here into the ATH_t struct
|
||||
*/
|
||||
typedef struct {
|
||||
int use_adjust; /* method for the auto adjustment */
|
||||
FLOAT aa_sensitivity_p; /* factor for tuning the (sample power)
|
||||
point below which adaptive threshold
|
||||
of hearing adjustment occurs */
|
||||
FLOAT adjust_factor; /* lowering based on peak volume, 1 = no lowering */
|
||||
FLOAT adjust_limit; /* limit for dynamic ATH adjust */
|
||||
FLOAT decay; /* determined to lower x dB each second */
|
||||
FLOAT floor; /* lowest ATH value */
|
||||
FLOAT l[SBMAX_l]; /* ATH for sfbs in long blocks */
|
||||
FLOAT s[SBMAX_s]; /* ATH for sfbs in short blocks */
|
||||
FLOAT psfb21[PSFB21]; /* ATH for partitionned sfb21 in long blocks */
|
||||
FLOAT psfb12[PSFB12]; /* ATH for partitionned sfb12 in short blocks */
|
||||
FLOAT cb_l[CBANDS]; /* ATH for long block convolution bands */
|
||||
FLOAT cb_s[CBANDS]; /* ATH for short block convolution bands */
|
||||
FLOAT eql_w[BLKSIZE / 2]; /* equal loudness weights (based on ATH) */
|
||||
} ATH_t;
|
||||
|
||||
/**
|
||||
* PSY Model related stuff
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
FLOAT masking_lower[CBANDS];
|
||||
FLOAT minval[CBANDS];
|
||||
FLOAT rnumlines[CBANDS];
|
||||
FLOAT mld_cb[CBANDS];
|
||||
FLOAT mld[Max(SBMAX_l,SBMAX_s)];
|
||||
FLOAT bo_weight[Max(SBMAX_l,SBMAX_s)]; /* band weight long scalefactor bands, at transition */
|
||||
FLOAT attack_threshold; /* short block tuning */
|
||||
int s3ind[CBANDS][2];
|
||||
int numlines[CBANDS];
|
||||
int bm[Max(SBMAX_l,SBMAX_s)];
|
||||
int bo[Max(SBMAX_l,SBMAX_s)];
|
||||
int npart;
|
||||
int n_sb; /* SBMAX_l or SBMAX_s */
|
||||
FLOAT *s3;
|
||||
} PsyConst_CB2SB_t;
|
||||
|
||||
|
||||
/**
|
||||
* global data constants
|
||||
*/
|
||||
typedef struct {
|
||||
FLOAT window[BLKSIZE], window_s[BLKSIZE_s / 2];
|
||||
PsyConst_CB2SB_t l;
|
||||
PsyConst_CB2SB_t s;
|
||||
PsyConst_CB2SB_t l_to_s;
|
||||
FLOAT attack_threshold[4];
|
||||
FLOAT decay;
|
||||
int force_short_block_calc;
|
||||
} PsyConst_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
||||
FLOAT nb_l1[4][CBANDS], nb_l2[4][CBANDS];
|
||||
FLOAT nb_s1[4][CBANDS], nb_s2[4][CBANDS];
|
||||
|
||||
III_psy_xmin thm[4];
|
||||
III_psy_xmin en[4];
|
||||
|
||||
/* loudness calculation (for adaptive threshold of hearing) */
|
||||
FLOAT loudness_sq_save[2]; /* account for granule delay of L3psycho_anal */
|
||||
|
||||
FLOAT tot_ener[4];
|
||||
|
||||
FLOAT last_en_subshort[4][9];
|
||||
int last_attacks[4];
|
||||
|
||||
int blocktype_old[2];
|
||||
} PsyStateVar_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
/* loudness calculation (for adaptive threshold of hearing) */
|
||||
FLOAT loudness_sq[2][2]; /* loudness^2 approx. per granule and channel */
|
||||
} PsyResult_t;
|
||||
|
||||
|
||||
/* variables used by encoder.c */
|
||||
typedef struct {
|
||||
/* variables for newmdct.c */
|
||||
FLOAT sb_sample[2][2][18][SBLIMIT];
|
||||
FLOAT amp_filter[32];
|
||||
|
||||
/* variables used by util.c */
|
||||
/* BPC = maximum number of filter convolution windows to precompute */
|
||||
#define BPC 320
|
||||
double itime[2]; /* float precision seems to be not enough */
|
||||
sample_t *inbuf_old[2];
|
||||
sample_t *blackfilt[2 * BPC + 1];
|
||||
|
||||
FLOAT pefirbuf[19];
|
||||
|
||||
/* used for padding */
|
||||
int frac_SpF;
|
||||
int slot_lag;
|
||||
|
||||
/* variables for bitstream.c */
|
||||
/* mpeg1: buffer=511 bytes smallest frame: 96-38(sideinfo)=58
|
||||
* max number of frames in reservoir: 8
|
||||
* mpeg2: buffer=255 bytes. smallest frame: 24-23bytes=1
|
||||
* with VBR, if you are encoding all silence, it is possible to
|
||||
* have 8kbs/24khz frames with 1byte of data each, which means we need
|
||||
* to buffer up to 255 headers! */
|
||||
/* also, max_header_buf has to be a power of two */
|
||||
#define MAX_HEADER_BUF 256
|
||||
#define MAX_HEADER_LEN 40 /* max size of header is 38 */
|
||||
struct {
|
||||
int write_timing;
|
||||
int ptr;
|
||||
char buf[MAX_HEADER_LEN];
|
||||
} header[MAX_HEADER_BUF];
|
||||
|
||||
int h_ptr;
|
||||
int w_ptr;
|
||||
int ancillary_flag;
|
||||
|
||||
/* variables for reservoir.c */
|
||||
int ResvSize; /* in bits */
|
||||
int ResvMax; /* in bits */
|
||||
|
||||
int in_buffer_nsamples;
|
||||
sample_t *in_buffer_0;
|
||||
sample_t *in_buffer_1;
|
||||
|
||||
#ifndef MFSIZE
|
||||
# define MFSIZE ( 3*1152 + ENCDELAY - MDCTDELAY )
|
||||
#endif
|
||||
sample_t mfbuf[2][MFSIZE];
|
||||
|
||||
int mf_samples_to_encode;
|
||||
int mf_size;
|
||||
|
||||
} EncStateVar_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
/* simple statistics */
|
||||
int bitrate_channelmode_hist[16][4 + 1];
|
||||
int bitrate_blocktype_hist[16][4 + 1 + 1]; /*norm/start/short/stop/mixed(short)/sum */
|
||||
|
||||
int bitrate_index;
|
||||
int frame_number; /* number of frames encoded */
|
||||
int padding; /* padding for the current frame? */
|
||||
int mode_ext;
|
||||
int encoder_delay;
|
||||
int encoder_padding; /* number of samples of padding appended to input */
|
||||
} EncResult_t;
|
||||
|
||||
|
||||
/* variables used by quantize.c */
|
||||
typedef struct {
|
||||
/* variables for nspsytune */
|
||||
FLOAT longfact[SBMAX_l];
|
||||
FLOAT shortfact[SBMAX_s];
|
||||
FLOAT masking_lower;
|
||||
FLOAT mask_adjust; /* the dbQ stuff */
|
||||
FLOAT mask_adjust_short; /* the dbQ stuff */
|
||||
int OldValue[2];
|
||||
int CurrentStep[2];
|
||||
int pseudohalf[SFBMAX];
|
||||
int sfb21_extra; /* will be set in lame_init_params */
|
||||
int substep_shaping; /* 0 = no substep
|
||||
1 = use substep shaping at last step(VBR only)
|
||||
(not implemented yet)
|
||||
2 = use substep inside loop
|
||||
3 = use substep inside loop and last step
|
||||
*/
|
||||
|
||||
|
||||
char bv_scf[576];
|
||||
} QntStateVar_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
replaygain_t *rgdata;
|
||||
/* ReplayGain */
|
||||
} RpgStateVar_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
FLOAT noclipScale; /* user-specified scale factor required for preventing clipping */
|
||||
sample_t PeakSample;
|
||||
int RadioGain;
|
||||
int noclipGainChange; /* gain change required for preventing clipping */
|
||||
} RpgResult_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
int version; /* 0=MPEG-2/2.5 1=MPEG-1 */
|
||||
int samplerate_index;
|
||||
int sideinfo_len;
|
||||
|
||||
int noise_shaping; /* 0 = none
|
||||
1 = ISO AAC model
|
||||
2 = allow scalefac_select=1
|
||||
*/
|
||||
|
||||
int subblock_gain; /* 0 = no, 1 = yes */
|
||||
int use_best_huffman; /* 0 = no. 1=outside loop 2=inside loop(slow) */
|
||||
int noise_shaping_amp; /* 0 = ISO model: amplify all distorted bands
|
||||
1 = amplify within 50% of max (on db scale)
|
||||
2 = amplify only most distorted band
|
||||
3 = method 1 and refine with method 2
|
||||
*/
|
||||
|
||||
int noise_shaping_stop; /* 0 = stop at over=0, all scalefacs amplified or
|
||||
a scalefac has reached max value
|
||||
1 = stop when all scalefacs amplified or
|
||||
a scalefac has reached max value
|
||||
2 = stop when all scalefacs amplified
|
||||
*/
|
||||
|
||||
|
||||
int full_outer_loop; /* 0 = stop early after 0 distortion found. 1 = full search */
|
||||
|
||||
int lowpassfreq;
|
||||
int highpassfreq;
|
||||
int samplerate_in; /* input_samp_rate in Hz. default=44.1 kHz */
|
||||
int samplerate_out; /* output_samp_rate. */
|
||||
int channels_in; /* number of channels in the input data stream (PCM or decoded PCM) */
|
||||
int channels_out; /* number of channels in the output data stream (not used for decoding) */
|
||||
int mode_gr; /* granules per frame */
|
||||
int force_ms; /* force M/S mode. requires mode=1 */
|
||||
|
||||
int quant_comp;
|
||||
int quant_comp_short;
|
||||
|
||||
int use_temporal_masking_effect;
|
||||
int use_safe_joint_stereo;
|
||||
|
||||
int preset;
|
||||
|
||||
vbr_mode vbr;
|
||||
int vbr_avg_bitrate_kbps;
|
||||
int vbr_min_bitrate_index; /* min bitrate index */
|
||||
int vbr_max_bitrate_index; /* max bitrate index */
|
||||
int avg_bitrate;
|
||||
int enforce_min_bitrate; /* strictly enforce VBR_min_bitrate normaly, it will be violated for analog silence */
|
||||
|
||||
int findReplayGain; /* find the RG value? default=0 */
|
||||
int findPeakSample;
|
||||
int decode_on_the_fly; /* decode on the fly? default=0 */
|
||||
int analysis;
|
||||
int disable_reservoir;
|
||||
int buffer_constraint; /* enforce ISO spec as much as possible */
|
||||
int free_format;
|
||||
int write_lame_tag; /* add Xing VBR tag? */
|
||||
|
||||
int error_protection; /* use 2 bytes per frame for a CRC checksum. default=0 */
|
||||
int copyright; /* mark as copyright. default=0 */
|
||||
int original; /* mark as original. default=1 */
|
||||
int extension; /* the MP3 'private extension' bit. Meaningless */
|
||||
int emphasis; /* Input PCM is emphased PCM (for
|
||||
instance from one of the rarely
|
||||
emphased CDs), it is STRONGLY not
|
||||
recommended to use this, because
|
||||
psycho does not take it into account,
|
||||
and last but not least many decoders
|
||||
don't care about these bits */
|
||||
|
||||
|
||||
MPEG_mode mode;
|
||||
short_block_t short_blocks;
|
||||
|
||||
float interChRatio;
|
||||
float msfix; /* Naoki's adjustment of Mid/Side maskings */
|
||||
float ATH_offset_db;/* add to ATH this many db */
|
||||
float ATH_offset_factor;/* change ATH by this factor, derived from ATH_offset_db */
|
||||
float ATHcurve; /* change ATH formula 4 shape */
|
||||
int ATHtype;
|
||||
int ATHonly; /* only use ATH */
|
||||
int ATHshort; /* only use ATH for short blocks */
|
||||
int noATH; /* disable ATH */
|
||||
|
||||
float ATHfixpoint;
|
||||
|
||||
float adjust_alto_db;
|
||||
float adjust_bass_db;
|
||||
float adjust_treble_db;
|
||||
float adjust_sfb21_db;
|
||||
|
||||
float compression_ratio; /* sizeof(wav file)/sizeof(mp3 file) */
|
||||
|
||||
/* lowpass and highpass filter control */
|
||||
FLOAT lowpass1, lowpass2; /* normalized frequency bounds of passband */
|
||||
FLOAT highpass1, highpass2; /* normalized frequency bounds of passband */
|
||||
|
||||
/* scale input by this amount before encoding at least not used for MP3 decoding */
|
||||
FLOAT pcm_transform[2][2];
|
||||
|
||||
FLOAT minval;
|
||||
} SessionConfig_t;
|
||||
|
||||
|
||||
struct lame_internal_flags {
|
||||
|
||||
/********************************************************************
|
||||
* internal variables NOT set by calling program, and should not be *
|
||||
* modified by the calling program *
|
||||
********************************************************************/
|
||||
|
||||
/*
|
||||
* Some remarks to the Class_ID field:
|
||||
* The Class ID is an Identifier for a pointer to this struct.
|
||||
* It is very unlikely that a pointer to lame_global_flags has the same 32 bits
|
||||
* in it's structure (large and other special properties, for instance prime).
|
||||
*
|
||||
* To test that the structure is right and initialized, use:
|
||||
* if ( gfc -> Class_ID == LAME_ID ) ...
|
||||
* Other remark:
|
||||
* If you set a flag to 0 for uninit data and 1 for init data, the right test
|
||||
* should be "if (flag == 1)" and NOT "if (flag)". Unintended modification
|
||||
* of this element will be otherwise misinterpreted as an init.
|
||||
*/
|
||||
# define LAME_ID 0xFFF88E3B
|
||||
unsigned long class_id;
|
||||
|
||||
int lame_init_params_successful;
|
||||
int lame_encode_frame_init;
|
||||
int iteration_init_init;
|
||||
int fill_buffer_resample_init;
|
||||
|
||||
SessionConfig_t cfg;
|
||||
|
||||
/* variables used by lame.c */
|
||||
Bit_stream_struc bs;
|
||||
III_side_info_t l3_side;
|
||||
|
||||
scalefac_struct scalefac_band;
|
||||
|
||||
PsyStateVar_t sv_psy; /* DATA FROM PSYMODEL.C */
|
||||
PsyResult_t ov_psy;
|
||||
EncStateVar_t sv_enc; /* DATA FROM ENCODER.C */
|
||||
EncResult_t ov_enc;
|
||||
QntStateVar_t sv_qnt; /* DATA FROM QUANTIZE.C */
|
||||
|
||||
RpgStateVar_t sv_rpg;
|
||||
RpgResult_t ov_rpg;
|
||||
|
||||
/* optional ID3 tags, used in id3tag.c */
|
||||
struct id3tag_spec tag_spec;
|
||||
uint16_t nMusicCRC;
|
||||
|
||||
uint16_t _unused;
|
||||
|
||||
/* CPU features */
|
||||
struct {
|
||||
unsigned int MMX:1; /* Pentium MMX, Pentium II...IV, K6, K6-2,
|
||||
K6-III, Athlon */
|
||||
unsigned int AMD_3DNow:1; /* K6-2, K6-III, Athlon */
|
||||
unsigned int SSE:1; /* Pentium III, Pentium 4 */
|
||||
unsigned int SSE2:1; /* Pentium 4, K8 */
|
||||
unsigned int _unused:28;
|
||||
} CPU_features;
|
||||
|
||||
|
||||
VBR_seek_info_t VBR_seek_table; /* used for Xing VBR header */
|
||||
|
||||
ATH_t *ATH; /* all ATH related stuff */
|
||||
|
||||
PsyConst_t *cd_psy;
|
||||
|
||||
/* used by the frame analyzer */
|
||||
plotting_data *pinfo;
|
||||
hip_t hip;
|
||||
|
||||
/* functions to replace with CPU feature optimized versions in takehiro.c */
|
||||
int (*choose_table) (const int *ix, const int *const end, int *const s);
|
||||
void (*fft_fht) (FLOAT *, int);
|
||||
void (*init_xrpow_core) (gr_info * const cod_info, FLOAT xrpow[576], int upper,
|
||||
FLOAT * sum);
|
||||
|
||||
lame_report_function report_msg;
|
||||
lame_report_function report_dbg;
|
||||
lame_report_function report_err;
|
||||
};
|
||||
|
||||
#ifndef lame_internal_flags_defined
|
||||
#define lame_internal_flags_defined
|
||||
typedef struct lame_internal_flags lame_internal_flags;
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Global Function Prototype Declarations
|
||||
*
|
||||
***********************************************************************/
|
||||
void freegfc(lame_internal_flags * const gfc);
|
||||
void free_id3tag(lame_internal_flags * const gfc);
|
||||
extern int BitrateIndex(int, int, int);
|
||||
extern int FindNearestBitrate(int, int, int);
|
||||
extern int map2MP3Frequency(int freq);
|
||||
extern int SmpFrqIndex(int, int *const);
|
||||
extern int nearestBitrateFullIndex(uint16_t brate);
|
||||
extern FLOAT ATHformula(SessionConfig_t const *cfg, FLOAT freq);
|
||||
extern FLOAT freq2bark(FLOAT freq);
|
||||
void disable_FPE(void);
|
||||
|
||||
/* log/log10 approximations */
|
||||
extern void init_log_table(void);
|
||||
extern ieee754_float32_t fast_log2(ieee754_float32_t x);
|
||||
|
||||
int isResamplingNecessary(SessionConfig_t const* cfg);
|
||||
|
||||
void fill_buffer(lame_internal_flags * gfc,
|
||||
sample_t *const mfbuf[2],
|
||||
sample_t const *const in_buffer[2], int nsamples, int *n_in, int *n_out);
|
||||
|
||||
/* same as lame_decode1 (look in lame.h), but returns
|
||||
unclipped raw floating-point samples. It is declared
|
||||
here, not in lame.h, because it returns LAME's
|
||||
internal type sample_t. No more than 1152 samples
|
||||
per channel are allowed. */
|
||||
int hip_decode1_unclipped(hip_t hip, unsigned char *mp3buf,
|
||||
size_t len, sample_t pcm_l[], sample_t pcm_r[]);
|
||||
|
||||
|
||||
extern int has_MMX(void);
|
||||
extern int has_3DNow(void);
|
||||
extern int has_SSE(void);
|
||||
extern int has_SSE2(void);
|
||||
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Macros about Message Printing and Exit
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
extern void lame_report_def(const char* format, va_list args);
|
||||
extern void lame_report_fnc(lame_report_function print_f, const char *, ...);
|
||||
extern void lame_errorf(const lame_internal_flags * gfc, const char *, ...);
|
||||
extern void lame_debugf(const lame_internal_flags * gfc, const char *, ...);
|
||||
extern void lame_msgf(const lame_internal_flags * gfc, const char *, ...);
|
||||
#define DEBUGF lame_debugf
|
||||
#define ERRORF lame_errorf
|
||||
#define MSGF lame_msgf
|
||||
|
||||
int is_lame_internal_flags_valid(const lame_internal_flags * gfp);
|
||||
|
||||
extern void hip_set_pinfo(hip_t hip, plotting_data* pinfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* LAME_UTIL_H */
|
||||
+1580
File diff suppressed because it is too large
Load Diff
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* MP3 VBR quantization
|
||||
*
|
||||
* Copyright (c) 1999 Mark Taylor
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_VBRQUANTIZE_H
|
||||
#define LAME_VBRQUANTIZE_H
|
||||
|
||||
int VBR_encode_frame(lame_internal_flags * gfc, const FLOAT xr34orig[2][2][576],
|
||||
const FLOAT l3_xmin[2][2][SFBMAX], const int maxbits[2][2]);
|
||||
|
||||
#endif /* LAME_VBRQUANTIZE_H */
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* lame_intrin.h include file
|
||||
*
|
||||
* Copyright (c) 2006 Gabriel Bouvigne
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LAME_INTRIN_H
|
||||
#define LAME_INTRIN_H
|
||||
|
||||
|
||||
void
|
||||
init_xrpow_core_sse(gr_info * const cod_info, FLOAT xrpow[576], int upper, FLOAT * sum);
|
||||
|
||||
void
|
||||
fht_SSE2(FLOAT* , int);
|
||||
|
||||
#endif
|
||||
+240
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* MP3 quantization, intrinsics functions
|
||||
*
|
||||
* Copyright (c) 2005-2006 Gabriel Bouvigne
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "lame.h"
|
||||
#include "machine.h"
|
||||
#include "encoder.h"
|
||||
#include "util.h"
|
||||
#include "lame_intrin.h"
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE_XMMINTRIN_H
|
||||
|
||||
#include <xmmintrin.h>
|
||||
|
||||
typedef union {
|
||||
int32_t _i_32[4]; /* unions are initialized by its first member */
|
||||
float _float[4];
|
||||
__m128 _m128;
|
||||
} vecfloat_union;
|
||||
|
||||
#define TRI_SIZE (5-1) /* 1024 = 4**5 */
|
||||
static const FLOAT costab[TRI_SIZE * 2] = {
|
||||
9.238795325112867e-01, 3.826834323650898e-01,
|
||||
9.951847266721969e-01, 9.801714032956060e-02,
|
||||
9.996988186962042e-01, 2.454122852291229e-02,
|
||||
9.999811752826011e-01, 6.135884649154475e-03
|
||||
};
|
||||
|
||||
|
||||
/* make sure functions with SSE instructions maintain their own properly aligned stack */
|
||||
#if defined (__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)))
|
||||
#define SSE_FUNCTION __attribute__((force_align_arg_pointer))
|
||||
#else
|
||||
#define SSE_FUNCTION
|
||||
#endif
|
||||
|
||||
|
||||
SSE_FUNCTION void
|
||||
init_xrpow_core_sse(gr_info * const cod_info, FLOAT xrpow[576], int upper, FLOAT * sum)
|
||||
{
|
||||
int i;
|
||||
float tmp_max = 0;
|
||||
float tmp_sum = 0;
|
||||
int upper4 = (upper / 4) * 4;
|
||||
int rest = upper-upper4;
|
||||
|
||||
const vecfloat_union fabs_mask = {{ 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF }};
|
||||
const __m128 vec_fabs_mask = _mm_loadu_ps(&fabs_mask._float[0]);
|
||||
vecfloat_union vec_xrpow_max;
|
||||
vecfloat_union vec_sum;
|
||||
vecfloat_union vec_tmp;
|
||||
|
||||
_mm_prefetch((char *) cod_info->xr, _MM_HINT_T0);
|
||||
_mm_prefetch((char *) xrpow, _MM_HINT_T0);
|
||||
|
||||
vec_xrpow_max._m128 = _mm_set_ps1(0);
|
||||
vec_sum._m128 = _mm_set_ps1(0);
|
||||
|
||||
for (i = 0; i < upper4; i += 4) {
|
||||
vec_tmp._m128 = _mm_loadu_ps(&(cod_info->xr[i])); /* load */
|
||||
vec_tmp._m128 = _mm_and_ps(vec_tmp._m128, vec_fabs_mask); /* fabs */
|
||||
vec_sum._m128 = _mm_add_ps(vec_sum._m128, vec_tmp._m128);
|
||||
vec_tmp._m128 = _mm_sqrt_ps(_mm_mul_ps(vec_tmp._m128, _mm_sqrt_ps(vec_tmp._m128)));
|
||||
vec_xrpow_max._m128 = _mm_max_ps(vec_xrpow_max._m128, vec_tmp._m128); /* retrieve max */
|
||||
_mm_storeu_ps(&(xrpow[i]), vec_tmp._m128); /* store into xrpow[] */
|
||||
}
|
||||
vec_tmp._m128 = _mm_set_ps1(0);
|
||||
switch (rest) {
|
||||
case 3: vec_tmp._float[2] = cod_info->xr[upper4+2];
|
||||
case 2: vec_tmp._float[1] = cod_info->xr[upper4+1];
|
||||
case 1: vec_tmp._float[0] = cod_info->xr[upper4+0];
|
||||
vec_tmp._m128 = _mm_and_ps(vec_tmp._m128, vec_fabs_mask); /* fabs */
|
||||
vec_sum._m128 = _mm_add_ps(vec_sum._m128, vec_tmp._m128);
|
||||
vec_tmp._m128 = _mm_sqrt_ps(_mm_mul_ps(vec_tmp._m128, _mm_sqrt_ps(vec_tmp._m128)));
|
||||
vec_xrpow_max._m128 = _mm_max_ps(vec_xrpow_max._m128, vec_tmp._m128); /* retrieve max */
|
||||
switch (rest) {
|
||||
case 3: xrpow[upper4+2] = vec_tmp._float[2];
|
||||
case 2: xrpow[upper4+1] = vec_tmp._float[1];
|
||||
case 1: xrpow[upper4+0] = vec_tmp._float[0];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
tmp_sum = vec_sum._float[0] + vec_sum._float[1] + vec_sum._float[2] + vec_sum._float[3];
|
||||
{
|
||||
float ma = vec_xrpow_max._float[0] > vec_xrpow_max._float[1]
|
||||
? vec_xrpow_max._float[0] : vec_xrpow_max._float[1];
|
||||
float mb = vec_xrpow_max._float[2] > vec_xrpow_max._float[3]
|
||||
? vec_xrpow_max._float[2] : vec_xrpow_max._float[3];
|
||||
tmp_max = ma > mb ? ma : mb;
|
||||
}
|
||||
cod_info->xrpow_max = tmp_max;
|
||||
*sum = tmp_sum;
|
||||
}
|
||||
|
||||
|
||||
SSE_FUNCTION static void
|
||||
store4(__m128 v, float* f0, float* f1, float* f2, float* f3)
|
||||
{
|
||||
vecfloat_union r;
|
||||
r._m128 = v;
|
||||
*f0 = r._float[0];
|
||||
*f1 = r._float[1];
|
||||
*f2 = r._float[2];
|
||||
*f3 = r._float[3];
|
||||
}
|
||||
|
||||
|
||||
SSE_FUNCTION void
|
||||
fht_SSE2(FLOAT * fz, int n)
|
||||
{
|
||||
const FLOAT *tri = costab;
|
||||
int k4;
|
||||
FLOAT *fi, *gi;
|
||||
FLOAT const *fn;
|
||||
|
||||
n <<= 1; /* to get BLKSIZE, because of 3DNow! ASM routine */
|
||||
fn = fz + n;
|
||||
k4 = 4;
|
||||
do {
|
||||
FLOAT s1, c1;
|
||||
int i, k1, k2, k3, kx;
|
||||
kx = k4 >> 1;
|
||||
k1 = k4;
|
||||
k2 = k4 << 1;
|
||||
k3 = k2 + k1;
|
||||
k4 = k2 << 1;
|
||||
fi = fz;
|
||||
gi = fi + kx;
|
||||
do {
|
||||
FLOAT f0, f1, f2, f3;
|
||||
f1 = fi[0] - fi[k1];
|
||||
f0 = fi[0] + fi[k1];
|
||||
f3 = fi[k2] - fi[k3];
|
||||
f2 = fi[k2] + fi[k3];
|
||||
fi[k2] = f0 - f2;
|
||||
fi[0] = f0 + f2;
|
||||
fi[k3] = f1 - f3;
|
||||
fi[k1] = f1 + f3;
|
||||
f1 = gi[0] - gi[k1];
|
||||
f0 = gi[0] + gi[k1];
|
||||
f3 = SQRT2 * gi[k3];
|
||||
f2 = SQRT2 * gi[k2];
|
||||
gi[k2] = f0 - f2;
|
||||
gi[0] = f0 + f2;
|
||||
gi[k3] = f1 - f3;
|
||||
gi[k1] = f1 + f3;
|
||||
gi += k4;
|
||||
fi += k4;
|
||||
} while (fi < fn);
|
||||
c1 = tri[0];
|
||||
s1 = tri[1];
|
||||
for (i = 1; i < kx; i++) {
|
||||
__m128 v_s2;
|
||||
__m128 v_c2;
|
||||
__m128 v_c1;
|
||||
__m128 v_s1;
|
||||
FLOAT c2, s2, s1_2 = s1+s1;
|
||||
c2 = 1 - s1_2 * s1;
|
||||
s2 = s1_2 * c1;
|
||||
fi = fz + i;
|
||||
gi = fz + k1 - i;
|
||||
v_c1 = _mm_set_ps1(c1);
|
||||
v_s1 = _mm_set_ps1(s1);
|
||||
v_c2 = _mm_set_ps1(c2);
|
||||
v_s2 = _mm_set_ps1(s2);
|
||||
{
|
||||
static const vecfloat_union sign_mask = {{0x80000000,0,0,0}};
|
||||
v_c1 = _mm_xor_ps(sign_mask._m128, v_c1); /* v_c1 := {-c1, +c1, +c1, +c1} */
|
||||
}
|
||||
{
|
||||
static const vecfloat_union sign_mask = {{0,0x80000000,0,0}};
|
||||
v_s1 = _mm_xor_ps(sign_mask._m128, v_s1); /* v_s1 := {+s1, -s1, +s1, +s1} */
|
||||
}
|
||||
{
|
||||
static const vecfloat_union sign_mask = {{0,0,0x80000000,0x80000000}};
|
||||
v_c2 = _mm_xor_ps(sign_mask._m128, v_c2); /* v_c2 := {+c2, +c2, -c2, -c2} */
|
||||
}
|
||||
do {
|
||||
__m128 p, q, r;
|
||||
|
||||
q = _mm_setr_ps(fi[k1], fi[k3], gi[k1], gi[k3]); /* Q := {fi_k1,fi_k3,gi_k1,gi_k3}*/
|
||||
p = _mm_mul_ps(_mm_set_ps1(s2), q); /* P := s2 * Q */
|
||||
q = _mm_mul_ps(v_c2, q); /* Q := c2 * Q */
|
||||
q = _mm_shuffle_ps(q, q, _MM_SHUFFLE(1,0,3,2)); /* Q := {-c2*gi_k1,-c2*gi_k3,c2*fi_k1,c2*fi_k3} */
|
||||
p = _mm_add_ps(p, q);
|
||||
|
||||
r = _mm_setr_ps(gi[0], gi[k2], fi[0], fi[k2]); /* R := {gi_0,gi_k2,fi_0,fi_k2} */
|
||||
q = _mm_sub_ps(r, p); /* Q := {gi_0-p0,gi_k2-p1,fi_0-p2,fi_k2-p3} */
|
||||
r = _mm_add_ps(r, p); /* R := {gi_0+p0,gi_k2+p1,fi_0+p2,fi_k2+p3} */
|
||||
p = _mm_shuffle_ps(q, r, _MM_SHUFFLE(2,0,2,0)); /* P := {q0,q2,r0,r2} */
|
||||
p = _mm_shuffle_ps(p, p, _MM_SHUFFLE(3,1,2,0)); /* P := {q0,r0,q2,r2} */
|
||||
q = _mm_shuffle_ps(q, r, _MM_SHUFFLE(3,1,3,1)); /* Q := {q1,q3,r1,r3} */
|
||||
r = _mm_mul_ps(v_c1, q);
|
||||
q = _mm_mul_ps(v_s1, q);
|
||||
q = _mm_shuffle_ps(q, q, _MM_SHUFFLE(0,1,2,3)); /* Q := {q3,q2,q1,q0} */
|
||||
q = _mm_add_ps(q, r);
|
||||
|
||||
store4(_mm_sub_ps(p, q), &gi[k3], &gi[k2], &fi[k3], &fi[k2]);
|
||||
store4(_mm_add_ps(p, q), &gi[k1], &gi[ 0], &fi[k1], &fi[ 0]);
|
||||
|
||||
gi += k4;
|
||||
fi += k4;
|
||||
} while (fi < fn);
|
||||
c2 = c1;
|
||||
c1 = c2 * tri[0] - s1 * tri[1];
|
||||
s1 = c2 * tri[1] + s1 * tri[0];
|
||||
}
|
||||
tri += 2;
|
||||
} while (k4 < n);
|
||||
}
|
||||
|
||||
#endif /* HAVE_XMMINTRIN_H */
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* Version numbering for LAME.
|
||||
*
|
||||
* Copyright (c) 1999 A.L. Faber
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\file version.c
|
||||
\brief Version numbering for LAME.
|
||||
|
||||
Contains functions which describe the version of LAME.
|
||||
|
||||
\author A.L. Faber
|
||||
\version \$Id: version.c,v 1.34 2011/11/18 09:51:02 robert Exp $
|
||||
\ingroup libmp3lame
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "lame.h"
|
||||
#include "machine.h"
|
||||
|
||||
#include "version.h" /* macros of version numbers */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*! Get the LAME version string. */
|
||||
/*!
|
||||
\param void
|
||||
\return a pointer to a string which describes the version of LAME.
|
||||
*/
|
||||
const char *
|
||||
get_lame_version(void)
|
||||
{ /* primary to write screen reports */
|
||||
/* Here we can also add informations about compile time configurations */
|
||||
|
||||
#if LAME_ALPHA_VERSION
|
||||
static /*@observer@ */ const char *const str =
|
||||
STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " "
|
||||
"(alpha " STR(LAME_PATCH_VERSION) ", " __DATE__ " " __TIME__ ")";
|
||||
#elif LAME_BETA_VERSION
|
||||
static /*@observer@ */ const char *const str =
|
||||
STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " "
|
||||
"(beta " STR(LAME_PATCH_VERSION) ", " __DATE__ ")";
|
||||
#elif LAME_RELEASE_VERSION && (LAME_PATCH_VERSION > 0)
|
||||
static /*@observer@ */ const char *const str =
|
||||
STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) "." STR(LAME_PATCH_VERSION);
|
||||
#else
|
||||
static /*@observer@ */ const char *const str =
|
||||
STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION);
|
||||
#endif
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/*! Get the short LAME version string. */
|
||||
/*!
|
||||
It's mainly for inclusion into the MP3 stream.
|
||||
|
||||
\param void
|
||||
\return a pointer to the short version of the LAME version string.
|
||||
*/
|
||||
const char *
|
||||
get_lame_short_version(void)
|
||||
{
|
||||
/* adding date and time to version string makes it harder for output
|
||||
validation */
|
||||
|
||||
#if LAME_ALPHA_VERSION
|
||||
static /*@observer@ */ const char *const str =
|
||||
STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " (alpha " STR(LAME_PATCH_VERSION) ")";
|
||||
#elif LAME_BETA_VERSION
|
||||
static /*@observer@ */ const char *const str =
|
||||
STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " (beta " STR(LAME_PATCH_VERSION) ")";
|
||||
#elif LAME_RELEASE_VERSION && (LAME_PATCH_VERSION > 0)
|
||||
static /*@observer@ */ const char *const str =
|
||||
STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) "." STR(LAME_PATCH_VERSION);
|
||||
#else
|
||||
static /*@observer@ */ const char *const str =
|
||||
STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION);
|
||||
#endif
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/*! Get the _very_ short LAME version string. */
|
||||
/*!
|
||||
It's used in the LAME VBR tag only.
|
||||
|
||||
\param void
|
||||
\return a pointer to the short version of the LAME version string.
|
||||
*/
|
||||
const char *
|
||||
get_lame_very_short_version(void)
|
||||
{
|
||||
/* adding date and time to version string makes it harder for output
|
||||
validation */
|
||||
#if LAME_ALPHA_VERSION
|
||||
#define P "a"
|
||||
#elif LAME_BETA_VERSION
|
||||
#define P "b"
|
||||
#elif LAME_RELEASE_VERSION && (LAME_PATCH_VERSION > 0)
|
||||
#define P "r"
|
||||
#else
|
||||
#define P " "
|
||||
#endif
|
||||
static /*@observer@ */ const char *const str =
|
||||
#if (LAME_PATCH_VERSION > 0)
|
||||
"LAME" STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) P STR(LAME_PATCH_VERSION)
|
||||
#else
|
||||
"LAME" STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) P
|
||||
#endif
|
||||
;
|
||||
return str;
|
||||
}
|
||||
|
||||
/*! Get the _very_ short LAME version string. */
|
||||
/*!
|
||||
It's used in the LAME VBR tag only, limited to 9 characters max.
|
||||
Due to some 3rd party HW/SW decoders, it has to start with LAME.
|
||||
|
||||
\param void
|
||||
\return a pointer to the short version of the LAME version string.
|
||||
*/
|
||||
const char*
|
||||
get_lame_tag_encoder_short_version(void)
|
||||
{
|
||||
static /*@observer@ */ const char *const str =
|
||||
/* FIXME: new scheme / new version counting / drop versioning here ? */
|
||||
"LAME" STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) P
|
||||
;
|
||||
return str;
|
||||
}
|
||||
|
||||
/*! Get the version string for GPSYCHO. */
|
||||
/*!
|
||||
\param void
|
||||
\return a pointer to a string which describes the version of GPSYCHO.
|
||||
*/
|
||||
const char *
|
||||
get_psy_version(void)
|
||||
{
|
||||
#if PSY_ALPHA_VERSION > 0
|
||||
static /*@observer@ */ const char *const str =
|
||||
STR(PSY_MAJOR_VERSION) "." STR(PSY_MINOR_VERSION)
|
||||
" (alpha " STR(PSY_ALPHA_VERSION) ", " __DATE__ " " __TIME__ ")";
|
||||
#elif PSY_BETA_VERSION > 0
|
||||
static /*@observer@ */ const char *const str =
|
||||
STR(PSY_MAJOR_VERSION) "." STR(PSY_MINOR_VERSION)
|
||||
" (beta " STR(PSY_BETA_VERSION) ", " __DATE__ ")";
|
||||
#else
|
||||
static /*@observer@ */ const char *const str =
|
||||
STR(PSY_MAJOR_VERSION) "." STR(PSY_MINOR_VERSION);
|
||||
#endif
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/*! Get the URL for the LAME website. */
|
||||
/*!
|
||||
\param void
|
||||
\return a pointer to a string which is a URL for the LAME website.
|
||||
*/
|
||||
const char *
|
||||
get_lame_url(void)
|
||||
{
|
||||
static /*@observer@ */ const char *const str = LAME_URL;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/*! Get the numerical representation of the version. */
|
||||
/*!
|
||||
Writes the numerical representation of the version of LAME and
|
||||
GPSYCHO into lvp.
|
||||
|
||||
\param lvp
|
||||
*/
|
||||
void
|
||||
get_lame_version_numerical(lame_version_t * lvp)
|
||||
{
|
||||
static /*@observer@ */ const char *const features = ""; /* obsolete */
|
||||
|
||||
/* generic version */
|
||||
lvp->major = LAME_MAJOR_VERSION;
|
||||
lvp->minor = LAME_MINOR_VERSION;
|
||||
#if LAME_ALPHA_VERSION
|
||||
lvp->alpha = LAME_PATCH_VERSION;
|
||||
lvp->beta = 0;
|
||||
#elif LAME_BETA_VERSION
|
||||
lvp->alpha = 0;
|
||||
lvp->beta = LAME_PATCH_VERSION;
|
||||
#else
|
||||
lvp->alpha = 0;
|
||||
lvp->beta = 0;
|
||||
#endif
|
||||
|
||||
/* psy version */
|
||||
lvp->psy_major = PSY_MAJOR_VERSION;
|
||||
lvp->psy_minor = PSY_MINOR_VERSION;
|
||||
lvp->psy_alpha = PSY_ALPHA_VERSION;
|
||||
lvp->psy_beta = PSY_BETA_VERSION;
|
||||
|
||||
/* compile time features */
|
||||
/*@-mustfree@ */
|
||||
lvp->features = features;
|
||||
/*@=mustfree@ */
|
||||
}
|
||||
|
||||
|
||||
const char *
|
||||
get_lame_os_bitness(void)
|
||||
{
|
||||
static /*@observer@ */ const char *const strXX = "";
|
||||
static /*@observer@ */ const char *const str32 = "32bits";
|
||||
static /*@observer@ */ const char *const str64 = "64bits";
|
||||
|
||||
switch (sizeof(void *)) {
|
||||
case 4:
|
||||
return str32;
|
||||
|
||||
case 8:
|
||||
return str64;
|
||||
|
||||
default:
|
||||
return strXX;
|
||||
}
|
||||
}
|
||||
|
||||
/* end of version.c */
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Version numbering for LAME.
|
||||
*
|
||||
* Copyright (c) 1999 A.L. Faber
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAME_VERSION_H
|
||||
#define LAME_VERSION_H
|
||||
|
||||
|
||||
/*
|
||||
* To make a string from a token, use the # operator:
|
||||
*/
|
||||
#ifndef STR
|
||||
# define __STR(x) #x
|
||||
# define STR(x) __STR(x)
|
||||
#endif
|
||||
|
||||
# define LAME_URL "http://lame.sf.net"
|
||||
|
||||
|
||||
# define LAME_MAJOR_VERSION 3 /* Major version number */
|
||||
# define LAME_MINOR_VERSION 100 /* Minor version number */
|
||||
# define LAME_TYPE_VERSION 2 /* 0:alpha 1:beta 2:release */
|
||||
# define LAME_PATCH_VERSION 0 /* Patch level */
|
||||
# define LAME_ALPHA_VERSION (LAME_TYPE_VERSION==0)
|
||||
# define LAME_BETA_VERSION (LAME_TYPE_VERSION==1)
|
||||
# define LAME_RELEASE_VERSION (LAME_TYPE_VERSION==2)
|
||||
|
||||
# define PSY_MAJOR_VERSION 1 /* Major version number */
|
||||
# define PSY_MINOR_VERSION 0 /* Minor version number */
|
||||
# define PSY_ALPHA_VERSION 0 /* Set number if this is an alpha version, otherwise zero */
|
||||
# define PSY_BETA_VERSION 0 /* Set number if this is a beta version, otherwise zero */
|
||||
|
||||
#if LAME_ALPHA_VERSION
|
||||
#define LAME_PATCH_LEVEL_STRING " alpha " STR(LAME_PATCH_VERSION)
|
||||
#endif
|
||||
#if LAME_BETA_VERSION
|
||||
#define LAME_PATCH_LEVEL_STRING " beta " STR(LAME_PATCH_VERSION)
|
||||
#endif
|
||||
#if LAME_RELEASE_VERSION
|
||||
#if LAME_PATCH_VERSION
|
||||
#define LAME_PATCH_LEVEL_STRING " release " STR(LAME_PATCH_VERSION)
|
||||
#else
|
||||
#define LAME_PATCH_LEVEL_STRING ""
|
||||
#endif
|
||||
#endif
|
||||
|
||||
# define LAME_VERSION_STRING STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) LAME_PATCH_LEVEL_STRING
|
||||
|
||||
#endif /* LAME_VERSION_H */
|
||||
|
||||
/* End of version.h */
|
||||
@@ -0,0 +1,16 @@
|
||||
Michael Hipp <mh@mpg123.de> Author of orignal mpglib version 0.2a.
|
||||
|
||||
Albert L. Faber <afaber@users.sf.net>
|
||||
Aleksander Korzynski <olcios@users.sf.net>
|
||||
Alexander Leidinger <aleidinger@users.sf.net>
|
||||
Frank Klemm <pfk@users.sf.net>
|
||||
Gabriel Bouvigne <bouvigne@users.sf.net>
|
||||
Leigh Smith <leighsmith@users.sf.net>
|
||||
Mark Taylor <markt@users.sf.net>
|
||||
Myers Carpenter <myers@users.sf.net>
|
||||
Naoki Shibata <shibatch@users.sf.net>
|
||||
Robert Hegemann <robert@users.sf.net>
|
||||
Sigbjorn Skjaeret <cisc@users.sf.net>
|
||||
Stefan Bellon <sbellon@users.sf.net>
|
||||
Steve Lhomme <robux4@users.sf.net>
|
||||
Takehiro TOMINAGA <takehiro@users.sf.net>
|
||||
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
* common.c: some common bitstream operations
|
||||
*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* $Id: common.c,v 1.42 2017/08/19 14:20:27 robert Exp $ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifdef macintosh
|
||||
#include <types.h>
|
||||
#include <stat.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif
|
||||
|
||||
/* In C++ the array first must be prototyped, why ? */
|
||||
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
const int tabsel_123 [2] [3] [16] = {
|
||||
{ {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},
|
||||
{0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,},
|
||||
{0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,} },
|
||||
|
||||
{ {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,},
|
||||
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,},
|
||||
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} }
|
||||
};
|
||||
|
||||
const long freqs[9] = { 44100, 48000, 32000,
|
||||
22050, 24000, 16000,
|
||||
11025, 12000, 8000 };
|
||||
|
||||
/* *INDENT-ON* */
|
||||
|
||||
|
||||
real muls[27][64];
|
||||
|
||||
#if 0
|
||||
static void
|
||||
get_II_stuff(struct frame *fr)
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
static const int translate [3] [2] [16] = /* char ? */
|
||||
{ { { 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0 } ,
|
||||
{ 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0 } } ,
|
||||
{ { 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0 } ,
|
||||
{ 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0 } } ,
|
||||
{ { 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0 } ,
|
||||
{ 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0 } } };
|
||||
/* *INDENT-ON* */
|
||||
|
||||
int table, sblim;
|
||||
static const struct al_table2 *tables[5] = { alloc_0, alloc_1, alloc_2, alloc_3, alloc_4 };
|
||||
static int sblims[5] = { 27, 30, 8, 12, 30 };
|
||||
|
||||
if (fr->lsf)
|
||||
table = 4;
|
||||
else
|
||||
table = translate[fr->sampling_frequency][2 - fr->stereo][fr->bitrate_index];
|
||||
sblim = sblims[table];
|
||||
|
||||
fr->alloc = tables[table];
|
||||
fr->II_sblimit = sblim;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define HDRCMPMASK 0xfffffd00
|
||||
|
||||
#define MAX_INPUT_FRAMESIZE 4096
|
||||
|
||||
int
|
||||
head_check(unsigned long head, int check_layer)
|
||||
{
|
||||
/*
|
||||
look for a valid header.
|
||||
if check_layer > 0, then require that
|
||||
nLayer = check_layer.
|
||||
*/
|
||||
|
||||
/* bits 13-14 = layer 3 */
|
||||
int nLayer = 4 - ((head >> 17) & 3);
|
||||
|
||||
if ((head & 0xffe00000) != 0xffe00000) {
|
||||
/* syncword */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (nLayer == 4)
|
||||
return FALSE;
|
||||
|
||||
if (check_layer > 0 && nLayer != check_layer)
|
||||
return FALSE;
|
||||
|
||||
if (((head >> 12) & 0xf) == 0xf) {
|
||||
/* bits 16,17,18,19 = 1111 invalid bitrate */
|
||||
return FALSE;
|
||||
}
|
||||
if (((head >> 10) & 0x3) == 0x3) {
|
||||
/* bits 20,21 = 11 invalid sampling freq */
|
||||
return FALSE;
|
||||
}
|
||||
if ((head & 0x3) == 0x2)
|
||||
/* invalid emphasis */
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
static void
|
||||
print_header(PMPSTR mp, struct frame *fr)
|
||||
{
|
||||
static const char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" };
|
||||
static const char *layers[4] = { "Unknown", "I", "II", "III" };
|
||||
|
||||
lame_report_fnc(mp->report_msg, "MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n",
|
||||
fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
|
||||
layers[fr->lay], freqs[fr->sampling_frequency],
|
||||
modes[fr->mode], fr->mode_ext, fr->framesize + 4);
|
||||
lame_report_fnc(mp->report_msg, "Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n",
|
||||
fr->stereo, fr->copyright ? "Yes" : "No",
|
||||
fr->original ? "Yes" : "No", fr->error_protection ? "Yes" : "No", fr->emphasis);
|
||||
lame_report_fnc(mp->report_msg, "Bitrate: %d Kbits/s, Extension value: %d\n",
|
||||
tabsel_123[fr->lsf][fr->lay - 1][fr->bitrate_index], fr->extension);
|
||||
}
|
||||
|
||||
static void
|
||||
print_header_compact(PMPSTR mp, struct frame *fr)
|
||||
{
|
||||
static const char *modes[4] = { "stereo", "joint-stereo", "dual-channel", "mono" };
|
||||
static const char *layers[4] = { "Unknown", "I", "II", "III" };
|
||||
|
||||
lame_report_fnc(mp->report_err, "MPEG %s layer %s, %d kbit/s, %ld Hz %s\n",
|
||||
fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
|
||||
layers[fr->lay],
|
||||
tabsel_123[fr->lsf][fr->lay - 1][fr->bitrate_index],
|
||||
freqs[fr->sampling_frequency], modes[fr->mode]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* decode a header and write the information
|
||||
* into the frame structure
|
||||
*/
|
||||
int
|
||||
decode_header(PMPSTR mp, struct frame *fr, unsigned long newhead)
|
||||
{
|
||||
|
||||
|
||||
if (newhead & (1 << 20)) {
|
||||
fr->lsf = (newhead & (1 << 19)) ? 0x0 : 0x1;
|
||||
fr->mpeg25 = 0;
|
||||
}
|
||||
else {
|
||||
fr->lsf = 1;
|
||||
fr->mpeg25 = 1;
|
||||
}
|
||||
|
||||
|
||||
fr->lay = 4 - ((newhead >> 17) & 3);
|
||||
|
||||
if (fr->lay != 3 && fr->mpeg25) {
|
||||
lame_report_fnc(mp->report_err, "MPEG-2.5 is supported by Layer3 only\n");
|
||||
return 0;
|
||||
}
|
||||
if (((newhead >> 10) & 0x3) == 0x3) {
|
||||
lame_report_fnc(mp->report_err, "Stream error\n");
|
||||
return 0;
|
||||
}
|
||||
if (fr->mpeg25) {
|
||||
fr->sampling_frequency = 6 + ((newhead >> 10) & 0x3);
|
||||
}
|
||||
else
|
||||
fr->sampling_frequency = ((newhead >> 10) & 0x3) + (fr->lsf * 3);
|
||||
|
||||
fr->error_protection = ((newhead >> 16) & 0x1) ^ 0x1;
|
||||
|
||||
if (fr->mpeg25) /* allow Bitrate change for 2.5 ... */
|
||||
fr->bitrate_index = ((newhead >> 12) & 0xf);
|
||||
|
||||
fr->bitrate_index = ((newhead >> 12) & 0xf);
|
||||
fr->padding = ((newhead >> 9) & 0x1);
|
||||
fr->extension = ((newhead >> 8) & 0x1);
|
||||
fr->mode = ((newhead >> 6) & 0x3);
|
||||
fr->mode_ext = ((newhead >> 4) & 0x3);
|
||||
fr->copyright = ((newhead >> 3) & 0x1);
|
||||
fr->original = ((newhead >> 2) & 0x1);
|
||||
fr->emphasis = newhead & 0x3;
|
||||
|
||||
fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2;
|
||||
|
||||
switch (fr->lay) {
|
||||
case 1:
|
||||
fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
|
||||
fr->framesize /= freqs[fr->sampling_frequency];
|
||||
fr->framesize = ((fr->framesize + fr->padding) << 2) - 4;
|
||||
fr->down_sample = 0;
|
||||
fr->down_sample_sblimit = SBLIMIT >> (fr->down_sample);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
|
||||
fr->framesize /= freqs[fr->sampling_frequency];
|
||||
fr->framesize += fr->padding - 4;
|
||||
fr->down_sample = 0;
|
||||
fr->down_sample_sblimit = SBLIMIT >> (fr->down_sample);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
#if 0
|
||||
fr->do_layer = do_layer3;
|
||||
if (fr->lsf)
|
||||
ssize = (fr->stereo == 1) ? 9 : 17;
|
||||
else
|
||||
ssize = (fr->stereo == 1) ? 17 : 32;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
if (fr->error_protection)
|
||||
ssize += 2;
|
||||
#endif
|
||||
if (fr->framesize > MAX_INPUT_FRAMESIZE) {
|
||||
lame_report_fnc(mp->report_err, "Frame size too big.\n");
|
||||
fr->framesize = MAX_INPUT_FRAMESIZE;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
if (fr->bitrate_index == 0)
|
||||
fr->framesize = 0;
|
||||
else {
|
||||
fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
|
||||
fr->framesize /= freqs[fr->sampling_frequency] << (fr->lsf);
|
||||
fr->framesize = fr->framesize + fr->padding - 4;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lame_report_fnc(mp->report_err, "Sorry, layer %d not supported\n", fr->lay);
|
||||
return (0);
|
||||
}
|
||||
/* print_header(mp, fr); */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
unsigned int
|
||||
getbits(PMPSTR mp, int number_of_bits)
|
||||
{
|
||||
unsigned long rval;
|
||||
|
||||
if (number_of_bits <= 0 || !mp->wordpointer)
|
||||
return 0;
|
||||
|
||||
{
|
||||
rval = mp->wordpointer[0];
|
||||
rval <<= 8;
|
||||
rval |= mp->wordpointer[1];
|
||||
rval <<= 8;
|
||||
rval |= mp->wordpointer[2];
|
||||
rval <<= mp->bitindex;
|
||||
rval &= 0xffffff;
|
||||
|
||||
mp->bitindex += number_of_bits;
|
||||
|
||||
rval >>= (24 - number_of_bits);
|
||||
|
||||
mp->wordpointer += (mp->bitindex >> 3);
|
||||
mp->bitindex &= 7;
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
getbits_fast(PMPSTR mp, int number_of_bits)
|
||||
{
|
||||
unsigned long rval;
|
||||
|
||||
{
|
||||
rval = mp->wordpointer[0];
|
||||
rval <<= 8;
|
||||
rval |= mp->wordpointer[1];
|
||||
rval <<= mp->bitindex;
|
||||
rval &= 0xffff;
|
||||
mp->bitindex += number_of_bits;
|
||||
|
||||
rval >>= (16 - number_of_bits);
|
||||
|
||||
mp->wordpointer += (mp->bitindex >> 3);
|
||||
mp->bitindex &= 7;
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
|
||||
unsigned char
|
||||
get_leq_8_bits(PMPSTR mp, unsigned int number_of_bits)
|
||||
{
|
||||
assert(number_of_bits <= 8);
|
||||
return (unsigned char) getbits_fast(mp, number_of_bits);
|
||||
}
|
||||
|
||||
unsigned short
|
||||
get_leq_16_bits(PMPSTR mp, unsigned int number_of_bits)
|
||||
{
|
||||
assert(number_of_bits <= 16);
|
||||
return (unsigned short) getbits_fast(mp, number_of_bits);
|
||||
}
|
||||
|
||||
int
|
||||
set_pointer(PMPSTR mp, long backstep)
|
||||
{
|
||||
unsigned char *bsbufold;
|
||||
|
||||
if (mp->fsizeold < 0 && backstep > 0) {
|
||||
lame_report_fnc(mp->report_err, "hip: Can't step back %ld bytes!\n", backstep);
|
||||
return MP3_ERR;
|
||||
}
|
||||
bsbufold = mp->bsspace[1 - mp->bsnum] + 512;
|
||||
mp->wordpointer -= backstep;
|
||||
if (backstep)
|
||||
memcpy(mp->wordpointer, bsbufold + mp->fsizeold - backstep, (size_t) backstep);
|
||||
mp->bitindex = 0;
|
||||
return MP3_OK;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef COMMON_H_INCLUDED
|
||||
#define COMMON_H_INCLUDED
|
||||
|
||||
#include "mpg123.h"
|
||||
#include "mpglib.h"
|
||||
|
||||
extern const int tabsel_123[2][3][16];
|
||||
extern const long freqs[9];
|
||||
|
||||
extern real muls[27][64];
|
||||
|
||||
|
||||
int head_check(unsigned long head, int check_layer);
|
||||
int decode_header(PMPSTR mp, struct frame *fr, unsigned long newhead);
|
||||
unsigned int getbits(PMPSTR mp, int number_of_bits);
|
||||
unsigned int getbits_fast(PMPSTR mp, int number_of_bits);
|
||||
unsigned char get_leq_8_bits(PMPSTR mp, unsigned int number_of_bits);
|
||||
unsigned short get_leq_16_bits(PMPSTR mp, unsigned int number_of_bits);
|
||||
int set_pointer(PMPSTR mp, long backstep);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,348 @@
|
||||
/*
|
||||
* dct64_i368.c
|
||||
*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Discrete Cosine Tansform (DCT) for subband synthesis
|
||||
* optimized for machines with no auto-increment.
|
||||
* The performance is highly compiler dependend. Maybe
|
||||
* the dct64.c version for 'normal' processor may be faster
|
||||
* even for Intel processors.
|
||||
*/
|
||||
|
||||
/* $Id: dct64_i386.c,v 1.14 2010/03/22 14:30:19 robert Exp $ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "dct64_i386.h"
|
||||
#include "tabinit.h"
|
||||
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif
|
||||
|
||||
static void
|
||||
dct64_1(real * out0, real * out1, real * b1, real * b2, real * samples)
|
||||
{
|
||||
|
||||
{
|
||||
real *costab = pnts[0];
|
||||
|
||||
b1[0x00] = samples[0x00] + samples[0x1F];
|
||||
b1[0x1F] = (samples[0x00] - samples[0x1F]) * costab[0x0];
|
||||
|
||||
b1[0x01] = samples[0x01] + samples[0x1E];
|
||||
b1[0x1E] = (samples[0x01] - samples[0x1E]) * costab[0x1];
|
||||
|
||||
b1[0x02] = samples[0x02] + samples[0x1D];
|
||||
b1[0x1D] = (samples[0x02] - samples[0x1D]) * costab[0x2];
|
||||
|
||||
b1[0x03] = samples[0x03] + samples[0x1C];
|
||||
b1[0x1C] = (samples[0x03] - samples[0x1C]) * costab[0x3];
|
||||
|
||||
b1[0x04] = samples[0x04] + samples[0x1B];
|
||||
b1[0x1B] = (samples[0x04] - samples[0x1B]) * costab[0x4];
|
||||
|
||||
b1[0x05] = samples[0x05] + samples[0x1A];
|
||||
b1[0x1A] = (samples[0x05] - samples[0x1A]) * costab[0x5];
|
||||
|
||||
b1[0x06] = samples[0x06] + samples[0x19];
|
||||
b1[0x19] = (samples[0x06] - samples[0x19]) * costab[0x6];
|
||||
|
||||
b1[0x07] = samples[0x07] + samples[0x18];
|
||||
b1[0x18] = (samples[0x07] - samples[0x18]) * costab[0x7];
|
||||
|
||||
b1[0x08] = samples[0x08] + samples[0x17];
|
||||
b1[0x17] = (samples[0x08] - samples[0x17]) * costab[0x8];
|
||||
|
||||
b1[0x09] = samples[0x09] + samples[0x16];
|
||||
b1[0x16] = (samples[0x09] - samples[0x16]) * costab[0x9];
|
||||
|
||||
b1[0x0A] = samples[0x0A] + samples[0x15];
|
||||
b1[0x15] = (samples[0x0A] - samples[0x15]) * costab[0xA];
|
||||
|
||||
b1[0x0B] = samples[0x0B] + samples[0x14];
|
||||
b1[0x14] = (samples[0x0B] - samples[0x14]) * costab[0xB];
|
||||
|
||||
b1[0x0C] = samples[0x0C] + samples[0x13];
|
||||
b1[0x13] = (samples[0x0C] - samples[0x13]) * costab[0xC];
|
||||
|
||||
b1[0x0D] = samples[0x0D] + samples[0x12];
|
||||
b1[0x12] = (samples[0x0D] - samples[0x12]) * costab[0xD];
|
||||
|
||||
b1[0x0E] = samples[0x0E] + samples[0x11];
|
||||
b1[0x11] = (samples[0x0E] - samples[0x11]) * costab[0xE];
|
||||
|
||||
b1[0x0F] = samples[0x0F] + samples[0x10];
|
||||
b1[0x10] = (samples[0x0F] - samples[0x10]) * costab[0xF];
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
real *costab = pnts[1];
|
||||
|
||||
b2[0x00] = b1[0x00] + b1[0x0F];
|
||||
b2[0x0F] = (b1[0x00] - b1[0x0F]) * costab[0];
|
||||
b2[0x01] = b1[0x01] + b1[0x0E];
|
||||
b2[0x0E] = (b1[0x01] - b1[0x0E]) * costab[1];
|
||||
b2[0x02] = b1[0x02] + b1[0x0D];
|
||||
b2[0x0D] = (b1[0x02] - b1[0x0D]) * costab[2];
|
||||
b2[0x03] = b1[0x03] + b1[0x0C];
|
||||
b2[0x0C] = (b1[0x03] - b1[0x0C]) * costab[3];
|
||||
b2[0x04] = b1[0x04] + b1[0x0B];
|
||||
b2[0x0B] = (b1[0x04] - b1[0x0B]) * costab[4];
|
||||
b2[0x05] = b1[0x05] + b1[0x0A];
|
||||
b2[0x0A] = (b1[0x05] - b1[0x0A]) * costab[5];
|
||||
b2[0x06] = b1[0x06] + b1[0x09];
|
||||
b2[0x09] = (b1[0x06] - b1[0x09]) * costab[6];
|
||||
b2[0x07] = b1[0x07] + b1[0x08];
|
||||
b2[0x08] = (b1[0x07] - b1[0x08]) * costab[7];
|
||||
|
||||
b2[0x10] = b1[0x10] + b1[0x1F];
|
||||
b2[0x1F] = (b1[0x1F] - b1[0x10]) * costab[0];
|
||||
b2[0x11] = b1[0x11] + b1[0x1E];
|
||||
b2[0x1E] = (b1[0x1E] - b1[0x11]) * costab[1];
|
||||
b2[0x12] = b1[0x12] + b1[0x1D];
|
||||
b2[0x1D] = (b1[0x1D] - b1[0x12]) * costab[2];
|
||||
b2[0x13] = b1[0x13] + b1[0x1C];
|
||||
b2[0x1C] = (b1[0x1C] - b1[0x13]) * costab[3];
|
||||
b2[0x14] = b1[0x14] + b1[0x1B];
|
||||
b2[0x1B] = (b1[0x1B] - b1[0x14]) * costab[4];
|
||||
b2[0x15] = b1[0x15] + b1[0x1A];
|
||||
b2[0x1A] = (b1[0x1A] - b1[0x15]) * costab[5];
|
||||
b2[0x16] = b1[0x16] + b1[0x19];
|
||||
b2[0x19] = (b1[0x19] - b1[0x16]) * costab[6];
|
||||
b2[0x17] = b1[0x17] + b1[0x18];
|
||||
b2[0x18] = (b1[0x18] - b1[0x17]) * costab[7];
|
||||
}
|
||||
|
||||
{
|
||||
real *costab = pnts[2];
|
||||
|
||||
b1[0x00] = b2[0x00] + b2[0x07];
|
||||
b1[0x07] = (b2[0x00] - b2[0x07]) * costab[0];
|
||||
b1[0x01] = b2[0x01] + b2[0x06];
|
||||
b1[0x06] = (b2[0x01] - b2[0x06]) * costab[1];
|
||||
b1[0x02] = b2[0x02] + b2[0x05];
|
||||
b1[0x05] = (b2[0x02] - b2[0x05]) * costab[2];
|
||||
b1[0x03] = b2[0x03] + b2[0x04];
|
||||
b1[0x04] = (b2[0x03] - b2[0x04]) * costab[3];
|
||||
|
||||
b1[0x08] = b2[0x08] + b2[0x0F];
|
||||
b1[0x0F] = (b2[0x0F] - b2[0x08]) * costab[0];
|
||||
b1[0x09] = b2[0x09] + b2[0x0E];
|
||||
b1[0x0E] = (b2[0x0E] - b2[0x09]) * costab[1];
|
||||
b1[0x0A] = b2[0x0A] + b2[0x0D];
|
||||
b1[0x0D] = (b2[0x0D] - b2[0x0A]) * costab[2];
|
||||
b1[0x0B] = b2[0x0B] + b2[0x0C];
|
||||
b1[0x0C] = (b2[0x0C] - b2[0x0B]) * costab[3];
|
||||
|
||||
b1[0x10] = b2[0x10] + b2[0x17];
|
||||
b1[0x17] = (b2[0x10] - b2[0x17]) * costab[0];
|
||||
b1[0x11] = b2[0x11] + b2[0x16];
|
||||
b1[0x16] = (b2[0x11] - b2[0x16]) * costab[1];
|
||||
b1[0x12] = b2[0x12] + b2[0x15];
|
||||
b1[0x15] = (b2[0x12] - b2[0x15]) * costab[2];
|
||||
b1[0x13] = b2[0x13] + b2[0x14];
|
||||
b1[0x14] = (b2[0x13] - b2[0x14]) * costab[3];
|
||||
|
||||
b1[0x18] = b2[0x18] + b2[0x1F];
|
||||
b1[0x1F] = (b2[0x1F] - b2[0x18]) * costab[0];
|
||||
b1[0x19] = b2[0x19] + b2[0x1E];
|
||||
b1[0x1E] = (b2[0x1E] - b2[0x19]) * costab[1];
|
||||
b1[0x1A] = b2[0x1A] + b2[0x1D];
|
||||
b1[0x1D] = (b2[0x1D] - b2[0x1A]) * costab[2];
|
||||
b1[0x1B] = b2[0x1B] + b2[0x1C];
|
||||
b1[0x1C] = (b2[0x1C] - b2[0x1B]) * costab[3];
|
||||
}
|
||||
|
||||
{
|
||||
real const cos0 = pnts[3][0];
|
||||
real const cos1 = pnts[3][1];
|
||||
|
||||
b2[0x00] = b1[0x00] + b1[0x03];
|
||||
b2[0x03] = (b1[0x00] - b1[0x03]) * cos0;
|
||||
b2[0x01] = b1[0x01] + b1[0x02];
|
||||
b2[0x02] = (b1[0x01] - b1[0x02]) * cos1;
|
||||
|
||||
b2[0x04] = b1[0x04] + b1[0x07];
|
||||
b2[0x07] = (b1[0x07] - b1[0x04]) * cos0;
|
||||
b2[0x05] = b1[0x05] + b1[0x06];
|
||||
b2[0x06] = (b1[0x06] - b1[0x05]) * cos1;
|
||||
|
||||
b2[0x08] = b1[0x08] + b1[0x0B];
|
||||
b2[0x0B] = (b1[0x08] - b1[0x0B]) * cos0;
|
||||
b2[0x09] = b1[0x09] + b1[0x0A];
|
||||
b2[0x0A] = (b1[0x09] - b1[0x0A]) * cos1;
|
||||
|
||||
b2[0x0C] = b1[0x0C] + b1[0x0F];
|
||||
b2[0x0F] = (b1[0x0F] - b1[0x0C]) * cos0;
|
||||
b2[0x0D] = b1[0x0D] + b1[0x0E];
|
||||
b2[0x0E] = (b1[0x0E] - b1[0x0D]) * cos1;
|
||||
|
||||
b2[0x10] = b1[0x10] + b1[0x13];
|
||||
b2[0x13] = (b1[0x10] - b1[0x13]) * cos0;
|
||||
b2[0x11] = b1[0x11] + b1[0x12];
|
||||
b2[0x12] = (b1[0x11] - b1[0x12]) * cos1;
|
||||
|
||||
b2[0x14] = b1[0x14] + b1[0x17];
|
||||
b2[0x17] = (b1[0x17] - b1[0x14]) * cos0;
|
||||
b2[0x15] = b1[0x15] + b1[0x16];
|
||||
b2[0x16] = (b1[0x16] - b1[0x15]) * cos1;
|
||||
|
||||
b2[0x18] = b1[0x18] + b1[0x1B];
|
||||
b2[0x1B] = (b1[0x18] - b1[0x1B]) * cos0;
|
||||
b2[0x19] = b1[0x19] + b1[0x1A];
|
||||
b2[0x1A] = (b1[0x19] - b1[0x1A]) * cos1;
|
||||
|
||||
b2[0x1C] = b1[0x1C] + b1[0x1F];
|
||||
b2[0x1F] = (b1[0x1F] - b1[0x1C]) * cos0;
|
||||
b2[0x1D] = b1[0x1D] + b1[0x1E];
|
||||
b2[0x1E] = (b1[0x1E] - b1[0x1D]) * cos1;
|
||||
}
|
||||
|
||||
{
|
||||
real const cos0 = pnts[4][0];
|
||||
|
||||
b1[0x00] = b2[0x00] + b2[0x01];
|
||||
b1[0x01] = (b2[0x00] - b2[0x01]) * cos0;
|
||||
b1[0x02] = b2[0x02] + b2[0x03];
|
||||
b1[0x03] = (b2[0x03] - b2[0x02]) * cos0;
|
||||
b1[0x02] += b1[0x03];
|
||||
|
||||
b1[0x04] = b2[0x04] + b2[0x05];
|
||||
b1[0x05] = (b2[0x04] - b2[0x05]) * cos0;
|
||||
b1[0x06] = b2[0x06] + b2[0x07];
|
||||
b1[0x07] = (b2[0x07] - b2[0x06]) * cos0;
|
||||
b1[0x06] += b1[0x07];
|
||||
b1[0x04] += b1[0x06];
|
||||
b1[0x06] += b1[0x05];
|
||||
b1[0x05] += b1[0x07];
|
||||
|
||||
b1[0x08] = b2[0x08] + b2[0x09];
|
||||
b1[0x09] = (b2[0x08] - b2[0x09]) * cos0;
|
||||
b1[0x0A] = b2[0x0A] + b2[0x0B];
|
||||
b1[0x0B] = (b2[0x0B] - b2[0x0A]) * cos0;
|
||||
b1[0x0A] += b1[0x0B];
|
||||
|
||||
b1[0x0C] = b2[0x0C] + b2[0x0D];
|
||||
b1[0x0D] = (b2[0x0C] - b2[0x0D]) * cos0;
|
||||
b1[0x0E] = b2[0x0E] + b2[0x0F];
|
||||
b1[0x0F] = (b2[0x0F] - b2[0x0E]) * cos0;
|
||||
b1[0x0E] += b1[0x0F];
|
||||
b1[0x0C] += b1[0x0E];
|
||||
b1[0x0E] += b1[0x0D];
|
||||
b1[0x0D] += b1[0x0F];
|
||||
|
||||
b1[0x10] = b2[0x10] + b2[0x11];
|
||||
b1[0x11] = (b2[0x10] - b2[0x11]) * cos0;
|
||||
b1[0x12] = b2[0x12] + b2[0x13];
|
||||
b1[0x13] = (b2[0x13] - b2[0x12]) * cos0;
|
||||
b1[0x12] += b1[0x13];
|
||||
|
||||
b1[0x14] = b2[0x14] + b2[0x15];
|
||||
b1[0x15] = (b2[0x14] - b2[0x15]) * cos0;
|
||||
b1[0x16] = b2[0x16] + b2[0x17];
|
||||
b1[0x17] = (b2[0x17] - b2[0x16]) * cos0;
|
||||
b1[0x16] += b1[0x17];
|
||||
b1[0x14] += b1[0x16];
|
||||
b1[0x16] += b1[0x15];
|
||||
b1[0x15] += b1[0x17];
|
||||
|
||||
b1[0x18] = b2[0x18] + b2[0x19];
|
||||
b1[0x19] = (b2[0x18] - b2[0x19]) * cos0;
|
||||
b1[0x1A] = b2[0x1A] + b2[0x1B];
|
||||
b1[0x1B] = (b2[0x1B] - b2[0x1A]) * cos0;
|
||||
b1[0x1A] += b1[0x1B];
|
||||
|
||||
b1[0x1C] = b2[0x1C] + b2[0x1D];
|
||||
b1[0x1D] = (b2[0x1C] - b2[0x1D]) * cos0;
|
||||
b1[0x1E] = b2[0x1E] + b2[0x1F];
|
||||
b1[0x1F] = (b2[0x1F] - b2[0x1E]) * cos0;
|
||||
b1[0x1E] += b1[0x1F];
|
||||
b1[0x1C] += b1[0x1E];
|
||||
b1[0x1E] += b1[0x1D];
|
||||
b1[0x1D] += b1[0x1F];
|
||||
}
|
||||
|
||||
out0[0x10 * 16] = b1[0x00];
|
||||
out0[0x10 * 12] = b1[0x04];
|
||||
out0[0x10 * 8] = b1[0x02];
|
||||
out0[0x10 * 4] = b1[0x06];
|
||||
out0[0x10 * 0] = b1[0x01];
|
||||
out1[0x10 * 0] = b1[0x01];
|
||||
out1[0x10 * 4] = b1[0x05];
|
||||
out1[0x10 * 8] = b1[0x03];
|
||||
out1[0x10 * 12] = b1[0x07];
|
||||
|
||||
b1[0x08] += b1[0x0C];
|
||||
out0[0x10 * 14] = b1[0x08];
|
||||
b1[0x0C] += b1[0x0a];
|
||||
out0[0x10 * 10] = b1[0x0C];
|
||||
b1[0x0A] += b1[0x0E];
|
||||
out0[0x10 * 6] = b1[0x0A];
|
||||
b1[0x0E] += b1[0x09];
|
||||
out0[0x10 * 2] = b1[0x0E];
|
||||
b1[0x09] += b1[0x0D];
|
||||
out1[0x10 * 2] = b1[0x09];
|
||||
b1[0x0D] += b1[0x0B];
|
||||
out1[0x10 * 6] = b1[0x0D];
|
||||
b1[0x0B] += b1[0x0F];
|
||||
out1[0x10 * 10] = b1[0x0B];
|
||||
out1[0x10 * 14] = b1[0x0F];
|
||||
|
||||
b1[0x18] += b1[0x1C];
|
||||
out0[0x10 * 15] = b1[0x10] + b1[0x18];
|
||||
out0[0x10 * 13] = b1[0x18] + b1[0x14];
|
||||
b1[0x1C] += b1[0x1a];
|
||||
out0[0x10 * 11] = b1[0x14] + b1[0x1C];
|
||||
out0[0x10 * 9] = b1[0x1C] + b1[0x12];
|
||||
b1[0x1A] += b1[0x1E];
|
||||
out0[0x10 * 7] = b1[0x12] + b1[0x1A];
|
||||
out0[0x10 * 5] = b1[0x1A] + b1[0x16];
|
||||
b1[0x1E] += b1[0x19];
|
||||
out0[0x10 * 3] = b1[0x16] + b1[0x1E];
|
||||
out0[0x10 * 1] = b1[0x1E] + b1[0x11];
|
||||
b1[0x19] += b1[0x1D];
|
||||
out1[0x10 * 1] = b1[0x11] + b1[0x19];
|
||||
out1[0x10 * 3] = b1[0x19] + b1[0x15];
|
||||
b1[0x1D] += b1[0x1B];
|
||||
out1[0x10 * 5] = b1[0x15] + b1[0x1D];
|
||||
out1[0x10 * 7] = b1[0x1D] + b1[0x13];
|
||||
b1[0x1B] += b1[0x1F];
|
||||
out1[0x10 * 9] = b1[0x13] + b1[0x1B];
|
||||
out1[0x10 * 11] = b1[0x1B] + b1[0x17];
|
||||
out1[0x10 * 13] = b1[0x17] + b1[0x1F];
|
||||
out1[0x10 * 15] = b1[0x1F];
|
||||
}
|
||||
|
||||
/*
|
||||
* the call via dct64 is a trick to force GCC to use
|
||||
* (new) registers for the b1,b2 pointer to the bufs[xx] field
|
||||
*/
|
||||
void
|
||||
dct64(real * a, real * b, real * c)
|
||||
{
|
||||
real bufs[0x40];
|
||||
dct64_1(a, b, bufs, bufs + 0x20, c);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MPGLIB_DCT64_I386_H_INCLUDED
|
||||
#define MPGLIB_DCT64_I386_H_INCLUDED
|
||||
|
||||
#include "common.h"
|
||||
|
||||
void dct64(real * a, real * b, real * c);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* decode_i396.c: Mpeg Layer-1,2,3 audio decoder
|
||||
*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Slighlty optimized for machines without autoincrement/decrement.
|
||||
* The performance is highly compiler dependend. Maybe
|
||||
* the decode.c version for 'normal' processor may be faster
|
||||
* even for Intel processors.
|
||||
*/
|
||||
|
||||
/* $Id: decode_i386.c,v 1.22 2010/03/22 14:30:19 robert Exp $ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
#else
|
||||
# ifndef HAVE_STRCHR
|
||||
# define strchr index
|
||||
# define strrchr rindex
|
||||
# endif
|
||||
char *strchr(), *strrchr();
|
||||
# ifndef HAVE_MEMCPY
|
||||
# define memcpy(d, s, n) bcopy ((s), (d), (n))
|
||||
# define memmove(d, s, n) bcopy ((s), (d), (n))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__riscos__) && defined(FPA10)
|
||||
#include "ymath.h"
|
||||
#else
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
#include "decode_i386.h"
|
||||
#include "dct64_i386.h"
|
||||
#include "tabinit.h"
|
||||
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* old WRITE_SAMPLE_CLIPPED */
|
||||
#define WRITE_SAMPLE_CLIPPED(TYPE,samples,sum,clip) \
|
||||
if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
|
||||
else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
|
||||
else { *(samples) = (TYPE)((sum)>0 ? (sum)+0.5 : (sum)-0.5) ; }
|
||||
|
||||
#define WRITE_SAMPLE_UNCLIPPED(TYPE,samples,sum,clip) \
|
||||
*samples = (TYPE)sum;
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
|
||||
/* versions: clipped (when TYPE == short) and unclipped (when TYPE == real) of synth_1to1_mono* functions */
|
||||
#define SYNTH_1TO1_MONO_CLIPCHOICE(TYPE,SYNTH_1TO1) \
|
||||
TYPE samples_tmp[64]; \
|
||||
TYPE *tmp1 = samples_tmp; \
|
||||
int i,ret; \
|
||||
int pnt1 = 0; \
|
||||
\
|
||||
ret = SYNTH_1TO1 (mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1); \
|
||||
out += *pnt; \
|
||||
\
|
||||
for(i=0;i<32;i++) { \
|
||||
*( (TYPE *) out) = *tmp1; \
|
||||
out += sizeof(TYPE); \
|
||||
tmp1 += 2; \
|
||||
} \
|
||||
*pnt += 32*sizeof(TYPE); \
|
||||
\
|
||||
return ret;
|
||||
|
||||
/* *INDENT-ON* */
|
||||
|
||||
|
||||
int
|
||||
synth_1to1_mono(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt)
|
||||
{
|
||||
SYNTH_1TO1_MONO_CLIPCHOICE(short, synth_1to1)
|
||||
} int
|
||||
synth_1to1_mono_unclipped(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt)
|
||||
{
|
||||
SYNTH_1TO1_MONO_CLIPCHOICE(real, synth_1to1_unclipped)
|
||||
}
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
/* versions: clipped (when TYPE == short) and unclipped (when TYPE == real) of synth_1to1* functions */
|
||||
#define SYNTH_1TO1_CLIPCHOICE(TYPE,WRITE_SAMPLE) \
|
||||
static const int step = 2; \
|
||||
int bo; \
|
||||
TYPE *samples = (TYPE *) (out + *pnt); \
|
||||
\
|
||||
real *b0,(*buf)[0x110]; \
|
||||
int clip = 0; \
|
||||
int bo1; \
|
||||
\
|
||||
bo = mp->synth_bo; \
|
||||
\
|
||||
if(!channel) { \
|
||||
bo--; \
|
||||
bo &= 0xf; \
|
||||
buf = mp->synth_buffs[0]; \
|
||||
} \
|
||||
else { \
|
||||
samples++; \
|
||||
buf = mp->synth_buffs[1]; \
|
||||
} \
|
||||
\
|
||||
if(bo & 0x1) { \
|
||||
b0 = buf[0]; \
|
||||
bo1 = bo; \
|
||||
dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr); \
|
||||
} \
|
||||
else { \
|
||||
b0 = buf[1]; \
|
||||
bo1 = bo+1; \
|
||||
dct64(buf[0]+bo,buf[1]+bo+1,bandPtr); \
|
||||
} \
|
||||
\
|
||||
mp->synth_bo = bo; \
|
||||
\
|
||||
{ \
|
||||
int j; \
|
||||
real *window = decwin + 16 - bo1; \
|
||||
\
|
||||
for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step) \
|
||||
{ \
|
||||
real sum; \
|
||||
sum = window[0x0] * b0[0x0]; \
|
||||
sum -= window[0x1] * b0[0x1]; \
|
||||
sum += window[0x2] * b0[0x2]; \
|
||||
sum -= window[0x3] * b0[0x3]; \
|
||||
sum += window[0x4] * b0[0x4]; \
|
||||
sum -= window[0x5] * b0[0x5]; \
|
||||
sum += window[0x6] * b0[0x6]; \
|
||||
sum -= window[0x7] * b0[0x7]; \
|
||||
sum += window[0x8] * b0[0x8]; \
|
||||
sum -= window[0x9] * b0[0x9]; \
|
||||
sum += window[0xA] * b0[0xA]; \
|
||||
sum -= window[0xB] * b0[0xB]; \
|
||||
sum += window[0xC] * b0[0xC]; \
|
||||
sum -= window[0xD] * b0[0xD]; \
|
||||
sum += window[0xE] * b0[0xE]; \
|
||||
sum -= window[0xF] * b0[0xF]; \
|
||||
\
|
||||
WRITE_SAMPLE (TYPE,samples,sum,clip); \
|
||||
} \
|
||||
\
|
||||
{ \
|
||||
real sum; \
|
||||
sum = window[0x0] * b0[0x0]; \
|
||||
sum += window[0x2] * b0[0x2]; \
|
||||
sum += window[0x4] * b0[0x4]; \
|
||||
sum += window[0x6] * b0[0x6]; \
|
||||
sum += window[0x8] * b0[0x8]; \
|
||||
sum += window[0xA] * b0[0xA]; \
|
||||
sum += window[0xC] * b0[0xC]; \
|
||||
sum += window[0xE] * b0[0xE]; \
|
||||
WRITE_SAMPLE (TYPE,samples,sum,clip); \
|
||||
b0-=0x10,window-=0x20,samples+=step; \
|
||||
} \
|
||||
window += bo1<<1; \
|
||||
\
|
||||
for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step) \
|
||||
{ \
|
||||
real sum; \
|
||||
sum = -window[-0x1] * b0[0x0]; \
|
||||
sum -= window[-0x2] * b0[0x1]; \
|
||||
sum -= window[-0x3] * b0[0x2]; \
|
||||
sum -= window[-0x4] * b0[0x3]; \
|
||||
sum -= window[-0x5] * b0[0x4]; \
|
||||
sum -= window[-0x6] * b0[0x5]; \
|
||||
sum -= window[-0x7] * b0[0x6]; \
|
||||
sum -= window[-0x8] * b0[0x7]; \
|
||||
sum -= window[-0x9] * b0[0x8]; \
|
||||
sum -= window[-0xA] * b0[0x9]; \
|
||||
sum -= window[-0xB] * b0[0xA]; \
|
||||
sum -= window[-0xC] * b0[0xB]; \
|
||||
sum -= window[-0xD] * b0[0xC]; \
|
||||
sum -= window[-0xE] * b0[0xD]; \
|
||||
sum -= window[-0xF] * b0[0xE]; \
|
||||
sum -= window[-0x0] * b0[0xF]; \
|
||||
\
|
||||
WRITE_SAMPLE (TYPE,samples,sum,clip); \
|
||||
} \
|
||||
} \
|
||||
*pnt += 64*sizeof(TYPE); \
|
||||
\
|
||||
return clip;
|
||||
/* *INDENT-ON* */
|
||||
|
||||
|
||||
int
|
||||
synth_1to1(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
|
||||
{
|
||||
SYNTH_1TO1_CLIPCHOICE(short, WRITE_SAMPLE_CLIPPED)
|
||||
} int
|
||||
synth_1to1_unclipped(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
|
||||
{
|
||||
SYNTH_1TO1_CLIPCHOICE(real, WRITE_SAMPLE_UNCLIPPED)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef DECODE_I386_H_INCLUDED
|
||||
#define DECODE_I386_H_INCLUDED
|
||||
|
||||
#include "common.h"
|
||||
|
||||
int synth_1to1_mono(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt);
|
||||
int synth_1to1(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt);
|
||||
|
||||
int synth_1to1_mono_unclipped(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt);
|
||||
int synth_1to1_unclipped(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* huffman tables ... recalcualted to work with my optimzed
|
||||
* decoder scheme (MH)
|
||||
*
|
||||
* probably we could save a few bytes of memory, because the
|
||||
* smaller tables are often the part of a bigger table
|
||||
*/
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
|
||||
|
||||
struct newhuff
|
||||
{
|
||||
const unsigned int linbits;
|
||||
const short * const table;
|
||||
};
|
||||
|
||||
static const short tab0[] =
|
||||
{
|
||||
0
|
||||
};
|
||||
|
||||
static const short tab1[] =
|
||||
{
|
||||
-5, -3, -1, 17, 1, 16, 0
|
||||
};
|
||||
|
||||
static const short tab2[] =
|
||||
{
|
||||
-15, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 17, -1, 1, 16, 0
|
||||
};
|
||||
|
||||
static const short tab3[] =
|
||||
{
|
||||
-13, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 16, 17, -1,
|
||||
1, 0
|
||||
};
|
||||
|
||||
static const short tab5[] =
|
||||
{
|
||||
-29, -25, -23, -15, -7, -5, -3, -1, 51, 35, 50, 49, -3, -1, 19,
|
||||
3, -1, 48, 34, -3, -1, 18, 33, -1, 2, 32, 17, -1, 1, 16,
|
||||
0
|
||||
};
|
||||
|
||||
static const short tab6[] =
|
||||
{
|
||||
-25, -19, -13, -9, -5, -3, -1, 51, 3, 35, -1, 50, 48, -1, 19,
|
||||
49, -3, -1, 34, 2, 18, -3, -1, 33, 32, 1, -1, 17, -1, 16,
|
||||
0
|
||||
};
|
||||
|
||||
static const short tab7[] =
|
||||
{
|
||||
-69, -65, -57, -39, -29, -17, -11, -7, -3, -1, 85, 69, -1, 84, 83,
|
||||
-1, 53, 68, -3, -1, 37, 82, 21, -5, -1, 81, -1, 5, 52, -1,
|
||||
80, -1, 67, 51, -5, -3, -1, 36, 66, 20, -1, 65, 64, -11, -7,
|
||||
-3, -1, 4, 35, -1, 50, 3, -1, 19, 49, -3, -1, 48, 34, 18,
|
||||
-5, -1, 33, -1, 2, 32, 17, -1, 1, 16, 0
|
||||
};
|
||||
|
||||
static const short tab8[] =
|
||||
{
|
||||
-65, -63, -59, -45, -31, -19, -13, -7, -5, -3, -1, 85, 84, 69, 83,
|
||||
-3, -1, 53, 68, 37, -3, -1, 82, 5, 21, -5, -1, 81, -1, 52,
|
||||
67, -3, -1, 80, 51, 36, -5, -3, -1, 66, 20, 65, -3, -1, 4,
|
||||
64, -1, 35, 50, -9, -7, -3, -1, 19, 49, -1, 3, 48, 34, -1,
|
||||
2, 32, -1, 18, 33, 17, -3, -1, 1, 16, 0
|
||||
};
|
||||
|
||||
static const short tab9[] =
|
||||
{
|
||||
-63, -53, -41, -29, -19, -11, -5, -3, -1, 85, 69, 53, -1, 83, -1,
|
||||
84, 5, -3, -1, 68, 37, -1, 82, 21, -3, -1, 81, 52, -1, 67,
|
||||
-1, 80, 4, -7, -3, -1, 36, 66, -1, 51, 64, -1, 20, 65, -5,
|
||||
-3, -1, 35, 50, 19, -1, 49, -1, 3, 48, -5, -3, -1, 34, 2,
|
||||
18, -1, 33, 32, -3, -1, 17, 1, -1, 16, 0
|
||||
};
|
||||
|
||||
static const short tab10[] =
|
||||
{
|
||||
-125,-121,-111, -83, -55, -35, -21, -13, -7, -3, -1, 119, 103, -1, 118,
|
||||
87, -3, -1, 117, 102, 71, -3, -1, 116, 86, -1, 101, 55, -9, -3,
|
||||
-1, 115, 70, -3, -1, 85, 84, 99, -1, 39, 114, -11, -5, -3, -1,
|
||||
100, 7, 112, -1, 98, -1, 69, 53, -5, -1, 6, -1, 83, 68, 23,
|
||||
-17, -5, -1, 113, -1, 54, 38, -5, -3, -1, 37, 82, 21, -1, 81,
|
||||
-1, 52, 67, -3, -1, 22, 97, -1, 96, -1, 5, 80, -19, -11, -7,
|
||||
-3, -1, 36, 66, -1, 51, 4, -1, 20, 65, -3, -1, 64, 35, -1,
|
||||
50, 3, -3, -1, 19, 49, -1, 48, 34, -7, -3, -1, 18, 33, -1,
|
||||
2, 32, 17, -1, 1, 16, 0
|
||||
};
|
||||
|
||||
static const short tab11[] =
|
||||
{
|
||||
-121,-113, -89, -59, -43, -27, -17, -7, -3, -1, 119, 103, -1, 118, 117,
|
||||
-3, -1, 102, 71, -1, 116, -1, 87, 85, -5, -3, -1, 86, 101, 55,
|
||||
-1, 115, 70, -9, -7, -3, -1, 69, 84, -1, 53, 83, 39, -1, 114,
|
||||
-1, 100, 7, -5, -1, 113, -1, 23, 112, -3, -1, 54, 99, -1, 96,
|
||||
-1, 68, 37, -13, -7, -5, -3, -1, 82, 5, 21, 98, -3, -1, 38,
|
||||
6, 22, -5, -1, 97, -1, 81, 52, -5, -1, 80, -1, 67, 51, -1,
|
||||
36, 66, -15, -11, -7, -3, -1, 20, 65, -1, 4, 64, -1, 35, 50,
|
||||
-1, 19, 49, -5, -3, -1, 3, 48, 34, 33, -5, -1, 18, -1, 2,
|
||||
32, 17, -3, -1, 1, 16, 0
|
||||
};
|
||||
|
||||
static const short tab12[] =
|
||||
{
|
||||
-115, -99, -73, -45, -27, -17, -9, -5, -3, -1, 119, 103, 118, -1, 87,
|
||||
117, -3, -1, 102, 71, -1, 116, 101, -3, -1, 86, 55, -3, -1, 115,
|
||||
85, 39, -7, -3, -1, 114, 70, -1, 100, 23, -5, -1, 113, -1, 7,
|
||||
112, -1, 54, 99, -13, -9, -3, -1, 69, 84, -1, 68, -1, 6, 5,
|
||||
-1, 38, 98, -5, -1, 97, -1, 22, 96, -3, -1, 53, 83, -1, 37,
|
||||
82, -17, -7, -3, -1, 21, 81, -1, 52, 67, -5, -3, -1, 80, 4,
|
||||
36, -1, 66, 20, -3, -1, 51, 65, -1, 35, 50, -11, -7, -5, -3,
|
||||
-1, 64, 3, 48, 19, -1, 49, 34, -1, 18, 33, -7, -5, -3, -1,
|
||||
2, 32, 0, 17, -1, 1, 16
|
||||
};
|
||||
|
||||
static const short tab13[] =
|
||||
{
|
||||
-509,-503,-475,-405,-333,-265,-205,-153,-115, -83, -53, -35, -21, -13, -9,
|
||||
-7, -5, -3, -1, 254, 252, 253, 237, 255, -1, 239, 223, -3, -1, 238,
|
||||
207, -1, 222, 191, -9, -3, -1, 251, 206, -1, 220, -1, 175, 233, -1,
|
||||
236, 221, -9, -5, -3, -1, 250, 205, 190, -1, 235, 159, -3, -1, 249,
|
||||
234, -1, 189, 219, -17, -9, -3, -1, 143, 248, -1, 204, -1, 174, 158,
|
||||
-5, -1, 142, -1, 127, 126, 247, -5, -1, 218, -1, 173, 188, -3, -1,
|
||||
203, 246, 111, -15, -7, -3, -1, 232, 95, -1, 157, 217, -3, -1, 245,
|
||||
231, -1, 172, 187, -9, -3, -1, 79, 244, -3, -1, 202, 230, 243, -1,
|
||||
63, -1, 141, 216, -21, -9, -3, -1, 47, 242, -3, -1, 110, 156, 15,
|
||||
-5, -3, -1, 201, 94, 171, -3, -1, 125, 215, 78, -11, -5, -3, -1,
|
||||
200, 214, 62, -1, 185, -1, 155, 170, -1, 31, 241, -23, -13, -5, -1,
|
||||
240, -1, 186, 229, -3, -1, 228, 140, -1, 109, 227, -5, -1, 226, -1,
|
||||
46, 14, -1, 30, 225, -15, -7, -3, -1, 224, 93, -1, 213, 124, -3,
|
||||
-1, 199, 77, -1, 139, 184, -7, -3, -1, 212, 154, -1, 169, 108, -1,
|
||||
198, 61, -37, -21, -9, -5, -3, -1, 211, 123, 45, -1, 210, 29, -5,
|
||||
-1, 183, -1, 92, 197, -3, -1, 153, 122, 195, -7, -5, -3, -1, 167,
|
||||
151, 75, 209, -3, -1, 13, 208, -1, 138, 168, -11, -7, -3, -1, 76,
|
||||
196, -1, 107, 182, -1, 60, 44, -3, -1, 194, 91, -3, -1, 181, 137,
|
||||
28, -43, -23, -11, -5, -1, 193, -1, 152, 12, -1, 192, -1, 180, 106,
|
||||
-5, -3, -1, 166, 121, 59, -1, 179, -1, 136, 90, -11, -5, -1, 43,
|
||||
-1, 165, 105, -1, 164, -1, 120, 135, -5, -1, 148, -1, 119, 118, 178,
|
||||
-11, -3, -1, 27, 177, -3, -1, 11, 176, -1, 150, 74, -7, -3, -1,
|
||||
58, 163, -1, 89, 149, -1, 42, 162, -47, -23, -9, -3, -1, 26, 161,
|
||||
-3, -1, 10, 104, 160, -5, -3, -1, 134, 73, 147, -3, -1, 57, 88,
|
||||
-1, 133, 103, -9, -3, -1, 41, 146, -3, -1, 87, 117, 56, -5, -1,
|
||||
131, -1, 102, 71, -3, -1, 116, 86, -1, 101, 115, -11, -3, -1, 25,
|
||||
145, -3, -1, 9, 144, -1, 72, 132, -7, -5, -1, 114, -1, 70, 100,
|
||||
40, -1, 130, 24, -41, -27, -11, -5, -3, -1, 55, 39, 23, -1, 113,
|
||||
-1, 85, 7, -7, -3, -1, 112, 54, -1, 99, 69, -3, -1, 84, 38,
|
||||
-1, 98, 53, -5, -1, 129, -1, 8, 128, -3, -1, 22, 97, -1, 6,
|
||||
96, -13, -9, -5, -3, -1, 83, 68, 37, -1, 82, 5, -1, 21, 81,
|
||||
-7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20, -19, -11,
|
||||
-5, -1, 65, -1, 4, 64, -3, -1, 35, 50, 19, -3, -1, 49, 3,
|
||||
-1, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16,
|
||||
0
|
||||
};
|
||||
|
||||
static const short tab15[] =
|
||||
{
|
||||
-495,-445,-355,-263,-183,-115, -77, -43, -27, -13, -7, -3, -1, 255, 239,
|
||||
-1, 254, 223, -1, 238, -1, 253, 207, -7, -3, -1, 252, 222, -1, 237,
|
||||
191, -1, 251, -1, 206, 236, -7, -3, -1, 221, 175, -1, 250, 190, -3,
|
||||
-1, 235, 205, -1, 220, 159, -15, -7, -3, -1, 249, 234, -1, 189, 219,
|
||||
-3, -1, 143, 248, -1, 204, 158, -7, -3, -1, 233, 127, -1, 247, 173,
|
||||
-3, -1, 218, 188, -1, 111, -1, 174, 15, -19, -11, -3, -1, 203, 246,
|
||||
-3, -1, 142, 232, -1, 95, 157, -3, -1, 245, 126, -1, 231, 172, -9,
|
||||
-3, -1, 202, 187, -3, -1, 217, 141, 79, -3, -1, 244, 63, -1, 243,
|
||||
216, -33, -17, -9, -3, -1, 230, 47, -1, 242, -1, 110, 240, -3, -1,
|
||||
31, 241, -1, 156, 201, -7, -3, -1, 94, 171, -1, 186, 229, -3, -1,
|
||||
125, 215, -1, 78, 228, -15, -7, -3, -1, 140, 200, -1, 62, 109, -3,
|
||||
-1, 214, 227, -1, 155, 185, -7, -3, -1, 46, 170, -1, 226, 30, -5,
|
||||
-1, 225, -1, 14, 224, -1, 93, 213, -45, -25, -13, -7, -3, -1, 124,
|
||||
199, -1, 77, 139, -1, 212, -1, 184, 154, -7, -3, -1, 169, 108, -1,
|
||||
198, 61, -1, 211, 210, -9, -5, -3, -1, 45, 13, 29, -1, 123, 183,
|
||||
-5, -1, 209, -1, 92, 208, -1, 197, 138, -17, -7, -3, -1, 168, 76,
|
||||
-1, 196, 107, -5, -1, 182, -1, 153, 12, -1, 60, 195, -9, -3, -1,
|
||||
122, 167, -1, 166, -1, 192, 11, -1, 194, -1, 44, 91, -55, -29, -15,
|
||||
-7, -3, -1, 181, 28, -1, 137, 152, -3, -1, 193, 75, -1, 180, 106,
|
||||
-5, -3, -1, 59, 121, 179, -3, -1, 151, 136, -1, 43, 90, -11, -5,
|
||||
-1, 178, -1, 165, 27, -1, 177, -1, 176, 105, -7, -3, -1, 150, 74,
|
||||
-1, 164, 120, -3, -1, 135, 58, 163, -17, -7, -3, -1, 89, 149, -1,
|
||||
42, 162, -3, -1, 26, 161, -3, -1, 10, 160, 104, -7, -3, -1, 134,
|
||||
73, -1, 148, 57, -5, -1, 147, -1, 119, 9, -1, 88, 133, -53, -29,
|
||||
-13, -7, -3, -1, 41, 103, -1, 118, 146, -1, 145, -1, 25, 144, -7,
|
||||
-3, -1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 71, -7,
|
||||
-3, -1, 40, 130, -1, 24, 129, -7, -3, -1, 116, 8, -1, 128, 86,
|
||||
-3, -1, 101, 55, -1, 115, 70, -17, -7, -3, -1, 39, 114, -1, 100,
|
||||
23, -3, -1, 85, 113, -3, -1, 7, 112, 54, -7, -3, -1, 99, 69,
|
||||
-1, 84, 38, -3, -1, 98, 22, -3, -1, 6, 96, 53, -33, -19, -9,
|
||||
-5, -1, 97, -1, 83, 68, -1, 37, 82, -3, -1, 21, 81, -3, -1,
|
||||
5, 80, 52, -7, -3, -1, 67, 36, -1, 66, 51, -1, 65, -1, 20,
|
||||
4, -9, -3, -1, 35, 50, -3, -1, 64, 3, 19, -3, -1, 49, 48,
|
||||
34, -9, -7, -3, -1, 18, 33, -1, 2, 32, 17, -3, -1, 1, 16,
|
||||
0
|
||||
};
|
||||
|
||||
static const short tab16[] =
|
||||
{
|
||||
-509,-503,-461,-323,-103, -37, -27, -15, -7, -3, -1, 239, 254, -1, 223,
|
||||
253, -3, -1, 207, 252, -1, 191, 251, -5, -1, 175, -1, 250, 159, -3,
|
||||
-1, 249, 248, 143, -7, -3, -1, 127, 247, -1, 111, 246, 255, -9, -5,
|
||||
-3, -1, 95, 245, 79, -1, 244, 243, -53, -1, 240, -1, 63, -29, -19,
|
||||
-13, -7, -5, -1, 206, -1, 236, 221, 222, -1, 233, -1, 234, 217, -1,
|
||||
238, -1, 237, 235, -3, -1, 190, 205, -3, -1, 220, 219, 174, -11, -5,
|
||||
-1, 204, -1, 173, 218, -3, -1, 126, 172, 202, -5, -3, -1, 201, 125,
|
||||
94, 189, 242, -93, -5, -3, -1, 47, 15, 31, -1, 241, -49, -25, -13,
|
||||
-5, -1, 158, -1, 188, 203, -3, -1, 142, 232, -1, 157, 231, -7, -3,
|
||||
-1, 187, 141, -1, 216, 110, -1, 230, 156, -13, -7, -3, -1, 171, 186,
|
||||
-1, 229, 215, -1, 78, -1, 228, 140, -3, -1, 200, 62, -1, 109, -1,
|
||||
214, 155, -19, -11, -5, -3, -1, 185, 170, 225, -1, 212, -1, 184, 169,
|
||||
-5, -1, 123, -1, 183, 208, 227, -7, -3, -1, 14, 224, -1, 93, 213,
|
||||
-3, -1, 124, 199, -1, 77, 139, -75, -45, -27, -13, -7, -3, -1, 154,
|
||||
108, -1, 198, 61, -3, -1, 92, 197, 13, -7, -3, -1, 138, 168, -1,
|
||||
153, 76, -3, -1, 182, 122, 60, -11, -5, -3, -1, 91, 137, 28, -1,
|
||||
192, -1, 152, 121, -1, 226, -1, 46, 30, -15, -7, -3, -1, 211, 45,
|
||||
-1, 210, 209, -5, -1, 59, -1, 151, 136, 29, -7, -3, -1, 196, 107,
|
||||
-1, 195, 167, -1, 44, -1, 194, 181, -23, -13, -7, -3, -1, 193, 12,
|
||||
-1, 75, 180, -3, -1, 106, 166, 179, -5, -3, -1, 90, 165, 43, -1,
|
||||
178, 27, -13, -5, -1, 177, -1, 11, 176, -3, -1, 105, 150, -1, 74,
|
||||
164, -5, -3, -1, 120, 135, 163, -3, -1, 58, 89, 42, -97, -57, -33,
|
||||
-19, -11, -5, -3, -1, 149, 104, 161, -3, -1, 134, 119, 148, -5, -3,
|
||||
-1, 73, 87, 103, 162, -5, -1, 26, -1, 10, 160, -3, -1, 57, 147,
|
||||
-1, 88, 133, -9, -3, -1, 41, 146, -3, -1, 118, 9, 25, -5, -1,
|
||||
145, -1, 144, 72, -3, -1, 132, 117, -1, 56, 131, -21, -11, -5, -3,
|
||||
-1, 102, 40, 130, -3, -1, 71, 116, 24, -3, -1, 129, 128, -3, -1,
|
||||
8, 86, 55, -9, -5, -1, 115, -1, 101, 70, -1, 39, 114, -5, -3,
|
||||
-1, 100, 85, 7, 23, -23, -13, -5, -1, 113, -1, 112, 54, -3, -1,
|
||||
99, 69, -1, 84, 38, -3, -1, 98, 22, -1, 97, -1, 6, 96, -9,
|
||||
-5, -1, 83, -1, 53, 68, -1, 37, 82, -1, 81, -1, 21, 5, -33,
|
||||
-23, -13, -7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20,
|
||||
-5, -1, 65, -1, 4, 64, -1, 35, 50, -3, -1, 19, 49, -3, -1,
|
||||
3, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16,
|
||||
0
|
||||
};
|
||||
|
||||
static const short tab24[] =
|
||||
{
|
||||
-451,-117, -43, -25, -15, -7, -3, -1, 239, 254, -1, 223, 253, -3, -1,
|
||||
207, 252, -1, 191, 251, -5, -1, 250, -1, 175, 159, -1, 249, 248, -9,
|
||||
-5, -3, -1, 143, 127, 247, -1, 111, 246, -3, -1, 95, 245, -1, 79,
|
||||
244, -71, -7, -3, -1, 63, 243, -1, 47, 242, -5, -1, 241, -1, 31,
|
||||
240, -25, -9, -1, 15, -3, -1, 238, 222, -1, 237, 206, -7, -3, -1,
|
||||
236, 221, -1, 190, 235, -3, -1, 205, 220, -1, 174, 234, -15, -7, -3,
|
||||
-1, 189, 219, -1, 204, 158, -3, -1, 233, 173, -1, 218, 188, -7, -3,
|
||||
-1, 203, 142, -1, 232, 157, -3, -1, 217, 126, -1, 231, 172, 255,-235,
|
||||
-143, -77, -45, -25, -15, -7, -3, -1, 202, 187, -1, 141, 216, -5, -3,
|
||||
-1, 14, 224, 13, 230, -5, -3, -1, 110, 156, 201, -1, 94, 186, -9,
|
||||
-5, -1, 229, -1, 171, 125, -1, 215, 228, -3, -1, 140, 200, -3, -1,
|
||||
78, 46, 62, -15, -7, -3, -1, 109, 214, -1, 227, 155, -3, -1, 185,
|
||||
170, -1, 226, 30, -7, -3, -1, 225, 93, -1, 213, 124, -3, -1, 199,
|
||||
77, -1, 139, 184, -31, -15, -7, -3, -1, 212, 154, -1, 169, 108, -3,
|
||||
-1, 198, 61, -1, 211, 45, -7, -3, -1, 210, 29, -1, 123, 183, -3,
|
||||
-1, 209, 92, -1, 197, 138, -17, -7, -3, -1, 168, 153, -1, 76, 196,
|
||||
-3, -1, 107, 182, -3, -1, 208, 12, 60, -7, -3, -1, 195, 122, -1,
|
||||
167, 44, -3, -1, 194, 91, -1, 181, 28, -57, -35, -19, -7, -3, -1,
|
||||
137, 152, -1, 193, 75, -5, -3, -1, 192, 11, 59, -3, -1, 176, 10,
|
||||
26, -5, -1, 180, -1, 106, 166, -3, -1, 121, 151, -3, -1, 160, 9,
|
||||
144, -9, -3, -1, 179, 136, -3, -1, 43, 90, 178, -7, -3, -1, 165,
|
||||
27, -1, 177, 105, -1, 150, 164, -17, -9, -5, -3, -1, 74, 120, 135,
|
||||
-1, 58, 163, -3, -1, 89, 149, -1, 42, 162, -7, -3, -1, 161, 104,
|
||||
-1, 134, 119, -3, -1, 73, 148, -1, 57, 147, -63, -31, -15, -7, -3,
|
||||
-1, 88, 133, -1, 41, 103, -3, -1, 118, 146, -1, 25, 145, -7, -3,
|
||||
-1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 40, -17, -7,
|
||||
-3, -1, 130, 24, -1, 71, 116, -5, -1, 129, -1, 8, 128, -1, 86,
|
||||
101, -7, -5, -1, 23, -1, 7, 112, 115, -3, -1, 55, 39, 114, -15,
|
||||
-7, -3, -1, 70, 100, -1, 85, 113, -3, -1, 54, 99, -1, 69, 84,
|
||||
-7, -3, -1, 38, 98, -1, 22, 97, -5, -3, -1, 6, 96, 53, -1,
|
||||
83, 68, -51, -37, -23, -15, -9, -3, -1, 37, 82, -1, 21, -1, 5,
|
||||
80, -1, 81, -1, 52, 67, -3, -1, 36, 66, -1, 51, 20, -9, -5,
|
||||
-1, 65, -1, 4, 64, -1, 35, 50, -1, 19, 49, -7, -5, -3, -1,
|
||||
3, 48, 34, 18, -1, 33, -1, 2, 32, -3, -1, 17, 1, -1, 16,
|
||||
0
|
||||
};
|
||||
|
||||
static const short tab_c0[] =
|
||||
{
|
||||
-29, -21, -13, -7, -3, -1, 11, 15, -1, 13, 14, -3, -1, 7, 5,
|
||||
9, -3, -1, 6, 3, -1, 10, 12, -3, -1, 2, 1, -1, 4, 8,
|
||||
0
|
||||
};
|
||||
|
||||
static const short tab_c1[] =
|
||||
{
|
||||
-15, -7, -3, -1, 15, 14, -1, 13, 12, -3, -1, 11, 10, -1, 9,
|
||||
8, -7, -3, -1, 7, 6, -1, 5, 4, -3, -1, 3, 2, -1, 1,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
|
||||
static const struct newhuff ht[] =
|
||||
{
|
||||
{ /* 0 */ 0 , tab0 } ,
|
||||
{ /* 2 */ 0 , tab1 } ,
|
||||
{ /* 3 */ 0 , tab2 } ,
|
||||
{ /* 3 */ 0 , tab3 } ,
|
||||
{ /* 0 */ 0 , tab0 } ,
|
||||
{ /* 4 */ 0 , tab5 } ,
|
||||
{ /* 4 */ 0 , tab6 } ,
|
||||
{ /* 6 */ 0 , tab7 } ,
|
||||
{ /* 6 */ 0 , tab8 } ,
|
||||
{ /* 6 */ 0 , tab9 } ,
|
||||
{ /* 8 */ 0 , tab10 } ,
|
||||
{ /* 8 */ 0 , tab11 } ,
|
||||
{ /* 8 */ 0 , tab12 } ,
|
||||
{ /* 16 */ 0 , tab13 } ,
|
||||
{ /* 0 */ 0 , tab0 } ,
|
||||
{ /* 16 */ 0 , tab15 } ,
|
||||
|
||||
{ /* 16 */ 1 , tab16 } ,
|
||||
{ /* 16 */ 2 , tab16 } ,
|
||||
{ /* 16 */ 3 , tab16 } ,
|
||||
{ /* 16 */ 4 , tab16 } ,
|
||||
{ /* 16 */ 6 , tab16 } ,
|
||||
{ /* 16 */ 8 , tab16 } ,
|
||||
{ /* 16 */ 10, tab16 } ,
|
||||
{ /* 16 */ 13, tab16 } ,
|
||||
{ /* 16 */ 4 , tab24 } ,
|
||||
{ /* 16 */ 5 , tab24 } ,
|
||||
{ /* 16 */ 6 , tab24 } ,
|
||||
{ /* 16 */ 7 , tab24 } ,
|
||||
{ /* 16 */ 8 , tab24 } ,
|
||||
{ /* 16 */ 9 , tab24 } ,
|
||||
{ /* 16 */ 11, tab24 } ,
|
||||
{ /* 16 */ 13, tab24 }
|
||||
};
|
||||
|
||||
static const struct newhuff htc[] =
|
||||
{
|
||||
{ /* 1 , 1 , */ 0 , tab_c0 } ,
|
||||
{ /* 1 , 1 , */ 0 , tab_c1 }
|
||||
};
|
||||
|
||||
/* *INDENT-ON* */
|
||||
@@ -0,0 +1,718 @@
|
||||
/*
|
||||
* interface.c
|
||||
*
|
||||
* Copyright (C) 1999-2012 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
/* $Id: interface.c,v 1.69 2017/09/06 15:07:30 robert Exp $ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "interface.h"
|
||||
#include "tabinit.h"
|
||||
#include "layer3.h"
|
||||
#include "lame.h"
|
||||
#include "machine.h"
|
||||
#include "VbrTag.h"
|
||||
#include "decode_i386.h"
|
||||
|
||||
#include "layer1.h"
|
||||
#include "layer2.h"
|
||||
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif
|
||||
|
||||
extern void lame_report_def(const char* format, va_list args);
|
||||
|
||||
/* #define HIP_DEBUG */
|
||||
|
||||
int
|
||||
InitMP3(PMPSTR mp)
|
||||
{
|
||||
hip_init_tables_layer1();
|
||||
hip_init_tables_layer2();
|
||||
hip_init_tables_layer3();
|
||||
|
||||
if (mp) {
|
||||
memset(mp, 0, sizeof(MPSTR));
|
||||
|
||||
mp->framesize = 0;
|
||||
mp->num_frames = 0;
|
||||
mp->enc_delay = -1;
|
||||
mp->enc_padding = -1;
|
||||
mp->vbr_header = 0;
|
||||
mp->header_parsed = 0;
|
||||
mp->side_parsed = 0;
|
||||
mp->data_parsed = 0;
|
||||
mp->free_format = 0;
|
||||
mp->old_free_format = 0;
|
||||
mp->ssize = 0;
|
||||
mp->dsize = 0;
|
||||
mp->fsizeold = -1;
|
||||
mp->bsize = 0;
|
||||
mp->head = mp->tail = NULL;
|
||||
mp->fr.single = -1;
|
||||
mp->bsnum = 0;
|
||||
mp->wordpointer = mp->bsspace[mp->bsnum] + 512;
|
||||
mp->bitindex = 0;
|
||||
mp->synth_bo = 1;
|
||||
mp->sync_bitstream = 1;
|
||||
|
||||
mp->report_dbg = &lame_report_def;
|
||||
mp->report_err = &lame_report_def;
|
||||
mp->report_msg = &lame_report_def;
|
||||
}
|
||||
make_decode_tables(32767);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
ExitMP3(PMPSTR mp)
|
||||
{
|
||||
if (mp) {
|
||||
struct buf *b, *bn;
|
||||
|
||||
b = mp->tail;
|
||||
while (b) {
|
||||
free(b->pnt);
|
||||
bn = b->next;
|
||||
free(b);
|
||||
b = bn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct buf *
|
||||
addbuf(PMPSTR mp, unsigned char *buf, int size)
|
||||
{
|
||||
struct buf *nbuf;
|
||||
|
||||
nbuf = (struct buf *) malloc(sizeof(struct buf));
|
||||
if (!nbuf) {
|
||||
lame_report_fnc(mp->report_err, "hip: addbuf() Out of memory!\n");
|
||||
return NULL;
|
||||
}
|
||||
nbuf->pnt = (unsigned char *) malloc((size_t) size);
|
||||
if (!nbuf->pnt) {
|
||||
free(nbuf);
|
||||
return NULL;
|
||||
}
|
||||
nbuf->size = size;
|
||||
memcpy(nbuf->pnt, buf, (size_t) size);
|
||||
nbuf->next = NULL;
|
||||
nbuf->prev = mp->head;
|
||||
nbuf->pos = 0;
|
||||
|
||||
if (!mp->tail) {
|
||||
mp->tail = nbuf;
|
||||
}
|
||||
else {
|
||||
mp->head->next = nbuf;
|
||||
}
|
||||
|
||||
mp->head = nbuf;
|
||||
mp->bsize += size;
|
||||
|
||||
return nbuf;
|
||||
}
|
||||
|
||||
void
|
||||
remove_buf(PMPSTR mp)
|
||||
{
|
||||
struct buf *buf = mp->tail;
|
||||
|
||||
mp->tail = buf->next;
|
||||
if (mp->tail)
|
||||
mp->tail->prev = NULL;
|
||||
else {
|
||||
mp->tail = mp->head = NULL;
|
||||
}
|
||||
|
||||
free(buf->pnt);
|
||||
free(buf);
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
read_buf_byte(PMPSTR mp)
|
||||
{
|
||||
unsigned int b;
|
||||
|
||||
int pos;
|
||||
|
||||
|
||||
pos = mp->tail->pos;
|
||||
while (pos >= mp->tail->size) {
|
||||
remove_buf(mp);
|
||||
if (!mp->tail) {
|
||||
lame_report_fnc(mp->report_err, "hip: Fatal error! tried to read past mp buffer\n");
|
||||
exit(1);
|
||||
}
|
||||
pos = mp->tail->pos;
|
||||
}
|
||||
|
||||
b = mp->tail->pnt[pos];
|
||||
mp->bsize--;
|
||||
mp->tail->pos++;
|
||||
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
read_head(PMPSTR mp)
|
||||
{
|
||||
unsigned long head;
|
||||
|
||||
head = read_buf_byte(mp);
|
||||
head <<= 8;
|
||||
head |= read_buf_byte(mp);
|
||||
head <<= 8;
|
||||
head |= read_buf_byte(mp);
|
||||
head <<= 8;
|
||||
head |= read_buf_byte(mp);
|
||||
|
||||
mp->header = head;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
copy_mp(PMPSTR mp, int size, unsigned char *ptr)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
while (len < size && mp->tail) {
|
||||
int nlen;
|
||||
int blen = mp->tail->size - mp->tail->pos;
|
||||
if ((size - len) <= blen) {
|
||||
nlen = size - len;
|
||||
}
|
||||
else {
|
||||
nlen = blen;
|
||||
}
|
||||
memcpy(ptr + len, mp->tail->pnt + mp->tail->pos, (size_t) nlen);
|
||||
len += nlen;
|
||||
mp->tail->pos += nlen;
|
||||
mp->bsize -= nlen;
|
||||
if (mp->tail->pos == mp->tail->size) {
|
||||
remove_buf(mp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* number of bytes needed by GetVbrTag to parse header */
|
||||
#define XING_HEADER_SIZE 194
|
||||
|
||||
/*
|
||||
traverse mp data structure without changing it
|
||||
(just like sync_buffer)
|
||||
pull out Xing bytes
|
||||
call vbr header check code from LAME
|
||||
if we find a header, parse it and also compute the VBR header size
|
||||
if no header, do nothing.
|
||||
|
||||
bytes = number of bytes before MPEG header. skip this many bytes
|
||||
before starting to read
|
||||
return value: number of bytes in VBR header, including syncword
|
||||
*/
|
||||
static int
|
||||
check_vbr_header(PMPSTR mp, int bytes)
|
||||
{
|
||||
int i, pos;
|
||||
struct buf *buf = mp->tail;
|
||||
unsigned char xing[XING_HEADER_SIZE];
|
||||
VBRTAGDATA pTagData;
|
||||
|
||||
pos = buf->pos;
|
||||
/* skip to valid header */
|
||||
for (i = 0; i < bytes; ++i) {
|
||||
while (pos >= buf->size) {
|
||||
buf = buf->next;
|
||||
if (!buf)
|
||||
return -1; /* fatal error */
|
||||
pos = buf->pos;
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
/* now read header */
|
||||
for (i = 0; i < XING_HEADER_SIZE; ++i) {
|
||||
while (pos >= buf->size) {
|
||||
buf = buf->next;
|
||||
if (!buf)
|
||||
return -1; /* fatal error */
|
||||
pos = buf->pos;
|
||||
}
|
||||
xing[i] = buf->pnt[pos];
|
||||
++pos;
|
||||
}
|
||||
|
||||
/* check first bytes for Xing header */
|
||||
mp->vbr_header = GetVbrTag(&pTagData, xing);
|
||||
if (mp->vbr_header) {
|
||||
mp->num_frames = pTagData.frames;
|
||||
mp->enc_delay = pTagData.enc_delay;
|
||||
mp->enc_padding = pTagData.enc_padding;
|
||||
|
||||
/* lame_report_fnc(mp->report_msg,"hip: delays: %i %i \n",mp->enc_delay,mp->enc_padding); */
|
||||
/* lame_report_fnc(mp->report_msg,"hip: Xing VBR header dectected. MP3 file has %i frames\n", pTagData.frames); */
|
||||
if (pTagData.headersize < 1)
|
||||
return 1;
|
||||
return pTagData.headersize;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int
|
||||
sync_buffer(PMPSTR mp, int free_match)
|
||||
{
|
||||
/* traverse mp structure without modifying pointers, looking
|
||||
* for a frame valid header.
|
||||
* if free_format, valid header must also have the same
|
||||
* samplerate.
|
||||
* return number of bytes in mp, before the header
|
||||
* return -1 if header is not found
|
||||
*/
|
||||
unsigned int b[4] = { 0, 0, 0, 0 };
|
||||
int i, h, pos;
|
||||
struct buf *buf = mp->tail;
|
||||
if (!buf)
|
||||
return -1;
|
||||
|
||||
pos = buf->pos;
|
||||
for (i = 0; i < mp->bsize; i++) {
|
||||
/* get 4 bytes */
|
||||
|
||||
b[0] = b[1];
|
||||
b[1] = b[2];
|
||||
b[2] = b[3];
|
||||
while (pos >= buf->size) {
|
||||
buf = buf->next;
|
||||
if (!buf) {
|
||||
return -1;
|
||||
/* not enough data to read 4 bytes */
|
||||
}
|
||||
pos = buf->pos;
|
||||
}
|
||||
b[3] = buf->pnt[pos];
|
||||
++pos;
|
||||
|
||||
if (i >= 3) {
|
||||
struct frame *fr = &mp->fr;
|
||||
unsigned long head;
|
||||
|
||||
head = b[0];
|
||||
head <<= 8;
|
||||
head |= b[1];
|
||||
head <<= 8;
|
||||
head |= b[2];
|
||||
head <<= 8;
|
||||
head |= b[3];
|
||||
h = head_check(head, fr->lay);
|
||||
|
||||
if (h && free_match) {
|
||||
/* just to be even more thorough, match the sample rate */
|
||||
int mode, stereo, sampling_frequency, mpeg25, lsf;
|
||||
|
||||
if (head & (1 << 20)) {
|
||||
lsf = (head & (1 << 19)) ? 0x0 : 0x1;
|
||||
mpeg25 = 0;
|
||||
}
|
||||
else {
|
||||
lsf = 1;
|
||||
mpeg25 = 1;
|
||||
}
|
||||
|
||||
mode = ((head >> 6) & 0x3);
|
||||
stereo = (mode == MPG_MD_MONO) ? 1 : 2;
|
||||
|
||||
if (mpeg25)
|
||||
sampling_frequency = 6 + ((head >> 10) & 0x3);
|
||||
else
|
||||
sampling_frequency = ((head >> 10) & 0x3) + (lsf * 3);
|
||||
h = ((stereo == fr->stereo) && (lsf == fr->lsf) && (mpeg25 == fr->mpeg25) &&
|
||||
(sampling_frequency == fr->sampling_frequency));
|
||||
}
|
||||
|
||||
if (h) {
|
||||
return i - 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
decode_reset(PMPSTR mp)
|
||||
{
|
||||
#if 0
|
||||
remove_buf(mp);
|
||||
/* start looking for next frame */
|
||||
/* mp->fsizeold = mp->framesize; */
|
||||
mp->fsizeold = -1;
|
||||
mp->old_free_format = mp->free_format;
|
||||
mp->framesize = 0;
|
||||
mp->header_parsed = 0;
|
||||
mp->side_parsed = 0;
|
||||
mp->data_parsed = 0;
|
||||
mp->sync_bitstream = 1; /* TODO check if this is right */
|
||||
#else
|
||||
InitMP3(mp); /* Less error prone to just to reinitialise. */
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
audiodata_precedesframes(PMPSTR mp)
|
||||
{
|
||||
if (mp->fr.lay == 3)
|
||||
return layer3_audiodata_precedesframes(mp);
|
||||
else
|
||||
return 0; /* For Layer 1 & 2 the audio data starts at the frame that describes it, so no audio data precedes. */
|
||||
}
|
||||
|
||||
static int
|
||||
decodeMP3_clipchoice(PMPSTR mp, unsigned char *in, int isize, char *out, int *done,
|
||||
int (*synth_1to1_mono_ptr) (PMPSTR, real *, unsigned char *, int *),
|
||||
int (*synth_1to1_ptr) (PMPSTR, real *, int, unsigned char *, int *))
|
||||
{
|
||||
int i, iret, bits, bytes;
|
||||
|
||||
if (in && isize && addbuf(mp, in, isize) == NULL)
|
||||
return MP3_ERR;
|
||||
|
||||
/* First decode header */
|
||||
if (!mp->header_parsed) {
|
||||
|
||||
if (mp->fsizeold == -1 || mp->sync_bitstream) {
|
||||
int vbrbytes;
|
||||
mp->sync_bitstream = 0;
|
||||
|
||||
/* This is the very first call. sync with anything */
|
||||
/* bytes= number of bytes before header */
|
||||
bytes = sync_buffer(mp, 0);
|
||||
|
||||
/* now look for Xing VBR header */
|
||||
if (mp->bsize >= bytes + XING_HEADER_SIZE) {
|
||||
/* vbrbytes = number of bytes in entire vbr header */
|
||||
vbrbytes = check_vbr_header(mp, bytes);
|
||||
}
|
||||
else {
|
||||
/* not enough data to look for Xing header */
|
||||
#ifdef HIP_DEBUG
|
||||
lame_report_fnc(mp->report_dbg, "hip: not enough data to look for Xing header\n");
|
||||
#endif
|
||||
return MP3_NEED_MORE;
|
||||
}
|
||||
|
||||
if (mp->vbr_header) {
|
||||
/* do we have enough data to parse entire Xing header? */
|
||||
if (bytes + vbrbytes > mp->bsize) {
|
||||
/* lame_report_fnc(mp->report_err,"hip: not enough data to parse entire Xing header\n"); */
|
||||
return MP3_NEED_MORE;
|
||||
}
|
||||
|
||||
/* read in Xing header. Buffer data in case it
|
||||
* is used by a non zero main_data_begin for the next
|
||||
* frame, but otherwise dont decode Xing header */
|
||||
#ifdef HIP_DEBUG
|
||||
lame_report_fnc(mp->report_dbg, "hip: found xing header, skipping %i bytes\n", vbrbytes + bytes);
|
||||
#endif
|
||||
for (i = 0; i < vbrbytes + bytes; ++i)
|
||||
read_buf_byte(mp);
|
||||
/* now we need to find another syncword */
|
||||
/* just return and make user send in more data */
|
||||
|
||||
return MP3_NEED_MORE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* match channels, samplerate, etc, when syncing */
|
||||
bytes = sync_buffer(mp, 1);
|
||||
}
|
||||
|
||||
/* buffer now synchronized */
|
||||
if (bytes < 0) {
|
||||
/* lame_report_fnc(mp->report_err,"hip: need more bytes %d\n", bytes); */
|
||||
return MP3_NEED_MORE;
|
||||
}
|
||||
if (bytes > 0) {
|
||||
/* there were some extra bytes in front of header.
|
||||
* bitstream problem, but we are now resynced
|
||||
* should try to buffer previous data in case new
|
||||
* frame has nonzero main_data_begin, but we need
|
||||
* to make sure we do not overflow buffer
|
||||
*/
|
||||
int size;
|
||||
if (mp->fsizeold != -1) {
|
||||
lame_report_fnc(mp->report_err, "hip: bitstream problem, resyncing skipping %d bytes...\n", bytes);
|
||||
}
|
||||
mp->old_free_format = 0;
|
||||
#if 1
|
||||
/* FIXME: correct ??? */
|
||||
mp->sync_bitstream = 1;
|
||||
#endif
|
||||
/* skip some bytes, buffer the rest */
|
||||
size = (int) (mp->wordpointer - (mp->bsspace[mp->bsnum] + 512));
|
||||
|
||||
if (size > MAXFRAMESIZE) {
|
||||
/* wordpointer buffer is trashed. probably cant recover, but try anyway */
|
||||
lame_report_fnc(mp->report_err, "hip: wordpointer trashed. size=%i (%i) bytes=%i \n",
|
||||
size, MAXFRAMESIZE, bytes);
|
||||
size = 0;
|
||||
mp->wordpointer = mp->bsspace[mp->bsnum] + 512;
|
||||
}
|
||||
|
||||
/* buffer contains 'size' data right now
|
||||
we want to add 'bytes' worth of data, but do not
|
||||
exceed MAXFRAMESIZE, so we through away 'i' bytes */
|
||||
i = (size + bytes) - MAXFRAMESIZE;
|
||||
for (; i > 0; --i) {
|
||||
--bytes;
|
||||
read_buf_byte(mp);
|
||||
}
|
||||
|
||||
copy_mp(mp, bytes, mp->wordpointer);
|
||||
mp->fsizeold += bytes;
|
||||
}
|
||||
|
||||
read_head(mp);
|
||||
if (!decode_header(mp, &mp->fr, mp->header))
|
||||
return MP3_ERR;
|
||||
mp->header_parsed = 1;
|
||||
mp->framesize = mp->fr.framesize;
|
||||
mp->free_format = (mp->framesize == 0);
|
||||
|
||||
if (mp->fr.lsf)
|
||||
mp->ssize = (mp->fr.stereo == 1) ? 9 : 17;
|
||||
else
|
||||
mp->ssize = (mp->fr.stereo == 1) ? 17 : 32;
|
||||
if (mp->fr.error_protection)
|
||||
mp->ssize += 2;
|
||||
|
||||
mp->bsnum = 1 - mp->bsnum; /* toggle buffer */
|
||||
mp->wordpointer = mp->bsspace[mp->bsnum] + 512;
|
||||
mp->bitindex = 0;
|
||||
|
||||
/* for very first header, never parse rest of data */
|
||||
if (mp->fsizeold == -1) {
|
||||
#ifdef HIP_DEBUG
|
||||
lame_report_fnc(mp->report_dbg, "hip: not parsing the rest of the data of the first header\n");
|
||||
#endif
|
||||
return MP3_NEED_MORE;
|
||||
}
|
||||
} /* end of header parsing block */
|
||||
|
||||
/* now decode side information */
|
||||
if (!mp->side_parsed) {
|
||||
|
||||
/* Layer 3 only */
|
||||
if (mp->fr.lay == 3) {
|
||||
if (mp->bsize < mp->ssize)
|
||||
return MP3_NEED_MORE;
|
||||
|
||||
copy_mp(mp, mp->ssize, mp->wordpointer);
|
||||
|
||||
if (mp->fr.error_protection)
|
||||
getbits(mp, 16);
|
||||
bits = decode_layer3_sideinfo(mp);
|
||||
/* bits = actual number of bits needed to parse this frame */
|
||||
/* can be negative, if all bits needed are in the reservoir */
|
||||
if (bits < 0)
|
||||
bits = 0;
|
||||
|
||||
/* read just as many bytes as necessary before decoding */
|
||||
mp->dsize = (bits + 7) / 8;
|
||||
|
||||
if (!mp->free_format) {
|
||||
/* do not read more than framsize data */
|
||||
int framesize = mp->fr.framesize - mp->ssize;
|
||||
if (mp->dsize > framesize) {
|
||||
lame_report_fnc(mp->report_err,
|
||||
"hip: error audio data exceeds framesize by %d bytes\n",
|
||||
mp->dsize - framesize);
|
||||
mp->dsize = framesize;
|
||||
}
|
||||
}
|
||||
#ifdef HIP_DEBUG
|
||||
lame_report_fnc(mp->report_dbg,
|
||||
"hip: %d bits needed to parse layer III frame, number of bytes to read before decoding dsize = %d\n",
|
||||
bits, mp->dsize);
|
||||
#endif
|
||||
|
||||
/* this will force mpglib to read entire frame before decoding */
|
||||
/* mp->dsize= mp->framesize - mp->ssize; */
|
||||
|
||||
}
|
||||
else {
|
||||
/* Layers 1 and 2 */
|
||||
|
||||
/* check if there is enough input data */
|
||||
if (mp->fr.framesize > mp->bsize)
|
||||
return MP3_NEED_MORE;
|
||||
|
||||
/* takes care that the right amount of data is copied into wordpointer */
|
||||
mp->dsize = mp->fr.framesize;
|
||||
mp->ssize = 0;
|
||||
}
|
||||
|
||||
mp->side_parsed = 1;
|
||||
}
|
||||
|
||||
/* now decode main data */
|
||||
iret = MP3_NEED_MORE;
|
||||
if (!mp->data_parsed) {
|
||||
if (mp->dsize > mp->bsize) {
|
||||
return MP3_NEED_MORE;
|
||||
}
|
||||
|
||||
copy_mp(mp, mp->dsize, mp->wordpointer);
|
||||
|
||||
*done = 0;
|
||||
|
||||
/*do_layer3(&mp->fr,(unsigned char *) out,done); */
|
||||
switch (mp->fr.lay) {
|
||||
case 1:
|
||||
if (mp->fr.error_protection)
|
||||
getbits(mp, 16);
|
||||
|
||||
if (decode_layer1_frame(mp, (unsigned char *) out, done) < 0)
|
||||
return MP3_ERR;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (mp->fr.error_protection)
|
||||
getbits(mp, 16);
|
||||
|
||||
decode_layer2_frame(mp, (unsigned char *) out, done);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
decode_layer3_frame(mp, (unsigned char *) out, done, synth_1to1_mono_ptr, synth_1to1_ptr);
|
||||
break;
|
||||
default:
|
||||
lame_report_fnc(mp->report_err, "hip: invalid layer %d\n", mp->fr.lay);
|
||||
}
|
||||
|
||||
mp->wordpointer = mp->bsspace[mp->bsnum] + 512 + mp->ssize + mp->dsize;
|
||||
|
||||
mp->data_parsed = 1;
|
||||
iret = MP3_OK;
|
||||
}
|
||||
|
||||
|
||||
/* remaining bits are ancillary data, or reservoir for next frame
|
||||
* If free format, scan stream looking for next frame to determine
|
||||
* mp->framesize */
|
||||
if (mp->free_format) {
|
||||
if (mp->old_free_format) {
|
||||
/* free format. bitrate must not vary */
|
||||
mp->framesize = mp->fsizeold_nopadding + (mp->fr.padding);
|
||||
}
|
||||
else {
|
||||
bytes = sync_buffer(mp, 1);
|
||||
if (bytes < 0)
|
||||
return iret;
|
||||
mp->framesize = bytes + mp->ssize + mp->dsize;
|
||||
mp->fsizeold_nopadding = mp->framesize - mp->fr.padding;
|
||||
#if 0
|
||||
lame_report_fnc(mp->report_dbg,"hip: freeformat bitstream: estimated bitrate=%ikbs \n",
|
||||
8*(4+mp->framesize)*freqs[mp->fr.sampling_frequency]/
|
||||
(1000*576*(2-mp->fr.lsf)));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* buffer the ancillary data and reservoir for next frame */
|
||||
bytes = mp->framesize - (mp->ssize + mp->dsize);
|
||||
if (bytes > mp->bsize) {
|
||||
return iret;
|
||||
}
|
||||
|
||||
if (bytes > 0) {
|
||||
int size;
|
||||
#if 1
|
||||
/* FIXME: while loop OK ??? */
|
||||
while (bytes > 512) {
|
||||
read_buf_byte(mp);
|
||||
bytes--;
|
||||
mp->framesize--;
|
||||
}
|
||||
#endif
|
||||
copy_mp(mp, bytes, mp->wordpointer);
|
||||
mp->wordpointer += bytes;
|
||||
|
||||
size = (int) (mp->wordpointer - (mp->bsspace[mp->bsnum] + 512));
|
||||
if (size > MAXFRAMESIZE) {
|
||||
lame_report_fnc(mp->report_err, "hip: fatal error. MAXFRAMESIZE not large enough.\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* the above frame is completely parsed. start looking for next frame */
|
||||
mp->fsizeold = mp->framesize;
|
||||
mp->old_free_format = mp->free_format;
|
||||
mp->framesize = 0;
|
||||
mp->header_parsed = 0;
|
||||
mp->side_parsed = 0;
|
||||
mp->data_parsed = 0;
|
||||
|
||||
return iret;
|
||||
}
|
||||
|
||||
int
|
||||
decodeMP3(PMPSTR mp, unsigned char *in, int isize, char *out, int osize, int *done)
|
||||
{
|
||||
if (osize < 4608) {
|
||||
lame_report_fnc(mp->report_err, "hip: Insufficient memory for decoding buffer %d\n", osize);
|
||||
return MP3_ERR;
|
||||
}
|
||||
|
||||
/* passing pointers to the functions which clip the samples */
|
||||
return decodeMP3_clipchoice(mp, in, isize, out, done, synth_1to1_mono, synth_1to1);
|
||||
}
|
||||
|
||||
int
|
||||
decodeMP3_unclipped(PMPSTR mp, unsigned char *in, int isize, char *out, int osize, int *done)
|
||||
{
|
||||
/* we forbid input with more than 1152 samples per channel for output in unclipped mode */
|
||||
if (osize < (int) (1152 * 2 * sizeof(real))) {
|
||||
lame_report_fnc(mp->report_err, "hip: out space too small for unclipped mode\n");
|
||||
return MP3_ERR;
|
||||
}
|
||||
|
||||
/* passing pointers to the functions which don't clip the samples */
|
||||
return decodeMP3_clipchoice(mp, in, isize, out, done, synth_1to1_mono_unclipped,
|
||||
synth_1to1_unclipped);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef INTERFACE_H_INCLUDED
|
||||
#define INTERFACE_H_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
|
||||
int InitMP3(PMPSTR mp);
|
||||
int decodeMP3(PMPSTR mp, unsigned char *inmemory, int inmemsize, char *outmemory,
|
||||
int outmemsize, int *done);
|
||||
void ExitMP3(PMPSTR mp);
|
||||
|
||||
/* added decodeMP3_unclipped to support returning raw floating-point values of samples. The representation
|
||||
of the floating-point numbers is defined in mpg123.h as #define real. It is 64-bit double by default.
|
||||
No more than 1152 samples per channel are allowed. */
|
||||
int decodeMP3_unclipped(PMPSTR mp, unsigned char *inmemory, int inmemsize, char *outmemory,
|
||||
int outmemsize, int *done);
|
||||
|
||||
/* added remove_buf to support mpglib seeking */
|
||||
void remove_buf(PMPSTR mp);
|
||||
|
||||
/* added audiodata_precedesframes to return the number of bitstream frames the audio data will precede the
|
||||
current frame by for Layer 3 data. Aids seeking.
|
||||
*/
|
||||
int audiodata_precedesframes(PMPSTR mp);
|
||||
|
||||
/* Resets decoding. Aids seeking. */
|
||||
void decode_reset(PMPSTR mp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Layer 2 Alloc tables ..
|
||||
* most other tables are calculated on program start (which is (of course)
|
||||
* not ISO-conform) ..
|
||||
* Layer-3 huffman table is in huffman.h
|
||||
*/
|
||||
|
||||
const struct al_table2 alloc_0[] = {
|
||||
{4, 0}, {5, 3}, {3, -3}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255}, {10,
|
||||
-511},
|
||||
{11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {3, -3}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255}, {10,
|
||||
-511},
|
||||
{11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {3, -3}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255}, {10,
|
||||
-511},
|
||||
{11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{2, 0}, {5, 3}, {7, 5}, {16, -32767},
|
||||
{2, 0}, {5, 3}, {7, 5}, {16, -32767},
|
||||
{2, 0}, {5, 3}, {7, 5}, {16, -32767},
|
||||
{2, 0}, {5, 3}, {7, 5}, {16, -32767}
|
||||
};
|
||||
|
||||
const struct al_table2 alloc_1[] = {
|
||||
{4, 0}, {5, 3}, {3, -3}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255}, {10,
|
||||
-511},
|
||||
{11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {3, -3}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255}, {10,
|
||||
-511},
|
||||
{11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {3, -3}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255}, {10,
|
||||
-511},
|
||||
{11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
|
||||
{2, 0}, {5, 3}, {7, 5}, {16, -32767},
|
||||
{2, 0}, {5, 3}, {7, 5}, {16, -32767},
|
||||
{2, 0}, {5, 3}, {7, 5}, {16, -32767},
|
||||
{2, 0}, {5, 3}, {7, 5}, {16, -32767},
|
||||
{2, 0}, {5, 3}, {7, 5}, {16, -32767},
|
||||
{2, 0}, {5, 3}, {7, 5}, {16, -32767},
|
||||
{2, 0}, {5, 3}, {7, 5}, {16, -32767}
|
||||
};
|
||||
|
||||
const struct al_table2 alloc_2[] = {
|
||||
{4, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255},
|
||||
{10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383},
|
||||
{4, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255},
|
||||
{10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}
|
||||
};
|
||||
|
||||
const struct al_table2 alloc_3[] = {
|
||||
{4, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255},
|
||||
{10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383},
|
||||
{4, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255},
|
||||
{10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}
|
||||
};
|
||||
|
||||
const struct al_table2 alloc_4[] = {
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191},
|
||||
{4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
|
||||
{9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9},
|
||||
{2, 0}, {5, 3}, {7, 5}, {10, 9}
|
||||
};
|
||||
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* layer1.c: Mpeg Layer-1 audio decoder
|
||||
*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* $Id: layer1.c,v 1.31 2017/08/23 13:22:23 robert Exp $ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include "common.h"
|
||||
#include "decode_i386.h"
|
||||
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif
|
||||
|
||||
#include "layer1.h"
|
||||
|
||||
static int gd_are_hip_tables_layer1_initialized = 0;
|
||||
|
||||
void
|
||||
hip_init_tables_layer1(void)
|
||||
{
|
||||
if (gd_are_hip_tables_layer1_initialized) {
|
||||
return;
|
||||
}
|
||||
gd_are_hip_tables_layer1_initialized = 1;
|
||||
}
|
||||
|
||||
typedef struct sideinfo_layer_I_struct
|
||||
{
|
||||
unsigned char allocation[SBLIMIT][2];
|
||||
unsigned char scalefactor[SBLIMIT][2];
|
||||
} sideinfo_layer_I;
|
||||
|
||||
static int
|
||||
I_step_one(PMPSTR mp, sideinfo_layer_I* si)
|
||||
{
|
||||
struct frame *fr = &(mp->fr);
|
||||
int jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext << 2) + 4 : 32;
|
||||
int i;
|
||||
int illegal_value_detected = 0;
|
||||
unsigned char const ba15 = 15; /* bit pattern not allowed, looks like sync(?) */
|
||||
memset(si, 0, sizeof(*si));
|
||||
assert(fr->stereo == 1 || fr->stereo == 2);
|
||||
|
||||
if (fr->stereo == 2) {
|
||||
for (i = 0; i < jsbound; i++) {
|
||||
unsigned char b0 = get_leq_8_bits(mp, 4); /* values 0-15 */
|
||||
unsigned char b1 = get_leq_8_bits(mp, 4); /* values 0-15 */
|
||||
si->allocation[i][0] = b0;
|
||||
si->allocation[i][1] = b1;
|
||||
if (b0 == ba15 || b1 == ba15)
|
||||
illegal_value_detected = 1;
|
||||
}
|
||||
for (i = jsbound; i < SBLIMIT; i++) {
|
||||
unsigned char b = get_leq_8_bits(mp, 4); /* values 0-15 */
|
||||
si->allocation[i][0] = b;
|
||||
si->allocation[i][1] = b;
|
||||
if (b == ba15)
|
||||
illegal_value_detected = 1;
|
||||
}
|
||||
for (i = 0; i < SBLIMIT; i++) {
|
||||
unsigned char n0 = si->allocation[i][0];
|
||||
unsigned char n1 = si->allocation[i][1];
|
||||
unsigned char b0 = n0 ? get_leq_8_bits(mp, 6) : 0; /* values 0-63 */
|
||||
unsigned char b1 = n1 ? get_leq_8_bits(mp, 6) : 0; /* values 0-63 */
|
||||
si->scalefactor[i][0] = b0;
|
||||
si->scalefactor[i][1] = b1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < SBLIMIT; i++) {
|
||||
unsigned char b0 = get_leq_8_bits(mp, 4); /* values 0-15 */
|
||||
si->allocation[i][0] = b0;
|
||||
if (b0 == ba15)
|
||||
illegal_value_detected = 1;
|
||||
}
|
||||
for (i = 0; i < SBLIMIT; i++) {
|
||||
unsigned char n0 = si->allocation[i][0];
|
||||
unsigned char b0 = n0 ? get_leq_8_bits(mp, 6) : 0; /* values 0-63 */
|
||||
si->scalefactor[i][0] = b0;
|
||||
}
|
||||
}
|
||||
return illegal_value_detected;
|
||||
}
|
||||
|
||||
static void
|
||||
I_step_two(PMPSTR mp, sideinfo_layer_I *si, real fraction[2][SBLIMIT])
|
||||
{
|
||||
double r0, r1;
|
||||
struct frame *fr = &(mp->fr);
|
||||
int ds_limit = fr->down_sample_sblimit;
|
||||
int i;
|
||||
|
||||
assert(fr->stereo == 1 || fr->stereo == 2);
|
||||
if (fr->stereo == 2) {
|
||||
int jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext << 2) + 4 : 32;
|
||||
for (i = 0; i < jsbound; i++) {
|
||||
unsigned char i0 = si->scalefactor[i][0];
|
||||
unsigned char i1 = si->scalefactor[i][1];
|
||||
unsigned char n0 = si->allocation[i][0];
|
||||
unsigned char n1 = si->allocation[i][1];
|
||||
assert( i0 < 64 );
|
||||
assert( i1 < 64 );
|
||||
assert( n0 < 16 );
|
||||
assert( n1 < 16 );
|
||||
if (n0 > 0) {
|
||||
unsigned short v = get_leq_16_bits(mp, n0 + 1); /* 0-65535 */
|
||||
r0 = (((-1) << n0) + v + 1) * muls[n0 + 1][i0];
|
||||
}
|
||||
else {
|
||||
r0 = 0;
|
||||
}
|
||||
if (n1 > 0) {
|
||||
unsigned short v = get_leq_16_bits(mp, n1 + 1); /* 0-65535 */
|
||||
r1 = (((-1) << n1) + v + 1) * muls[n1 + 1][i1];
|
||||
}
|
||||
else {
|
||||
r1 = 0;
|
||||
}
|
||||
fraction[0][i] = (real)r0;
|
||||
fraction[1][i] = (real)r1;
|
||||
}
|
||||
for (i = jsbound; i < SBLIMIT; i++) {
|
||||
unsigned char i0 = si->scalefactor[i][0];
|
||||
unsigned char i1 = si->scalefactor[i][1];
|
||||
unsigned char n = si->allocation[i][0];
|
||||
assert( i0 < 64 );
|
||||
assert( i1 < 64 );
|
||||
assert( n < 16 );
|
||||
if (n > 0) {
|
||||
unsigned short v = get_leq_16_bits(mp, n + 1); /* 0-65535 */
|
||||
unsigned int w = (((-1) << n) + v + 1);
|
||||
r0 = w * muls[n + 1][i0];
|
||||
r1 = w * muls[n + 1][i1];
|
||||
}
|
||||
else {
|
||||
r0 = r1 = 0;
|
||||
}
|
||||
fraction[0][i] = (real)r0;
|
||||
fraction[1][i] = (real)r1;
|
||||
}
|
||||
for (i = ds_limit; i < SBLIMIT; i++) {
|
||||
fraction[0][i] = 0.0;
|
||||
fraction[1][i] = 0.0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < SBLIMIT; i++) {
|
||||
unsigned char n = si->allocation[i][0];
|
||||
unsigned char j = si->scalefactor[i][0];
|
||||
assert( j < 64 );
|
||||
assert( n < 16 );
|
||||
if (n > 0) {
|
||||
unsigned short v = get_leq_16_bits(mp, n + 1);
|
||||
r0 = (((-1) << n) + v + 1) * muls[n + 1][j];
|
||||
}
|
||||
else {
|
||||
r0 = 0;
|
||||
}
|
||||
fraction[0][i] = (real)r0;
|
||||
}
|
||||
for (i = ds_limit; i < SBLIMIT; i++) {
|
||||
fraction[0][i] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
decode_layer1_sideinfo(PMPSTR mp)
|
||||
{
|
||||
(void) mp;
|
||||
/* FIXME: extract side information and check values */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
decode_layer1_frame(PMPSTR mp, unsigned char *pcm_sample, int *pcm_point)
|
||||
{
|
||||
real fraction[2][SBLIMIT]; /* FIXME: change real -> double ? */
|
||||
sideinfo_layer_I si;
|
||||
struct frame *fr = &(mp->fr);
|
||||
int single = fr->single;
|
||||
int i, clip = 0;
|
||||
|
||||
if (I_step_one(mp, &si)) {
|
||||
lame_report_fnc(mp->report_err, "hip: Aborting layer 1 decode, illegal bit allocation value\n");
|
||||
return -1;
|
||||
}
|
||||
if (fr->stereo == 1 || single == 3)
|
||||
single = 0;
|
||||
|
||||
if (single >= 0) {
|
||||
/* decoding one of possibly two channels */
|
||||
for (i = 0; i < SCALE_BLOCK; i++) {
|
||||
I_step_two(mp, &si, fraction);
|
||||
clip += synth_1to1_mono(mp, (real *) fraction[single], pcm_sample, pcm_point);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < SCALE_BLOCK; i++) {
|
||||
int p1 = *pcm_point;
|
||||
I_step_two(mp, &si, fraction);
|
||||
clip += synth_1to1(mp, (real *) fraction[0], 0, pcm_sample, &p1);
|
||||
clip += synth_1to1(mp, (real *) fraction[1], 1, pcm_sample, pcm_point);
|
||||
}
|
||||
}
|
||||
|
||||
return clip;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAYER1_H_INCLUDED
|
||||
#define LAYER1_H_INCLUDED
|
||||
|
||||
void hip_init_tables_layer1(void);
|
||||
int decode_layer1_sideinfo(PMPSTR mp);
|
||||
int decode_layer1_frame(PMPSTR mp, unsigned char *pcm_sample, int *pcm_point);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,403 @@
|
||||
/*
|
||||
* layer2.c: Mpeg Layer-2 audio decoder
|
||||
*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
/* $Id: layer2.c,v 1.34 2017/08/22 23:31:07 robert Exp $ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
#include "layer2.h"
|
||||
#include "l2tables.h"
|
||||
#include "decode_i386.h"
|
||||
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
static int gd_are_hip_tables_layer2_initialized = 0;
|
||||
|
||||
static unsigned char grp_3tab[32 * 3] = { 0, }; /* used: 27 */
|
||||
static unsigned char grp_5tab[128 * 3] = { 0, }; /* used: 125 */
|
||||
static unsigned char grp_9tab[1024 * 3] = { 0, }; /* used: 729 */
|
||||
|
||||
|
||||
void
|
||||
hip_init_tables_layer2(void)
|
||||
{
|
||||
static const double mulmul[27] = {
|
||||
0.0, -2.0 / 3.0, 2.0 / 3.0,
|
||||
2.0 / 7.0, 2.0 / 15.0, 2.0 / 31.0, 2.0 / 63.0, 2.0 / 127.0, 2.0 / 255.0,
|
||||
2.0 / 511.0, 2.0 / 1023.0, 2.0 / 2047.0, 2.0 / 4095.0, 2.0 / 8191.0,
|
||||
2.0 / 16383.0, 2.0 / 32767.0, 2.0 / 65535.0,
|
||||
-4.0 / 5.0, -2.0 / 5.0, 2.0 / 5.0, 4.0 / 5.0,
|
||||
-8.0 / 9.0, -4.0 / 9.0, -2.0 / 9.0, 2.0 / 9.0, 4.0 / 9.0, 8.0 / 9.0
|
||||
};
|
||||
static const unsigned char base[3][9] = {
|
||||
{1, 0, 2,},
|
||||
{17, 18, 0, 19, 20,},
|
||||
{21, 1, 22, 23, 0, 24, 25, 2, 26}
|
||||
};
|
||||
int i, j, k, l, len;
|
||||
real *table;
|
||||
static const int tablen[3] = { 3, 5, 9 };
|
||||
static unsigned char *itable, *tables[3] = { grp_3tab, grp_5tab, grp_9tab };
|
||||
|
||||
if (gd_are_hip_tables_layer2_initialized) {
|
||||
return;
|
||||
}
|
||||
gd_are_hip_tables_layer2_initialized = 1;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
itable = tables[i];
|
||||
len = tablen[i];
|
||||
for (j = 0; j < len; j++)
|
||||
for (k = 0; k < len; k++)
|
||||
for (l = 0; l < len; l++) {
|
||||
*itable++ = base[i][l];
|
||||
*itable++ = base[i][k];
|
||||
*itable++ = base[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for (k = 0; k < 27; k++) {
|
||||
double m = mulmul[k];
|
||||
table = muls[k];
|
||||
for (j = 3, i = 0; i < 63; i++, j--)
|
||||
*table++ = (real) (m * pow(2.0, (double) j / 3.0));
|
||||
*table++ = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static unsigned char*
|
||||
grp_table_select(short d1, unsigned int idx)
|
||||
{
|
||||
/* RH: it seems to be common, that idx is larger than the table's sizes.
|
||||
is it OK to return a zero vector in this case? FIXME
|
||||
/*/
|
||||
static unsigned char dummy_table[] = { 0,0,0 };
|
||||
unsigned int x;
|
||||
switch (d1) {
|
||||
case 3:
|
||||
x = 3*3*3;
|
||||
idx = idx < x ? idx : x;
|
||||
return &grp_3tab[3 * idx];
|
||||
case 5:
|
||||
x = 5*5*5;
|
||||
idx = idx < x ? idx : x;
|
||||
return &grp_5tab[3 * idx];
|
||||
case 9:
|
||||
x = 9*9*9;
|
||||
idx = idx < x ? idx : x;
|
||||
return &grp_9tab[3 * idx];
|
||||
default:
|
||||
/* fatal error */
|
||||
assert(0);
|
||||
}
|
||||
return &dummy_table[0];
|
||||
}
|
||||
|
||||
typedef struct sideinfo_layer_II_struct
|
||||
{
|
||||
unsigned char allocation[SBLIMIT][2];
|
||||
unsigned char scalefactor[SBLIMIT][2][3]; /* subband / channel / block */
|
||||
} sideinfo_layer_II;
|
||||
|
||||
|
||||
|
||||
static void
|
||||
II_step_one(PMPSTR mp, sideinfo_layer_II *si, struct frame *fr)
|
||||
{
|
||||
int nch = fr->stereo;
|
||||
int sblimit = fr->II_sblimit;
|
||||
int jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext << 2) + 4 : fr->II_sblimit;
|
||||
struct al_table2 const *alloc1 = fr->alloc;
|
||||
unsigned char scfsi[SBLIMIT][2];
|
||||
int i, ch;
|
||||
|
||||
memset(si, 0, sizeof(*si));
|
||||
if (jsbound > sblimit)
|
||||
jsbound = sblimit;
|
||||
if (nch == 2) {
|
||||
for (i = 0; i < jsbound; ++i) {
|
||||
short step = alloc1->bits;
|
||||
unsigned char b0 = get_leq_8_bits(mp, step);
|
||||
unsigned char b1 = get_leq_8_bits(mp, step);
|
||||
alloc1 += ((size_t)1 << step);
|
||||
si->allocation[i][0] = b0;
|
||||
si->allocation[i][1] = b1;
|
||||
}
|
||||
for (i = jsbound; i < sblimit; ++i) {
|
||||
short step = alloc1->bits;
|
||||
unsigned char b0 = get_leq_8_bits(mp, step);
|
||||
alloc1 += ((size_t)1 << step);
|
||||
si->allocation[i][0] = b0;
|
||||
si->allocation[i][1] = b0;
|
||||
}
|
||||
for (i = 0; i < sblimit; ++i) {
|
||||
unsigned char n0 = si->allocation[i][0];
|
||||
unsigned char n1 = si->allocation[i][1];
|
||||
unsigned char b0 = n0 ? get_leq_8_bits(mp, 2) : 0;
|
||||
unsigned char b1 = n1 ? get_leq_8_bits(mp, 2) : 0;
|
||||
scfsi[i][0] = b0;
|
||||
scfsi[i][1] = b1;
|
||||
}
|
||||
}
|
||||
else { /* mono */
|
||||
for (i = 0; i < sblimit; ++i) {
|
||||
short step = alloc1->bits;
|
||||
unsigned char b0 = get_leq_8_bits(mp, step);
|
||||
alloc1 += ((size_t)1 << step);
|
||||
si->allocation[i][0] = b0;
|
||||
}
|
||||
for (i = 0; i < sblimit; ++i) {
|
||||
unsigned char n0 = si->allocation[i][0];
|
||||
unsigned char b0 = n0 ? get_leq_8_bits(mp, 2) : 0;
|
||||
scfsi[i][0] = b0;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < sblimit; ++i) {
|
||||
for (ch = 0; ch < nch; ++ch) {
|
||||
unsigned char s0 = 0, s1 = 0, s2 = 0;
|
||||
if (si->allocation[i][ch]) {
|
||||
switch (scfsi[i][ch]) {
|
||||
case 0:
|
||||
s0 = get_leq_8_bits(mp, 6);
|
||||
s1 = get_leq_8_bits(mp, 6);
|
||||
s2 = get_leq_8_bits(mp, 6);
|
||||
break;
|
||||
case 1:
|
||||
s0 = get_leq_8_bits(mp, 6);
|
||||
s1 = s0;
|
||||
s2 = get_leq_8_bits(mp, 6);
|
||||
break;
|
||||
case 2:
|
||||
s0 = get_leq_8_bits(mp, 6);
|
||||
s1 = s0;
|
||||
s2 = s0;
|
||||
break;
|
||||
case 3:
|
||||
s0 = get_leq_8_bits(mp, 6);
|
||||
s1 = get_leq_8_bits(mp, 6);
|
||||
s2 = s1;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
si->scalefactor[i][ch][0] = s0;
|
||||
si->scalefactor[i][ch][1] = s1;
|
||||
si->scalefactor[i][ch][2] = s2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
II_step_two(PMPSTR mp, sideinfo_layer_II* si, struct frame *fr, int gr, real fraction[2][4][SBLIMIT])
|
||||
{
|
||||
struct al_table2 const *alloc1 = fr->alloc;
|
||||
int sblimit = fr->II_sblimit;
|
||||
int jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext << 2) + 4 : fr->II_sblimit;
|
||||
int i, ch, nch = fr->stereo;
|
||||
double cm, r0, r1, r2;
|
||||
|
||||
if (jsbound > sblimit)
|
||||
jsbound = sblimit;
|
||||
for (i = 0; i < jsbound; ++i) {
|
||||
short step = alloc1->bits;
|
||||
for (ch = 0; ch < nch; ++ch) {
|
||||
unsigned char ba = si->allocation[i][ch];
|
||||
if (ba) {
|
||||
unsigned char x1 = si->scalefactor[i][ch][gr];
|
||||
struct al_table2 const *alloc2 = alloc1 + ba;
|
||||
short k = alloc2->bits;
|
||||
short d1 = alloc2->d;
|
||||
assert( k <= 16 );
|
||||
k = (k <= 16) ? k : 16;
|
||||
assert( x1 < 64 );
|
||||
x1 = (x1 < 64) ? x1 : 63;
|
||||
if (d1 < 0) {
|
||||
int v0 = getbits(mp, k);
|
||||
int v1 = getbits(mp, k);
|
||||
int v2 = getbits(mp, k);
|
||||
cm = muls[k][x1];
|
||||
r0 = (v0 + d1) * cm;
|
||||
r1 = (v1 + d1) * cm;
|
||||
r2 = (v2 + d1) * cm;
|
||||
}
|
||||
else {
|
||||
unsigned int idx = getbits(mp, k);
|
||||
unsigned char *tab = grp_table_select(d1, idx);
|
||||
unsigned char k0 = tab[0];
|
||||
unsigned char k1 = tab[1];
|
||||
unsigned char k2 = tab[2];
|
||||
r0 = muls[k0][x1];
|
||||
r1 = muls[k1][x1];
|
||||
r2 = muls[k2][x1];
|
||||
}
|
||||
fraction[ch][0][i] = (real) r0;
|
||||
fraction[ch][1][i] = (real) r1;
|
||||
fraction[ch][2][i] = (real) r2;
|
||||
}
|
||||
else {
|
||||
fraction[ch][0][i] = fraction[ch][1][i] = fraction[ch][2][i] = 0.0;
|
||||
}
|
||||
}
|
||||
alloc1 += ((size_t)1 << step);
|
||||
}
|
||||
|
||||
for (i = jsbound; i < sblimit; i++) {
|
||||
short step = alloc1->bits;
|
||||
unsigned char ba = si->allocation[i][0];
|
||||
if (ba) {
|
||||
struct al_table2 const *alloc2 = alloc1 + ba;
|
||||
short k = alloc2->bits;
|
||||
short d1 = alloc2->d;
|
||||
assert( k <= 16 );
|
||||
k = (k <= 16) ? k : 16;
|
||||
if (d1 < 0) {
|
||||
int v0 = getbits(mp, k);
|
||||
int v1 = getbits(mp, k);
|
||||
int v2 = getbits(mp, k);
|
||||
for (ch = 0; ch < nch; ++ch) {
|
||||
unsigned char x1 = si->scalefactor[i][ch][gr];
|
||||
assert( x1 < 64 );
|
||||
x1 = (x1 < 64) ? x1 : 63;
|
||||
cm = muls[k][x1];
|
||||
r0 = (v0 + d1) * cm;
|
||||
r1 = (v1 + d1) * cm;
|
||||
r2 = (v2 + d1) * cm;
|
||||
fraction[ch][0][i] = (real) r0;
|
||||
fraction[ch][1][i] = (real) r1;
|
||||
fraction[ch][2][i] = (real) r2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
unsigned int idx = getbits(mp, k);
|
||||
unsigned char *tab = grp_table_select(d1, idx);
|
||||
unsigned char k0 = tab[0];
|
||||
unsigned char k1 = tab[1];
|
||||
unsigned char k2 = tab[2];
|
||||
for (ch = 0; ch < nch; ++ch) {
|
||||
unsigned char x1 = si->scalefactor[i][ch][gr];
|
||||
assert( x1 < 64 );
|
||||
x1 = (x1 < 64) ? x1 : 63;
|
||||
r0 = muls[k0][x1];
|
||||
r1 = muls[k1][x1];
|
||||
r2 = muls[k2][x1];
|
||||
fraction[ch][0][i] = (real) r0;
|
||||
fraction[ch][1][i] = (real) r1;
|
||||
fraction[ch][2][i] = (real) r2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] = 0.0;
|
||||
fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0;
|
||||
}
|
||||
alloc1 += ((size_t)1 << step);
|
||||
}
|
||||
if (sblimit > fr->down_sample_sblimit) {
|
||||
sblimit = fr->down_sample_sblimit;
|
||||
}
|
||||
for (ch = 0; ch < nch; ++ch) {
|
||||
for (i = sblimit; i < SBLIMIT; ++i) {
|
||||
fraction[ch][0][i] = fraction[ch][1][i] = fraction[ch][2][i] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
II_select_table(struct frame *fr)
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
static const int translate[3][2][16] =
|
||||
{ { { 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0 } ,
|
||||
{ 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0 } } ,
|
||||
{ { 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0 } ,
|
||||
{ 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0 } } ,
|
||||
{ { 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0 } ,
|
||||
{ 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0 } } };
|
||||
/* *INDENT-ON* */
|
||||
|
||||
int table, sblim;
|
||||
static const struct al_table2 *tables[5] = { alloc_0, alloc_1, alloc_2, alloc_3, alloc_4 };
|
||||
static const int sblims[5] = { 27, 30, 8, 12, 30 };
|
||||
|
||||
if (fr->lsf)
|
||||
table = 4;
|
||||
else
|
||||
table = translate[fr->sampling_frequency][2 - fr->stereo][fr->bitrate_index];
|
||||
sblim = sblims[table];
|
||||
|
||||
fr->alloc = (struct al_table2 const *) tables[table];
|
||||
fr->II_sblimit = sblim;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
decode_layer2_sideinfo(PMPSTR mp)
|
||||
{
|
||||
(void) mp;
|
||||
/* FIXME: extract side information and check values */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
decode_layer2_frame(PMPSTR mp, unsigned char *pcm_sample, int *pcm_point)
|
||||
{
|
||||
real fraction[2][4][SBLIMIT]; /* pick_table clears unused subbands */
|
||||
sideinfo_layer_II si;
|
||||
struct frame *fr = &(mp->fr);
|
||||
int single = fr->single;
|
||||
int i, j, clip = 0;
|
||||
|
||||
II_select_table(fr);
|
||||
II_step_one(mp, &si, fr);
|
||||
|
||||
if (fr->stereo == 1 || single == 3)
|
||||
single = 0;
|
||||
|
||||
if (single >= 0) {
|
||||
for (i = 0; i < SCALE_BLOCK; i++) {
|
||||
II_step_two(mp, &si, fr, i >> 2, fraction);
|
||||
for (j = 0; j < 3; j++) {
|
||||
clip += synth_1to1_mono(mp, fraction[single][j], pcm_sample, pcm_point);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < SCALE_BLOCK; i++) {
|
||||
II_step_two(mp, &si, fr, i >> 2, fraction);
|
||||
for (j = 0; j < 3; j++) {
|
||||
int p1 = *pcm_point;
|
||||
clip += synth_1to1(mp, fraction[0][j], 0, pcm_sample, &p1);
|
||||
clip += synth_1to1(mp, fraction[1][j], 1, pcm_sample, pcm_point);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return clip;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LAYER2_H_INCLUDED
|
||||
#define LAYER2_H_INCLUDED
|
||||
|
||||
|
||||
struct al_table2 {
|
||||
short bits;
|
||||
short d;
|
||||
};
|
||||
|
||||
|
||||
|
||||
void hip_init_tables_layer2(void);
|
||||
int decode_layer2_sideinfo(PMPSTR mp);
|
||||
int decode_layer2_frame(PMPSTR mp, unsigned char *pcm_sample, int *pcm_point);
|
||||
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LAYER3_H_INCLUDED
|
||||
#define LAYER3_H_INCLUDED
|
||||
|
||||
void hip_init_tables_layer3(void);
|
||||
int decode_layer3_sideinfo(PMPSTR mp);
|
||||
int decode_layer3_frame(PMPSTR mp, unsigned char *pcm_sample, int *pcm_point,
|
||||
int (*synth_1to1_mono_ptr) (PMPSTR, real *, unsigned char *, int *),
|
||||
int (*synth_1to1_ptr) (PMPSTR, real *, int, unsigned char *, int *));
|
||||
int layer3_audiodata_precedesframes(PMPSTR mp);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MPG123_H_INCLUDED
|
||||
#define MPG123_H_INCLUDED
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef STDC_HEADERS
|
||||
# include <string.h>
|
||||
#else
|
||||
# ifndef HAVE_STRCHR
|
||||
# define strchr index
|
||||
# define strrchr rindex
|
||||
# endif
|
||||
char *strchr(), *strrchr();
|
||||
# ifndef HAVE_MEMCPY
|
||||
# define memcpy(d, s, n) bcopy ((s), (d), (n))
|
||||
# define memmove(d, s, n) bcopy ((s), (d), (n))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
#if defined(__riscos__) && defined(FPA10)
|
||||
#include "ymath.h"
|
||||
#else
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
#ifndef M_SQRT2
|
||||
#define M_SQRT2 1.41421356237309504880
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#undef REAL_IS_FLOAT
|
||||
#define REAL_IS_FLOAT
|
||||
|
||||
#ifdef REAL_IS_FLOAT
|
||||
# define real float
|
||||
#elif defined(REAL_IS_LONG_DOUBLE)
|
||||
# define real long double
|
||||
#else
|
||||
# define real double
|
||||
#endif
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
#define SBLIMIT 32
|
||||
#define SSLIMIT 18
|
||||
|
||||
#define MPG_MD_STEREO 0
|
||||
#define MPG_MD_JOINT_STEREO 1
|
||||
#define MPG_MD_DUAL_CHANNEL 2
|
||||
#define MPG_MD_MONO 3
|
||||
|
||||
#define MAXFRAMESIZE 2880
|
||||
|
||||
/* AF: ADDED FOR LAYER1/LAYER2 */
|
||||
#define SCALE_BLOCK 12
|
||||
|
||||
|
||||
/* Pre Shift fo 16 to 8 bit converter table */
|
||||
#define AUSHIFT (3)
|
||||
|
||||
struct frame {
|
||||
int stereo;
|
||||
int single; /* single channel (monophonic) */
|
||||
int lsf; /* 0 = MPEG-1, 1 = MPEG-2/2.5 */
|
||||
int mpeg25; /* 1 = MPEG-2.5, 0 = MPEG-1/2 */
|
||||
int header_change;
|
||||
int lay; /* Layer */
|
||||
int error_protection; /* 1 = CRC-16 code following header */
|
||||
int bitrate_index;
|
||||
int sampling_frequency; /* sample rate of decompressed audio in Hz */
|
||||
int padding;
|
||||
int extension;
|
||||
int mode;
|
||||
int mode_ext;
|
||||
int copyright;
|
||||
int original;
|
||||
int emphasis;
|
||||
int framesize; /* computed framesize */
|
||||
|
||||
/* AF: ADDED FOR LAYER1/LAYER2 */
|
||||
int II_sblimit;
|
||||
struct al_table2 const *alloc;
|
||||
int down_sample_sblimit;
|
||||
int down_sample;
|
||||
|
||||
|
||||
};
|
||||
|
||||
struct gr_info_s {
|
||||
int scfsi;
|
||||
unsigned part2_3_length;
|
||||
unsigned big_values;
|
||||
unsigned scalefac_compress;
|
||||
unsigned block_type;
|
||||
unsigned mixed_block_flag;
|
||||
unsigned table_select[3];
|
||||
unsigned subblock_gain[3];
|
||||
unsigned maxband[3];
|
||||
unsigned maxbandl;
|
||||
unsigned maxb;
|
||||
unsigned region1start;
|
||||
unsigned region2start;
|
||||
unsigned preflag;
|
||||
unsigned scalefac_scale;
|
||||
unsigned count1table_select;
|
||||
real *full_gain[3];
|
||||
real *pow2gain;
|
||||
};
|
||||
|
||||
struct III_sideinfo {
|
||||
unsigned main_data_begin;
|
||||
unsigned private_bits;
|
||||
struct {
|
||||
struct gr_info_s gr[2];
|
||||
} ch[2];
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef _MPGLIB_H_
|
||||
#define _MPGLIB_H_
|
||||
|
||||
#include "lame.h"
|
||||
|
||||
#ifndef plotting_data_defined
|
||||
#define plotting_data_defined
|
||||
struct plotting_data;
|
||||
typedef struct plotting_data plotting_data;
|
||||
#endif
|
||||
|
||||
|
||||
extern void lame_report_fnc(lame_report_function f, const char *format, ...);
|
||||
|
||||
struct buf {
|
||||
unsigned char *pnt;
|
||||
long size;
|
||||
long pos;
|
||||
struct buf *next;
|
||||
struct buf *prev;
|
||||
};
|
||||
|
||||
struct framebuf {
|
||||
struct buf *buf;
|
||||
long pos;
|
||||
struct frame *next;
|
||||
struct frame *prev;
|
||||
};
|
||||
|
||||
typedef struct mpstr_tag {
|
||||
struct buf *head, *tail; /* buffer linked list pointers, tail points to oldest buffer */
|
||||
int vbr_header; /* 1 if valid Xing vbr header detected */
|
||||
int num_frames; /* set if vbr header present */
|
||||
int enc_delay; /* set if vbr header present */
|
||||
int enc_padding; /* set if vbr header present */
|
||||
/* header_parsed, side_parsed and data_parsed must be all set 1
|
||||
before the full frame has been parsed */
|
||||
int header_parsed; /* 1 = header of current frame has been parsed */
|
||||
int side_parsed; /* 1 = header of sideinfo of current frame has been parsed */
|
||||
int data_parsed;
|
||||
int free_format; /* 1 = free format frame */
|
||||
int old_free_format; /* 1 = last frame was free format */
|
||||
int bsize;
|
||||
int framesize;
|
||||
int ssize; /* number of bytes used for side information, including 2 bytes for CRC-16 if present */
|
||||
int dsize;
|
||||
int fsizeold; /* size of previous frame, -1 for first */
|
||||
int fsizeold_nopadding;
|
||||
struct frame fr; /* holds the parameters decoded from the header */
|
||||
struct III_sideinfo sideinfo;
|
||||
unsigned char bsspace[2][MAXFRAMESIZE + 1024]; /* bit stream space used ???? */ /* MAXFRAMESIZE */
|
||||
real hybrid_block[2][2][SBLIMIT * SSLIMIT];
|
||||
int hybrid_blc[2];
|
||||
unsigned long header;
|
||||
int bsnum;
|
||||
real synth_buffs[2][2][0x110];
|
||||
int synth_bo;
|
||||
int sync_bitstream; /* 1 = bitstream is yet to be synchronized */
|
||||
|
||||
int bitindex;
|
||||
unsigned char *wordpointer;
|
||||
plotting_data *pinfo;
|
||||
|
||||
lame_report_function report_msg;
|
||||
lame_report_function report_dbg;
|
||||
lame_report_function report_err;
|
||||
} MPSTR, *PMPSTR;
|
||||
|
||||
|
||||
#define MP3_ERR -1
|
||||
#define MP3_OK 0
|
||||
#define MP3_NEED_MORE 1
|
||||
|
||||
|
||||
|
||||
#endif /* _MPGLIB_H_ */
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* tabinit.c
|
||||
*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
/* $Id: tabinit.c,v 1.17 2017/09/06 15:07:30 robert Exp $ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "tabinit.h"
|
||||
#include "mpg123.h"
|
||||
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif
|
||||
|
||||
static int table_init_called = 0;
|
||||
|
||||
real decwin[512 + 32];
|
||||
static real cos64[16], cos32[8], cos16[4], cos8[2], cos4[1];
|
||||
real *pnts[] = { cos64, cos32, cos16, cos8, cos4 };
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
|
||||
static const double dewin[512] = {
|
||||
0.000000000,-0.000015259,-0.000015259,-0.000015259,
|
||||
-0.000015259,-0.000015259,-0.000015259,-0.000030518,
|
||||
-0.000030518,-0.000030518,-0.000030518,-0.000045776,
|
||||
-0.000045776,-0.000061035,-0.000061035,-0.000076294,
|
||||
-0.000076294,-0.000091553,-0.000106812,-0.000106812,
|
||||
-0.000122070,-0.000137329,-0.000152588,-0.000167847,
|
||||
-0.000198364,-0.000213623,-0.000244141,-0.000259399,
|
||||
-0.000289917,-0.000320435,-0.000366211,-0.000396729,
|
||||
-0.000442505,-0.000473022,-0.000534058,-0.000579834,
|
||||
-0.000625610,-0.000686646,-0.000747681,-0.000808716,
|
||||
-0.000885010,-0.000961304,-0.001037598,-0.001113892,
|
||||
-0.001205444,-0.001296997,-0.001388550,-0.001480103,
|
||||
-0.001586914,-0.001693726,-0.001785278,-0.001907349,
|
||||
-0.002014160,-0.002120972,-0.002243042,-0.002349854,
|
||||
-0.002456665,-0.002578735,-0.002685547,-0.002792358,
|
||||
-0.002899170,-0.002990723,-0.003082275,-0.003173828,
|
||||
-0.003250122,-0.003326416,-0.003387451,-0.003433228,
|
||||
-0.003463745,-0.003479004,-0.003479004,-0.003463745,
|
||||
-0.003417969,-0.003372192,-0.003280640,-0.003173828,
|
||||
-0.003051758,-0.002883911,-0.002700806,-0.002487183,
|
||||
-0.002227783,-0.001937866,-0.001617432,-0.001266479,
|
||||
-0.000869751,-0.000442505, 0.000030518, 0.000549316,
|
||||
0.001098633, 0.001693726, 0.002334595, 0.003005981,
|
||||
0.003723145, 0.004486084, 0.005294800, 0.006118774,
|
||||
0.007003784, 0.007919312, 0.008865356, 0.009841919,
|
||||
0.010848999, 0.011886597, 0.012939453, 0.014022827,
|
||||
0.015121460, 0.016235352, 0.017349243, 0.018463135,
|
||||
0.019577026, 0.020690918, 0.021789551, 0.022857666,
|
||||
0.023910522, 0.024932861, 0.025909424, 0.026840210,
|
||||
0.027725220, 0.028533936, 0.029281616, 0.029937744,
|
||||
0.030532837, 0.031005859, 0.031387329, 0.031661987,
|
||||
0.031814575, 0.031845093, 0.031738281, 0.031478882,
|
||||
0.031082153, 0.030517578, 0.029785156, 0.028884888,
|
||||
0.027801514, 0.026535034, 0.025085449, 0.023422241,
|
||||
0.021575928, 0.019531250, 0.017257690, 0.014801025,
|
||||
0.012115479, 0.009231567, 0.006134033, 0.002822876,
|
||||
-0.000686646,-0.004394531,-0.008316040,-0.012420654,
|
||||
-0.016708374,-0.021179199,-0.025817871,-0.030609131,
|
||||
-0.035552979,-0.040634155,-0.045837402,-0.051132202,
|
||||
-0.056533813,-0.061996460,-0.067520142,-0.073059082,
|
||||
-0.078628540,-0.084182739,-0.089706421,-0.095169067,
|
||||
-0.100540161,-0.105819702,-0.110946655,-0.115921021,
|
||||
-0.120697021,-0.125259399,-0.129562378,-0.133590698,
|
||||
-0.137298584,-0.140670776,-0.143676758,-0.146255493,
|
||||
-0.148422241,-0.150115967,-0.151306152,-0.151962280,
|
||||
-0.152069092,-0.151596069,-0.150497437,-0.148773193,
|
||||
-0.146362305,-0.143264771,-0.139450073,-0.134887695,
|
||||
-0.129577637,-0.123474121,-0.116577148,-0.108856201,
|
||||
-0.100311279,-0.090927124,-0.080688477,-0.069595337,
|
||||
-0.057617187,-0.044784546,-0.031082153,-0.016510010,
|
||||
-0.001068115, 0.015228271, 0.032379150, 0.050354004,
|
||||
0.069168091, 0.088775635, 0.109161377, 0.130310059,
|
||||
0.152206421, 0.174789429, 0.198059082, 0.221984863,
|
||||
0.246505737, 0.271591187, 0.297210693, 0.323318481,
|
||||
0.349868774, 0.376800537, 0.404083252, 0.431655884,
|
||||
0.459472656, 0.487472534, 0.515609741, 0.543823242,
|
||||
0.572036743, 0.600219727, 0.628295898, 0.656219482,
|
||||
0.683914185, 0.711318970, 0.738372803, 0.765029907,
|
||||
0.791213989, 0.816864014, 0.841949463, 0.866363525,
|
||||
0.890090942, 0.913055420, 0.935195923, 0.956481934,
|
||||
0.976852417, 0.996246338, 1.014617920, 1.031936646,
|
||||
1.048156738, 1.063217163, 1.077117920, 1.089782715,
|
||||
1.101211548, 1.111373901, 1.120223999, 1.127746582,
|
||||
1.133926392, 1.138763428, 1.142211914, 1.144287109,
|
||||
1.144989014
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
void
|
||||
make_decode_tables(long scaleval)
|
||||
{
|
||||
int i, j, k, kr, divv;
|
||||
real *table, *costab;
|
||||
|
||||
if (table_init_called)
|
||||
return;
|
||||
|
||||
table_init_called = 1;
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
kr = 0x10 >> i;
|
||||
divv = 0x40 >> i;
|
||||
costab = pnts[i];
|
||||
for (k = 0; k < kr; k++)
|
||||
costab[k] = (real) (1.0 / (2.0 * cos(M_PI * ((double) k * 2.0 + 1.0) / (double) divv)));
|
||||
}
|
||||
|
||||
table = decwin;
|
||||
scaleval = -scaleval;
|
||||
for (i = 0, j = 0; i < 256; i++, j++, table += 32) {
|
||||
if (table < decwin + 512 + 16)
|
||||
table[16] = table[0] = (real) (dewin[j] * scaleval);
|
||||
if (i % 32 == 31)
|
||||
table -= 1023;
|
||||
if (i % 64 == 63)
|
||||
scaleval = -scaleval;
|
||||
}
|
||||
|
||||
for ( /* i=256 */ ; i < 512; i++, j--, table += 32) {
|
||||
if (table < decwin + 512 + 16)
|
||||
table[16] = table[0] = (real) (dewin[j] * scaleval);
|
||||
if (i % 32 == 31)
|
||||
table -= 1023;
|
||||
if (i % 64 == 63)
|
||||
scaleval = -scaleval;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2010 The L.A.M.E. project
|
||||
*
|
||||
* Initially written by Michael Hipp, see also AUTHORS and README.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MPGLIB_TABINIT_H_INCLUDED
|
||||
#define MPGLIB_TABINIT_H_INCLUDED
|
||||
|
||||
#include "mpg123.h"
|
||||
|
||||
extern real decwin[512 + 32];
|
||||
extern real *pnts[5];
|
||||
|
||||
void make_decode_tables(long scale);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user