mirror of https://github.com/arendst/Tasmota.git
add shine mp3 encoder
This commit is contained in:
parent
1ae58ed0ac
commit
df9a99944e
|
@ -0,0 +1,482 @@
|
|||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the library GPL. It is
|
||||
numbered 2 because it goes with version 2 of the ordinary GPL.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Library General Public License, applies to some
|
||||
specially designated Free Software Foundation software, and to any
|
||||
other libraries whose authors decide to use it. You can use it for
|
||||
your libraries, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if
|
||||
you distribute copies of the library, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link a program with the library, you must provide
|
||||
complete object files to the recipients so that they can relink them
|
||||
with the library, after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
Our method of protecting your rights has two steps: (1) copyright
|
||||
the library, and (2) offer you this license which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
Also, for each distributor's protection, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
library. If the library is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original
|
||||
version, so that any problems introduced by others will not reflect on
|
||||
the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that companies distributing free
|
||||
software will individually obtain patent licenses, thus in effect
|
||||
transforming the program into proprietary software. To prevent this,
|
||||
we have made it clear that any patent must be licensed for everyone's
|
||||
free use or not licensed at all.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the ordinary
|
||||
GNU General Public License, which was designed for utility programs. This
|
||||
license, the GNU Library General Public License, applies to certain
|
||||
designated libraries. This license is quite different from the ordinary
|
||||
one; be sure to read it in full, and don't assume that anything in it is
|
||||
the same as in the ordinary license.
|
||||
|
||||
The reason we have a separate public license for some libraries is that
|
||||
they blur the distinction we usually make between modifying or adding to a
|
||||
program and simply using it. Linking a program with a library, without
|
||||
changing the library, is in some sense simply using the library, and is
|
||||
analogous to running a utility program or application program. However, in
|
||||
a textual and legal sense, the linked executable is a combined work, a
|
||||
derivative of the original library, and the ordinary General Public License
|
||||
treats it as such.
|
||||
|
||||
Because of this blurred distinction, using the ordinary General
|
||||
Public License for libraries did not effectively promote software
|
||||
sharing, because most developers did not use the libraries. We
|
||||
concluded that weaker conditions might promote sharing better.
|
||||
|
||||
However, unrestricted linking of non-free programs would deprive the
|
||||
users of those programs of all benefit from the free status of the
|
||||
libraries themselves. This Library General Public License is intended to
|
||||
permit developers of non-free programs to use free libraries, while
|
||||
preserving your freedom as a user of such programs to change the free
|
||||
libraries that are incorporated in them. (We have not seen how to achieve
|
||||
this as regards changes in header files, but we have achieved it as regards
|
||||
changes in the actual functions of the Library.) The hope is that this
|
||||
will lead to faster development of free libraries.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, while the latter only
|
||||
works together with the library.
|
||||
|
||||
Note that it is possible for a library to be covered by the ordinary
|
||||
General Public License rather than by this special one.
|
||||
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library which
|
||||
contains a notice placed by the copyright holder or other authorized
|
||||
party saying it may be distributed under the terms of this Library
|
||||
General Public License (also called "this License"). Each licensee is
|
||||
addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also compile or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
c) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
d) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the source code distributed need not include anything that is normally
|
||||
distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Library General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<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,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, 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
|
||||
them 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 prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If 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 convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state 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 program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
@ -0,0 +1,30 @@
|
|||
# mp3_shine_esp32
|
||||
Shine MP3 encoder for ESP32 - Last updated FEB 2019 - Compatibility with current IDF unknown!!
|
||||
|
||||
This is a 'port' of the old Shine MP3 encoder originally written for ARM or MIPS arch devices, quite a long time ago.
|
||||
|
||||
Memory allocation has been optimised for the ESP32
|
||||
Some asm has been added to boost performance in the ESP32 arch
|
||||
|
||||
The are leftovers of the beginings of a dual core implementation but this was not required in the end, the code has not been cleaned up.
|
||||
|
||||
You should init the encoder ASAP in your code as the encoder needs large contiguous chunks of RAM.
|
||||
|
||||
A sample FreeRTOS task has been included as a guide. Change it to suit your own needs.
|
||||
|
||||
For full 48000Hz Joint Stereo performance on one core your will need to compile with the -Os optimisation option.
|
||||
|
||||
I will try to get an HTTP MP3 streaming demo up at some stage, but I'm currently working 80 hour weeks so don't hold your breath.
|
||||
|
||||
Any questions feel free to ask.
|
||||
|
||||
Cheers!
|
||||
-fkn
|
||||
|
||||
Limitations
|
||||
|
||||
The encoding algorithm is rather simple. In particular, it does not have any Psychoacoustic Model.
|
||||
|
||||
A bit of history
|
||||
|
||||
This code was dug out from the dusty crates of those times before internet and github. It apparently was created by Gabriel Bouvigne sometime around the end of the 20th century. The encoder was converted circa 2001 by Pete Everett to fixed-point arithmetic for the RISC OS. Latest we know, Patrick Roberts had worked on the code to make it multi-platform and more library oriented. That was around 2006.
|
|
@ -0,0 +1,2 @@
|
|||
0.1.4: better input wav file handling (from Yichin Lin)
|
||||
code cleanup
|
|
@ -0,0 +1,12 @@
|
|||
#
|
||||
# Main Makefile. This is basically the same as a component makefile.
|
||||
#
|
||||
# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default,
|
||||
# this will take the sources in the src/ directory, compile them and link them into
|
||||
# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
|
||||
# please read the ESP-IDF documents if you need to do this.
|
||||
#
|
||||
|
||||
COMPONENT_SRCDIRS := .
|
||||
COMPONENT_PRIV_INCLUDEDIRS := .
|
||||
# CFLAGS +=
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "mp3_shine_esp32",
|
||||
"description": "mp3 encoder",
|
||||
"keywords": "ESP32, MP3",
|
||||
"version": "1.0.0",
|
||||
"frameworks": "Arduino"
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
name=mp3_shine_esp32
|
||||
version=1.0
|
||||
author=
|
||||
maintainer=
|
||||
sentence=mp3 encoder for ESP32
|
||||
paragraph=
|
||||
category=Signal processor
|
||||
url=
|
||||
architectures=esp32
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* bit_stream.c package
|
||||
* Author: Jean-Georges Fritsch, C-Cube Microsystems
|
||||
*
|
||||
* This package provides functions to write information to the bit stream.
|
||||
*
|
||||
* Removed unused functions. Feb 2001 P.Everett
|
||||
*/
|
||||
|
||||
#include "types.h"
|
||||
#include "bitstream.h"
|
||||
|
||||
#if !defined(__APPLE__) && !defined(__FreeBSD__)
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
/* open the device to write the bit stream into it */
|
||||
void shine_open_bit_stream(bitstream_t *bs, int size) {
|
||||
bs->data = (unsigned char *)malloc(size*sizeof(unsigned char));
|
||||
bs->data_size = size;
|
||||
bs->data_position = 0;
|
||||
bs->cache = 0;
|
||||
bs->cache_bits = 32;
|
||||
}
|
||||
|
||||
/*close the device containing the bit stream */
|
||||
void shine_close_bit_stream(bitstream_t *bs) {
|
||||
if (bs->data)
|
||||
free(bs->data);
|
||||
}
|
||||
|
||||
/*
|
||||
* shine_putbits:
|
||||
* --------
|
||||
* write N bits into the bit stream.
|
||||
* bs = bit stream structure
|
||||
* val = value to write into the buffer
|
||||
* N = number of bits of val
|
||||
*/
|
||||
void shine_putbits(bitstream_t *bs, unsigned int val, unsigned int N) {
|
||||
#ifdef SHINE_DEBUG
|
||||
if (N > 32) {
|
||||
printf("Cannot write more than 32 bits at a time.\n");
|
||||
}
|
||||
if (N < 32 && (val >> N) != 0) {
|
||||
printf("Upper bits (higher than %d) are not all zeros.\n", N);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (bs->cache_bits > N) {
|
||||
bs->cache_bits -= N;
|
||||
bs->cache |= val << bs->cache_bits;
|
||||
} else {
|
||||
if (bs->data_position + sizeof(unsigned int) >= bs->data_size) {
|
||||
bs->data = (unsigned char *)realloc(bs->data, bs->data_size + (bs->data_size / 2));
|
||||
bs->data_size += (bs->data_size / 2);
|
||||
}
|
||||
|
||||
N -= bs->cache_bits;
|
||||
bs->cache |= val >> N;
|
||||
#ifdef SHINE_BIG_ENDIAN
|
||||
*(unsigned int*)(bs->data + bs->data_position) = bs->cache;
|
||||
#else
|
||||
*(unsigned int*)(bs->data + bs->data_position) = SWAB32(bs->cache);
|
||||
#endif
|
||||
bs->data_position += sizeof(unsigned int);
|
||||
bs->cache_bits = 32 - N;
|
||||
if (N != 0)
|
||||
bs->cache = val << bs->cache_bits;
|
||||
else
|
||||
bs->cache = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int shine_get_bits_count(bitstream_t *bs) {
|
||||
return bs->data_position * 8 + 32 - bs->cache_bits;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef BITSTREAM_H
|
||||
#define BITSTREAM_H
|
||||
|
||||
typedef struct bit_stream_struc {
|
||||
unsigned char *data; /* Processed data */
|
||||
int data_size; /* Total data size */
|
||||
int data_position; /* Data position */
|
||||
unsigned int cache; /* bit stream cache */
|
||||
int cache_bits; /* free bits in cache */
|
||||
} bitstream_t;
|
||||
|
||||
/* "bit_stream.h" Definitions */
|
||||
|
||||
#define MINIMUM 4 /* Minimum size of the buffer in bytes */
|
||||
#define MAX_LENGTH 32 /* Maximum length of word written or
|
||||
read from bit stream */
|
||||
|
||||
#define BUFFER_SIZE 4096
|
||||
|
||||
//#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||
//#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
||||
|
||||
void shine_open_bit_stream(bitstream_t *bs,const int size);
|
||||
void shine_close_bit_stream(bitstream_t *bs);
|
||||
void shine_putbits(bitstream_t *bs,unsigned int val, unsigned int N);
|
||||
int shine_get_bits_count(bitstream_t *bs);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,120 @@
|
|||
/* huffman.c */
|
||||
|
||||
#include "types.h"
|
||||
#include "huffman.h"
|
||||
#include "bitstream.h"
|
||||
#include "l3bitstream.h"
|
||||
|
||||
const HUFFBITS dmask = 1 << (((sizeof(HUFFBITS))<<3)-1);
|
||||
const unsigned int hs = sizeof(HUFFBITS)<<3;
|
||||
|
||||
static const HUFFBITS t1HB[] = {1, 1, 1, 0};
|
||||
static const HUFFBITS t2HB[] = {1, 2, 1, 3, 1, 1, 3, 2, 0};
|
||||
static const HUFFBITS t3HB[] = {3, 2, 1, 1, 1, 1, 3, 2, 0};
|
||||
static const HUFFBITS t5HB[] = {1, 2, 6, 5, 3, 1, 4, 4, 7, 5, 7, 1, 6, 1, 1, 0};
|
||||
static const HUFFBITS t6HB[] = {7, 3, 5, 1, 6, 2, 3, 2, 5, 4, 4, 1, 3, 3, 2, 0};
|
||||
static const HUFFBITS 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 HUFFBITS 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 HUFFBITS 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 HUFFBITS 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 HUFFBITS 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 HUFFBITS 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 HUFFBITS 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 HUFFBITS 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 HUFFBITS 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 HUFFBITS 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 HUFFBITS t32HB[] = {1, 5, 4, 5, 6, 5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1};
|
||||
static const HUFFBITS t33HB[] = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
|
||||
|
||||
static const unsigned char t1l[] = {1, 3, 2, 3};
|
||||
static const unsigned char t2l[] = {1, 3, 6, 3, 3, 5, 5, 5, 6};
|
||||
static const unsigned char t3l[] = {2, 2, 6, 3, 2, 5, 5, 5, 6};
|
||||
static const unsigned char t5l[] = {1, 3, 6, 7, 3, 3, 6, 7, 6, 6, 7, 8, 7, 6, 7, 8};
|
||||
static const unsigned char t6l[] = {3, 3, 5, 7, 3, 2, 4, 5, 4, 4, 5, 6, 6, 5, 6, 7};
|
||||
static const unsigned char t7l[] = {1, 3, 6, 8, 8, 9, 3, 4, 6, 7, 7, 8, 6, 5, 7, 8, 8, 9, 7, 7, 8, 9, 9, 9, 7, 7, 8, 9, 9, 10, 8, 8, 9, 10, 10, 10};
|
||||
static const unsigned char t8l[] = {2, 3, 6, 8, 8, 9, 3, 2, 4, 8, 8, 8, 6, 4, 6, 8, 8, 9, 8, 8, 8, 9, 9, 10, 8, 7, 8, 9, 10, 10, 9, 8, 9, 9, 11, 11};
|
||||
static const unsigned char t9l[] = {3, 3, 5, 6, 8, 9, 3, 3, 4, 5, 6, 8, 4, 4, 5, 6, 7, 8, 6, 5, 6, 7, 7, 8, 7, 6, 7, 7, 8, 9, 8, 7, 8, 8, 9, 9};
|
||||
static const unsigned char t10l[] = {1, 3, 6, 8, 9, 9, 9, 10, 3, 4, 6, 7, 8, 9, 8, 8, 6, 6, 7, 8, 9, 10, 9, 9, 7, 7, 8, 9, 10, 10, 9, 10, 8, 8, 9, 10, 10, 10, 10, 10, 9, 9, 10, 10, 11, 11, 10, 11, 8, 8, 9, 10, 10, 10, 11, 11, 9, 8, 9, 10, 10, 11, 11, 11};
|
||||
static const unsigned char t11l[] = {2, 3, 5, 7, 8, 9, 8, 9, 3, 3, 4, 6, 8, 8, 7, 8, 5, 5, 6, 7, 8, 9, 8, 8, 7, 6, 7, 9, 8, 10, 8, 9, 8, 8, 8, 9, 9, 10, 9, 10, 8, 8, 9, 10, 10, 11, 10, 11, 8, 7, 7, 8, 9, 10, 10, 10, 8, 7, 8, 9, 10, 10, 10, 10};
|
||||
static const unsigned char t12l[] = {4, 3, 5, 7, 8, 9, 9, 9, 3, 3, 4, 5, 7, 7, 8, 8, 5, 4, 5, 6, 7, 8, 7, 8, 6, 5, 6, 6, 7, 8, 8, 8, 7, 6, 7, 7, 8, 8, 8, 9, 8, 7, 8, 8, 8, 9, 8, 9, 8, 7, 7, 8, 8, 9, 9, 10, 9, 8, 8, 9, 9, 9, 9, 10};
|
||||
static const unsigned char t13l[] = {1, 4, 6, 7, 8, 9, 9, 10, 9, 10, 11, 11, 12, 12, 13, 13, 3, 4, 6, 7, 8, 8, 9, 9, 9, 9, 10, 10, 11, 12, 12, 12, 6, 6, 7, 8, 9, 9, 10, 10, 9, 10, 10, 11, 11, 12, 13, 13, 7, 7, 8, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 13, 13,
|
||||
8, 7, 9, 9, 10, 10, 11, 11, 10, 11, 11, 12, 12, 13, 13, 14, 9, 8, 9, 10, 10, 10, 11, 11, 11, 11, 12, 11, 13, 13, 14, 14, 9, 9, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 13, 13, 14, 14, 10, 9, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 16, 16, 9, 8, 9, 10,
|
||||
10, 11, 11, 12, 12, 12, 12, 13, 13, 14, 15, 15, 10, 9, 10, 10, 11, 11, 11, 13, 12, 13, 13, 14, 14, 14, 16, 15, 10, 10, 10, 11, 11, 12, 12, 13, 12, 13, 14, 13, 14, 15, 16, 17, 11, 10, 10, 11, 12, 12, 12, 12, 13, 13, 13, 14, 15, 15, 15, 16, 11, 11, 11, 12, 12,
|
||||
13, 12, 13, 14, 14, 15, 15, 15, 16, 16, 16, 12, 11, 12, 13, 13, 13, 14, 14, 14, 14, 14, 15, 16, 15, 16, 16, 13, 12, 12, 13, 13, 13, 15, 14, 14, 17, 15, 15, 15, 17, 16, 16, 12, 12, 13, 14, 14, 14, 15, 14, 15, 15, 16, 16, 19, 18, 19, 16};
|
||||
static const unsigned char t15l[] = {3, 4, 5, 7, 7, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 13, 4, 3, 5, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 5, 5, 5, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 11, 11, 11, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 7, 6, 7,
|
||||
7, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 8, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 11, 12, 9, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 9, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 12, 9, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11,
|
||||
12, 12, 12, 9, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 10, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 12, 13, 12, 10, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 11, 10, 9, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 13, 13,
|
||||
11, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 12, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 12, 13, 12, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13};
|
||||
static const unsigned char t16l[] = {1, 4, 6, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 9, 3, 4, 6, 7, 8, 9, 9, 9, 10, 10, 10, 11, 12, 11, 12, 8, 6, 6, 7, 8, 9, 9, 10, 10, 11, 10, 11, 11, 11, 12, 12, 9, 8, 7, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13,
|
||||
10, 9, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 9, 9, 8, 9, 9, 10, 11, 11, 12, 11, 12, 12, 13, 13, 13, 14, 10, 10, 9, 9, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 14, 10, 10, 9, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 13, 15, 15, 10, 10, 10,
|
||||
10, 11, 11, 11, 12, 12, 13, 13, 13, 13, 14, 14, 14, 10, 11, 10, 10, 11, 11, 12, 12, 13, 13, 13, 13, 14, 13, 14, 13, 11, 11, 11, 10, 11, 12, 12, 12, 12, 13, 14, 14, 14, 15, 15, 14, 10, 12, 11, 11, 11, 12, 12, 13, 14, 14, 14, 14, 14, 14, 13, 14, 11, 12, 12,
|
||||
12, 12, 12, 13, 13, 13, 13, 15, 14, 14, 14, 14, 16, 11, 14, 12, 12, 12, 13, 13, 14, 14, 14, 16, 15, 15, 15, 17, 15, 11, 13, 13, 11, 12, 14, 14, 13, 14, 14, 15, 16, 15, 17, 15, 14, 11, 9, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 8};
|
||||
static const unsigned char t24l[] = {4, 4, 6, 7, 8, 9, 9, 10, 10, 11, 11, 11, 11, 11, 12, 9, 4, 4, 5, 6, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10, 8, 6, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 7, 7, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 7, 8, 7, 7, 8,
|
||||
8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 7, 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 7, 9, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 7, 10, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 8, 10, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11,
|
||||
8, 10, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 8, 11, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 8, 11, 10, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 8, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 8, 11, 10, 10,
|
||||
10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 8, 12, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 4};
|
||||
static const unsigned char t32l[] = {1, 4, 4, 5, 4, 6, 5, 6, 4, 5, 5, 6, 5, 6, 6, 6};
|
||||
static const unsigned char t33l[] = {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4};
|
||||
|
||||
#define NOREF -1
|
||||
const struct huffcodetab shine_huffman_table[HTN] =
|
||||
{
|
||||
{ 0, 0, 0, 0,NULL,NULL},
|
||||
{ 2, 2, 0, 0,t1HB, t1l},
|
||||
{ 3, 3, 0, 0,t2HB, t2l},
|
||||
{ 3, 3, 0, 0,t3HB, t3l},
|
||||
{ 0, 0, 0, 0,NULL,NULL},/* Apparently not used*/
|
||||
{ 4, 4, 0, 0,t5HB, t5l},
|
||||
{ 4, 4, 0, 0,t6HB, t6l},
|
||||
{ 6, 6, 0, 0,t7HB, t7l},
|
||||
{ 6, 6, 0, 0,t8HB, t8l},
|
||||
{ 6, 6, 0, 0,t9HB, t9l},
|
||||
{ 8, 8, 0, 0,t10HB, t10l},
|
||||
{ 8, 8, 0, 0,t11HB, t11l},
|
||||
{ 8, 8, 0, 0,t12HB, t12l},
|
||||
{16,16, 0, 0,t13HB, t13l},
|
||||
{ 0, 0, 0, 0,NULL,NULL},/* Apparently not used*/
|
||||
{16,16, 0, 0,t15HB, t15l},
|
||||
{16,16, 1, 1,t16HB, t16l},
|
||||
{16,16, 2, 3,t16HB, t16l},
|
||||
{16,16, 3, 7,t16HB, t16l},
|
||||
{16,16, 4, 15,t16HB, t16l},
|
||||
{16,16, 6, 63,t16HB, t16l},
|
||||
{16,16, 8, 255,t16HB, t16l},
|
||||
{16,16,10,1023,t16HB, t16l},
|
||||
{16,16,13,8191,t16HB, t16l},
|
||||
{16,16, 4, 15,t24HB, t24l},
|
||||
{16,16, 5, 31,t24HB, t24l},
|
||||
{16,16, 6, 63,t24HB, t24l},
|
||||
{16,16, 7, 127,t24HB, t24l},
|
||||
{16,16, 8, 255,t24HB, t24l},
|
||||
{16,16, 9, 511,t24HB, t24l},
|
||||
{16,16,11,2047,t24HB, t24l},
|
||||
{16,16,13,8191,t24HB, t24l},
|
||||
{ 1,16, 0, 0,t32HB, t32l},
|
||||
{ 1,16, 0, 0,t33HB, t33l},
|
||||
};
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#define HUFFBITS uint16_t
|
||||
#define HTN 34
|
||||
#define MXOFF 250
|
||||
|
||||
struct huffcodetab {
|
||||
unsigned int xlen; /*max. x-index+ */
|
||||
unsigned int ylen; /*max. y-index+ */
|
||||
unsigned int linbits; /*number of linbits */
|
||||
unsigned int linmax; /*max number to be stored in linbits */
|
||||
const HUFFBITS *table; /*pointer to array[xlen][ylen] */
|
||||
const unsigned char *hlen; /*pointer to array[xlen][ylen] */
|
||||
};
|
||||
|
||||
extern const struct huffcodetab shine_huffman_table[HTN];/* global memory block */
|
||||
/* array of all huffcodtable headers */
|
||||
/* 0..31 Huffman code table 0..31 */
|
||||
/* 32,33 count1-tables */
|
||||
|
||||
|
|
@ -0,0 +1,323 @@
|
|||
/* l3bitstrea.c */
|
||||
|
||||
#include "types.h"
|
||||
#include "l3mdct.h"
|
||||
#include "l3loop.h"
|
||||
#include "layer3.h"
|
||||
#include "huffman.h"
|
||||
#include "bitstream.h"
|
||||
#include "tables.h"
|
||||
#include "l3bitstream.h" /* the public interface */
|
||||
|
||||
static void shine_HuffmanCode(bitstream_t *bs, int table_select, int x, int y);
|
||||
static void shine_huffman_coder_count1(bitstream_t *bs, const struct huffcodetab *h, int v, int w, int x, int y);
|
||||
|
||||
static void encodeSideInfo( shine_global_config *config );
|
||||
static void encodeMainData( shine_global_config *config );
|
||||
static void Huffmancodebits( shine_global_config *config, int *ix, gr_info *gi);
|
||||
|
||||
/*
|
||||
shine_format_bitstream()
|
||||
|
||||
This is called after a frame of audio has been quantized and coded.
|
||||
It will write the encoded audio to the bitstream. Note that
|
||||
from a layer3 encoder's perspective the bit stream is primarily
|
||||
a series of main_data() blocks, with header and side information
|
||||
inserted at the proper locations to maintain framing. (See Figure A.7
|
||||
in the IS).
|
||||
*/
|
||||
|
||||
void shine_format_bitstream(shine_global_config *config) {
|
||||
int gr, ch, i;
|
||||
|
||||
for ( ch = 0; ch < config->wave.channels; ch++ )
|
||||
for ( gr = 0; gr < config->mpeg.granules_per_frame; gr++ )
|
||||
{
|
||||
int *pi = &config->l3_enc[ch][gr][0];
|
||||
int32_t *pr = &config->mdct_freq[ch][gr][0];
|
||||
for ( i = 0; i < GRANULE_SIZE; i++ )
|
||||
{
|
||||
if ( (pr[i] < 0) && (pi[i] > 0) )
|
||||
pi[i] *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
encodeSideInfo( config );
|
||||
encodeMainData( config );
|
||||
}
|
||||
|
||||
static void encodeMainData(shine_global_config *config) {
|
||||
int gr, ch, sfb;
|
||||
shine_side_info_t si = config->side_info;
|
||||
|
||||
for ( gr = 0; gr < config->mpeg.granules_per_frame; gr++ )
|
||||
{
|
||||
for ( ch = 0; ch < config->wave.channels; ch++ )
|
||||
{
|
||||
gr_info *gi = &(si.gr[gr].ch[ch].tt);
|
||||
unsigned slen1 = shine_slen1_tab[ gi->scalefac_compress ];
|
||||
unsigned slen2 = shine_slen2_tab[ gi->scalefac_compress ];
|
||||
int *ix = &config->l3_enc[ch][gr][0];
|
||||
|
||||
if ( gr == 0 || si.scfsi[ch][0] == 0 )
|
||||
for ( sfb = 0; sfb < 6; sfb++ )
|
||||
shine_putbits( &config->bs, config->scalefactor.l[gr][ch][sfb], slen1 );
|
||||
if ( gr == 0 || si.scfsi[ch][1] == 0 )
|
||||
for ( sfb = 6; sfb < 11; sfb++ )
|
||||
shine_putbits( &config->bs, config->scalefactor.l[gr][ch][sfb], slen1 );
|
||||
if ( gr == 0 || si.scfsi[ch][2] == 0 )
|
||||
for ( sfb = 11; sfb < 16; sfb++ )
|
||||
shine_putbits( &config->bs, config->scalefactor.l[gr][ch][sfb], slen2 );
|
||||
if ( gr == 0 || si.scfsi[ch][3] == 0 )
|
||||
for ( sfb = 16; sfb < 21; sfb++ )
|
||||
shine_putbits( &config->bs, config->scalefactor.l[gr][ch][sfb], slen2 );
|
||||
|
||||
Huffmancodebits( config, ix, gi );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void encodeSideInfo( shine_global_config *config ) {
|
||||
int gr, ch, scfsi_band, region;
|
||||
shine_side_info_t si = config->side_info;
|
||||
|
||||
shine_putbits( &config->bs, 0x7ff, 11 );
|
||||
shine_putbits( &config->bs, config->mpeg.version, 2 );
|
||||
shine_putbits( &config->bs, config->mpeg.layer, 2 );
|
||||
shine_putbits( &config->bs, !config->mpeg.crc, 1 );
|
||||
shine_putbits( &config->bs, config->mpeg.bitrate_index, 4 );
|
||||
shine_putbits( &config->bs, config->mpeg.samplerate_index % 3, 2 );
|
||||
shine_putbits( &config->bs, config->mpeg.padding, 1 );
|
||||
shine_putbits( &config->bs, config->mpeg.ext, 1 );
|
||||
shine_putbits( &config->bs, config->mpeg.mode, 2 );
|
||||
shine_putbits( &config->bs, config->mpeg.mode_ext, 2 );
|
||||
shine_putbits( &config->bs, config->mpeg.copyright, 1 );
|
||||
shine_putbits( &config->bs, config->mpeg.original, 1 );
|
||||
shine_putbits( &config->bs, config->mpeg.emph, 2 );
|
||||
|
||||
if ( config->mpeg.version == MPEG_I ) {
|
||||
shine_putbits( &config->bs, 0, 9 );
|
||||
if ( config->wave.channels == 2 )
|
||||
shine_putbits( &config->bs, si.private_bits, 3 );
|
||||
else
|
||||
shine_putbits( &config->bs, si.private_bits, 5 );
|
||||
} else {
|
||||
shine_putbits( &config->bs, 0, 8 );
|
||||
if ( config->wave.channels == 2 )
|
||||
shine_putbits( &config->bs, si.private_bits, 2 );
|
||||
else
|
||||
shine_putbits( &config->bs, si.private_bits, 1 );
|
||||
}
|
||||
|
||||
if ( config->mpeg.version == MPEG_I )
|
||||
for ( ch = 0; ch < config->wave.channels; ch++ ) {
|
||||
for ( scfsi_band = 0; scfsi_band < 4; scfsi_band++ )
|
||||
shine_putbits( &config->bs, si.scfsi[ch][scfsi_band], 1 );
|
||||
}
|
||||
|
||||
for ( gr = 0; gr < config->mpeg.granules_per_frame; gr++ )
|
||||
for ( ch = 0; ch < config->wave.channels ; ch++ )
|
||||
{
|
||||
gr_info *gi = &(si.gr[gr].ch[ch].tt);
|
||||
|
||||
shine_putbits( &config->bs, gi->part2_3_length, 12 );
|
||||
shine_putbits( &config->bs, gi->big_values, 9 );
|
||||
shine_putbits( &config->bs, gi->global_gain, 8 );
|
||||
if ( config->mpeg.version == MPEG_I )
|
||||
shine_putbits( &config->bs, gi->scalefac_compress, 4 );
|
||||
else
|
||||
shine_putbits( &config->bs, gi->scalefac_compress, 9 );
|
||||
shine_putbits( &config->bs, 0, 1 );
|
||||
|
||||
for ( region = 0; region < 3; region++ )
|
||||
shine_putbits( &config->bs, gi->table_select[region], 5 );
|
||||
|
||||
shine_putbits( &config->bs, gi->region0_count, 4 );
|
||||
shine_putbits( &config->bs, gi->region1_count, 3 );
|
||||
|
||||
if ( config->mpeg.version == MPEG_I )
|
||||
shine_putbits( &config->bs, gi->preflag, 1 );
|
||||
shine_putbits( &config->bs, gi->scalefac_scale, 1 );
|
||||
shine_putbits( &config->bs, gi->count1table_select, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Note the discussion of huffmancodebits() on pages 28 and 29 of the IS, as
|
||||
well as the definitions of the side information on pages 26 and 27. */
|
||||
static void Huffmancodebits( shine_global_config *config, int *ix, gr_info *gi ) {
|
||||
const int *scalefac = &shine_scale_fact_band_index[config->mpeg.samplerate_index][0];
|
||||
unsigned scalefac_index;
|
||||
int region1Start, region2Start;
|
||||
int i, bigvalues, count1End;
|
||||
int v, w, x, y;
|
||||
const struct huffcodetab *h;
|
||||
int bits;
|
||||
|
||||
bits = shine_get_bits_count(&config->bs);
|
||||
|
||||
/* 1: Write the bigvalues */
|
||||
bigvalues = gi->big_values << 1;
|
||||
|
||||
scalefac_index = gi->region0_count + 1;
|
||||
region1Start = scalefac[ scalefac_index ];
|
||||
scalefac_index += gi->region1_count + 1;
|
||||
region2Start = scalefac[ scalefac_index ];
|
||||
|
||||
for ( i = 0; i < bigvalues; i += 2 )
|
||||
{
|
||||
/* get table pointer */
|
||||
int idx = (i >= region1Start) + (i >= region2Start);
|
||||
unsigned tableindex = gi->table_select[idx];
|
||||
/* get huffman code */
|
||||
if ( tableindex )
|
||||
{
|
||||
x = ix[i];
|
||||
y = ix[i + 1];
|
||||
shine_HuffmanCode( &config->bs, tableindex, x, y );
|
||||
}
|
||||
}
|
||||
|
||||
/* 2: Write count1 area */
|
||||
h = &shine_huffman_table[gi->count1table_select + 32];
|
||||
count1End = bigvalues + (gi->count1 <<2);
|
||||
for ( i = bigvalues; i < count1End; i += 4 )
|
||||
{
|
||||
v = ix[i];
|
||||
w = ix[i+1];
|
||||
x = ix[i+2];
|
||||
y = ix[i+3];
|
||||
shine_huffman_coder_count1( &config->bs, h, v, w, x, y );
|
||||
}
|
||||
|
||||
bits = shine_get_bits_count(&config->bs) - bits;
|
||||
bits = gi->part2_3_length - gi->part2_length - bits;
|
||||
if (bits)
|
||||
{
|
||||
int stuffingWords = bits / 32;
|
||||
int remainingBits = bits % 32;
|
||||
|
||||
/* Due to the nature of the Huffman code tables, we will pad with ones */
|
||||
while ( stuffingWords-- )
|
||||
shine_putbits( &config->bs, ~0, 32 );
|
||||
if ( remainingBits )
|
||||
shine_putbits( &config->bs, (1UL << remainingBits) - 1, remainingBits );
|
||||
}
|
||||
}
|
||||
|
||||
static inline int shine_abs_and_sign( int *x ) {
|
||||
if ( *x > 0 ) return 0;
|
||||
*x *= -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void shine_huffman_coder_count1( bitstream_t *bs, const struct huffcodetab *h, int v, int w, int x, int y ) {
|
||||
unsigned int signv, signw, signx, signy;
|
||||
unsigned int code = 0;
|
||||
int p, cbits = 0;
|
||||
|
||||
signv = shine_abs_and_sign( &v );
|
||||
signw = shine_abs_and_sign( &w );
|
||||
signx = shine_abs_and_sign( &x );
|
||||
signy = shine_abs_and_sign( &y );
|
||||
|
||||
p = v + (w << 1) + (x << 2) + (y << 3);
|
||||
shine_putbits( bs, h->table[p], h->hlen[p] );
|
||||
|
||||
if ( v ) {
|
||||
code = signv;
|
||||
cbits = 1;
|
||||
}
|
||||
if ( w ) {
|
||||
code = (code << 1) | signw;
|
||||
cbits++;
|
||||
}
|
||||
if ( x ) {
|
||||
code = (code << 1) | signx;
|
||||
cbits++;
|
||||
}
|
||||
if ( y ) {
|
||||
code = (code << 1) | signy;
|
||||
cbits++;
|
||||
}
|
||||
shine_putbits( bs, code, cbits );
|
||||
}
|
||||
|
||||
/* Implements the pseudocode of page 98 of the IS */
|
||||
static void shine_HuffmanCode(bitstream_t *bs, int table_select, int x, int y) {
|
||||
int cbits = 0, xbits = 0;
|
||||
unsigned int code = 0, ext = 0;
|
||||
unsigned signx, signy, ylen, idx;
|
||||
const struct huffcodetab *h;
|
||||
|
||||
signx = shine_abs_and_sign( &x );
|
||||
signy = shine_abs_and_sign( &y );
|
||||
|
||||
h = &(shine_huffman_table[table_select]);
|
||||
ylen = h->ylen;
|
||||
|
||||
if ( table_select > 15 )
|
||||
{ /* ESC-table is used */
|
||||
unsigned linbitsx = 0, linbitsy = 0, linbits = h->linbits;
|
||||
|
||||
if ( x > 14 )
|
||||
{
|
||||
linbitsx = x - 15;
|
||||
x = 15;
|
||||
}
|
||||
if ( y > 14 )
|
||||
{
|
||||
linbitsy = y - 15;
|
||||
y = 15;
|
||||
}
|
||||
|
||||
idx = (x * ylen) + y;
|
||||
code = h->table[idx];
|
||||
cbits = h->hlen [idx];
|
||||
if ( x > 14 )
|
||||
{
|
||||
ext |= linbitsx;
|
||||
xbits += linbits;
|
||||
}
|
||||
if ( x != 0 )
|
||||
{
|
||||
ext <<= 1;
|
||||
ext |= signx;
|
||||
xbits += 1;
|
||||
}
|
||||
if ( y > 14 )
|
||||
{
|
||||
ext <<= linbits;
|
||||
ext |= linbitsy;
|
||||
xbits += linbits;
|
||||
}
|
||||
if ( y != 0 )
|
||||
{
|
||||
ext <<= 1;
|
||||
ext |= signy;
|
||||
xbits += 1;
|
||||
}
|
||||
|
||||
shine_putbits( bs, code, cbits);
|
||||
shine_putbits( bs, ext, xbits);
|
||||
}
|
||||
else
|
||||
{ /* No ESC-words */
|
||||
idx = (x * ylen) + y;
|
||||
code = h->table[idx];
|
||||
cbits = h->hlen[idx];
|
||||
if ( x != 0 )
|
||||
{
|
||||
code <<= 1;
|
||||
code |= signx;
|
||||
cbits += 1;
|
||||
}
|
||||
if ( y != 0 )
|
||||
{
|
||||
code <<= 1;
|
||||
code |= signy;
|
||||
cbits += 1;
|
||||
}
|
||||
|
||||
shine_putbits( bs, code, cbits);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef shine_BITSTREAM_H
|
||||
#define shine_BITSTREAM_H
|
||||
|
||||
void shine_format_bitstream(shine_global_config *config);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,857 @@
|
|||
/* l3loop->c */
|
||||
|
||||
#include "types.h"
|
||||
#include "tables.h"
|
||||
#include "l3loop.h"
|
||||
#include "layer3.h"
|
||||
#include "huffman.h"
|
||||
#include "bitstream.h"
|
||||
#include "l3bitstream.h"
|
||||
#include "reservoir.h"
|
||||
|
||||
#define e 2.71828182845
|
||||
#define CBLIMIT 21
|
||||
#define SFB_LMAX 22
|
||||
#define en_tot_krit 10
|
||||
#define en_dif_krit 100
|
||||
#define en_scfsi_band_krit 10
|
||||
#define xm_scfsi_band_krit 10
|
||||
|
||||
static void calc_scfsi(shine_psy_xmin_t *l3_xmin, int ch, int gr, shine_global_config *config);
|
||||
static int part2_length(int gr, int ch, shine_global_config *config);
|
||||
static int bin_search_StepSize(int desired_rate, int ix[GRANULE_SIZE], gr_info * cod_info, shine_global_config *config);
|
||||
static int count_bit(int ix[GRANULE_SIZE], unsigned int start, unsigned int end, unsigned int table );
|
||||
static int bigv_bitcount(int ix[GRANULE_SIZE], gr_info *gi);
|
||||
static int new_choose_table( int ix[GRANULE_SIZE], unsigned int begin, unsigned int end );
|
||||
static void bigv_tab_select( int ix[GRANULE_SIZE], gr_info *cod_info );
|
||||
static void subdivide(gr_info *cod_info, shine_global_config *config );
|
||||
static int count1_bitcount( int ix[ GRANULE_SIZE ], gr_info *cod_info );
|
||||
static void calc_runlen( int ix[GRANULE_SIZE], gr_info *cod_info );
|
||||
static void calc_xmin( gr_info *cod_info, shine_psy_xmin_t *l3_xmin, int gr, int ch );
|
||||
static int quantize(int ix[GRANULE_SIZE], int stepsize, shine_global_config *config);
|
||||
|
||||
|
||||
int32_t sqrt_int(int32_t r) {
|
||||
float x;
|
||||
float rr = r;
|
||||
float y = rr*0.5;
|
||||
*(unsigned int*)&x = (0xbe6f0000 - *(uint32_t*)&rr) >> 1;
|
||||
|
||||
x = (1.5f*x) - (x*x)*(x*y);
|
||||
if(r>101123) x = (1.5f*x) - (x*x)*(x*y);
|
||||
|
||||
int32_t is = (int32_t)(x*rr + 0.5f);
|
||||
return is + ((r - is*is)>>31);
|
||||
}
|
||||
|
||||
#define SQRT_MAGIC_F 0x5f3759df
|
||||
|
||||
float f_sqrt(const float x) {
|
||||
const float xhalf = 0.5f*x;
|
||||
//float step;
|
||||
union // get bits for floating value
|
||||
{
|
||||
float x;
|
||||
int i;
|
||||
} u;
|
||||
u.x = x;
|
||||
u.i = SQRT_MAGIC_F - (u.i >> 1); // gives initial guess y0
|
||||
|
||||
return x*u.x*(1.5f - xhalf*u.x*u.x);// Newton step, repeating increases accuracy
|
||||
}
|
||||
/*
|
||||
* shine_inner_loop:
|
||||
* ----------
|
||||
* The code selects the best quantizerStepSize for a particular set
|
||||
* of scalefacs.
|
||||
*/
|
||||
int shine_inner_loop(int ix[GRANULE_SIZE],
|
||||
int max_bits, gr_info *cod_info, int gr, int ch,
|
||||
shine_global_config *config ) {
|
||||
int bits, c1bits, bvbits;
|
||||
|
||||
if(max_bits<0)
|
||||
cod_info->quantizerStepSize--;
|
||||
do
|
||||
{
|
||||
while(quantize(ix,++cod_info->quantizerStepSize,config) > 8192); /* within table range? */
|
||||
|
||||
calc_runlen(ix,cod_info); /* rzero,count1,big_values*/
|
||||
bits = c1bits = count1_bitcount(ix,cod_info); /* count1_table selection*/
|
||||
subdivide(cod_info, config); /* bigvalues sfb division */
|
||||
bigv_tab_select(ix,cod_info); /* codebook selection*/
|
||||
bits += bvbits = bigv_bitcount( ix, cod_info ); /* bit count */
|
||||
}
|
||||
while(bits>max_bits);
|
||||
return bits;
|
||||
}
|
||||
|
||||
/*
|
||||
* shine_outer_loop:
|
||||
* -----------
|
||||
* Function: The outer iteration loop controls the masking conditions
|
||||
* of all scalefactorbands. It computes the best scalefac and
|
||||
* global gain. This module calls the inner iteration loop.
|
||||
*/
|
||||
|
||||
int shine_outer_loop( int max_bits,
|
||||
shine_psy_xmin_t *l3_xmin, /* the allowed distortion of the scalefactor */
|
||||
int ix[GRANULE_SIZE], /* vector of quantized values ix(0..575) */
|
||||
int gr, int ch, shine_global_config *config) {
|
||||
int bits, huff_bits;
|
||||
shine_side_info_t *side_info = &config->side_info;
|
||||
gr_info *cod_info = &side_info->gr[gr].ch[ch].tt;
|
||||
|
||||
cod_info->quantizerStepSize = bin_search_StepSize(max_bits,ix,cod_info, config);
|
||||
|
||||
cod_info->part2_length = part2_length(gr,ch,config);
|
||||
huff_bits = max_bits - cod_info->part2_length;
|
||||
|
||||
bits = shine_inner_loop(ix, huff_bits, cod_info, gr, ch, config );
|
||||
cod_info->part2_3_length = cod_info->part2_length + bits;
|
||||
|
||||
return cod_info->part2_3_length;
|
||||
}
|
||||
|
||||
/*
|
||||
* shine_iteration_loop:
|
||||
* ------------------
|
||||
*/
|
||||
void shine_iteration_loop(shine_global_config *config) {
|
||||
shine_psy_xmin_t l3_xmin;
|
||||
gr_info *cod_info;
|
||||
int max_bits;
|
||||
int ch, gr, i;
|
||||
int *ix;
|
||||
|
||||
|
||||
for(ch=config->wave.channels; ch--; )
|
||||
{
|
||||
for(gr=0; gr<config->mpeg.granules_per_frame; gr++)
|
||||
{
|
||||
/* setup pointers */
|
||||
ix = config->l3_enc[ch][gr];
|
||||
config->l3loop->xr = config->mdct_freq[ch][gr];
|
||||
|
||||
/* Precalculate the square, abs, and maximum,
|
||||
* for use later on.
|
||||
*/
|
||||
for (i=GRANULE_SIZE, config->l3loop->xrmax=0; i--;)
|
||||
{
|
||||
config->l3loop->xrsq[i] = mulsr(config->l3loop->xr[i],config->l3loop->xr[i]);
|
||||
config->l3loop->xrabs[i] = abs(config->l3loop->xr[i]);
|
||||
if(config->l3loop->xrabs[i]>config->l3loop->xrmax)
|
||||
config->l3loop->xrmax=config->l3loop->xrabs[i];
|
||||
}
|
||||
|
||||
cod_info = (gr_info *) &(config->side_info.gr[gr].ch[ch]);
|
||||
cod_info->sfb_lmax = SFB_LMAX - 1; /* gr_deco */
|
||||
|
||||
calc_xmin(cod_info, &l3_xmin, gr, ch );
|
||||
|
||||
if ( config->mpeg.version == MPEG_I )
|
||||
calc_scfsi(&l3_xmin,ch,gr,config);
|
||||
|
||||
/* calculation of number of available bit( per granule ) */
|
||||
max_bits = shine_max_reservoir_bits(&config->pe[ch][gr],config);
|
||||
|
||||
/* reset of iteration variables */
|
||||
memset(config->scalefactor.l[gr][ch],0,sizeof(config->scalefactor.l[gr][ch]));
|
||||
memset(config->scalefactor.s[gr][ch],0,sizeof(config->scalefactor.s[gr][ch]));
|
||||
|
||||
for ( i=4; i--; )
|
||||
cod_info->slen[i] = 0;
|
||||
|
||||
cod_info->part2_3_length = 0;
|
||||
cod_info->big_values = 0;
|
||||
cod_info->count1 = 0;
|
||||
cod_info->scalefac_compress = 0;
|
||||
cod_info->table_select[0] = 0;
|
||||
cod_info->table_select[1] = 0;
|
||||
cod_info->table_select[2] = 0;
|
||||
cod_info->region0_count = 0;
|
||||
cod_info->region1_count = 0;
|
||||
cod_info->part2_length = 0;
|
||||
cod_info->preflag = 0;
|
||||
cod_info->scalefac_scale = 0;
|
||||
cod_info->count1table_select= 0;
|
||||
|
||||
/* all spectral values zero ? */
|
||||
if(config->l3loop->xrmax)
|
||||
cod_info->part2_3_length = shine_outer_loop(max_bits,&l3_xmin,ix,
|
||||
gr,ch,config);
|
||||
|
||||
shine_ResvAdjust(cod_info, config );
|
||||
cod_info->global_gain = cod_info->quantizerStepSize+210;
|
||||
|
||||
} /* for gr */
|
||||
} /* for ch */
|
||||
|
||||
shine_ResvFrameEnd(config);
|
||||
}
|
||||
|
||||
/*
|
||||
* calc_scfsi:
|
||||
* -----------
|
||||
* calculation of the scalefactor select information ( scfsi ).
|
||||
*/
|
||||
void calc_scfsi( shine_psy_xmin_t *l3_xmin, int ch, int gr,
|
||||
shine_global_config *config ) {
|
||||
shine_side_info_t *l3_side = &config->side_info;
|
||||
/* This is the scfsi_band table from 2.4.2.7 of the IS */
|
||||
static const int scfsi_band_long[5] = { 0, 6, 11, 16, 21 };
|
||||
|
||||
int scfsi_band;
|
||||
unsigned scfsi_set;
|
||||
|
||||
int sfb, start, end, i;
|
||||
int condition = 0;
|
||||
int temp;
|
||||
|
||||
const int *scalefac_band_long = &shine_scale_fact_band_index[config->mpeg.samplerate_index][0];
|
||||
|
||||
// note. it goes quite a bit faster if you uncomment the next bit and exit
|
||||
// early from scfsi, but you then loose the advantage of common scale factors.
|
||||
|
||||
/*for(scfsi_band=0;scfsi_band<4;scfsi_band++)
|
||||
l3_side->scfsi[ch][scfsi_band] = 0;
|
||||
return;*/
|
||||
|
||||
|
||||
|
||||
config->l3loop->xrmaxl[gr] = config->l3loop->xrmax;
|
||||
scfsi_set = 0;
|
||||
|
||||
/* the total energy of the granule */
|
||||
for ( temp = 0, i =GRANULE_SIZE; i--; )
|
||||
temp += config->l3loop->xrsq[i]>>10; /* a bit of scaling to avoid overflow, (not very good) */
|
||||
if ( temp )
|
||||
config->l3loop->en_tot[gr] = log((float)temp * 4.768371584e-7) / LN2; /* 1024 / 0x7fffffff */
|
||||
else
|
||||
config->l3loop->en_tot[gr] = 0;
|
||||
|
||||
/* the energy of each scalefactor band, en */
|
||||
/* the allowed distortion of each scalefactor band, xm */
|
||||
|
||||
for(sfb=21; sfb--; )
|
||||
{
|
||||
start = scalefac_band_long[ sfb ];
|
||||
end = scalefac_band_long[ sfb+1 ];
|
||||
|
||||
for ( temp = 0, i = start; i < end; i++ )
|
||||
temp += config->l3loop->xrsq[i]>>10;
|
||||
if ( temp )
|
||||
config->l3loop->en[gr][sfb] = log((float)temp * 4.768371584e-7) / LN2; /* 1024 / 0x7fffffff */
|
||||
else
|
||||
config->l3loop->en[gr][sfb] = 0;
|
||||
|
||||
if ( l3_xmin->l[gr][ch][sfb])
|
||||
config->l3loop->xm[gr][sfb] = log( l3_xmin->l[gr][ch][sfb] ) / LN2;
|
||||
else
|
||||
config->l3loop->xm[gr][sfb] = 0;
|
||||
}
|
||||
|
||||
if(gr==1)
|
||||
{
|
||||
int gr2, tp;
|
||||
|
||||
for(gr2=2; gr2--; )
|
||||
{
|
||||
/* The spectral values are not all zero */
|
||||
if(config->l3loop->xrmaxl[gr2])
|
||||
condition++;
|
||||
|
||||
condition++;
|
||||
}
|
||||
if(abs(config->l3loop->en_tot[0]-config->l3loop->en_tot[1]) < en_tot_krit)
|
||||
condition++;
|
||||
for(tp=0,sfb=21; sfb--; )
|
||||
tp += abs(config->l3loop->en[0][sfb]-config->l3loop->en[1][sfb]);
|
||||
if (tp < en_dif_krit)
|
||||
condition++;
|
||||
|
||||
if(condition==6)
|
||||
{
|
||||
for(scfsi_band=0;scfsi_band<4;scfsi_band++)
|
||||
{
|
||||
int sum0 = 0, sum1 = 0;
|
||||
l3_side->scfsi[ch][scfsi_band] = 0;
|
||||
start = scfsi_band_long[scfsi_band];
|
||||
end = scfsi_band_long[scfsi_band+1];
|
||||
for ( sfb = start; sfb < end; sfb++ )
|
||||
{
|
||||
sum0 += abs( config->l3loop->en[0][sfb] - config->l3loop->en[1][sfb] );
|
||||
sum1 += abs( config->l3loop->xm[0][sfb] - config->l3loop->xm[1][sfb] );
|
||||
}
|
||||
|
||||
if(sum0<en_scfsi_band_krit && sum1<xm_scfsi_band_krit)
|
||||
{
|
||||
l3_side->scfsi[ch][scfsi_band] = 1;
|
||||
scfsi_set |= (1 << scfsi_band);
|
||||
}
|
||||
else
|
||||
l3_side->scfsi[ch][scfsi_band] = 0;
|
||||
} /* for scfsi_band */
|
||||
} /* if condition == 6 */
|
||||
else
|
||||
for(scfsi_band=0;scfsi_band<4;scfsi_band++)
|
||||
l3_side->scfsi[ch][scfsi_band] = 0;
|
||||
} /* if gr == 1 */
|
||||
}
|
||||
|
||||
/*
|
||||
* part2_length:
|
||||
* -------------
|
||||
* calculates the number of bits needed to encode the scalefacs in the
|
||||
* main data block.
|
||||
*/
|
||||
int part2_length(int gr, int ch, shine_global_config *config) {
|
||||
int slen1, slen2, bits;
|
||||
gr_info *gi = &config->side_info.gr[gr].ch[ch].tt;
|
||||
|
||||
bits = 0;
|
||||
|
||||
{
|
||||
slen1 = shine_slen1_tab[ gi->scalefac_compress ];
|
||||
slen2 = shine_slen2_tab[ gi->scalefac_compress ];
|
||||
|
||||
if ( !gr || !(config->side_info.scfsi[ch][0]) )
|
||||
bits += (6 * slen1);
|
||||
|
||||
if ( !gr || !(config->side_info.scfsi[ch][1]) )
|
||||
bits += (5 * slen1);
|
||||
|
||||
if ( !gr || !(config->side_info.scfsi[ch][2]) )
|
||||
bits += (5 * slen2);
|
||||
|
||||
if ( !gr || !(config->side_info.scfsi[ch][3]) )
|
||||
bits += (5 * slen2);
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
|
||||
/*
|
||||
* calc_xmin:
|
||||
* ----------
|
||||
* Calculate the allowed distortion for each scalefactor band,
|
||||
* as determined by the psychoacoustic model.
|
||||
* xmin(sb) = ratio(sb) * en(sb) / bw(sb)
|
||||
*/
|
||||
void calc_xmin(gr_info *cod_info,
|
||||
shine_psy_xmin_t *l3_xmin,
|
||||
int gr, int ch ) {
|
||||
int sfb;
|
||||
|
||||
for ( sfb = cod_info->sfb_lmax; sfb--; )
|
||||
{
|
||||
/*note. xmin will always be zero with no psychoacoustic model
|
||||
|
||||
start = scalefac_band_long[ sfb ];
|
||||
end = scalefac_band_long[ sfb+1 ];
|
||||
bw = end - start;
|
||||
|
||||
for ( en = 0, l = start; l < end; l++ )
|
||||
en += config->l3loop->xrsq[l];
|
||||
|
||||
l3_xmin->l[gr][ch][sfb] = ratio->l[gr][ch][sfb] * en / bw;*/
|
||||
|
||||
l3_xmin->l[gr][ch][sfb] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* shine_loop_initialise:
|
||||
* -------------------
|
||||
* Calculates the look up tables used by the iteration loop.
|
||||
*/
|
||||
void shine_loop_initialise(shine_global_config *config) {
|
||||
int i;
|
||||
|
||||
/* quantize: stepsize conversion, fourth root of 2 table.
|
||||
* The table is inverted (negative power) from the equation given
|
||||
* in the spec because it is quicker to do x*y than x/y.
|
||||
* The 0.5 is for rounding.
|
||||
*/
|
||||
for(i=128; i--;)
|
||||
{
|
||||
config->l3loop->steptab[i] = pow(2.0,(double)(127-i)/4);
|
||||
if((config->l3loop->steptab[i]*2)>0x7fffffff) /* MAXINT = 2**31 = 2**(124/4) */
|
||||
config->l3loop->steptabi[i]=0x7fffffff;
|
||||
else
|
||||
/* The table is multiplied by 2 to give an extra bit of accuracy.
|
||||
* In quantize, the long multiply does not shift it's result left one
|
||||
* bit to compensate.
|
||||
*/
|
||||
config->l3loop->steptabi[i] = (int32_t)((config->l3loop->steptab[i]*2) + 0.5);
|
||||
}
|
||||
|
||||
/* quantize: vector conversion, three quarter power table.
|
||||
* The 0.5 is for rounding, the .0946 comes from the spec.
|
||||
*/
|
||||
for(i=10000; i--;)
|
||||
config->l3loop->int2idx[i] = (int)(sqrt(sqrt((double)i)*(double)i) - 0.0946 + 0.5);
|
||||
}
|
||||
|
||||
/*
|
||||
* quantize:
|
||||
* ---------
|
||||
* Function: Quantization of the vector xr ( -> ix).
|
||||
* Returns maximum value of ix.
|
||||
*/
|
||||
int quantize(int ix[GRANULE_SIZE], int stepsize, shine_global_config *config )
|
||||
{
|
||||
int i, max, ln;
|
||||
int32_t scalei;
|
||||
float scale, dbl;
|
||||
|
||||
scalei = config->l3loop->steptabi[stepsize+127]; /* 2**(-stepsize/4) */
|
||||
|
||||
/* a quick check to see if ixmax will be less than 8192 */
|
||||
/* this speeds up the early calls to bin_search_StepSize */
|
||||
if((mulr(config->l3loop->xrmax,scalei)) > 165140) /* 8192**(4/3) */
|
||||
max = 16384; /* no point in continuing, stepsize not big enough */
|
||||
else
|
||||
for(i=0, max=0;i<GRANULE_SIZE;i++)
|
||||
{
|
||||
/* This calculation is very sensitive. The multiply must round it's
|
||||
* result or bad things happen to the quality.
|
||||
*/
|
||||
ln = mulr(abs(config->l3loop->xr[i]),scalei);
|
||||
|
||||
if(ln<10000) /* ln < 10000 catches most values */
|
||||
ix[i] = config->l3loop->int2idx[ln]; /* quick look up method */
|
||||
else
|
||||
{
|
||||
/* outside table range so have to do it using floats */
|
||||
scale = config->l3loop->steptab[stepsize+127]; /* 2**(-stepsize/4) */
|
||||
dbl = ((float)config->l3loop->xrabs[i]) * scale * 4.656612875e-10; /* 0x7fffffff */
|
||||
//ix[i] = sqrt_int((int)(f_sqrt(dbl)*dbl)); /* dbl**(3/4) */
|
||||
ix[i] = (int)sqrt(sqrt(dbl)*dbl); /* dbl**(3/4) */
|
||||
}
|
||||
|
||||
/* calculate ixmax while we're here */
|
||||
/* note. ix cannot be negative */
|
||||
if(max < ix[i])
|
||||
max = ix[i];
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
/*
|
||||
* ix_max:
|
||||
* -------
|
||||
* Function: Calculate the maximum of ix from 0 to 575
|
||||
*/
|
||||
static inline int ix_max( int ix[GRANULE_SIZE], unsigned int begin, unsigned int end ) {
|
||||
register int i;
|
||||
register int max = 0;
|
||||
|
||||
for(i=begin;i<end;i++)
|
||||
if(max < ix[i])
|
||||
max = ix[i];
|
||||
return max;
|
||||
}
|
||||
|
||||
/*
|
||||
* calc_runlen:
|
||||
* ------------
|
||||
* Function: Calculation of rzero, count1, big_values
|
||||
* (Partitions ix into big values, quadruples and zeros).
|
||||
*/
|
||||
void calc_runlen( int ix[GRANULE_SIZE], gr_info *cod_info ) {
|
||||
int i;
|
||||
int rzero = 0;
|
||||
|
||||
for ( i = GRANULE_SIZE; i > 1; i -= 2 )
|
||||
if ( !ix[i-1] && !ix[i-2] )
|
||||
rzero++;
|
||||
else
|
||||
break;
|
||||
|
||||
cod_info->count1 = 0 ;
|
||||
for ( ; i > 3; i -= 4 )
|
||||
if ( ix[i-1] <= 1
|
||||
&& ix[i-2] <= 1
|
||||
&& ix[i-3] <= 1
|
||||
&& ix[i-4] <= 1 )
|
||||
cod_info->count1++;
|
||||
else
|
||||
break;
|
||||
|
||||
cod_info->big_values = i>>1;
|
||||
}
|
||||
|
||||
/*
|
||||
* count1_bitcount:
|
||||
* ----------------
|
||||
* Determines the number of bits to encode the quadruples.
|
||||
*/
|
||||
int count1_bitcount(int ix[GRANULE_SIZE], gr_info *cod_info) {
|
||||
int p, i, k;
|
||||
int v, w, x, y, signbits;
|
||||
int sum0 = 0,
|
||||
sum1 = 0;
|
||||
|
||||
for(i=cod_info->big_values<<1, k=0; k<cod_info->count1; i+=4, k++)
|
||||
{
|
||||
v = ix[i];
|
||||
w = ix[i+1];
|
||||
x = ix[i+2];
|
||||
y = ix[i+3];
|
||||
|
||||
p = v + (w<<1) + (x<<2) + (y<<3);
|
||||
|
||||
signbits = 0;
|
||||
if(v!=0) signbits++;
|
||||
if(w!=0) signbits++;
|
||||
if(x!=0) signbits++;
|
||||
if(y!=0) signbits++;
|
||||
|
||||
sum0 += signbits;
|
||||
sum1 += signbits;
|
||||
|
||||
sum0 += shine_huffman_table[32].hlen[p];
|
||||
sum1 += shine_huffman_table[33].hlen[p];
|
||||
}
|
||||
|
||||
if(sum0<sum1)
|
||||
{
|
||||
cod_info->count1table_select = 0;
|
||||
return sum0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cod_info->count1table_select = 1;
|
||||
return sum1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* subdivide:
|
||||
* ----------
|
||||
* presumable subdivides the bigvalue region which will use separate Huffman tables.
|
||||
*/
|
||||
void subdivide(gr_info *cod_info, shine_global_config *config) {
|
||||
static const struct
|
||||
{
|
||||
unsigned region0_count;
|
||||
unsigned region1_count;
|
||||
} subdv_table[ 23 ] =
|
||||
{
|
||||
{0, 0}, /* 0 bands */
|
||||
{0, 0}, /* 1 bands */
|
||||
{0, 0}, /* 2 bands */
|
||||
{0, 0}, /* 3 bands */
|
||||
{0, 0}, /* 4 bands */
|
||||
{0, 1}, /* 5 bands */
|
||||
{1, 1}, /* 6 bands */
|
||||
{1, 1}, /* 7 bands */
|
||||
{1, 2}, /* 8 bands */
|
||||
{2, 2}, /* 9 bands */
|
||||
{2, 3}, /* 10 bands */
|
||||
{2, 3}, /* 11 bands */
|
||||
{3, 4}, /* 12 bands */
|
||||
{3, 4}, /* 13 bands */
|
||||
{3, 4}, /* 14 bands */
|
||||
{4, 5}, /* 15 bands */
|
||||
{4, 5}, /* 16 bands */
|
||||
{4, 6}, /* 17 bands */
|
||||
{5, 6}, /* 18 bands */
|
||||
{5, 6}, /* 19 bands */
|
||||
{5, 7}, /* 20 bands */
|
||||
{6, 7}, /* 21 bands */
|
||||
{6, 7}, /* 22 bands */
|
||||
};
|
||||
|
||||
if (!cod_info->big_values)
|
||||
{ /* no big_values region */
|
||||
cod_info->region0_count = 0;
|
||||
cod_info->region1_count = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
const int *scalefac_band_long = &shine_scale_fact_band_index[config->mpeg.samplerate_index][0];
|
||||
int bigvalues_region, scfb_anz, thiscount;
|
||||
|
||||
bigvalues_region = 2 * cod_info->big_values;
|
||||
|
||||
/* Calculate scfb_anz */
|
||||
scfb_anz = 0;
|
||||
while ( scalefac_band_long[scfb_anz] < bigvalues_region )
|
||||
scfb_anz++;
|
||||
|
||||
for (thiscount = subdv_table[scfb_anz].region0_count; thiscount; thiscount--) {
|
||||
if (scalefac_band_long[thiscount + 1] <= bigvalues_region)
|
||||
break;
|
||||
}
|
||||
cod_info->region0_count = thiscount;
|
||||
cod_info->address1 = scalefac_band_long[thiscount + 1];
|
||||
|
||||
scalefac_band_long += cod_info->region0_count + 1;
|
||||
|
||||
for (thiscount = subdv_table[scfb_anz].region1_count; thiscount; thiscount--) {
|
||||
if (scalefac_band_long[thiscount + 1] <= bigvalues_region)
|
||||
break;
|
||||
}
|
||||
cod_info->region1_count = thiscount;
|
||||
cod_info->address2 = scalefac_band_long[thiscount + 1];
|
||||
|
||||
cod_info->address3 = bigvalues_region;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* bigv_tab_select:
|
||||
* ----------------
|
||||
* Function: Select huffman code tables for bigvalues regions
|
||||
*/
|
||||
void bigv_tab_select( int ix[GRANULE_SIZE], gr_info *cod_info ) {
|
||||
cod_info->table_select[0] = 0;
|
||||
cod_info->table_select[1] = 0;
|
||||
cod_info->table_select[2] = 0;
|
||||
|
||||
{
|
||||
if ( cod_info->address1 > 0 )
|
||||
cod_info->table_select[0] = new_choose_table( ix, 0, cod_info->address1 );
|
||||
|
||||
if ( cod_info->address2 > cod_info->address1 )
|
||||
cod_info->table_select[1] = new_choose_table( ix, cod_info->address1, cod_info->address2 );
|
||||
|
||||
if ( cod_info->big_values<<1 > cod_info->address2 )
|
||||
cod_info->table_select[2] = new_choose_table( ix, cod_info->address2, cod_info->big_values<<1 );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* new_choose_table:
|
||||
* -----------------
|
||||
* Choose the Huffman table that will encode ix[begin..end] with
|
||||
* the fewest bits.
|
||||
* Note: This code contains knowledge about the sizes and characteristics
|
||||
* of the Huffman tables as defined in the IS (Table B.7), and will not work
|
||||
* with any arbitrary tables.
|
||||
*/
|
||||
int new_choose_table( int ix[GRANULE_SIZE], unsigned int begin, unsigned int end ) {
|
||||
int i, max;
|
||||
int choice[2];
|
||||
int sum[2];
|
||||
|
||||
max = ix_max(ix,begin,end);
|
||||
if(!max)
|
||||
return 0;
|
||||
|
||||
choice[0] = 0;
|
||||
choice[1] = 0;
|
||||
|
||||
if(max<15)
|
||||
{
|
||||
/* try tables with no linbits */
|
||||
for ( i =14; i--; )
|
||||
if ( shine_huffman_table[i].xlen > max )
|
||||
{
|
||||
choice[0] = i;
|
||||
break;
|
||||
}
|
||||
|
||||
sum[0] = count_bit( ix, begin, end, choice[0] );
|
||||
|
||||
switch (choice[0])
|
||||
{
|
||||
case 2:
|
||||
sum[1] = count_bit( ix, begin, end, 3 );
|
||||
if ( sum[1] <= sum[0] )
|
||||
choice[0] = 3;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
sum[1] = count_bit( ix, begin, end, 6 );
|
||||
if ( sum[1] <= sum[0] )
|
||||
choice[0] = 6;
|
||||
break;
|
||||
|
||||
case 7:
|
||||
sum[1] = count_bit( ix, begin, end, 8 );
|
||||
if ( sum[1] <= sum[0] )
|
||||
{
|
||||
choice[0] = 8;
|
||||
sum[0] = sum[1];
|
||||
}
|
||||
sum[1] = count_bit( ix, begin, end, 9 );
|
||||
if ( sum[1] <= sum[0] )
|
||||
choice[0] = 9;
|
||||
break;
|
||||
|
||||
case 10:
|
||||
sum[1] = count_bit( ix, begin, end, 11 );
|
||||
if ( sum[1] <= sum[0] )
|
||||
{
|
||||
choice[0] = 11;
|
||||
sum[0] = sum[1];
|
||||
}
|
||||
sum[1] = count_bit( ix, begin, end, 12 );
|
||||
if ( sum[1] <= sum[0] )
|
||||
choice[0] = 12;
|
||||
break;
|
||||
|
||||
case 13:
|
||||
sum[1] = count_bit( ix, begin, end, 15 );
|
||||
if ( sum[1] <= sum[0] )
|
||||
choice[0] = 15;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* try tables with linbits */
|
||||
max -= 15;
|
||||
|
||||
for(i=15;i<24;i++)
|
||||
if(shine_huffman_table[i].linmax>=max)
|
||||
{
|
||||
choice[0] = i;
|
||||
break;
|
||||
}
|
||||
|
||||
for(i=24;i<32;i++)
|
||||
if(shine_huffman_table[i].linmax>=max)
|
||||
{
|
||||
choice[1] = i;
|
||||
break;
|
||||
}
|
||||
|
||||
sum[0] = count_bit(ix,begin,end,choice[0]);
|
||||
sum[1] = count_bit(ix,begin,end,choice[1]);
|
||||
if (sum[1]<sum[0])
|
||||
choice[0] = choice[1];
|
||||
}
|
||||
return choice[0];
|
||||
}
|
||||
|
||||
/*
|
||||
* bigv_bitcount:
|
||||
* --------------
|
||||
* Function: Count the number of bits necessary to code the bigvalues region.
|
||||
*/
|
||||
int bigv_bitcount(int ix[GRANULE_SIZE], gr_info *gi) {
|
||||
int bits = 0;
|
||||
unsigned int table;
|
||||
|
||||
if( (table=gi->table_select[0])) /* region0 */
|
||||
bits += count_bit(ix, 0, gi->address1, table );
|
||||
if( (table=gi->table_select[1])) /* region1 */
|
||||
bits += count_bit(ix, gi->address1, gi->address2, table );
|
||||
if( (table=gi->table_select[2])) /* region2 */
|
||||
bits += count_bit(ix, gi->address2, gi->address3, table );
|
||||
return bits;
|
||||
}
|
||||
|
||||
/*
|
||||
* count_bit:
|
||||
* ----------
|
||||
* Function: Count the number of bits necessary to code the subregion.
|
||||
*/
|
||||
int count_bit(int ix[GRANULE_SIZE],
|
||||
unsigned int start,
|
||||
unsigned int end,
|
||||
unsigned int table ) {
|
||||
unsigned linbits, ylen;
|
||||
register int i, sum;
|
||||
register int x,y;
|
||||
const struct huffcodetab *h;
|
||||
|
||||
if(!table)
|
||||
return 0;
|
||||
|
||||
h = &(shine_huffman_table[table]);
|
||||
sum = 0;
|
||||
|
||||
ylen = h->ylen;
|
||||
linbits = h->linbits;
|
||||
|
||||
if(table>15)
|
||||
{ /* ESC-table is used */
|
||||
for(i=start;i<end;i+=2)
|
||||
{
|
||||
x = ix[i];
|
||||
y = ix[i+1];
|
||||
if(x>14)
|
||||
{
|
||||
x = 15;
|
||||
sum += linbits;
|
||||
}
|
||||
if(y>14)
|
||||
{
|
||||
y = 15;
|
||||
sum += linbits;
|
||||
}
|
||||
|
||||
sum += h->hlen[(x*ylen)+y];
|
||||
if(x)
|
||||
sum++;
|
||||
if(y)
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* No ESC-words */
|
||||
for(i=start;i<end;i+=2)
|
||||
{
|
||||
x = ix[i];
|
||||
y = ix[i+1];
|
||||
|
||||
sum += h->hlen[(x*ylen)+y];
|
||||
|
||||
if(x!=0)
|
||||
sum++;
|
||||
if(y!=0)
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/*
|
||||
* bin_search_StepSize:
|
||||
* --------------------
|
||||
* Succesive approximation approach to obtaining a initial quantizer
|
||||
* step size.
|
||||
* The following optional code written by Seymour Shlien
|
||||
* will speed up the shine_outer_loop code which is called
|
||||
* by iteration_loop. When BIN_SEARCH is defined, the
|
||||
* shine_outer_loop function precedes the call to the function shine_inner_loop
|
||||
* with a call to bin_search gain defined below, which
|
||||
* returns a good starting quantizerStepSize.
|
||||
*/
|
||||
int bin_search_StepSize(int desired_rate, int ix[GRANULE_SIZE],
|
||||
gr_info * cod_info, shine_global_config *config) {
|
||||
int bit, next, count;
|
||||
|
||||
next = -120;
|
||||
count = 120;
|
||||
|
||||
do {
|
||||
int half = count / 2;
|
||||
|
||||
if (quantize(ix, next + half, config) > 8192)
|
||||
bit = 100000; /* fail */
|
||||
else
|
||||
{
|
||||
calc_runlen(ix, cod_info); /* rzero,count1,big_values */
|
||||
bit = count1_bitcount(ix, cod_info); /* count1_table selection */
|
||||
subdivide(cod_info, config); /* bigvalues sfb division */
|
||||
bigv_tab_select(ix, cod_info); /* codebook selection */
|
||||
bit += bigv_bitcount(ix, cod_info); /* bit count */
|
||||
}
|
||||
|
||||
if (bit < desired_rate)
|
||||
count = half;
|
||||
else
|
||||
{
|
||||
next += half;
|
||||
count -= half;
|
||||
}
|
||||
} while (count > 1);
|
||||
|
||||
return next;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef L3LOOP_H
|
||||
#define L3LOOP_H
|
||||
|
||||
void shine_loop_initialise(shine_global_config *config);
|
||||
|
||||
void shine_iteration_loop(shine_global_config *config);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
/* L3mdct */
|
||||
|
||||
#include "types.h"
|
||||
#include "l3mdct.h"
|
||||
#include "l3subband.h"
|
||||
|
||||
/* This is table B.9: coefficients for aliasing reduction */
|
||||
#define MDCT_CA(coef) (int32_t)(coef / sqrt(1.0 + (coef * coef)) * 0x7fffffff)
|
||||
#define MDCT_CS(coef) (int32_t)(1.0 / sqrt(1.0 + (coef * coef)) * 0x7fffffff)
|
||||
|
||||
#define MDCT_CA0 MDCT_CA(-0.6)
|
||||
#define MDCT_CA1 MDCT_CA(-0.535)
|
||||
#define MDCT_CA2 MDCT_CA(-0.33)
|
||||
#define MDCT_CA3 MDCT_CA(-0.185)
|
||||
#define MDCT_CA4 MDCT_CA(-0.095)
|
||||
#define MDCT_CA5 MDCT_CA(-0.041)
|
||||
#define MDCT_CA6 MDCT_CA(-0.0142)
|
||||
#define MDCT_CA7 MDCT_CA(-0.0037)
|
||||
|
||||
#define MDCT_CS0 MDCT_CS(-0.6)
|
||||
#define MDCT_CS1 MDCT_CS(-0.535)
|
||||
#define MDCT_CS2 MDCT_CS(-0.33)
|
||||
#define MDCT_CS3 MDCT_CS(-0.185)
|
||||
#define MDCT_CS4 MDCT_CS(-0.095)
|
||||
#define MDCT_CS5 MDCT_CS(-0.041)
|
||||
#define MDCT_CS6 MDCT_CS(-0.0142)
|
||||
#define MDCT_CS7 MDCT_CS(-0.0037)
|
||||
|
||||
/*
|
||||
* shine_mdct_initialise:
|
||||
* -------------------
|
||||
*/
|
||||
void shine_mdct_initialise(shine_global_config *config) {
|
||||
int m,k;
|
||||
|
||||
/* prepare the mdct coefficients */
|
||||
for(m=18; m--; )
|
||||
for(k=36; k--; )
|
||||
/* combine window and mdct coefficients into a single table */
|
||||
/* scale and convert to fixed point before storing */
|
||||
config->mdct.cos_l[m][k] = (int32_t)(sin(PI36*(k+0.5))
|
||||
* cos((PI/72)*(2*k+19)*(2*m+1)) * 0x7fffffff);
|
||||
}
|
||||
|
||||
/*
|
||||
* shine_mdct_sub:
|
||||
* ------------
|
||||
*/
|
||||
void shine_mdct_sub(shine_global_config *config, int stride) {
|
||||
/* note. we wish to access the array 'config->mdct_freq[2][2][576]' as
|
||||
* [2][2][32][18]. (32*18=576),
|
||||
*/
|
||||
int32_t (*mdct_enc)[18];
|
||||
|
||||
int ch,gr,band,j,k;
|
||||
int32_t mdct_in[36];
|
||||
|
||||
for(ch=config->wave.channels; ch--; )
|
||||
{
|
||||
for(gr=0; gr<config->mpeg.granules_per_frame; gr++)
|
||||
{
|
||||
/* set up pointer to the part of config->mdct_freq we're using */
|
||||
mdct_enc = (int32_t (*)[18]) config->mdct_freq[ch][gr];
|
||||
|
||||
/* polyphase filtering */
|
||||
for(k=0; k<18; k+=2)
|
||||
{
|
||||
shine_window_filter_subband(&config->buffer[ch], &config->l3_sb_sample[ch][gr+1][k ][0], ch, config, stride);
|
||||
shine_window_filter_subband(&config->buffer[ch], &config->l3_sb_sample[ch][gr+1][k+1][0], ch, config, stride);
|
||||
/* Compensate for inversion in the analysis filter
|
||||
* (every odd index of band AND k)
|
||||
*/
|
||||
for(band=1; band<32; band+=2)
|
||||
config->l3_sb_sample[ch][gr+1][k+1][band] *= -1;
|
||||
}
|
||||
|
||||
/* Perform imdct of 18 previous subband samples + 18 current subband samples */
|
||||
for(band=0; band<32; band++)
|
||||
{
|
||||
for(k=18; k--; )
|
||||
{
|
||||
mdct_in[k ] = config->l3_sb_sample[ch][gr ][k][band];
|
||||
mdct_in[k+18] = config->l3_sb_sample[ch][gr+1][k][band];
|
||||
}
|
||||
|
||||
/* Calculation of the MDCT
|
||||
* In the case of long blocks ( block_type 0,1,3 ) there are
|
||||
* 36 coefficients in the time domain and 18 in the frequency
|
||||
* domain.
|
||||
*/
|
||||
|
||||
for(k=18; k--; )
|
||||
{
|
||||
int32_t vm;
|
||||
#ifdef __BORLANDC__
|
||||
uint32_t vm_lo;
|
||||
#else
|
||||
uint32_t vm_lo __attribute__((unused));
|
||||
#endif
|
||||
|
||||
mul0(vm, vm_lo, mdct_in[35], config->mdct.cos_l[k][35]);
|
||||
for(j=35; j; j-=7) {
|
||||
muladd(vm, vm_lo, mdct_in[j-1], config->mdct.cos_l[k][j-1]);
|
||||
muladd(vm, vm_lo, mdct_in[j-2], config->mdct.cos_l[k][j-2]);
|
||||
muladd(vm, vm_lo, mdct_in[j-3], config->mdct.cos_l[k][j-3]);
|
||||
muladd(vm, vm_lo, mdct_in[j-4], config->mdct.cos_l[k][j-4]);
|
||||
muladd(vm, vm_lo, mdct_in[j-5], config->mdct.cos_l[k][j-5]);
|
||||
muladd(vm, vm_lo, mdct_in[j-6], config->mdct.cos_l[k][j-6]);
|
||||
muladd(vm, vm_lo, mdct_in[j-7], config->mdct.cos_l[k][j-7]);
|
||||
}
|
||||
mulz(vm, vm_lo);
|
||||
mdct_enc[band][k] = vm;
|
||||
}
|
||||
|
||||
/* Perform aliasing reduction butterfly */
|
||||
asm ("#cmuls:");
|
||||
if (band != 0)
|
||||
{
|
||||
cmuls(mdct_enc[band][0], mdct_enc[band-1][17-0], mdct_enc[band][0], mdct_enc[band-1][17-0], MDCT_CS0, MDCT_CA0);
|
||||
cmuls(mdct_enc[band][1], mdct_enc[band-1][17-1], mdct_enc[band][1], mdct_enc[band-1][17-1], MDCT_CS1, MDCT_CA1);
|
||||
cmuls(mdct_enc[band][2], mdct_enc[band-1][17-2], mdct_enc[band][2], mdct_enc[band-1][17-2], MDCT_CS2, MDCT_CA2);
|
||||
cmuls(mdct_enc[band][3], mdct_enc[band-1][17-3], mdct_enc[band][3], mdct_enc[band-1][17-3], MDCT_CS3, MDCT_CA3);
|
||||
cmuls(mdct_enc[band][4], mdct_enc[band-1][17-4], mdct_enc[band][4], mdct_enc[band-1][17-4], MDCT_CS4, MDCT_CA4);
|
||||
cmuls(mdct_enc[band][5], mdct_enc[band-1][17-5], mdct_enc[band][5], mdct_enc[band-1][17-5], MDCT_CS5, MDCT_CA5);
|
||||
cmuls(mdct_enc[band][6], mdct_enc[band-1][17-6], mdct_enc[band][6], mdct_enc[band-1][17-6], MDCT_CS6, MDCT_CA6);
|
||||
cmuls(mdct_enc[band][7], mdct_enc[band-1][17-7], mdct_enc[band][7], mdct_enc[band-1][17-7], MDCT_CS7, MDCT_CA7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Save latest granule's subband samples to be used in the next mdct call */
|
||||
memcpy(config->l3_sb_sample[ch][0], config->l3_sb_sample[ch][config->mpeg.granules_per_frame], sizeof(config->l3_sb_sample[0][0]));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef shine_MDCT_H
|
||||
#define shine_MDCT_H
|
||||
|
||||
void shine_mdct_initialise(shine_global_config *config);
|
||||
void shine_mdct_sub(shine_global_config *config, int stride);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,104 @@
|
|||
/* L3SubBand */
|
||||
|
||||
#include "types.h"
|
||||
#include "tables.h"
|
||||
#include "l3subband.h"
|
||||
|
||||
/*
|
||||
* shine_subband_initialise:
|
||||
* ----------------------
|
||||
* Calculates the analysis filterbank coefficients and rounds to the
|
||||
* 9th decimal place accuracy of the filterbank tables in the ISO
|
||||
* document. The coefficients are stored in #filter#
|
||||
*/
|
||||
void shine_subband_initialise(shine_global_config *config) {
|
||||
int i,j;
|
||||
double filter;
|
||||
|
||||
for(i=MAX_CHANNELS; i-- ; ) {
|
||||
config->subband.off[i] = 0;
|
||||
memset(config->subband.x[i], 0, sizeof(config->subband.x[i]));
|
||||
}
|
||||
|
||||
for (i=SBLIMIT; i--; )
|
||||
for (j=64; j--; )
|
||||
{
|
||||
if ((filter = 1e9*cos((double)((2*i+1)*(16-j)*PI64))) >= 0)
|
||||
modf(filter+0.5, &filter);
|
||||
else
|
||||
modf(filter-0.5, &filter);
|
||||
/* scale and convert to fixed point before storing */
|
||||
config->subband.fl[i][j] = (int32_t)(filter * (0x7fffffff * 1e-9));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* shine_window_filter_subband:
|
||||
* -------------------------
|
||||
* Overlapping window on PCM samples
|
||||
* 32 16-bit pcm samples are scaled to fractional 2's complement and
|
||||
* concatenated to the end of the window buffer #x#. The updated window
|
||||
* buffer #x# is then windowed by the analysis window #shine_enwindow# to produce
|
||||
* the windowed sample #z#
|
||||
* Calculates the analysis filter bank coefficients
|
||||
* The windowed samples #z# is filtered by the digital filter matrix #filter#
|
||||
* to produce the subband samples #s#. This done by first selectively
|
||||
* picking out values from the windowed samples, and then multiplying
|
||||
* them by the filter matrix, producing 32 subband samples.
|
||||
*/
|
||||
void shine_window_filter_subband(int16_t **buffer, int32_t s[SBLIMIT], int ch, shine_global_config *config, int stride) {
|
||||
int32_t y[64];
|
||||
int i,j;
|
||||
int16_t *ptr = *buffer;
|
||||
|
||||
/* replace 32 oldest samples with 32 new samples */
|
||||
for (i=32;i--;) {
|
||||
config->subband.x[ch][i+config->subband.off[ch]] = ((int32_t)*ptr) << 16;
|
||||
ptr += stride;
|
||||
}
|
||||
*buffer = ptr;
|
||||
|
||||
for (i=64; i--; ) {
|
||||
int32_t s_value;
|
||||
#ifdef __BORLANDC__
|
||||
uint32_t s_value_lo;
|
||||
#else
|
||||
uint32_t s_value_lo __attribute__((unused));
|
||||
#endif
|
||||
|
||||
mul0 (s_value, s_value_lo, config->subband.x[ch][(config->subband.off[ch] + i + (0<<6)) & (HAN_SIZE-1)], shine_enwindow[i + (0<<6)]);
|
||||
muladd(s_value, s_value_lo, config->subband.x[ch][(config->subband.off[ch] + i + (1<<6)) & (HAN_SIZE-1)], shine_enwindow[i + (1<<6)]);
|
||||
muladd(s_value, s_value_lo, config->subband.x[ch][(config->subband.off[ch] + i + (2<<6)) & (HAN_SIZE-1)], shine_enwindow[i + (2<<6)]);
|
||||
muladd(s_value, s_value_lo, config->subband.x[ch][(config->subband.off[ch] + i + (3<<6)) & (HAN_SIZE-1)], shine_enwindow[i + (3<<6)]);
|
||||
muladd(s_value, s_value_lo, config->subband.x[ch][(config->subband.off[ch] + i + (4<<6)) & (HAN_SIZE-1)], shine_enwindow[i + (4<<6)]);
|
||||
muladd(s_value, s_value_lo, config->subband.x[ch][(config->subband.off[ch] + i + (5<<6)) & (HAN_SIZE-1)], shine_enwindow[i + (5<<6)]);
|
||||
muladd(s_value, s_value_lo, config->subband.x[ch][(config->subband.off[ch] + i + (6<<6)) & (HAN_SIZE-1)], shine_enwindow[i + (6<<6)]);
|
||||
muladd(s_value, s_value_lo, config->subband.x[ch][(config->subband.off[ch] + i + (7<<6)) & (HAN_SIZE-1)], shine_enwindow[i + (7<<6)]);
|
||||
mulz (s_value, s_value_lo);
|
||||
y[i] = s_value;
|
||||
}
|
||||
|
||||
config->subband.off[ch] = (config->subband.off[ch] + 480) & (HAN_SIZE-1); /* offset is modulo (HAN_SIZE)*/
|
||||
|
||||
for (i=SBLIMIT; i--; ) {
|
||||
int32_t s_value;
|
||||
#ifdef __BORLANDC__
|
||||
uint32_t s_value_lo;
|
||||
#else
|
||||
uint32_t s_value_lo __attribute__((unused));
|
||||
#endif
|
||||
|
||||
mul0(s_value, s_value_lo, config->subband.fl[i][63], y[63]);
|
||||
for (j=63; j; j-=7) {
|
||||
muladd(s_value, s_value_lo, config->subband.fl[i][j-1], y[j-1]);
|
||||
muladd(s_value, s_value_lo, config->subband.fl[i][j-2], y[j-2]);
|
||||
muladd(s_value, s_value_lo, config->subband.fl[i][j-3], y[j-3]);
|
||||
muladd(s_value, s_value_lo, config->subband.fl[i][j-4], y[j-4]);
|
||||
muladd(s_value, s_value_lo, config->subband.fl[i][j-5], y[j-5]);
|
||||
muladd(s_value, s_value_lo, config->subband.fl[i][j-6], y[j-6]);
|
||||
muladd(s_value, s_value_lo, config->subband.fl[i][j-7], y[j-7]);
|
||||
}
|
||||
mulz(s_value, s_value_lo);
|
||||
s[i] = s_value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef L3SUBBAND_H
|
||||
#define L3SUBBAND_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void shine_subband_initialise( shine_global_config *config );
|
||||
void shine_window_filter_subband(int16_t **buffer, int32_t s[SBLIMIT], int k, shine_global_config *config, int stride);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,290 @@
|
|||
/* layer3.c */
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
#include "types.h"
|
||||
#include "tables.h"
|
||||
#include "layer3.h"
|
||||
#include "l3subband.h"
|
||||
#include "l3mdct.h"
|
||||
#include "l3loop.h"
|
||||
#include "bitstream.h"
|
||||
#include "l3bitstream.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_system.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
static uint32_t counter[5] = {0};
|
||||
|
||||
static int granules_per_frame[4] = {
|
||||
1, /* MPEG 2.5 */
|
||||
-1, /* Reserved */
|
||||
1, /* MPEG II */
|
||||
2 /* MPEG I */
|
||||
};
|
||||
|
||||
/* Set default values for important vars */
|
||||
void shine_set_config_mpeg_defaults(shine_mpeg_t *mpeg) {
|
||||
mpeg->bitr = 128;
|
||||
mpeg->emph = NONE;
|
||||
mpeg->copyright = 0;
|
||||
mpeg->original = 1;
|
||||
}
|
||||
|
||||
int shine_mpeg_version(int samplerate_index) {
|
||||
/* Pick mpeg version according to samplerate index. */
|
||||
if (samplerate_index < 3) {
|
||||
/* First 3 samplerates are for MPEG-I */
|
||||
return MPEG_I;
|
||||
} else if (samplerate_index < 6) {
|
||||
/* Then it's MPEG-II */
|
||||
return MPEG_II;
|
||||
} else {
|
||||
/* Finally, MPEG-2.5 */
|
||||
return MPEG_25;
|
||||
}
|
||||
}
|
||||
|
||||
int shine_find_samplerate_index(int freq) {
|
||||
int i;
|
||||
|
||||
for(i=0;i<9;i++) {
|
||||
if(freq==samplerates[i]) return i;
|
||||
}
|
||||
return -1; /* error - not a valid samplerate for encoder */
|
||||
}
|
||||
|
||||
int shine_find_bitrate_index(int bitr, int mpeg_version) {
|
||||
int i;
|
||||
|
||||
for(i=0;i<16;i++) {
|
||||
if(bitr==bitrates[i][mpeg_version]) return i;
|
||||
}
|
||||
return -1; /* error - not a valid samplerate for encoder */
|
||||
}
|
||||
|
||||
int shine_check_config(int freq, int bitr) {
|
||||
int samplerate_index, bitrate_index, mpeg_version;
|
||||
|
||||
samplerate_index = shine_find_samplerate_index(freq);
|
||||
if (samplerate_index < 0) {
|
||||
return -1;
|
||||
}
|
||||
mpeg_version = shine_mpeg_version(samplerate_index);
|
||||
|
||||
bitrate_index = shine_find_bitrate_index(bitr, mpeg_version);
|
||||
if (bitrate_index < 0) {
|
||||
return -1;
|
||||
}
|
||||
return mpeg_version;
|
||||
}
|
||||
|
||||
int shine_samples_per_pass(shine_t s) {
|
||||
return s->mpeg.granules_per_frame * GRANULE_SIZE;
|
||||
}
|
||||
|
||||
/* Compute default encoding values. */
|
||||
shine_global_config *shine_initialise(shine_config_t *pub_config) {
|
||||
double avg_slots_per_frame;
|
||||
shine_global_config *config;
|
||||
int x, y;
|
||||
if (shine_check_config(pub_config->wave.samplerate, pub_config->mpeg.bitr) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
config = (shine_global_config*)heap_caps_malloc(sizeof(shine_global_config), MALLOC_CAP_SPIRAM);
|
||||
if (config == NULL) {
|
||||
return config;
|
||||
}
|
||||
|
||||
memset(config, 0, sizeof(shine_global_config));
|
||||
|
||||
#ifdef SHINE_DEBUG
|
||||
printf("l3_enc & mdct_freq each: %d\n", sizeof(int32_t)*GRANULE_SIZE*MAX_GRANULES*MAX_CHANNELS);
|
||||
#endif
|
||||
|
||||
for (x = 0; x < MAX_CHANNELS; x++) {
|
||||
for (y = 0; y < MAX_GRANULES; y++) {
|
||||
// 2 * 2 * 576 each
|
||||
config->l3_enc[x][y] = (int*)heap_caps_malloc(sizeof(int32_t)*GRANULE_SIZE, MALLOC_CAP_32BIT); //Significant performance hit in IRAM
|
||||
config->mdct_freq[x][y] = (int*)heap_caps_malloc(sizeof(int32_t)*GRANULE_SIZE, MALLOC_CAP_32BIT); //OK 1%
|
||||
}
|
||||
}
|
||||
#ifdef SHINE_DEBUG
|
||||
printf("l3loop struct: %d\n", sizeof(l3loop_t));
|
||||
#endif
|
||||
config->l3loop = (l3loop_t*)heap_caps_malloc(sizeof(l3loop_t), MALLOC_CAP_SPIRAM);
|
||||
#ifdef SHINE_DEBUG
|
||||
printf("xrsq & xrabs each: %d\n", sizeof(int32_t)*GRANULE_SIZE);
|
||||
#endif
|
||||
config->l3loop->xrsq = (int*)heap_caps_malloc(sizeof(int32_t)*GRANULE_SIZE, MALLOC_CAP_32BIT); //OK 0.5%
|
||||
config->l3loop->xrabs = (int*)heap_caps_malloc(sizeof(int32_t)*GRANULE_SIZE, MALLOC_CAP_32BIT); //OK 0.5%
|
||||
|
||||
/*typedef struct {
|
||||
int32_t *xr;
|
||||
int32_t *xrsq[GRANULE_SIZE];
|
||||
int32_t *xrabs[GRANULE_SIZE];
|
||||
int32_t xrmax;
|
||||
int32_t en_tot[MAX_GRANULES];
|
||||
int32_t en[MAX_GRANULES][21];
|
||||
int32_t xm[MAX_GRANULES][21];
|
||||
int32_t xrmaxl[MAX_GRANULES];
|
||||
double steptab[128];
|
||||
int32_t steptabi[128];
|
||||
int16_t int2idx[10000];
|
||||
} l3loop_t;*/
|
||||
|
||||
shine_subband_initialise(config);
|
||||
shine_mdct_initialise(config);
|
||||
shine_loop_initialise(config);
|
||||
|
||||
/* Copy public config. */
|
||||
config->wave.channels = pub_config->wave.channels;
|
||||
config->wave.samplerate = pub_config->wave.samplerate;
|
||||
config->mpeg.mode = pub_config->mpeg.mode;
|
||||
config->mpeg.bitr = pub_config->mpeg.bitr;
|
||||
config->mpeg.emph = pub_config->mpeg.emph;
|
||||
config->mpeg.copyright = pub_config->mpeg.copyright;
|
||||
config->mpeg.original = pub_config->mpeg.original;
|
||||
|
||||
/* Set default values. */
|
||||
config->ResvMax = 0;
|
||||
config->ResvSize = 0;
|
||||
config->mpeg.layer = LAYER_III;
|
||||
config->mpeg.crc = 0;
|
||||
config->mpeg.ext = 0;
|
||||
config->mpeg.mode_ext = 0;
|
||||
config->mpeg.bits_per_slot = 8;
|
||||
|
||||
config->mpeg.samplerate_index = shine_find_samplerate_index(config->wave.samplerate);
|
||||
config->mpeg.version = shine_mpeg_version(config->mpeg.samplerate_index);
|
||||
config->mpeg.bitrate_index = shine_find_bitrate_index(config->mpeg.bitr, config->mpeg.version);
|
||||
config->mpeg.granules_per_frame = granules_per_frame[config->mpeg.version];
|
||||
|
||||
/* Figure average number of 'slots' per frame. */
|
||||
avg_slots_per_frame = ((double)config->mpeg.granules_per_frame * GRANULE_SIZE /
|
||||
((double)config->wave.samplerate)) *
|
||||
(1000*(double)config->mpeg.bitr /
|
||||
(double)config->mpeg.bits_per_slot);
|
||||
|
||||
config->mpeg.whole_slots_per_frame = (int)avg_slots_per_frame;
|
||||
|
||||
config->mpeg.frac_slots_per_frame = avg_slots_per_frame - (double)config->mpeg.whole_slots_per_frame;
|
||||
config->mpeg.slot_lag = -config->mpeg.frac_slots_per_frame;
|
||||
|
||||
if(config->mpeg.frac_slots_per_frame==0) {
|
||||
config->mpeg.padding = 0;
|
||||
}
|
||||
|
||||
shine_open_bit_stream(&config->bs, BUFFER_SIZE);
|
||||
|
||||
memset((char *)&config->side_info,0,sizeof(shine_side_info_t));
|
||||
|
||||
/* determine the mean bitrate for main data */
|
||||
if (config->mpeg.granules_per_frame == 2) { /* MPEG 1 */
|
||||
config->sideinfo_len = 8 * ((config->wave.channels==1) ? 4 + 17 : 4 + 32);
|
||||
} else { /* MPEG 2 */
|
||||
config->sideinfo_len = 8 * ((config->wave.channels==1) ? 4 + 9 : 4 + 17);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t *shine_get_counters() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
/* Counter results
|
||||
Counters 1550541561 : 1550541629 : 1553135798 : 1555116724 : 1555309952
|
||||
68
|
||||
core 1 will do:
|
||||
2594169
|
||||
core 0 will do:
|
||||
1980926
|
||||
193228
|
||||
|
||||
|
||||
Counters 2664123380 : 2664123448 : 2666717886 : 2668665908 : 2668859025
|
||||
*/
|
||||
|
||||
|
||||
static unsigned char *shine_encode_buffer_internal(shine_global_config *config, int *written, int stride) {
|
||||
counter[0] = xthal_get_ccount();
|
||||
if(config->mpeg.frac_slots_per_frame) {
|
||||
config->mpeg.padding = (config->mpeg.slot_lag <= (config->mpeg.frac_slots_per_frame - 1.0));
|
||||
config->mpeg.slot_lag += (config->mpeg.padding - config->mpeg.frac_slots_per_frame);
|
||||
}
|
||||
|
||||
config->mpeg.bits_per_frame = 8*(config->mpeg.whole_slots_per_frame + config->mpeg.padding);
|
||||
config->mean_bits = (config->mpeg.bits_per_frame - config->sideinfo_len)/config->mpeg.granules_per_frame;
|
||||
counter[1] = xthal_get_ccount();
|
||||
/* apply mdct to the polyphase output */
|
||||
// put on core 1
|
||||
shine_mdct_sub(config, stride);
|
||||
counter[2] = xthal_get_ccount();
|
||||
/* bit and noise allocation */
|
||||
//put on core 0
|
||||
shine_iteration_loop(config);
|
||||
counter[3] = xthal_get_ccount();
|
||||
/* write the frame to the bitstream */
|
||||
shine_format_bitstream(config);
|
||||
counter[4] = xthal_get_ccount();
|
||||
/* Return data. */
|
||||
*written = config->bs.data_position;
|
||||
config->bs.data_position = 0;
|
||||
|
||||
return config->bs.data;
|
||||
}
|
||||
|
||||
unsigned char *shine_encode_buffer(shine_global_config *config, int16_t **data, int *written) {
|
||||
config->buffer[0] = data[0];
|
||||
if (config->wave.channels == 2) {
|
||||
config->buffer[1] = data[1];
|
||||
}
|
||||
return shine_encode_buffer_internal(config, written, 1);
|
||||
}
|
||||
|
||||
unsigned char *shine_encode_buffer_interleaved(shine_global_config *config, int16_t *data, int *written) {
|
||||
config->buffer[0] = data;
|
||||
if (config->wave.channels == 2) {
|
||||
config->buffer[1] = data + 1;
|
||||
}
|
||||
return shine_encode_buffer_internal(config, written, config->wave.channels);
|
||||
}
|
||||
|
||||
unsigned char *shine_flush(shine_global_config *config, int *written) {
|
||||
*written = config->bs.data_position;
|
||||
config->bs.data_position = 0;
|
||||
return config->bs.data;
|
||||
}
|
||||
|
||||
void shine_close(shine_global_config *config) {
|
||||
shine_close_bit_stream(&config->bs);
|
||||
|
||||
for (uint16_t x = 0; x < MAX_CHANNELS; x++) {
|
||||
for (uint16_t y = 0; y < MAX_GRANULES; y++) {
|
||||
if (config->l3_enc[x][y]) {
|
||||
free(config->l3_enc[x][y]);
|
||||
}
|
||||
if (config->mdct_freq[x][y]) {
|
||||
free(config->mdct_freq[x][y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config->l3loop = (l3loop_t*)heap_caps_malloc(sizeof(l3loop_t), MALLOC_CAP_SPIRAM);
|
||||
if (config->l3loop) {
|
||||
free(config->l3loop);
|
||||
}
|
||||
if (config->l3loop->xrsq) {
|
||||
free(config->l3loop->xrsq);
|
||||
}
|
||||
if (config->l3loop->xrabs) {
|
||||
free(config->l3loop->xrabs);
|
||||
}
|
||||
|
||||
free(config);
|
||||
}
|
||||
|
||||
#endif // ESP32
|
|
@ -0,0 +1,166 @@
|
|||
#ifndef LAYER3_H
|
||||
#define LAYER3_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* This is the struct used to tell the encoder about the input PCM */
|
||||
|
||||
//#define SHINE_DEBUG
|
||||
|
||||
enum channels {
|
||||
PCM_MONO = 1,
|
||||
PCM_STEREO = 2
|
||||
};
|
||||
|
||||
enum mpeg_versions {
|
||||
MPEG_I = 3,
|
||||
MPEG_II = 2,
|
||||
MPEG_25 = 0
|
||||
};
|
||||
|
||||
/* Only Layer III currently implemented. */
|
||||
enum mpeg_layers {
|
||||
LAYER_III = 1
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
enum channels channels;
|
||||
int samplerate;
|
||||
} shine_wave_t;
|
||||
|
||||
/* This is the struct the encoder uses to tell the encoder about the output MP3 */
|
||||
|
||||
enum modes {
|
||||
STEREO = 0,
|
||||
JOINT_STEREO = 1,
|
||||
DUAL_CHANNEL = 2,
|
||||
MONO = 3
|
||||
};
|
||||
|
||||
enum emph {
|
||||
NONE = 0,
|
||||
MU50_15 = 1,
|
||||
CITT = 3
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
enum modes mode; /* Stereo mode */
|
||||
int bitr; /* Must conform to known bitrate */
|
||||
enum emph emph; /* De-emphasis */
|
||||
int copyright;
|
||||
int original;
|
||||
} shine_mpeg_t;
|
||||
|
||||
typedef struct {
|
||||
shine_wave_t wave;
|
||||
shine_mpeg_t mpeg;
|
||||
} shine_config_t;
|
||||
|
||||
/* Tables of supported audio parameters & format.
|
||||
*
|
||||
* Valid samplerates and bitrates.
|
||||
* const int samplerates[9] = {
|
||||
* 44100, 48000, 32000, // MPEG-I
|
||||
* 22050, 24000, 16000, // MPEG-II
|
||||
* 11025, 12000, 8000 // MPEG-2.5
|
||||
* };
|
||||
*
|
||||
* const int bitrates[16][4] = {
|
||||
* // MPEG version:
|
||||
* // 2.5, reserved, II, I
|
||||
* { -1, -1, -1, -1},
|
||||
* { 8, -1, 8, 32},
|
||||
* { 16, -1, 16, 40},
|
||||
* { 24, -1, 24, 48},
|
||||
* { 32, -1, 32, 56},
|
||||
* { 40, -1, 40, 64},
|
||||
* { 48, -1, 48, 80},
|
||||
* { 56, -1, 56, 96},
|
||||
* { 64, -1, 64, 112},
|
||||
* { 80, -1, 80, 128},
|
||||
* { 96, -1, 96, 160},
|
||||
* {112, -1, 112, 192},
|
||||
* {128, -1, 128, 224},
|
||||
* {144, -1, 144, 256},
|
||||
* {160, -1, 160, 320},
|
||||
* { -1, -1, -1, -1}
|
||||
* };
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* Abtract type for the shine encoder handle. */
|
||||
typedef struct shine_global_flags *shine_t;
|
||||
|
||||
/* Fill in a `mpeg_t` structure with default values. */
|
||||
void shine_set_config_mpeg_defaults(shine_mpeg_t *mpeg);
|
||||
|
||||
/* Check if a given bitrate is supported by the encoder (see `bitrates` above for a list
|
||||
* of acceptable values. */
|
||||
int shine_find_bitrate_index(int bitr, int mpeg_version);
|
||||
|
||||
/* Check if a given samplerate is supported by the encoder (see `samplerates` above for a list
|
||||
* of acceptable values. */
|
||||
int shine_find_samplerate_index(int freq);
|
||||
|
||||
/* Returns the MPEG version used for the given samplerate index. See above
|
||||
* `mpeg_versions` for a list of possible values. */
|
||||
int shine_mpeg_version(int samplerate_index);
|
||||
|
||||
/* Check if a given bitrate and samplerate is supported by the encoder (see `samplerates`
|
||||
* and `bitrates` above for a list of acceptable values).
|
||||
*
|
||||
* Returns -1 on error, mpeg_version on success. */
|
||||
int shine_check_config(int freq, int bitr);
|
||||
|
||||
/* Pass a pointer to a `config_t` structure and returns an initialized
|
||||
* encoder.
|
||||
*
|
||||
* Configuration data is copied over to the encoder. It is not possible
|
||||
* to change its values after initializing the encoder at the moment.
|
||||
*
|
||||
* Checking for valid configuration values is left for the application to
|
||||
* implement. You can use the `shine_find_bitrate_index` and
|
||||
* `shine_find_samplerate_index` functions or the `bitrates` and
|
||||
* `samplerates` arrays above to check those parameters. Mone and stereo
|
||||
* mode for wave and mpeg should also be consistent with each other.
|
||||
*
|
||||
* This function returns NULL if it was not able to allocate memory data for
|
||||
* the encoder. */
|
||||
shine_t shine_initialise(shine_config_t *config);
|
||||
|
||||
/* Maximun possible value for the function below. */
|
||||
#define SHINE_MAX_SAMPLES 1152
|
||||
|
||||
uint32_t *shine_get_counters();
|
||||
|
||||
/* Returns audio samples expected in each frame. */
|
||||
int shine_samples_per_pass(shine_t s);
|
||||
|
||||
/* Encode audio data. Source data must have `shine_samples_per_pass(s)` audio samples per
|
||||
* channels. Mono encoder only expect one channel.
|
||||
*
|
||||
* Returns a pointer to freshly encoded data while `written` contains the size of
|
||||
* available data. This pointer's memory is handled by the library and is only valid
|
||||
* until the next call to `shine_encode_buffer` or `shine_close` and may be NULL if no data
|
||||
* was written. */
|
||||
unsigned char *shine_encode_buffer(shine_t s, int16_t **data, int *written);
|
||||
|
||||
/* Encode interleaved audio data. Source data must have `shine_samples_per_pass(s)` audio samples per
|
||||
* channels. Mono encoder only expect one channel.
|
||||
*
|
||||
* Returns a pointer to freshly encoded data while `written` contains the size of
|
||||
* available data. This pointer's memory is handled by the library and is only valid
|
||||
* until the next call to `shine_encode_buffer` or `shine_close` and may be NULL if no data
|
||||
* was written. */
|
||||
unsigned char *shine_encode_buffer_interleaved(shine_t s, int16_t *data, int *written);
|
||||
|
||||
/* Flush all data currently in the encoding buffer. Should be used before closing
|
||||
* the encoder, to make all encoded data has been written. */
|
||||
unsigned char *shine_flush(shine_t s, int *written);
|
||||
|
||||
/* Close an encoder, freeing all associated memory. Encoder handler is not
|
||||
* valid after this call. */
|
||||
void shine_close(shine_t s);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,51 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#define mul(a,b) \
|
||||
({ \
|
||||
register int32_t res; \
|
||||
__asm__ __volatile__("mult %0, %1" : : "r" (a), "r" (b)); \
|
||||
__asm__ __volatile__("mfhi %0" : "=r" (res)); \
|
||||
res; \
|
||||
})
|
||||
|
||||
#define mul0(hi,lo,a,b) \
|
||||
__asm__ __volatile__("mult %0, %1" : : "r" (a), "r" (b))
|
||||
|
||||
#define muladd(hi,lo,a,b) \
|
||||
__asm__ __volatile__("madd %0, %1" : : "r" (a), "r" (b))
|
||||
|
||||
#define mulsub(hi,lo,a,b) \
|
||||
__asm__ __volatile__("msub %0, %1" : : "r" (a), "r" (b))
|
||||
|
||||
#define mulz(hi,lo) \
|
||||
do { \
|
||||
register int32_t t; \
|
||||
__asm__ __volatile__("mfhi %0" : "=r" (t)); \
|
||||
(hi) = t; \
|
||||
} while (0)
|
||||
|
||||
#define cmuls(dre, dim, are, aim, bre, bim) \
|
||||
do { \
|
||||
register int32_t t1, t2, tre; \
|
||||
__asm__ __volatile__("mult %0, %1" : : "r" (are), "r" (bre)); \
|
||||
__asm__ __volatile__("msub %0, %1" : : "r" (aim), "r" (bim)); \
|
||||
__asm__ __volatile__("mfhi %0; mflo %1" : "=r" (t1), "=r" (t2)); \
|
||||
tre = (t1 << 1) | ((uint32_t)t2 >> 31); \
|
||||
__asm__ __volatile__("mult %0, %1" : : "r" (are), "r" (bim)); \
|
||||
__asm__ __volatile__("madd %0, %1" : : "r" (bre), "r" (aim)); \
|
||||
dre = tre; \
|
||||
__asm__ __volatile__("mfhi %0; mflo %1" : "=r" (t1), "=r" (t2)); \
|
||||
dim = (t1 << 1) | ((uint32_t)t2 >> 31); \
|
||||
} while (0)
|
||||
|
||||
#if __mips_isa_rev >= 2
|
||||
static inline uint32_t SWAB32(uint32_t x)
|
||||
{
|
||||
__asm__(
|
||||
" wsbh %0, %1 \n"
|
||||
" rotr %0, %0, 16 \n"
|
||||
: "=r" (x) : "r" (x));
|
||||
return x;
|
||||
}
|
||||
#define SWAB32 SWAB32
|
||||
#endif
|
|
@ -0,0 +1,119 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#ifndef mul
|
||||
//#define /// mul(a,b) (int32_t) ( ( ((int64_t) a) * ((int64_t) b) ) >>32 )
|
||||
|
||||
#define mul(x,y) \
|
||||
({ \
|
||||
register int32_t result; \
|
||||
asm ("mulsh %0, %2, %1" : "=r" (result) : "r" (x), "r" (y)); \
|
||||
result ;\
|
||||
})
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef muls //Not sure about this
|
||||
#define muls(x,y) \
|
||||
({ \
|
||||
register int32_t result; \
|
||||
asm ( \
|
||||
"mulsh %0, %2, %1\n\t" \
|
||||
"add %0, %0, %0" \
|
||||
: "=r" (result) : "r" (x), "r" (y)); \
|
||||
result ;\
|
||||
})
|
||||
|
||||
|
||||
|
||||
//#define muls(a,b) (int32_t) ( ( ((int64_t) a) * ((int64_t) b) ) >>31 )
|
||||
#endif
|
||||
|
||||
#ifndef mulr //no rounding shortcut
|
||||
#define mulr(x,y) \
|
||||
({ \
|
||||
register int32_t result; \
|
||||
asm ("mulsh %0, %2, %1" : "=r" (result) : "r" (x), "r" (y)); \
|
||||
result ;\
|
||||
})
|
||||
|
||||
//#define mulr(a,b) (int32_t) ( ( ( ((int64_t) a) * ((int64_t) b)) + 0x80000000LL ) >>32 )
|
||||
#endif
|
||||
|
||||
#ifndef mulsr //no rounding shortcut
|
||||
#define mulsr(x,y) \
|
||||
({ \
|
||||
register int32_t result; \
|
||||
asm ( \
|
||||
"mulsh %0, %2, %1\n\t" \
|
||||
"add %0, %0, %0" \
|
||||
: "=r" (result) : "r" (x), "r" (y)); \
|
||||
result ;\
|
||||
})
|
||||
|
||||
//#define mulsr(a,b) (int32_t) ( ( ( ((int64_t) a) * ((int64_t) b)) + 0x40000000LL ) >>31 )
|
||||
#endif
|
||||
|
||||
#ifndef mul0
|
||||
#define mul0(hi,lo,a,b) ((hi) = mul((a), (b)))
|
||||
|
||||
// This didn't seem to help either
|
||||
#define muladd(hi, lo, x, y) \
|
||||
({ \
|
||||
asm ( \
|
||||
"mulsh a7, %2, %1\n\t" \
|
||||
"add %0, %0, a7\n\t" \
|
||||
: "+r" (hi) : "r" (x), "r" (y) \
|
||||
: "a7");\
|
||||
})
|
||||
|
||||
|
||||
//#define muladd(hi,lo,a,b) ((hi) += mul((a), (b)))
|
||||
#define mulsub(hi, lo, x, y) \
|
||||
({ \
|
||||
asm ( \
|
||||
"mulsh a8, %2, %1\n\t" \
|
||||
"sub %0, %0, a8\n\t" \
|
||||
: "+r" (hi) : "r" (x), "r" (y) \
|
||||
: "a8");\
|
||||
})
|
||||
//#define mulsub(hi,lo,a,b) ((hi) -= mul((a), (b)))
|
||||
#define mulz(hi,lo)
|
||||
#endif
|
||||
|
||||
#ifndef cmuls
|
||||
/*
|
||||
#define cmuls(dre, dim, are, aim, bre, bim) \
|
||||
do { \
|
||||
register int32_t tre, tim; \
|
||||
asm ( \
|
||||
"mull %0, %2, %4\n\t" \ //mulsh
|
||||
"mulsh r3, %2, %4\n\t" \ //mulsh
|
||||
"mull r4, %3, %5\n\t" \ //mulsh
|
||||
"mulsh r5, %3, %5\n\t" \ //mulsh
|
||||
"add %0, %0, %0\n\t" \ shl
|
||||
|
||||
"smull r3, %0, %2, %4\n\t" \ //mulsh
|
||||
"smlal r3, %0, %3, %5\n\t" \ //mulsh + add
|
||||
"movs r3, r3, lsl #1\n\t" \ //add r to r
|
||||
"adc %0, %0, %0\n\t" \. //add with carry
|
||||
"smull r3, %1, %2, %6\n\t" \
|
||||
"smlal r3, %1, %4, %3\n\t" \
|
||||
"movs r3, r3, lsl #1\n\t" \
|
||||
"adc %1, %1, %1\n\t" \
|
||||
: "=&r" (tre), "=&r" (tim) \
|
||||
: "r" (are), "r" (aim), "r" (bre), "r" (-(bim)), "r" (bim) \
|
||||
: "r3", "cc" \
|
||||
); \
|
||||
dre = tre; \
|
||||
dim = tim; \
|
||||
} while (0)*/
|
||||
|
||||
|
||||
#define cmuls(dre, dim, are, aim, bre, bim) \
|
||||
do { \
|
||||
int32_t tre; \
|
||||
(tre) = (int32_t) (((int64_t) (are) * (int64_t) (bre) - (int64_t) (aim) * (int64_t) (bim)) >> 31); \
|
||||
(dim) = (int32_t) (((int64_t) (are) * (int64_t) (bim) + (int64_t) (aim) * (int64_t) (bre)) >> 31); \
|
||||
(dre) = tre; \
|
||||
} while (0)
|
||||
#endif
|
|
@ -0,0 +1,109 @@
|
|||
#include <stdint.h>
|
||||
|
||||
/* Fractional multiply */
|
||||
#if __ARM_ARCH >= 6
|
||||
#define mul(x,y) \
|
||||
({ \
|
||||
register int32_t result; \
|
||||
asm ("smmul %0, %2, %1" : "=r" (result) : "r" (x), "r" (y)); \
|
||||
result ;\
|
||||
})
|
||||
#else
|
||||
#define mul(x,y) \
|
||||
({ \
|
||||
register int32_t result; \
|
||||
asm ("smull r3, %0, %2, %1" : "=r" (result) : "r" (x), "r" (y) : "r3"); \
|
||||
result ; \
|
||||
})
|
||||
#endif
|
||||
|
||||
/* Fractional multiply with single bit left shift. */
|
||||
#define muls(x,y) \
|
||||
({ \
|
||||
register int32_t result; \
|
||||
asm ( \
|
||||
"smull r3, %0, %2, %1\n\t" \
|
||||
"movs r3, r3, lsl #1\n\t" \
|
||||
"adc %0, %0, %0" \
|
||||
: "=r" (result) : "r" (x), "r" (y) : "r3", "cc" \
|
||||
); \
|
||||
result; \
|
||||
})
|
||||
|
||||
|
||||
#if __ARM_ARCH >= 6
|
||||
#define mulr(x,y) \
|
||||
({ \
|
||||
register int32_t result; \
|
||||
asm ( \
|
||||
"smmulr %0, %2, %1" : "=r" (result) : "r" (x), "r" (y) \
|
||||
); \
|
||||
result; \
|
||||
})
|
||||
#else
|
||||
#define mulr(x,y) \
|
||||
({ \
|
||||
register int32_t result; \
|
||||
asm ( \
|
||||
"smull r3, %0, %2, %1\n\t" \
|
||||
"adds r3, r3, #0x80000000\n\t" \
|
||||
"adc %0, %0, #0" \
|
||||
: "=r" (result) : "r" (x), "r" (y) : "r3", "cc" \
|
||||
); \
|
||||
result; \
|
||||
})
|
||||
#endif
|
||||
|
||||
#define mulsr(x,y) \
|
||||
({ \
|
||||
register int32_t result; \
|
||||
asm ( \
|
||||
"smull r3, %0, %1, %2\n\t" \
|
||||
"movs r3, r3, lsl #1\n\t" \
|
||||
"adc %0, %0, %0\n\t" \
|
||||
"adds r3, r3, #0x80000000\n\t" \
|
||||
"adc %0, %0, #0" \
|
||||
: "=r" (result) : "r" (x), "r" (y) : "r3", "cc" \
|
||||
); \
|
||||
result; \
|
||||
})
|
||||
|
||||
#define mul0(hi,lo,a,b) \
|
||||
asm ("smull %0, %1, %2, %3" : "=r" (lo), "=r" (hi) : "r" (a), "r" (b))
|
||||
|
||||
#define muladd(hi,lo,a,b) \
|
||||
asm ("smlal %0, %1, %2, %3" : "+r" (lo), "+r" (hi) : "r" (a), "r" (b))
|
||||
|
||||
#define mulsub(hi,lo,a,b) \
|
||||
asm ("smlal %0, %1, %2, %3" : "+r" (lo), "+r" (hi) : "r" (a), "r" (-(b)))
|
||||
|
||||
#define mulz(hi,lo)
|
||||
|
||||
#define cmuls(dre, dim, are, aim, bre, bim) \
|
||||
do { \
|
||||
register int32_t tre, tim; \
|
||||
asm ( \
|
||||
"smull r3, %0, %2, %4\n\t" \
|
||||
"smlal r3, %0, %3, %5\n\t" \
|
||||
"movs r3, r3, lsl #1\n\t" \
|
||||
"adc %0, %0, %0\n\t" \
|
||||
"smull r3, %1, %2, %6\n\t" \
|
||||
"smlal r3, %1, %4, %3\n\t" \
|
||||
"movs r3, r3, lsl #1\n\t" \
|
||||
"adc %1, %1, %1\n\t" \
|
||||
: "=&r" (tre), "=&r" (tim) \
|
||||
: "r" (are), "r" (aim), "r" (bre), "r" (-(bim)), "r" (bim) \
|
||||
: "r3", "cc" \
|
||||
); \
|
||||
dre = tre; \
|
||||
dim = tim; \
|
||||
} while (0)
|
||||
|
||||
#if __ARM_ARCH >= 6
|
||||
static inline uint32_t SWAB32(uint32_t x)
|
||||
{
|
||||
asm ("rev %0, %1" : "=r" (x) : "r" (x));
|
||||
return x;
|
||||
}
|
||||
#define SWAB32 SWAB32
|
||||
#endif
|
|
@ -0,0 +1,132 @@
|
|||
/* reservoir.c
|
||||
* Layer3 bit reservoir: Described in C.1.5.4.2.2 of the IS
|
||||
*/
|
||||
|
||||
#include "types.h"
|
||||
#include "layer3.h"
|
||||
#include "l3loop.h"
|
||||
#include "huffman.h"
|
||||
#include "bitstream.h"
|
||||
#include "l3bitstream.h"
|
||||
#include "reservoir.h"
|
||||
|
||||
/*
|
||||
* shine_max_reservoir_bits:
|
||||
* ------------
|
||||
* Called at the beginning of each granule to get the max bit
|
||||
* allowance for the current granule based on reservoir size
|
||||
* and perceptual entropy.
|
||||
*/
|
||||
int shine_max_reservoir_bits (double *pe, shine_global_config *config ) {
|
||||
int more_bits, max_bits, add_bits, over_bits;
|
||||
int mean_bits = config->mean_bits;
|
||||
|
||||
mean_bits /= config->wave.channels;
|
||||
max_bits = mean_bits;
|
||||
|
||||
if(max_bits>4095)
|
||||
max_bits = 4095;
|
||||
if(!config->ResvMax)
|
||||
return max_bits;
|
||||
|
||||
more_bits = *pe * 3.1 - mean_bits;
|
||||
add_bits = 0;
|
||||
if(more_bits>100)
|
||||
{
|
||||
int frac = (config->ResvSize * 6) / 10;
|
||||
|
||||
if(frac<more_bits)
|
||||
add_bits = frac;
|
||||
else
|
||||
add_bits = more_bits;
|
||||
}
|
||||
over_bits = config->ResvSize - ((config->ResvMax <<3) / 10) - add_bits;
|
||||
if (over_bits>0)
|
||||
add_bits += over_bits;
|
||||
|
||||
max_bits += add_bits;
|
||||
if(max_bits>4095)
|
||||
max_bits = 4095;
|
||||
return max_bits;
|
||||
}
|
||||
|
||||
/*
|
||||
* shine_ResvAdjust:
|
||||
* -----------
|
||||
* Called after a granule's bit allocation. Readjusts the size of
|
||||
* the reservoir to reflect the granule's usage.
|
||||
*/
|
||||
void shine_ResvAdjust(gr_info *gi, shine_global_config *config ) {
|
||||
config->ResvSize += (config->mean_bits / config->wave.channels) - gi->part2_3_length;
|
||||
}
|
||||
|
||||
/*
|
||||
* shine_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. Note that stuffing bits are added by increasing a granule's
|
||||
* part2_3_length. The bitstream formatter will detect this and write the
|
||||
* appropriate stuffing bits to the bitstream.
|
||||
*/
|
||||
void shine_ResvFrameEnd(shine_global_config *config ) {
|
||||
gr_info *gi;
|
||||
int gr, ch, ancillary_pad, stuffingBits;
|
||||
int over_bits;
|
||||
shine_side_info_t *l3_side = &config->side_info;
|
||||
|
||||
ancillary_pad = 0;
|
||||
|
||||
/* just in case mean_bits is odd, this is necessary... */
|
||||
if((config->wave.channels==2) && (config->mean_bits & 1))
|
||||
config->ResvSize += 1;
|
||||
|
||||
over_bits = config->ResvSize - config->ResvMax;
|
||||
if(over_bits<0)
|
||||
over_bits = 0;
|
||||
|
||||
config->ResvSize -= over_bits;
|
||||
stuffingBits = over_bits + ancillary_pad;
|
||||
|
||||
/* we must be byte aligned */
|
||||
if((over_bits = config->ResvSize % 8))
|
||||
{
|
||||
stuffingBits += over_bits;
|
||||
config->ResvSize -= over_bits;
|
||||
}
|
||||
|
||||
if(stuffingBits)
|
||||
{
|
||||
/*
|
||||
* plan a: put all into the first granule
|
||||
* This was preferred by someone designing a
|
||||
* real-time decoder...
|
||||
*/
|
||||
gi = (gr_info *) &(l3_side->gr[0].ch[0]);
|
||||
|
||||
if ( gi->part2_3_length + stuffingBits < 4095 )
|
||||
gi->part2_3_length += stuffingBits;
|
||||
else
|
||||
{
|
||||
/* plan b: distribute throughout the granules */
|
||||
for (gr = 0; gr < config->mpeg.granules_per_frame; gr++ )
|
||||
for (ch = 0; ch < config->wave.channels; ch++ )
|
||||
{
|
||||
int extraBits, bitsThisGr;
|
||||
gr_info *gi = (gr_info *) &(l3_side->gr[gr].ch[ch]);
|
||||
if (!stuffingBits)
|
||||
break;
|
||||
extraBits = 4095 - gi->part2_3_length;
|
||||
bitsThisGr = extraBits < stuffingBits ? extraBits : stuffingBits;
|
||||
gi->part2_3_length += bitsThisGr;
|
||||
stuffingBits -= bitsThisGr;
|
||||
}
|
||||
/*
|
||||
* If any stuffing bits remain, we elect to spill them
|
||||
* into ancillary data. The bitstream formatter will do this if
|
||||
* l3side->resvDrain is set
|
||||
*/
|
||||
l3_side->resvDrain = stuffingBits;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef RESERVOIR_H
|
||||
#define RESERVOIR_H
|
||||
|
||||
void shine_ResvFrameBegin(int frameLength, shine_global_config *config);
|
||||
int shine_max_reservoir_bits (double *pe, shine_global_config *config);
|
||||
void shine_ResvAdjust (gr_info *gi, shine_global_config *config );
|
||||
void shine_ResvFrameEnd (shine_global_config *config );
|
||||
|
||||
#endif
|
|
@ -0,0 +1,126 @@
|
|||
/* tables.c
|
||||
*
|
||||
* Here are MPEG1 Table B.8 and MPEG2 Table B.1 -- Layer III scalefactor bands.
|
||||
* Index into this using a method such as:
|
||||
* idx = fr_ps->header->sampling_frequency + (fr_ps->header->version * 3)
|
||||
*/
|
||||
|
||||
#include "tables.h"
|
||||
|
||||
const int shine_slen1_tab[16] = { 0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 };
|
||||
const int shine_slen2_tab[16] = { 0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3 };
|
||||
|
||||
/* Valid samplerates and bitrates. */
|
||||
const int samplerates[9] = {
|
||||
44100, 48000, 32000, /* MPEG-I */
|
||||
22050, 24000, 16000, /* MPEG-II */
|
||||
11025, 12000, 8000 /* MPEG-2.5 */
|
||||
};
|
||||
|
||||
const int bitrates[16][4] = {
|
||||
/* MPEG version:
|
||||
* 2.5, reserved, II, I */
|
||||
{ -1, -1, -1, -1},
|
||||
{ 8, -1, 8, 32},
|
||||
{ 16, -1, 16, 40},
|
||||
{ 24, -1, 24, 48},
|
||||
{ 32, -1, 32, 56},
|
||||
{ 40, -1, 40, 64},
|
||||
{ 48, -1, 48, 80},
|
||||
{ 56, -1, 56, 96},
|
||||
{ 64, -1, 64, 112},
|
||||
{ -1, -1, 80, 128},
|
||||
{ -1, -1, 96, 160},
|
||||
{ -1, -1, 112, 192},
|
||||
{ -1, -1, 128, 224},
|
||||
{ -1, -1, 144, 256},
|
||||
{ -1, -1, 160, 320},
|
||||
{ -1, -1, -1, -1}
|
||||
};
|
||||
|
||||
const int shine_scale_fact_band_index[9][23] =
|
||||
{
|
||||
/* MPEG-I */
|
||||
/* Table B.8.b: 44.1 kHz */
|
||||
{0,4,8,12,16,20,24,30,36,44,52,62,74,90,110,134,162,196,238,288,342,418,576},
|
||||
/* Table B.8.c: 48 kHz */
|
||||
{0,4,8,12,16,20,24,30,36,42,50,60,72,88,106,128,156,190,230,276,330,384,576},
|
||||
/* Table B.8.a: 32 kHz */
|
||||
{0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576},
|
||||
/* MPEG-II */
|
||||
/* Table B.2.b: 22.05 kHz */
|
||||
{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
|
||||
/* Table B.2.c: 24 kHz */
|
||||
{0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576},
|
||||
/* Table B.2.a: 16 kHz */
|
||||
{0,6,12,18,24,30,36,44,45,66,80,96,116,140,168,200,238,248,336,396,464,522,576},
|
||||
|
||||
/* MPEG-2.5 */
|
||||
/* 11.025 kHz */
|
||||
{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
|
||||
/* 12 kHz */
|
||||
{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
|
||||
/* MPEG-2.5 8 kHz */
|
||||
{0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576},
|
||||
};
|
||||
|
||||
/* note. 0.035781 is shine_enwindow maximum value */
|
||||
/* scale and convert to fixed point before storing */
|
||||
#define SHINE_EW(x) (int32_t)((double)(x) * 0x7fffffff)
|
||||
#define SHINE_EW2(a,b) SHINE_EW(a), SHINE_EW(b)
|
||||
#define SHINE_EW10(a,b,c,d,e,f,g,h,i,j) SHINE_EW2(a,b), SHINE_EW2(c,d), SHINE_EW2(e,f), SHINE_EW2(g,h), SHINE_EW2(i,j)
|
||||
|
||||
const int32_t shine_enwindow[] = {
|
||||
SHINE_EW10( 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, -0.000000, -0.000000, -0.000001, -0.000001, -0.000001),
|
||||
SHINE_EW10( -0.000001, -0.000001, -0.000001, -0.000002, -0.000002, -0.000002, -0.000002, -0.000003, -0.000003, -0.000003),
|
||||
SHINE_EW10( -0.000004, -0.000004, -0.000005, -0.000005, -0.000006, -0.000007, -0.000008, -0.000008, -0.000009, -0.000010),
|
||||
SHINE_EW10( -0.000011, -0.000012, -0.000014, -0.000015, -0.000017, -0.000018, -0.000020, -0.000021, -0.000023, -0.000025),
|
||||
SHINE_EW10( -0.000028, -0.000030, -0.000032, -0.000035, -0.000038, -0.000041, -0.000043, -0.000046, -0.000050, -0.000053),
|
||||
SHINE_EW10( -0.000056, -0.000060, -0.000063, -0.000066, -0.000070, -0.000073, -0.000077, -0.000081, -0.000084, -0.000087),
|
||||
SHINE_EW10( -0.000091, -0.000093, -0.000096, -0.000099, 0.000102, 0.000104, 0.000106, 0.000107, 0.000108, 0.000109),
|
||||
SHINE_EW10( 0.000109, 0.000108, 0.000107, 0.000105, 0.000103, 0.000099, 0.000095, 0.000090, 0.000084, 0.000078),
|
||||
SHINE_EW10( 0.000070, 0.000061, 0.000051, 0.000040, 0.000027, 0.000014, -0.000001, -0.000017, -0.000034, -0.000053),
|
||||
SHINE_EW10( -0.000073, -0.000094, -0.000116, -0.000140, -0.000165, -0.000191, -0.000219, -0.000247, -0.000277, -0.000308),
|
||||
SHINE_EW10( -0.000339, -0.000371, -0.000404, -0.000438, -0.000473, -0.000507, -0.000542, -0.000577, -0.000612, -0.000647),
|
||||
SHINE_EW10( -0.000681, -0.000714, -0.000747, -0.000779, -0.000810, -0.000839, -0.000866, -0.000892, -0.000915, -0.000936),
|
||||
SHINE_EW10( -0.000954, -0.000969, -0.000981, -0.000989, -0.000994, -0.000995, -0.000992, -0.000984, 0.000971, 0.000954),
|
||||
SHINE_EW10( 0.000931, 0.000903, 0.000869, 0.000829, 0.000784, 0.000732, 0.000674, 0.000610, 0.000539, 0.000463),
|
||||
SHINE_EW10( 0.000379, 0.000288, 0.000192, 0.000088, -0.000021, -0.000137, -0.000260, -0.000388, -0.000522, -0.000662),
|
||||
SHINE_EW10( -0.000807, -0.000957, -0.001111, -0.001270, -0.001432, -0.001598, -0.001767, -0.001937, -0.002110, -0.002283),
|
||||
SHINE_EW10( -0.002457, -0.002631, -0.002803, -0.002974, -0.003142, -0.003307, -0.003467, -0.003623, -0.003772, -0.003914),
|
||||
SHINE_EW10( -0.004049, -0.004175, -0.004291, -0.004396, -0.004490, -0.004570, -0.004638, -0.004691, -0.004728, -0.004749),
|
||||
SHINE_EW10( -0.004752, -0.004737, -0.004703, -0.004649, -0.004574, -0.004477, -0.004358, -0.004215, -0.004049, -0.003859),
|
||||
SHINE_EW10( -0.003643, -0.003402, 0.003135, 0.002841, 0.002522, 0.002175, 0.001801, 0.001400, 0.000971, 0.000516),
|
||||
SHINE_EW10( 0.000033, -0.000476, -0.001012, -0.001574, -0.002162, -0.002774, -0.003411, -0.004072, -0.004756, -0.005462),
|
||||
SHINE_EW10( -0.006189, -0.006937, -0.007703, -0.008487, -0.009288, -0.010104, -0.010933, -0.011775, -0.012628, -0.013489),
|
||||
SHINE_EW10( -0.014359, -0.015234, -0.016113, -0.016994, -0.017876, -0.018757, -0.019634, -0.020507, -0.021372, -0.022229),
|
||||
SHINE_EW10( -0.023074, -0.023907, -0.024725, -0.025527, -0.026311, -0.027074, -0.027815, -0.028533, -0.029225, -0.029890),
|
||||
SHINE_EW10( -0.030527, -0.031133, -0.031707, -0.032248, -0.032755, -0.033226, -0.033660, -0.034056, -0.034413, -0.034730),
|
||||
SHINE_EW10( -0.035007, -0.035242, -0.035435, -0.035586, -0.035694, -0.035759, 0.035781, 0.035759, 0.035694, 0.035586),
|
||||
SHINE_EW10( 0.035435, 0.035242, 0.035007, 0.034730, 0.034413, 0.034056, 0.033660, 0.033226, 0.032755, 0.032248),
|
||||
SHINE_EW10( 0.031707, 0.031133, 0.030527, 0.029890, 0.029225, 0.028533, 0.027815, 0.027074, 0.026311, 0.025527),
|
||||
SHINE_EW10( 0.024725, 0.023907, 0.023074, 0.022229, 0.021372, 0.020507, 0.019634, 0.018757, 0.017876, 0.016994),
|
||||
SHINE_EW10( 0.016113, 0.015234, 0.014359, 0.013489, 0.012628, 0.011775, 0.010933, 0.010104, 0.009288, 0.008487),
|
||||
SHINE_EW10( 0.007703, 0.006937, 0.006189, 0.005462, 0.004756, 0.004072, 0.003411, 0.002774, 0.002162, 0.001574),
|
||||
SHINE_EW10( 0.001012, 0.000476, -0.000033, -0.000516, -0.000971, -0.001400, -0.001801, -0.002175, -0.002522, -0.002841),
|
||||
SHINE_EW10( 0.003135, 0.003402, 0.003643, 0.003859, 0.004049, 0.004215, 0.004358, 0.004477, 0.004574, 0.004649),
|
||||
SHINE_EW10( 0.004703, 0.004737, 0.004752, 0.004749, 0.004728, 0.004691, 0.004638, 0.004570, 0.004490, 0.004396),
|
||||
SHINE_EW10( 0.004291, 0.004175, 0.004049, 0.003914, 0.003772, 0.003623, 0.003467, 0.003307, 0.003142, 0.002974),
|
||||
SHINE_EW10( 0.002803, 0.002631, 0.002457, 0.002283, 0.002110, 0.001937, 0.001767, 0.001598, 0.001432, 0.001270),
|
||||
SHINE_EW10( 0.001111, 0.000957, 0.000807, 0.000662, 0.000522, 0.000388, 0.000260, 0.000137, 0.000021, -0.000088),
|
||||
SHINE_EW10( -0.000192, -0.000288, -0.000379, -0.000463, -0.000539, -0.000610, -0.000674, -0.000732, -0.000784, -0.000829),
|
||||
SHINE_EW10( -0.000869, -0.000903, -0.000931, -0.000954, 0.000971, 0.000984, 0.000992, 0.000995, 0.000994, 0.000989),
|
||||
SHINE_EW10( 0.000981, 0.000969, 0.000954, 0.000936, 0.000915, 0.000892, 0.000866, 0.000839, 0.000810, 0.000779),
|
||||
SHINE_EW10( 0.000747, 0.000714, 0.000681, 0.000647, 0.000612, 0.000577, 0.000542, 0.000507, 0.000473, 0.000438),
|
||||
SHINE_EW10( 0.000404, 0.000371, 0.000339, 0.000308, 0.000277, 0.000247, 0.000219, 0.000191, 0.000165, 0.000140),
|
||||
SHINE_EW10( 0.000116, 0.000094, 0.000073, 0.000053, 0.000034, 0.000017, 0.000001, -0.000014, -0.000027, -0.000040),
|
||||
SHINE_EW10( -0.000051, -0.000061, -0.000070, -0.000078, -0.000084, -0.000090, -0.000095, -0.000099, -0.000103, -0.000105),
|
||||
SHINE_EW10( -0.000107, -0.000108, -0.000109, -0.000109, -0.000108, -0.000107, -0.000106, -0.000104, 0.000102, 0.000099),
|
||||
SHINE_EW10( 0.000096, 0.000093, 0.000091, 0.000087, 0.000084, 0.000081, 0.000077, 0.000073, 0.000070, 0.000066),
|
||||
SHINE_EW10( 0.000063, 0.000060, 0.000056, 0.000053, 0.000050, 0.000046, 0.000043, 0.000041, 0.000038, 0.000035),
|
||||
SHINE_EW10( 0.000032, 0.000030, 0.000028, 0.000025, 0.000023, 0.000021, 0.000020, 0.000018, 0.000017, 0.000015),
|
||||
SHINE_EW10( 0.000014, 0.000012, 0.000011, 0.000010, 0.000009, 0.000008, 0.000008, 0.000007, 0.000006, 0.000005),
|
||||
SHINE_EW10( 0.000005, 0.000004, 0.000004, 0.000003, 0.000003, 0.000003, 0.000002, 0.000002, 0.000002, 0.000002),
|
||||
SHINE_EW10( 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000000, 0.000000, 0.000000, 0.000000),
|
||||
SHINE_EW2 ( 0.000000, 0.000000)
|
||||
};
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef TABLES_H
|
||||
#define TABLES_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
extern const int shine_slen1_tab[16];
|
||||
extern const int shine_slen2_tab[16];
|
||||
|
||||
extern const int samplerates[9];
|
||||
extern const int bitrates[16][4];
|
||||
|
||||
extern const int shine_scale_fact_band_index[9][23];
|
||||
extern const int32_t shine_enwindow[];
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
#ifndef PRIV_TYPES_H
|
||||
#define PRIV_TYPES_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define GRANULE_SIZE 576
|
||||
|
||||
#include "bitstream.h"
|
||||
|
||||
/* Include arch-specific instructions,
|
||||
* when defined. */
|
||||
#if defined(__mips__) && (__mips == 32)
|
||||
#include "mult_mips_gcc.h"
|
||||
#elif defined(__arm__) && !defined(__thumb__)
|
||||
#include "mult_sarm_gcc.h"
|
||||
#endif
|
||||
|
||||
/* Include and define generic instructions,
|
||||
* when not already defined above. */
|
||||
#include "mult_noarch_gcc.h"
|
||||
|
||||
#ifndef SWAB32
|
||||
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
|
||||
#define SWAB32(x) __builtin_bswap32(x)
|
||||
#else
|
||||
#define SWAB32(x) (((unsigned int)(x) >> 24) | (((unsigned int)(x) >> 8) & 0xff00) | (((unsigned int)(x) & 0xff00) << 8) | ((unsigned int)(x) << 24))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* #define SHINE_DEBUG if you want the library to dump info to stdout */
|
||||
|
||||
#undef PI
|
||||
#define PI 3.14159265358979
|
||||
#define PI4 0.78539816339745
|
||||
#define PI12 0.26179938779915
|
||||
#define PI36 0.087266462599717
|
||||
#define PI64 0.049087385212
|
||||
#define SQRT2 1.41421356237
|
||||
#define LN2 0.69314718
|
||||
#define LN_TO_LOG10 0.2302585093
|
||||
#define BLKSIZE 1024
|
||||
#define HAN_SIZE 512 /* for loop unrolling, require that HAN_SIZE%8==0 */
|
||||
#define SCALE_BLOCK 12
|
||||
#define SCALE_RANGE 64
|
||||
#define SCALE 32768
|
||||
#define SBLIMIT 32
|
||||
|
||||
#ifndef MAX_CHANNELS
|
||||
#define MAX_CHANNELS 2
|
||||
#endif
|
||||
|
||||
#ifndef MAX_GRANULES
|
||||
#define MAX_GRANULES 2
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int16_t channels;
|
||||
int samplerate;
|
||||
} priv_shine_wave_t;
|
||||
|
||||
typedef struct {
|
||||
int version;
|
||||
int layer;
|
||||
int granules_per_frame;
|
||||
int mode; /* + */ /* Stereo mode */
|
||||
int bitr; /* + */ /* Must conform to known bitrate - see Main.c */
|
||||
int emph; /* + */ /* De-emphasis */
|
||||
int padding;
|
||||
int bits_per_frame;
|
||||
int bits_per_slot;
|
||||
double frac_slots_per_frame;
|
||||
double slot_lag;
|
||||
int whole_slots_per_frame;
|
||||
int bitrate_index; /* + */ /* See Main.c and Layer3.c */
|
||||
int samplerate_index; /* + */ /* See Main.c and Layer3.c */
|
||||
int crc;
|
||||
int ext;
|
||||
int mode_ext;
|
||||
int copyright; /* + */
|
||||
int original; /* + */
|
||||
} priv_shine_mpeg_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t *xr; /* magnitudes of the spectral values */
|
||||
int32_t *xrsq; /* xr squared */
|
||||
int32_t *xrabs; /* xr absolute */
|
||||
int32_t xrmax; /* maximum of xrabs array */
|
||||
int32_t en_tot[MAX_GRANULES]; /* gr */
|
||||
int32_t en[MAX_GRANULES][21];
|
||||
int32_t xm[MAX_GRANULES][21];
|
||||
int32_t xrmaxl[MAX_GRANULES];
|
||||
double steptab[128]; /* 2**(-x/4) for x = -127..0 */
|
||||
int32_t steptabi[128]; /* 2**(-x/4) for x = -127..0 */
|
||||
int16_t int2idx[10000]; /* x**(3/4) for x = 0..9999 */
|
||||
} l3loop_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t cos_l[18][36];
|
||||
} mdct_t;
|
||||
|
||||
typedef struct {
|
||||
int off[MAX_CHANNELS];
|
||||
int32_t fl[SBLIMIT][64];
|
||||
int32_t x[MAX_CHANNELS][HAN_SIZE];
|
||||
} subband_t;
|
||||
|
||||
/* Side information */
|
||||
typedef struct {
|
||||
unsigned part2_3_length;
|
||||
unsigned big_values;
|
||||
unsigned count1;
|
||||
unsigned global_gain;
|
||||
unsigned scalefac_compress;
|
||||
unsigned table_select[3];
|
||||
unsigned region0_count;
|
||||
unsigned region1_count;
|
||||
unsigned preflag;
|
||||
unsigned scalefac_scale;
|
||||
unsigned count1table_select;
|
||||
unsigned part2_length;
|
||||
unsigned sfb_lmax;
|
||||
unsigned address1;
|
||||
unsigned address2;
|
||||
unsigned address3;
|
||||
int quantizerStepSize;
|
||||
unsigned slen[4];
|
||||
} gr_info;
|
||||
|
||||
typedef struct {
|
||||
unsigned private_bits;
|
||||
int resvDrain;
|
||||
unsigned scfsi[MAX_CHANNELS][4];
|
||||
struct {
|
||||
struct {
|
||||
gr_info tt;
|
||||
} ch[MAX_CHANNELS];
|
||||
} gr[MAX_GRANULES];
|
||||
} shine_side_info_t;
|
||||
|
||||
typedef struct {
|
||||
float l[MAX_GRANULES][MAX_CHANNELS][21];
|
||||
} shine_psy_ratio_t;
|
||||
|
||||
typedef struct {
|
||||
double l[MAX_GRANULES][MAX_CHANNELS][21];
|
||||
} shine_psy_xmin_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t l[MAX_GRANULES][MAX_CHANNELS][22]; /* [cb] */
|
||||
int32_t s[MAX_GRANULES][MAX_CHANNELS][13][3]; /* [window][cb] */
|
||||
} shine_scalefac_t;
|
||||
|
||||
|
||||
typedef struct shine_global_flags {
|
||||
priv_shine_wave_t wave;
|
||||
priv_shine_mpeg_t mpeg;
|
||||
bitstream_t bs;
|
||||
shine_side_info_t side_info;
|
||||
int sideinfo_len;
|
||||
int mean_bits;
|
||||
//shine_psy_ratio_t ratio;
|
||||
shine_scalefac_t scalefactor;
|
||||
int16_t *buffer[MAX_CHANNELS];
|
||||
double pe[MAX_CHANNELS][MAX_GRANULES];
|
||||
int *l3_enc[MAX_CHANNELS][MAX_GRANULES]; //4% reduction in performance IRAM
|
||||
int32_t l3_sb_sample[MAX_CHANNELS][MAX_GRANULES+1][18][SBLIMIT];
|
||||
int32_t *mdct_freq[MAX_CHANNELS][MAX_GRANULES]; //1% reduction in perormance IRAM
|
||||
int ResvSize;
|
||||
int ResvMax;
|
||||
l3loop_t *l3loop;
|
||||
mdct_t mdct;
|
||||
subband_t subband;
|
||||
} shine_global_config;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue