Fixed FFMPEG by replacing it with a proper build, should be faster now, too.
This commit is contained in:
parent
6c25858e66
commit
8308f30d5f
519 changed files with 7400 additions and 169771 deletions
Binary file not shown.
File diff suppressed because it is too large
Load diff
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:WMA.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
|
@ -1,7 +0,0 @@
|
|||
//
|
||||
// Prefix header for all source files of the 'FFMPEG' target in the 'FFMPEG' project.
|
||||
//
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#endif
|
|
@ -1,26 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
Binary file not shown.
|
@ -1,504 +0,0 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 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 Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
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 Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
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 and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
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 other code 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.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
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, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser 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 combine 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) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) 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.
|
||||
|
||||
d) 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.
|
||||
|
||||
e) 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 materials to be 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 with
|
||||
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 Lesser 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 Lesser 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
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!
|
||||
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
This file contains the name of the people who have contributed to
|
||||
ffmpeg. The names are sorted alphabetically.
|
||||
|
||||
Fabrice Bellard
|
||||
BERO
|
||||
Mario Brito
|
||||
Alex Beregszaszi
|
||||
Tim Ferguson
|
||||
Brian Foley
|
||||
Arpad Gereoffy
|
||||
Philip Gladstone
|
||||
Vladimir Gneushev
|
||||
Falk Hueffner
|
||||
Zdenek Kabelac
|
||||
Robin Kay
|
||||
Nick Kurshev
|
||||
Mike Melanson
|
||||
Michael Niedermayer
|
||||
François Revol
|
||||
Dieter Shirley
|
||||
Juan J. Sierralta
|
||||
Ewald Snel
|
||||
Roberto Togni
|
||||
Lionel Ulmer
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* MSVC Compatible va_copy macro
|
||||
* Copyright (c) 2012 Derek Buitenhuis
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#if !defined(va_copy) && defined(_MSC_VER)
|
||||
#define va_copy(dst, src) ((dst) = (src))
|
||||
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -1,334 +0,0 @@
|
|||
/*
|
||||
* AAC definitions and structures
|
||||
* Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
|
||||
* Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* AAC definitions and structures
|
||||
* @author Oded Shimon ( ods15 ods15 dyndns org )
|
||||
* @author Maxim Gavrilov ( maxim.gavrilov gmail com )
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AAC_H
|
||||
#define AVCODEC_AAC_H
|
||||
|
||||
#include "libavutil/float_dsp.h"
|
||||
#include "avcodec.h"
|
||||
#include "fft.h"
|
||||
#include "mpeg4audio.h"
|
||||
#include "sbr.h"
|
||||
#include "fmtconvert.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define MAX_CHANNELS 64
|
||||
#define MAX_ELEM_ID 16
|
||||
|
||||
#define TNS_MAX_ORDER 20
|
||||
#define MAX_LTP_LONG_SFB 40
|
||||
|
||||
enum RawDataBlockType {
|
||||
TYPE_SCE,
|
||||
TYPE_CPE,
|
||||
TYPE_CCE,
|
||||
TYPE_LFE,
|
||||
TYPE_DSE,
|
||||
TYPE_PCE,
|
||||
TYPE_FIL,
|
||||
TYPE_END,
|
||||
};
|
||||
|
||||
enum ExtensionPayloadID {
|
||||
EXT_FILL,
|
||||
EXT_FILL_DATA,
|
||||
EXT_DATA_ELEMENT,
|
||||
EXT_DYNAMIC_RANGE = 0xb,
|
||||
EXT_SBR_DATA = 0xd,
|
||||
EXT_SBR_DATA_CRC = 0xe,
|
||||
};
|
||||
|
||||
enum WindowSequence {
|
||||
ONLY_LONG_SEQUENCE,
|
||||
LONG_START_SEQUENCE,
|
||||
EIGHT_SHORT_SEQUENCE,
|
||||
LONG_STOP_SEQUENCE,
|
||||
};
|
||||
|
||||
enum BandType {
|
||||
ZERO_BT = 0, ///< Scalefactors and spectral data are all zero.
|
||||
FIRST_PAIR_BT = 5, ///< This and later band types encode two values (rather than four) with one code word.
|
||||
ESC_BT = 11, ///< Spectral data are coded with an escape sequence.
|
||||
NOISE_BT = 13, ///< Spectral data are scaled white noise not coded in the bitstream.
|
||||
INTENSITY_BT2 = 14, ///< Scalefactor data are intensity stereo positions.
|
||||
INTENSITY_BT = 15, ///< Scalefactor data are intensity stereo positions.
|
||||
};
|
||||
|
||||
#define IS_CODEBOOK_UNSIGNED(x) ((x - 1) & 10)
|
||||
|
||||
enum ChannelPosition {
|
||||
AAC_CHANNEL_OFF = 0,
|
||||
AAC_CHANNEL_FRONT = 1,
|
||||
AAC_CHANNEL_SIDE = 2,
|
||||
AAC_CHANNEL_BACK = 3,
|
||||
AAC_CHANNEL_LFE = 4,
|
||||
AAC_CHANNEL_CC = 5,
|
||||
};
|
||||
|
||||
/**
|
||||
* The point during decoding at which channel coupling is applied.
|
||||
*/
|
||||
enum CouplingPoint {
|
||||
BEFORE_TNS,
|
||||
BETWEEN_TNS_AND_IMDCT,
|
||||
AFTER_IMDCT = 3,
|
||||
};
|
||||
|
||||
/**
|
||||
* Output configuration status
|
||||
*/
|
||||
enum OCStatus {
|
||||
OC_NONE, ///< Output unconfigured
|
||||
OC_TRIAL_PCE, ///< Output configuration under trial specified by an inband PCE
|
||||
OC_TRIAL_FRAME, ///< Output configuration under trial specified by a frame header
|
||||
OC_GLOBAL_HDR, ///< Output configuration set in a global header but not yet locked
|
||||
OC_LOCKED, ///< Output configuration locked in place
|
||||
};
|
||||
|
||||
typedef struct OutputConfiguration {
|
||||
MPEG4AudioConfig m4ac;
|
||||
uint8_t layout_map[MAX_ELEM_ID*4][3];
|
||||
int layout_map_tags;
|
||||
int channels;
|
||||
uint64_t channel_layout;
|
||||
enum OCStatus status;
|
||||
} OutputConfiguration;
|
||||
|
||||
/**
|
||||
* Predictor State
|
||||
*/
|
||||
typedef struct PredictorState {
|
||||
float cor0;
|
||||
float cor1;
|
||||
float var0;
|
||||
float var1;
|
||||
float r0;
|
||||
float r1;
|
||||
} PredictorState;
|
||||
|
||||
#define MAX_PREDICTORS 672
|
||||
|
||||
#define SCALE_DIV_512 36 ///< scalefactor difference that corresponds to scale difference in 512 times
|
||||
#define SCALE_ONE_POS 140 ///< scalefactor index that corresponds to scale=1.0
|
||||
#define SCALE_MAX_POS 255 ///< scalefactor index maximum value
|
||||
#define SCALE_MAX_DIFF 60 ///< maximum scalefactor difference allowed by standard
|
||||
#define SCALE_DIFF_ZERO 60 ///< codebook index corresponding to zero scalefactor indices difference
|
||||
|
||||
/**
|
||||
* Long Term Prediction
|
||||
*/
|
||||
typedef struct LongTermPrediction {
|
||||
int8_t present;
|
||||
int16_t lag;
|
||||
float coef;
|
||||
int8_t used[MAX_LTP_LONG_SFB];
|
||||
} LongTermPrediction;
|
||||
|
||||
/**
|
||||
* Individual Channel Stream
|
||||
*/
|
||||
typedef struct IndividualChannelStream {
|
||||
uint8_t max_sfb; ///< number of scalefactor bands per group
|
||||
enum WindowSequence window_sequence[2];
|
||||
uint8_t use_kb_window[2]; ///< If set, use Kaiser-Bessel window, otherwise use a sine window.
|
||||
int num_window_groups;
|
||||
uint8_t group_len[8];
|
||||
LongTermPrediction ltp;
|
||||
const uint16_t *swb_offset; ///< table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular window
|
||||
const uint8_t *swb_sizes; ///< table of scalefactor band sizes for a particular window
|
||||
int num_swb; ///< number of scalefactor window bands
|
||||
int num_windows;
|
||||
int tns_max_bands;
|
||||
int predictor_present;
|
||||
int predictor_initialized;
|
||||
int predictor_reset_group;
|
||||
uint8_t prediction_used[41];
|
||||
} IndividualChannelStream;
|
||||
|
||||
/**
|
||||
* Temporal Noise Shaping
|
||||
*/
|
||||
typedef struct TemporalNoiseShaping {
|
||||
int present;
|
||||
int n_filt[8];
|
||||
int length[8][4];
|
||||
int direction[8][4];
|
||||
int order[8][4];
|
||||
float coef[8][4][TNS_MAX_ORDER];
|
||||
} TemporalNoiseShaping;
|
||||
|
||||
/**
|
||||
* Dynamic Range Control - decoded from the bitstream but not processed further.
|
||||
*/
|
||||
typedef struct DynamicRangeControl {
|
||||
int pce_instance_tag; ///< Indicates with which program the DRC info is associated.
|
||||
int dyn_rng_sgn[17]; ///< DRC sign information; 0 - positive, 1 - negative
|
||||
int dyn_rng_ctl[17]; ///< DRC magnitude information
|
||||
int exclude_mask[MAX_CHANNELS]; ///< Channels to be excluded from DRC processing.
|
||||
int band_incr; ///< Number of DRC bands greater than 1 having DRC info.
|
||||
int interpolation_scheme; ///< Indicates the interpolation scheme used in the SBR QMF domain.
|
||||
int band_top[17]; ///< Indicates the top of the i-th DRC band in units of 4 spectral lines.
|
||||
int prog_ref_level; /**< A reference level for the long-term program audio level for all
|
||||
* channels combined.
|
||||
*/
|
||||
} DynamicRangeControl;
|
||||
|
||||
typedef struct Pulse {
|
||||
int num_pulse;
|
||||
int start;
|
||||
int pos[4];
|
||||
int amp[4];
|
||||
} Pulse;
|
||||
|
||||
/**
|
||||
* coupling parameters
|
||||
*/
|
||||
typedef struct ChannelCoupling {
|
||||
enum CouplingPoint coupling_point; ///< The point during decoding at which coupling is applied.
|
||||
int num_coupled; ///< number of target elements
|
||||
enum RawDataBlockType type[8]; ///< Type of channel element to be coupled - SCE or CPE.
|
||||
int id_select[8]; ///< element id
|
||||
int ch_select[8]; /**< [0] shared list of gains; [1] list of gains for right channel;
|
||||
* [2] list of gains for left channel; [3] lists of gains for both channels
|
||||
*/
|
||||
float gain[16][120];
|
||||
} ChannelCoupling;
|
||||
|
||||
/**
|
||||
* Single Channel Element - used for both SCE and LFE elements.
|
||||
*/
|
||||
typedef struct SingleChannelElement {
|
||||
IndividualChannelStream ics;
|
||||
TemporalNoiseShaping tns;
|
||||
Pulse pulse;
|
||||
enum BandType band_type[128]; ///< band types
|
||||
int band_type_run_end[120]; ///< band type run end points
|
||||
float sf[120]; ///< scalefactors
|
||||
int sf_idx[128]; ///< scalefactor indices (used by encoder)
|
||||
uint8_t zeroes[128]; ///< band is not coded (used by encoder)
|
||||
DECLARE_ALIGNED(32, float, coeffs)[1024]; ///< coefficients for IMDCT
|
||||
DECLARE_ALIGNED(32, float, saved)[1536]; ///< overlap
|
||||
DECLARE_ALIGNED(32, float, ret_buf)[2048]; ///< PCM output buffer
|
||||
DECLARE_ALIGNED(16, float, ltp_state)[3072]; ///< time signal for LTP
|
||||
PredictorState predictor_state[MAX_PREDICTORS];
|
||||
float *ret; ///< PCM output
|
||||
} SingleChannelElement;
|
||||
|
||||
/**
|
||||
* channel element - generic struct for SCE/CPE/CCE/LFE
|
||||
*/
|
||||
typedef struct ChannelElement {
|
||||
// CPE specific
|
||||
int common_window; ///< Set if channels share a common 'IndividualChannelStream' in bitstream.
|
||||
int ms_mode; ///< Signals mid/side stereo flags coding mode (used by encoder)
|
||||
uint8_t ms_mask[128]; ///< Set if mid/side stereo is used for each scalefactor window band
|
||||
// shared
|
||||
SingleChannelElement ch[2];
|
||||
// CCE specific
|
||||
ChannelCoupling coup;
|
||||
SpectralBandReplication sbr;
|
||||
} ChannelElement;
|
||||
|
||||
/**
|
||||
* main AAC context
|
||||
*/
|
||||
struct AACContext {
|
||||
AVClass *class;
|
||||
AVCodecContext *avctx;
|
||||
AVFrame *frame;
|
||||
|
||||
int is_saved; ///< Set if elements have stored overlap from previous frame.
|
||||
DynamicRangeControl che_drc;
|
||||
|
||||
/**
|
||||
* @name Channel element related data
|
||||
* @{
|
||||
*/
|
||||
ChannelElement *che[4][MAX_ELEM_ID];
|
||||
ChannelElement *tag_che_map[4][MAX_ELEM_ID];
|
||||
int tags_mapped;
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name temporary aligned temporary buffers
|
||||
* (We do not want to have these on the stack.)
|
||||
* @{
|
||||
*/
|
||||
DECLARE_ALIGNED(32, float, buf_mdct)[1024];
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Computed / set up during initialization
|
||||
* @{
|
||||
*/
|
||||
FFTContext mdct;
|
||||
FFTContext mdct_small;
|
||||
FFTContext mdct_ld;
|
||||
FFTContext mdct_ltp;
|
||||
FmtConvertContext fmt_conv;
|
||||
AVFloatDSPContext fdsp;
|
||||
int random_state;
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Members used for output
|
||||
* @{
|
||||
*/
|
||||
SingleChannelElement *output_element[MAX_CHANNELS]; ///< Points to each SingleChannelElement
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @name Japanese DTV specific extension
|
||||
* @{
|
||||
*/
|
||||
int force_dmono_mode;///< 0->not dmono, 1->use first channel, 2->use second channel
|
||||
int dmono_mode; ///< 0->not dmono, 1->use first channel, 2->use second channel
|
||||
/** @} */
|
||||
|
||||
DECLARE_ALIGNED(32, float, temp)[128];
|
||||
|
||||
OutputConfiguration oc[2];
|
||||
int warned_num_aac_frames;
|
||||
|
||||
/* aacdec functions pointers */
|
||||
void (*imdct_and_windowing)(AACContext *ac, SingleChannelElement *sce);
|
||||
void (*apply_ltp)(AACContext *ac, SingleChannelElement *sce);
|
||||
void (*apply_tns)(float coef[1024], TemporalNoiseShaping *tns,
|
||||
IndividualChannelStream *ics, int decode);
|
||||
void (*windowing_and_mdct_ltp)(AACContext *ac, float *out,
|
||||
float *in, IndividualChannelStream *ics);
|
||||
void (*update_ltp)(AACContext *ac, SingleChannelElement *sce);
|
||||
|
||||
};
|
||||
|
||||
void ff_aacdec_init_mips(AACContext *c);
|
||||
|
||||
#endif /* AVCODEC_AAC_H */
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* Common AAC and AC-3 parser
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
* Copyright (c) 2003 Michael Niedermayer
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavutil/channel_layout.h"
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/internal.h"
|
||||
#include "parser.h"
|
||||
#include "aac_ac3_parser.h"
|
||||
|
||||
int ff_aac_ac3_parse(AVCodecParserContext *s1,
|
||||
AVCodecContext *avctx,
|
||||
const uint8_t **poutbuf, int *poutbuf_size,
|
||||
const uint8_t *buf, int buf_size)
|
||||
{
|
||||
AACAC3ParseContext *s = s1->priv_data;
|
||||
ParseContext *pc = &s->pc;
|
||||
int len, i;
|
||||
int new_frame_start;
|
||||
|
||||
get_next:
|
||||
i=END_NOT_FOUND;
|
||||
if(s->remaining_size <= buf_size){
|
||||
if(s->remaining_size && !s->need_next_header){
|
||||
i= s->remaining_size;
|
||||
s->remaining_size = 0;
|
||||
}else{ //we need a header first
|
||||
len=0;
|
||||
for(i=s->remaining_size; i<buf_size; i++){
|
||||
s->state = (s->state<<8) + buf[i];
|
||||
if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start)))
|
||||
break;
|
||||
}
|
||||
if(len<=0){
|
||||
i=END_NOT_FOUND;
|
||||
}else{
|
||||
s->state=0;
|
||||
i-= s->header_size -1;
|
||||
s->remaining_size = len;
|
||||
if(!new_frame_start || pc->index+i<=0){
|
||||
s->remaining_size += i;
|
||||
goto get_next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ff_combine_frame(pc, i, &buf, &buf_size)<0){
|
||||
s->remaining_size -= FFMIN(s->remaining_size, buf_size);
|
||||
*poutbuf = NULL;
|
||||
*poutbuf_size = 0;
|
||||
return buf_size;
|
||||
}
|
||||
|
||||
*poutbuf = buf;
|
||||
*poutbuf_size = buf_size;
|
||||
|
||||
/* update codec info */
|
||||
if(s->codec_id)
|
||||
avctx->codec_id = s->codec_id;
|
||||
|
||||
/* Due to backwards compatible HE-AAC the sample rate, channel count,
|
||||
and total number of samples found in an AAC ADTS header are not
|
||||
reliable. Bit rate is still accurate because the total frame duration in
|
||||
seconds is still correct (as is the number of bits in the frame). */
|
||||
if (avctx->codec_id != AV_CODEC_ID_AAC) {
|
||||
avctx->sample_rate = s->sample_rate;
|
||||
|
||||
/* (E-)AC-3: allow downmixing to stereo or mono */
|
||||
#if FF_API_REQUEST_CHANNELS
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
if (avctx->request_channels == 1)
|
||||
avctx->request_channel_layout = AV_CH_LAYOUT_MONO;
|
||||
else if (avctx->request_channels == 2)
|
||||
avctx->request_channel_layout = AV_CH_LAYOUT_STEREO;
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
#endif
|
||||
if (s->channels > 1 &&
|
||||
avctx->request_channel_layout == AV_CH_LAYOUT_MONO) {
|
||||
avctx->channels = 1;
|
||||
avctx->channel_layout = AV_CH_LAYOUT_MONO;
|
||||
} else if (s->channels > 2 &&
|
||||
avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
|
||||
avctx->channels = 2;
|
||||
avctx->channel_layout = AV_CH_LAYOUT_STEREO;
|
||||
} else {
|
||||
avctx->channels = s->channels;
|
||||
avctx->channel_layout = s->channel_layout;
|
||||
}
|
||||
s1->duration = s->samples;
|
||||
avctx->audio_service_type = s->service_type;
|
||||
}
|
||||
|
||||
avctx->bit_rate = s->bit_rate;
|
||||
|
||||
return i;
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Common AAC and AC-3 parser prototypes
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
* Copyright (c) 2003 Michael Niedermayer
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AAC_AC3_PARSER_H
|
||||
#define AVCODEC_AAC_AC3_PARSER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "avcodec.h"
|
||||
#include "parser.h"
|
||||
|
||||
typedef enum {
|
||||
AAC_AC3_PARSE_ERROR_SYNC = -0x1030c0a,
|
||||
AAC_AC3_PARSE_ERROR_BSID = -0x2030c0a,
|
||||
AAC_AC3_PARSE_ERROR_SAMPLE_RATE = -0x3030c0a,
|
||||
AAC_AC3_PARSE_ERROR_FRAME_SIZE = -0x4030c0a,
|
||||
AAC_AC3_PARSE_ERROR_FRAME_TYPE = -0x5030c0a,
|
||||
AAC_AC3_PARSE_ERROR_CRC = -0x6030c0a,
|
||||
AAC_AC3_PARSE_ERROR_CHANNEL_CFG = -0x7030c0a,
|
||||
} AACAC3ParseError;
|
||||
|
||||
typedef struct AACAC3ParseContext {
|
||||
ParseContext pc;
|
||||
int frame_size;
|
||||
int header_size;
|
||||
int (*sync)(uint64_t state, struct AACAC3ParseContext *hdr_info,
|
||||
int *need_next_header, int *new_frame_start);
|
||||
|
||||
int channels;
|
||||
int sample_rate;
|
||||
int bit_rate;
|
||||
int samples;
|
||||
uint64_t channel_layout;
|
||||
int service_type;
|
||||
|
||||
int remaining_size;
|
||||
uint64_t state;
|
||||
|
||||
int need_next_header;
|
||||
enum AVCodecID codec_id;
|
||||
} AACAC3ParseContext;
|
||||
|
||||
int ff_aac_ac3_parse(AVCodecParserContext *s1,
|
||||
AVCodecContext *avctx,
|
||||
const uint8_t **poutbuf, int *poutbuf_size,
|
||||
const uint8_t *buf, int buf_size);
|
||||
|
||||
#endif /* AVCODEC_AAC_AC3_PARSER_H */
|
|
@ -1,120 +0,0 @@
|
|||
/*
|
||||
* MPEG-2/4 AAC ADTS to MPEG-4 Audio Specific Configuration bitstream filter
|
||||
* Copyright (c) 2009 Alex Converse <alex.converse@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "avcodec.h"
|
||||
#include "aacadtsdec.h"
|
||||
#include "put_bits.h"
|
||||
#include "get_bits.h"
|
||||
#include "mpeg4audio.h"
|
||||
#include "internal.h"
|
||||
#include "libavutil/internal.h"
|
||||
|
||||
typedef struct AACBSFContext {
|
||||
int first_frame_done;
|
||||
} AACBSFContext;
|
||||
|
||||
/**
|
||||
* This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4
|
||||
* ADTS header and removes the ADTS header.
|
||||
*/
|
||||
static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc,
|
||||
AVCodecContext *avctx, const char *args,
|
||||
uint8_t **poutbuf, int *poutbuf_size,
|
||||
const uint8_t *buf, int buf_size,
|
||||
int keyframe)
|
||||
{
|
||||
GetBitContext gb;
|
||||
PutBitContext pb;
|
||||
AACADTSHeaderInfo hdr;
|
||||
|
||||
AACBSFContext *ctx = bsfc->priv_data;
|
||||
|
||||
init_get_bits(&gb, buf, AAC_ADTS_HEADER_SIZE*8);
|
||||
|
||||
*poutbuf = (uint8_t*) buf;
|
||||
*poutbuf_size = buf_size;
|
||||
|
||||
if (avctx->extradata)
|
||||
if (show_bits(&gb, 12) != 0xfff)
|
||||
return 0;
|
||||
|
||||
if (avpriv_aac_parse_header(&gb, &hdr) < 0) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Error parsing ADTS frame header!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!hdr.crc_absent && hdr.num_aac_frames > 1) {
|
||||
avpriv_report_missing_feature(avctx,
|
||||
"Multiple RDBs per frame with CRC");
|
||||
return AVERROR_PATCHWELCOME;
|
||||
}
|
||||
|
||||
buf += AAC_ADTS_HEADER_SIZE + 2*!hdr.crc_absent;
|
||||
buf_size -= AAC_ADTS_HEADER_SIZE + 2*!hdr.crc_absent;
|
||||
|
||||
if (!ctx->first_frame_done) {
|
||||
int pce_size = 0;
|
||||
uint8_t pce_data[MAX_PCE_SIZE];
|
||||
if (!hdr.chan_config) {
|
||||
init_get_bits(&gb, buf, buf_size * 8);
|
||||
if (get_bits(&gb, 3) != 5) {
|
||||
avpriv_report_missing_feature(avctx,
|
||||
"PCE-based channel configuration "
|
||||
"without PCE as first syntax "
|
||||
"element");
|
||||
return AVERROR_PATCHWELCOME;
|
||||
}
|
||||
init_put_bits(&pb, pce_data, MAX_PCE_SIZE);
|
||||
pce_size = avpriv_copy_pce_data(&pb, &gb)/8;
|
||||
flush_put_bits(&pb);
|
||||
buf_size -= get_bits_count(&gb)/8;
|
||||
buf += get_bits_count(&gb)/8;
|
||||
}
|
||||
av_free(avctx->extradata);
|
||||
avctx->extradata_size = 2 + pce_size;
|
||||
avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
|
||||
init_put_bits(&pb, avctx->extradata, avctx->extradata_size);
|
||||
put_bits(&pb, 5, hdr.object_type);
|
||||
put_bits(&pb, 4, hdr.sampling_index);
|
||||
put_bits(&pb, 4, hdr.chan_config);
|
||||
put_bits(&pb, 1, 0); //frame length - 1024 samples
|
||||
put_bits(&pb, 1, 0); //does not depend on core coder
|
||||
put_bits(&pb, 1, 0); //is not extension
|
||||
flush_put_bits(&pb);
|
||||
if (pce_size) {
|
||||
memcpy(avctx->extradata + 2, pce_data, pce_size);
|
||||
}
|
||||
|
||||
ctx->first_frame_done = 1;
|
||||
}
|
||||
|
||||
*poutbuf = (uint8_t*) buf;
|
||||
*poutbuf_size = buf_size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
AVBitStreamFilter ff_aac_adtstoasc_bsf = {
|
||||
.name = "aac_adtstoasc",
|
||||
.priv_data_size = sizeof(AACBSFContext),
|
||||
.filter = aac_adtstoasc_filter,
|
||||
};
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Audio and Video frame extraction
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
* Copyright (c) 2003 Michael Niedermayer
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "parser.h"
|
||||
#include "aac_ac3_parser.h"
|
||||
#include "aacadtsdec.h"
|
||||
#include "get_bits.h"
|
||||
#include "mpeg4audio.h"
|
||||
|
||||
static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info,
|
||||
int *need_next_header, int *new_frame_start)
|
||||
{
|
||||
GetBitContext bits;
|
||||
AACADTSHeaderInfo hdr;
|
||||
int size;
|
||||
union {
|
||||
uint64_t u64;
|
||||
uint8_t u8[8];
|
||||
} tmp;
|
||||
|
||||
tmp.u64 = av_be2ne64(state);
|
||||
init_get_bits(&bits, tmp.u8+8-AAC_ADTS_HEADER_SIZE, AAC_ADTS_HEADER_SIZE * 8);
|
||||
|
||||
if ((size = avpriv_aac_parse_header(&bits, &hdr)) < 0)
|
||||
return 0;
|
||||
*need_next_header = 0;
|
||||
*new_frame_start = 1;
|
||||
hdr_info->sample_rate = hdr.sample_rate;
|
||||
hdr_info->channels = ff_mpeg4audio_channels[hdr.chan_config];
|
||||
hdr_info->samples = hdr.samples;
|
||||
hdr_info->bit_rate = hdr.bit_rate;
|
||||
return size;
|
||||
}
|
||||
|
||||
static av_cold int aac_parse_init(AVCodecParserContext *s1)
|
||||
{
|
||||
AACAC3ParseContext *s = s1->priv_data;
|
||||
s->header_size = AAC_ADTS_HEADER_SIZE;
|
||||
s->sync = aac_sync;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
AVCodecParser ff_aac_parser = {
|
||||
.codec_ids = { AV_CODEC_ID_AAC },
|
||||
.priv_data_size = sizeof(AACAC3ParseContext),
|
||||
.parser_init = aac_parse_init,
|
||||
.parser_parse = ff_aac_ac3_parse,
|
||||
.parser_close = ff_parse_close,
|
||||
};
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Header file for hardcoded AAC tables
|
||||
*
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AAC_TABLEGEN_H
|
||||
#define AVCODEC_AAC_TABLEGEN_H
|
||||
|
||||
#include "aac_tablegen_decl.h"
|
||||
|
||||
#if CONFIG_HARDCODED_TABLES
|
||||
#include "libavcodec/aac_tables.h"
|
||||
#else
|
||||
#include "libavutil/mathematics.h"
|
||||
float ff_aac_pow2sf_tab[428];
|
||||
|
||||
void ff_aac_tableinit(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 428; i++)
|
||||
ff_aac_pow2sf_tab[i] = pow(2, (i - POW_SF2_ZERO) / 4.0);
|
||||
}
|
||||
#endif /* CONFIG_HARDCODED_TABLES */
|
||||
|
||||
#endif /* AVCODEC_AAC_TABLEGEN_H */
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Header file for hardcoded AAC tables
|
||||
*
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AAC_TABLEGEN_DECL_H
|
||||
#define AVCODEC_AAC_TABLEGEN_DECL_H
|
||||
|
||||
#define POW_SF2_ZERO 200 ///< ff_aac_pow2sf_tab index corresponding to pow(2, 0);
|
||||
|
||||
#if CONFIG_HARDCODED_TABLES
|
||||
#define ff_aac_tableinit()
|
||||
extern const float ff_aac_pow2sf_tab[428];
|
||||
#else
|
||||
void ff_aac_tableinit(void);
|
||||
extern float ff_aac_pow2sf_tab[428];
|
||||
#endif /* CONFIG_HARDCODED_TABLES */
|
||||
|
||||
#endif /* AVCODEC_AAC_TABLEGEN_DECL_H */
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Audio and Video frame extraction
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
* Copyright (c) 2003 Michael Niedermayer
|
||||
* Copyright (c) 2009 Alex Converse
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "aac_ac3_parser.h"
|
||||
#include "aacadtsdec.h"
|
||||
#include "get_bits.h"
|
||||
#include "mpeg4audio.h"
|
||||
|
||||
int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
|
||||
{
|
||||
int size, rdb, ch, sr;
|
||||
int aot, crc_abs;
|
||||
|
||||
if(get_bits(gbc, 12) != 0xfff)
|
||||
return AAC_AC3_PARSE_ERROR_SYNC;
|
||||
|
||||
skip_bits1(gbc); /* id */
|
||||
skip_bits(gbc, 2); /* layer */
|
||||
crc_abs = get_bits1(gbc); /* protection_absent */
|
||||
aot = get_bits(gbc, 2); /* profile_objecttype */
|
||||
sr = get_bits(gbc, 4); /* sample_frequency_index */
|
||||
if(!avpriv_mpeg4audio_sample_rates[sr])
|
||||
return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
|
||||
skip_bits1(gbc); /* private_bit */
|
||||
ch = get_bits(gbc, 3); /* channel_configuration */
|
||||
|
||||
skip_bits1(gbc); /* original/copy */
|
||||
skip_bits1(gbc); /* home */
|
||||
|
||||
/* adts_variable_header */
|
||||
skip_bits1(gbc); /* copyright_identification_bit */
|
||||
skip_bits1(gbc); /* copyright_identification_start */
|
||||
size = get_bits(gbc, 13); /* aac_frame_length */
|
||||
if(size < AAC_ADTS_HEADER_SIZE)
|
||||
return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
|
||||
|
||||
skip_bits(gbc, 11); /* adts_buffer_fullness */
|
||||
rdb = get_bits(gbc, 2); /* number_of_raw_data_blocks_in_frame */
|
||||
|
||||
hdr->object_type = aot + 1;
|
||||
hdr->chan_config = ch;
|
||||
hdr->crc_absent = crc_abs;
|
||||
hdr->num_aac_frames = rdb + 1;
|
||||
hdr->sampling_index = sr;
|
||||
hdr->sample_rate = avpriv_mpeg4audio_sample_rates[sr];
|
||||
hdr->samples = (rdb + 1) * 1024;
|
||||
hdr->bit_rate = size * 8 * hdr->sample_rate / hdr->samples;
|
||||
|
||||
return size;
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* AAC ADTS header decoding prototypes and structures
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
* Copyright (c) 2003 Michael Niedermayer
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AACADTSDEC_H
|
||||
#define AVCODEC_AACADTSDEC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "get_bits.h"
|
||||
|
||||
#define AAC_ADTS_HEADER_SIZE 7
|
||||
|
||||
typedef struct AACADTSHeaderInfo {
|
||||
uint32_t sample_rate;
|
||||
uint32_t samples;
|
||||
uint32_t bit_rate;
|
||||
uint8_t crc_absent;
|
||||
uint8_t object_type;
|
||||
uint8_t sampling_index;
|
||||
uint8_t chan_config;
|
||||
uint8_t num_aac_frames;
|
||||
} AACADTSHeaderInfo;
|
||||
|
||||
/**
|
||||
* Parse AAC frame header.
|
||||
* Parse the ADTS frame header to the end of the variable header, which is
|
||||
* the first 54 bits.
|
||||
* @param[in] gbc BitContext containing the first 54 bits of the frame.
|
||||
* @param[out] hdr Pointer to struct where header info is written.
|
||||
* @return Returns 0 on success, -1 if there is a sync word mismatch,
|
||||
* -2 if the version element is invalid, -3 if the sample rate
|
||||
* element is invalid, or -4 if the bit rate element is invalid.
|
||||
*/
|
||||
int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr);
|
||||
|
||||
#endif /* AVCODEC_AACADTSDEC_H */
|
File diff suppressed because it is too large
Load diff
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
* AAC decoder data
|
||||
* Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
|
||||
* Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* AAC decoder data
|
||||
* @author Oded Shimon ( ods15 ods15 dyndns org )
|
||||
* @author Maxim Gavrilov ( maxim.gavrilov gmail com )
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AACDECTAB_H
|
||||
#define AVCODEC_AACDECTAB_H
|
||||
|
||||
#include "libavutil/channel_layout.h"
|
||||
#include "aac.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* @name ltp_coef
|
||||
* Table of the LTP coefficients
|
||||
*/
|
||||
static const float ltp_coef[8] = {
|
||||
0.570829, 0.696616, 0.813004, 0.911304,
|
||||
0.984900, 1.067894, 1.194601, 1.369533,
|
||||
};
|
||||
|
||||
/* @name tns_tmp2_map
|
||||
* Tables of the tmp2[] arrays of LPC coefficients used for TNS.
|
||||
* The suffix _M_N[] indicate the values of coef_compress and coef_res
|
||||
* respectively.
|
||||
* @{
|
||||
*/
|
||||
static const float tns_tmp2_map_1_3[4] = {
|
||||
0.00000000, -0.43388373, 0.64278758, 0.34202015,
|
||||
};
|
||||
|
||||
static const float tns_tmp2_map_0_3[8] = {
|
||||
0.00000000, -0.43388373, -0.78183150, -0.97492790,
|
||||
0.98480773, 0.86602539, 0.64278758, 0.34202015,
|
||||
};
|
||||
|
||||
static const float tns_tmp2_map_1_4[8] = {
|
||||
0.00000000, -0.20791170, -0.40673664, -0.58778524,
|
||||
0.67369562, 0.52643216, 0.36124167, 0.18374951,
|
||||
};
|
||||
|
||||
static const float tns_tmp2_map_0_4[16] = {
|
||||
0.00000000, -0.20791170, -0.40673664, -0.58778524,
|
||||
-0.74314481, -0.86602539, -0.95105654, -0.99452192,
|
||||
0.99573416, 0.96182561, 0.89516330, 0.79801720,
|
||||
0.67369562, 0.52643216, 0.36124167, 0.18374951,
|
||||
};
|
||||
|
||||
static const float * const tns_tmp2_map[4] = {
|
||||
tns_tmp2_map_0_3,
|
||||
tns_tmp2_map_0_4,
|
||||
tns_tmp2_map_1_3,
|
||||
tns_tmp2_map_1_4
|
||||
};
|
||||
// @}
|
||||
|
||||
static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
static const uint8_t aac_channel_layout_map[7][5][3] = {
|
||||
{ { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, },
|
||||
{ { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, },
|
||||
{ { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, },
|
||||
{ { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 1, AAC_CHANNEL_BACK }, },
|
||||
{ { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, },
|
||||
{ { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, },
|
||||
{ { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_FRONT }, { TYPE_CPE, 2, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, },
|
||||
};
|
||||
|
||||
static const uint64_t aac_channel_layout[8] = {
|
||||
AV_CH_LAYOUT_MONO,
|
||||
AV_CH_LAYOUT_STEREO,
|
||||
AV_CH_LAYOUT_SURROUND,
|
||||
AV_CH_LAYOUT_4POINT0,
|
||||
AV_CH_LAYOUT_5POINT0_BACK,
|
||||
AV_CH_LAYOUT_5POINT1_BACK,
|
||||
AV_CH_LAYOUT_7POINT1_WIDE_BACK,
|
||||
0,
|
||||
};
|
||||
|
||||
#endif /* AVCODEC_AACDECTAB_H */
|
|
@ -1,975 +0,0 @@
|
|||
/*
|
||||
* MPEG-4 Parametric Stereo decoding functions
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/internal.h"
|
||||
#include "libavutil/mathematics.h"
|
||||
#include "libavutil/intmath.h"
|
||||
#include "avcodec.h"
|
||||
#include "get_bits.h"
|
||||
#include "aacps.h"
|
||||
#include "aacps_tablegen.h"
|
||||
#include "aacpsdata.c"
|
||||
|
||||
#define PS_BASELINE 0 ///< Operate in Baseline PS mode
|
||||
///< Baseline implies 10 or 20 stereo bands,
|
||||
///< mixing mode A, and no ipd/opd
|
||||
|
||||
#define numQMFSlots 32 //numTimeSlots * RATE
|
||||
|
||||
static const int8_t num_env_tab[2][4] = {
|
||||
{ 0, 1, 2, 4, },
|
||||
{ 1, 2, 3, 4, },
|
||||
};
|
||||
|
||||
static const int8_t nr_iidicc_par_tab[] = {
|
||||
10, 20, 34, 10, 20, 34,
|
||||
};
|
||||
|
||||
static const int8_t nr_iidopd_par_tab[] = {
|
||||
5, 11, 17, 5, 11, 17,
|
||||
};
|
||||
|
||||
enum {
|
||||
huff_iid_df1,
|
||||
huff_iid_dt1,
|
||||
huff_iid_df0,
|
||||
huff_iid_dt0,
|
||||
huff_icc_df,
|
||||
huff_icc_dt,
|
||||
huff_ipd_df,
|
||||
huff_ipd_dt,
|
||||
huff_opd_df,
|
||||
huff_opd_dt,
|
||||
};
|
||||
|
||||
static const int huff_iid[] = {
|
||||
huff_iid_df0,
|
||||
huff_iid_df1,
|
||||
huff_iid_dt0,
|
||||
huff_iid_dt1,
|
||||
};
|
||||
|
||||
static VLC vlc_ps[10];
|
||||
|
||||
#define READ_PAR_DATA(PAR, OFFSET, MASK, ERR_CONDITION) \
|
||||
/** \
|
||||
* Read Inter-channel Intensity Difference/Inter-Channel Coherence/ \
|
||||
* Inter-channel Phase Difference/Overall Phase Difference parameters from the \
|
||||
* bitstream. \
|
||||
* \
|
||||
* @param avctx contains the current codec context \
|
||||
* @param gb pointer to the input bitstream \
|
||||
* @param ps pointer to the Parametric Stereo context \
|
||||
* @param PAR pointer to the parameter to be read \
|
||||
* @param e envelope to decode \
|
||||
* @param dt 1: time delta-coded, 0: frequency delta-coded \
|
||||
*/ \
|
||||
static int read_ ## PAR ## _data(AVCodecContext *avctx, GetBitContext *gb, PSContext *ps, \
|
||||
int8_t (*PAR)[PS_MAX_NR_IIDICC], int table_idx, int e, int dt) \
|
||||
{ \
|
||||
int b, num = ps->nr_ ## PAR ## _par; \
|
||||
VLC_TYPE (*vlc_table)[2] = vlc_ps[table_idx].table; \
|
||||
if (dt) { \
|
||||
int e_prev = e ? e - 1 : ps->num_env_old - 1; \
|
||||
e_prev = FFMAX(e_prev, 0); \
|
||||
for (b = 0; b < num; b++) { \
|
||||
int val = PAR[e_prev][b] + get_vlc2(gb, vlc_table, 9, 3) - OFFSET; \
|
||||
if (MASK) val &= MASK; \
|
||||
PAR[e][b] = val; \
|
||||
if (ERR_CONDITION) \
|
||||
goto err; \
|
||||
} \
|
||||
} else { \
|
||||
int val = 0; \
|
||||
for (b = 0; b < num; b++) { \
|
||||
val += get_vlc2(gb, vlc_table, 9, 3) - OFFSET; \
|
||||
if (MASK) val &= MASK; \
|
||||
PAR[e][b] = val; \
|
||||
if (ERR_CONDITION) \
|
||||
goto err; \
|
||||
} \
|
||||
} \
|
||||
return 0; \
|
||||
err: \
|
||||
av_log(avctx, AV_LOG_ERROR, "illegal "#PAR"\n"); \
|
||||
return -1; \
|
||||
}
|
||||
|
||||
READ_PAR_DATA(iid, huff_offset[table_idx], 0, FFABS(ps->iid_par[e][b]) > 7 + 8 * ps->iid_quant)
|
||||
READ_PAR_DATA(icc, huff_offset[table_idx], 0, ps->icc_par[e][b] > 7U)
|
||||
READ_PAR_DATA(ipdopd, 0, 0x07, 0)
|
||||
|
||||
static int ps_read_extension_data(GetBitContext *gb, PSContext *ps, int ps_extension_id)
|
||||
{
|
||||
int e;
|
||||
int count = get_bits_count(gb);
|
||||
|
||||
if (ps_extension_id)
|
||||
return 0;
|
||||
|
||||
ps->enable_ipdopd = get_bits1(gb);
|
||||
if (ps->enable_ipdopd) {
|
||||
for (e = 0; e < ps->num_env; e++) {
|
||||
int dt = get_bits1(gb);
|
||||
read_ipdopd_data(NULL, gb, ps, ps->ipd_par, dt ? huff_ipd_dt : huff_ipd_df, e, dt);
|
||||
dt = get_bits1(gb);
|
||||
read_ipdopd_data(NULL, gb, ps, ps->opd_par, dt ? huff_opd_dt : huff_opd_df, e, dt);
|
||||
}
|
||||
}
|
||||
skip_bits1(gb); //reserved_ps
|
||||
return get_bits_count(gb) - count;
|
||||
}
|
||||
|
||||
static void ipdopd_reset(int8_t *ipd_hist, int8_t *opd_hist)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < PS_MAX_NR_IPDOPD; i++) {
|
||||
opd_hist[i] = 0;
|
||||
ipd_hist[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host, PSContext *ps, int bits_left)
|
||||
{
|
||||
int e;
|
||||
int bit_count_start = get_bits_count(gb_host);
|
||||
int header;
|
||||
int bits_consumed;
|
||||
GetBitContext gbc = *gb_host, *gb = &gbc;
|
||||
|
||||
header = get_bits1(gb);
|
||||
if (header) { //enable_ps_header
|
||||
ps->enable_iid = get_bits1(gb);
|
||||
if (ps->enable_iid) {
|
||||
int iid_mode = get_bits(gb, 3);
|
||||
if (iid_mode > 5) {
|
||||
av_log(avctx, AV_LOG_ERROR, "iid_mode %d is reserved.\n",
|
||||
iid_mode);
|
||||
goto err;
|
||||
}
|
||||
ps->nr_iid_par = nr_iidicc_par_tab[iid_mode];
|
||||
ps->iid_quant = iid_mode > 2;
|
||||
ps->nr_ipdopd_par = nr_iidopd_par_tab[iid_mode];
|
||||
}
|
||||
ps->enable_icc = get_bits1(gb);
|
||||
if (ps->enable_icc) {
|
||||
ps->icc_mode = get_bits(gb, 3);
|
||||
if (ps->icc_mode > 5) {
|
||||
av_log(avctx, AV_LOG_ERROR, "icc_mode %d is reserved.\n",
|
||||
ps->icc_mode);
|
||||
goto err;
|
||||
}
|
||||
ps->nr_icc_par = nr_iidicc_par_tab[ps->icc_mode];
|
||||
}
|
||||
ps->enable_ext = get_bits1(gb);
|
||||
}
|
||||
|
||||
ps->frame_class = get_bits1(gb);
|
||||
ps->num_env_old = ps->num_env;
|
||||
ps->num_env = num_env_tab[ps->frame_class][get_bits(gb, 2)];
|
||||
|
||||
ps->border_position[0] = -1;
|
||||
if (ps->frame_class) {
|
||||
for (e = 1; e <= ps->num_env; e++)
|
||||
ps->border_position[e] = get_bits(gb, 5);
|
||||
} else
|
||||
for (e = 1; e <= ps->num_env; e++)
|
||||
ps->border_position[e] = (e * numQMFSlots >> ff_log2_tab[ps->num_env]) - 1;
|
||||
|
||||
if (ps->enable_iid) {
|
||||
for (e = 0; e < ps->num_env; e++) {
|
||||
int dt = get_bits1(gb);
|
||||
if (read_iid_data(avctx, gb, ps, ps->iid_par, huff_iid[2*dt+ps->iid_quant], e, dt))
|
||||
goto err;
|
||||
}
|
||||
} else
|
||||
memset(ps->iid_par, 0, sizeof(ps->iid_par));
|
||||
|
||||
if (ps->enable_icc)
|
||||
for (e = 0; e < ps->num_env; e++) {
|
||||
int dt = get_bits1(gb);
|
||||
if (read_icc_data(avctx, gb, ps, ps->icc_par, dt ? huff_icc_dt : huff_icc_df, e, dt))
|
||||
goto err;
|
||||
}
|
||||
else
|
||||
memset(ps->icc_par, 0, sizeof(ps->icc_par));
|
||||
|
||||
if (ps->enable_ext) {
|
||||
int cnt = get_bits(gb, 4);
|
||||
if (cnt == 15) {
|
||||
cnt += get_bits(gb, 8);
|
||||
}
|
||||
cnt *= 8;
|
||||
while (cnt > 7) {
|
||||
int ps_extension_id = get_bits(gb, 2);
|
||||
cnt -= 2 + ps_read_extension_data(gb, ps, ps_extension_id);
|
||||
}
|
||||
if (cnt < 0) {
|
||||
av_log(avctx, AV_LOG_ERROR, "ps extension overflow %d\n", cnt);
|
||||
goto err;
|
||||
}
|
||||
skip_bits(gb, cnt);
|
||||
}
|
||||
|
||||
ps->enable_ipdopd &= !PS_BASELINE;
|
||||
|
||||
//Fix up envelopes
|
||||
if (!ps->num_env || ps->border_position[ps->num_env] < numQMFSlots - 1) {
|
||||
//Create a fake envelope
|
||||
int source = ps->num_env ? ps->num_env - 1 : ps->num_env_old - 1;
|
||||
int b;
|
||||
if (source >= 0 && source != ps->num_env) {
|
||||
if (ps->enable_iid) {
|
||||
memcpy(ps->iid_par+ps->num_env, ps->iid_par+source, sizeof(ps->iid_par[0]));
|
||||
}
|
||||
if (ps->enable_icc) {
|
||||
memcpy(ps->icc_par+ps->num_env, ps->icc_par+source, sizeof(ps->icc_par[0]));
|
||||
}
|
||||
if (ps->enable_ipdopd) {
|
||||
memcpy(ps->ipd_par+ps->num_env, ps->ipd_par+source, sizeof(ps->ipd_par[0]));
|
||||
memcpy(ps->opd_par+ps->num_env, ps->opd_par+source, sizeof(ps->opd_par[0]));
|
||||
}
|
||||
}
|
||||
if (ps->enable_iid){
|
||||
for (b = 0; b < ps->nr_iid_par; b++) {
|
||||
if (FFABS(ps->iid_par[ps->num_env][b]) > 7 + 8 * ps->iid_quant) {
|
||||
av_log(avctx, AV_LOG_ERROR, "iid_par invalid\n");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ps->enable_icc){
|
||||
for (b = 0; b < ps->nr_iid_par; b++) {
|
||||
if (ps->icc_par[ps->num_env][b] > 7U) {
|
||||
av_log(avctx, AV_LOG_ERROR, "icc_par invalid\n");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
}
|
||||
ps->num_env++;
|
||||
ps->border_position[ps->num_env] = numQMFSlots - 1;
|
||||
}
|
||||
|
||||
|
||||
ps->is34bands_old = ps->is34bands;
|
||||
if (!PS_BASELINE && (ps->enable_iid || ps->enable_icc))
|
||||
ps->is34bands = (ps->enable_iid && ps->nr_iid_par == 34) ||
|
||||
(ps->enable_icc && ps->nr_icc_par == 34);
|
||||
|
||||
//Baseline
|
||||
if (!ps->enable_ipdopd) {
|
||||
memset(ps->ipd_par, 0, sizeof(ps->ipd_par));
|
||||
memset(ps->opd_par, 0, sizeof(ps->opd_par));
|
||||
}
|
||||
|
||||
if (header)
|
||||
ps->start = 1;
|
||||
|
||||
bits_consumed = get_bits_count(gb) - bit_count_start;
|
||||
if (bits_consumed <= bits_left) {
|
||||
skip_bits_long(gb_host, bits_consumed);
|
||||
return bits_consumed;
|
||||
}
|
||||
av_log(avctx, AV_LOG_ERROR, "Expected to read %d PS bits actually read %d.\n", bits_left, bits_consumed);
|
||||
err:
|
||||
ps->start = 0;
|
||||
skip_bits_long(gb_host, bits_left);
|
||||
memset(ps->iid_par, 0, sizeof(ps->iid_par));
|
||||
memset(ps->icc_par, 0, sizeof(ps->icc_par));
|
||||
memset(ps->ipd_par, 0, sizeof(ps->ipd_par));
|
||||
memset(ps->opd_par, 0, sizeof(ps->opd_par));
|
||||
return bits_left;
|
||||
}
|
||||
|
||||
/** Split one subband into 2 subsubbands with a symmetric real filter.
|
||||
* The filter must have its non-center even coefficients equal to zero. */
|
||||
static void hybrid2_re(float (*in)[2], float (*out)[32][2], const float filter[8], int len, int reverse)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < len; i++, in++) {
|
||||
float re_in = filter[6] * in[6][0]; //real inphase
|
||||
float re_op = 0.0f; //real out of phase
|
||||
float im_in = filter[6] * in[6][1]; //imag inphase
|
||||
float im_op = 0.0f; //imag out of phase
|
||||
for (j = 0; j < 6; j += 2) {
|
||||
re_op += filter[j+1] * (in[j+1][0] + in[12-j-1][0]);
|
||||
im_op += filter[j+1] * (in[j+1][1] + in[12-j-1][1]);
|
||||
}
|
||||
out[ reverse][i][0] = re_in + re_op;
|
||||
out[ reverse][i][1] = im_in + im_op;
|
||||
out[!reverse][i][0] = re_in - re_op;
|
||||
out[!reverse][i][1] = im_in - im_op;
|
||||
}
|
||||
}
|
||||
|
||||
/** Split one subband into 6 subsubbands with a complex filter */
|
||||
static void hybrid6_cx(PSDSPContext *dsp, float (*in)[2], float (*out)[32][2],
|
||||
TABLE_CONST float (*filter)[8][2], int len)
|
||||
{
|
||||
int i;
|
||||
int N = 8;
|
||||
LOCAL_ALIGNED_16(float, temp, [8], [2]);
|
||||
|
||||
for (i = 0; i < len; i++, in++) {
|
||||
dsp->hybrid_analysis(temp, in, (const float (*)[8][2]) filter, 1, N);
|
||||
out[0][i][0] = temp[6][0];
|
||||
out[0][i][1] = temp[6][1];
|
||||
out[1][i][0] = temp[7][0];
|
||||
out[1][i][1] = temp[7][1];
|
||||
out[2][i][0] = temp[0][0];
|
||||
out[2][i][1] = temp[0][1];
|
||||
out[3][i][0] = temp[1][0];
|
||||
out[3][i][1] = temp[1][1];
|
||||
out[4][i][0] = temp[2][0] + temp[5][0];
|
||||
out[4][i][1] = temp[2][1] + temp[5][1];
|
||||
out[5][i][0] = temp[3][0] + temp[4][0];
|
||||
out[5][i][1] = temp[3][1] + temp[4][1];
|
||||
}
|
||||
}
|
||||
|
||||
static void hybrid4_8_12_cx(PSDSPContext *dsp,
|
||||
float (*in)[2], float (*out)[32][2],
|
||||
TABLE_CONST float (*filter)[8][2], int N, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++, in++) {
|
||||
dsp->hybrid_analysis(out[0] + i, in, (const float (*)[8][2]) filter, 32, N);
|
||||
}
|
||||
}
|
||||
|
||||
static void hybrid_analysis(PSDSPContext *dsp, float out[91][32][2],
|
||||
float in[5][44][2], float L[2][38][64],
|
||||
int is34, int len)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < 5; i++) {
|
||||
for (j = 0; j < 38; j++) {
|
||||
in[i][j+6][0] = L[0][j][i];
|
||||
in[i][j+6][1] = L[1][j][i];
|
||||
}
|
||||
}
|
||||
if (is34) {
|
||||
hybrid4_8_12_cx(dsp, in[0], out, f34_0_12, 12, len);
|
||||
hybrid4_8_12_cx(dsp, in[1], out+12, f34_1_8, 8, len);
|
||||
hybrid4_8_12_cx(dsp, in[2], out+20, f34_2_4, 4, len);
|
||||
hybrid4_8_12_cx(dsp, in[3], out+24, f34_2_4, 4, len);
|
||||
hybrid4_8_12_cx(dsp, in[4], out+28, f34_2_4, 4, len);
|
||||
dsp->hybrid_analysis_ileave(out + 27, L, 5, len);
|
||||
} else {
|
||||
hybrid6_cx(dsp, in[0], out, f20_0_8, len);
|
||||
hybrid2_re(in[1], out+6, g1_Q2, len, 1);
|
||||
hybrid2_re(in[2], out+8, g1_Q2, len, 0);
|
||||
dsp->hybrid_analysis_ileave(out + 7, L, 3, len);
|
||||
}
|
||||
//update in_buf
|
||||
for (i = 0; i < 5; i++) {
|
||||
memcpy(in[i], in[i]+32, 6 * sizeof(in[i][0]));
|
||||
}
|
||||
}
|
||||
|
||||
static void hybrid_synthesis(PSDSPContext *dsp, float out[2][38][64],
|
||||
float in[91][32][2], int is34, int len)
|
||||
{
|
||||
int i, n;
|
||||
if (is34) {
|
||||
for (n = 0; n < len; n++) {
|
||||
memset(out[0][n], 0, 5*sizeof(out[0][n][0]));
|
||||
memset(out[1][n], 0, 5*sizeof(out[1][n][0]));
|
||||
for (i = 0; i < 12; i++) {
|
||||
out[0][n][0] += in[ i][n][0];
|
||||
out[1][n][0] += in[ i][n][1];
|
||||
}
|
||||
for (i = 0; i < 8; i++) {
|
||||
out[0][n][1] += in[12+i][n][0];
|
||||
out[1][n][1] += in[12+i][n][1];
|
||||
}
|
||||
for (i = 0; i < 4; i++) {
|
||||
out[0][n][2] += in[20+i][n][0];
|
||||
out[1][n][2] += in[20+i][n][1];
|
||||
out[0][n][3] += in[24+i][n][0];
|
||||
out[1][n][3] += in[24+i][n][1];
|
||||
out[0][n][4] += in[28+i][n][0];
|
||||
out[1][n][4] += in[28+i][n][1];
|
||||
}
|
||||
}
|
||||
dsp->hybrid_synthesis_deint(out, in + 27, 5, len);
|
||||
} else {
|
||||
for (n = 0; n < len; n++) {
|
||||
out[0][n][0] = in[0][n][0] + in[1][n][0] + in[2][n][0] +
|
||||
in[3][n][0] + in[4][n][0] + in[5][n][0];
|
||||
out[1][n][0] = in[0][n][1] + in[1][n][1] + in[2][n][1] +
|
||||
in[3][n][1] + in[4][n][1] + in[5][n][1];
|
||||
out[0][n][1] = in[6][n][0] + in[7][n][0];
|
||||
out[1][n][1] = in[6][n][1] + in[7][n][1];
|
||||
out[0][n][2] = in[8][n][0] + in[9][n][0];
|
||||
out[1][n][2] = in[8][n][1] + in[9][n][1];
|
||||
}
|
||||
dsp->hybrid_synthesis_deint(out, in + 7, 3, len);
|
||||
}
|
||||
}
|
||||
|
||||
/// All-pass filter decay slope
|
||||
#define DECAY_SLOPE 0.05f
|
||||
/// Number of frequency bands that can be addressed by the parameter index, b(k)
|
||||
static const int NR_PAR_BANDS[] = { 20, 34 };
|
||||
static const int NR_IPDOPD_BANDS[] = { 11, 17 };
|
||||
/// Number of frequency bands that can be addressed by the sub subband index, k
|
||||
static const int NR_BANDS[] = { 71, 91 };
|
||||
/// Start frequency band for the all-pass filter decay slope
|
||||
static const int DECAY_CUTOFF[] = { 10, 32 };
|
||||
/// Number of all-pass filer bands
|
||||
static const int NR_ALLPASS_BANDS[] = { 30, 50 };
|
||||
/// First stereo band using the short one sample delay
|
||||
static const int SHORT_DELAY_BAND[] = { 42, 62 };
|
||||
|
||||
/** Table 8.46 */
|
||||
static void map_idx_10_to_20(int8_t *par_mapped, const int8_t *par, int full)
|
||||
{
|
||||
int b;
|
||||
if (full)
|
||||
b = 9;
|
||||
else {
|
||||
b = 4;
|
||||
par_mapped[10] = 0;
|
||||
}
|
||||
for (; b >= 0; b--) {
|
||||
par_mapped[2*b+1] = par_mapped[2*b] = par[b];
|
||||
}
|
||||
}
|
||||
|
||||
static void map_idx_34_to_20(int8_t *par_mapped, const int8_t *par, int full)
|
||||
{
|
||||
par_mapped[ 0] = (2*par[ 0] + par[ 1]) / 3;
|
||||
par_mapped[ 1] = ( par[ 1] + 2*par[ 2]) / 3;
|
||||
par_mapped[ 2] = (2*par[ 3] + par[ 4]) / 3;
|
||||
par_mapped[ 3] = ( par[ 4] + 2*par[ 5]) / 3;
|
||||
par_mapped[ 4] = ( par[ 6] + par[ 7]) / 2;
|
||||
par_mapped[ 5] = ( par[ 8] + par[ 9]) / 2;
|
||||
par_mapped[ 6] = par[10];
|
||||
par_mapped[ 7] = par[11];
|
||||
par_mapped[ 8] = ( par[12] + par[13]) / 2;
|
||||
par_mapped[ 9] = ( par[14] + par[15]) / 2;
|
||||
par_mapped[10] = par[16];
|
||||
if (full) {
|
||||
par_mapped[11] = par[17];
|
||||
par_mapped[12] = par[18];
|
||||
par_mapped[13] = par[19];
|
||||
par_mapped[14] = ( par[20] + par[21]) / 2;
|
||||
par_mapped[15] = ( par[22] + par[23]) / 2;
|
||||
par_mapped[16] = ( par[24] + par[25]) / 2;
|
||||
par_mapped[17] = ( par[26] + par[27]) / 2;
|
||||
par_mapped[18] = ( par[28] + par[29] + par[30] + par[31]) / 4;
|
||||
par_mapped[19] = ( par[32] + par[33]) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void map_val_34_to_20(float par[PS_MAX_NR_IIDICC])
|
||||
{
|
||||
par[ 0] = (2*par[ 0] + par[ 1]) * 0.33333333f;
|
||||
par[ 1] = ( par[ 1] + 2*par[ 2]) * 0.33333333f;
|
||||
par[ 2] = (2*par[ 3] + par[ 4]) * 0.33333333f;
|
||||
par[ 3] = ( par[ 4] + 2*par[ 5]) * 0.33333333f;
|
||||
par[ 4] = ( par[ 6] + par[ 7]) * 0.5f;
|
||||
par[ 5] = ( par[ 8] + par[ 9]) * 0.5f;
|
||||
par[ 6] = par[10];
|
||||
par[ 7] = par[11];
|
||||
par[ 8] = ( par[12] + par[13]) * 0.5f;
|
||||
par[ 9] = ( par[14] + par[15]) * 0.5f;
|
||||
par[10] = par[16];
|
||||
par[11] = par[17];
|
||||
par[12] = par[18];
|
||||
par[13] = par[19];
|
||||
par[14] = ( par[20] + par[21]) * 0.5f;
|
||||
par[15] = ( par[22] + par[23]) * 0.5f;
|
||||
par[16] = ( par[24] + par[25]) * 0.5f;
|
||||
par[17] = ( par[26] + par[27]) * 0.5f;
|
||||
par[18] = ( par[28] + par[29] + par[30] + par[31]) * 0.25f;
|
||||
par[19] = ( par[32] + par[33]) * 0.5f;
|
||||
}
|
||||
|
||||
static void map_idx_10_to_34(int8_t *par_mapped, const int8_t *par, int full)
|
||||
{
|
||||
if (full) {
|
||||
par_mapped[33] = par[9];
|
||||
par_mapped[32] = par[9];
|
||||
par_mapped[31] = par[9];
|
||||
par_mapped[30] = par[9];
|
||||
par_mapped[29] = par[9];
|
||||
par_mapped[28] = par[9];
|
||||
par_mapped[27] = par[8];
|
||||
par_mapped[26] = par[8];
|
||||
par_mapped[25] = par[8];
|
||||
par_mapped[24] = par[8];
|
||||
par_mapped[23] = par[7];
|
||||
par_mapped[22] = par[7];
|
||||
par_mapped[21] = par[7];
|
||||
par_mapped[20] = par[7];
|
||||
par_mapped[19] = par[6];
|
||||
par_mapped[18] = par[6];
|
||||
par_mapped[17] = par[5];
|
||||
par_mapped[16] = par[5];
|
||||
} else {
|
||||
par_mapped[16] = 0;
|
||||
}
|
||||
par_mapped[15] = par[4];
|
||||
par_mapped[14] = par[4];
|
||||
par_mapped[13] = par[4];
|
||||
par_mapped[12] = par[4];
|
||||
par_mapped[11] = par[3];
|
||||
par_mapped[10] = par[3];
|
||||
par_mapped[ 9] = par[2];
|
||||
par_mapped[ 8] = par[2];
|
||||
par_mapped[ 7] = par[2];
|
||||
par_mapped[ 6] = par[2];
|
||||
par_mapped[ 5] = par[1];
|
||||
par_mapped[ 4] = par[1];
|
||||
par_mapped[ 3] = par[1];
|
||||
par_mapped[ 2] = par[0];
|
||||
par_mapped[ 1] = par[0];
|
||||
par_mapped[ 0] = par[0];
|
||||
}
|
||||
|
||||
static void map_idx_20_to_34(int8_t *par_mapped, const int8_t *par, int full)
|
||||
{
|
||||
if (full) {
|
||||
par_mapped[33] = par[19];
|
||||
par_mapped[32] = par[19];
|
||||
par_mapped[31] = par[18];
|
||||
par_mapped[30] = par[18];
|
||||
par_mapped[29] = par[18];
|
||||
par_mapped[28] = par[18];
|
||||
par_mapped[27] = par[17];
|
||||
par_mapped[26] = par[17];
|
||||
par_mapped[25] = par[16];
|
||||
par_mapped[24] = par[16];
|
||||
par_mapped[23] = par[15];
|
||||
par_mapped[22] = par[15];
|
||||
par_mapped[21] = par[14];
|
||||
par_mapped[20] = par[14];
|
||||
par_mapped[19] = par[13];
|
||||
par_mapped[18] = par[12];
|
||||
par_mapped[17] = par[11];
|
||||
}
|
||||
par_mapped[16] = par[10];
|
||||
par_mapped[15] = par[ 9];
|
||||
par_mapped[14] = par[ 9];
|
||||
par_mapped[13] = par[ 8];
|
||||
par_mapped[12] = par[ 8];
|
||||
par_mapped[11] = par[ 7];
|
||||
par_mapped[10] = par[ 6];
|
||||
par_mapped[ 9] = par[ 5];
|
||||
par_mapped[ 8] = par[ 5];
|
||||
par_mapped[ 7] = par[ 4];
|
||||
par_mapped[ 6] = par[ 4];
|
||||
par_mapped[ 5] = par[ 3];
|
||||
par_mapped[ 4] = (par[ 2] + par[ 3]) / 2;
|
||||
par_mapped[ 3] = par[ 2];
|
||||
par_mapped[ 2] = par[ 1];
|
||||
par_mapped[ 1] = (par[ 0] + par[ 1]) / 2;
|
||||
par_mapped[ 0] = par[ 0];
|
||||
}
|
||||
|
||||
static void map_val_20_to_34(float par[PS_MAX_NR_IIDICC])
|
||||
{
|
||||
par[33] = par[19];
|
||||
par[32] = par[19];
|
||||
par[31] = par[18];
|
||||
par[30] = par[18];
|
||||
par[29] = par[18];
|
||||
par[28] = par[18];
|
||||
par[27] = par[17];
|
||||
par[26] = par[17];
|
||||
par[25] = par[16];
|
||||
par[24] = par[16];
|
||||
par[23] = par[15];
|
||||
par[22] = par[15];
|
||||
par[21] = par[14];
|
||||
par[20] = par[14];
|
||||
par[19] = par[13];
|
||||
par[18] = par[12];
|
||||
par[17] = par[11];
|
||||
par[16] = par[10];
|
||||
par[15] = par[ 9];
|
||||
par[14] = par[ 9];
|
||||
par[13] = par[ 8];
|
||||
par[12] = par[ 8];
|
||||
par[11] = par[ 7];
|
||||
par[10] = par[ 6];
|
||||
par[ 9] = par[ 5];
|
||||
par[ 8] = par[ 5];
|
||||
par[ 7] = par[ 4];
|
||||
par[ 6] = par[ 4];
|
||||
par[ 5] = par[ 3];
|
||||
par[ 4] = (par[ 2] + par[ 3]) * 0.5f;
|
||||
par[ 3] = par[ 2];
|
||||
par[ 2] = par[ 1];
|
||||
par[ 1] = (par[ 0] + par[ 1]) * 0.5f;
|
||||
}
|
||||
|
||||
static void decorrelation(PSContext *ps, float (*out)[32][2], const float (*s)[32][2], int is34)
|
||||
{
|
||||
LOCAL_ALIGNED_16(float, power, [34], [PS_QMF_TIME_SLOTS]);
|
||||
LOCAL_ALIGNED_16(float, transient_gain, [34], [PS_QMF_TIME_SLOTS]);
|
||||
float *peak_decay_nrg = ps->peak_decay_nrg;
|
||||
float *power_smooth = ps->power_smooth;
|
||||
float *peak_decay_diff_smooth = ps->peak_decay_diff_smooth;
|
||||
float (*delay)[PS_QMF_TIME_SLOTS + PS_MAX_DELAY][2] = ps->delay;
|
||||
float (*ap_delay)[PS_AP_LINKS][PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2] = ps->ap_delay;
|
||||
const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20;
|
||||
const float peak_decay_factor = 0.76592833836465f;
|
||||
const float transient_impact = 1.5f;
|
||||
const float a_smooth = 0.25f; ///< Smoothing coefficient
|
||||
int i, k, m, n;
|
||||
int n0 = 0, nL = 32;
|
||||
|
||||
memset(power, 0, 34 * sizeof(*power));
|
||||
|
||||
if (is34 != ps->is34bands_old) {
|
||||
memset(ps->peak_decay_nrg, 0, sizeof(ps->peak_decay_nrg));
|
||||
memset(ps->power_smooth, 0, sizeof(ps->power_smooth));
|
||||
memset(ps->peak_decay_diff_smooth, 0, sizeof(ps->peak_decay_diff_smooth));
|
||||
memset(ps->delay, 0, sizeof(ps->delay));
|
||||
memset(ps->ap_delay, 0, sizeof(ps->ap_delay));
|
||||
}
|
||||
|
||||
for (k = 0; k < NR_BANDS[is34]; k++) {
|
||||
int i = k_to_i[k];
|
||||
ps->dsp.add_squares(power[i], s[k], nL - n0);
|
||||
}
|
||||
|
||||
//Transient detection
|
||||
for (i = 0; i < NR_PAR_BANDS[is34]; i++) {
|
||||
for (n = n0; n < nL; n++) {
|
||||
float decayed_peak = peak_decay_factor * peak_decay_nrg[i];
|
||||
float denom;
|
||||
peak_decay_nrg[i] = FFMAX(decayed_peak, power[i][n]);
|
||||
power_smooth[i] += a_smooth * (power[i][n] - power_smooth[i]);
|
||||
peak_decay_diff_smooth[i] += a_smooth * (peak_decay_nrg[i] - power[i][n] - peak_decay_diff_smooth[i]);
|
||||
denom = transient_impact * peak_decay_diff_smooth[i];
|
||||
transient_gain[i][n] = (denom > power_smooth[i]) ?
|
||||
power_smooth[i] / denom : 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
//Decorrelation and transient reduction
|
||||
// PS_AP_LINKS - 1
|
||||
// -----
|
||||
// | | Q_fract_allpass[k][m]*z^-link_delay[m] - a[m]*g_decay_slope[k]
|
||||
//H[k][z] = z^-2 * phi_fract[k] * | | ----------------------------------------------------------------
|
||||
// | | 1 - a[m]*g_decay_slope[k]*Q_fract_allpass[k][m]*z^-link_delay[m]
|
||||
// m = 0
|
||||
//d[k][z] (out) = transient_gain_mapped[k][z] * H[k][z] * s[k][z]
|
||||
for (k = 0; k < NR_ALLPASS_BANDS[is34]; k++) {
|
||||
int b = k_to_i[k];
|
||||
float g_decay_slope = 1.f - DECAY_SLOPE * (k - DECAY_CUTOFF[is34]);
|
||||
g_decay_slope = av_clipf(g_decay_slope, 0.f, 1.f);
|
||||
memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));
|
||||
memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));
|
||||
for (m = 0; m < PS_AP_LINKS; m++) {
|
||||
memcpy(ap_delay[k][m], ap_delay[k][m]+numQMFSlots, 5*sizeof(ap_delay[k][m][0]));
|
||||
}
|
||||
ps->dsp.decorrelate(out[k], delay[k] + PS_MAX_DELAY - 2, ap_delay[k],
|
||||
phi_fract[is34][k],
|
||||
(const float (*)[2]) Q_fract_allpass[is34][k],
|
||||
transient_gain[b], g_decay_slope, nL - n0);
|
||||
}
|
||||
for (; k < SHORT_DELAY_BAND[is34]; k++) {
|
||||
int i = k_to_i[k];
|
||||
memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));
|
||||
memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));
|
||||
//H = delay 14
|
||||
ps->dsp.mul_pair_single(out[k], delay[k] + PS_MAX_DELAY - 14,
|
||||
transient_gain[i], nL - n0);
|
||||
}
|
||||
for (; k < NR_BANDS[is34]; k++) {
|
||||
int i = k_to_i[k];
|
||||
memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));
|
||||
memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));
|
||||
//H = delay 1
|
||||
ps->dsp.mul_pair_single(out[k], delay[k] + PS_MAX_DELAY - 1,
|
||||
transient_gain[i], nL - n0);
|
||||
}
|
||||
}
|
||||
|
||||
static void remap34(int8_t (**p_par_mapped)[PS_MAX_NR_IIDICC],
|
||||
int8_t (*par)[PS_MAX_NR_IIDICC],
|
||||
int num_par, int num_env, int full)
|
||||
{
|
||||
int8_t (*par_mapped)[PS_MAX_NR_IIDICC] = *p_par_mapped;
|
||||
int e;
|
||||
if (num_par == 20 || num_par == 11) {
|
||||
for (e = 0; e < num_env; e++) {
|
||||
map_idx_20_to_34(par_mapped[e], par[e], full);
|
||||
}
|
||||
} else if (num_par == 10 || num_par == 5) {
|
||||
for (e = 0; e < num_env; e++) {
|
||||
map_idx_10_to_34(par_mapped[e], par[e], full);
|
||||
}
|
||||
} else {
|
||||
*p_par_mapped = par;
|
||||
}
|
||||
}
|
||||
|
||||
static void remap20(int8_t (**p_par_mapped)[PS_MAX_NR_IIDICC],
|
||||
int8_t (*par)[PS_MAX_NR_IIDICC],
|
||||
int num_par, int num_env, int full)
|
||||
{
|
||||
int8_t (*par_mapped)[PS_MAX_NR_IIDICC] = *p_par_mapped;
|
||||
int e;
|
||||
if (num_par == 34 || num_par == 17) {
|
||||
for (e = 0; e < num_env; e++) {
|
||||
map_idx_34_to_20(par_mapped[e], par[e], full);
|
||||
}
|
||||
} else if (num_par == 10 || num_par == 5) {
|
||||
for (e = 0; e < num_env; e++) {
|
||||
map_idx_10_to_20(par_mapped[e], par[e], full);
|
||||
}
|
||||
} else {
|
||||
*p_par_mapped = par;
|
||||
}
|
||||
}
|
||||
|
||||
static void stereo_processing(PSContext *ps, float (*l)[32][2], float (*r)[32][2], int is34)
|
||||
{
|
||||
int e, b, k;
|
||||
|
||||
float (*H11)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H11;
|
||||
float (*H12)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H12;
|
||||
float (*H21)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H21;
|
||||
float (*H22)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H22;
|
||||
int8_t *opd_hist = ps->opd_hist;
|
||||
int8_t *ipd_hist = ps->ipd_hist;
|
||||
int8_t iid_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];
|
||||
int8_t icc_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];
|
||||
int8_t ipd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];
|
||||
int8_t opd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];
|
||||
int8_t (*iid_mapped)[PS_MAX_NR_IIDICC] = iid_mapped_buf;
|
||||
int8_t (*icc_mapped)[PS_MAX_NR_IIDICC] = icc_mapped_buf;
|
||||
int8_t (*ipd_mapped)[PS_MAX_NR_IIDICC] = ipd_mapped_buf;
|
||||
int8_t (*opd_mapped)[PS_MAX_NR_IIDICC] = opd_mapped_buf;
|
||||
const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20;
|
||||
TABLE_CONST float (*H_LUT)[8][4] = (PS_BASELINE || ps->icc_mode < 3) ? HA : HB;
|
||||
|
||||
//Remapping
|
||||
if (ps->num_env_old) {
|
||||
memcpy(H11[0][0], H11[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[0][0][0]));
|
||||
memcpy(H11[1][0], H11[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[1][0][0]));
|
||||
memcpy(H12[0][0], H12[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[0][0][0]));
|
||||
memcpy(H12[1][0], H12[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[1][0][0]));
|
||||
memcpy(H21[0][0], H21[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[0][0][0]));
|
||||
memcpy(H21[1][0], H21[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[1][0][0]));
|
||||
memcpy(H22[0][0], H22[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[0][0][0]));
|
||||
memcpy(H22[1][0], H22[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[1][0][0]));
|
||||
}
|
||||
|
||||
if (is34) {
|
||||
remap34(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1);
|
||||
remap34(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1);
|
||||
if (ps->enable_ipdopd) {
|
||||
remap34(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0);
|
||||
remap34(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0);
|
||||
}
|
||||
if (!ps->is34bands_old) {
|
||||
map_val_20_to_34(H11[0][0]);
|
||||
map_val_20_to_34(H11[1][0]);
|
||||
map_val_20_to_34(H12[0][0]);
|
||||
map_val_20_to_34(H12[1][0]);
|
||||
map_val_20_to_34(H21[0][0]);
|
||||
map_val_20_to_34(H21[1][0]);
|
||||
map_val_20_to_34(H22[0][0]);
|
||||
map_val_20_to_34(H22[1][0]);
|
||||
ipdopd_reset(ipd_hist, opd_hist);
|
||||
}
|
||||
} else {
|
||||
remap20(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1);
|
||||
remap20(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1);
|
||||
if (ps->enable_ipdopd) {
|
||||
remap20(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0);
|
||||
remap20(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0);
|
||||
}
|
||||
if (ps->is34bands_old) {
|
||||
map_val_34_to_20(H11[0][0]);
|
||||
map_val_34_to_20(H11[1][0]);
|
||||
map_val_34_to_20(H12[0][0]);
|
||||
map_val_34_to_20(H12[1][0]);
|
||||
map_val_34_to_20(H21[0][0]);
|
||||
map_val_34_to_20(H21[1][0]);
|
||||
map_val_34_to_20(H22[0][0]);
|
||||
map_val_34_to_20(H22[1][0]);
|
||||
ipdopd_reset(ipd_hist, opd_hist);
|
||||
}
|
||||
}
|
||||
|
||||
//Mixing
|
||||
for (e = 0; e < ps->num_env; e++) {
|
||||
for (b = 0; b < NR_PAR_BANDS[is34]; b++) {
|
||||
float h11, h12, h21, h22;
|
||||
h11 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][0];
|
||||
h12 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][1];
|
||||
h21 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][2];
|
||||
h22 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][3];
|
||||
|
||||
if (!PS_BASELINE && ps->enable_ipdopd && b < NR_IPDOPD_BANDS[is34]) {
|
||||
//The spec say says to only run this smoother when enable_ipdopd
|
||||
//is set but the reference decoder appears to run it constantly
|
||||
float h11i, h12i, h21i, h22i;
|
||||
float ipd_adj_re, ipd_adj_im;
|
||||
int opd_idx = opd_hist[b] * 8 + opd_mapped[e][b];
|
||||
int ipd_idx = ipd_hist[b] * 8 + ipd_mapped[e][b];
|
||||
float opd_re = pd_re_smooth[opd_idx];
|
||||
float opd_im = pd_im_smooth[opd_idx];
|
||||
float ipd_re = pd_re_smooth[ipd_idx];
|
||||
float ipd_im = pd_im_smooth[ipd_idx];
|
||||
opd_hist[b] = opd_idx & 0x3F;
|
||||
ipd_hist[b] = ipd_idx & 0x3F;
|
||||
|
||||
ipd_adj_re = opd_re*ipd_re + opd_im*ipd_im;
|
||||
ipd_adj_im = opd_im*ipd_re - opd_re*ipd_im;
|
||||
h11i = h11 * opd_im;
|
||||
h11 = h11 * opd_re;
|
||||
h12i = h12 * ipd_adj_im;
|
||||
h12 = h12 * ipd_adj_re;
|
||||
h21i = h21 * opd_im;
|
||||
h21 = h21 * opd_re;
|
||||
h22i = h22 * ipd_adj_im;
|
||||
h22 = h22 * ipd_adj_re;
|
||||
H11[1][e+1][b] = h11i;
|
||||
H12[1][e+1][b] = h12i;
|
||||
H21[1][e+1][b] = h21i;
|
||||
H22[1][e+1][b] = h22i;
|
||||
}
|
||||
H11[0][e+1][b] = h11;
|
||||
H12[0][e+1][b] = h12;
|
||||
H21[0][e+1][b] = h21;
|
||||
H22[0][e+1][b] = h22;
|
||||
}
|
||||
for (k = 0; k < NR_BANDS[is34]; k++) {
|
||||
float h[2][4];
|
||||
float h_step[2][4];
|
||||
int start = ps->border_position[e];
|
||||
int stop = ps->border_position[e+1];
|
||||
float width = 1.f / (stop - start);
|
||||
b = k_to_i[k];
|
||||
h[0][0] = H11[0][e][b];
|
||||
h[0][1] = H12[0][e][b];
|
||||
h[0][2] = H21[0][e][b];
|
||||
h[0][3] = H22[0][e][b];
|
||||
if (!PS_BASELINE && ps->enable_ipdopd) {
|
||||
//Is this necessary? ps_04_new seems unchanged
|
||||
if ((is34 && k <= 13 && k >= 9) || (!is34 && k <= 1)) {
|
||||
h[1][0] = -H11[1][e][b];
|
||||
h[1][1] = -H12[1][e][b];
|
||||
h[1][2] = -H21[1][e][b];
|
||||
h[1][3] = -H22[1][e][b];
|
||||
} else {
|
||||
h[1][0] = H11[1][e][b];
|
||||
h[1][1] = H12[1][e][b];
|
||||
h[1][2] = H21[1][e][b];
|
||||
h[1][3] = H22[1][e][b];
|
||||
}
|
||||
}
|
||||
//Interpolation
|
||||
h_step[0][0] = (H11[0][e+1][b] - h[0][0]) * width;
|
||||
h_step[0][1] = (H12[0][e+1][b] - h[0][1]) * width;
|
||||
h_step[0][2] = (H21[0][e+1][b] - h[0][2]) * width;
|
||||
h_step[0][3] = (H22[0][e+1][b] - h[0][3]) * width;
|
||||
if (!PS_BASELINE && ps->enable_ipdopd) {
|
||||
h_step[1][0] = (H11[1][e+1][b] - h[1][0]) * width;
|
||||
h_step[1][1] = (H12[1][e+1][b] - h[1][1]) * width;
|
||||
h_step[1][2] = (H21[1][e+1][b] - h[1][2]) * width;
|
||||
h_step[1][3] = (H22[1][e+1][b] - h[1][3]) * width;
|
||||
}
|
||||
ps->dsp.stereo_interpolate[!PS_BASELINE && ps->enable_ipdopd](
|
||||
l[k] + start + 1, r[k] + start + 1,
|
||||
h, h_step, stop - start);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ff_ps_apply(AVCodecContext *avctx, PSContext *ps, float L[2][38][64], float R[2][38][64], int top)
|
||||
{
|
||||
LOCAL_ALIGNED_16(float, Lbuf, [91], [32][2]);
|
||||
LOCAL_ALIGNED_16(float, Rbuf, [91], [32][2]);
|
||||
const int len = 32;
|
||||
int is34 = ps->is34bands;
|
||||
|
||||
top += NR_BANDS[is34] - 64;
|
||||
memset(ps->delay+top, 0, (NR_BANDS[is34] - top)*sizeof(ps->delay[0]));
|
||||
if (top < NR_ALLPASS_BANDS[is34])
|
||||
memset(ps->ap_delay + top, 0, (NR_ALLPASS_BANDS[is34] - top)*sizeof(ps->ap_delay[0]));
|
||||
|
||||
hybrid_analysis(&ps->dsp, Lbuf, ps->in_buf, L, is34, len);
|
||||
decorrelation(ps, Rbuf, (const float (*)[32][2]) Lbuf, is34);
|
||||
stereo_processing(ps, Lbuf, Rbuf, is34);
|
||||
hybrid_synthesis(&ps->dsp, L, Lbuf, is34, len);
|
||||
hybrid_synthesis(&ps->dsp, R, Rbuf, is34, len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define PS_INIT_VLC_STATIC(num, size) \
|
||||
INIT_VLC_STATIC(&vlc_ps[num], 9, ps_tmp[num].table_size / ps_tmp[num].elem_size, \
|
||||
ps_tmp[num].ps_bits, 1, 1, \
|
||||
ps_tmp[num].ps_codes, ps_tmp[num].elem_size, ps_tmp[num].elem_size, \
|
||||
size);
|
||||
|
||||
#define PS_VLC_ROW(name) \
|
||||
{ name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
|
||||
|
||||
av_cold void ff_ps_init(void) {
|
||||
// Syntax initialization
|
||||
static const struct {
|
||||
const void *ps_codes, *ps_bits;
|
||||
const unsigned int table_size, elem_size;
|
||||
} ps_tmp[] = {
|
||||
PS_VLC_ROW(huff_iid_df1),
|
||||
PS_VLC_ROW(huff_iid_dt1),
|
||||
PS_VLC_ROW(huff_iid_df0),
|
||||
PS_VLC_ROW(huff_iid_dt0),
|
||||
PS_VLC_ROW(huff_icc_df),
|
||||
PS_VLC_ROW(huff_icc_dt),
|
||||
PS_VLC_ROW(huff_ipd_df),
|
||||
PS_VLC_ROW(huff_ipd_dt),
|
||||
PS_VLC_ROW(huff_opd_df),
|
||||
PS_VLC_ROW(huff_opd_dt),
|
||||
};
|
||||
|
||||
PS_INIT_VLC_STATIC(0, 1544);
|
||||
PS_INIT_VLC_STATIC(1, 832);
|
||||
PS_INIT_VLC_STATIC(2, 1024);
|
||||
PS_INIT_VLC_STATIC(3, 1036);
|
||||
PS_INIT_VLC_STATIC(4, 544);
|
||||
PS_INIT_VLC_STATIC(5, 544);
|
||||
PS_INIT_VLC_STATIC(6, 512);
|
||||
PS_INIT_VLC_STATIC(7, 512);
|
||||
PS_INIT_VLC_STATIC(8, 512);
|
||||
PS_INIT_VLC_STATIC(9, 512);
|
||||
|
||||
ps_tableinit();
|
||||
}
|
||||
|
||||
av_cold void ff_ps_ctx_init(PSContext *ps)
|
||||
{
|
||||
ff_psdsp_init(&ps->dsp);
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* MPEG-4 Parametric Stereo definitions and declarations
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_PS_H
|
||||
#define AVCODEC_PS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "aacpsdsp.h"
|
||||
#include "avcodec.h"
|
||||
#include "get_bits.h"
|
||||
|
||||
#define PS_MAX_NUM_ENV 5
|
||||
#define PS_MAX_NR_IIDICC 34
|
||||
#define PS_MAX_NR_IPDOPD 17
|
||||
#define PS_MAX_SSB 91
|
||||
#define PS_MAX_AP_BANDS 50
|
||||
#define PS_QMF_TIME_SLOTS 32
|
||||
#define PS_MAX_DELAY 14
|
||||
#define PS_AP_LINKS 3
|
||||
#define PS_MAX_AP_DELAY 5
|
||||
|
||||
typedef struct PSContext {
|
||||
int start;
|
||||
int enable_iid;
|
||||
int iid_quant;
|
||||
int nr_iid_par;
|
||||
int nr_ipdopd_par;
|
||||
int enable_icc;
|
||||
int icc_mode;
|
||||
int nr_icc_par;
|
||||
int enable_ext;
|
||||
int frame_class;
|
||||
int num_env_old;
|
||||
int num_env;
|
||||
int enable_ipdopd;
|
||||
int border_position[PS_MAX_NUM_ENV+1];
|
||||
int8_t iid_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Inter-channel Intensity Difference Parameters
|
||||
int8_t icc_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Inter-Channel Coherence Parameters
|
||||
/* ipd/opd is iid/icc sized so that the same functions can handle both */
|
||||
int8_t ipd_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Inter-channel Phase Difference Parameters
|
||||
int8_t opd_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Overall Phase Difference Parameters
|
||||
int is34bands;
|
||||
int is34bands_old;
|
||||
|
||||
DECLARE_ALIGNED(16, float, in_buf)[5][44][2];
|
||||
DECLARE_ALIGNED(16, float, delay)[PS_MAX_SSB][PS_QMF_TIME_SLOTS + PS_MAX_DELAY][2];
|
||||
DECLARE_ALIGNED(16, float, ap_delay)[PS_MAX_AP_BANDS][PS_AP_LINKS][PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2];
|
||||
DECLARE_ALIGNED(16, float, peak_decay_nrg)[34];
|
||||
DECLARE_ALIGNED(16, float, power_smooth)[34];
|
||||
DECLARE_ALIGNED(16, float, peak_decay_diff_smooth)[34];
|
||||
DECLARE_ALIGNED(16, float, H11)[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC];
|
||||
DECLARE_ALIGNED(16, float, H12)[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC];
|
||||
DECLARE_ALIGNED(16, float, H21)[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC];
|
||||
DECLARE_ALIGNED(16, float, H22)[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC];
|
||||
int8_t opd_hist[PS_MAX_NR_IIDICC];
|
||||
int8_t ipd_hist[PS_MAX_NR_IIDICC];
|
||||
PSDSPContext dsp;
|
||||
} PSContext;
|
||||
|
||||
void ff_ps_init(void);
|
||||
void ff_ps_ctx_init(PSContext *ps);
|
||||
int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb, PSContext *ps, int bits_left);
|
||||
int ff_ps_apply(AVCodecContext *avctx, PSContext *ps, float L[2][38][64], float R[2][38][64], int top);
|
||||
|
||||
#endif /* AVCODEC_PS_H */
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* Generate a header file for hardcoded Parametric Stereo tables
|
||||
*
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#define CONFIG_HARDCODED_TABLES 0
|
||||
#include "aacps_tablegen.h"
|
||||
#include "tableprint.h"
|
||||
|
||||
void write_float_3d_array (const void *p, int b, int c, int d)
|
||||
{
|
||||
int i;
|
||||
const float *f = p;
|
||||
for (i = 0; i < b; i++) {
|
||||
printf("{\n");
|
||||
write_float_2d_array(f, c, d);
|
||||
printf("},\n");
|
||||
f += c * d;
|
||||
}
|
||||
}
|
||||
|
||||
void write_float_4d_array (const void *p, int a, int b, int c, int d)
|
||||
{
|
||||
int i;
|
||||
const float *f = p;
|
||||
for (i = 0; i < a; i++) {
|
||||
printf("{\n");
|
||||
write_float_3d_array(f, b, c, d);
|
||||
printf("},\n");
|
||||
f += b * c * d;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ps_tableinit();
|
||||
|
||||
write_fileheader();
|
||||
|
||||
printf("static const float pd_re_smooth[8*8*8] = {\n");
|
||||
write_float_array(pd_re_smooth, 8*8*8);
|
||||
printf("};\n");
|
||||
printf("static const float pd_im_smooth[8*8*8] = {\n");
|
||||
write_float_array(pd_im_smooth, 8*8*8);
|
||||
printf("};\n");
|
||||
|
||||
printf("static const float HA[46][8][4] = {\n");
|
||||
write_float_3d_array(HA, 46, 8, 4);
|
||||
printf("};\n");
|
||||
printf("static const float HB[46][8][4] = {\n");
|
||||
write_float_3d_array(HB, 46, 8, 4);
|
||||
printf("};\n");
|
||||
|
||||
printf("static const DECLARE_ALIGNED(16, float, f20_0_8)[8][8][2] = {\n");
|
||||
write_float_3d_array(f20_0_8, 8, 8, 2);
|
||||
printf("};\n");
|
||||
printf("static const DECLARE_ALIGNED(16, float, f34_0_12)[12][8][2] = {\n");
|
||||
write_float_3d_array(f34_0_12, 12, 8, 2);
|
||||
printf("};\n");
|
||||
printf("static const DECLARE_ALIGNED(16, float, f34_1_8)[8][8][2] = {\n");
|
||||
write_float_3d_array(f34_1_8, 8, 8, 2);
|
||||
printf("};\n");
|
||||
printf("static const DECLARE_ALIGNED(16, float, f34_2_4)[4][8][2] = {\n");
|
||||
write_float_3d_array(f34_2_4, 4, 8, 2);
|
||||
printf("};\n");
|
||||
|
||||
printf("static TABLE_CONST DECLARE_ALIGNED(16, float, Q_fract_allpass)[2][50][3][2] = {\n");
|
||||
write_float_4d_array(Q_fract_allpass, 2, 50, 3, 2);
|
||||
printf("};\n");
|
||||
printf("static const DECLARE_ALIGNED(16, float, phi_fract)[2][50][2] = {\n");
|
||||
write_float_3d_array(phi_fract, 2, 50, 2);
|
||||
printf("};\n");
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,217 +0,0 @@
|
|||
/*
|
||||
* Header file for hardcoded Parametric Stereo tables
|
||||
*
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AACPS_TABLEGEN_H
|
||||
#define AACPS_TABLEGEN_H
|
||||
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if CONFIG_HARDCODED_TABLES
|
||||
#define ps_tableinit()
|
||||
#define TABLE_CONST const
|
||||
#include "libavcodec/aacps_tables.h"
|
||||
#else
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/libm.h"
|
||||
#include "libavutil/mathematics.h"
|
||||
#include "libavutil/mem.h"
|
||||
#define NR_ALLPASS_BANDS20 30
|
||||
#define NR_ALLPASS_BANDS34 50
|
||||
#define PS_AP_LINKS 3
|
||||
#define TABLE_CONST
|
||||
static float pd_re_smooth[8*8*8];
|
||||
static float pd_im_smooth[8*8*8];
|
||||
static float HA[46][8][4];
|
||||
static float HB[46][8][4];
|
||||
static DECLARE_ALIGNED(16, float, f20_0_8) [ 8][8][2];
|
||||
static DECLARE_ALIGNED(16, float, f34_0_12)[12][8][2];
|
||||
static DECLARE_ALIGNED(16, float, f34_1_8) [ 8][8][2];
|
||||
static DECLARE_ALIGNED(16, float, f34_2_4) [ 4][8][2];
|
||||
static TABLE_CONST DECLARE_ALIGNED(16, float, Q_fract_allpass)[2][50][3][2];
|
||||
static DECLARE_ALIGNED(16, float, phi_fract)[2][50][2];
|
||||
|
||||
static const float g0_Q8[] = {
|
||||
0.00746082949812f, 0.02270420949825f, 0.04546865930473f, 0.07266113929591f,
|
||||
0.09885108575264f, 0.11793710567217f, 0.125f
|
||||
};
|
||||
|
||||
static const float g0_Q12[] = {
|
||||
0.04081179924692f, 0.03812810994926f, 0.05144908135699f, 0.06399831151592f,
|
||||
0.07428313801106f, 0.08100347892914f, 0.08333333333333f
|
||||
};
|
||||
|
||||
static const float g1_Q8[] = {
|
||||
0.01565675600122f, 0.03752716391991f, 0.05417891378782f, 0.08417044116767f,
|
||||
0.10307344158036f, 0.12222452249753f, 0.125f
|
||||
};
|
||||
|
||||
static const float g2_Q4[] = {
|
||||
-0.05908211155639f, -0.04871498374946f, 0.0f, 0.07778723915851f,
|
||||
0.16486303567403f, 0.23279856662996f, 0.25f
|
||||
};
|
||||
|
||||
static void make_filters_from_proto(float (*filter)[8][2], const float *proto, int bands)
|
||||
{
|
||||
int q, n;
|
||||
for (q = 0; q < bands; q++) {
|
||||
for (n = 0; n < 7; n++) {
|
||||
double theta = 2 * M_PI * (q + 0.5) * (n - 6) / bands;
|
||||
filter[q][n][0] = proto[n] * cos(theta);
|
||||
filter[q][n][1] = proto[n] * -sin(theta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ps_tableinit(void)
|
||||
{
|
||||
static const float ipdopd_sin[] = { 0, M_SQRT1_2, 1, M_SQRT1_2, 0, -M_SQRT1_2, -1, -M_SQRT1_2 };
|
||||
static const float ipdopd_cos[] = { 1, M_SQRT1_2, 0, -M_SQRT1_2, -1, -M_SQRT1_2, 0, M_SQRT1_2 };
|
||||
int pd0, pd1, pd2;
|
||||
|
||||
static const float iid_par_dequant[] = {
|
||||
//iid_par_dequant_default
|
||||
0.05623413251903, 0.12589254117942, 0.19952623149689, 0.31622776601684,
|
||||
0.44668359215096, 0.63095734448019, 0.79432823472428, 1,
|
||||
1.25892541179417, 1.58489319246111, 2.23872113856834, 3.16227766016838,
|
||||
5.01187233627272, 7.94328234724282, 17.7827941003892,
|
||||
//iid_par_dequant_fine
|
||||
0.00316227766017, 0.00562341325190, 0.01, 0.01778279410039,
|
||||
0.03162277660168, 0.05623413251903, 0.07943282347243, 0.11220184543020,
|
||||
0.15848931924611, 0.22387211385683, 0.31622776601684, 0.39810717055350,
|
||||
0.50118723362727, 0.63095734448019, 0.79432823472428, 1,
|
||||
1.25892541179417, 1.58489319246111, 1.99526231496888, 2.51188643150958,
|
||||
3.16227766016838, 4.46683592150963, 6.30957344480193, 8.91250938133745,
|
||||
12.5892541179417, 17.7827941003892, 31.6227766016838, 56.2341325190349,
|
||||
100, 177.827941003892, 316.227766016837,
|
||||
};
|
||||
static const float icc_invq[] = {
|
||||
1, 0.937, 0.84118, 0.60092, 0.36764, 0, -0.589, -1
|
||||
};
|
||||
static const float acos_icc_invq[] = {
|
||||
0, 0.35685527, 0.57133466, 0.92614472, 1.1943263, M_PI/2, 2.2006171, M_PI
|
||||
};
|
||||
int iid, icc;
|
||||
|
||||
int k, m;
|
||||
static const int8_t f_center_20[] = {
|
||||
-3, -1, 1, 3, 5, 7, 10, 14, 18, 22,
|
||||
};
|
||||
static const int8_t f_center_34[] = {
|
||||
2, 6, 10, 14, 18, 22, 26, 30,
|
||||
34,-10, -6, -2, 51, 57, 15, 21,
|
||||
27, 33, 39, 45, 54, 66, 78, 42,
|
||||
102, 66, 78, 90,102,114,126, 90,
|
||||
};
|
||||
static const float fractional_delay_links[] = { 0.43f, 0.75f, 0.347f };
|
||||
const float fractional_delay_gain = 0.39f;
|
||||
|
||||
for (pd0 = 0; pd0 < 8; pd0++) {
|
||||
float pd0_re = ipdopd_cos[pd0];
|
||||
float pd0_im = ipdopd_sin[pd0];
|
||||
for (pd1 = 0; pd1 < 8; pd1++) {
|
||||
float pd1_re = ipdopd_cos[pd1];
|
||||
float pd1_im = ipdopd_sin[pd1];
|
||||
for (pd2 = 0; pd2 < 8; pd2++) {
|
||||
float pd2_re = ipdopd_cos[pd2];
|
||||
float pd2_im = ipdopd_sin[pd2];
|
||||
float re_smooth = 0.25f * pd0_re + 0.5f * pd1_re + pd2_re;
|
||||
float im_smooth = 0.25f * pd0_im + 0.5f * pd1_im + pd2_im;
|
||||
float pd_mag = 1 / sqrt(im_smooth * im_smooth + re_smooth * re_smooth);
|
||||
pd_re_smooth[pd0*64+pd1*8+pd2] = re_smooth * pd_mag;
|
||||
pd_im_smooth[pd0*64+pd1*8+pd2] = im_smooth * pd_mag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (iid = 0; iid < 46; iid++) {
|
||||
float c = iid_par_dequant[iid]; ///< Linear Inter-channel Intensity Difference
|
||||
float c1 = (float)M_SQRT2 / sqrtf(1.0f + c*c);
|
||||
float c2 = c * c1;
|
||||
for (icc = 0; icc < 8; icc++) {
|
||||
/*if (PS_BASELINE || ps->icc_mode < 3)*/ {
|
||||
float alpha = 0.5f * acos_icc_invq[icc];
|
||||
float beta = alpha * (c1 - c2) * (float)M_SQRT1_2;
|
||||
HA[iid][icc][0] = c2 * cosf(beta + alpha);
|
||||
HA[iid][icc][1] = c1 * cosf(beta - alpha);
|
||||
HA[iid][icc][2] = c2 * sinf(beta + alpha);
|
||||
HA[iid][icc][3] = c1 * sinf(beta - alpha);
|
||||
} /* else */ {
|
||||
float alpha, gamma, mu, rho;
|
||||
float alpha_c, alpha_s, gamma_c, gamma_s;
|
||||
rho = FFMAX(icc_invq[icc], 0.05f);
|
||||
alpha = 0.5f * atan2f(2.0f * c * rho, c*c - 1.0f);
|
||||
mu = c + 1.0f / c;
|
||||
mu = sqrtf(1 + (4 * rho * rho - 4)/(mu * mu));
|
||||
gamma = atanf(sqrtf((1.0f - mu)/(1.0f + mu)));
|
||||
if (alpha < 0) alpha += M_PI/2;
|
||||
alpha_c = cosf(alpha);
|
||||
alpha_s = sinf(alpha);
|
||||
gamma_c = cosf(gamma);
|
||||
gamma_s = sinf(gamma);
|
||||
HB[iid][icc][0] = M_SQRT2 * alpha_c * gamma_c;
|
||||
HB[iid][icc][1] = M_SQRT2 * alpha_s * gamma_c;
|
||||
HB[iid][icc][2] = -M_SQRT2 * alpha_s * gamma_s;
|
||||
HB[iid][icc][3] = M_SQRT2 * alpha_c * gamma_s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (k = 0; k < NR_ALLPASS_BANDS20; k++) {
|
||||
double f_center, theta;
|
||||
if (k < FF_ARRAY_ELEMS(f_center_20))
|
||||
f_center = f_center_20[k] * 0.125;
|
||||
else
|
||||
f_center = k - 6.5f;
|
||||
for (m = 0; m < PS_AP_LINKS; m++) {
|
||||
theta = -M_PI * fractional_delay_links[m] * f_center;
|
||||
Q_fract_allpass[0][k][m][0] = cos(theta);
|
||||
Q_fract_allpass[0][k][m][1] = sin(theta);
|
||||
}
|
||||
theta = -M_PI*fractional_delay_gain*f_center;
|
||||
phi_fract[0][k][0] = cos(theta);
|
||||
phi_fract[0][k][1] = sin(theta);
|
||||
}
|
||||
for (k = 0; k < NR_ALLPASS_BANDS34; k++) {
|
||||
double f_center, theta;
|
||||
if (k < FF_ARRAY_ELEMS(f_center_34))
|
||||
f_center = f_center_34[k] / 24.0;
|
||||
else
|
||||
f_center = k - 26.5f;
|
||||
for (m = 0; m < PS_AP_LINKS; m++) {
|
||||
theta = -M_PI * fractional_delay_links[m] * f_center;
|
||||
Q_fract_allpass[1][k][m][0] = cos(theta);
|
||||
Q_fract_allpass[1][k][m][1] = sin(theta);
|
||||
}
|
||||
theta = -M_PI*fractional_delay_gain*f_center;
|
||||
phi_fract[1][k][0] = cos(theta);
|
||||
phi_fract[1][k][1] = sin(theta);
|
||||
}
|
||||
|
||||
make_filters_from_proto(f20_0_8, g0_Q8, 8);
|
||||
make_filters_from_proto(f34_0_12, g0_Q12, 12);
|
||||
make_filters_from_proto(f34_1_8, g1_Q8, 8);
|
||||
make_filters_from_proto(f34_2_4, g2_Q4, 4);
|
||||
}
|
||||
#endif /* CONFIG_HARDCODED_TABLES */
|
||||
|
||||
#endif /* AACPS_TABLEGEN_H */
|
|
@ -1,163 +0,0 @@
|
|||
/*
|
||||
* MPEG-4 Parametric Stereo data tables
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
static const uint8_t huff_iid_df1_bits[] = {
|
||||
18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 17, 17, 16, 16, 15, 14, 14,
|
||||
13, 12, 12, 11, 10, 10, 8, 7, 6, 5, 4, 3, 1, 3, 4, 5, 6, 7,
|
||||
8, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 16, 17, 17, 18, 17, 18, 18,
|
||||
18, 18, 18, 18, 18, 18, 18,
|
||||
};
|
||||
|
||||
static const uint32_t huff_iid_df1_codes[] = {
|
||||
0x01FEB4, 0x01FEB5, 0x01FD76, 0x01FD77, 0x01FD74, 0x01FD75, 0x01FE8A,
|
||||
0x01FE8B, 0x01FE88, 0x00FE80, 0x01FEB6, 0x00FE82, 0x00FEB8, 0x007F42,
|
||||
0x007FAE, 0x003FAF, 0x001FD1, 0x001FE9, 0x000FE9, 0x0007EA, 0x0007FB,
|
||||
0x0003FB, 0x0001FB, 0x0001FF, 0x00007C, 0x00003C, 0x00001C, 0x00000C,
|
||||
0x000000, 0x000001, 0x000001, 0x000002, 0x000001, 0x00000D, 0x00001D,
|
||||
0x00003D, 0x00007D, 0x0000FC, 0x0001FC, 0x0003FC, 0x0003F4, 0x0007EB,
|
||||
0x000FEA, 0x001FEA, 0x001FD6, 0x003FD0, 0x007FAF, 0x007F43, 0x00FEB9,
|
||||
0x00FE83, 0x01FEB7, 0x00FE81, 0x01FE89, 0x01FE8E, 0x01FE8F, 0x01FE8C,
|
||||
0x01FE8D, 0x01FEB2, 0x01FEB3, 0x01FEB0, 0x01FEB1,
|
||||
};
|
||||
|
||||
static const uint8_t huff_iid_dt1_bits[] = {
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 13,
|
||||
13, 13, 12, 12, 11, 10, 9, 9, 7, 6, 5, 3, 1, 2, 5, 6, 7, 8,
|
||||
9, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16,
|
||||
};
|
||||
|
||||
static const uint16_t huff_iid_dt1_codes[] = {
|
||||
0x004ED4, 0x004ED5, 0x004ECE, 0x004ECF, 0x004ECC, 0x004ED6, 0x004ED8,
|
||||
0x004F46, 0x004F60, 0x002718, 0x002719, 0x002764, 0x002765, 0x00276D,
|
||||
0x0027B1, 0x0013B7, 0x0013D6, 0x0009C7, 0x0009E9, 0x0009ED, 0x0004EE,
|
||||
0x0004F7, 0x000278, 0x000139, 0x00009A, 0x00009F, 0x000020, 0x000011,
|
||||
0x00000A, 0x000003, 0x000001, 0x000000, 0x00000B, 0x000012, 0x000021,
|
||||
0x00004C, 0x00009B, 0x00013A, 0x000279, 0x000270, 0x0004EF, 0x0004E2,
|
||||
0x0009EA, 0x0009D8, 0x0013D7, 0x0013D0, 0x0027B2, 0x0027A2, 0x00271A,
|
||||
0x00271B, 0x004F66, 0x004F67, 0x004F61, 0x004F47, 0x004ED9, 0x004ED7,
|
||||
0x004ECD, 0x004ED2, 0x004ED3, 0x004ED0, 0x004ED1,
|
||||
};
|
||||
|
||||
static const uint8_t huff_iid_df0_bits[] = {
|
||||
17, 17, 17, 17, 16, 15, 13, 10, 9, 7, 6, 5, 4, 3, 1, 3, 4, 5,
|
||||
6, 6, 8, 11, 13, 14, 14, 15, 17, 18, 18,
|
||||
};
|
||||
|
||||
static const uint32_t huff_iid_df0_codes[] = {
|
||||
0x01FFFB, 0x01FFFC, 0x01FFFD, 0x01FFFA, 0x00FFFC, 0x007FFC, 0x001FFD,
|
||||
0x0003FE, 0x0001FE, 0x00007E, 0x00003C, 0x00001D, 0x00000D, 0x000005,
|
||||
0x000000, 0x000004, 0x00000C, 0x00001C, 0x00003D, 0x00003E, 0x0000FE,
|
||||
0x0007FE, 0x001FFC, 0x003FFC, 0x003FFD, 0x007FFD, 0x01FFFE, 0x03FFFE,
|
||||
0x03FFFF,
|
||||
};
|
||||
|
||||
static const uint8_t huff_iid_dt0_bits[] = {
|
||||
19, 19, 19, 20, 20, 20, 17, 15, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7,
|
||||
9, 11, 13, 14, 17, 19, 20, 20, 20, 20, 20,
|
||||
};
|
||||
|
||||
static const uint32_t huff_iid_dt0_codes[] = {
|
||||
0x07FFF9, 0x07FFFA, 0x07FFFB, 0x0FFFF8, 0x0FFFF9, 0x0FFFFA, 0x01FFFD,
|
||||
0x007FFE, 0x000FFE, 0x0003FE, 0x0000FE, 0x00003E, 0x00000E, 0x000002,
|
||||
0x000000, 0x000006, 0x00001E, 0x00007E, 0x0001FE, 0x0007FE, 0x001FFE,
|
||||
0x003FFE, 0x01FFFC, 0x07FFF8, 0x0FFFFB, 0x0FFFFC, 0x0FFFFD, 0x0FFFFE,
|
||||
0x0FFFFF,
|
||||
};
|
||||
|
||||
static const uint8_t huff_icc_df_bits[] = {
|
||||
14, 14, 12, 10, 7, 5, 3, 1, 2, 4, 6, 8, 9, 11, 13,
|
||||
};
|
||||
|
||||
static const uint16_t huff_icc_df_codes[] = {
|
||||
0x3FFF, 0x3FFE, 0x0FFE, 0x03FE, 0x007E, 0x001E, 0x0006, 0x0000,
|
||||
0x0002, 0x000E, 0x003E, 0x00FE, 0x01FE, 0x07FE, 0x1FFE,
|
||||
};
|
||||
|
||||
static const uint8_t huff_icc_dt_bits[] = {
|
||||
14, 13, 11, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14,
|
||||
};
|
||||
|
||||
static const uint16_t huff_icc_dt_codes[] = {
|
||||
0x3FFE, 0x1FFE, 0x07FE, 0x01FE, 0x007E, 0x001E, 0x0006, 0x0000,
|
||||
0x0002, 0x000E, 0x003E, 0x00FE, 0x03FE, 0x0FFE, 0x3FFF,
|
||||
};
|
||||
|
||||
static const uint8_t huff_ipd_df_bits[] = {
|
||||
1, 3, 4, 4, 4, 4, 4, 4,
|
||||
};
|
||||
|
||||
static const uint8_t huff_ipd_df_codes[] = {
|
||||
0x01, 0x00, 0x06, 0x04, 0x02, 0x03, 0x05, 0x07,
|
||||
};
|
||||
|
||||
static const uint8_t huff_ipd_dt_bits[] = {
|
||||
1, 3, 4, 5, 5, 4, 4, 3,
|
||||
};
|
||||
|
||||
static const uint8_t huff_ipd_dt_codes[] = {
|
||||
0x01, 0x02, 0x02, 0x03, 0x02, 0x00, 0x03, 0x03,
|
||||
};
|
||||
|
||||
static const uint8_t huff_opd_df_bits[] = {
|
||||
1, 3, 4, 4, 5, 5, 4, 3,
|
||||
};
|
||||
|
||||
static const uint8_t huff_opd_df_codes[] = {
|
||||
0x01, 0x01, 0x06, 0x04, 0x0F, 0x0E, 0x05, 0x00,
|
||||
};
|
||||
|
||||
static const uint8_t huff_opd_dt_bits[] = {
|
||||
1, 3, 4, 5, 5, 4, 4, 3,
|
||||
};
|
||||
|
||||
static const uint8_t huff_opd_dt_codes[] = {
|
||||
0x01, 0x02, 0x01, 0x07, 0x06, 0x00, 0x02, 0x03,
|
||||
};
|
||||
|
||||
static const int8_t huff_offset[] = {
|
||||
30, 30,
|
||||
14, 14,
|
||||
7, 7,
|
||||
0, 0,
|
||||
0, 0,
|
||||
};
|
||||
|
||||
///Table 8.48
|
||||
static const int8_t k_to_i_20[] = {
|
||||
1, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14, 15,
|
||||
15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18,
|
||||
18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19
|
||||
};
|
||||
///Table 8.49
|
||||
static const int8_t k_to_i_34[] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 6, 7, 2, 1, 0, 10, 10, 4, 5, 6, 7, 8,
|
||||
9, 10, 11, 12, 9, 14, 11, 12, 13, 14, 15, 16, 13, 16, 17, 18, 19, 20, 21,
|
||||
22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29,
|
||||
30, 30, 30, 31, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 33,
|
||||
33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33
|
||||
};
|
||||
|
||||
static const float g1_Q2[] = {
|
||||
0.0f, 0.01899487526049f, 0.0f, -0.07293139167538f,
|
||||
0.0f, 0.30596630545168f, 0.5f
|
||||
};
|
|
@ -1,216 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "libavutil/attributes.h"
|
||||
#include "aacpsdsp.h"
|
||||
|
||||
static void ps_add_squares_c(float *dst, const float (*src)[2], int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; i++)
|
||||
dst[i] += src[i][0] * src[i][0] + src[i][1] * src[i][1];
|
||||
}
|
||||
|
||||
static void ps_mul_pair_single_c(float (*dst)[2], float (*src0)[2], float *src1,
|
||||
int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
dst[i][0] = src0[i][0] * src1[i];
|
||||
dst[i][1] = src0[i][1] * src1[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void ps_hybrid_analysis_c(float (*out)[2], float (*in)[2],
|
||||
const float (*filter)[8][2],
|
||||
int stride, int n)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
float sum_re = filter[i][6][0] * in[6][0];
|
||||
float sum_im = filter[i][6][0] * in[6][1];
|
||||
|
||||
for (j = 0; j < 6; j++) {
|
||||
float in0_re = in[j][0];
|
||||
float in0_im = in[j][1];
|
||||
float in1_re = in[12-j][0];
|
||||
float in1_im = in[12-j][1];
|
||||
sum_re += filter[i][j][0] * (in0_re + in1_re) -
|
||||
filter[i][j][1] * (in0_im - in1_im);
|
||||
sum_im += filter[i][j][0] * (in0_im + in1_im) +
|
||||
filter[i][j][1] * (in0_re - in1_re);
|
||||
}
|
||||
out[i * stride][0] = sum_re;
|
||||
out[i * stride][1] = sum_im;
|
||||
}
|
||||
}
|
||||
|
||||
static void ps_hybrid_analysis_ileave_c(float (*out)[32][2], float L[2][38][64],
|
||||
int i, int len)
|
||||
{
|
||||
int j;
|
||||
|
||||
for (; i < 64; i++) {
|
||||
for (j = 0; j < len; j++) {
|
||||
out[i][j][0] = L[0][j][i];
|
||||
out[i][j][1] = L[1][j][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ps_hybrid_synthesis_deint_c(float out[2][38][64],
|
||||
float (*in)[32][2],
|
||||
int i, int len)
|
||||
{
|
||||
int n;
|
||||
|
||||
for (; i < 64; i++) {
|
||||
for (n = 0; n < len; n++) {
|
||||
out[0][n][i] = in[i][n][0];
|
||||
out[1][n][i] = in[i][n][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ps_decorrelate_c(float (*out)[2], float (*delay)[2],
|
||||
float (*ap_delay)[PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2],
|
||||
const float phi_fract[2], const float (*Q_fract)[2],
|
||||
const float *transient_gain,
|
||||
float g_decay_slope,
|
||||
int len)
|
||||
{
|
||||
static const float a[] = { 0.65143905753106f,
|
||||
0.56471812200776f,
|
||||
0.48954165955695f };
|
||||
float ag[PS_AP_LINKS];
|
||||
int m, n;
|
||||
|
||||
for (m = 0; m < PS_AP_LINKS; m++)
|
||||
ag[m] = a[m] * g_decay_slope;
|
||||
|
||||
for (n = 0; n < len; n++) {
|
||||
float in_re = delay[n][0] * phi_fract[0] - delay[n][1] * phi_fract[1];
|
||||
float in_im = delay[n][0] * phi_fract[1] + delay[n][1] * phi_fract[0];
|
||||
for (m = 0; m < PS_AP_LINKS; m++) {
|
||||
float a_re = ag[m] * in_re;
|
||||
float a_im = ag[m] * in_im;
|
||||
float link_delay_re = ap_delay[m][n+2-m][0];
|
||||
float link_delay_im = ap_delay[m][n+2-m][1];
|
||||
float fractional_delay_re = Q_fract[m][0];
|
||||
float fractional_delay_im = Q_fract[m][1];
|
||||
float apd_re = in_re;
|
||||
float apd_im = in_im;
|
||||
in_re = link_delay_re * fractional_delay_re -
|
||||
link_delay_im * fractional_delay_im - a_re;
|
||||
in_im = link_delay_re * fractional_delay_im +
|
||||
link_delay_im * fractional_delay_re - a_im;
|
||||
ap_delay[m][n+5][0] = apd_re + ag[m] * in_re;
|
||||
ap_delay[m][n+5][1] = apd_im + ag[m] * in_im;
|
||||
}
|
||||
out[n][0] = transient_gain[n] * in_re;
|
||||
out[n][1] = transient_gain[n] * in_im;
|
||||
}
|
||||
}
|
||||
|
||||
static void ps_stereo_interpolate_c(float (*l)[2], float (*r)[2],
|
||||
float h[2][4], float h_step[2][4],
|
||||
int len)
|
||||
{
|
||||
float h0 = h[0][0];
|
||||
float h1 = h[0][1];
|
||||
float h2 = h[0][2];
|
||||
float h3 = h[0][3];
|
||||
float hs0 = h_step[0][0];
|
||||
float hs1 = h_step[0][1];
|
||||
float hs2 = h_step[0][2];
|
||||
float hs3 = h_step[0][3];
|
||||
int n;
|
||||
|
||||
for (n = 0; n < len; n++) {
|
||||
//l is s, r is d
|
||||
float l_re = l[n][0];
|
||||
float l_im = l[n][1];
|
||||
float r_re = r[n][0];
|
||||
float r_im = r[n][1];
|
||||
h0 += hs0;
|
||||
h1 += hs1;
|
||||
h2 += hs2;
|
||||
h3 += hs3;
|
||||
l[n][0] = h0 * l_re + h2 * r_re;
|
||||
l[n][1] = h0 * l_im + h2 * r_im;
|
||||
r[n][0] = h1 * l_re + h3 * r_re;
|
||||
r[n][1] = h1 * l_im + h3 * r_im;
|
||||
}
|
||||
}
|
||||
|
||||
static void ps_stereo_interpolate_ipdopd_c(float (*l)[2], float (*r)[2],
|
||||
float h[2][4], float h_step[2][4],
|
||||
int len)
|
||||
{
|
||||
float h00 = h[0][0], h10 = h[1][0];
|
||||
float h01 = h[0][1], h11 = h[1][1];
|
||||
float h02 = h[0][2], h12 = h[1][2];
|
||||
float h03 = h[0][3], h13 = h[1][3];
|
||||
float hs00 = h_step[0][0], hs10 = h_step[1][0];
|
||||
float hs01 = h_step[0][1], hs11 = h_step[1][1];
|
||||
float hs02 = h_step[0][2], hs12 = h_step[1][2];
|
||||
float hs03 = h_step[0][3], hs13 = h_step[1][3];
|
||||
int n;
|
||||
|
||||
for (n = 0; n < len; n++) {
|
||||
//l is s, r is d
|
||||
float l_re = l[n][0];
|
||||
float l_im = l[n][1];
|
||||
float r_re = r[n][0];
|
||||
float r_im = r[n][1];
|
||||
h00 += hs00;
|
||||
h01 += hs01;
|
||||
h02 += hs02;
|
||||
h03 += hs03;
|
||||
h10 += hs10;
|
||||
h11 += hs11;
|
||||
h12 += hs12;
|
||||
h13 += hs13;
|
||||
|
||||
l[n][0] = h00 * l_re + h02 * r_re - h10 * l_im - h12 * r_im;
|
||||
l[n][1] = h00 * l_im + h02 * r_im + h10 * l_re + h12 * r_re;
|
||||
r[n][0] = h01 * l_re + h03 * r_re - h11 * l_im - h13 * r_im;
|
||||
r[n][1] = h01 * l_im + h03 * r_im + h11 * l_re + h13 * r_re;
|
||||
}
|
||||
}
|
||||
|
||||
av_cold void ff_psdsp_init(PSDSPContext *s)
|
||||
{
|
||||
s->add_squares = ps_add_squares_c;
|
||||
s->mul_pair_single = ps_mul_pair_single_c;
|
||||
s->hybrid_analysis = ps_hybrid_analysis_c;
|
||||
s->hybrid_analysis_ileave = ps_hybrid_analysis_ileave_c;
|
||||
s->hybrid_synthesis_deint = ps_hybrid_synthesis_deint_c;
|
||||
s->decorrelate = ps_decorrelate_c;
|
||||
s->stereo_interpolate[0] = ps_stereo_interpolate_c;
|
||||
s->stereo_interpolate[1] = ps_stereo_interpolate_ipdopd_c;
|
||||
|
||||
if (ARCH_ARM)
|
||||
ff_psdsp_init_arm(s);
|
||||
if (ARCH_MIPS)
|
||||
ff_psdsp_init_mips(s);
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Mans Rullgard
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef LIBAVCODEC_AACPSDSP_H
|
||||
#define LIBAVCODEC_AACPSDSP_H
|
||||
|
||||
#define PS_QMF_TIME_SLOTS 32
|
||||
#define PS_AP_LINKS 3
|
||||
#define PS_MAX_AP_DELAY 5
|
||||
|
||||
typedef struct PSDSPContext {
|
||||
void (*add_squares)(float *dst, const float (*src)[2], int n);
|
||||
void (*mul_pair_single)(float (*dst)[2], float (*src0)[2], float *src1,
|
||||
int n);
|
||||
void (*hybrid_analysis)(float (*out)[2], float (*in)[2],
|
||||
const float (*filter)[8][2],
|
||||
int stride, int n);
|
||||
void (*hybrid_analysis_ileave)(float (*out)[32][2], float L[2][38][64],
|
||||
int i, int len);
|
||||
void (*hybrid_synthesis_deint)(float out[2][38][64], float (*in)[32][2],
|
||||
int i, int len);
|
||||
void (*decorrelate)(float (*out)[2], float (*delay)[2],
|
||||
float (*ap_delay)[PS_QMF_TIME_SLOTS+PS_MAX_AP_DELAY][2],
|
||||
const float phi_fract[2], const float (*Q_fract)[2],
|
||||
const float *transient_gain,
|
||||
float g_decay_slope,
|
||||
int len);
|
||||
void (*stereo_interpolate[2])(float (*l)[2], float (*r)[2],
|
||||
float h[2][4], float h_step[2][4],
|
||||
int len);
|
||||
} PSDSPContext;
|
||||
|
||||
void ff_psdsp_init(PSDSPContext *s);
|
||||
void ff_psdsp_init_arm(PSDSPContext *s);
|
||||
void ff_psdsp_init_mips(PSDSPContext *s);
|
||||
|
||||
#endif /* LIBAVCODEC_AACPSDSP_H */
|
|
@ -1,965 +0,0 @@
|
|||
/*
|
||||
* AAC encoder psychoacoustic model
|
||||
* Copyright (C) 2008 Konstantin Shishkov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* AAC encoder psychoacoustic model
|
||||
*/
|
||||
|
||||
#include "libavutil/attributes.h"
|
||||
#include "libavutil/libm.h"
|
||||
|
||||
#include "avcodec.h"
|
||||
#include "aactab.h"
|
||||
#include "psymodel.h"
|
||||
|
||||
/***********************************
|
||||
* TODOs:
|
||||
* try other bitrate controlling mechanism (maybe use ratecontrol.c?)
|
||||
* control quality for quality-based output
|
||||
**********************************/
|
||||
|
||||
/**
|
||||
* constants for 3GPP AAC psychoacoustic model
|
||||
* @{
|
||||
*/
|
||||
#define PSY_3GPP_THR_SPREAD_HI 1.5f // spreading factor for low-to-hi threshold spreading (15 dB/Bark)
|
||||
#define PSY_3GPP_THR_SPREAD_LOW 3.0f // spreading factor for hi-to-low threshold spreading (30 dB/Bark)
|
||||
/* spreading factor for low-to-hi energy spreading, long block, > 22kbps/channel (20dB/Bark) */
|
||||
#define PSY_3GPP_EN_SPREAD_HI_L1 2.0f
|
||||
/* spreading factor for low-to-hi energy spreading, long block, <= 22kbps/channel (15dB/Bark) */
|
||||
#define PSY_3GPP_EN_SPREAD_HI_L2 1.5f
|
||||
/* spreading factor for low-to-hi energy spreading, short block (15 dB/Bark) */
|
||||
#define PSY_3GPP_EN_SPREAD_HI_S 1.5f
|
||||
/* spreading factor for hi-to-low energy spreading, long block (30dB/Bark) */
|
||||
#define PSY_3GPP_EN_SPREAD_LOW_L 3.0f
|
||||
/* spreading factor for hi-to-low energy spreading, short block (20dB/Bark) */
|
||||
#define PSY_3GPP_EN_SPREAD_LOW_S 2.0f
|
||||
|
||||
#define PSY_3GPP_RPEMIN 0.01f
|
||||
#define PSY_3GPP_RPELEV 2.0f
|
||||
|
||||
#define PSY_3GPP_C1 3.0f /* log2(8) */
|
||||
#define PSY_3GPP_C2 1.3219281f /* log2(2.5) */
|
||||
#define PSY_3GPP_C3 0.55935729f /* 1 - C2 / C1 */
|
||||
|
||||
#define PSY_SNR_1DB 7.9432821e-1f /* -1dB */
|
||||
#define PSY_SNR_25DB 3.1622776e-3f /* -25dB */
|
||||
|
||||
#define PSY_3GPP_SAVE_SLOPE_L -0.46666667f
|
||||
#define PSY_3GPP_SAVE_SLOPE_S -0.36363637f
|
||||
#define PSY_3GPP_SAVE_ADD_L -0.84285712f
|
||||
#define PSY_3GPP_SAVE_ADD_S -0.75f
|
||||
#define PSY_3GPP_SPEND_SLOPE_L 0.66666669f
|
||||
#define PSY_3GPP_SPEND_SLOPE_S 0.81818181f
|
||||
#define PSY_3GPP_SPEND_ADD_L -0.35f
|
||||
#define PSY_3GPP_SPEND_ADD_S -0.26111111f
|
||||
#define PSY_3GPP_CLIP_LO_L 0.2f
|
||||
#define PSY_3GPP_CLIP_LO_S 0.2f
|
||||
#define PSY_3GPP_CLIP_HI_L 0.95f
|
||||
#define PSY_3GPP_CLIP_HI_S 0.75f
|
||||
|
||||
#define PSY_3GPP_AH_THR_LONG 0.5f
|
||||
#define PSY_3GPP_AH_THR_SHORT 0.63f
|
||||
|
||||
enum {
|
||||
PSY_3GPP_AH_NONE,
|
||||
PSY_3GPP_AH_INACTIVE,
|
||||
PSY_3GPP_AH_ACTIVE
|
||||
};
|
||||
|
||||
#define PSY_3GPP_BITS_TO_PE(bits) ((bits) * 1.18f)
|
||||
|
||||
/* LAME psy model constants */
|
||||
#define PSY_LAME_FIR_LEN 21 ///< LAME psy model FIR order
|
||||
#define AAC_BLOCK_SIZE_LONG 1024 ///< long block size
|
||||
#define AAC_BLOCK_SIZE_SHORT 128 ///< short block size
|
||||
#define AAC_NUM_BLOCKS_SHORT 8 ///< number of blocks in a short sequence
|
||||
#define PSY_LAME_NUM_SUBBLOCKS 3 ///< Number of sub-blocks in each short block
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* information for single band used by 3GPP TS26.403-inspired psychoacoustic model
|
||||
*/
|
||||
typedef struct AacPsyBand{
|
||||
float energy; ///< band energy
|
||||
float thr; ///< energy threshold
|
||||
float thr_quiet; ///< threshold in quiet
|
||||
float nz_lines; ///< number of non-zero spectral lines
|
||||
float active_lines; ///< number of active spectral lines
|
||||
float pe; ///< perceptual entropy
|
||||
float pe_const; ///< constant part of the PE calculation
|
||||
float norm_fac; ///< normalization factor for linearization
|
||||
int avoid_holes; ///< hole avoidance flag
|
||||
}AacPsyBand;
|
||||
|
||||
/**
|
||||
* single/pair channel context for psychoacoustic model
|
||||
*/
|
||||
typedef struct AacPsyChannel{
|
||||
AacPsyBand band[128]; ///< bands information
|
||||
AacPsyBand prev_band[128]; ///< bands information from the previous frame
|
||||
|
||||
float win_energy; ///< sliding average of channel energy
|
||||
float iir_state[2]; ///< hi-pass IIR filter state
|
||||
uint8_t next_grouping; ///< stored grouping scheme for the next frame (in case of 8 short window sequence)
|
||||
enum WindowSequence next_window_seq; ///< window sequence to be used in the next frame
|
||||
/* LAME psy model specific members */
|
||||
float attack_threshold; ///< attack threshold for this channel
|
||||
float prev_energy_subshort[AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS];
|
||||
int prev_attack; ///< attack value for the last short block in the previous sequence
|
||||
}AacPsyChannel;
|
||||
|
||||
/**
|
||||
* psychoacoustic model frame type-dependent coefficients
|
||||
*/
|
||||
typedef struct AacPsyCoeffs{
|
||||
float ath; ///< absolute threshold of hearing per bands
|
||||
float barks; ///< Bark value for each spectral band in long frame
|
||||
float spread_low[2]; ///< spreading factor for low-to-high threshold spreading in long frame
|
||||
float spread_hi [2]; ///< spreading factor for high-to-low threshold spreading in long frame
|
||||
float min_snr; ///< minimal SNR
|
||||
}AacPsyCoeffs;
|
||||
|
||||
/**
|
||||
* 3GPP TS26.403-inspired psychoacoustic model specific data
|
||||
*/
|
||||
typedef struct AacPsyContext{
|
||||
int chan_bitrate; ///< bitrate per channel
|
||||
int frame_bits; ///< average bits per frame
|
||||
int fill_level; ///< bit reservoir fill level
|
||||
struct {
|
||||
float min; ///< minimum allowed PE for bit factor calculation
|
||||
float max; ///< maximum allowed PE for bit factor calculation
|
||||
float previous; ///< allowed PE of the previous frame
|
||||
float correction; ///< PE correction factor
|
||||
} pe;
|
||||
AacPsyCoeffs psy_coef[2][64];
|
||||
AacPsyChannel *ch;
|
||||
}AacPsyContext;
|
||||
|
||||
/**
|
||||
* LAME psy model preset struct
|
||||
*/
|
||||
typedef struct {
|
||||
int quality; ///< Quality to map the rest of the vaules to.
|
||||
/* This is overloaded to be both kbps per channel in ABR mode, and
|
||||
* requested quality in constant quality mode.
|
||||
*/
|
||||
float st_lrm; ///< short threshold for L, R, and M channels
|
||||
} PsyLamePreset;
|
||||
|
||||
/**
|
||||
* LAME psy model preset table for ABR
|
||||
*/
|
||||
static const PsyLamePreset psy_abr_map[] = {
|
||||
/* TODO: Tuning. These were taken from LAME. */
|
||||
/* kbps/ch st_lrm */
|
||||
{ 8, 6.60},
|
||||
{ 16, 6.60},
|
||||
{ 24, 6.60},
|
||||
{ 32, 6.60},
|
||||
{ 40, 6.60},
|
||||
{ 48, 6.60},
|
||||
{ 56, 6.60},
|
||||
{ 64, 6.40},
|
||||
{ 80, 6.00},
|
||||
{ 96, 5.60},
|
||||
{112, 5.20},
|
||||
{128, 5.20},
|
||||
{160, 5.20}
|
||||
};
|
||||
|
||||
/**
|
||||
* LAME psy model preset table for constant quality
|
||||
*/
|
||||
static const PsyLamePreset psy_vbr_map[] = {
|
||||
/* vbr_q st_lrm */
|
||||
{ 0, 4.20},
|
||||
{ 1, 4.20},
|
||||
{ 2, 4.20},
|
||||
{ 3, 4.20},
|
||||
{ 4, 4.20},
|
||||
{ 5, 4.20},
|
||||
{ 6, 4.20},
|
||||
{ 7, 4.20},
|
||||
{ 8, 4.20},
|
||||
{ 9, 4.20},
|
||||
{10, 4.20}
|
||||
};
|
||||
|
||||
/**
|
||||
* LAME psy model FIR coefficient table
|
||||
*/
|
||||
static const float psy_fir_coeffs[] = {
|
||||
-8.65163e-18 * 2, -0.00851586 * 2, -6.74764e-18 * 2, 0.0209036 * 2,
|
||||
-3.36639e-17 * 2, -0.0438162 * 2, -1.54175e-17 * 2, 0.0931738 * 2,
|
||||
-5.52212e-17 * 2, -0.313819 * 2
|
||||
};
|
||||
|
||||
#if ARCH_MIPS
|
||||
# include "mips/aacpsy_mips.h"
|
||||
#endif /* ARCH_MIPS */
|
||||
|
||||
/**
|
||||
* Calculate the ABR attack threshold from the above LAME psymodel table.
|
||||
*/
|
||||
static float lame_calc_attack_threshold(int bitrate)
|
||||
{
|
||||
/* Assume max bitrate to start with */
|
||||
int lower_range = 12, upper_range = 12;
|
||||
int lower_range_kbps = psy_abr_map[12].quality;
|
||||
int upper_range_kbps = psy_abr_map[12].quality;
|
||||
int i;
|
||||
|
||||
/* Determine which bitrates the value specified falls between.
|
||||
* If the loop ends without breaking our above assumption of 320kbps was correct.
|
||||
*/
|
||||
for (i = 1; i < 13; i++) {
|
||||
if (FFMAX(bitrate, psy_abr_map[i].quality) != bitrate) {
|
||||
upper_range = i;
|
||||
upper_range_kbps = psy_abr_map[i ].quality;
|
||||
lower_range = i - 1;
|
||||
lower_range_kbps = psy_abr_map[i - 1].quality;
|
||||
break; /* Upper range found */
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine which range the value specified is closer to */
|
||||
if ((upper_range_kbps - bitrate) > (bitrate - lower_range_kbps))
|
||||
return psy_abr_map[lower_range].st_lrm;
|
||||
return psy_abr_map[upper_range].st_lrm;
|
||||
}
|
||||
|
||||
/**
|
||||
* LAME psy model specific initialization
|
||||
*/
|
||||
static av_cold void lame_window_init(AacPsyContext *ctx, AVCodecContext *avctx)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < avctx->channels; i++) {
|
||||
AacPsyChannel *pch = &ctx->ch[i];
|
||||
|
||||
if (avctx->flags & CODEC_FLAG_QSCALE)
|
||||
pch->attack_threshold = psy_vbr_map[avctx->global_quality / FF_QP2LAMBDA].st_lrm;
|
||||
else
|
||||
pch->attack_threshold = lame_calc_attack_threshold(avctx->bit_rate / avctx->channels / 1000);
|
||||
|
||||
for (j = 0; j < AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS; j++)
|
||||
pch->prev_energy_subshort[j] = 10.0f;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bark value for given line.
|
||||
*/
|
||||
static av_cold float calc_bark(float f)
|
||||
{
|
||||
return 13.3f * atanf(0.00076f * f) + 3.5f * atanf((f / 7500.0f) * (f / 7500.0f));
|
||||
}
|
||||
|
||||
#define ATH_ADD 4
|
||||
/**
|
||||
* Calculate ATH value for given frequency.
|
||||
* Borrowed from Lame.
|
||||
*/
|
||||
static av_cold float ath(float f, float add)
|
||||
{
|
||||
f /= 1000.0f;
|
||||
return 3.64 * pow(f, -0.8)
|
||||
- 6.8 * exp(-0.6 * (f - 3.4) * (f - 3.4))
|
||||
+ 6.0 * exp(-0.15 * (f - 8.7) * (f - 8.7))
|
||||
+ (0.6 + 0.04 * add) * 0.001 * f * f * f * f;
|
||||
}
|
||||
|
||||
static av_cold int psy_3gpp_init(FFPsyContext *ctx) {
|
||||
AacPsyContext *pctx;
|
||||
float bark;
|
||||
int i, j, g, start;
|
||||
float prev, minscale, minath, minsnr, pe_min;
|
||||
const int chan_bitrate = ctx->avctx->bit_rate / ctx->avctx->channels;
|
||||
const int bandwidth = ctx->avctx->cutoff ? ctx->avctx->cutoff : AAC_CUTOFF(ctx->avctx);
|
||||
const float num_bark = calc_bark((float)bandwidth);
|
||||
|
||||
ctx->model_priv_data = av_mallocz(sizeof(AacPsyContext));
|
||||
pctx = (AacPsyContext*) ctx->model_priv_data;
|
||||
|
||||
pctx->chan_bitrate = chan_bitrate;
|
||||
pctx->frame_bits = chan_bitrate * AAC_BLOCK_SIZE_LONG / ctx->avctx->sample_rate;
|
||||
pctx->pe.min = 8.0f * AAC_BLOCK_SIZE_LONG * bandwidth / (ctx->avctx->sample_rate * 2.0f);
|
||||
pctx->pe.max = 12.0f * AAC_BLOCK_SIZE_LONG * bandwidth / (ctx->avctx->sample_rate * 2.0f);
|
||||
ctx->bitres.size = 6144 - pctx->frame_bits;
|
||||
ctx->bitres.size -= ctx->bitres.size % 8;
|
||||
pctx->fill_level = ctx->bitres.size;
|
||||
minath = ath(3410, ATH_ADD);
|
||||
for (j = 0; j < 2; j++) {
|
||||
AacPsyCoeffs *coeffs = pctx->psy_coef[j];
|
||||
const uint8_t *band_sizes = ctx->bands[j];
|
||||
float line_to_frequency = ctx->avctx->sample_rate / (j ? 256.f : 2048.0f);
|
||||
float avg_chan_bits = chan_bitrate * (j ? 128.0f : 1024.0f) / ctx->avctx->sample_rate;
|
||||
/* reference encoder uses 2.4% here instead of 60% like the spec says */
|
||||
float bark_pe = 0.024f * PSY_3GPP_BITS_TO_PE(avg_chan_bits) / num_bark;
|
||||
float en_spread_low = j ? PSY_3GPP_EN_SPREAD_LOW_S : PSY_3GPP_EN_SPREAD_LOW_L;
|
||||
/* High energy spreading for long blocks <= 22kbps/channel and short blocks are the same. */
|
||||
float en_spread_hi = (j || (chan_bitrate <= 22.0f)) ? PSY_3GPP_EN_SPREAD_HI_S : PSY_3GPP_EN_SPREAD_HI_L1;
|
||||
|
||||
i = 0;
|
||||
prev = 0.0;
|
||||
for (g = 0; g < ctx->num_bands[j]; g++) {
|
||||
i += band_sizes[g];
|
||||
bark = calc_bark((i-1) * line_to_frequency);
|
||||
coeffs[g].barks = (bark + prev) / 2.0;
|
||||
prev = bark;
|
||||
}
|
||||
for (g = 0; g < ctx->num_bands[j] - 1; g++) {
|
||||
AacPsyCoeffs *coeff = &coeffs[g];
|
||||
float bark_width = coeffs[g+1].barks - coeffs->barks;
|
||||
coeff->spread_low[0] = pow(10.0, -bark_width * PSY_3GPP_THR_SPREAD_LOW);
|
||||
coeff->spread_hi [0] = pow(10.0, -bark_width * PSY_3GPP_THR_SPREAD_HI);
|
||||
coeff->spread_low[1] = pow(10.0, -bark_width * en_spread_low);
|
||||
coeff->spread_hi [1] = pow(10.0, -bark_width * en_spread_hi);
|
||||
pe_min = bark_pe * bark_width;
|
||||
minsnr = exp2(pe_min / band_sizes[g]) - 1.5f;
|
||||
coeff->min_snr = av_clipf(1.0f / minsnr, PSY_SNR_25DB, PSY_SNR_1DB);
|
||||
}
|
||||
start = 0;
|
||||
for (g = 0; g < ctx->num_bands[j]; g++) {
|
||||
minscale = ath(start * line_to_frequency, ATH_ADD);
|
||||
for (i = 1; i < band_sizes[g]; i++)
|
||||
minscale = FFMIN(minscale, ath((start + i) * line_to_frequency, ATH_ADD));
|
||||
coeffs[g].ath = minscale - minath;
|
||||
start += band_sizes[g];
|
||||
}
|
||||
}
|
||||
|
||||
pctx->ch = av_mallocz(sizeof(AacPsyChannel) * ctx->avctx->channels);
|
||||
|
||||
lame_window_init(pctx, ctx->avctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* IIR filter used in block switching decision
|
||||
*/
|
||||
static float iir_filter(int in, float state[2])
|
||||
{
|
||||
float ret;
|
||||
|
||||
ret = 0.7548f * (in - state[0]) + 0.5095f * state[1];
|
||||
state[0] = in;
|
||||
state[1] = ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* window grouping information stored as bits (0 - new group, 1 - group continues)
|
||||
*/
|
||||
static const uint8_t window_grouping[9] = {
|
||||
0xB6, 0x6C, 0xD8, 0xB2, 0x66, 0xC6, 0x96, 0x36, 0x36
|
||||
};
|
||||
|
||||
/**
|
||||
* Tell encoder which window types to use.
|
||||
* @see 3GPP TS26.403 5.4.1 "Blockswitching"
|
||||
*/
|
||||
static av_unused FFPsyWindowInfo psy_3gpp_window(FFPsyContext *ctx,
|
||||
const int16_t *audio,
|
||||
const int16_t *la,
|
||||
int channel, int prev_type)
|
||||
{
|
||||
int i, j;
|
||||
int br = ctx->avctx->bit_rate / ctx->avctx->channels;
|
||||
int attack_ratio = br <= 16000 ? 18 : 10;
|
||||
AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data;
|
||||
AacPsyChannel *pch = &pctx->ch[channel];
|
||||
uint8_t grouping = 0;
|
||||
int next_type = pch->next_window_seq;
|
||||
FFPsyWindowInfo wi = { { 0 } };
|
||||
|
||||
if (la) {
|
||||
float s[8], v;
|
||||
int switch_to_eight = 0;
|
||||
float sum = 0.0, sum2 = 0.0;
|
||||
int attack_n = 0;
|
||||
int stay_short = 0;
|
||||
for (i = 0; i < 8; i++) {
|
||||
for (j = 0; j < 128; j++) {
|
||||
v = iir_filter(la[i*128+j], pch->iir_state);
|
||||
sum += v*v;
|
||||
}
|
||||
s[i] = sum;
|
||||
sum2 += sum;
|
||||
}
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (s[i] > pch->win_energy * attack_ratio) {
|
||||
attack_n = i + 1;
|
||||
switch_to_eight = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pch->win_energy = pch->win_energy*7/8 + sum2/64;
|
||||
|
||||
wi.window_type[1] = prev_type;
|
||||
switch (prev_type) {
|
||||
case ONLY_LONG_SEQUENCE:
|
||||
wi.window_type[0] = switch_to_eight ? LONG_START_SEQUENCE : ONLY_LONG_SEQUENCE;
|
||||
next_type = switch_to_eight ? EIGHT_SHORT_SEQUENCE : ONLY_LONG_SEQUENCE;
|
||||
break;
|
||||
case LONG_START_SEQUENCE:
|
||||
wi.window_type[0] = EIGHT_SHORT_SEQUENCE;
|
||||
grouping = pch->next_grouping;
|
||||
next_type = switch_to_eight ? EIGHT_SHORT_SEQUENCE : LONG_STOP_SEQUENCE;
|
||||
break;
|
||||
case LONG_STOP_SEQUENCE:
|
||||
wi.window_type[0] = switch_to_eight ? LONG_START_SEQUENCE : ONLY_LONG_SEQUENCE;
|
||||
next_type = switch_to_eight ? EIGHT_SHORT_SEQUENCE : ONLY_LONG_SEQUENCE;
|
||||
break;
|
||||
case EIGHT_SHORT_SEQUENCE:
|
||||
stay_short = next_type == EIGHT_SHORT_SEQUENCE || switch_to_eight;
|
||||
wi.window_type[0] = stay_short ? EIGHT_SHORT_SEQUENCE : LONG_STOP_SEQUENCE;
|
||||
grouping = next_type == EIGHT_SHORT_SEQUENCE ? pch->next_grouping : 0;
|
||||
next_type = switch_to_eight ? EIGHT_SHORT_SEQUENCE : LONG_STOP_SEQUENCE;
|
||||
break;
|
||||
}
|
||||
|
||||
pch->next_grouping = window_grouping[attack_n];
|
||||
pch->next_window_seq = next_type;
|
||||
} else {
|
||||
for (i = 0; i < 3; i++)
|
||||
wi.window_type[i] = prev_type;
|
||||
grouping = (prev_type == EIGHT_SHORT_SEQUENCE) ? window_grouping[0] : 0;
|
||||
}
|
||||
|
||||
wi.window_shape = 1;
|
||||
if (wi.window_type[0] != EIGHT_SHORT_SEQUENCE) {
|
||||
wi.num_windows = 1;
|
||||
wi.grouping[0] = 1;
|
||||
} else {
|
||||
int lastgrp = 0;
|
||||
wi.num_windows = 8;
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (!((grouping >> i) & 1))
|
||||
lastgrp = i;
|
||||
wi.grouping[lastgrp]++;
|
||||
}
|
||||
}
|
||||
|
||||
return wi;
|
||||
}
|
||||
|
||||
/* 5.6.1.2 "Calculation of Bit Demand" */
|
||||
static int calc_bit_demand(AacPsyContext *ctx, float pe, int bits, int size,
|
||||
int short_window)
|
||||
{
|
||||
const float bitsave_slope = short_window ? PSY_3GPP_SAVE_SLOPE_S : PSY_3GPP_SAVE_SLOPE_L;
|
||||
const float bitsave_add = short_window ? PSY_3GPP_SAVE_ADD_S : PSY_3GPP_SAVE_ADD_L;
|
||||
const float bitspend_slope = short_window ? PSY_3GPP_SPEND_SLOPE_S : PSY_3GPP_SPEND_SLOPE_L;
|
||||
const float bitspend_add = short_window ? PSY_3GPP_SPEND_ADD_S : PSY_3GPP_SPEND_ADD_L;
|
||||
const float clip_low = short_window ? PSY_3GPP_CLIP_LO_S : PSY_3GPP_CLIP_LO_L;
|
||||
const float clip_high = short_window ? PSY_3GPP_CLIP_HI_S : PSY_3GPP_CLIP_HI_L;
|
||||
float clipped_pe, bit_save, bit_spend, bit_factor, fill_level;
|
||||
|
||||
ctx->fill_level += ctx->frame_bits - bits;
|
||||
ctx->fill_level = av_clip(ctx->fill_level, 0, size);
|
||||
fill_level = av_clipf((float)ctx->fill_level / size, clip_low, clip_high);
|
||||
clipped_pe = av_clipf(pe, ctx->pe.min, ctx->pe.max);
|
||||
bit_save = (fill_level + bitsave_add) * bitsave_slope;
|
||||
assert(bit_save <= 0.3f && bit_save >= -0.05000001f);
|
||||
bit_spend = (fill_level + bitspend_add) * bitspend_slope;
|
||||
assert(bit_spend <= 0.5f && bit_spend >= -0.1f);
|
||||
/* The bit factor graph in the spec is obviously incorrect.
|
||||
* bit_spend + ((bit_spend - bit_spend))...
|
||||
* The reference encoder subtracts everything from 1, but also seems incorrect.
|
||||
* 1 - bit_save + ((bit_spend + bit_save))...
|
||||
* Hopefully below is correct.
|
||||
*/
|
||||
bit_factor = 1.0f - bit_save + ((bit_spend - bit_save) / (ctx->pe.max - ctx->pe.min)) * (clipped_pe - ctx->pe.min);
|
||||
/* NOTE: The reference encoder attempts to center pe max/min around the current pe. */
|
||||
ctx->pe.max = FFMAX(pe, ctx->pe.max);
|
||||
ctx->pe.min = FFMIN(pe, ctx->pe.min);
|
||||
|
||||
return FFMIN(ctx->frame_bits * bit_factor, ctx->frame_bits + size - bits);
|
||||
}
|
||||
|
||||
static float calc_pe_3gpp(AacPsyBand *band)
|
||||
{
|
||||
float pe, a;
|
||||
|
||||
band->pe = 0.0f;
|
||||
band->pe_const = 0.0f;
|
||||
band->active_lines = 0.0f;
|
||||
if (band->energy > band->thr) {
|
||||
a = log2f(band->energy);
|
||||
pe = a - log2f(band->thr);
|
||||
band->active_lines = band->nz_lines;
|
||||
if (pe < PSY_3GPP_C1) {
|
||||
pe = pe * PSY_3GPP_C3 + PSY_3GPP_C2;
|
||||
a = a * PSY_3GPP_C3 + PSY_3GPP_C2;
|
||||
band->active_lines *= PSY_3GPP_C3;
|
||||
}
|
||||
band->pe = pe * band->nz_lines;
|
||||
band->pe_const = a * band->nz_lines;
|
||||
}
|
||||
|
||||
return band->pe;
|
||||
}
|
||||
|
||||
static float calc_reduction_3gpp(float a, float desired_pe, float pe,
|
||||
float active_lines)
|
||||
{
|
||||
float thr_avg, reduction;
|
||||
|
||||
if(active_lines == 0.0)
|
||||
return 0;
|
||||
|
||||
thr_avg = exp2f((a - pe) / (4.0f * active_lines));
|
||||
reduction = exp2f((a - desired_pe) / (4.0f * active_lines)) - thr_avg;
|
||||
|
||||
return FFMAX(reduction, 0.0f);
|
||||
}
|
||||
|
||||
static float calc_reduced_thr_3gpp(AacPsyBand *band, float min_snr,
|
||||
float reduction)
|
||||
{
|
||||
float thr = band->thr;
|
||||
|
||||
if (band->energy > thr) {
|
||||
thr = sqrtf(thr);
|
||||
thr = sqrtf(thr) + reduction;
|
||||
thr *= thr;
|
||||
thr *= thr;
|
||||
|
||||
/* This deviates from the 3GPP spec to match the reference encoder.
|
||||
* It performs min(thr_reduced, max(thr, energy/min_snr)) only for bands
|
||||
* that have hole avoidance on (active or inactive). It always reduces the
|
||||
* threshold of bands with hole avoidance off.
|
||||
*/
|
||||
if (thr > band->energy * min_snr && band->avoid_holes != PSY_3GPP_AH_NONE) {
|
||||
thr = FFMAX(band->thr, band->energy * min_snr);
|
||||
band->avoid_holes = PSY_3GPP_AH_ACTIVE;
|
||||
}
|
||||
}
|
||||
|
||||
return thr;
|
||||
}
|
||||
|
||||
#ifndef calc_thr_3gpp
|
||||
static void calc_thr_3gpp(const FFPsyWindowInfo *wi, const int num_bands, AacPsyChannel *pch,
|
||||
const uint8_t *band_sizes, const float *coefs)
|
||||
{
|
||||
int i, w, g;
|
||||
int start = 0;
|
||||
for (w = 0; w < wi->num_windows*16; w += 16) {
|
||||
for (g = 0; g < num_bands; g++) {
|
||||
AacPsyBand *band = &pch->band[w+g];
|
||||
|
||||
float form_factor = 0.0f;
|
||||
float Temp;
|
||||
band->energy = 0.0f;
|
||||
for (i = 0; i < band_sizes[g]; i++) {
|
||||
band->energy += coefs[start+i] * coefs[start+i];
|
||||
form_factor += sqrtf(fabs(coefs[start+i]));
|
||||
}
|
||||
Temp = band->energy > 0 ? sqrtf((float)band_sizes[g] / band->energy) : 0;
|
||||
band->thr = band->energy * 0.001258925f;
|
||||
band->nz_lines = form_factor * sqrtf(Temp);
|
||||
|
||||
start += band_sizes[g];
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* calc_thr_3gpp */
|
||||
|
||||
#ifndef psy_hp_filter
|
||||
static void psy_hp_filter(const float *firbuf, float *hpfsmpl, const float *psy_fir_coeffs)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < AAC_BLOCK_SIZE_LONG; i++) {
|
||||
float sum1, sum2;
|
||||
sum1 = firbuf[i + (PSY_LAME_FIR_LEN - 1) / 2];
|
||||
sum2 = 0.0;
|
||||
for (j = 0; j < ((PSY_LAME_FIR_LEN - 1) / 2) - 1; j += 2) {
|
||||
sum1 += psy_fir_coeffs[j] * (firbuf[i + j] + firbuf[i + PSY_LAME_FIR_LEN - j]);
|
||||
sum2 += psy_fir_coeffs[j + 1] * (firbuf[i + j + 1] + firbuf[i + PSY_LAME_FIR_LEN - j - 1]);
|
||||
}
|
||||
/* NOTE: The LAME psymodel expects it's input in the range -32768 to 32768.
|
||||
* Tuning this for normalized floats would be difficult. */
|
||||
hpfsmpl[i] = (sum1 + sum2) * 32768.0f;
|
||||
}
|
||||
}
|
||||
#endif /* psy_hp_filter */
|
||||
|
||||
/**
|
||||
* Calculate band thresholds as suggested in 3GPP TS26.403
|
||||
*/
|
||||
static void psy_3gpp_analyze_channel(FFPsyContext *ctx, int channel,
|
||||
const float *coefs, const FFPsyWindowInfo *wi)
|
||||
{
|
||||
AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data;
|
||||
AacPsyChannel *pch = &pctx->ch[channel];
|
||||
int i, w, g;
|
||||
float desired_bits, desired_pe, delta_pe, reduction= NAN, spread_en[128] = {0};
|
||||
float a = 0.0f, active_lines = 0.0f, norm_fac = 0.0f;
|
||||
float pe = pctx->chan_bitrate > 32000 ? 0.0f : FFMAX(50.0f, 100.0f - pctx->chan_bitrate * 100.0f / 32000.0f);
|
||||
const int num_bands = ctx->num_bands[wi->num_windows == 8];
|
||||
const uint8_t *band_sizes = ctx->bands[wi->num_windows == 8];
|
||||
AacPsyCoeffs *coeffs = pctx->psy_coef[wi->num_windows == 8];
|
||||
const float avoid_hole_thr = wi->num_windows == 8 ? PSY_3GPP_AH_THR_SHORT : PSY_3GPP_AH_THR_LONG;
|
||||
|
||||
//calculate energies, initial thresholds and related values - 5.4.2 "Threshold Calculation"
|
||||
calc_thr_3gpp(wi, num_bands, pch, band_sizes, coefs);
|
||||
|
||||
//modify thresholds and energies - spread, threshold in quiet, pre-echo control
|
||||
for (w = 0; w < wi->num_windows*16; w += 16) {
|
||||
AacPsyBand *bands = &pch->band[w];
|
||||
|
||||
/* 5.4.2.3 "Spreading" & 5.4.3 "Spread Energy Calculation" */
|
||||
spread_en[0] = bands[0].energy;
|
||||
for (g = 1; g < num_bands; g++) {
|
||||
bands[g].thr = FFMAX(bands[g].thr, bands[g-1].thr * coeffs[g].spread_hi[0]);
|
||||
spread_en[w+g] = FFMAX(bands[g].energy, spread_en[w+g-1] * coeffs[g].spread_hi[1]);
|
||||
}
|
||||
for (g = num_bands - 2; g >= 0; g--) {
|
||||
bands[g].thr = FFMAX(bands[g].thr, bands[g+1].thr * coeffs[g].spread_low[0]);
|
||||
spread_en[w+g] = FFMAX(spread_en[w+g], spread_en[w+g+1] * coeffs[g].spread_low[1]);
|
||||
}
|
||||
//5.4.2.4 "Threshold in quiet"
|
||||
for (g = 0; g < num_bands; g++) {
|
||||
AacPsyBand *band = &bands[g];
|
||||
|
||||
band->thr_quiet = band->thr = FFMAX(band->thr, coeffs[g].ath);
|
||||
//5.4.2.5 "Pre-echo control"
|
||||
if (!(wi->window_type[0] == LONG_STOP_SEQUENCE || (wi->window_type[1] == LONG_START_SEQUENCE && !w)))
|
||||
band->thr = FFMAX(PSY_3GPP_RPEMIN*band->thr, FFMIN(band->thr,
|
||||
PSY_3GPP_RPELEV*pch->prev_band[w+g].thr_quiet));
|
||||
|
||||
/* 5.6.1.3.1 "Preparatory steps of the perceptual entropy calculation" */
|
||||
pe += calc_pe_3gpp(band);
|
||||
a += band->pe_const;
|
||||
active_lines += band->active_lines;
|
||||
|
||||
/* 5.6.1.3.3 "Selection of the bands for avoidance of holes" */
|
||||
if (spread_en[w+g] * avoid_hole_thr > band->energy || coeffs[g].min_snr > 1.0f)
|
||||
band->avoid_holes = PSY_3GPP_AH_NONE;
|
||||
else
|
||||
band->avoid_holes = PSY_3GPP_AH_INACTIVE;
|
||||
}
|
||||
}
|
||||
|
||||
/* 5.6.1.3.2 "Calculation of the desired perceptual entropy" */
|
||||
ctx->ch[channel].entropy = pe;
|
||||
desired_bits = calc_bit_demand(pctx, pe, ctx->bitres.bits, ctx->bitres.size, wi->num_windows == 8);
|
||||
desired_pe = PSY_3GPP_BITS_TO_PE(desired_bits);
|
||||
/* NOTE: PE correction is kept simple. During initial testing it had very
|
||||
* little effect on the final bitrate. Probably a good idea to come
|
||||
* back and do more testing later.
|
||||
*/
|
||||
if (ctx->bitres.bits > 0)
|
||||
desired_pe *= av_clipf(pctx->pe.previous / PSY_3GPP_BITS_TO_PE(ctx->bitres.bits),
|
||||
0.85f, 1.15f);
|
||||
pctx->pe.previous = PSY_3GPP_BITS_TO_PE(desired_bits);
|
||||
|
||||
if (desired_pe < pe) {
|
||||
/* 5.6.1.3.4 "First Estimation of the reduction value" */
|
||||
for (w = 0; w < wi->num_windows*16; w += 16) {
|
||||
reduction = calc_reduction_3gpp(a, desired_pe, pe, active_lines);
|
||||
pe = 0.0f;
|
||||
a = 0.0f;
|
||||
active_lines = 0.0f;
|
||||
for (g = 0; g < num_bands; g++) {
|
||||
AacPsyBand *band = &pch->band[w+g];
|
||||
|
||||
band->thr = calc_reduced_thr_3gpp(band, coeffs[g].min_snr, reduction);
|
||||
/* recalculate PE */
|
||||
pe += calc_pe_3gpp(band);
|
||||
a += band->pe_const;
|
||||
active_lines += band->active_lines;
|
||||
}
|
||||
}
|
||||
|
||||
/* 5.6.1.3.5 "Second Estimation of the reduction value" */
|
||||
for (i = 0; i < 2; i++) {
|
||||
float pe_no_ah = 0.0f, desired_pe_no_ah;
|
||||
active_lines = a = 0.0f;
|
||||
for (w = 0; w < wi->num_windows*16; w += 16) {
|
||||
for (g = 0; g < num_bands; g++) {
|
||||
AacPsyBand *band = &pch->band[w+g];
|
||||
|
||||
if (band->avoid_holes != PSY_3GPP_AH_ACTIVE) {
|
||||
pe_no_ah += band->pe;
|
||||
a += band->pe_const;
|
||||
active_lines += band->active_lines;
|
||||
}
|
||||
}
|
||||
}
|
||||
desired_pe_no_ah = FFMAX(desired_pe - (pe - pe_no_ah), 0.0f);
|
||||
if (active_lines > 0.0f)
|
||||
reduction += calc_reduction_3gpp(a, desired_pe_no_ah, pe_no_ah, active_lines);
|
||||
|
||||
pe = 0.0f;
|
||||
for (w = 0; w < wi->num_windows*16; w += 16) {
|
||||
for (g = 0; g < num_bands; g++) {
|
||||
AacPsyBand *band = &pch->band[w+g];
|
||||
|
||||
if (active_lines > 0.0f)
|
||||
band->thr = calc_reduced_thr_3gpp(band, coeffs[g].min_snr, reduction);
|
||||
pe += calc_pe_3gpp(band);
|
||||
band->norm_fac = band->active_lines / band->thr;
|
||||
norm_fac += band->norm_fac;
|
||||
}
|
||||
}
|
||||
delta_pe = desired_pe - pe;
|
||||
if (fabs(delta_pe) > 0.05f * desired_pe)
|
||||
break;
|
||||
}
|
||||
|
||||
if (pe < 1.15f * desired_pe) {
|
||||
/* 6.6.1.3.6 "Final threshold modification by linearization" */
|
||||
norm_fac = 1.0f / norm_fac;
|
||||
for (w = 0; w < wi->num_windows*16; w += 16) {
|
||||
for (g = 0; g < num_bands; g++) {
|
||||
AacPsyBand *band = &pch->band[w+g];
|
||||
|
||||
if (band->active_lines > 0.5f) {
|
||||
float delta_sfb_pe = band->norm_fac * norm_fac * delta_pe;
|
||||
float thr = band->thr;
|
||||
|
||||
thr *= exp2f(delta_sfb_pe / band->active_lines);
|
||||
if (thr > coeffs[g].min_snr * band->energy && band->avoid_holes == PSY_3GPP_AH_INACTIVE)
|
||||
thr = FFMAX(band->thr, coeffs[g].min_snr * band->energy);
|
||||
band->thr = thr;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* 5.6.1.3.7 "Further perceptual entropy reduction" */
|
||||
g = num_bands;
|
||||
while (pe > desired_pe && g--) {
|
||||
for (w = 0; w < wi->num_windows*16; w+= 16) {
|
||||
AacPsyBand *band = &pch->band[w+g];
|
||||
if (band->avoid_holes != PSY_3GPP_AH_NONE && coeffs[g].min_snr < PSY_SNR_1DB) {
|
||||
coeffs[g].min_snr = PSY_SNR_1DB;
|
||||
band->thr = band->energy * PSY_SNR_1DB;
|
||||
pe += band->active_lines * 1.5f - band->pe;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* TODO: allow more holes (unused without mid/side) */
|
||||
}
|
||||
}
|
||||
|
||||
for (w = 0; w < wi->num_windows*16; w += 16) {
|
||||
for (g = 0; g < num_bands; g++) {
|
||||
AacPsyBand *band = &pch->band[w+g];
|
||||
FFPsyBand *psy_band = &ctx->ch[channel].psy_bands[w+g];
|
||||
|
||||
psy_band->threshold = band->thr;
|
||||
psy_band->energy = band->energy;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(pch->prev_band, pch->band, sizeof(pch->band));
|
||||
}
|
||||
|
||||
static void psy_3gpp_analyze(FFPsyContext *ctx, int channel,
|
||||
const float **coeffs, const FFPsyWindowInfo *wi)
|
||||
{
|
||||
int ch;
|
||||
FFPsyChannelGroup *group = ff_psy_find_group(ctx, channel);
|
||||
|
||||
for (ch = 0; ch < group->num_ch; ch++)
|
||||
psy_3gpp_analyze_channel(ctx, channel + ch, coeffs[ch], &wi[ch]);
|
||||
}
|
||||
|
||||
static av_cold void psy_3gpp_end(FFPsyContext *apc)
|
||||
{
|
||||
AacPsyContext *pctx = (AacPsyContext*) apc->model_priv_data;
|
||||
av_freep(&pctx->ch);
|
||||
av_freep(&apc->model_priv_data);
|
||||
}
|
||||
|
||||
static void lame_apply_block_type(AacPsyChannel *ctx, FFPsyWindowInfo *wi, int uselongblock)
|
||||
{
|
||||
int blocktype = ONLY_LONG_SEQUENCE;
|
||||
if (uselongblock) {
|
||||
if (ctx->next_window_seq == EIGHT_SHORT_SEQUENCE)
|
||||
blocktype = LONG_STOP_SEQUENCE;
|
||||
} else {
|
||||
blocktype = EIGHT_SHORT_SEQUENCE;
|
||||
if (ctx->next_window_seq == ONLY_LONG_SEQUENCE)
|
||||
ctx->next_window_seq = LONG_START_SEQUENCE;
|
||||
if (ctx->next_window_seq == LONG_STOP_SEQUENCE)
|
||||
ctx->next_window_seq = EIGHT_SHORT_SEQUENCE;
|
||||
}
|
||||
|
||||
wi->window_type[0] = ctx->next_window_seq;
|
||||
ctx->next_window_seq = blocktype;
|
||||
}
|
||||
|
||||
static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio,
|
||||
const float *la, int channel, int prev_type)
|
||||
{
|
||||
AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data;
|
||||
AacPsyChannel *pch = &pctx->ch[channel];
|
||||
int grouping = 0;
|
||||
int uselongblock = 1;
|
||||
int attacks[AAC_NUM_BLOCKS_SHORT + 1] = { 0 };
|
||||
int i;
|
||||
FFPsyWindowInfo wi = { { 0 } };
|
||||
|
||||
if (la) {
|
||||
float hpfsmpl[AAC_BLOCK_SIZE_LONG];
|
||||
float const *pf = hpfsmpl;
|
||||
float attack_intensity[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS];
|
||||
float energy_subshort[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS];
|
||||
float energy_short[AAC_NUM_BLOCKS_SHORT + 1] = { 0 };
|
||||
const float *firbuf = la + (AAC_BLOCK_SIZE_SHORT/4 - PSY_LAME_FIR_LEN);
|
||||
int att_sum = 0;
|
||||
|
||||
/* LAME comment: apply high pass filter of fs/4 */
|
||||
psy_hp_filter(firbuf, hpfsmpl, psy_fir_coeffs);
|
||||
|
||||
/* Calculate the energies of each sub-shortblock */
|
||||
for (i = 0; i < PSY_LAME_NUM_SUBBLOCKS; i++) {
|
||||
energy_subshort[i] = pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 1) * PSY_LAME_NUM_SUBBLOCKS)];
|
||||
assert(pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 2) * PSY_LAME_NUM_SUBBLOCKS + 1)] > 0);
|
||||
attack_intensity[i] = energy_subshort[i] / pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 2) * PSY_LAME_NUM_SUBBLOCKS + 1)];
|
||||
energy_short[0] += energy_subshort[i];
|
||||
}
|
||||
|
||||
for (i = 0; i < AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS; i++) {
|
||||
float const *const pfe = pf + AAC_BLOCK_SIZE_LONG / (AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS);
|
||||
float p = 1.0f;
|
||||
for (; pf < pfe; pf++)
|
||||
p = FFMAX(p, fabsf(*pf));
|
||||
pch->prev_energy_subshort[i] = energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS] = p;
|
||||
energy_short[1 + i / PSY_LAME_NUM_SUBBLOCKS] += p;
|
||||
/* NOTE: The indexes below are [i + 3 - 2] in the LAME source.
|
||||
* Obviously the 3 and 2 have some significance, or this would be just [i + 1]
|
||||
* (which is what we use here). What the 3 stands for is ambiguous, as it is both
|
||||
* number of short blocks, and the number of sub-short blocks.
|
||||
* It seems that LAME is comparing each sub-block to sub-block + 1 in the
|
||||
* previous block.
|
||||
*/
|
||||
if (p > energy_subshort[i + 1])
|
||||
p = p / energy_subshort[i + 1];
|
||||
else if (energy_subshort[i + 1] > p * 10.0f)
|
||||
p = energy_subshort[i + 1] / (p * 10.0f);
|
||||
else
|
||||
p = 0.0;
|
||||
attack_intensity[i + PSY_LAME_NUM_SUBBLOCKS] = p;
|
||||
}
|
||||
|
||||
/* compare energy between sub-short blocks */
|
||||
for (i = 0; i < (AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS; i++)
|
||||
if (!attacks[i / PSY_LAME_NUM_SUBBLOCKS])
|
||||
if (attack_intensity[i] > pch->attack_threshold)
|
||||
attacks[i / PSY_LAME_NUM_SUBBLOCKS] = (i % PSY_LAME_NUM_SUBBLOCKS) + 1;
|
||||
|
||||
/* should have energy change between short blocks, in order to avoid periodic signals */
|
||||
/* Good samples to show the effect are Trumpet test songs */
|
||||
/* GB: tuned (1) to avoid too many short blocks for test sample TRUMPET */
|
||||
/* RH: tuned (2) to let enough short blocks through for test sample FSOL and SNAPS */
|
||||
for (i = 1; i < AAC_NUM_BLOCKS_SHORT + 1; i++) {
|
||||
float const u = energy_short[i - 1];
|
||||
float const v = energy_short[i];
|
||||
float const m = FFMAX(u, v);
|
||||
if (m < 40000) { /* (2) */
|
||||
if (u < 1.7f * v && v < 1.7f * u) { /* (1) */
|
||||
if (i == 1 && attacks[0] < attacks[i])
|
||||
attacks[0] = 0;
|
||||
attacks[i] = 0;
|
||||
}
|
||||
}
|
||||
att_sum += attacks[i];
|
||||
}
|
||||
|
||||
if (attacks[0] <= pch->prev_attack)
|
||||
attacks[0] = 0;
|
||||
|
||||
att_sum += attacks[0];
|
||||
/* 3 below indicates the previous attack happened in the last sub-block of the previous sequence */
|
||||
if (pch->prev_attack == 3 || att_sum) {
|
||||
uselongblock = 0;
|
||||
|
||||
for (i = 1; i < AAC_NUM_BLOCKS_SHORT + 1; i++)
|
||||
if (attacks[i] && attacks[i-1])
|
||||
attacks[i] = 0;
|
||||
}
|
||||
} else {
|
||||
/* We have no lookahead info, so just use same type as the previous sequence. */
|
||||
uselongblock = !(prev_type == EIGHT_SHORT_SEQUENCE);
|
||||
}
|
||||
|
||||
lame_apply_block_type(pch, &wi, uselongblock);
|
||||
|
||||
wi.window_type[1] = prev_type;
|
||||
if (wi.window_type[0] != EIGHT_SHORT_SEQUENCE) {
|
||||
wi.num_windows = 1;
|
||||
wi.grouping[0] = 1;
|
||||
if (wi.window_type[0] == LONG_START_SEQUENCE)
|
||||
wi.window_shape = 0;
|
||||
else
|
||||
wi.window_shape = 1;
|
||||
} else {
|
||||
int lastgrp = 0;
|
||||
|
||||
wi.num_windows = 8;
|
||||
wi.window_shape = 0;
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (!((pch->next_grouping >> i) & 1))
|
||||
lastgrp = i;
|
||||
wi.grouping[lastgrp]++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine grouping, based on the location of the first attack, and save for
|
||||
* the next frame.
|
||||
* FIXME: Move this to analysis.
|
||||
* TODO: Tune groupings depending on attack location
|
||||
* TODO: Handle more than one attack in a group
|
||||
*/
|
||||
for (i = 0; i < 9; i++) {
|
||||
if (attacks[i]) {
|
||||
grouping = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pch->next_grouping = window_grouping[grouping];
|
||||
|
||||
pch->prev_attack = attacks[8];
|
||||
|
||||
return wi;
|
||||
}
|
||||
|
||||
const FFPsyModel ff_aac_psy_model =
|
||||
{
|
||||
.name = "3GPP TS 26.403-inspired model",
|
||||
.init = psy_3gpp_init,
|
||||
.window = psy_lame_window,
|
||||
.analyze = psy_3gpp_analyze,
|
||||
.end = psy_3gpp_end,
|
||||
};
|
File diff suppressed because it is too large
Load diff
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* AAC Spectral Band Replication function declarations
|
||||
* Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* AAC Spectral Band Replication function declarations
|
||||
* @author Robert Swain ( rob opendot cl )
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AACSBR_H
|
||||
#define AVCODEC_AACSBR_H
|
||||
|
||||
#include "get_bits.h"
|
||||
#include "aac.h"
|
||||
#include "sbr.h"
|
||||
|
||||
/** Initialize SBR. */
|
||||
void ff_aac_sbr_init(void);
|
||||
/** Initialize one SBR context. */
|
||||
void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr);
|
||||
/** Close one SBR context. */
|
||||
void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr);
|
||||
/** Decode one SBR element. */
|
||||
int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr,
|
||||
GetBitContext *gb, int crc, int cnt, int id_aac);
|
||||
/** Apply one SBR element to one AAC element. */
|
||||
void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac,
|
||||
float* L, float *R);
|
||||
|
||||
void ff_aacsbr_func_ptr_init_mips(AACSBRContext *c);
|
||||
|
||||
#endif /* AVCODEC_AACSBR_H */
|
|
@ -1,620 +0,0 @@
|
|||
/*
|
||||
* AAC Spectral Band Replication decoding data
|
||||
* Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* AAC Spectral Band Replication decoding data
|
||||
* @author Robert Swain ( rob opendot cl )
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AACSBRDATA_H
|
||||
#define AVCODEC_AACSBRDATA_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "libavutil/mem.h"
|
||||
|
||||
///< Huffman tables for SBR
|
||||
|
||||
static const uint8_t t_huffman_env_1_5dB_bits[121] = {
|
||||
18, 18, 18, 18, 18, 18, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 17, 18, 16, 17, 18, 17,
|
||||
16, 16, 16, 16, 15, 14, 14, 13,
|
||||
13, 12, 11, 10, 9, 8, 7, 6,
|
||||
5, 4, 3, 2, 2, 3, 4, 5,
|
||||
6, 7, 8, 9, 10, 12, 13, 14,
|
||||
14, 15, 16, 17, 16, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19,
|
||||
};
|
||||
|
||||
static const uint32_t t_huffman_env_1_5dB_codes[121] = {
|
||||
0x3ffd6, 0x3ffd7, 0x3ffd8, 0x3ffd9, 0x3ffda, 0x3ffdb, 0x7ffb8, 0x7ffb9,
|
||||
0x7ffba, 0x7ffbb, 0x7ffbc, 0x7ffbd, 0x7ffbe, 0x7ffbf, 0x7ffc0, 0x7ffc1,
|
||||
0x7ffc2, 0x7ffc3, 0x7ffc4, 0x7ffc5, 0x7ffc6, 0x7ffc7, 0x7ffc8, 0x7ffc9,
|
||||
0x7ffca, 0x7ffcb, 0x7ffcc, 0x7ffcd, 0x7ffce, 0x7ffcf, 0x7ffd0, 0x7ffd1,
|
||||
0x7ffd2, 0x7ffd3, 0x1ffe6, 0x3ffd4, 0x0fff0, 0x1ffe9, 0x3ffd5, 0x1ffe7,
|
||||
0x0fff1, 0x0ffec, 0x0ffed, 0x0ffee, 0x07ff4, 0x03ff9, 0x03ff7, 0x01ffa,
|
||||
0x01ff9, 0x00ffb, 0x007fc, 0x003fc, 0x001fd, 0x000fd, 0x0007d, 0x0003d,
|
||||
0x0001d, 0x0000d, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000c, 0x0001c,
|
||||
0x0003c, 0x0007c, 0x000fc, 0x001fc, 0x003fd, 0x00ffa, 0x01ff8, 0x03ff6,
|
||||
0x03ff8, 0x07ff5, 0x0ffef, 0x1ffe8, 0x0fff2, 0x7ffd4, 0x7ffd5, 0x7ffd6,
|
||||
0x7ffd7, 0x7ffd8, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd, 0x7ffde,
|
||||
0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffe6,
|
||||
0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffec, 0x7ffed, 0x7ffee,
|
||||
0x7ffef, 0x7fff0, 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6,
|
||||
0x7fff7, 0x7fff8, 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe,
|
||||
0x7ffff,
|
||||
};
|
||||
|
||||
static const uint8_t f_huffman_env_1_5dB_bits[121] = {
|
||||
19, 19, 20, 20, 20, 20, 20, 20,
|
||||
20, 19, 20, 20, 20, 20, 19, 20,
|
||||
19, 19, 20, 18, 20, 20, 20, 19,
|
||||
20, 20, 20, 19, 20, 19, 18, 19,
|
||||
18, 18, 17, 18, 17, 17, 17, 16,
|
||||
16, 16, 15, 15, 14, 13, 13, 12,
|
||||
12, 11, 10, 9, 9, 8, 7, 6,
|
||||
5, 4, 3, 2, 2, 3, 4, 5,
|
||||
6, 8, 8, 9, 10, 11, 11, 11,
|
||||
12, 12, 13, 13, 14, 14, 16, 16,
|
||||
17, 17, 18, 18, 18, 18, 18, 18,
|
||||
18, 20, 19, 20, 20, 20, 20, 20,
|
||||
20, 19, 20, 20, 20, 20, 19, 20,
|
||||
18, 20, 20, 19, 19, 20, 20, 20,
|
||||
20, 20, 20, 20, 20, 20, 20, 20,
|
||||
20,
|
||||
};
|
||||
|
||||
static const uint32_t f_huffman_env_1_5dB_codes[121] = {
|
||||
0x7ffe7, 0x7ffe8, 0xfffd2, 0xfffd3, 0xfffd4, 0xfffd5, 0xfffd6, 0xfffd7,
|
||||
0xfffd8, 0x7ffda, 0xfffd9, 0xfffda, 0xfffdb, 0xfffdc, 0x7ffdb, 0xfffdd,
|
||||
0x7ffdc, 0x7ffdd, 0xfffde, 0x3ffe4, 0xfffdf, 0xfffe0, 0xfffe1, 0x7ffde,
|
||||
0xfffe2, 0xfffe3, 0xfffe4, 0x7ffdf, 0xfffe5, 0x7ffe0, 0x3ffe8, 0x7ffe1,
|
||||
0x3ffe0, 0x3ffe9, 0x1ffef, 0x3ffe5, 0x1ffec, 0x1ffed, 0x1ffee, 0x0fff4,
|
||||
0x0fff3, 0x0fff0, 0x07ff7, 0x07ff6, 0x03ffa, 0x01ffa, 0x01ff9, 0x00ffa,
|
||||
0x00ff8, 0x007f9, 0x003fb, 0x001fc, 0x001fa, 0x000fb, 0x0007c, 0x0003c,
|
||||
0x0001c, 0x0000c, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000d, 0x0001d,
|
||||
0x0003d, 0x000fa, 0x000fc, 0x001fb, 0x003fa, 0x007f8, 0x007fa, 0x007fb,
|
||||
0x00ff9, 0x00ffb, 0x01ff8, 0x01ffb, 0x03ff8, 0x03ff9, 0x0fff1, 0x0fff2,
|
||||
0x1ffea, 0x1ffeb, 0x3ffe1, 0x3ffe2, 0x3ffea, 0x3ffe3, 0x3ffe6, 0x3ffe7,
|
||||
0x3ffeb, 0xfffe6, 0x7ffe2, 0xfffe7, 0xfffe8, 0xfffe9, 0xfffea, 0xfffeb,
|
||||
0xfffec, 0x7ffe3, 0xfffed, 0xfffee, 0xfffef, 0xffff0, 0x7ffe4, 0xffff1,
|
||||
0x3ffec, 0xffff2, 0xffff3, 0x7ffe5, 0x7ffe6, 0xffff4, 0xffff5, 0xffff6,
|
||||
0xffff7, 0xffff8, 0xffff9, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe,
|
||||
0xfffff,
|
||||
};
|
||||
|
||||
static const uint8_t t_huffman_env_bal_1_5dB_bits[49] = {
|
||||
16, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 12, 11, 9, 7, 5, 3,
|
||||
1, 2, 4, 6, 8, 11, 12, 15,
|
||||
16, 16, 16, 16, 16, 16, 16, 17,
|
||||
17, 17, 17, 17, 17, 17, 17, 17,
|
||||
17,
|
||||
};
|
||||
|
||||
static const uint32_t t_huffman_env_bal_1_5dB_codes[49] = {
|
||||
0x0ffe4, 0x0ffe5, 0x0ffe6, 0x0ffe7, 0x0ffe8, 0x0ffe9, 0x0ffea, 0x0ffeb,
|
||||
0x0ffec, 0x0ffed, 0x0ffee, 0x0ffef, 0x0fff0, 0x0fff1, 0x0fff2, 0x0fff3,
|
||||
0x0fff4, 0x0ffe2, 0x00ffc, 0x007fc, 0x001fe, 0x0007e, 0x0001e, 0x00006,
|
||||
0x00000, 0x00002, 0x0000e, 0x0003e, 0x000fe, 0x007fd, 0x00ffd, 0x07ff0,
|
||||
0x0ffe3, 0x0fff5, 0x0fff6, 0x0fff7, 0x0fff8, 0x0fff9, 0x0fffa, 0x1fff6,
|
||||
0x1fff7, 0x1fff8, 0x1fff9, 0x1fffa, 0x1fffb, 0x1fffc, 0x1fffd, 0x1fffe,
|
||||
0x1ffff,
|
||||
};
|
||||
|
||||
static const uint8_t f_huffman_env_bal_1_5dB_bits[49] = {
|
||||
18, 18, 18, 18, 18, 18, 18, 18,
|
||||
18, 18, 18, 18, 18, 18, 18, 16,
|
||||
17, 14, 11, 11, 8, 7, 4, 2,
|
||||
1, 3, 5, 6, 9, 11, 12, 15,
|
||||
16, 18, 18, 18, 18, 18, 18, 18,
|
||||
18, 18, 18, 18, 18, 18, 18, 19,
|
||||
19,
|
||||
};
|
||||
|
||||
static const uint32_t f_huffman_env_bal_1_5dB_codes[49] = {
|
||||
0x3ffe2, 0x3ffe3, 0x3ffe4, 0x3ffe5, 0x3ffe6, 0x3ffe7, 0x3ffe8, 0x3ffe9,
|
||||
0x3ffea, 0x3ffeb, 0x3ffec, 0x3ffed, 0x3ffee, 0x3ffef, 0x3fff0, 0x0fff7,
|
||||
0x1fff0, 0x03ffc, 0x007fe, 0x007fc, 0x000fe, 0x0007e, 0x0000e, 0x00002,
|
||||
0x00000, 0x00006, 0x0001e, 0x0003e, 0x001fe, 0x007fd, 0x00ffe, 0x07ffa,
|
||||
0x0fff6, 0x3fff1, 0x3fff2, 0x3fff3, 0x3fff4, 0x3fff5, 0x3fff6, 0x3fff7,
|
||||
0x3fff8, 0x3fff9, 0x3fffa, 0x3fffb, 0x3fffc, 0x3fffd, 0x3fffe, 0x7fffe,
|
||||
0x7ffff,
|
||||
};
|
||||
|
||||
static const uint8_t t_huffman_env_3_0dB_bits[63] = {
|
||||
18, 18, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 17, 16, 16, 16, 14, 14, 14,
|
||||
13, 12, 11, 8, 6, 4, 2, 1,
|
||||
3, 5, 7, 9, 11, 13, 14, 14,
|
||||
15, 16, 17, 18, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19,
|
||||
};
|
||||
|
||||
static const uint32_t t_huffman_env_3_0dB_codes[63] = {
|
||||
0x3ffed, 0x3ffee, 0x7ffde, 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3,
|
||||
0x7ffe4, 0x7ffe5, 0x7ffe6, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb,
|
||||
0x7ffec, 0x1fff4, 0x0fff7, 0x0fff9, 0x0fff8, 0x03ffb, 0x03ffa, 0x03ff8,
|
||||
0x01ffa, 0x00ffc, 0x007fc, 0x000fe, 0x0003e, 0x0000e, 0x00002, 0x00000,
|
||||
0x00006, 0x0001e, 0x0007e, 0x001fe, 0x007fd, 0x01ffb, 0x03ff9, 0x03ffc,
|
||||
0x07ffa, 0x0fff6, 0x1fff5, 0x3ffec, 0x7ffed, 0x7ffee, 0x7ffef, 0x7fff0,
|
||||
0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6, 0x7fff7, 0x7fff8,
|
||||
0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe, 0x7ffff,
|
||||
};
|
||||
|
||||
static const uint8_t f_huffman_env_3_0dB_bits[63] = {
|
||||
20, 20, 20, 20, 20, 20, 20, 18,
|
||||
19, 19, 19, 19, 18, 18, 20, 19,
|
||||
17, 18, 17, 16, 16, 15, 14, 12,
|
||||
11, 10, 9, 8, 6, 4, 2, 1,
|
||||
3, 5, 8, 9, 10, 11, 12, 13,
|
||||
14, 15, 15, 16, 16, 17, 17, 18,
|
||||
18, 18, 20, 19, 19, 19, 20, 19,
|
||||
19, 20, 20, 20, 20, 20, 20,
|
||||
};
|
||||
|
||||
static const uint32_t f_huffman_env_3_0dB_codes[63] = {
|
||||
0xffff0, 0xffff1, 0xffff2, 0xffff3, 0xffff4, 0xffff5, 0xffff6, 0x3fff3,
|
||||
0x7fff5, 0x7ffee, 0x7ffef, 0x7fff6, 0x3fff4, 0x3fff2, 0xffff7, 0x7fff0,
|
||||
0x1fff5, 0x3fff0, 0x1fff4, 0x0fff7, 0x0fff6, 0x07ff8, 0x03ffb, 0x00ffd,
|
||||
0x007fd, 0x003fd, 0x001fd, 0x000fd, 0x0003e, 0x0000e, 0x00002, 0x00000,
|
||||
0x00006, 0x0001e, 0x000fc, 0x001fc, 0x003fc, 0x007fc, 0x00ffc, 0x01ffc,
|
||||
0x03ffa, 0x07ff9, 0x07ffa, 0x0fff8, 0x0fff9, 0x1fff6, 0x1fff7, 0x3fff5,
|
||||
0x3fff6, 0x3fff1, 0xffff8, 0x7fff1, 0x7fff2, 0x7fff3, 0xffff9, 0x7fff7,
|
||||
0x7fff4, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe, 0xfffff,
|
||||
};
|
||||
|
||||
static const uint8_t t_huffman_env_bal_3_0dB_bits[25] = {
|
||||
13, 13, 13, 13, 13, 13, 13, 12,
|
||||
8, 7, 4, 3, 1, 2, 5, 6,
|
||||
9, 13, 13, 13, 13, 13, 13, 14,
|
||||
14,
|
||||
};
|
||||
|
||||
static const uint16_t t_huffman_env_bal_3_0dB_codes[25] = {
|
||||
0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x0ff8,
|
||||
0x00fe, 0x007e, 0x000e, 0x0006, 0x0000, 0x0002, 0x001e, 0x003e,
|
||||
0x01fe, 0x1ff9, 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe,
|
||||
0x3fff,
|
||||
};
|
||||
|
||||
static const uint8_t f_huffman_env_bal_3_0dB_bits[25] = {
|
||||
13, 13, 13, 13, 13, 14, 14, 11,
|
||||
8, 7, 4, 2, 1, 3, 5, 6,
|
||||
9, 12, 13, 14, 14, 14, 14, 14,
|
||||
14,
|
||||
};
|
||||
|
||||
static const uint16_t f_huffman_env_bal_3_0dB_codes[25] = {
|
||||
0x1ff7, 0x1ff8, 0x1ff9, 0x1ffa, 0x1ffb, 0x3ff8, 0x3ff9, 0x07fc,
|
||||
0x00fe, 0x007e, 0x000e, 0x0002, 0x0000, 0x0006, 0x001e, 0x003e,
|
||||
0x01fe, 0x0ffa, 0x1ff6, 0x3ffa, 0x3ffb, 0x3ffc, 0x3ffd, 0x3ffe,
|
||||
0x3fff,
|
||||
};
|
||||
|
||||
static const uint8_t t_huffman_noise_3_0dB_bits[63] = {
|
||||
13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 11, 8, 6, 4, 3, 1,
|
||||
2, 5, 8, 10, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 14, 14,
|
||||
};
|
||||
|
||||
static const uint16_t t_huffman_noise_3_0dB_codes[63] = {
|
||||
0x1fce, 0x1fcf, 0x1fd0, 0x1fd1, 0x1fd2, 0x1fd3, 0x1fd4, 0x1fd5,
|
||||
0x1fd6, 0x1fd7, 0x1fd8, 0x1fd9, 0x1fda, 0x1fdb, 0x1fdc, 0x1fdd,
|
||||
0x1fde, 0x1fdf, 0x1fe0, 0x1fe1, 0x1fe2, 0x1fe3, 0x1fe4, 0x1fe5,
|
||||
0x1fe6, 0x1fe7, 0x07f2, 0x00fd, 0x003e, 0x000e, 0x0006, 0x0000,
|
||||
0x0002, 0x001e, 0x00fc, 0x03f8, 0x1fcc, 0x1fe8, 0x1fe9, 0x1fea,
|
||||
0x1feb, 0x1fec, 0x1fcd, 0x1fed, 0x1fee, 0x1fef, 0x1ff0, 0x1ff1,
|
||||
0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x1ff9,
|
||||
0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe, 0x3fff,
|
||||
};
|
||||
|
||||
static const uint8_t t_huffman_noise_bal_3_0dB_bits[25] = {
|
||||
8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 5, 2, 1, 3, 6, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8,
|
||||
};
|
||||
|
||||
static const uint8_t t_huffman_noise_bal_3_0dB_codes[25] = {
|
||||
0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,
|
||||
0xf4, 0xf5, 0x1c, 0x02, 0x00, 0x06, 0x3a, 0xf6,
|
||||
0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe,
|
||||
0xff,
|
||||
};
|
||||
|
||||
static const int8_t sbr_offset[6][16] = {
|
||||
{-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}, // fs_sbr = 16000 Hz
|
||||
{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13}, // fs_sbr = 22050 Hz
|
||||
{-5, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16}, // fs_sbr = 24000 Hz
|
||||
{-6, -4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16}, // fs_sbr = 32000 Hz
|
||||
{-4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20}, // 44100 Hz <= fs_sbr <= 64000 Hz
|
||||
{-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24}, // 64000 Hz < fs_sbr
|
||||
};
|
||||
|
||||
///< window coefficients for analysis/synthesis QMF banks
|
||||
static DECLARE_ALIGNED(32, float, sbr_qmf_window_ds)[320];
|
||||
static DECLARE_ALIGNED(32, float, sbr_qmf_window_us)[640] = {
|
||||
0.0000000000, -0.0005525286, -0.0005617692, -0.0004947518,
|
||||
-0.0004875227, -0.0004893791, -0.0005040714, -0.0005226564,
|
||||
-0.0005466565, -0.0005677802, -0.0005870930, -0.0006132747,
|
||||
-0.0006312493, -0.0006540333, -0.0006777690, -0.0006941614,
|
||||
-0.0007157736, -0.0007255043, -0.0007440941, -0.0007490598,
|
||||
-0.0007681371, -0.0007724848, -0.0007834332, -0.0007779869,
|
||||
-0.0007803664, -0.0007801449, -0.0007757977, -0.0007630793,
|
||||
-0.0007530001, -0.0007319357, -0.0007215391, -0.0006917937,
|
||||
-0.0006650415, -0.0006341594, -0.0005946118, -0.0005564576,
|
||||
-0.0005145572, -0.0004606325, -0.0004095121, -0.0003501175,
|
||||
-0.0002896981, -0.0002098337, -0.0001446380, -0.0000617334,
|
||||
0.0000134949, 0.0001094383, 0.0002043017, 0.0002949531,
|
||||
0.0004026540, 0.0005107388, 0.0006239376, 0.0007458025,
|
||||
0.0008608443, 0.0009885988, 0.0011250155, 0.0012577884,
|
||||
0.0013902494, 0.0015443219, 0.0016868083, 0.0018348265,
|
||||
0.0019841140, 0.0021461583, 0.0023017254, 0.0024625616,
|
||||
0.0026201758, 0.0027870464, 0.0029469447, 0.0031125420,
|
||||
0.0032739613, 0.0034418874, 0.0036008268, 0.0037603922,
|
||||
0.0039207432, 0.0040819753, 0.0042264269, 0.0043730719,
|
||||
0.0045209852, 0.0046606460, 0.0047932560, 0.0049137603,
|
||||
0.0050393022, 0.0051407353, 0.0052461166, 0.0053471681,
|
||||
0.0054196775, 0.0054876040, 0.0055475714, 0.0055938023,
|
||||
0.0056220643, 0.0056455196, 0.0056389199, 0.0056266114,
|
||||
0.0055917128, 0.0055404363, 0.0054753783, 0.0053838975,
|
||||
0.0052715758, 0.0051382275, 0.0049839687, 0.0048109469,
|
||||
0.0046039530, 0.0043801861, 0.0041251642, 0.0038456408,
|
||||
0.0035401246, 0.0032091885, 0.0028446757, 0.0024508540,
|
||||
0.0020274176, 0.0015784682, 0.0010902329, 0.0005832264,
|
||||
0.0000276045, -0.0005464280, -0.0011568135, -0.0018039472,
|
||||
-0.0024826723, -0.0031933778, -0.0039401124, -0.0047222596,
|
||||
-0.0055337211, -0.0063792293, -0.0072615816, -0.0081798233,
|
||||
-0.0091325329, -0.0101150215, -0.0111315548, -0.0121849995,
|
||||
0.0132718220, 0.0143904666, 0.0155405553, 0.0167324712,
|
||||
0.0179433381, 0.0191872431, 0.0204531793, 0.0217467550,
|
||||
0.0230680169, 0.0244160992, 0.0257875847, 0.0271859429,
|
||||
0.0286072173, 0.0300502657, 0.0315017608, 0.0329754081,
|
||||
0.0344620948, 0.0359697560, 0.0374812850, 0.0390053679,
|
||||
0.0405349170, 0.0420649094, 0.0436097542, 0.0451488405,
|
||||
0.0466843027, 0.0482165720, 0.0497385755, 0.0512556155,
|
||||
0.0527630746, 0.0542452768, 0.0557173648, 0.0571616450,
|
||||
0.0585915683, 0.0599837480, 0.0613455171, 0.0626857808,
|
||||
0.0639715898, 0.0652247106, 0.0664367512, 0.0676075985,
|
||||
0.0687043828, 0.0697630244, 0.0707628710, 0.0717002673,
|
||||
0.0725682583, 0.0733620255, 0.0741003642, 0.0747452558,
|
||||
0.0753137336, 0.0758008358, 0.0761992479, 0.0764992170,
|
||||
0.0767093490, 0.0768173975, 0.0768230011, 0.0767204924,
|
||||
0.0765050718, 0.0761748321, 0.0757305756, 0.0751576255,
|
||||
0.0744664394, 0.0736406005, 0.0726774642, 0.0715826364,
|
||||
0.0703533073, 0.0689664013, 0.0674525021, 0.0657690668,
|
||||
0.0639444805, 0.0619602779, 0.0598166570, 0.0575152691,
|
||||
0.0550460034, 0.0524093821, 0.0495978676, 0.0466303305,
|
||||
0.0434768782, 0.0401458278, 0.0366418116, 0.0329583930,
|
||||
0.0290824006, 0.0250307561, 0.0207997072, 0.0163701258,
|
||||
0.0117623832, 0.0069636862, 0.0019765601, -0.0032086896,
|
||||
-0.0085711749, -0.0141288827, -0.0198834129, -0.0258227288,
|
||||
-0.0319531274, -0.0382776572, -0.0447806821, -0.0514804176,
|
||||
-0.0583705326, -0.0654409853, -0.0726943300, -0.0801372934,
|
||||
-0.0877547536, -0.0955533352, -0.1035329531, -0.1116826931,
|
||||
-0.1200077984, -0.1285002850, -0.1371551761, -0.1459766491,
|
||||
-0.1549607071, -0.1640958855, -0.1733808172, -0.1828172548,
|
||||
-0.1923966745, -0.2021250176, -0.2119735853, -0.2219652696,
|
||||
-0.2320690870, -0.2423016884, -0.2526480309, -0.2631053299,
|
||||
-0.2736634040, -0.2843214189, -0.2950716717, -0.3059098575,
|
||||
-0.3168278913, -0.3278113727, -0.3388722693, -0.3499914122,
|
||||
0.3611589903, 0.3723795546, 0.3836350013, 0.3949211761,
|
||||
0.4062317676, 0.4175696896, 0.4289119920, 0.4402553754,
|
||||
0.4515996535, 0.4629308085, 0.4742453214, 0.4855253091,
|
||||
0.4967708254, 0.5079817500, 0.5191234970, 0.5302240895,
|
||||
0.5412553448, 0.5522051258, 0.5630789140, 0.5738524131,
|
||||
0.5845403235, 0.5951123086, 0.6055783538, 0.6159109932,
|
||||
0.6261242695, 0.6361980107, 0.6461269695, 0.6559016302,
|
||||
0.6655139880, 0.6749663190, 0.6842353293, 0.6933282376,
|
||||
0.7022388719, 0.7109410426, 0.7194462634, 0.7277448900,
|
||||
0.7358211758, 0.7436827863, 0.7513137456, 0.7587080760,
|
||||
0.7658674865, 0.7727780881, 0.7794287519, 0.7858353120,
|
||||
0.7919735841, 0.7978466413, 0.8034485751, 0.8087695004,
|
||||
0.8138191270, 0.8185776004, 0.8230419890, 0.8272275347,
|
||||
0.8311038457, 0.8346937361, 0.8379717337, 0.8409541392,
|
||||
0.8436238281, 0.8459818469, 0.8480315777, 0.8497805198,
|
||||
0.8511971524, 0.8523047035, 0.8531020949, 0.8535720573,
|
||||
0.8537385600,
|
||||
};
|
||||
|
||||
/* First eight entries repeated at end to simplify SIMD implementations. */
|
||||
const DECLARE_ALIGNED(16, float, ff_sbr_noise_table)[][2] = {
|
||||
{-0.99948153278296, -0.59483417516607}, { 0.97113454393991, -0.67528515225647},
|
||||
{ 0.14130051758487, -0.95090983575689}, {-0.47005496701697, -0.37340549728647},
|
||||
{ 0.80705063769351, 0.29653668284408}, {-0.38981478896926, 0.89572605717087},
|
||||
{-0.01053049862020, -0.66959058036166}, {-0.91266367957293, -0.11522938140034},
|
||||
{ 0.54840422910309, 0.75221367176302}, { 0.40009252867955, -0.98929400334421},
|
||||
{-0.99867974711855, -0.88147068645358}, {-0.95531076805040, 0.90908757154593},
|
||||
{-0.45725933317144, -0.56716323646760}, {-0.72929675029275, -0.98008272727324},
|
||||
{ 0.75622801399036, 0.20950329995549}, { 0.07069442601050, -0.78247898470706},
|
||||
{ 0.74496252926055, -0.91169004445807}, {-0.96440182703856, -0.94739918296622},
|
||||
{ 0.30424629369539, -0.49438267012479}, { 0.66565033746925, 0.64652935542491},
|
||||
{ 0.91697008020594, 0.17514097332009}, {-0.70774918760427, 0.52548653416543},
|
||||
{-0.70051415345560, -0.45340028808763}, {-0.99496513054797, -0.90071908066973},
|
||||
{ 0.98164490790123, -0.77463155528697}, {-0.54671580548181, -0.02570928536004},
|
||||
{-0.01689629065389, 0.00287506445732}, {-0.86110349531986, 0.42548583726477},
|
||||
{-0.98892980586032, -0.87881132267556}, { 0.51756627678691, 0.66926784710139},
|
||||
{-0.99635026409640, -0.58107730574765}, {-0.99969370862163, 0.98369989360250},
|
||||
{ 0.55266258627194, 0.59449057465591}, { 0.34581177741673, 0.94879421061866},
|
||||
{ 0.62664209577999, -0.74402970906471}, {-0.77149701404973, -0.33883658042801},
|
||||
{-0.91592244254432, 0.03687901376713}, {-0.76285492357887, -0.91371867919124},
|
||||
{ 0.79788337195331, -0.93180971199849}, { 0.54473080610200, -0.11919206037186},
|
||||
{-0.85639281671058, 0.42429854760451}, {-0.92882402971423, 0.27871809078609},
|
||||
{-0.11708371046774, -0.99800843444966}, { 0.21356749817493, -0.90716295627033},
|
||||
{-0.76191692573909, 0.99768118356265}, { 0.98111043100884, -0.95854459734407},
|
||||
{-0.85913269895572, 0.95766566168880}, {-0.93307242253692, 0.49431757696466},
|
||||
{ 0.30485754879632, -0.70540034357529}, { 0.85289650925190, 0.46766131791044},
|
||||
{ 0.91328082618125, -0.99839597361769}, {-0.05890199924154, 0.70741827819497},
|
||||
{ 0.28398686150148, 0.34633555702188}, { 0.95258164539612, -0.54893416026939},
|
||||
{-0.78566324168507, -0.75568541079691}, {-0.95789495447877, -0.20423194696966},
|
||||
{ 0.82411158711197, 0.96654618432562}, {-0.65185446735885, -0.88734990773289},
|
||||
{-0.93643603134666, 0.99870790442385}, { 0.91427159529618, -0.98290505544444},
|
||||
{-0.70395684036886, 0.58796798221039}, { 0.00563771969365, 0.61768196727244},
|
||||
{ 0.89065051931895, 0.52783352697585}, {-0.68683707712762, 0.80806944710339},
|
||||
{ 0.72165342518718, -0.69259857349564}, {-0.62928247730667, 0.13627037407335},
|
||||
{ 0.29938434065514, -0.46051329682246}, {-0.91781958879280, -0.74012716684186},
|
||||
{ 0.99298717043688, 0.40816610075661}, { 0.82368298622748, -0.74036047190173},
|
||||
{-0.98512833386833, -0.99972330709594}, {-0.95915368242257, -0.99237800466040},
|
||||
{-0.21411126572790, -0.93424819052545}, {-0.68821476106884, -0.26892306315457},
|
||||
{ 0.91851997982317, 0.09358228901785}, {-0.96062769559127, 0.36099095133739},
|
||||
{ 0.51646184922287, -0.71373332873917}, { 0.61130721139669, 0.46950141175917},
|
||||
{ 0.47336129371299, -0.27333178296162}, { 0.90998308703519, 0.96715662938132},
|
||||
{ 0.44844799194357, 0.99211574628306}, { 0.66614891079092, 0.96590176169121},
|
||||
{ 0.74922239129237, -0.89879858826087}, {-0.99571588506485, 0.52785521494349},
|
||||
{ 0.97401082477563, -0.16855870075190}, { 0.72683747733879, -0.48060774432251},
|
||||
{ 0.95432193457128, 0.68849603408441}, {-0.72962208425191, -0.76608443420917},
|
||||
{-0.85359479233537, 0.88738125901579}, {-0.81412430338535, -0.97480768049637},
|
||||
{-0.87930772356786, 0.74748307690436}, {-0.71573331064977, -0.98570608178923},
|
||||
{ 0.83524300028228, 0.83702537075163}, {-0.48086065601423, -0.98848504923531},
|
||||
{ 0.97139128574778, 0.80093621198236}, { 0.51992825347895, 0.80247631400510},
|
||||
{-0.00848591195325, -0.76670128000486}, {-0.70294374303036, 0.55359910445577},
|
||||
{-0.95894428168140, -0.43265504344783}, { 0.97079252950321, 0.09325857238682},
|
||||
{-0.92404293670797, 0.85507704027855}, {-0.69506469500450, 0.98633412625459},
|
||||
{ 0.26559203620024, 0.73314307966524}, { 0.28038443336943, 0.14537913654427},
|
||||
{-0.74138124825523, 0.99310339807762}, {-0.01752795995444, -0.82616635284178},
|
||||
{-0.55126773094930, -0.98898543862153}, { 0.97960898850996, -0.94021446752851},
|
||||
{-0.99196309146936, 0.67019017358456}, {-0.67684928085260, 0.12631491649378},
|
||||
{ 0.09140039465500, -0.20537731453108}, {-0.71658965751996, -0.97788200391224},
|
||||
{ 0.81014640078925, 0.53722648362443}, { 0.40616991671205, -0.26469008598449},
|
||||
{-0.67680188682972, 0.94502052337695}, { 0.86849774348749, -0.18333598647899},
|
||||
{-0.99500381284851, -0.02634122068550}, { 0.84329189340667, 0.10406957462213},
|
||||
{-0.09215968531446, 0.69540012101253}, { 0.99956173327206, -0.12358542001404},
|
||||
{-0.79732779473535, -0.91582524736159}, { 0.96349973642406, 0.96640458041000},
|
||||
{-0.79942778496547, 0.64323902822857}, {-0.11566039853896, 0.28587846253726},
|
||||
{-0.39922954514662, 0.94129601616966}, { 0.99089197565987, -0.92062625581587},
|
||||
{ 0.28631285179909, -0.91035047143603}, {-0.83302725605608, -0.67330410892084},
|
||||
{ 0.95404443402072, 0.49162765398743}, {-0.06449863579434, 0.03250560813135},
|
||||
{-0.99575054486311, 0.42389784469507}, {-0.65501142790847, 0.82546114655624},
|
||||
{-0.81254441908887, -0.51627234660629}, {-0.99646369485481, 0.84490533520752},
|
||||
{ 0.00287840603348, 0.64768261158166}, { 0.70176989408455, -0.20453028573322},
|
||||
{ 0.96361882270190, 0.40706967140989}, {-0.68883758192426, 0.91338958840772},
|
||||
{-0.34875585502238, 0.71472290693300}, { 0.91980081243087, 0.66507455644919},
|
||||
{-0.99009048343881, 0.85868021604848}, { 0.68865791458395, 0.55660316809678},
|
||||
{-0.99484402129368, -0.20052559254934}, { 0.94214511408023, -0.99696425367461},
|
||||
{-0.67414626793544, 0.49548221180078}, {-0.47339353684664, -0.85904328834047},
|
||||
{ 0.14323651387360, -0.94145598222488}, {-0.29268293575672, 0.05759224927952},
|
||||
{ 0.43793861458754, -0.78904969892724}, {-0.36345126374441, 0.64874435357162},
|
||||
{-0.08750604656825, 0.97686944362527}, {-0.96495267812511, -0.53960305946511},
|
||||
{ 0.55526940659947, 0.78891523734774}, { 0.73538215752630, 0.96452072373404},
|
||||
{-0.30889773919437, -0.80664389776860}, { 0.03574995626194, -0.97325616900959},
|
||||
{ 0.98720684660488, 0.48409133691962}, {-0.81689296271203, -0.90827703628298},
|
||||
{ 0.67866860118215, 0.81284503870856}, {-0.15808569732583, 0.85279555024382},
|
||||
{ 0.80723395114371, -0.24717418514605}, { 0.47788757329038, -0.46333147839295},
|
||||
{ 0.96367554763201, 0.38486749303242}, {-0.99143875716818, -0.24945277239809},
|
||||
{ 0.83081876925833, -0.94780851414763}, {-0.58753191905341, 0.01290772389163},
|
||||
{ 0.95538108220960, -0.85557052096538}, {-0.96490920476211, -0.64020970923102},
|
||||
{-0.97327101028521, 0.12378128133110}, { 0.91400366022124, 0.57972471346930},
|
||||
{-0.99925837363824, 0.71084847864067}, {-0.86875903507313, -0.20291699203564},
|
||||
{-0.26240034795124, -0.68264554369108}, {-0.24664412953388, -0.87642273115183},
|
||||
{ 0.02416275806869, 0.27192914288905}, { 0.82068619590515, -0.85087787994476},
|
||||
{ 0.88547373760759, -0.89636802901469}, {-0.18173078152226, -0.26152145156800},
|
||||
{ 0.09355476558534, 0.54845123045604}, {-0.54668414224090, 0.95980774020221},
|
||||
{ 0.37050990604091, -0.59910140383171}, {-0.70373594262891, 0.91227665827081},
|
||||
{-0.34600785879594, -0.99441426144200}, {-0.68774481731008, -0.30238837956299},
|
||||
{-0.26843291251234, 0.83115668004362}, { 0.49072334613242, -0.45359708737775},
|
||||
{ 0.38975993093975, 0.95515358099121}, {-0.97757125224150, 0.05305894580606},
|
||||
{-0.17325552859616, -0.92770672250494}, { 0.99948035025744, 0.58285545563426},
|
||||
{-0.64946246527458, 0.68645507104960}, {-0.12016920576437, -0.57147322153312},
|
||||
{-0.58947456517751, -0.34847132454388}, {-0.41815140454465, 0.16276422358861},
|
||||
{ 0.99885650204884, 0.11136095490444}, {-0.56649614128386, -0.90494866361587},
|
||||
{ 0.94138021032330, 0.35281916733018}, {-0.75725076534641, 0.53650549640587},
|
||||
{ 0.20541973692630, -0.94435144369918}, { 0.99980371023351, 0.79835913565599},
|
||||
{ 0.29078277605775, 0.35393777921520}, {-0.62858772103030, 0.38765693387102},
|
||||
{ 0.43440904467688, -0.98546330463232}, {-0.98298583762390, 0.21021524625209},
|
||||
{ 0.19513029146934, -0.94239832251867}, {-0.95476662400101, 0.98364554179143},
|
||||
{ 0.93379635304810, -0.70881994583682}, {-0.85235410573336, -0.08342347966410},
|
||||
{-0.86425093011245, -0.45795025029466}, { 0.38879779059045, 0.97274429344593},
|
||||
{ 0.92045124735495, -0.62433652524220}, { 0.89162532251878, 0.54950955570563},
|
||||
{-0.36834336949252, 0.96458298020975}, { 0.93891760988045, -0.89968353740388},
|
||||
{ 0.99267657565094, -0.03757034316958}, {-0.94063471614176, 0.41332338538963},
|
||||
{ 0.99740224117019, -0.16830494996370}, {-0.35899413170555, -0.46633226649613},
|
||||
{ 0.05237237274947, -0.25640361602661}, { 0.36703583957424, -0.38653265641875},
|
||||
{ 0.91653180367913, -0.30587628726597}, { 0.69000803499316, 0.90952171386132},
|
||||
{-0.38658751133527, 0.99501571208985}, {-0.29250814029851, 0.37444994344615},
|
||||
{-0.60182204677608, 0.86779651036123}, {-0.97418588163217, 0.96468523666475},
|
||||
{ 0.88461574003963, 0.57508405276414}, { 0.05198933055162, 0.21269661669964},
|
||||
{-0.53499621979720, 0.97241553731237}, {-0.49429560226497, 0.98183865291903},
|
||||
{-0.98935142339139, -0.40249159006933}, {-0.98081380091130, -0.72856895534041},
|
||||
{-0.27338148835532, 0.99950922447209}, { 0.06310802338302, -0.54539587529618},
|
||||
{-0.20461677199539, -0.14209977628489}, { 0.66223843141647, 0.72528579940326},
|
||||
{-0.84764345483665, 0.02372316801261}, {-0.89039863483811, 0.88866581484602},
|
||||
{ 0.95903308477986, 0.76744927173873}, { 0.73504123909879, -0.03747203173192},
|
||||
{-0.31744434966056, -0.36834111883652}, {-0.34110827591623, 0.40211222807691},
|
||||
{ 0.47803883714199, -0.39423219786288}, { 0.98299195879514, 0.01989791390047},
|
||||
{-0.30963073129751, -0.18076720599336}, { 0.99992588229018, -0.26281872094289},
|
||||
{-0.93149731080767, -0.98313162570490}, { 0.99923472302773, -0.80142993767554},
|
||||
{-0.26024169633417, -0.75999759855752}, {-0.35712514743563, 0.19298963768574},
|
||||
{-0.99899084509530, 0.74645156992493}, { 0.86557171579452, 0.55593866696299},
|
||||
{ 0.33408042438752, 0.86185953874709}, { 0.99010736374716, 0.04602397576623},
|
||||
{-0.66694269691195, -0.91643611810148}, { 0.64016792079480, 0.15649530836856},
|
||||
{ 0.99570534804836, 0.45844586038111}, {-0.63431466947340, 0.21079116459234},
|
||||
{-0.07706847005931, -0.89581437101329}, { 0.98590090577724, 0.88241721133981},
|
||||
{ 0.80099335254678, -0.36851896710853}, { 0.78368131392666, 0.45506999802597},
|
||||
{ 0.08707806671691, 0.80938994918745}, {-0.86811883080712, 0.39347308654705},
|
||||
{-0.39466529740375, -0.66809432114456}, { 0.97875325649683, -0.72467840967746},
|
||||
{-0.95038560288864, 0.89563219587625}, { 0.17005239424212, 0.54683053962658},
|
||||
{-0.76910792026848, -0.96226617549298}, { 0.99743281016846, 0.42697157037567},
|
||||
{ 0.95437383549973, 0.97002324109952}, { 0.99578905365569, -0.54106826257356},
|
||||
{ 0.28058259829990, -0.85361420634036}, { 0.85256524470573, -0.64567607735589},
|
||||
{-0.50608540105128, -0.65846015480300}, {-0.97210735183243, -0.23095213067791},
|
||||
{ 0.95424048234441, -0.99240147091219}, {-0.96926570524023, 0.73775654896574},
|
||||
{ 0.30872163214726, 0.41514960556126}, {-0.24523839572639, 0.63206633394807},
|
||||
{-0.33813265086024, -0.38661779441897}, {-0.05826828420146, -0.06940774188029},
|
||||
{-0.22898461455054, 0.97054853316316}, {-0.18509915019881, 0.47565762892084},
|
||||
{-0.10488238045009, -0.87769947402394}, {-0.71886586182037, 0.78030982480538},
|
||||
{ 0.99793873738654, 0.90041310491497}, { 0.57563307626120, -0.91034337352097},
|
||||
{ 0.28909646383717, 0.96307783970534}, { 0.42188998312520, 0.48148651230437},
|
||||
{ 0.93335049681047, -0.43537023883588}, {-0.97087374418267, 0.86636445711364},
|
||||
{ 0.36722871286923, 0.65291654172961}, {-0.81093025665696, 0.08778370229363},
|
||||
{-0.26240603062237, -0.92774095379098}, { 0.83996497984604, 0.55839849139647},
|
||||
{-0.99909615720225, -0.96024605713970}, { 0.74649464155061, 0.12144893606462},
|
||||
{-0.74774595569805, -0.26898062008959}, { 0.95781667469567, -0.79047927052628},
|
||||
{ 0.95472308713099, -0.08588776019550}, { 0.48708332746299, 0.99999041579432},
|
||||
{ 0.46332038247497, 0.10964126185063}, {-0.76497004940162, 0.89210929242238},
|
||||
{ 0.57397389364339, 0.35289703373760}, { 0.75374316974495, 0.96705214651335},
|
||||
{-0.59174397685714, -0.89405370422752}, { 0.75087906691890, -0.29612672982396},
|
||||
{-0.98607857336230, 0.25034911730023}, {-0.40761056640505, -0.90045573444695},
|
||||
{ 0.66929266740477, 0.98629493401748}, {-0.97463695257310, -0.00190223301301},
|
||||
{ 0.90145509409859, 0.99781390365446}, {-0.87259289048043, 0.99233587353666},
|
||||
{-0.91529461447692, -0.15698707534206}, {-0.03305738840705, -0.37205262859764},
|
||||
{ 0.07223051368337, -0.88805001733626}, { 0.99498012188353, 0.97094358113387},
|
||||
{-0.74904939500519, 0.99985483641521}, { 0.04585228574211, 0.99812337444082},
|
||||
{-0.89054954257993, -0.31791913188064}, {-0.83782144651251, 0.97637632547466},
|
||||
{ 0.33454804933804, -0.86231516800408}, {-0.99707579362824, 0.93237990079441},
|
||||
{-0.22827527843994, 0.18874759397997}, { 0.67248046289143, -0.03646211390569},
|
||||
{-0.05146538187944, -0.92599700120679}, { 0.99947295749905, 0.93625229707912},
|
||||
{ 0.66951124390363, 0.98905825623893}, {-0.99602956559179, -0.44654715757688},
|
||||
{ 0.82104905483590, 0.99540741724928}, { 0.99186510988782, 0.72023001312947},
|
||||
{-0.65284592392918, 0.52186723253637}, { 0.93885443798188, -0.74895312615259},
|
||||
{ 0.96735248738388, 0.90891816978629}, {-0.22225968841114, 0.57124029781228},
|
||||
{-0.44132783753414, -0.92688840659280}, {-0.85694974219574, 0.88844532719844},
|
||||
{ 0.91783042091762, -0.46356892383970}, { 0.72556974415690, -0.99899555770747},
|
||||
{-0.99711581834508, 0.58211560180426}, { 0.77638976371966, 0.94321834873819},
|
||||
{ 0.07717324253925, 0.58638399856595}, {-0.56049829194163, 0.82522301569036},
|
||||
{ 0.98398893639988, 0.39467440420569}, { 0.47546946844938, 0.68613044836811},
|
||||
{ 0.65675089314631, 0.18331637134880}, { 0.03273375457980, -0.74933109564108},
|
||||
{-0.38684144784738, 0.51337349030406}, {-0.97346267944545, -0.96549364384098},
|
||||
{-0.53282156061942, -0.91423265091354}, { 0.99817310731176, 0.61133572482148},
|
||||
{-0.50254500772635, -0.88829338134294}, { 0.01995873238855, 0.85223515096765},
|
||||
{ 0.99930381973804, 0.94578896296649}, { 0.82907767600783, -0.06323442598128},
|
||||
{-0.58660709669728, 0.96840773806582}, {-0.17573736667267, -0.48166920859485},
|
||||
{ 0.83434292401346, -0.13023450646997}, { 0.05946491307025, 0.20511047074866},
|
||||
{ 0.81505484574602, -0.94685947861369}, {-0.44976380954860, 0.40894572671545},
|
||||
{-0.89746474625671, 0.99846578838537}, { 0.39677256130792, -0.74854668609359},
|
||||
{-0.07588948563079, 0.74096214084170}, { 0.76343198951445, 0.41746629422634},
|
||||
{-0.74490104699626, 0.94725911744610}, { 0.64880119792759, 0.41336660830571},
|
||||
{ 0.62319537462542, -0.93098313552599}, { 0.42215817594807, -0.07712787385208},
|
||||
{ 0.02704554141885, -0.05417518053666}, { 0.80001773566818, 0.91542195141039},
|
||||
{-0.79351832348816, -0.36208897989136}, { 0.63872359151636, 0.08128252493444},
|
||||
{ 0.52890520960295, 0.60048872455592}, { 0.74238552914587, 0.04491915291044},
|
||||
{ 0.99096131449250, -0.19451182854402}, {-0.80412329643109, -0.88513818199457},
|
||||
{-0.64612616129736, 0.72198674804544}, { 0.11657770663191, -0.83662833815041},
|
||||
{-0.95053182488101, -0.96939905138082}, {-0.62228872928622, 0.82767262846661},
|
||||
{ 0.03004475787316, -0.99738896333384}, {-0.97987214341034, 0.36526129686425},
|
||||
{-0.99986980746200, -0.36021610299715}, { 0.89110648599879, -0.97894250343044},
|
||||
{ 0.10407960510582, 0.77357793811619}, { 0.95964737821728, -0.35435818285502},
|
||||
{ 0.50843233159162, 0.96107691266205}, { 0.17006334670615, -0.76854025314829},
|
||||
{ 0.25872675063360, 0.99893303933816}, {-0.01115998681937, 0.98496019742444},
|
||||
{-0.79598702973261, 0.97138411318894}, {-0.99264708948101, -0.99542822402536},
|
||||
{-0.99829663752818, 0.01877138824311}, {-0.70801016548184, 0.33680685948117},
|
||||
{-0.70467057786826, 0.93272777501857}, { 0.99846021905254, -0.98725746254433},
|
||||
{-0.63364968534650, -0.16473594423746}, {-0.16258217500792, -0.95939125400802},
|
||||
{-0.43645594360633, -0.94805030113284}, {-0.99848471702976, 0.96245166923809},
|
||||
{-0.16796458968998, -0.98987511890470}, {-0.87979225745213, -0.71725725041680},
|
||||
{ 0.44183099021786, -0.93568974498761}, { 0.93310180125532, -0.99913308068246},
|
||||
{-0.93941931782002, -0.56409379640356}, {-0.88590003188677, 0.47624600491382},
|
||||
{ 0.99971463703691, -0.83889954253462}, {-0.75376385639978, 0.00814643438625},
|
||||
{ 0.93887685615875, -0.11284528204636}, { 0.85126435782309, 0.52349251543547},
|
||||
{ 0.39701421446381, 0.81779634174316}, {-0.37024464187437, -0.87071656222959},
|
||||
{-0.36024828242896, 0.34655735648287}, {-0.93388812549209, -0.84476541096429},
|
||||
{-0.65298804552119, -0.18439575450921}, { 0.11960319006843, 0.99899346780168},
|
||||
{ 0.94292565553160, 0.83163906518293}, { 0.75081145286948, -0.35533223142265},
|
||||
{ 0.56721979748394, -0.24076836414499}, { 0.46857766746029, -0.30140233457198},
|
||||
{ 0.97312313923635, -0.99548191630031}, {-0.38299976567017, 0.98516909715427},
|
||||
{ 0.41025800019463, 0.02116736935734}, { 0.09638062008048, 0.04411984381457},
|
||||
{-0.85283249275397, 0.91475563922421}, { 0.88866808958124, -0.99735267083226},
|
||||
{-0.48202429536989, -0.96805608884164}, { 0.27572582416567, 0.58634753335832},
|
||||
{-0.65889129659168, 0.58835634138583}, { 0.98838086953732, 0.99994349600236},
|
||||
{-0.20651349620689, 0.54593044066355}, {-0.62126416356920, -0.59893681700392},
|
||||
{ 0.20320105410437, -0.86879180355289}, {-0.97790548600584, 0.96290806999242},
|
||||
{ 0.11112534735126, 0.21484763313301}, {-0.41368337314182, 0.28216837680365},
|
||||
{ 0.24133038992960, 0.51294362630238}, {-0.66393410674885, -0.08249679629081},
|
||||
{-0.53697829178752, -0.97649903936228}, {-0.97224737889348, 0.22081333579837},
|
||||
{ 0.87392477144549, -0.12796173740361}, { 0.19050361015753, 0.01602615387195},
|
||||
{-0.46353441212724, -0.95249041539006}, {-0.07064096339021, -0.94479803205886},
|
||||
{-0.92444085484466, -0.10457590187436}, {-0.83822593578728, -0.01695043208885},
|
||||
{ 0.75214681811150, -0.99955681042665}, {-0.42102998829339, 0.99720941999394},
|
||||
{-0.72094786237696, -0.35008961934255}, { 0.78843311019251, 0.52851398958271},
|
||||
{ 0.97394027897442, -0.26695944086561}, { 0.99206463477946, -0.57010120849429},
|
||||
{ 0.76789609461795, -0.76519356730966}, {-0.82002421836409, -0.73530179553767},
|
||||
{ 0.81924990025724, 0.99698425250579}, {-0.26719850873357, 0.68903369776193},
|
||||
{-0.43311260380975, 0.85321815947490}, { 0.99194979673836, 0.91876249766422},
|
||||
{-0.80692001248487, -0.32627540663214}, { 0.43080003649976, -0.21919095636638},
|
||||
{ 0.67709491937357, -0.95478075822906}, { 0.56151770568316, -0.70693811747778},
|
||||
{ 0.10831862810749, -0.08628837174592}, { 0.91229417540436, -0.65987351408410},
|
||||
{-0.48972893932274, 0.56289246362686}, {-0.89033658689697, -0.71656563987082},
|
||||
{ 0.65269447475094, 0.65916004833932}, { 0.67439478141121, -0.81684380846796},
|
||||
{-0.47770832416973, -0.16789556203025}, {-0.99715979260878, -0.93565784007648},
|
||||
{-0.90889593602546, 0.62034397054380}, {-0.06618622548177, -0.23812217221359},
|
||||
{ 0.99430266919728, 0.18812555317553}, { 0.97686402381843, -0.28664534366620},
|
||||
{ 0.94813650221268, -0.97506640027128}, {-0.95434497492853, -0.79607978501983},
|
||||
{-0.49104783137150, 0.32895214359663}, { 0.99881175120751, 0.88993983831354},
|
||||
{ 0.50449166760303, -0.85995072408434}, { 0.47162891065108, -0.18680204049569},
|
||||
{-0.62081581361840, 0.75000676218956}, {-0.43867015250812, 0.99998069244322},
|
||||
{ 0.98630563232075, -0.53578899600662}, {-0.61510362277374, -0.89515019899997},
|
||||
{-0.03841517601843, -0.69888815681179}, {-0.30102157304644, -0.07667808922205},
|
||||
{ 0.41881284182683, 0.02188098922282}, {-0.86135454941237, 0.98947480909359},
|
||||
{ 0.67226861393788, -0.13494389011014}, {-0.70737398842068, -0.76547349325992},
|
||||
{ 0.94044946687963, 0.09026201157416}, {-0.82386352534327, 0.08924768823676},
|
||||
{-0.32070666698656, 0.50143421908753}, { 0.57593163224487, -0.98966422921509},
|
||||
{-0.36326018419965, 0.07440243123228}, { 0.99979044674350, -0.14130287347405},
|
||||
{-0.92366023326932, -0.97979298068180}, {-0.44607178518598, -0.54233252016394},
|
||||
{ 0.44226800932956, 0.71326756742752}, { 0.03671907158312, 0.63606389366675},
|
||||
{ 0.52175424682195, -0.85396826735705}, {-0.94701139690956, -0.01826348194255},
|
||||
{-0.98759606946049, 0.82288714303073}, { 0.87434794743625, 0.89399495655433},
|
||||
{-0.93412041758744, 0.41374052024363}, { 0.96063943315511, 0.93116709541280},
|
||||
{ 0.97534253457837, 0.86150930812689}, { 0.99642466504163, 0.70190043427512},
|
||||
{-0.94705089665984, -0.29580042814306}, { 0.91599807087376, -0.98147830385781},
|
||||
// Start of duplicated table
|
||||
{-0.99948153278296, -0.59483417516607}, { 0.97113454393991, -0.67528515225647},
|
||||
{ 0.14130051758487, -0.95090983575689}, {-0.47005496701697, -0.37340549728647},
|
||||
{ 0.80705063769351, 0.29653668284408}, {-0.38981478896926, 0.89572605717087},
|
||||
{-0.01053049862020, -0.66959058036166}, {-0.91266367957293, -0.11522938140034},
|
||||
};
|
||||
|
||||
#endif /* AVCODEC_AACSBRDATA_H */
|
File diff suppressed because it is too large
Load diff
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* AAC data declarations
|
||||
* Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
|
||||
* Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* AAC data declarations
|
||||
* @author Oded Shimon ( ods15 ods15 dyndns org )
|
||||
* @author Maxim Gavrilov ( maxim.gavrilov gmail com )
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AACTAB_H
|
||||
#define AVCODEC_AACTAB_H
|
||||
|
||||
#include "libavutil/mem.h"
|
||||
#include "aac.h"
|
||||
#include "aac_tablegen_decl.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* NOTE:
|
||||
* Tables in this file are used by the AAC decoder and will be used by the AAC
|
||||
* encoder.
|
||||
*/
|
||||
|
||||
/* @name window coefficients
|
||||
* @{
|
||||
*/
|
||||
DECLARE_ALIGNED(32, extern float, ff_aac_kbd_long_1024)[1024];
|
||||
DECLARE_ALIGNED(32, extern float, ff_aac_kbd_short_128)[128];
|
||||
const DECLARE_ALIGNED(32, extern float, ff_aac_eld_window)[1920];
|
||||
// @}
|
||||
|
||||
/* @name number of scalefactor window bands for long and short transform windows respectively
|
||||
* @{
|
||||
*/
|
||||
extern const uint8_t ff_aac_num_swb_1024[];
|
||||
extern const uint8_t ff_aac_num_swb_512 [];
|
||||
extern const uint8_t ff_aac_num_swb_128 [];
|
||||
// @}
|
||||
|
||||
extern const uint8_t ff_aac_pred_sfb_max [];
|
||||
|
||||
extern const uint32_t ff_aac_scalefactor_code[121];
|
||||
extern const uint8_t ff_aac_scalefactor_bits[121];
|
||||
|
||||
extern const uint16_t * const ff_aac_spectral_codes[11];
|
||||
extern const uint8_t * const ff_aac_spectral_bits [11];
|
||||
extern const uint16_t ff_aac_spectral_sizes[11];
|
||||
|
||||
extern const float *ff_aac_codebook_vectors[];
|
||||
extern const float *ff_aac_codebook_vector_vals[];
|
||||
extern const uint16_t *ff_aac_codebook_vector_idx[];
|
||||
|
||||
extern const uint16_t * const ff_swb_offset_1024[13];
|
||||
extern const uint16_t * const ff_swb_offset_512 [13];
|
||||
extern const uint16_t * const ff_swb_offset_128 [13];
|
||||
|
||||
extern const uint8_t ff_tns_max_bands_1024[13];
|
||||
extern const uint8_t ff_tns_max_bands_512 [13];
|
||||
extern const uint8_t ff_tns_max_bands_128 [13];
|
||||
|
||||
#endif /* AVCODEC_AACTAB_H */
|
|
@ -1,231 +0,0 @@
|
|||
/*
|
||||
* Common code between the AC-3 encoder and decoder
|
||||
* Copyright (c) 2000 Fabrice Bellard
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Common code between the AC-3 encoder and decoder.
|
||||
*/
|
||||
|
||||
#include "avcodec.h"
|
||||
#include "ac3.h"
|
||||
#include "get_bits.h"
|
||||
|
||||
/**
|
||||
* Starting frequency coefficient bin for each critical band.
|
||||
*/
|
||||
const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
|
||||
20, 21, 22, 23, 24, 25, 26, 27, 28, 31,
|
||||
34, 37, 40, 43, 46, 49, 55, 61, 67, 73,
|
||||
79, 85, 97, 109, 121, 133, 157, 181, 205, 229, 253
|
||||
};
|
||||
|
||||
#if CONFIG_HARDCODED_TABLES
|
||||
|
||||
/**
|
||||
* Map each frequency coefficient bin to the critical band that contains it.
|
||||
*/
|
||||
const uint8_t ff_ac3_bin_to_band_tab[253] = {
|
||||
0,
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
|
||||
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
||||
25, 26, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30,
|
||||
31, 31, 31, 32, 32, 32, 33, 33, 33, 34, 34, 34,
|
||||
35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36,
|
||||
37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38,
|
||||
39, 39, 39, 39, 39, 39, 40, 40, 40, 40, 40, 40,
|
||||
41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
|
||||
42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
|
||||
43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
|
||||
44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
|
||||
45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||
45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||
46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
|
||||
46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
|
||||
47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
|
||||
47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
|
||||
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
|
||||
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
|
||||
49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
|
||||
49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49
|
||||
};
|
||||
|
||||
#else /* CONFIG_HARDCODED_TABLES */
|
||||
uint8_t ff_ac3_bin_to_band_tab[253];
|
||||
#endif
|
||||
|
||||
static inline int calc_lowcomp1(int a, int b0, int b1, int c)
|
||||
{
|
||||
if ((b0 + 256) == b1) {
|
||||
a = c;
|
||||
} else if (b0 > b1) {
|
||||
a = FFMAX(a - 64, 0);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
static inline int calc_lowcomp(int a, int b0, int b1, int bin)
|
||||
{
|
||||
if (bin < 7) {
|
||||
return calc_lowcomp1(a, b0, b1, 384);
|
||||
} else if (bin < 20) {
|
||||
return calc_lowcomp1(a, b0, b1, 320);
|
||||
} else {
|
||||
return FFMAX(a - 128, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
|
||||
int16_t *band_psd)
|
||||
{
|
||||
int bin, band;
|
||||
|
||||
/* exponent mapping to PSD */
|
||||
for (bin = start; bin < end; bin++) {
|
||||
psd[bin]=(3072 - (exp[bin] << 7));
|
||||
}
|
||||
|
||||
/* PSD integration */
|
||||
bin = start;
|
||||
band = ff_ac3_bin_to_band_tab[start];
|
||||
do {
|
||||
int v = psd[bin++];
|
||||
int band_end = FFMIN(ff_ac3_band_start_tab[band+1], end);
|
||||
for (; bin < band_end; bin++) {
|
||||
int max = FFMAX(v, psd[bin]);
|
||||
/* logadd */
|
||||
int adr = FFMIN(max - ((v + psd[bin] + 1) >> 1), 255);
|
||||
v = max + ff_ac3_log_add_tab[adr];
|
||||
}
|
||||
band_psd[band++] = v;
|
||||
} while (end > ff_ac3_band_start_tab[band]);
|
||||
}
|
||||
|
||||
int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
|
||||
int start, int end, int fast_gain, int is_lfe,
|
||||
int dba_mode, int dba_nsegs, uint8_t *dba_offsets,
|
||||
uint8_t *dba_lengths, uint8_t *dba_values,
|
||||
int16_t *mask)
|
||||
{
|
||||
int16_t excite[AC3_CRITICAL_BANDS]; /* excitation */
|
||||
int band;
|
||||
int band_start, band_end, begin, end1;
|
||||
int lowcomp, fastleak, slowleak;
|
||||
|
||||
/* excitation function */
|
||||
band_start = ff_ac3_bin_to_band_tab[start];
|
||||
band_end = ff_ac3_bin_to_band_tab[end-1] + 1;
|
||||
|
||||
if (band_start == 0) {
|
||||
lowcomp = 0;
|
||||
lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384);
|
||||
excite[0] = band_psd[0] - fast_gain - lowcomp;
|
||||
lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384);
|
||||
excite[1] = band_psd[1] - fast_gain - lowcomp;
|
||||
begin = 7;
|
||||
for (band = 2; band < 7; band++) {
|
||||
if (!(is_lfe && band == 6))
|
||||
lowcomp = calc_lowcomp1(lowcomp, band_psd[band], band_psd[band+1], 384);
|
||||
fastleak = band_psd[band] - fast_gain;
|
||||
slowleak = band_psd[band] - s->slow_gain;
|
||||
excite[band] = fastleak - lowcomp;
|
||||
if (!(is_lfe && band == 6)) {
|
||||
if (band_psd[band] <= band_psd[band+1]) {
|
||||
begin = band + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end1 = FFMIN(band_end, 22);
|
||||
for (band = begin; band < end1; band++) {
|
||||
if (!(is_lfe && band == 6))
|
||||
lowcomp = calc_lowcomp(lowcomp, band_psd[band], band_psd[band+1], band);
|
||||
fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain);
|
||||
slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain);
|
||||
excite[band] = FFMAX(fastleak - lowcomp, slowleak);
|
||||
}
|
||||
begin = 22;
|
||||
} else {
|
||||
/* coupling channel */
|
||||
begin = band_start;
|
||||
fastleak = (s->cpl_fast_leak << 8) + 768;
|
||||
slowleak = (s->cpl_slow_leak << 8) + 768;
|
||||
}
|
||||
|
||||
for (band = begin; band < band_end; band++) {
|
||||
fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain);
|
||||
slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain);
|
||||
excite[band] = FFMAX(fastleak, slowleak);
|
||||
}
|
||||
|
||||
/* compute masking curve */
|
||||
|
||||
for (band = band_start; band < band_end; band++) {
|
||||
int tmp = s->db_per_bit - band_psd[band];
|
||||
if (tmp > 0) {
|
||||
excite[band] += tmp >> 2;
|
||||
}
|
||||
mask[band] = FFMAX(ff_ac3_hearing_threshold_tab[band >> s->sr_shift][s->sr_code], excite[band]);
|
||||
}
|
||||
|
||||
/* delta bit allocation */
|
||||
|
||||
if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {
|
||||
int i, seg, delta;
|
||||
if (dba_nsegs > 8)
|
||||
return -1;
|
||||
band = band_start;
|
||||
for (seg = 0; seg < dba_nsegs; seg++) {
|
||||
band += dba_offsets[seg];
|
||||
if (band >= AC3_CRITICAL_BANDS || dba_lengths[seg] > AC3_CRITICAL_BANDS-band)
|
||||
return -1;
|
||||
if (dba_values[seg] >= 4) {
|
||||
delta = (dba_values[seg] - 3) << 7;
|
||||
} else {
|
||||
delta = (dba_values[seg] - 4) << 7;
|
||||
}
|
||||
for (i = 0; i < dba_lengths[seg]; i++) {
|
||||
mask[band++] += delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize some tables.
|
||||
* note: This function must remain thread safe because it is called by the
|
||||
* AVParser init code.
|
||||
*/
|
||||
av_cold void ff_ac3_common_init(void)
|
||||
{
|
||||
#if !CONFIG_HARDCODED_TABLES
|
||||
/* compute ff_ac3_bin_to_band_tab from ff_ac3_band_start_tab */
|
||||
int bin = 0, band;
|
||||
for (band = 0; band < AC3_CRITICAL_BANDS; band++) {
|
||||
int band_end = ff_ac3_band_start_tab[band+1];
|
||||
while (bin < band_end)
|
||||
ff_ac3_bin_to_band_tab[bin++] = band;
|
||||
}
|
||||
#endif /* !CONFIG_HARDCODED_TABLES */
|
||||
}
|
|
@ -1,219 +0,0 @@
|
|||
/*
|
||||
* Common code between the AC-3 encoder and decoder
|
||||
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Common code between the AC-3 encoder and decoder.
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AC3_H
|
||||
#define AVCODEC_AC3_H
|
||||
|
||||
#define AC3_MAX_CODED_FRAME_SIZE 3840 /* in bytes */
|
||||
#define AC3_MAX_CHANNELS 7 /**< maximum number of channels, including coupling channel */
|
||||
#define CPL_CH 0 /**< coupling channel index */
|
||||
|
||||
#define AC3_MAX_COEFS 256
|
||||
#define AC3_BLOCK_SIZE 256
|
||||
#define AC3_MAX_BLOCKS 6
|
||||
#define AC3_FRAME_SIZE (AC3_MAX_BLOCKS * 256)
|
||||
#define AC3_WINDOW_SIZE (AC3_BLOCK_SIZE * 2)
|
||||
#define AC3_CRITICAL_BANDS 50
|
||||
#define AC3_MAX_CPL_BANDS 18
|
||||
|
||||
#include "libavutil/opt.h"
|
||||
#include "avcodec.h"
|
||||
#include "ac3tab.h"
|
||||
|
||||
/* exponent encoding strategy */
|
||||
#define EXP_REUSE 0
|
||||
#define EXP_NEW 1
|
||||
|
||||
#define EXP_D15 1
|
||||
#define EXP_D25 2
|
||||
#define EXP_D45 3
|
||||
|
||||
/* pre-defined gain values */
|
||||
#define LEVEL_PLUS_3DB 1.4142135623730950
|
||||
#define LEVEL_PLUS_1POINT5DB 1.1892071150027209
|
||||
#define LEVEL_MINUS_1POINT5DB 0.8408964152537145
|
||||
#define LEVEL_MINUS_3DB 0.7071067811865476
|
||||
#define LEVEL_MINUS_4POINT5DB 0.5946035575013605
|
||||
#define LEVEL_MINUS_6DB 0.5000000000000000
|
||||
#define LEVEL_MINUS_9DB 0.3535533905932738
|
||||
#define LEVEL_ZERO 0.0000000000000000
|
||||
#define LEVEL_ONE 1.0000000000000000
|
||||
|
||||
/** Delta bit allocation strategy */
|
||||
typedef enum {
|
||||
DBA_REUSE = 0,
|
||||
DBA_NEW,
|
||||
DBA_NONE,
|
||||
DBA_RESERVED
|
||||
} AC3DeltaStrategy;
|
||||
|
||||
/** Channel mode (audio coding mode) */
|
||||
typedef enum {
|
||||
AC3_CHMODE_DUALMONO = 0,
|
||||
AC3_CHMODE_MONO,
|
||||
AC3_CHMODE_STEREO,
|
||||
AC3_CHMODE_3F,
|
||||
AC3_CHMODE_2F1R,
|
||||
AC3_CHMODE_3F1R,
|
||||
AC3_CHMODE_2F2R,
|
||||
AC3_CHMODE_3F2R
|
||||
} AC3ChannelMode;
|
||||
|
||||
/** Dolby Surround mode */
|
||||
typedef enum AC3DolbySurroundMode {
|
||||
AC3_DSURMOD_NOTINDICATED = 0,
|
||||
AC3_DSURMOD_OFF,
|
||||
AC3_DSURMOD_ON,
|
||||
AC3_DSURMOD_RESERVED
|
||||
} AC3DolbySurroundMode;
|
||||
|
||||
/** Dolby Surround EX mode */
|
||||
typedef enum AC3DolbySurroundEXMode {
|
||||
AC3_DSUREXMOD_NOTINDICATED = 0,
|
||||
AC3_DSUREXMOD_OFF,
|
||||
AC3_DSUREXMOD_ON,
|
||||
AC3_DSUREXMOD_PLIIZ
|
||||
} AC3DolbySurroundEXMode;
|
||||
|
||||
/** Dolby Headphone mode */
|
||||
typedef enum AC3DolbyHeadphoneMode {
|
||||
AC3_DHEADPHONMOD_NOTINDICATED = 0,
|
||||
AC3_DHEADPHONMOD_OFF,
|
||||
AC3_DHEADPHONMOD_ON,
|
||||
AC3_DHEADPHONMOD_RESERVED
|
||||
} AC3DolbyHeadphoneMode;
|
||||
|
||||
/** Preferred Stereo Downmix mode */
|
||||
typedef enum AC3PreferredStereoDownmixMode {
|
||||
AC3_DMIXMOD_NOTINDICATED = 0,
|
||||
AC3_DMIXMOD_LTRT,
|
||||
AC3_DMIXMOD_LORO,
|
||||
AC3_DMIXMOD_DPLII // reserved value in A/52, but used by encoders to indicate DPL2
|
||||
} AC3PreferredStereoDownmixMode;
|
||||
|
||||
typedef struct AC3BitAllocParameters {
|
||||
int sr_code;
|
||||
int sr_shift;
|
||||
int slow_gain, slow_decay, fast_decay, db_per_bit, floor;
|
||||
int cpl_fast_leak, cpl_slow_leak;
|
||||
} AC3BitAllocParameters;
|
||||
|
||||
/**
|
||||
* @struct AC3HeaderInfo
|
||||
* Coded AC-3 header values up to the lfeon element, plus derived values.
|
||||
*/
|
||||
typedef struct AC3HeaderInfo {
|
||||
/** @name Coded elements
|
||||
* @{
|
||||
*/
|
||||
uint16_t sync_word;
|
||||
uint16_t crc1;
|
||||
uint8_t sr_code;
|
||||
uint8_t bitstream_id;
|
||||
uint8_t bitstream_mode;
|
||||
uint8_t channel_mode;
|
||||
uint8_t lfe_on;
|
||||
uint8_t frame_type;
|
||||
int substreamid; ///< substream identification
|
||||
int center_mix_level; ///< Center mix level index
|
||||
int surround_mix_level; ///< Surround mix level index
|
||||
uint16_t channel_map;
|
||||
int num_blocks; ///< number of audio blocks
|
||||
#if AV_HAVE_INCOMPATIBLE_LIBAV_ABI
|
||||
int dolby_surround_mode;
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
/** @name Derived values
|
||||
* @{
|
||||
*/
|
||||
uint8_t sr_shift;
|
||||
uint16_t sample_rate;
|
||||
uint32_t bit_rate;
|
||||
uint8_t channels;
|
||||
uint16_t frame_size;
|
||||
uint64_t channel_layout;
|
||||
/** @} */
|
||||
#if !AV_HAVE_INCOMPATIBLE_LIBAV_ABI
|
||||
int dolby_surround_mode;
|
||||
#endif
|
||||
} AC3HeaderInfo;
|
||||
|
||||
typedef enum {
|
||||
EAC3_FRAME_TYPE_INDEPENDENT = 0,
|
||||
EAC3_FRAME_TYPE_DEPENDENT,
|
||||
EAC3_FRAME_TYPE_AC3_CONVERT,
|
||||
EAC3_FRAME_TYPE_RESERVED
|
||||
} EAC3FrameType;
|
||||
|
||||
void ff_ac3_common_init(void);
|
||||
|
||||
/**
|
||||
* Calculate the log power-spectral density of the input signal.
|
||||
* This gives a rough estimate of signal power in the frequency domain by using
|
||||
* the spectral envelope (exponents). The psd is also separately grouped
|
||||
* into critical bands for use in the calculating the masking curve.
|
||||
* 128 units in psd = -6 dB. The dbknee parameter in AC3BitAllocParameters
|
||||
* determines the reference level.
|
||||
*
|
||||
* @param[in] exp frequency coefficient exponents
|
||||
* @param[in] start starting bin location
|
||||
* @param[in] end ending bin location
|
||||
* @param[out] psd signal power for each frequency bin
|
||||
* @param[out] band_psd signal power for each critical band
|
||||
*/
|
||||
void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
|
||||
int16_t *band_psd);
|
||||
|
||||
/**
|
||||
* Calculate the masking curve.
|
||||
* First, the excitation is calculated using parameters in s and the signal
|
||||
* power in each critical band. The excitation is compared with a predefined
|
||||
* hearing threshold table to produce the masking curve. If delta bit
|
||||
* allocation information is provided, it is used for adjusting the masking
|
||||
* curve, usually to give a closer match to a better psychoacoustic model.
|
||||
*
|
||||
* @param[in] s adjustable bit allocation parameters
|
||||
* @param[in] band_psd signal power for each critical band
|
||||
* @param[in] start starting bin location
|
||||
* @param[in] end ending bin location
|
||||
* @param[in] fast_gain fast gain (estimated signal-to-mask ratio)
|
||||
* @param[in] is_lfe whether or not the channel being processed is the LFE
|
||||
* @param[in] dba_mode delta bit allocation mode (none, reuse, or new)
|
||||
* @param[in] dba_nsegs number of delta segments
|
||||
* @param[in] dba_offsets location offsets for each segment
|
||||
* @param[in] dba_lengths length of each segment
|
||||
* @param[in] dba_values delta bit allocation for each segment
|
||||
* @param[out] mask calculated masking curve
|
||||
* @return returns 0 for success, non-zero for error
|
||||
*/
|
||||
int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
|
||||
int start, int end, int fast_gain, int is_lfe,
|
||||
int dba_mode, int dba_nsegs, uint8_t *dba_offsets,
|
||||
uint8_t *dba_lengths, uint8_t *dba_values,
|
||||
int16_t *mask);
|
||||
|
||||
#endif /* AVCODEC_AC3_H */
|
|
@ -1,213 +0,0 @@
|
|||
/*
|
||||
* AC-3 parser
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
* Copyright (c) 2003 Michael Niedermayer
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavutil/channel_layout.h"
|
||||
#include "parser.h"
|
||||
#include "ac3_parser.h"
|
||||
#include "aac_ac3_parser.h"
|
||||
#include "get_bits.h"
|
||||
|
||||
|
||||
#define AC3_HEADER_SIZE 7
|
||||
|
||||
|
||||
static const uint8_t eac3_blocks[4] = {
|
||||
1, 2, 3, 6
|
||||
};
|
||||
|
||||
/**
|
||||
* Table for center mix levels
|
||||
* reference: Section 5.4.2.4 cmixlev
|
||||
*/
|
||||
static const uint8_t center_levels[4] = { 4, 5, 6, 5 };
|
||||
|
||||
/**
|
||||
* Table for surround mix levels
|
||||
* reference: Section 5.4.2.5 surmixlev
|
||||
*/
|
||||
static const uint8_t surround_levels[4] = { 4, 6, 7, 6 };
|
||||
|
||||
|
||||
int avpriv_ac3_parse_header2(GetBitContext *gbc, AC3HeaderInfo **phdr)
|
||||
{
|
||||
int frame_size_code;
|
||||
AC3HeaderInfo *hdr;
|
||||
|
||||
if (!*phdr)
|
||||
*phdr = av_mallocz(sizeof(AC3HeaderInfo));
|
||||
if (!*phdr)
|
||||
return AVERROR(ENOMEM);
|
||||
hdr = *phdr;
|
||||
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
|
||||
hdr->sync_word = get_bits(gbc, 16);
|
||||
if(hdr->sync_word != 0x0B77)
|
||||
return AAC_AC3_PARSE_ERROR_SYNC;
|
||||
|
||||
/* read ahead to bsid to distinguish between AC-3 and E-AC-3 */
|
||||
hdr->bitstream_id = show_bits_long(gbc, 29) & 0x1F;
|
||||
if(hdr->bitstream_id > 16)
|
||||
return AAC_AC3_PARSE_ERROR_BSID;
|
||||
|
||||
hdr->num_blocks = 6;
|
||||
|
||||
/* set default mix levels */
|
||||
hdr->center_mix_level = 5; // -4.5dB
|
||||
hdr->surround_mix_level = 6; // -6.0dB
|
||||
|
||||
/* set default dolby surround mode */
|
||||
hdr->dolby_surround_mode = AC3_DSURMOD_NOTINDICATED;
|
||||
|
||||
if(hdr->bitstream_id <= 10) {
|
||||
/* Normal AC-3 */
|
||||
hdr->crc1 = get_bits(gbc, 16);
|
||||
hdr->sr_code = get_bits(gbc, 2);
|
||||
if(hdr->sr_code == 3)
|
||||
return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
|
||||
|
||||
frame_size_code = get_bits(gbc, 6);
|
||||
if(frame_size_code > 37)
|
||||
return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
|
||||
|
||||
skip_bits(gbc, 5); // skip bsid, already got it
|
||||
|
||||
hdr->bitstream_mode = get_bits(gbc, 3);
|
||||
hdr->channel_mode = get_bits(gbc, 3);
|
||||
|
||||
if(hdr->channel_mode == AC3_CHMODE_STEREO) {
|
||||
hdr->dolby_surround_mode = get_bits(gbc, 2);
|
||||
} else {
|
||||
if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO)
|
||||
hdr-> center_mix_level = center_levels[get_bits(gbc, 2)];
|
||||
if(hdr->channel_mode & 4)
|
||||
hdr->surround_mix_level = surround_levels[get_bits(gbc, 2)];
|
||||
}
|
||||
hdr->lfe_on = get_bits1(gbc);
|
||||
|
||||
hdr->sr_shift = FFMAX(hdr->bitstream_id, 8) - 8;
|
||||
hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code] >> hdr->sr_shift;
|
||||
hdr->bit_rate = (ff_ac3_bitrate_tab[frame_size_code>>1] * 1000) >> hdr->sr_shift;
|
||||
hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on;
|
||||
hdr->frame_size = ff_ac3_frame_size_tab[frame_size_code][hdr->sr_code] * 2;
|
||||
hdr->frame_type = EAC3_FRAME_TYPE_AC3_CONVERT; //EAC3_FRAME_TYPE_INDEPENDENT;
|
||||
hdr->substreamid = 0;
|
||||
} else {
|
||||
/* Enhanced AC-3 */
|
||||
hdr->crc1 = 0;
|
||||
hdr->frame_type = get_bits(gbc, 2);
|
||||
if(hdr->frame_type == EAC3_FRAME_TYPE_RESERVED)
|
||||
return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
|
||||
|
||||
hdr->substreamid = get_bits(gbc, 3);
|
||||
|
||||
hdr->frame_size = (get_bits(gbc, 11) + 1) << 1;
|
||||
if(hdr->frame_size < AC3_HEADER_SIZE)
|
||||
return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
|
||||
|
||||
hdr->sr_code = get_bits(gbc, 2);
|
||||
if (hdr->sr_code == 3) {
|
||||
int sr_code2 = get_bits(gbc, 2);
|
||||
if(sr_code2 == 3)
|
||||
return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
|
||||
hdr->sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2;
|
||||
hdr->sr_shift = 1;
|
||||
} else {
|
||||
hdr->num_blocks = eac3_blocks[get_bits(gbc, 2)];
|
||||
hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code];
|
||||
hdr->sr_shift = 0;
|
||||
}
|
||||
|
||||
hdr->channel_mode = get_bits(gbc, 3);
|
||||
hdr->lfe_on = get_bits1(gbc);
|
||||
|
||||
hdr->bit_rate = (uint32_t)(8.0 * hdr->frame_size * hdr->sample_rate /
|
||||
(hdr->num_blocks * 256.0));
|
||||
hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on;
|
||||
}
|
||||
hdr->channel_layout = avpriv_ac3_channel_layout_tab[hdr->channel_mode];
|
||||
if (hdr->lfe_on)
|
||||
hdr->channel_layout |= AV_CH_LOW_FREQUENCY;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
|
||||
{
|
||||
AC3HeaderInfo tmp, *ptmp = &tmp;
|
||||
int ret = avpriv_ac3_parse_header2(gbc, &ptmp);
|
||||
|
||||
memcpy(hdr, ptmp, ((intptr_t)&tmp.channel_layout) - ((intptr_t)&tmp) + sizeof(uint64_t));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ac3_sync(uint64_t state, AACAC3ParseContext *hdr_info,
|
||||
int *need_next_header, int *new_frame_start)
|
||||
{
|
||||
int err;
|
||||
union {
|
||||
uint64_t u64;
|
||||
uint8_t u8[8];
|
||||
} tmp = { av_be2ne64(state) };
|
||||
AC3HeaderInfo hdr, *phdr = &hdr;
|
||||
GetBitContext gbc;
|
||||
|
||||
init_get_bits(&gbc, tmp.u8+8-AC3_HEADER_SIZE, 54);
|
||||
err = avpriv_ac3_parse_header2(&gbc, &phdr);
|
||||
|
||||
if(err < 0)
|
||||
return 0;
|
||||
|
||||
hdr_info->sample_rate = hdr.sample_rate;
|
||||
hdr_info->bit_rate = hdr.bit_rate;
|
||||
hdr_info->channels = hdr.channels;
|
||||
hdr_info->channel_layout = hdr.channel_layout;
|
||||
hdr_info->samples = hdr.num_blocks * 256;
|
||||
hdr_info->service_type = hdr.bitstream_mode;
|
||||
if (hdr.bitstream_mode == 0x7 && hdr.channels > 1)
|
||||
hdr_info->service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE;
|
||||
if(hdr.bitstream_id>10)
|
||||
hdr_info->codec_id = AV_CODEC_ID_EAC3;
|
||||
else if (hdr_info->codec_id == AV_CODEC_ID_NONE)
|
||||
hdr_info->codec_id = AV_CODEC_ID_AC3;
|
||||
|
||||
*need_next_header = (hdr.frame_type != EAC3_FRAME_TYPE_AC3_CONVERT);
|
||||
*new_frame_start = (hdr.frame_type != EAC3_FRAME_TYPE_DEPENDENT);
|
||||
return hdr.frame_size;
|
||||
}
|
||||
|
||||
static av_cold int ac3_parse_init(AVCodecParserContext *s1)
|
||||
{
|
||||
AACAC3ParseContext *s = s1->priv_data;
|
||||
s->header_size = AC3_HEADER_SIZE;
|
||||
s->sync = ac3_sync;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
AVCodecParser ff_ac3_parser = {
|
||||
.codec_ids = { AV_CODEC_ID_AC3, AV_CODEC_ID_EAC3 },
|
||||
.priv_data_size = sizeof(AACAC3ParseContext),
|
||||
.parser_init = ac3_parse_init,
|
||||
.parser_parse = ff_aac_ac3_parse,
|
||||
.parser_close = ff_parse_close,
|
||||
};
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* AC-3 parser prototypes
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
* Copyright (c) 2003 Michael Niedermayer
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AC3_PARSER_H
|
||||
#define AVCODEC_AC3_PARSER_H
|
||||
|
||||
#include "ac3.h"
|
||||
#include "get_bits.h"
|
||||
|
||||
/**
|
||||
* Parse AC-3 frame header.
|
||||
* Parse the header up to the lfeon element, which is the first 52 or 54 bits
|
||||
* depending on the audio coding mode.
|
||||
* @param[in] gbc BitContext containing the first 54 bits of the frame.
|
||||
* @param[out] hdr Pointer to Pointer to struct where header info is written.
|
||||
* will be allocated if NULL
|
||||
* @return Returns 0 on success, -1 if there is a sync word mismatch,
|
||||
* -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate)
|
||||
* element is invalid, or -4 if the frmsizecod (bit rate) element is invalid.
|
||||
*/
|
||||
int avpriv_ac3_parse_header2(GetBitContext *gbc, AC3HeaderInfo **hdr);
|
||||
|
||||
int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr);
|
||||
|
||||
#endif /* AVCODEC_AC3_PARSER_H */
|
File diff suppressed because it is too large
Load diff
|
@ -1,249 +0,0 @@
|
|||
/*
|
||||
* Common code between the AC-3 and E-AC-3 decoders
|
||||
* Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Common code between the AC-3 and E-AC-3 decoders.
|
||||
*
|
||||
* Summary of MDCT Coefficient Grouping:
|
||||
* The individual MDCT coefficient indices are often referred to in the
|
||||
* (E-)AC-3 specification as frequency bins. These bins are grouped together
|
||||
* into subbands of 12 coefficients each. The subbands are grouped together
|
||||
* into bands as defined in the bitstream by the band structures, which
|
||||
* determine the number of bands and the size of each band. The full spectrum
|
||||
* of 256 frequency bins is divided into 1 DC bin + 21 subbands = 253 bins.
|
||||
* This system of grouping coefficients is used for channel bandwidth, stereo
|
||||
* rematrixing, channel coupling, enhanced coupling, and spectral extension.
|
||||
*
|
||||
* +-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-+
|
||||
* |1| |12| | [12|12|12|12] | | | | | | | | | | | | |3|
|
||||
* +-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-+
|
||||
* ~~~ ~~~~ ~~~~~~~~~~~~~ ~~~
|
||||
* | | | |
|
||||
* | | | 3 unused frequency bins--+
|
||||
* | | |
|
||||
* | | +--1 band containing 4 subbands
|
||||
* | |
|
||||
* | +--1 subband of 12 frequency bins
|
||||
* |
|
||||
* +--DC frequency bin
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AC3DEC_H
|
||||
#define AVCODEC_AC3DEC_H
|
||||
|
||||
#include "libavutil/float_dsp.h"
|
||||
#include "libavutil/lfg.h"
|
||||
#include "ac3.h"
|
||||
#include "ac3dsp.h"
|
||||
#include "get_bits.h"
|
||||
#include "dsputil.h"
|
||||
#include "fft.h"
|
||||
#include "fmtconvert.h"
|
||||
|
||||
#define AC3_OUTPUT_LFEON 8
|
||||
|
||||
#define SPX_MAX_BANDS 17
|
||||
|
||||
/** Large enough for maximum possible frame size when the specification limit is ignored */
|
||||
#define AC3_FRAME_BUFFER_SIZE 32768
|
||||
|
||||
typedef struct AC3DecodeContext {
|
||||
AVClass *class; ///< class for AVOptions
|
||||
AVCodecContext *avctx; ///< parent context
|
||||
GetBitContext gbc; ///< bitstream reader
|
||||
|
||||
///@name Bit stream information
|
||||
///@{
|
||||
int frame_type; ///< frame type (strmtyp)
|
||||
int substreamid; ///< substream identification
|
||||
int frame_size; ///< current frame size, in bytes
|
||||
int bit_rate; ///< stream bit rate, in bits-per-second
|
||||
int sample_rate; ///< sample frequency, in Hz
|
||||
int num_blocks; ///< number of audio blocks
|
||||
int bitstream_id; ///< bitstream id (bsid)
|
||||
int bitstream_mode; ///< bitstream mode (bsmod)
|
||||
int channel_mode; ///< channel mode (acmod)
|
||||
int lfe_on; ///< lfe channel in use
|
||||
int channel_map; ///< custom channel map
|
||||
int preferred_downmix; ///< Preferred 2-channel downmix mode (dmixmod)
|
||||
int center_mix_level; ///< Center mix level index
|
||||
int center_mix_level_ltrt; ///< Center mix level index for Lt/Rt (ltrtcmixlev)
|
||||
int surround_mix_level; ///< Surround mix level index
|
||||
int surround_mix_level_ltrt; ///< Surround mix level index for Lt/Rt (ltrtsurmixlev)
|
||||
int lfe_mix_level_exists; ///< indicates if lfemixlevcod is specified (lfemixlevcode)
|
||||
int lfe_mix_level; ///< LFE mix level index (lfemixlevcod)
|
||||
int eac3; ///< indicates if current frame is E-AC-3
|
||||
int dolby_surround_mode; ///< dolby surround mode (dsurmod)
|
||||
int dolby_surround_ex_mode; ///< dolby surround ex mode (dsurexmod)
|
||||
int dolby_headphone_mode; ///< dolby headphone mode (dheadphonmod)
|
||||
///@}
|
||||
|
||||
int preferred_stereo_downmix;
|
||||
float ltrt_center_mix_level;
|
||||
float ltrt_surround_mix_level;
|
||||
float loro_center_mix_level;
|
||||
float loro_surround_mix_level;
|
||||
|
||||
///@name Frame syntax parameters
|
||||
int snr_offset_strategy; ///< SNR offset strategy (snroffststr)
|
||||
int block_switch_syntax; ///< block switch syntax enabled (blkswe)
|
||||
int dither_flag_syntax; ///< dither flag syntax enabled (dithflage)
|
||||
int bit_allocation_syntax; ///< bit allocation model syntax enabled (bamode)
|
||||
int fast_gain_syntax; ///< fast gain codes enabled (frmfgaincode)
|
||||
int dba_syntax; ///< delta bit allocation syntax enabled (dbaflde)
|
||||
int skip_syntax; ///< skip field syntax enabled (skipflde)
|
||||
///@}
|
||||
|
||||
///@name Standard coupling
|
||||
int cpl_in_use[AC3_MAX_BLOCKS]; ///< coupling in use (cplinu)
|
||||
int cpl_strategy_exists[AC3_MAX_BLOCKS];///< coupling strategy exists (cplstre)
|
||||
int channel_in_cpl[AC3_MAX_CHANNELS]; ///< channel in coupling (chincpl)
|
||||
int phase_flags_in_use; ///< phase flags in use (phsflginu)
|
||||
int phase_flags[AC3_MAX_CPL_BANDS]; ///< phase flags (phsflg)
|
||||
int num_cpl_bands; ///< number of coupling bands (ncplbnd)
|
||||
uint8_t cpl_band_sizes[AC3_MAX_CPL_BANDS]; ///< number of coeffs in each coupling band
|
||||
int firstchincpl; ///< first channel in coupling
|
||||
int first_cpl_coords[AC3_MAX_CHANNELS]; ///< first coupling coordinates states (firstcplcos)
|
||||
int cpl_coords[AC3_MAX_CHANNELS][AC3_MAX_CPL_BANDS]; ///< coupling coordinates (cplco)
|
||||
///@}
|
||||
|
||||
///@name Spectral extension
|
||||
///@{
|
||||
int spx_in_use; ///< spectral extension in use (spxinu)
|
||||
uint8_t channel_uses_spx[AC3_MAX_CHANNELS]; ///< channel uses spectral extension (chinspx)
|
||||
int8_t spx_atten_code[AC3_MAX_CHANNELS]; ///< spx attenuation code (spxattencod)
|
||||
int spx_src_start_freq; ///< spx start frequency bin
|
||||
int spx_dst_end_freq; ///< spx end frequency bin
|
||||
int spx_dst_start_freq; ///< spx starting frequency bin for copying (copystartmant)
|
||||
///< the copy region ends at the start of the spx region.
|
||||
int num_spx_bands; ///< number of spx bands (nspxbnds)
|
||||
uint8_t spx_band_sizes[SPX_MAX_BANDS]; ///< number of bins in each spx band
|
||||
uint8_t first_spx_coords[AC3_MAX_CHANNELS]; ///< first spx coordinates states (firstspxcos)
|
||||
float spx_noise_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]; ///< spx noise blending factor (nblendfact)
|
||||
float spx_signal_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS];///< spx signal blending factor (sblendfact)
|
||||
///@}
|
||||
|
||||
///@name Adaptive hybrid transform
|
||||
int channel_uses_aht[AC3_MAX_CHANNELS]; ///< channel AHT in use (chahtinu)
|
||||
int pre_mantissa[AC3_MAX_CHANNELS][AC3_MAX_COEFS][AC3_MAX_BLOCKS]; ///< pre-IDCT mantissas
|
||||
///@}
|
||||
|
||||
///@name Channel
|
||||
int fbw_channels; ///< number of full-bandwidth channels
|
||||
int channels; ///< number of total channels
|
||||
int lfe_ch; ///< index of LFE channel
|
||||
float downmix_coeffs[AC3_MAX_CHANNELS][2]; ///< stereo downmix coefficients
|
||||
int downmixed; ///< indicates if coeffs are currently downmixed
|
||||
int output_mode; ///< output channel configuration
|
||||
int out_channels; ///< number of output channels
|
||||
///@}
|
||||
|
||||
///@name Dynamic range
|
||||
float dynamic_range[2]; ///< dynamic range
|
||||
float drc_scale; ///< percentage of dynamic range compression to be applied
|
||||
///@}
|
||||
|
||||
///@name Bandwidth
|
||||
int start_freq[AC3_MAX_CHANNELS]; ///< start frequency bin (strtmant)
|
||||
int end_freq[AC3_MAX_CHANNELS]; ///< end frequency bin (endmant)
|
||||
///@}
|
||||
|
||||
///@name Rematrixing
|
||||
int num_rematrixing_bands; ///< number of rematrixing bands (nrematbnd)
|
||||
int rematrixing_flags[4]; ///< rematrixing flags (rematflg)
|
||||
///@}
|
||||
|
||||
///@name Exponents
|
||||
int num_exp_groups[AC3_MAX_CHANNELS]; ///< Number of exponent groups (nexpgrp)
|
||||
int8_t dexps[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< decoded exponents
|
||||
int exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS]; ///< exponent strategies (expstr)
|
||||
///@}
|
||||
|
||||
///@name Bit allocation
|
||||
AC3BitAllocParameters bit_alloc_params; ///< bit allocation parameters
|
||||
int first_cpl_leak; ///< first coupling leak state (firstcplleak)
|
||||
int snr_offset[AC3_MAX_CHANNELS]; ///< signal-to-noise ratio offsets (snroffst)
|
||||
int fast_gain[AC3_MAX_CHANNELS]; ///< fast gain values/SMR's (fgain)
|
||||
uint8_t bap[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< bit allocation pointers
|
||||
int16_t psd[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< scaled exponents
|
||||
int16_t band_psd[AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS]; ///< interpolated exponents
|
||||
int16_t mask[AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS]; ///< masking curve values
|
||||
int dba_mode[AC3_MAX_CHANNELS]; ///< delta bit allocation mode
|
||||
int dba_nsegs[AC3_MAX_CHANNELS]; ///< number of delta segments
|
||||
uint8_t dba_offsets[AC3_MAX_CHANNELS][8]; ///< delta segment offsets
|
||||
uint8_t dba_lengths[AC3_MAX_CHANNELS][8]; ///< delta segment lengths
|
||||
uint8_t dba_values[AC3_MAX_CHANNELS][8]; ///< delta values for each segment
|
||||
///@}
|
||||
|
||||
///@name Zero-mantissa dithering
|
||||
int dither_flag[AC3_MAX_CHANNELS]; ///< dither flags (dithflg)
|
||||
AVLFG dith_state; ///< for dither generation
|
||||
///@}
|
||||
|
||||
///@name IMDCT
|
||||
int block_switch[AC3_MAX_CHANNELS]; ///< block switch flags (blksw)
|
||||
FFTContext imdct_512; ///< for 512 sample IMDCT
|
||||
FFTContext imdct_256; ///< for 256 sample IMDCT
|
||||
///@}
|
||||
|
||||
///@name Optimization
|
||||
DSPContext dsp; ///< for optimization
|
||||
AVFloatDSPContext fdsp;
|
||||
AC3DSPContext ac3dsp;
|
||||
FmtConvertContext fmt_conv; ///< optimized conversion functions
|
||||
///@}
|
||||
|
||||
float *outptr[AC3_MAX_CHANNELS];
|
||||
float *xcfptr[AC3_MAX_CHANNELS];
|
||||
float *dlyptr[AC3_MAX_CHANNELS];
|
||||
|
||||
///@name Aligned arrays
|
||||
DECLARE_ALIGNED(16, int32_t, fixed_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< fixed-point transform coefficients
|
||||
DECLARE_ALIGNED(32, float, transform_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< transform coefficients
|
||||
DECLARE_ALIGNED(32, float, delay)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< delay - added to the next block
|
||||
DECLARE_ALIGNED(32, float, window)[AC3_BLOCK_SIZE]; ///< window coefficients
|
||||
DECLARE_ALIGNED(32, float, tmp_output)[AC3_BLOCK_SIZE]; ///< temporary storage for output before windowing
|
||||
DECLARE_ALIGNED(32, float, output)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< output after imdct transform and windowing
|
||||
DECLARE_ALIGNED(32, uint8_t, input_buffer)[AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; ///< temp buffer to prevent overread
|
||||
///@}
|
||||
} AC3DecodeContext;
|
||||
|
||||
/**
|
||||
* Parse the E-AC-3 frame header.
|
||||
* This parses both the bit stream info and audio frame header.
|
||||
*/
|
||||
int ff_eac3_parse_header(AC3DecodeContext *s);
|
||||
|
||||
/**
|
||||
* Decode mantissas in a single channel for the entire frame.
|
||||
* This is used when AHT mode is enabled.
|
||||
*/
|
||||
void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch);
|
||||
|
||||
/**
|
||||
* Apply spectral extension to each channel by copying lower frequency
|
||||
* coefficients to higher frequency bins and applying side information to
|
||||
* approximate the original high frequency signal.
|
||||
*/
|
||||
void ff_eac3_apply_spectral_extension(AC3DecodeContext *s);
|
||||
|
||||
#endif /* AVCODEC_AC3DEC_H */
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* AC-3 and E-AC-3 decoder tables
|
||||
* Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tables taken directly from the AC-3 spec.
|
||||
*/
|
||||
|
||||
#include "ac3dec_data.h"
|
||||
#include "ac3.h"
|
||||
|
||||
/**
|
||||
* Table used to ungroup 3 values stored in 5 bits.
|
||||
* Used by bap=1 mantissas and GAQ.
|
||||
* ff_ac3_ungroup_3_in_5_bits_tab[i] = { i/9, (i%9)/3, (i%9)%3 }
|
||||
*/
|
||||
const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3] = {
|
||||
{ 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 }, { 0, 1, 0 },
|
||||
{ 0, 1, 1 }, { 0, 1, 2 }, { 0, 2, 0 }, { 0, 2, 1 },
|
||||
{ 0, 2, 2 }, { 1, 0, 0 }, { 1, 0, 1 }, { 1, 0, 2 },
|
||||
{ 1, 1, 0 }, { 1, 1, 1 }, { 1, 1, 2 }, { 1, 2, 0 },
|
||||
{ 1, 2, 1 }, { 1, 2, 2 }, { 2, 0, 0 }, { 2, 0, 1 },
|
||||
{ 2, 0, 2 }, { 2, 1, 0 }, { 2, 1, 1 }, { 2, 1, 2 },
|
||||
{ 2, 2, 0 }, { 2, 2, 1 }, { 2, 2, 2 }, { 3, 0, 0 },
|
||||
{ 3, 0, 1 }, { 3, 0, 2 }, { 3, 1, 0 }, { 3, 1, 1 }
|
||||
};
|
||||
|
||||
const uint8_t ff_eac3_hebap_tab[64] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 8,
|
||||
8, 8, 9, 9, 9, 10, 10, 10, 10, 11,
|
||||
11, 11, 11, 12, 12, 12, 12, 13, 13, 13,
|
||||
13, 14, 14, 14, 14, 15, 15, 15, 15, 16,
|
||||
16, 16, 16, 17, 17, 17, 17, 18, 18, 18,
|
||||
18, 18, 18, 18, 18, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19,
|
||||
};
|
||||
|
||||
/**
|
||||
* Table E2.15 Default Spectral Extension Banding Structure
|
||||
*/
|
||||
const uint8_t ff_eac3_default_spx_band_struct[17] =
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* AC-3 and E-AC-3 decoder tables
|
||||
* Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AC3DEC_DATA_H
|
||||
#define AVCODEC_AC3DEC_DATA_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3];
|
||||
|
||||
extern const uint8_t ff_eac3_hebap_tab[64];
|
||||
extern const uint8_t ff_eac3_default_spx_band_struct[17];
|
||||
|
||||
#endif /* AVCODEC_AC3DEC_DATA_H */
|
|
@ -1,277 +0,0 @@
|
|||
/*
|
||||
* AC-3 DSP utils
|
||||
* Copyright (c) 2011 Justin Ruggles
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavutil/avassert.h"
|
||||
#include "avcodec.h"
|
||||
#include "ac3.h"
|
||||
#include "ac3dsp.h"
|
||||
#include "mathops.h"
|
||||
|
||||
static void ac3_exponent_min_c(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
|
||||
{
|
||||
int blk, i;
|
||||
|
||||
if (!num_reuse_blocks)
|
||||
return;
|
||||
|
||||
for (i = 0; i < nb_coefs; i++) {
|
||||
uint8_t min_exp = *exp;
|
||||
uint8_t *exp1 = exp + 256;
|
||||
for (blk = 0; blk < num_reuse_blocks; blk++) {
|
||||
uint8_t next_exp = *exp1;
|
||||
if (next_exp < min_exp)
|
||||
min_exp = next_exp;
|
||||
exp1 += 256;
|
||||
}
|
||||
*exp++ = min_exp;
|
||||
}
|
||||
}
|
||||
|
||||
static int ac3_max_msb_abs_int16_c(const int16_t *src, int len)
|
||||
{
|
||||
int i, v = 0;
|
||||
for (i = 0; i < len; i++)
|
||||
v |= abs(src[i]);
|
||||
return v;
|
||||
}
|
||||
|
||||
static void ac3_lshift_int16_c(int16_t *src, unsigned int len,
|
||||
unsigned int shift)
|
||||
{
|
||||
uint32_t *src32 = (uint32_t *)src;
|
||||
const uint32_t mask = ~(((1 << shift) - 1) << 16);
|
||||
int i;
|
||||
len >>= 1;
|
||||
for (i = 0; i < len; i += 8) {
|
||||
src32[i ] = (src32[i ] << shift) & mask;
|
||||
src32[i+1] = (src32[i+1] << shift) & mask;
|
||||
src32[i+2] = (src32[i+2] << shift) & mask;
|
||||
src32[i+3] = (src32[i+3] << shift) & mask;
|
||||
src32[i+4] = (src32[i+4] << shift) & mask;
|
||||
src32[i+5] = (src32[i+5] << shift) & mask;
|
||||
src32[i+6] = (src32[i+6] << shift) & mask;
|
||||
src32[i+7] = (src32[i+7] << shift) & mask;
|
||||
}
|
||||
}
|
||||
|
||||
static void ac3_rshift_int32_c(int32_t *src, unsigned int len,
|
||||
unsigned int shift)
|
||||
{
|
||||
do {
|
||||
*src++ >>= shift;
|
||||
*src++ >>= shift;
|
||||
*src++ >>= shift;
|
||||
*src++ >>= shift;
|
||||
*src++ >>= shift;
|
||||
*src++ >>= shift;
|
||||
*src++ >>= shift;
|
||||
*src++ >>= shift;
|
||||
len -= 8;
|
||||
} while (len > 0);
|
||||
}
|
||||
|
||||
static void float_to_fixed24_c(int32_t *dst, const float *src, unsigned int len)
|
||||
{
|
||||
const float scale = 1 << 24;
|
||||
do {
|
||||
*dst++ = lrintf(*src++ * scale);
|
||||
*dst++ = lrintf(*src++ * scale);
|
||||
*dst++ = lrintf(*src++ * scale);
|
||||
*dst++ = lrintf(*src++ * scale);
|
||||
*dst++ = lrintf(*src++ * scale);
|
||||
*dst++ = lrintf(*src++ * scale);
|
||||
*dst++ = lrintf(*src++ * scale);
|
||||
*dst++ = lrintf(*src++ * scale);
|
||||
len -= 8;
|
||||
} while (len > 0);
|
||||
}
|
||||
|
||||
static void ac3_bit_alloc_calc_bap_c(int16_t *mask, int16_t *psd,
|
||||
int start, int end,
|
||||
int snr_offset, int floor,
|
||||
const uint8_t *bap_tab, uint8_t *bap)
|
||||
{
|
||||
int bin, band, band_end;
|
||||
|
||||
/* special case, if snr offset is -960, set all bap's to zero */
|
||||
if (snr_offset == -960) {
|
||||
memset(bap, 0, AC3_MAX_COEFS);
|
||||
return;
|
||||
}
|
||||
|
||||
bin = start;
|
||||
band = ff_ac3_bin_to_band_tab[start];
|
||||
do {
|
||||
int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor;
|
||||
band_end = ff_ac3_band_start_tab[++band];
|
||||
band_end = FFMIN(band_end, end);
|
||||
|
||||
for (; bin < band_end; bin++) {
|
||||
int address = av_clip((psd[bin] - m) >> 5, 0, 63);
|
||||
bap[bin] = bap_tab[address];
|
||||
}
|
||||
} while (end > band_end);
|
||||
}
|
||||
|
||||
static void ac3_update_bap_counts_c(uint16_t mant_cnt[16], uint8_t *bap,
|
||||
int len)
|
||||
{
|
||||
while (len-- > 0)
|
||||
mant_cnt[bap[len]]++;
|
||||
}
|
||||
|
||||
DECLARE_ALIGNED(16, const uint16_t, ff_ac3_bap_bits)[16] = {
|
||||
0, 0, 0, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16
|
||||
};
|
||||
|
||||
static int ac3_compute_mantissa_size_c(uint16_t mant_cnt[6][16])
|
||||
{
|
||||
int blk, bap;
|
||||
int bits = 0;
|
||||
|
||||
for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
|
||||
// bap=1 : 3 mantissas in 5 bits
|
||||
bits += (mant_cnt[blk][1] / 3) * 5;
|
||||
// bap=2 : 3 mantissas in 7 bits
|
||||
// bap=4 : 2 mantissas in 7 bits
|
||||
bits += ((mant_cnt[blk][2] / 3) + (mant_cnt[blk][4] >> 1)) * 7;
|
||||
// bap=3 : 1 mantissa in 3 bits
|
||||
bits += mant_cnt[blk][3] * 3;
|
||||
// bap=5 to 15 : get bits per mantissa from table
|
||||
for (bap = 5; bap < 16; bap++)
|
||||
bits += mant_cnt[blk][bap] * ff_ac3_bap_bits[bap];
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
|
||||
static void ac3_extract_exponents_c(uint8_t *exp, int32_t *coef, int nb_coefs)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nb_coefs; i++) {
|
||||
int v = abs(coef[i]);
|
||||
exp[i] = v ? 23 - av_log2(v) : 24;
|
||||
}
|
||||
}
|
||||
|
||||
static void ac3_sum_square_butterfly_int32_c(int64_t sum[4],
|
||||
const int32_t *coef0,
|
||||
const int32_t *coef1,
|
||||
int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
sum[0] = sum[1] = sum[2] = sum[3] = 0;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
int lt = coef0[i];
|
||||
int rt = coef1[i];
|
||||
int md = lt + rt;
|
||||
int sd = lt - rt;
|
||||
MAC64(sum[0], lt, lt);
|
||||
MAC64(sum[1], rt, rt);
|
||||
MAC64(sum[2], md, md);
|
||||
MAC64(sum[3], sd, sd);
|
||||
}
|
||||
}
|
||||
|
||||
static void ac3_sum_square_butterfly_float_c(float sum[4],
|
||||
const float *coef0,
|
||||
const float *coef1,
|
||||
int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
sum[0] = sum[1] = sum[2] = sum[3] = 0;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
float lt = coef0[i];
|
||||
float rt = coef1[i];
|
||||
float md = lt + rt;
|
||||
float sd = lt - rt;
|
||||
sum[0] += lt * lt;
|
||||
sum[1] += rt * rt;
|
||||
sum[2] += md * md;
|
||||
sum[3] += sd * sd;
|
||||
}
|
||||
}
|
||||
|
||||
static void ac3_downmix_c(float **samples, float (*matrix)[2],
|
||||
int out_ch, int in_ch, int len)
|
||||
{
|
||||
int i, j;
|
||||
float v0, v1;
|
||||
if (out_ch == 2) {
|
||||
for (i = 0; i < len; i++) {
|
||||
v0 = v1 = 0.0f;
|
||||
for (j = 0; j < in_ch; j++) {
|
||||
v0 += samples[j][i] * matrix[j][0];
|
||||
v1 += samples[j][i] * matrix[j][1];
|
||||
}
|
||||
samples[0][i] = v0;
|
||||
samples[1][i] = v1;
|
||||
}
|
||||
} else if (out_ch == 1) {
|
||||
for (i = 0; i < len; i++) {
|
||||
v0 = 0.0f;
|
||||
for (j = 0; j < in_ch; j++)
|
||||
v0 += samples[j][i] * matrix[j][0];
|
||||
samples[0][i] = v0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void apply_window_int16_c(int16_t *output, const int16_t *input,
|
||||
const int16_t *window, unsigned int len)
|
||||
{
|
||||
int i;
|
||||
int len2 = len >> 1;
|
||||
|
||||
for (i = 0; i < len2; i++) {
|
||||
int16_t w = window[i];
|
||||
output[i] = (MUL16(input[i], w) + (1 << 14)) >> 15;
|
||||
output[len-i-1] = (MUL16(input[len-i-1], w) + (1 << 14)) >> 15;
|
||||
}
|
||||
}
|
||||
|
||||
av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
|
||||
{
|
||||
c->ac3_exponent_min = ac3_exponent_min_c;
|
||||
c->ac3_max_msb_abs_int16 = ac3_max_msb_abs_int16_c;
|
||||
c->ac3_lshift_int16 = ac3_lshift_int16_c;
|
||||
c->ac3_rshift_int32 = ac3_rshift_int32_c;
|
||||
c->float_to_fixed24 = float_to_fixed24_c;
|
||||
c->bit_alloc_calc_bap = ac3_bit_alloc_calc_bap_c;
|
||||
c->update_bap_counts = ac3_update_bap_counts_c;
|
||||
c->compute_mantissa_size = ac3_compute_mantissa_size_c;
|
||||
c->extract_exponents = ac3_extract_exponents_c;
|
||||
c->sum_square_butterfly_int32 = ac3_sum_square_butterfly_int32_c;
|
||||
c->sum_square_butterfly_float = ac3_sum_square_butterfly_float_c;
|
||||
c->downmix = ac3_downmix_c;
|
||||
c->apply_window_int16 = apply_window_int16_c;
|
||||
|
||||
if (ARCH_ARM)
|
||||
ff_ac3dsp_init_arm(c, bit_exact);
|
||||
if (ARCH_X86)
|
||||
ff_ac3dsp_init_x86(c, bit_exact);
|
||||
if (ARCH_MIPS)
|
||||
ff_ac3dsp_init_mips(c, bit_exact);
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
/*
|
||||
* AC-3 DSP utils
|
||||
* Copyright (c) 2011 Justin Ruggles
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AC3DSP_H
|
||||
#define AVCODEC_AC3DSP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Number of mantissa bits written for each bap value.
|
||||
* bap values with fractional bits are set to 0 and are calculated separately.
|
||||
*/
|
||||
extern const uint16_t ff_ac3_bap_bits[16];
|
||||
|
||||
typedef struct AC3DSPContext {
|
||||
/**
|
||||
* Set each encoded exponent in a block to the minimum of itself and the
|
||||
* exponents in the same frequency bin of up to 5 following blocks.
|
||||
* @param exp pointer to the start of the current block of exponents.
|
||||
* constraints: align 16
|
||||
* @param num_reuse_blocks number of blocks that will reuse exponents from the current block.
|
||||
* constraints: range 0 to 5
|
||||
* @param nb_coefs number of frequency coefficients.
|
||||
*/
|
||||
void (*ac3_exponent_min)(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
|
||||
|
||||
/**
|
||||
* Calculate the maximum MSB of the absolute value of each element in an
|
||||
* array of int16_t.
|
||||
* @param src input array
|
||||
* constraints: align 16. values must be in range [-32767,32767]
|
||||
* @param len number of values in the array
|
||||
* constraints: multiple of 16 greater than 0
|
||||
* @return a value with the same MSB as max(abs(src[]))
|
||||
*/
|
||||
int (*ac3_max_msb_abs_int16)(const int16_t *src, int len);
|
||||
|
||||
/**
|
||||
* Left-shift each value in an array of int16_t by a specified amount.
|
||||
* @param src input array
|
||||
* constraints: align 16
|
||||
* @param len number of values in the array
|
||||
* constraints: multiple of 32 greater than 0
|
||||
* @param shift left shift amount
|
||||
* constraints: range [0,15]
|
||||
*/
|
||||
void (*ac3_lshift_int16)(int16_t *src, unsigned int len, unsigned int shift);
|
||||
|
||||
/**
|
||||
* Right-shift each value in an array of int32_t by a specified amount.
|
||||
* @param src input array
|
||||
* constraints: align 16
|
||||
* @param len number of values in the array
|
||||
* constraints: multiple of 16 greater than 0
|
||||
* @param shift right shift amount
|
||||
* constraints: range [0,31]
|
||||
*/
|
||||
void (*ac3_rshift_int32)(int32_t *src, unsigned int len, unsigned int shift);
|
||||
|
||||
/**
|
||||
* Convert an array of float in range [-1.0,1.0] to int32_t with range
|
||||
* [-(1<<24),(1<<24)]
|
||||
*
|
||||
* @param dst destination array of int32_t.
|
||||
* constraints: 16-byte aligned
|
||||
* @param src source array of float.
|
||||
* constraints: 16-byte aligned
|
||||
* @param len number of elements to convert.
|
||||
* constraints: multiple of 32 greater than zero
|
||||
*/
|
||||
void (*float_to_fixed24)(int32_t *dst, const float *src, unsigned int len);
|
||||
|
||||
/**
|
||||
* Calculate bit allocation pointers.
|
||||
* The SNR is the difference between the masking curve and the signal. AC-3
|
||||
* uses this value for each frequency bin to allocate bits. The snroffset
|
||||
* parameter is a global adjustment to the SNR for all bins.
|
||||
*
|
||||
* @param[in] mask masking curve
|
||||
* @param[in] psd signal power for each frequency bin
|
||||
* @param[in] start starting bin location
|
||||
* @param[in] end ending bin location
|
||||
* @param[in] snr_offset SNR adjustment
|
||||
* @param[in] floor noise floor
|
||||
* @param[in] bap_tab look-up table for bit allocation pointers
|
||||
* @param[out] bap bit allocation pointers
|
||||
*/
|
||||
void (*bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end,
|
||||
int snr_offset, int floor,
|
||||
const uint8_t *bap_tab, uint8_t *bap);
|
||||
|
||||
/**
|
||||
* Update bap counts using the supplied array of bap.
|
||||
*
|
||||
* @param[out] mant_cnt bap counts for 1 block
|
||||
* @param[in] bap array of bap, pointing to start coef bin
|
||||
* @param[in] len number of elements to process
|
||||
*/
|
||||
void (*update_bap_counts)(uint16_t mant_cnt[16], uint8_t *bap, int len);
|
||||
|
||||
/**
|
||||
* Calculate the number of bits needed to encode a set of mantissas.
|
||||
*
|
||||
* @param[in] mant_cnt bap counts for all blocks
|
||||
* @return mantissa bit count
|
||||
*/
|
||||
int (*compute_mantissa_size)(uint16_t mant_cnt[6][16]);
|
||||
|
||||
void (*extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs);
|
||||
|
||||
void (*sum_square_butterfly_int32)(int64_t sum[4], const int32_t *coef0,
|
||||
const int32_t *coef1, int len);
|
||||
|
||||
void (*sum_square_butterfly_float)(float sum[4], const float *coef0,
|
||||
const float *coef1, int len);
|
||||
|
||||
void (*downmix)(float **samples, float (*matrix)[2], int out_ch,
|
||||
int in_ch, int len);
|
||||
|
||||
/**
|
||||
* Apply symmetric window in 16-bit fixed-point.
|
||||
* @param output destination array
|
||||
* constraints: 16-byte aligned
|
||||
* @param input source array
|
||||
* constraints: 16-byte aligned
|
||||
* @param window window array
|
||||
* constraints: 16-byte aligned, at least len/2 elements
|
||||
* @param len full window length
|
||||
* constraints: multiple of ? greater than zero
|
||||
*/
|
||||
void (*apply_window_int16)(int16_t *output, const int16_t *input,
|
||||
const int16_t *window, unsigned int len);
|
||||
} AC3DSPContext;
|
||||
|
||||
void ff_ac3dsp_init (AC3DSPContext *c, int bit_exact);
|
||||
void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact);
|
||||
void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact);
|
||||
void ff_ac3dsp_init_mips(AC3DSPContext *c, int bit_exact);
|
||||
|
||||
#endif /* AVCODEC_AC3DSP_H */
|
|
@ -1,314 +0,0 @@
|
|||
/*
|
||||
* AC-3 tables
|
||||
* copyright (c) 2001 Fabrice Bellard
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* tables taken directly from the AC-3 spec.
|
||||
*/
|
||||
|
||||
#include "libavutil/channel_layout.h"
|
||||
#include "avcodec.h"
|
||||
#include "ac3tab.h"
|
||||
|
||||
/**
|
||||
* Possible frame sizes.
|
||||
* from ATSC A/52 Table 5.18 Frame Size Code Table.
|
||||
*/
|
||||
const uint16_t ff_ac3_frame_size_tab[38][3] = {
|
||||
{ 64, 69, 96 },
|
||||
{ 64, 70, 96 },
|
||||
{ 80, 87, 120 },
|
||||
{ 80, 88, 120 },
|
||||
{ 96, 104, 144 },
|
||||
{ 96, 105, 144 },
|
||||
{ 112, 121, 168 },
|
||||
{ 112, 122, 168 },
|
||||
{ 128, 139, 192 },
|
||||
{ 128, 140, 192 },
|
||||
{ 160, 174, 240 },
|
||||
{ 160, 175, 240 },
|
||||
{ 192, 208, 288 },
|
||||
{ 192, 209, 288 },
|
||||
{ 224, 243, 336 },
|
||||
{ 224, 244, 336 },
|
||||
{ 256, 278, 384 },
|
||||
{ 256, 279, 384 },
|
||||
{ 320, 348, 480 },
|
||||
{ 320, 349, 480 },
|
||||
{ 384, 417, 576 },
|
||||
{ 384, 418, 576 },
|
||||
{ 448, 487, 672 },
|
||||
{ 448, 488, 672 },
|
||||
{ 512, 557, 768 },
|
||||
{ 512, 558, 768 },
|
||||
{ 640, 696, 960 },
|
||||
{ 640, 697, 960 },
|
||||
{ 768, 835, 1152 },
|
||||
{ 768, 836, 1152 },
|
||||
{ 896, 975, 1344 },
|
||||
{ 896, 976, 1344 },
|
||||
{ 1024, 1114, 1536 },
|
||||
{ 1024, 1115, 1536 },
|
||||
{ 1152, 1253, 1728 },
|
||||
{ 1152, 1254, 1728 },
|
||||
{ 1280, 1393, 1920 },
|
||||
{ 1280, 1394, 1920 },
|
||||
};
|
||||
|
||||
/**
|
||||
* Map audio coding mode (acmod) to number of full-bandwidth channels.
|
||||
* from ATSC A/52 Table 5.8 Audio Coding Mode
|
||||
*/
|
||||
const uint8_t ff_ac3_channels_tab[8] = {
|
||||
2, 1, 2, 3, 3, 4, 4, 5
|
||||
};
|
||||
|
||||
/**
|
||||
* Map audio coding mode (acmod) to channel layout mask.
|
||||
*/
|
||||
const uint16_t avpriv_ac3_channel_layout_tab[8] = {
|
||||
AV_CH_LAYOUT_STEREO,
|
||||
AV_CH_LAYOUT_MONO,
|
||||
AV_CH_LAYOUT_STEREO,
|
||||
AV_CH_LAYOUT_SURROUND,
|
||||
AV_CH_LAYOUT_2_1,
|
||||
AV_CH_LAYOUT_4POINT0,
|
||||
AV_CH_LAYOUT_2_2,
|
||||
AV_CH_LAYOUT_5POINT0
|
||||
};
|
||||
|
||||
#define COMMON_CHANNEL_MAP \
|
||||
{ { 0, 1, }, { 0, 1, 2, } },\
|
||||
{ { 0, }, { 0, 1, } },\
|
||||
{ { 0, 1, }, { 0, 1, 2, } },\
|
||||
{ { 0, 2, 1, }, { 0, 2, 1, 3, } },\
|
||||
{ { 0, 1, 2, }, { 0, 1, 3, 2, } },\
|
||||
{ { 0, 2, 1, 3, }, { 0, 2, 1, 4, 3, } },
|
||||
|
||||
/**
|
||||
* Table to remap channels from SMPTE order to AC-3 order.
|
||||
* [channel_mode][lfe][ch]
|
||||
*/
|
||||
const uint8_t ff_ac3_enc_channel_map[8][2][6] = {
|
||||
COMMON_CHANNEL_MAP
|
||||
{ { 0, 1, 2, 3, }, { 0, 1, 3, 4, 2, } },
|
||||
{ { 0, 2, 1, 3, 4, }, { 0, 2, 1, 4, 5, 3 } },
|
||||
};
|
||||
|
||||
/**
|
||||
* Table to remap channels from AC-3 order to SMPTE order.
|
||||
* [channel_mode][lfe][ch]
|
||||
*/
|
||||
const uint8_t ff_ac3_dec_channel_map[8][2][6] = {
|
||||
COMMON_CHANNEL_MAP
|
||||
{ { 0, 1, 2, 3, }, { 0, 1, 4, 2, 3, } },
|
||||
{ { 0, 2, 1, 3, 4, }, { 0, 2, 1, 5, 3, 4 } },
|
||||
};
|
||||
|
||||
/* possible frequencies */
|
||||
const uint16_t ff_ac3_sample_rate_tab[3] = { 48000, 44100, 32000 };
|
||||
|
||||
/* possible bitrates */
|
||||
const uint16_t ff_ac3_bitrate_tab[19] = {
|
||||
32, 40, 48, 56, 64, 80, 96, 112, 128,
|
||||
160, 192, 224, 256, 320, 384, 448, 512, 576, 640
|
||||
};
|
||||
|
||||
/**
|
||||
* Table of bin locations for rematrixing bands
|
||||
* reference: Section 7.5.2 Rematrixing : Frequency Band Definitions
|
||||
*/
|
||||
const uint8_t ff_ac3_rematrix_band_tab[5] = { 13, 25, 37, 61, 253 };
|
||||
|
||||
/**
|
||||
* Table E2.16 Default Coupling Banding Structure
|
||||
*/
|
||||
const uint8_t ff_eac3_default_cpl_band_struct[18] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1
|
||||
};
|
||||
|
||||
/* AC-3 MDCT window */
|
||||
|
||||
/* MDCT window */
|
||||
DECLARE_ALIGNED(16, const int16_t, ff_ac3_window)[AC3_WINDOW_SIZE/2] = {
|
||||
4, 7, 12, 16, 21, 28, 34, 42,
|
||||
51, 61, 72, 84, 97, 111, 127, 145,
|
||||
164, 184, 207, 231, 257, 285, 315, 347,
|
||||
382, 419, 458, 500, 544, 591, 641, 694,
|
||||
750, 810, 872, 937, 1007, 1079, 1155, 1235,
|
||||
1318, 1406, 1497, 1593, 1692, 1796, 1903, 2016,
|
||||
2132, 2253, 2379, 2509, 2644, 2783, 2927, 3076,
|
||||
3230, 3389, 3552, 3721, 3894, 4072, 4255, 4444,
|
||||
4637, 4835, 5038, 5246, 5459, 5677, 5899, 6127,
|
||||
6359, 6596, 6837, 7083, 7334, 7589, 7848, 8112,
|
||||
8380, 8652, 8927, 9207, 9491, 9778,10069,10363,
|
||||
10660,10960,11264,11570,11879,12190,12504,12820,
|
||||
13138,13458,13780,14103,14427,14753,15079,15407,
|
||||
15735,16063,16392,16720,17049,17377,17705,18032,
|
||||
18358,18683,19007,19330,19651,19970,20287,20602,
|
||||
20914,21225,21532,21837,22139,22438,22733,23025,
|
||||
23314,23599,23880,24157,24430,24699,24964,25225,
|
||||
25481,25732,25979,26221,26459,26691,26919,27142,
|
||||
27359,27572,27780,27983,28180,28373,28560,28742,
|
||||
28919,29091,29258,29420,29577,29729,29876,30018,
|
||||
30155,30288,30415,30538,30657,30771,30880,30985,
|
||||
31086,31182,31274,31363,31447,31528,31605,31678,
|
||||
31747,31814,31877,31936,31993,32046,32097,32145,
|
||||
32190,32232,32272,32310,32345,32378,32409,32438,
|
||||
32465,32490,32513,32535,32556,32574,32592,32608,
|
||||
32623,32636,32649,32661,32671,32681,32690,32698,
|
||||
32705,32712,32718,32724,32729,32733,32737,32741,
|
||||
32744,32747,32750,32752,32754,32756,32757,32759,
|
||||
32760,32761,32762,32763,32764,32764,32765,32765,
|
||||
32766,32766,32766,32766,32767,32767,32767,32767,
|
||||
32767,32767,32767,32767,32767,32767,32767,32767,
|
||||
32767,32767,32767,32767,32767,32767,32767,32767,
|
||||
};
|
||||
|
||||
const uint8_t ff_ac3_log_add_tab[260]= {
|
||||
0x40,0x3f,0x3e,0x3d,0x3c,0x3b,0x3a,0x39,0x38,0x37,
|
||||
0x36,0x35,0x34,0x34,0x33,0x32,0x31,0x30,0x2f,0x2f,
|
||||
0x2e,0x2d,0x2c,0x2c,0x2b,0x2a,0x29,0x29,0x28,0x27,
|
||||
0x26,0x26,0x25,0x24,0x24,0x23,0x23,0x22,0x21,0x21,
|
||||
0x20,0x20,0x1f,0x1e,0x1e,0x1d,0x1d,0x1c,0x1c,0x1b,
|
||||
0x1b,0x1a,0x1a,0x19,0x19,0x18,0x18,0x17,0x17,0x16,
|
||||
0x16,0x15,0x15,0x15,0x14,0x14,0x13,0x13,0x13,0x12,
|
||||
0x12,0x12,0x11,0x11,0x11,0x10,0x10,0x10,0x0f,0x0f,
|
||||
0x0f,0x0e,0x0e,0x0e,0x0d,0x0d,0x0d,0x0d,0x0c,0x0c,
|
||||
0x0c,0x0c,0x0b,0x0b,0x0b,0x0b,0x0a,0x0a,0x0a,0x0a,
|
||||
0x0a,0x09,0x09,0x09,0x09,0x09,0x08,0x08,0x08,0x08,
|
||||
0x08,0x08,0x07,0x07,0x07,0x07,0x07,0x07,0x06,0x06,
|
||||
0x06,0x06,0x06,0x06,0x06,0x06,0x05,0x05,0x05,0x05,
|
||||
0x05,0x05,0x05,0x05,0x04,0x04,0x04,0x04,0x04,0x04,
|
||||
0x04,0x04,0x04,0x04,0x04,0x03,0x03,0x03,0x03,0x03,
|
||||
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x02,
|
||||
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
|
||||
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x01,
|
||||
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
|
||||
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
|
||||
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
};
|
||||
|
||||
const uint16_t ff_ac3_hearing_threshold_tab[AC3_CRITICAL_BANDS][3]= {
|
||||
{ 0x04d0,0x04f0,0x0580 },
|
||||
{ 0x04d0,0x04f0,0x0580 },
|
||||
{ 0x0440,0x0460,0x04b0 },
|
||||
{ 0x0400,0x0410,0x0450 },
|
||||
{ 0x03e0,0x03e0,0x0420 },
|
||||
{ 0x03c0,0x03d0,0x03f0 },
|
||||
{ 0x03b0,0x03c0,0x03e0 },
|
||||
{ 0x03b0,0x03b0,0x03d0 },
|
||||
{ 0x03a0,0x03b0,0x03c0 },
|
||||
{ 0x03a0,0x03a0,0x03b0 },
|
||||
{ 0x03a0,0x03a0,0x03b0 },
|
||||
{ 0x03a0,0x03a0,0x03b0 },
|
||||
{ 0x03a0,0x03a0,0x03a0 },
|
||||
{ 0x0390,0x03a0,0x03a0 },
|
||||
{ 0x0390,0x0390,0x03a0 },
|
||||
{ 0x0390,0x0390,0x03a0 },
|
||||
{ 0x0380,0x0390,0x03a0 },
|
||||
{ 0x0380,0x0380,0x03a0 },
|
||||
{ 0x0370,0x0380,0x03a0 },
|
||||
{ 0x0370,0x0380,0x03a0 },
|
||||
{ 0x0360,0x0370,0x0390 },
|
||||
{ 0x0360,0x0370,0x0390 },
|
||||
{ 0x0350,0x0360,0x0390 },
|
||||
{ 0x0350,0x0360,0x0390 },
|
||||
{ 0x0340,0x0350,0x0380 },
|
||||
{ 0x0340,0x0350,0x0380 },
|
||||
{ 0x0330,0x0340,0x0380 },
|
||||
{ 0x0320,0x0340,0x0370 },
|
||||
{ 0x0310,0x0320,0x0360 },
|
||||
{ 0x0300,0x0310,0x0350 },
|
||||
{ 0x02f0,0x0300,0x0340 },
|
||||
{ 0x02f0,0x02f0,0x0330 },
|
||||
{ 0x02f0,0x02f0,0x0320 },
|
||||
{ 0x02f0,0x02f0,0x0310 },
|
||||
{ 0x0300,0x02f0,0x0300 },
|
||||
{ 0x0310,0x0300,0x02f0 },
|
||||
{ 0x0340,0x0320,0x02f0 },
|
||||
{ 0x0390,0x0350,0x02f0 },
|
||||
{ 0x03e0,0x0390,0x0300 },
|
||||
{ 0x0420,0x03e0,0x0310 },
|
||||
{ 0x0460,0x0420,0x0330 },
|
||||
{ 0x0490,0x0450,0x0350 },
|
||||
{ 0x04a0,0x04a0,0x03c0 },
|
||||
{ 0x0460,0x0490,0x0410 },
|
||||
{ 0x0440,0x0460,0x0470 },
|
||||
{ 0x0440,0x0440,0x04a0 },
|
||||
{ 0x0520,0x0480,0x0460 },
|
||||
{ 0x0800,0x0630,0x0440 },
|
||||
{ 0x0840,0x0840,0x0450 },
|
||||
{ 0x0840,0x0840,0x04e0 },
|
||||
};
|
||||
|
||||
const uint8_t ff_ac3_bap_tab[64]= {
|
||||
0, 1, 1, 1, 1, 1, 2, 2, 3, 3,
|
||||
3, 4, 4, 5, 5, 6, 6, 6, 6, 7,
|
||||
7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
|
||||
9, 10, 10, 10, 10, 11, 11, 11, 11, 12,
|
||||
12, 12, 12, 13, 13, 13, 13, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15,
|
||||
};
|
||||
|
||||
const uint8_t ff_ac3_slow_decay_tab[4]={
|
||||
0x0f, 0x11, 0x13, 0x15,
|
||||
};
|
||||
|
||||
const uint8_t ff_ac3_fast_decay_tab[4]={
|
||||
0x3f, 0x53, 0x67, 0x7b,
|
||||
};
|
||||
|
||||
const uint16_t ff_ac3_slow_gain_tab[4]= {
|
||||
0x540, 0x4d8, 0x478, 0x410,
|
||||
};
|
||||
|
||||
const uint16_t ff_ac3_db_per_bit_tab[4]= {
|
||||
0x000, 0x700, 0x900, 0xb00,
|
||||
};
|
||||
|
||||
const int16_t ff_ac3_floor_tab[8]= {
|
||||
0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800,
|
||||
};
|
||||
|
||||
const uint16_t ff_ac3_fast_gain_tab[8]= {
|
||||
0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400,
|
||||
};
|
||||
|
||||
/**
|
||||
* Default channel map for a dependent substream defined by acmod
|
||||
*/
|
||||
const uint16_t ff_eac3_default_chmap[8] = {
|
||||
AC3_CHMAP_L | AC3_CHMAP_R, // FIXME Ch1+Ch2
|
||||
AC3_CHMAP_C,
|
||||
AC3_CHMAP_L | AC3_CHMAP_R,
|
||||
AC3_CHMAP_L | AC3_CHMAP_C | AC3_CHMAP_R,
|
||||
AC3_CHMAP_L | AC3_CHMAP_R | AC3_CHMAP_C_SUR,
|
||||
AC3_CHMAP_L | AC3_CHMAP_C | AC3_CHMAP_R | AC3_CHMAP_C_SUR,
|
||||
AC3_CHMAP_L | AC3_CHMAP_R | AC3_CHMAP_L_SUR | AC3_CHMAP_R_SUR,
|
||||
AC3_CHMAP_L | AC3_CHMAP_C | AC3_CHMAP_R | AC3_CHMAP_L_SUR | AC3_CHMAP_R_SUR
|
||||
};
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* AC-3 tables
|
||||
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AC3TAB_H
|
||||
#define AVCODEC_AC3TAB_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libavutil/internal.h"
|
||||
#include "ac3.h"
|
||||
|
||||
#if CONFIG_HARDCODED_TABLES
|
||||
# define HCONST const
|
||||
#else
|
||||
# define HCONST
|
||||
#endif
|
||||
|
||||
extern const uint16_t ff_ac3_frame_size_tab[38][3];
|
||||
extern const uint8_t ff_ac3_channels_tab[8];
|
||||
extern av_export const uint16_t avpriv_ac3_channel_layout_tab[8];
|
||||
extern const uint8_t ff_ac3_enc_channel_map[8][2][6];
|
||||
extern const uint8_t ff_ac3_dec_channel_map[8][2][6];
|
||||
extern const uint16_t ff_ac3_sample_rate_tab[3];
|
||||
extern const uint16_t ff_ac3_bitrate_tab[19];
|
||||
extern const uint8_t ff_ac3_rematrix_band_tab[5];
|
||||
extern const uint8_t ff_eac3_default_cpl_band_struct[18];
|
||||
extern const int16_t ff_ac3_window[AC3_WINDOW_SIZE/2];
|
||||
extern const uint8_t ff_ac3_log_add_tab[260];
|
||||
extern const uint16_t ff_ac3_hearing_threshold_tab[AC3_CRITICAL_BANDS][3];
|
||||
extern const uint8_t ff_ac3_bap_tab[64];
|
||||
extern const uint8_t ff_ac3_slow_decay_tab[4];
|
||||
extern const uint8_t ff_ac3_fast_decay_tab[4];
|
||||
extern const uint16_t ff_ac3_slow_gain_tab[4];
|
||||
extern const uint16_t ff_ac3_db_per_bit_tab[4];
|
||||
extern const int16_t ff_ac3_floor_tab[8];
|
||||
extern const uint16_t ff_ac3_fast_gain_tab[8];
|
||||
extern const uint16_t ff_eac3_default_chmap[8];
|
||||
extern const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1];
|
||||
extern HCONST uint8_t ff_ac3_bin_to_band_tab[253];
|
||||
|
||||
/** Custom channel map locations bitmask
|
||||
* Other channels described in documentation:
|
||||
* Lc/Rc pair, Lrs/Rrs pair, Ts, Lsd/Rsd pair,
|
||||
* Lw/Rw pair, Lvh/Rvh pair, Cvh, Reserved, LFE2
|
||||
*/
|
||||
enum CustomChannelMapLocation{
|
||||
AC3_CHMAP_L= 1<<(15-0),
|
||||
AC3_CHMAP_C= 1<<(15-1),
|
||||
AC3_CHMAP_R= 1<<(15-2),
|
||||
AC3_CHMAP_L_SUR= 1<<(15-3),
|
||||
AC3_CHMAP_R_SUR = 1<<(15-4),
|
||||
AC3_CHMAP_C_SUR= 1<<(15-7),
|
||||
AC3_CHMAP_LFE = 1<<(15-15)
|
||||
};
|
||||
|
||||
#endif /* AVCODEC_AC3TAB_H */
|
|
@ -1,157 +0,0 @@
|
|||
/*
|
||||
* various filters for ACELP-based codecs
|
||||
*
|
||||
* Copyright (c) 2008 Vladimir Voroshilov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "libavutil/avassert.h"
|
||||
#include "libavutil/common.h"
|
||||
#include "avcodec.h"
|
||||
#include "acelp_filters.h"
|
||||
|
||||
const int16_t ff_acelp_interp_filter[61] = { /* (0.15) */
|
||||
29443, 28346, 25207, 20449, 14701, 8693,
|
||||
3143, -1352, -4402, -5865, -5850, -4673,
|
||||
-2783, -672, 1211, 2536, 3130, 2991,
|
||||
2259, 1170, 0, -1001, -1652, -1868,
|
||||
-1666, -1147, -464, 218, 756, 1060,
|
||||
1099, 904, 550, 135, -245, -514,
|
||||
-634, -602, -451, -231, 0, 191,
|
||||
308, 340, 296, 198, 78, -36,
|
||||
-120, -163, -165, -132, -79, -19,
|
||||
34, 73, 91, 89, 70, 38,
|
||||
0,
|
||||
};
|
||||
|
||||
void ff_acelp_interpolate(int16_t* out, const int16_t* in,
|
||||
const int16_t* filter_coeffs, int precision,
|
||||
int frac_pos, int filter_length, int length)
|
||||
{
|
||||
int n, i;
|
||||
|
||||
av_assert1(frac_pos >= 0 && frac_pos < precision);
|
||||
|
||||
for (n = 0; n < length; n++) {
|
||||
int idx = 0;
|
||||
int v = 0x4000;
|
||||
|
||||
for (i = 0; i < filter_length;) {
|
||||
|
||||
/* The reference G.729 and AMR fixed point code performs clipping after
|
||||
each of the two following accumulations.
|
||||
Since clipping affects only the synthetic OVERFLOW test without
|
||||
causing an int type overflow, it was moved outside the loop. */
|
||||
|
||||
/* R(x):=ac_v[-k+x]
|
||||
v += R(n-i)*ff_acelp_interp_filter(t+6i)
|
||||
v += R(n+i+1)*ff_acelp_interp_filter(6-t+6i) */
|
||||
|
||||
v += in[n + i] * filter_coeffs[idx + frac_pos];
|
||||
idx += precision;
|
||||
i++;
|
||||
v += in[n - i] * filter_coeffs[idx - frac_pos];
|
||||
}
|
||||
if (av_clip_int16(v >> 15) != (v >> 15))
|
||||
av_log(NULL, AV_LOG_WARNING, "overflow that would need cliping in ff_acelp_interpolate()\n");
|
||||
out[n] = v >> 15;
|
||||
}
|
||||
}
|
||||
|
||||
void ff_acelp_interpolatef(float *out, const float *in,
|
||||
const float *filter_coeffs, int precision,
|
||||
int frac_pos, int filter_length, int length)
|
||||
{
|
||||
int n, i;
|
||||
|
||||
for (n = 0; n < length; n++) {
|
||||
int idx = 0;
|
||||
float v = 0;
|
||||
|
||||
for (i = 0; i < filter_length;) {
|
||||
v += in[n + i] * filter_coeffs[idx + frac_pos];
|
||||
idx += precision;
|
||||
i++;
|
||||
v += in[n - i] * filter_coeffs[idx - frac_pos];
|
||||
}
|
||||
out[n] = v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ff_acelp_high_pass_filter(int16_t* out, int hpf_f[2],
|
||||
const int16_t* in, int length)
|
||||
{
|
||||
int i;
|
||||
int tmp;
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
tmp = (hpf_f[0]* 15836LL) >> 13;
|
||||
tmp += (hpf_f[1]* -7667LL) >> 13;
|
||||
tmp += 7699 * (in[i] - 2*in[i-1] + in[i-2]);
|
||||
|
||||
/* With "+0x800" rounding, clipping is needed
|
||||
for ALGTHM and SPEECH tests. */
|
||||
out[i] = av_clip_int16((tmp + 0x800) >> 12);
|
||||
|
||||
hpf_f[1] = hpf_f[0];
|
||||
hpf_f[0] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void ff_acelp_apply_order_2_transfer_function(float *out, const float *in,
|
||||
const float zero_coeffs[2],
|
||||
const float pole_coeffs[2],
|
||||
float gain, float mem[2], int n)
|
||||
{
|
||||
int i;
|
||||
float tmp;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
tmp = gain * in[i] - pole_coeffs[0] * mem[0] - pole_coeffs[1] * mem[1];
|
||||
out[i] = tmp + zero_coeffs[0] * mem[0] + zero_coeffs[1] * mem[1];
|
||||
|
||||
mem[1] = mem[0];
|
||||
mem[0] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void ff_tilt_compensation(float *mem, float tilt, float *samples, int size)
|
||||
{
|
||||
float new_tilt_mem = samples[size - 1];
|
||||
int i;
|
||||
|
||||
for (i = size - 1; i > 0; i--)
|
||||
samples[i] -= tilt * samples[i - 1];
|
||||
|
||||
samples[0] -= tilt * *mem;
|
||||
*mem = new_tilt_mem;
|
||||
}
|
||||
|
||||
void ff_acelp_filter_init(ACELPFContext *c)
|
||||
{
|
||||
c->acelp_interpolatef = ff_acelp_interpolatef;
|
||||
c->acelp_apply_order_2_transfer_function = ff_acelp_apply_order_2_transfer_function;
|
||||
|
||||
if(HAVE_MIPSFPU)
|
||||
ff_acelp_filter_init_mips(c);
|
||||
}
|
|
@ -1,153 +0,0 @@
|
|||
/*
|
||||
* various filters for ACELP-based codecs
|
||||
*
|
||||
* Copyright (c) 2008 Vladimir Voroshilov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_ACELP_FILTERS_H
|
||||
#define AVCODEC_ACELP_FILTERS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct ACELPFContext {
|
||||
/**
|
||||
* Floating point version of ff_acelp_interpolate()
|
||||
*/
|
||||
void (*acelp_interpolatef)(float *out, const float *in,
|
||||
const float *filter_coeffs, int precision,
|
||||
int frac_pos, int filter_length, int length);
|
||||
|
||||
/**
|
||||
* Apply an order 2 rational transfer function in-place.
|
||||
*
|
||||
* @param out output buffer for filtered speech samples
|
||||
* @param in input buffer containing speech data (may be the same as out)
|
||||
* @param zero_coeffs z^-1 and z^-2 coefficients of the numerator
|
||||
* @param pole_coeffs z^-1 and z^-2 coefficients of the denominator
|
||||
* @param gain scale factor for final output
|
||||
* @param mem intermediate values used by filter (should be 0 initially)
|
||||
* @param n number of samples (should be a multiple of eight)
|
||||
*/
|
||||
void (*acelp_apply_order_2_transfer_function)(float *out, const float *in,
|
||||
const float zero_coeffs[2],
|
||||
const float pole_coeffs[2],
|
||||
float gain,
|
||||
float mem[2], int n);
|
||||
|
||||
}ACELPFContext;
|
||||
|
||||
/**
|
||||
* Initialize ACELPFContext.
|
||||
*/
|
||||
void ff_acelp_filter_init(ACELPFContext *c);
|
||||
void ff_acelp_filter_init_mips(ACELPFContext *c);
|
||||
|
||||
/**
|
||||
* low-pass Finite Impulse Response filter coefficients.
|
||||
*
|
||||
* Hamming windowed sinc filter with cutoff freq 3/40 of the sampling freq,
|
||||
* the coefficients are scaled by 2^15.
|
||||
* This array only contains the right half of the filter.
|
||||
* This filter is likely identical to the one used in G.729, though this
|
||||
* could not be determined from the original comments with certainty.
|
||||
*/
|
||||
extern const int16_t ff_acelp_interp_filter[61];
|
||||
|
||||
/**
|
||||
* Generic FIR interpolation routine.
|
||||
* @param[out] out buffer for interpolated data
|
||||
* @param in input data
|
||||
* @param filter_coeffs interpolation filter coefficients (0.15)
|
||||
* @param precision sub sample factor, that is the precision of the position
|
||||
* @param frac_pos fractional part of position [0..precision-1]
|
||||
* @param filter_length filter length
|
||||
* @param length length of output
|
||||
*
|
||||
* filter_coeffs contains coefficients of the right half of the symmetric
|
||||
* interpolation filter. filter_coeffs[0] should the central (unpaired) coefficient.
|
||||
* See ff_acelp_interp_filter for an example.
|
||||
*
|
||||
*/
|
||||
void ff_acelp_interpolate(int16_t* out, const int16_t* in,
|
||||
const int16_t* filter_coeffs, int precision,
|
||||
int frac_pos, int filter_length, int length);
|
||||
|
||||
/**
|
||||
* Floating point version of ff_acelp_interpolate()
|
||||
*/
|
||||
void ff_acelp_interpolatef(float *out, const float *in,
|
||||
const float *filter_coeffs, int precision,
|
||||
int frac_pos, int filter_length, int length);
|
||||
|
||||
|
||||
/**
|
||||
* high-pass filtering and upscaling (4.2.5 of G.729).
|
||||
* @param[out] out output buffer for filtered speech data
|
||||
* @param[in,out] hpf_f past filtered data from previous (2 items long)
|
||||
* frames (-0x20000000 <= (14.13) < 0x20000000)
|
||||
* @param in speech data to process
|
||||
* @param length input data size
|
||||
*
|
||||
* out[i] = 0.93980581 * in[i] - 1.8795834 * in[i-1] + 0.93980581 * in[i-2] +
|
||||
* 1.9330735 * out[i-1] - 0.93589199 * out[i-2]
|
||||
*
|
||||
* The filter has a cut-off frequency of 1/80 of the sampling freq
|
||||
*
|
||||
* @note Two items before the top of the in buffer must contain two items from the
|
||||
* tail of the previous subframe.
|
||||
*
|
||||
* @remark It is safe to pass the same array in in and out parameters.
|
||||
*
|
||||
* @remark AMR uses mostly the same filter (cut-off frequency 60Hz, same formula,
|
||||
* but constants differs in 5th sign after comma). Fortunately in
|
||||
* fixed-point all coefficients are the same as in G.729. Thus this
|
||||
* routine can be used for the fixed-point AMR decoder, too.
|
||||
*/
|
||||
void ff_acelp_high_pass_filter(int16_t* out, int hpf_f[2],
|
||||
const int16_t* in, int length);
|
||||
|
||||
/**
|
||||
* Apply an order 2 rational transfer function in-place.
|
||||
*
|
||||
* @param out output buffer for filtered speech samples
|
||||
* @param in input buffer containing speech data (may be the same as out)
|
||||
* @param zero_coeffs z^-1 and z^-2 coefficients of the numerator
|
||||
* @param pole_coeffs z^-1 and z^-2 coefficients of the denominator
|
||||
* @param gain scale factor for final output
|
||||
* @param mem intermediate values used by filter (should be 0 initially)
|
||||
* @param n number of samples
|
||||
*/
|
||||
void ff_acelp_apply_order_2_transfer_function(float *out, const float *in,
|
||||
const float zero_coeffs[2],
|
||||
const float pole_coeffs[2],
|
||||
float gain,
|
||||
float mem[2], int n);
|
||||
|
||||
/**
|
||||
* Apply tilt compensation filter, 1 - tilt * z-1.
|
||||
*
|
||||
* @param mem pointer to the filter's state (one single float)
|
||||
* @param tilt tilt factor
|
||||
* @param samples array where the filter is applied
|
||||
* @param size the size of the samples array
|
||||
*/
|
||||
void ff_tilt_compensation(float *mem, float tilt, float *samples, int size);
|
||||
|
||||
|
||||
#endif /* AVCODEC_ACELP_FILTERS_H */
|
|
@ -1,189 +0,0 @@
|
|||
/*
|
||||
* gain code, gain pitch and pitch delay decoding
|
||||
*
|
||||
* Copyright (c) 2008 Vladimir Voroshilov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/float_dsp.h"
|
||||
#include "libavutil/libm.h"
|
||||
#include "libavutil/mathematics.h"
|
||||
#include "avcodec.h"
|
||||
#include "acelp_pitch_delay.h"
|
||||
#include "celp_math.h"
|
||||
|
||||
int ff_acelp_decode_8bit_to_1st_delay3(int ac_index)
|
||||
{
|
||||
ac_index += 58;
|
||||
if(ac_index > 254)
|
||||
ac_index = 3 * ac_index - 510;
|
||||
return ac_index;
|
||||
}
|
||||
|
||||
int ff_acelp_decode_4bit_to_2nd_delay3(
|
||||
int ac_index,
|
||||
int pitch_delay_min)
|
||||
{
|
||||
if(ac_index < 4)
|
||||
return 3 * (ac_index + pitch_delay_min);
|
||||
else if(ac_index < 12)
|
||||
return 3 * pitch_delay_min + ac_index + 6;
|
||||
else
|
||||
return 3 * (ac_index + pitch_delay_min) - 18;
|
||||
}
|
||||
|
||||
int ff_acelp_decode_5_6_bit_to_2nd_delay3(
|
||||
int ac_index,
|
||||
int pitch_delay_min)
|
||||
{
|
||||
return 3 * pitch_delay_min + ac_index - 2;
|
||||
}
|
||||
|
||||
int ff_acelp_decode_9bit_to_1st_delay6(int ac_index)
|
||||
{
|
||||
if(ac_index < 463)
|
||||
return ac_index + 105;
|
||||
else
|
||||
return 6 * (ac_index - 368);
|
||||
}
|
||||
int ff_acelp_decode_6bit_to_2nd_delay6(
|
||||
int ac_index,
|
||||
int pitch_delay_min)
|
||||
{
|
||||
return 6 * pitch_delay_min + ac_index - 3;
|
||||
}
|
||||
|
||||
void ff_acelp_update_past_gain(
|
||||
int16_t* quant_energy,
|
||||
int gain_corr_factor,
|
||||
int log2_ma_pred_order,
|
||||
int erasure)
|
||||
{
|
||||
int i;
|
||||
int avg_gain=quant_energy[(1 << log2_ma_pred_order) - 1]; // (5.10)
|
||||
|
||||
for(i=(1 << log2_ma_pred_order) - 1; i>0; i--)
|
||||
{
|
||||
avg_gain += quant_energy[i-1];
|
||||
quant_energy[i] = quant_energy[i-1];
|
||||
}
|
||||
|
||||
if(erasure)
|
||||
quant_energy[0] = FFMAX(avg_gain >> log2_ma_pred_order, -10240) - 4096; // -10 and -4 in (5.10)
|
||||
else
|
||||
quant_energy[0] = (6165 * ((ff_log2_q15(gain_corr_factor) >> 2) - (13 << 13))) >> 13;
|
||||
}
|
||||
|
||||
int16_t ff_acelp_decode_gain_code(
|
||||
DSPContext *dsp,
|
||||
int gain_corr_factor,
|
||||
const int16_t* fc_v,
|
||||
int mr_energy,
|
||||
const int16_t* quant_energy,
|
||||
const int16_t* ma_prediction_coeff,
|
||||
int subframe_size,
|
||||
int ma_pred_order)
|
||||
{
|
||||
int i;
|
||||
|
||||
mr_energy <<= 10;
|
||||
|
||||
for(i=0; i<ma_pred_order; i++)
|
||||
mr_energy += quant_energy[i] * ma_prediction_coeff[i];
|
||||
|
||||
#ifdef G729_BITEXACT
|
||||
mr_energy += (((-6165LL * ff_log2(dsp->scalarproduct_int16(fc_v, fc_v, subframe_size, 0))) >> 3) & ~0x3ff);
|
||||
|
||||
mr_energy = (5439 * (mr_energy >> 15)) >> 8; // (0.15) = (0.15) * (7.23)
|
||||
|
||||
return bidir_sal(
|
||||
((ff_exp2(mr_energy & 0x7fff) + 16) >> 5) * (gain_corr_factor >> 1),
|
||||
(mr_energy >> 15) - 25
|
||||
);
|
||||
#else
|
||||
mr_energy = gain_corr_factor * exp(M_LN10 / (20 << 23) * mr_energy) /
|
||||
sqrt(dsp->scalarproduct_int16(fc_v, fc_v, subframe_size));
|
||||
return mr_energy >> 12;
|
||||
#endif
|
||||
}
|
||||
|
||||
float ff_amr_set_fixed_gain(float fixed_gain_factor, float fixed_mean_energy,
|
||||
float *prediction_error, float energy_mean,
|
||||
const float *pred_table)
|
||||
{
|
||||
// Equations 66-69:
|
||||
// ^g_c = ^gamma_gc * 100.05 (predicted dB + mean dB - dB of fixed vector)
|
||||
// Note 10^(0.05 * -10log(average x2)) = 1/sqrt((average x2)).
|
||||
float val = fixed_gain_factor *
|
||||
exp2f(M_LOG2_10 * 0.05 *
|
||||
(avpriv_scalarproduct_float_c(pred_table, prediction_error, 4) +
|
||||
energy_mean)) /
|
||||
sqrtf(fixed_mean_energy);
|
||||
|
||||
// update quantified prediction error energy history
|
||||
memmove(&prediction_error[0], &prediction_error[1],
|
||||
3 * sizeof(prediction_error[0]));
|
||||
prediction_error[3] = 20.0 * log10f(fixed_gain_factor);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void ff_decode_pitch_lag(int *lag_int, int *lag_frac, int pitch_index,
|
||||
const int prev_lag_int, const int subframe,
|
||||
int third_as_first, int resolution)
|
||||
{
|
||||
/* Note n * 10923 >> 15 is floor(x/3) for 0 <= n <= 32767 */
|
||||
if (subframe == 0 || (subframe == 2 && third_as_first)) {
|
||||
|
||||
if (pitch_index < 197)
|
||||
pitch_index += 59;
|
||||
else
|
||||
pitch_index = 3 * pitch_index - 335;
|
||||
|
||||
} else {
|
||||
if (resolution == 4) {
|
||||
int search_range_min = av_clip(prev_lag_int - 5, PITCH_DELAY_MIN,
|
||||
PITCH_DELAY_MAX - 9);
|
||||
|
||||
// decoding with 4-bit resolution
|
||||
if (pitch_index < 4) {
|
||||
// integer only precision for [search_range_min, search_range_min+3]
|
||||
pitch_index = 3 * (pitch_index + search_range_min) + 1;
|
||||
} else if (pitch_index < 12) {
|
||||
// 1/3 fractional precision for [search_range_min+3 1/3, search_range_min+5 2/3]
|
||||
pitch_index += 3 * search_range_min + 7;
|
||||
} else {
|
||||
// integer only precision for [search_range_min+6, search_range_min+9]
|
||||
pitch_index = 3 * (pitch_index + search_range_min - 6) + 1;
|
||||
}
|
||||
} else {
|
||||
// decoding with 5 or 6 bit resolution, 1/3 fractional precision
|
||||
pitch_index--;
|
||||
|
||||
if (resolution == 5) {
|
||||
pitch_index += 3 * av_clip(prev_lag_int - 10, PITCH_DELAY_MIN,
|
||||
PITCH_DELAY_MAX - 19);
|
||||
} else
|
||||
pitch_index += 3 * av_clip(prev_lag_int - 5, PITCH_DELAY_MIN,
|
||||
PITCH_DELAY_MAX - 9);
|
||||
}
|
||||
}
|
||||
*lag_int = pitch_index * 10923 >> 15;
|
||||
*lag_frac = pitch_index - 3 * *lag_int - 1;
|
||||
}
|
|
@ -1,252 +0,0 @@
|
|||
/*
|
||||
* gain code, gain pitch and pitch delay decoding
|
||||
*
|
||||
* Copyright (c) 2008 Vladimir Voroshilov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_ACELP_PITCH_DELAY_H
|
||||
#define AVCODEC_ACELP_PITCH_DELAY_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "dsputil.h"
|
||||
|
||||
#define PITCH_DELAY_MIN 20
|
||||
#define PITCH_DELAY_MAX 143
|
||||
|
||||
/**
|
||||
* @brief Decode pitch delay of the first subframe encoded by 8 bits with 1/3
|
||||
* resolution.
|
||||
* @param ac_index adaptive codebook index (8 bits)
|
||||
*
|
||||
* @return pitch delay in 1/3 units
|
||||
*
|
||||
* Pitch delay is coded:
|
||||
* with 1/3 resolution, 19 < pitch_delay < 85
|
||||
* integers only, 85 <= pitch_delay <= 143
|
||||
*/
|
||||
int ff_acelp_decode_8bit_to_1st_delay3(int ac_index);
|
||||
|
||||
/**
|
||||
* @brief Decode pitch delay of the second subframe encoded by 5 or 6 bits
|
||||
* with 1/3 precision.
|
||||
* @param ac_index adaptive codebook index (5 or 6 bits)
|
||||
* @param pitch_delay_min lower bound (integer) of pitch delay interval
|
||||
* for second subframe
|
||||
*
|
||||
* @return pitch delay in 1/3 units
|
||||
*
|
||||
* Pitch delay is coded:
|
||||
* with 1/3 resolution, -6 < pitch_delay - int(prev_pitch_delay) < 5
|
||||
*
|
||||
* @remark The routine is used in G.729 @@8k, AMR @@10.2k, AMR @@7.95k,
|
||||
* AMR @@7.4k for the second subframe.
|
||||
*/
|
||||
int ff_acelp_decode_5_6_bit_to_2nd_delay3(
|
||||
int ac_index,
|
||||
int pitch_delay_min);
|
||||
|
||||
/**
|
||||
* @brief Decode pitch delay with 1/3 precision.
|
||||
* @param ac_index adaptive codebook index (4 bits)
|
||||
* @param pitch_delay_min lower bound (integer) of pitch delay interval for
|
||||
* second subframe
|
||||
*
|
||||
* @return pitch delay in 1/3 units
|
||||
*
|
||||
* Pitch delay is coded:
|
||||
* integers only, -6 < pitch_delay - int(prev_pitch_delay) <= -2
|
||||
* with 1/3 resolution, -2 < pitch_delay - int(prev_pitch_delay) < 1
|
||||
* integers only, 1 <= pitch_delay - int(prev_pitch_delay) < 5
|
||||
*
|
||||
* @remark The routine is used in G.729 @@6.4k, AMR @@6.7k, AMR @@5.9k,
|
||||
* AMR @@5.15k, AMR @@4.75k for the second subframe.
|
||||
*/
|
||||
int ff_acelp_decode_4bit_to_2nd_delay3(
|
||||
int ac_index,
|
||||
int pitch_delay_min);
|
||||
|
||||
/**
|
||||
* @brief Decode pitch delay of the first subframe encoded by 9 bits
|
||||
* with 1/6 precision.
|
||||
* @param ac_index adaptive codebook index (9 bits)
|
||||
*
|
||||
* @return pitch delay in 1/6 units
|
||||
*
|
||||
* Pitch delay is coded:
|
||||
* with 1/6 resolution, 17 < pitch_delay < 95
|
||||
* integers only, 95 <= pitch_delay <= 143
|
||||
*
|
||||
* @remark The routine is used in AMR @@12.2k for the first and third subframes.
|
||||
*/
|
||||
int ff_acelp_decode_9bit_to_1st_delay6(int ac_index);
|
||||
|
||||
/**
|
||||
* @brief Decode pitch delay of the second subframe encoded by 6 bits
|
||||
* with 1/6 precision.
|
||||
* @param ac_index adaptive codebook index (6 bits)
|
||||
* @param pitch_delay_min lower bound (integer) of pitch delay interval for
|
||||
* second subframe
|
||||
*
|
||||
* @return pitch delay in 1/6 units
|
||||
*
|
||||
* Pitch delay is coded:
|
||||
* with 1/6 resolution, -6 < pitch_delay - int(prev_pitch_delay) < 5
|
||||
*
|
||||
* @remark The routine is used in AMR @@12.2k for the second and fourth subframes.
|
||||
*/
|
||||
int ff_acelp_decode_6bit_to_2nd_delay6(
|
||||
int ac_index,
|
||||
int pitch_delay_min);
|
||||
|
||||
/**
|
||||
* @brief Update past quantized energies
|
||||
* @param[in,out] quant_energy past quantized energies (5.10)
|
||||
* @param gain_corr_factor gain correction factor
|
||||
* @param log2_ma_pred_order log2() of MA prediction order
|
||||
* @param erasure frame erasure flag
|
||||
*
|
||||
* If frame erasure flag is not equal to zero, memory is updated with
|
||||
* averaged energy, attenuated by 4dB:
|
||||
* max(avg(quant_energy[i])-4, -14), i=0,ma_pred_order
|
||||
*
|
||||
* In normal mode memory is updated with
|
||||
* Er - Ep = 20 * log10(gain_corr_factor)
|
||||
*
|
||||
* @remark The routine is used in G.729 and AMR (all modes).
|
||||
*/
|
||||
void ff_acelp_update_past_gain(
|
||||
int16_t* quant_energy,
|
||||
int gain_corr_factor,
|
||||
int log2_ma_pred_order,
|
||||
int erasure);
|
||||
|
||||
/**
|
||||
* @brief Decode the adaptive codebook gain and add
|
||||
* correction (4.1.5 and 3.9.1 of G.729).
|
||||
* @param dsp initialized dsputil context
|
||||
* @param gain_corr_factor gain correction factor (2.13)
|
||||
* @param fc_v fixed-codebook vector (2.13)
|
||||
* @param mr_energy mean innovation energy and fixed-point correction (7.13)
|
||||
* @param[in,out] quant_energy past quantized energies (5.10)
|
||||
* @param subframe_size length of subframe
|
||||
*
|
||||
* @return quantized fixed-codebook gain (14.1)
|
||||
*
|
||||
* The routine implements equations 69, 66 and 71 of the G.729 specification (3.9.1)
|
||||
*
|
||||
* Em - mean innovation energy (dB, constant, depends on decoding algorithm)
|
||||
* Ep - mean-removed predicted energy (dB)
|
||||
* Er - mean-removed innovation energy (dB)
|
||||
* Ei - mean energy of the fixed-codebook contribution (dB)
|
||||
* N - subframe_size
|
||||
* M - MA (Moving Average) prediction order
|
||||
* gc - fixed-codebook gain
|
||||
* gc_p - predicted fixed-codebook gain
|
||||
*
|
||||
* Fixed codebook gain is computed using predicted gain gc_p and
|
||||
* correction factor gain_corr_factor as shown below:
|
||||
*
|
||||
* gc = gc_p * gain_corr_factor
|
||||
*
|
||||
* The predicted fixed codebook gain gc_p is found by predicting
|
||||
* the energy of the fixed-codebook contribution from the energy
|
||||
* of previous fixed-codebook contributions.
|
||||
*
|
||||
* mean = 1/N * sum(i,0,N){ fc_v[i] * fc_v[i] }
|
||||
*
|
||||
* Ei = 10log(mean)
|
||||
*
|
||||
* Er = 10log(1/N * gc^2 * mean) - Em = 20log(gc) + Ei - Em
|
||||
*
|
||||
* Replacing Er with Ep and gc with gc_p we will receive:
|
||||
*
|
||||
* Ep = 10log(1/N * gc_p^2 * mean) - Em = 20log(gc_p) + Ei - Em
|
||||
*
|
||||
* and from above:
|
||||
*
|
||||
* gc_p = 10^((Ep - Ei + Em) / 20)
|
||||
*
|
||||
* Ep is predicted using past energies and prediction coefficients:
|
||||
*
|
||||
* Ep = sum(i,0,M){ ma_prediction_coeff[i] * quant_energy[i] }
|
||||
*
|
||||
* gc_p in fixed-point arithmetic is calculated as following:
|
||||
*
|
||||
* mean = 1/N * sum(i,0,N){ (fc_v[i] / 2^13) * (fc_v[i] / 2^13) } =
|
||||
* = 1/N * sum(i,0,N) { fc_v[i] * fc_v[i] } / 2^26
|
||||
*
|
||||
* Ei = 10log(mean) = -10log(N) - 10log(2^26) +
|
||||
* + 10log(sum(i,0,N) { fc_v[i] * fc_v[i] })
|
||||
*
|
||||
* Ep - Ei + Em = Ep + Em + 10log(N) + 10log(2^26) -
|
||||
* - 10log(sum(i,0,N) { fc_v[i] * fc_v[i] }) =
|
||||
* = Ep + mr_energy - 10log(sum(i,0,N) { fc_v[i] * fc_v[i] })
|
||||
*
|
||||
* gc_p = 10 ^ ((Ep - Ei + Em) / 20) =
|
||||
* = 2 ^ (3.3219 * (Ep - Ei + Em) / 20) = 2 ^ (0.166 * (Ep - Ei + Em))
|
||||
*
|
||||
* where
|
||||
*
|
||||
* mr_energy = Em + 10log(N) + 10log(2^26)
|
||||
*
|
||||
* @remark The routine is used in G.729 and AMR (all modes).
|
||||
*/
|
||||
int16_t ff_acelp_decode_gain_code(
|
||||
DSPContext *dsp,
|
||||
int gain_corr_factor,
|
||||
const int16_t* fc_v,
|
||||
int mr_energy,
|
||||
const int16_t* quant_energy,
|
||||
const int16_t* ma_prediction_coeff,
|
||||
int subframe_size,
|
||||
int max_pred_order);
|
||||
|
||||
/**
|
||||
* Calculate fixed gain (part of section 6.1.3 of AMR spec)
|
||||
*
|
||||
* @param fixed_gain_factor gain correction factor
|
||||
* @param fixed_mean_energy mean decoded algebraic codebook vector energy
|
||||
* @param prediction_error vector of the quantified predictor errors of
|
||||
* the four previous subframes. It is updated by this function.
|
||||
* @param energy_mean desired mean innovation energy
|
||||
* @param pred_table table of four moving average coefficients
|
||||
*/
|
||||
float ff_amr_set_fixed_gain(float fixed_gain_factor, float fixed_mean_energy,
|
||||
float *prediction_error, float energy_mean,
|
||||
const float *pred_table);
|
||||
|
||||
|
||||
/**
|
||||
* Decode the adaptive codebook index to the integer and fractional parts
|
||||
* of the pitch lag for one subframe at 1/3 fractional precision.
|
||||
*
|
||||
* The choice of pitch lag is described in 3GPP TS 26.090 section 5.6.1.
|
||||
*
|
||||
* @param lag_int integer part of pitch lag of the current subframe
|
||||
* @param lag_frac fractional part of pitch lag of the current subframe
|
||||
* @param pitch_index parsed adaptive codebook (pitch) index
|
||||
* @param prev_lag_int integer part of pitch lag for the previous subframe
|
||||
* @param subframe current subframe number
|
||||
* @param third_as_first treat the third frame the same way as the first
|
||||
*/
|
||||
void ff_decode_pitch_lag(int *lag_int, int *lag_frac, int pitch_index,
|
||||
const int prev_lag_int, const int subframe,
|
||||
int third_as_first, int resolution);
|
||||
|
||||
#endif /* AVCODEC_ACELP_PITCH_DELAY_H */
|
|
@ -1,272 +0,0 @@
|
|||
/*
|
||||
* adaptive and fixed codebook vector operations for ACELP-based codecs
|
||||
*
|
||||
* Copyright (c) 2008 Vladimir Voroshilov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/float_dsp.h"
|
||||
#include "avcodec.h"
|
||||
#include "acelp_vectors.h"
|
||||
|
||||
const uint8_t ff_fc_2pulses_9bits_track1[16] =
|
||||
{
|
||||
1, 3,
|
||||
6, 8,
|
||||
11, 13,
|
||||
16, 18,
|
||||
21, 23,
|
||||
26, 28,
|
||||
31, 33,
|
||||
36, 38
|
||||
};
|
||||
const uint8_t ff_fc_2pulses_9bits_track1_gray[16] =
|
||||
{
|
||||
1, 3,
|
||||
8, 6,
|
||||
18, 16,
|
||||
11, 13,
|
||||
38, 36,
|
||||
31, 33,
|
||||
21, 23,
|
||||
28, 26,
|
||||
};
|
||||
|
||||
const uint8_t ff_fc_2pulses_9bits_track2_gray[32] =
|
||||
{
|
||||
0, 2,
|
||||
5, 4,
|
||||
12, 10,
|
||||
7, 9,
|
||||
25, 24,
|
||||
20, 22,
|
||||
14, 15,
|
||||
19, 17,
|
||||
36, 31,
|
||||
21, 26,
|
||||
1, 6,
|
||||
16, 11,
|
||||
27, 29,
|
||||
32, 30,
|
||||
39, 37,
|
||||
34, 35,
|
||||
};
|
||||
|
||||
const uint8_t ff_fc_4pulses_8bits_tracks_13[16] =
|
||||
{
|
||||
0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75,
|
||||
};
|
||||
|
||||
const uint8_t ff_fc_4pulses_8bits_track_4[32] =
|
||||
{
|
||||
3, 4,
|
||||
8, 9,
|
||||
13, 14,
|
||||
18, 19,
|
||||
23, 24,
|
||||
28, 29,
|
||||
33, 34,
|
||||
38, 39,
|
||||
43, 44,
|
||||
48, 49,
|
||||
53, 54,
|
||||
58, 59,
|
||||
63, 64,
|
||||
68, 69,
|
||||
73, 74,
|
||||
78, 79,
|
||||
};
|
||||
|
||||
const float ff_pow_0_7[10] = {
|
||||
0.700000, 0.490000, 0.343000, 0.240100, 0.168070,
|
||||
0.117649, 0.082354, 0.057648, 0.040354, 0.028248
|
||||
};
|
||||
|
||||
const float ff_pow_0_75[10] = {
|
||||
0.750000, 0.562500, 0.421875, 0.316406, 0.237305,
|
||||
0.177979, 0.133484, 0.100113, 0.075085, 0.056314
|
||||
};
|
||||
|
||||
const float ff_pow_0_55[10] = {
|
||||
0.550000, 0.302500, 0.166375, 0.091506, 0.050328,
|
||||
0.027681, 0.015224, 0.008373, 0.004605, 0.002533
|
||||
};
|
||||
|
||||
const float ff_b60_sinc[61] = {
|
||||
0.898529 , 0.865051 , 0.769257 , 0.624054 , 0.448639 , 0.265289 ,
|
||||
0.0959167 , -0.0412598 , -0.134338 , -0.178986 , -0.178528 , -0.142609 ,
|
||||
-0.0849304 , -0.0205078 , 0.0369568 , 0.0773926 , 0.0955200 , 0.0912781 ,
|
||||
0.0689392 , 0.0357056 , 0.0 , -0.0305481 , -0.0504150 , -0.0570068 ,
|
||||
-0.0508423 , -0.0350037 , -0.0141602 , 0.00665283, 0.0230713 , 0.0323486 ,
|
||||
0.0335388 , 0.0275879 , 0.0167847 , 0.00411987, -0.00747681, -0.0156860 ,
|
||||
-0.0193481 , -0.0183716 , -0.0137634 , -0.00704956, 0.0 , 0.00582886 ,
|
||||
0.00939941, 0.0103760 , 0.00903320, 0.00604248, 0.00238037, -0.00109863 ,
|
||||
-0.00366211, -0.00497437, -0.00503540, -0.00402832, -0.00241089, -0.000579834,
|
||||
0.00103760, 0.00222778, 0.00277710, 0.00271606, 0.00213623, 0.00115967 ,
|
||||
0.
|
||||
};
|
||||
|
||||
void ff_acelp_fc_pulse_per_track(
|
||||
int16_t* fc_v,
|
||||
const uint8_t *tab1,
|
||||
const uint8_t *tab2,
|
||||
int pulse_indexes,
|
||||
int pulse_signs,
|
||||
int pulse_count,
|
||||
int bits)
|
||||
{
|
||||
int mask = (1 << bits) - 1;
|
||||
int i;
|
||||
|
||||
for(i=0; i<pulse_count; i++)
|
||||
{
|
||||
fc_v[i + tab1[pulse_indexes & mask]] +=
|
||||
(pulse_signs & 1) ? 8191 : -8192; // +/-1 in (2.13)
|
||||
|
||||
pulse_indexes >>= bits;
|
||||
pulse_signs >>= 1;
|
||||
}
|
||||
|
||||
fc_v[tab2[pulse_indexes]] += (pulse_signs & 1) ? 8191 : -8192;
|
||||
}
|
||||
|
||||
void ff_decode_10_pulses_35bits(const int16_t *fixed_index,
|
||||
AMRFixed *fixed_sparse,
|
||||
const uint8_t *gray_decode,
|
||||
int half_pulse_count, int bits)
|
||||
{
|
||||
int i;
|
||||
int mask = (1 << bits) - 1;
|
||||
|
||||
fixed_sparse->no_repeat_mask = 0;
|
||||
fixed_sparse->n = 2 * half_pulse_count;
|
||||
for (i = 0; i < half_pulse_count; i++) {
|
||||
const int pos1 = gray_decode[fixed_index[2*i+1] & mask] + i;
|
||||
const int pos2 = gray_decode[fixed_index[2*i ] & mask] + i;
|
||||
const float sign = (fixed_index[2*i+1] & (1 << bits)) ? -1.0 : 1.0;
|
||||
fixed_sparse->x[2*i+1] = pos1;
|
||||
fixed_sparse->x[2*i ] = pos2;
|
||||
fixed_sparse->y[2*i+1] = sign;
|
||||
fixed_sparse->y[2*i ] = pos2 < pos1 ? -sign : sign;
|
||||
}
|
||||
}
|
||||
|
||||
void ff_acelp_weighted_vector_sum(
|
||||
int16_t* out,
|
||||
const int16_t *in_a,
|
||||
const int16_t *in_b,
|
||||
int16_t weight_coeff_a,
|
||||
int16_t weight_coeff_b,
|
||||
int16_t rounder,
|
||||
int shift,
|
||||
int length)
|
||||
{
|
||||
int i;
|
||||
|
||||
// Clipping required here; breaks OVERFLOW test.
|
||||
for(i=0; i<length; i++)
|
||||
out[i] = av_clip_int16((
|
||||
in_a[i] * weight_coeff_a +
|
||||
in_b[i] * weight_coeff_b +
|
||||
rounder) >> shift);
|
||||
}
|
||||
|
||||
void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b,
|
||||
float weight_coeff_a, float weight_coeff_b, int length)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=0; i<length; i++)
|
||||
out[i] = weight_coeff_a * in_a[i]
|
||||
+ weight_coeff_b * in_b[i];
|
||||
}
|
||||
|
||||
void ff_adaptive_gain_control(float *out, const float *in, float speech_energ,
|
||||
int size, float alpha, float *gain_mem)
|
||||
{
|
||||
int i;
|
||||
float postfilter_energ = avpriv_scalarproduct_float_c(in, in, size);
|
||||
float gain_scale_factor = 1.0;
|
||||
float mem = *gain_mem;
|
||||
|
||||
if (postfilter_energ)
|
||||
gain_scale_factor = sqrt(speech_energ / postfilter_energ);
|
||||
|
||||
gain_scale_factor *= 1.0 - alpha;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
mem = alpha * mem + gain_scale_factor;
|
||||
out[i] = in[i] * mem;
|
||||
}
|
||||
|
||||
*gain_mem = mem;
|
||||
}
|
||||
|
||||
void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in,
|
||||
float sum_of_squares, const int n)
|
||||
{
|
||||
int i;
|
||||
float scalefactor = avpriv_scalarproduct_float_c(in, in, n);
|
||||
if (scalefactor)
|
||||
scalefactor = sqrt(sum_of_squares / scalefactor);
|
||||
for (i = 0; i < n; i++)
|
||||
out[i] = in[i] * scalefactor;
|
||||
}
|
||||
|
||||
void ff_set_fixed_vector(float *out, const AMRFixed *in, float scale, int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < in->n; i++) {
|
||||
int x = in->x[i], repeats = !((in->no_repeat_mask >> i) & 1);
|
||||
float y = in->y[i] * scale;
|
||||
|
||||
if (in->pitch_lag > 0)
|
||||
do {
|
||||
out[x] += y;
|
||||
y *= in->pitch_fac;
|
||||
x += in->pitch_lag;
|
||||
} while (x < size && repeats);
|
||||
}
|
||||
}
|
||||
|
||||
void ff_clear_fixed_vector(float *out, const AMRFixed *in, int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < in->n; i++) {
|
||||
int x = in->x[i], repeats = !((in->no_repeat_mask >> i) & 1);
|
||||
|
||||
if (in->pitch_lag > 0)
|
||||
do {
|
||||
out[x] = 0.0;
|
||||
x += in->pitch_lag;
|
||||
} while (x < size && repeats);
|
||||
}
|
||||
}
|
||||
|
||||
void ff_acelp_vectors_init(ACELPVContext *c)
|
||||
{
|
||||
c->weighted_vector_sumf = ff_weighted_vector_sumf;
|
||||
|
||||
if(HAVE_MIPSFPU)
|
||||
ff_acelp_vectors_init_mips(c);
|
||||
}
|
|
@ -1,288 +0,0 @@
|
|||
/*
|
||||
* adaptive and fixed codebook vector operations for ACELP-based codecs
|
||||
*
|
||||
* Copyright (c) 2008 Vladimir Voroshilov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_ACELP_VECTORS_H
|
||||
#define AVCODEC_ACELP_VECTORS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct ACELPVContext {
|
||||
/**
|
||||
* float implementation of weighted sum of two vectors.
|
||||
* @param[out] out result of addition
|
||||
* @param in_a first vector
|
||||
* @param in_b second vector
|
||||
* @param weight_coeff_a first vector weight coefficient
|
||||
* @param weight_coeff_a second vector weight coefficient
|
||||
* @param length vectors length (should be a multiple of two)
|
||||
*
|
||||
* @note It is safe to pass the same buffer for out and in_a or in_b.
|
||||
*/
|
||||
void (*weighted_vector_sumf)(float *out, const float *in_a, const float *in_b,
|
||||
float weight_coeff_a, float weight_coeff_b,
|
||||
int length);
|
||||
|
||||
}ACELPVContext;
|
||||
|
||||
/**
|
||||
* Initialize ACELPVContext.
|
||||
*/
|
||||
void ff_acelp_vectors_init(ACELPVContext *c);
|
||||
void ff_acelp_vectors_init_mips(ACELPVContext *c);
|
||||
|
||||
/** Sparse representation for the algebraic codebook (fixed) vector */
|
||||
typedef struct AMRFixed {
|
||||
int n;
|
||||
int x[10];
|
||||
float y[10];
|
||||
int no_repeat_mask;
|
||||
int pitch_lag;
|
||||
float pitch_fac;
|
||||
} AMRFixed;
|
||||
|
||||
/**
|
||||
* Track|Pulse| Positions
|
||||
* -------------------------------------------------------------------------
|
||||
* 1 | 0 | 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75
|
||||
* -------------------------------------------------------------------------
|
||||
* 2 | 1 | 1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76
|
||||
* -------------------------------------------------------------------------
|
||||
* 3 | 2 | 2, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Table contains only first the pulse indexes.
|
||||
*
|
||||
* Used in G.729 @@8k, G.729 @@4.4k, AMR @@7.95k, AMR @@7.40k
|
||||
*/
|
||||
extern const uint8_t ff_fc_4pulses_8bits_tracks_13[16];
|
||||
|
||||
/**
|
||||
* Track|Pulse| Positions
|
||||
* -------------------------------------------------------------------------
|
||||
* 4 | 3 | 3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58, 63, 68, 73, 78
|
||||
* | | 4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69, 74, 79
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* @remark Track in the table should be read top-to-bottom, left-to-right.
|
||||
*
|
||||
* Used in G.729 @@8k, G.729 @@4.4k, AMR @@7.95k, AMR @@7.40k
|
||||
*/
|
||||
extern const uint8_t ff_fc_4pulses_8bits_track_4[32];
|
||||
|
||||
/**
|
||||
* Track|Pulse| Positions
|
||||
* -----------------------------------------
|
||||
* 1 | 0 | 1, 6, 11, 16, 21, 26, 31, 36
|
||||
* | | 3, 8, 13, 18, 23, 28, 33, 38
|
||||
* -----------------------------------------
|
||||
*
|
||||
* @remark Track in the table should be read top-to-bottom, left-to-right.
|
||||
*
|
||||
* @note (EE) Reference G.729D code also uses gray decoding for each
|
||||
* pulse index before looking up the value in the table.
|
||||
*
|
||||
* Used in G.729 @@6.4k (with gray coding), AMR @@5.9k (without gray coding)
|
||||
*/
|
||||
extern const uint8_t ff_fc_2pulses_9bits_track1[16];
|
||||
extern const uint8_t ff_fc_2pulses_9bits_track1_gray[16];
|
||||
|
||||
/**
|
||||
* Track|Pulse| Positions
|
||||
* -----------------------------------------
|
||||
* 2 | 1 | 0, 7, 14, 20, 27, 34, 1, 21
|
||||
* | | 2, 9, 15, 22, 29, 35, 6, 26
|
||||
* | | 4,10, 17, 24, 30, 37, 11, 31
|
||||
* | | 5,12, 19, 25, 32, 39, 16, 36
|
||||
* -----------------------------------------
|
||||
*
|
||||
* @remark Track in the table should be read top-to-bottom, left-to-right.
|
||||
*
|
||||
* @note (EE.1) This table (from the reference code) does not comply with
|
||||
* the specification.
|
||||
* The specification contains the following table:
|
||||
*
|
||||
* Track|Pulse| Positions
|
||||
* -----------------------------------------
|
||||
* 2 | 1 | 0, 5, 10, 15, 20, 25, 30, 35
|
||||
* | | 1, 6, 11, 16, 21, 26, 31, 36
|
||||
* | | 2, 7, 12, 17, 22, 27, 32, 37
|
||||
* | | 4, 9, 14, 19, 24, 29, 34, 39
|
||||
*
|
||||
* -----------------------------------------
|
||||
*
|
||||
* @note (EE.2) Reference G.729D code also uses gray decoding for each
|
||||
* pulse index before looking up the value in the table.
|
||||
*
|
||||
* Used in G.729 @@6.4k (with gray coding)
|
||||
*/
|
||||
extern const uint8_t ff_fc_2pulses_9bits_track2_gray[32];
|
||||
|
||||
/**
|
||||
* b60 hamming windowed sinc function coefficients
|
||||
*/
|
||||
extern const float ff_b60_sinc[61];
|
||||
|
||||
/**
|
||||
* Table of pow(0.7,n)
|
||||
*/
|
||||
extern const float ff_pow_0_7[10];
|
||||
|
||||
/**
|
||||
* Table of pow(0.75,n)
|
||||
*/
|
||||
extern const float ff_pow_0_75[10];
|
||||
|
||||
/**
|
||||
* Table of pow(0.55,n)
|
||||
*/
|
||||
extern const float ff_pow_0_55[10];
|
||||
|
||||
/**
|
||||
* Decode fixed-codebook vector (3.8 and D.5.8 of G.729, 5.7.1 of AMR).
|
||||
* @param[out] fc_v decoded fixed codebook vector (2.13)
|
||||
* @param tab1 table used for first pulse_count pulses
|
||||
* @param tab2 table used for last pulse
|
||||
* @param pulse_indexes fixed codebook indexes
|
||||
* @param pulse_signs signs of the excitation pulses (0 bit value
|
||||
* means negative sign)
|
||||
* @param bits number of bits per one pulse index
|
||||
* @param pulse_count number of pulses decoded using first table
|
||||
* @param bits length of one pulse index in bits
|
||||
*
|
||||
* Used in G.729 @@8k, G.729 @@4.4k, G.729 @@6.4k, AMR @@7.95k, AMR @@7.40k
|
||||
*/
|
||||
void ff_acelp_fc_pulse_per_track(int16_t* fc_v,
|
||||
const uint8_t *tab1,
|
||||
const uint8_t *tab2,
|
||||
int pulse_indexes,
|
||||
int pulse_signs,
|
||||
int pulse_count,
|
||||
int bits);
|
||||
|
||||
/**
|
||||
* Decode the algebraic codebook index to pulse positions and signs and
|
||||
* construct the algebraic codebook vector for MODE_12k2.
|
||||
*
|
||||
* @note: The positions and signs are explicitly coded in MODE_12k2.
|
||||
*
|
||||
* @param fixed_index positions of the ten pulses
|
||||
* @param fixed_sparse pointer to the algebraic codebook vector
|
||||
* @param gray_decode gray decoding table
|
||||
* @param half_pulse_count number of couples of pulses
|
||||
* @param bits length of one pulse index in bits
|
||||
*/
|
||||
void ff_decode_10_pulses_35bits(const int16_t *fixed_index,
|
||||
AMRFixed *fixed_sparse,
|
||||
const uint8_t *gray_decode,
|
||||
int half_pulse_count, int bits);
|
||||
|
||||
|
||||
/**
|
||||
* weighted sum of two vectors with rounding.
|
||||
* @param[out] out result of addition
|
||||
* @param in_a first vector
|
||||
* @param in_b second vector
|
||||
* @param weight_coeff_a first vector weight coefficient
|
||||
* @param weight_coeff_a second vector weight coefficient
|
||||
* @param rounder this value will be added to the sum of the two vectors
|
||||
* @param shift result will be shifted to right by this value
|
||||
* @param length vectors length
|
||||
*
|
||||
* @note It is safe to pass the same buffer for out and in_a or in_b.
|
||||
*
|
||||
* out[i] = (in_a[i]*weight_a + in_b[i]*weight_b + rounder) >> shift
|
||||
*/
|
||||
void ff_acelp_weighted_vector_sum(int16_t* out,
|
||||
const int16_t *in_a,
|
||||
const int16_t *in_b,
|
||||
int16_t weight_coeff_a,
|
||||
int16_t weight_coeff_b,
|
||||
int16_t rounder,
|
||||
int shift,
|
||||
int length);
|
||||
|
||||
/**
|
||||
* float implementation of weighted sum of two vectors.
|
||||
* @param[out] out result of addition
|
||||
* @param in_a first vector
|
||||
* @param in_b second vector
|
||||
* @param weight_coeff_a first vector weight coefficient
|
||||
* @param weight_coeff_a second vector weight coefficient
|
||||
* @param length vectors length
|
||||
*
|
||||
* @note It is safe to pass the same buffer for out and in_a or in_b.
|
||||
*/
|
||||
void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b,
|
||||
float weight_coeff_a, float weight_coeff_b,
|
||||
int length);
|
||||
|
||||
/**
|
||||
* Adaptive gain control (as used in AMR postfiltering)
|
||||
*
|
||||
* @param out output buffer for filtered speech data
|
||||
* @param in the input speech buffer (may be the same as out)
|
||||
* @param speech_energ input energy
|
||||
* @param size the input buffer size
|
||||
* @param alpha exponential filter factor
|
||||
* @param gain_mem a pointer to the filter memory (single float of size)
|
||||
*/
|
||||
void ff_adaptive_gain_control(float *out, const float *in, float speech_energ,
|
||||
int size, float alpha, float *gain_mem);
|
||||
|
||||
/**
|
||||
* Set the sum of squares of a signal by scaling
|
||||
*
|
||||
* @param out output samples
|
||||
* @param in input samples
|
||||
* @param sum_of_squares new sum of squares
|
||||
* @param n number of samples
|
||||
*
|
||||
* @note If the input is zero (or its energy underflows), the output is zero.
|
||||
* This is the behavior of AGC in the AMR reference decoder. The QCELP
|
||||
* reference decoder seems to have undefined behavior.
|
||||
*
|
||||
* TIA/EIA/IS-733 2.4.8.3-2/3/4/5, 2.4.8.6
|
||||
* 3GPP TS 26.090 6.1 (6)
|
||||
*/
|
||||
void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in,
|
||||
float sum_of_squares, const int n);
|
||||
|
||||
/**
|
||||
* Add fixed vector to an array from a sparse representation
|
||||
*
|
||||
* @param out fixed vector with pitch sharpening
|
||||
* @param in sparse fixed vector
|
||||
* @param scale number to multiply the fixed vector by
|
||||
* @param size the output vector size
|
||||
*/
|
||||
void ff_set_fixed_vector(float *out, const AMRFixed *in, float scale, int size);
|
||||
|
||||
/**
|
||||
* Clear array values set by set_fixed_vector
|
||||
*
|
||||
* @param out fixed vector to be cleared
|
||||
* @param in sparse fixed vector
|
||||
* @param size the output vector size
|
||||
*/
|
||||
void ff_clear_fixed_vector(float *out, const AMRFixed *in, int size);
|
||||
|
||||
#endif /* AVCODEC_ACELP_VECTORS_H */
|
File diff suppressed because it is too large
Load diff
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2003 The ffmpeg Project
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* ADPCM encoder/decoder common header.
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_ADPCM_H
|
||||
#define AVCODEC_ADPCM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define BLKSIZE 1024
|
||||
|
||||
typedef struct ADPCMChannelStatus {
|
||||
int predictor;
|
||||
int16_t step_index;
|
||||
int step;
|
||||
/* for encoding */
|
||||
int prev_sample;
|
||||
|
||||
/* MS version */
|
||||
int sample1;
|
||||
int sample2;
|
||||
int coeff1;
|
||||
int coeff2;
|
||||
int idelta;
|
||||
} ADPCMChannelStatus;
|
||||
|
||||
#endif /* AVCODEC_ADPCM_H */
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2003 The ffmpeg Project
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* ADPCM tables
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* ff_adpcm_step_table[] and ff_adpcm_index_table[] are from the ADPCM
|
||||
reference source */
|
||||
static const int8_t adpcm_index_table2[4] = {
|
||||
-1, 2,
|
||||
-1, 2,
|
||||
};
|
||||
|
||||
static const int8_t adpcm_index_table3[8] = {
|
||||
-1, -1, 1, 2,
|
||||
-1, -1, 1, 2,
|
||||
};
|
||||
|
||||
const int8_t ff_adpcm_index_table[16] = {
|
||||
-1, -1, -1, -1, 2, 4, 6, 8,
|
||||
-1, -1, -1, -1, 2, 4, 6, 8,
|
||||
};
|
||||
|
||||
static const int8_t adpcm_index_table5[32] = {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
|
||||
};
|
||||
|
||||
const int8_t * const ff_adpcm_index_tables[4] = {
|
||||
&adpcm_index_table2[0],
|
||||
&adpcm_index_table3[0],
|
||||
&ff_adpcm_index_table[0],
|
||||
&adpcm_index_table5[0],
|
||||
};
|
||||
|
||||
/**
|
||||
* This is the step table. Note that many programs use slight deviations from
|
||||
* this table, but such deviations are negligible:
|
||||
*/
|
||||
const int16_t ff_adpcm_step_table[89] = {
|
||||
7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
|
||||
19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
|
||||
50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
|
||||
130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
|
||||
337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
|
||||
876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
|
||||
2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
|
||||
5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
|
||||
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
|
||||
};
|
||||
|
||||
const int16_t ff_adpcm_oki_step_table[49] = {
|
||||
16, 17, 19, 21, 23, 25, 28, 31, 34, 37,
|
||||
41, 45, 50, 55, 60, 66, 73, 80, 88, 97,
|
||||
107, 118, 130, 143, 157, 173, 190, 209, 230, 253,
|
||||
279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
|
||||
724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552
|
||||
};
|
||||
|
||||
/* These are for MS-ADPCM */
|
||||
/* ff_adpcm_AdaptationTable[], ff_adpcm_AdaptCoeff1[], and
|
||||
ff_adpcm_AdaptCoeff2[] are from libsndfile */
|
||||
const int16_t ff_adpcm_AdaptationTable[] = {
|
||||
230, 230, 230, 230, 307, 409, 512, 614,
|
||||
768, 614, 512, 409, 307, 230, 230, 230
|
||||
};
|
||||
|
||||
/** Divided by 4 to fit in 8-bit integers */
|
||||
const uint8_t ff_adpcm_AdaptCoeff1[] = {
|
||||
64, 128, 0, 48, 60, 115, 98
|
||||
};
|
||||
|
||||
/** Divided by 4 to fit in 8-bit integers */
|
||||
const int8_t ff_adpcm_AdaptCoeff2[] = {
|
||||
0, -64, 0, 16, 0, -52, -58
|
||||
};
|
||||
|
||||
const int16_t ff_adpcm_yamaha_indexscale[] = {
|
||||
230, 230, 230, 230, 307, 409, 512, 614,
|
||||
230, 230, 230, 230, 307, 409, 512, 614
|
||||
};
|
||||
|
||||
const int8_t ff_adpcm_yamaha_difflookup[] = {
|
||||
1, 3, 5, 7, 9, 11, 13, 15,
|
||||
-1, -3, -5, -7, -9, -11, -13, -15
|
||||
};
|
||||
|
||||
const int16_t ff_adpcm_afc_coeffs[2][16] = {
|
||||
{ 0, 2048, 0, 1024, 4096, 3584, 3072, 4608, 4200, 4800, 5120, 2048, 1024, 64512, 64512, 63488 },
|
||||
{ 0, 0, 2048, 1024, 63488, 64000, 64512, 62976, 63288, 63236, 62464, 63488, 64512, 1024, 0, 0 }
|
||||
};
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2003 The ffmpeg Project
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* ADPCM tables
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_ADPCM_DATA_H
|
||||
#define AVCODEC_ADPCM_DATA_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint8_t ff_adpcm_ima_block_sizes[4] = { 4, 12, 4, 20 };
|
||||
static const uint8_t ff_adpcm_ima_block_samples[4] = { 16, 32, 8, 32 };
|
||||
|
||||
extern const int8_t * const ff_adpcm_index_tables[4];
|
||||
extern const int8_t ff_adpcm_index_table[16];
|
||||
extern const int16_t ff_adpcm_step_table[89];
|
||||
extern const int16_t ff_adpcm_oki_step_table[49];
|
||||
extern const int16_t ff_adpcm_AdaptationTable[];
|
||||
extern const uint8_t ff_adpcm_AdaptCoeff1[];
|
||||
extern const int8_t ff_adpcm_AdaptCoeff2[];
|
||||
extern const int16_t ff_adpcm_yamaha_indexscale[];
|
||||
extern const int8_t ff_adpcm_yamaha_difflookup[];
|
||||
extern const int16_t ff_adpcm_afc_coeffs[2][16];
|
||||
|
||||
#endif /* AVCODEC_ADPCM_DATA_H */
|
|
@ -1,578 +0,0 @@
|
|||
/*
|
||||
* Provide registration of all codecs, parsers and bitstream filters for libavcodec.
|
||||
* Copyright (c) 2002 Fabrice Bellard
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provide registration of all codecs, parsers and bitstream filters for libavcodec.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "avcodec.h"
|
||||
#include "version.h"
|
||||
|
||||
#define REGISTER_HWACCEL(X, x) \
|
||||
{ \
|
||||
extern AVHWAccel ff_##x##_hwaccel; \
|
||||
if (CONFIG_##X##_HWACCEL) \
|
||||
av_register_hwaccel(&ff_##x##_hwaccel); \
|
||||
}
|
||||
|
||||
#define REGISTER_ENCODER(X, x) \
|
||||
{ \
|
||||
extern AVCodec ff_##x##_encoder; \
|
||||
if (CONFIG_##X##_ENCODER) \
|
||||
avcodec_register(&ff_##x##_encoder); \
|
||||
}
|
||||
|
||||
#define REGISTER_DECODER(X, x) \
|
||||
{ \
|
||||
extern AVCodec ff_##x##_decoder; \
|
||||
if (CONFIG_##X##_DECODER) \
|
||||
avcodec_register(&ff_##x##_decoder); \
|
||||
}
|
||||
|
||||
#define REGISTER_ENCDEC(X, x) REGISTER_ENCODER(X, x); REGISTER_DECODER(X, x)
|
||||
|
||||
#define REGISTER_PARSER(X, x) \
|
||||
{ \
|
||||
extern AVCodecParser ff_##x##_parser; \
|
||||
if (CONFIG_##X##_PARSER) \
|
||||
av_register_codec_parser(&ff_##x##_parser); \
|
||||
}
|
||||
|
||||
#define REGISTER_BSF(X, x) \
|
||||
{ \
|
||||
extern AVBitStreamFilter ff_##x##_bsf; \
|
||||
if (CONFIG_##X##_BSF) \
|
||||
av_register_bitstream_filter(&ff_##x##_bsf); \
|
||||
}
|
||||
|
||||
void avcodec_register_all(void)
|
||||
{
|
||||
static int initialized;
|
||||
|
||||
if (initialized)
|
||||
return;
|
||||
initialized = 1;
|
||||
|
||||
/* hardware accelerators */
|
||||
REGISTER_HWACCEL(H263_VAAPI, h263_vaapi);
|
||||
REGISTER_HWACCEL(H263_VDPAU, h263_vdpau);
|
||||
REGISTER_HWACCEL(H264_DXVA2, h264_dxva2);
|
||||
REGISTER_HWACCEL(H264_VAAPI, h264_vaapi);
|
||||
REGISTER_HWACCEL(H264_VDA, h264_vda);
|
||||
REGISTER_HWACCEL(H264_VDPAU, h264_vdpau);
|
||||
REGISTER_HWACCEL(MPEG1_XVMC, mpeg1_xvmc);
|
||||
REGISTER_HWACCEL(MPEG1_VDPAU, mpeg1_vdpau);
|
||||
REGISTER_HWACCEL(MPEG2_XVMC, mpeg2_xvmc);
|
||||
REGISTER_HWACCEL(MPEG2_DXVA2, mpeg2_dxva2);
|
||||
REGISTER_HWACCEL(MPEG2_VAAPI, mpeg2_vaapi);
|
||||
REGISTER_HWACCEL(MPEG2_VDPAU, mpeg2_vdpau);
|
||||
REGISTER_HWACCEL(MPEG4_VAAPI, mpeg4_vaapi);
|
||||
REGISTER_HWACCEL(MPEG4_VDPAU, mpeg4_vdpau);
|
||||
REGISTER_HWACCEL(VC1_DXVA2, vc1_dxva2);
|
||||
REGISTER_HWACCEL(VC1_VAAPI, vc1_vaapi);
|
||||
REGISTER_HWACCEL(VC1_VDPAU, vc1_vdpau);
|
||||
REGISTER_HWACCEL(WMV3_DXVA2, wmv3_dxva2);
|
||||
REGISTER_HWACCEL(WMV3_VAAPI, wmv3_vaapi);
|
||||
REGISTER_HWACCEL(WMV3_VDPAU, wmv3_vdpau);
|
||||
|
||||
/* video codecs */
|
||||
REGISTER_ENCODER(A64MULTI, a64multi);
|
||||
REGISTER_ENCODER(A64MULTI5, a64multi5);
|
||||
REGISTER_DECODER(AASC, aasc);
|
||||
REGISTER_DECODER(AIC, aic);
|
||||
REGISTER_ENCDEC (AMV, amv);
|
||||
REGISTER_DECODER(ANM, anm);
|
||||
REGISTER_DECODER(ANSI, ansi);
|
||||
REGISTER_ENCDEC (ASV1, asv1);
|
||||
REGISTER_ENCDEC (ASV2, asv2);
|
||||
REGISTER_DECODER(AURA, aura);
|
||||
REGISTER_DECODER(AURA2, aura2);
|
||||
REGISTER_ENCDEC (AVRP, avrp);
|
||||
REGISTER_DECODER(AVRN, avrn);
|
||||
REGISTER_DECODER(AVS, avs);
|
||||
REGISTER_ENCDEC (AVUI, avui);
|
||||
REGISTER_ENCDEC (AYUV, ayuv);
|
||||
REGISTER_DECODER(BETHSOFTVID, bethsoftvid);
|
||||
REGISTER_DECODER(BFI, bfi);
|
||||
REGISTER_DECODER(BINK, bink);
|
||||
REGISTER_ENCDEC (BMP, bmp);
|
||||
REGISTER_DECODER(BMV_VIDEO, bmv_video);
|
||||
REGISTER_DECODER(BRENDER_PIX, brender_pix);
|
||||
REGISTER_DECODER(C93, c93);
|
||||
REGISTER_DECODER(CAVS, cavs);
|
||||
REGISTER_DECODER(CDGRAPHICS, cdgraphics);
|
||||
REGISTER_DECODER(CDXL, cdxl);
|
||||
REGISTER_ENCDEC (CINEPAK, cinepak);
|
||||
REGISTER_ENCDEC (CLJR, cljr);
|
||||
REGISTER_DECODER(CLLC, cllc);
|
||||
REGISTER_ENCDEC (COMFORTNOISE, comfortnoise);
|
||||
REGISTER_DECODER(CPIA, cpia);
|
||||
REGISTER_DECODER(CSCD, cscd);
|
||||
REGISTER_DECODER(CYUV, cyuv);
|
||||
REGISTER_DECODER(DFA, dfa);
|
||||
REGISTER_DECODER(DIRAC, dirac);
|
||||
REGISTER_ENCDEC (DNXHD, dnxhd);
|
||||
REGISTER_ENCDEC (DPX, dpx);
|
||||
REGISTER_DECODER(DSICINVIDEO, dsicinvideo);
|
||||
REGISTER_ENCDEC (DVVIDEO, dvvideo);
|
||||
REGISTER_DECODER(DXA, dxa);
|
||||
REGISTER_DECODER(DXTORY, dxtory);
|
||||
REGISTER_DECODER(EACMV, eacmv);
|
||||
REGISTER_DECODER(EAMAD, eamad);
|
||||
REGISTER_DECODER(EATGQ, eatgq);
|
||||
REGISTER_DECODER(EATGV, eatgv);
|
||||
REGISTER_DECODER(EATQI, eatqi);
|
||||
REGISTER_DECODER(EIGHTBPS, eightbps);
|
||||
REGISTER_DECODER(EIGHTSVX_EXP, eightsvx_exp);
|
||||
REGISTER_DECODER(EIGHTSVX_FIB, eightsvx_fib);
|
||||
REGISTER_DECODER(ESCAPE124, escape124);
|
||||
REGISTER_DECODER(ESCAPE130, escape130);
|
||||
REGISTER_DECODER(EXR, exr);
|
||||
REGISTER_ENCDEC (FFV1, ffv1);
|
||||
REGISTER_ENCDEC (FFVHUFF, ffvhuff);
|
||||
REGISTER_DECODER(FIC, fic);
|
||||
REGISTER_ENCDEC (FLASHSV, flashsv);
|
||||
REGISTER_ENCDEC (FLASHSV2, flashsv2);
|
||||
REGISTER_DECODER(FLIC, flic);
|
||||
REGISTER_ENCDEC (FLV, flv);
|
||||
REGISTER_DECODER(FOURXM, fourxm);
|
||||
REGISTER_DECODER(FRAPS, fraps);
|
||||
REGISTER_DECODER(FRWU, frwu);
|
||||
REGISTER_DECODER(G2M, g2m);
|
||||
REGISTER_ENCDEC (GIF, gif);
|
||||
REGISTER_ENCDEC (H261, h261);
|
||||
REGISTER_ENCDEC (H263, h263);
|
||||
REGISTER_DECODER(H263I, h263i);
|
||||
REGISTER_ENCDEC (H263P, h263p);
|
||||
REGISTER_DECODER(H264, h264);
|
||||
REGISTER_DECODER(H264_CRYSTALHD, h264_crystalhd);
|
||||
REGISTER_DECODER(H264_VDA, h264_vda);
|
||||
REGISTER_DECODER(H264_VDPAU, h264_vdpau);
|
||||
REGISTER_DECODER(HEVC, hevc);
|
||||
REGISTER_DECODER(HNM4_VIDEO, hnm4_video);
|
||||
REGISTER_ENCDEC (HUFFYUV, huffyuv);
|
||||
REGISTER_DECODER(IDCIN, idcin);
|
||||
REGISTER_DECODER(IFF_BYTERUN1, iff_byterun1);
|
||||
REGISTER_DECODER(IFF_ILBM, iff_ilbm);
|
||||
REGISTER_DECODER(INDEO2, indeo2);
|
||||
REGISTER_DECODER(INDEO3, indeo3);
|
||||
REGISTER_DECODER(INDEO4, indeo4);
|
||||
REGISTER_DECODER(INDEO5, indeo5);
|
||||
REGISTER_DECODER(INTERPLAY_VIDEO, interplay_video);
|
||||
REGISTER_ENCDEC (JPEG2000, jpeg2000);
|
||||
REGISTER_ENCDEC (JPEGLS, jpegls);
|
||||
REGISTER_DECODER(JV, jv);
|
||||
REGISTER_DECODER(KGV1, kgv1);
|
||||
REGISTER_DECODER(KMVC, kmvc);
|
||||
REGISTER_DECODER(LAGARITH, lagarith);
|
||||
REGISTER_ENCODER(LJPEG, ljpeg);
|
||||
REGISTER_DECODER(LOCO, loco);
|
||||
REGISTER_DECODER(MDEC, mdec);
|
||||
REGISTER_DECODER(MIMIC, mimic);
|
||||
REGISTER_ENCDEC (MJPEG, mjpeg);
|
||||
REGISTER_DECODER(MJPEGB, mjpegb);
|
||||
REGISTER_DECODER(MMVIDEO, mmvideo);
|
||||
REGISTER_DECODER(MOTIONPIXELS, motionpixels);
|
||||
#if FF_API_XVMC
|
||||
REGISTER_DECODER(MPEG_XVMC, mpeg_xvmc);
|
||||
#endif /* FF_API_XVMC */
|
||||
REGISTER_ENCDEC (MPEG1VIDEO, mpeg1video);
|
||||
REGISTER_ENCDEC (MPEG2VIDEO, mpeg2video);
|
||||
REGISTER_ENCDEC (MPEG4, mpeg4);
|
||||
REGISTER_DECODER(MPEG4_CRYSTALHD, mpeg4_crystalhd);
|
||||
REGISTER_DECODER(MPEG4_VDPAU, mpeg4_vdpau);
|
||||
REGISTER_DECODER(MPEGVIDEO, mpegvideo);
|
||||
REGISTER_DECODER(MPEG_VDPAU, mpeg_vdpau);
|
||||
REGISTER_DECODER(MPEG1_VDPAU, mpeg1_vdpau);
|
||||
REGISTER_DECODER(MPEG2_CRYSTALHD, mpeg2_crystalhd);
|
||||
REGISTER_DECODER(MSA1, msa1);
|
||||
REGISTER_DECODER(MSMPEG4_CRYSTALHD, msmpeg4_crystalhd);
|
||||
REGISTER_DECODER(MSMPEG4V1, msmpeg4v1);
|
||||
REGISTER_ENCDEC (MSMPEG4V2, msmpeg4v2);
|
||||
REGISTER_ENCDEC (MSMPEG4V3, msmpeg4v3);
|
||||
REGISTER_DECODER(MSRLE, msrle);
|
||||
REGISTER_DECODER(MSS1, mss1);
|
||||
REGISTER_DECODER(MSS2, mss2);
|
||||
REGISTER_ENCDEC (MSVIDEO1, msvideo1);
|
||||
REGISTER_DECODER(MSZH, mszh);
|
||||
REGISTER_DECODER(MTS2, mts2);
|
||||
REGISTER_DECODER(MVC1, mvc1);
|
||||
REGISTER_DECODER(MVC2, mvc2);
|
||||
REGISTER_DECODER(MXPEG, mxpeg);
|
||||
REGISTER_DECODER(NUV, nuv);
|
||||
REGISTER_DECODER(PAF_VIDEO, paf_video);
|
||||
REGISTER_ENCDEC (PAM, pam);
|
||||
REGISTER_ENCDEC (PBM, pbm);
|
||||
REGISTER_ENCDEC (PCX, pcx);
|
||||
REGISTER_ENCDEC (PGM, pgm);
|
||||
REGISTER_ENCDEC (PGMYUV, pgmyuv);
|
||||
REGISTER_DECODER(PICTOR, pictor);
|
||||
REGISTER_ENCDEC (PNG, png);
|
||||
REGISTER_ENCDEC (PPM, ppm);
|
||||
REGISTER_ENCDEC (PRORES, prores);
|
||||
REGISTER_ENCODER(PRORES_AW, prores_aw);
|
||||
REGISTER_ENCODER(PRORES_KS, prores_ks);
|
||||
REGISTER_DECODER(PRORES_LGPL, prores_lgpl);
|
||||
REGISTER_DECODER(PTX, ptx);
|
||||
REGISTER_DECODER(QDRAW, qdraw);
|
||||
REGISTER_DECODER(QPEG, qpeg);
|
||||
REGISTER_ENCDEC (QTRLE, qtrle);
|
||||
REGISTER_ENCDEC (R10K, r10k);
|
||||
REGISTER_ENCDEC (R210, r210);
|
||||
REGISTER_ENCDEC (RAWVIDEO, rawvideo);
|
||||
REGISTER_DECODER(RL2, rl2);
|
||||
REGISTER_ENCDEC (ROQ, roq);
|
||||
REGISTER_DECODER(RPZA, rpza);
|
||||
REGISTER_ENCDEC (RV10, rv10);
|
||||
REGISTER_ENCDEC (RV20, rv20);
|
||||
REGISTER_DECODER(RV30, rv30);
|
||||
REGISTER_DECODER(RV40, rv40);
|
||||
REGISTER_ENCDEC (S302M, s302m);
|
||||
REGISTER_DECODER(SANM, sanm);
|
||||
REGISTER_ENCDEC (SGI, sgi);
|
||||
REGISTER_DECODER(SGIRLE, sgirle);
|
||||
REGISTER_DECODER(SMACKER, smacker);
|
||||
REGISTER_DECODER(SMC, smc);
|
||||
REGISTER_DECODER(SMVJPEG, smvjpeg);
|
||||
REGISTER_ENCDEC (SNOW, snow);
|
||||
REGISTER_DECODER(SP5X, sp5x);
|
||||
REGISTER_ENCDEC (SUNRAST, sunrast);
|
||||
REGISTER_ENCDEC (SVQ1, svq1);
|
||||
REGISTER_DECODER(SVQ3, svq3);
|
||||
REGISTER_ENCDEC (TARGA, targa);
|
||||
REGISTER_DECODER(TARGA_Y216, targa_y216);
|
||||
REGISTER_DECODER(THEORA, theora);
|
||||
REGISTER_DECODER(THP, thp);
|
||||
REGISTER_DECODER(TIERTEXSEQVIDEO, tiertexseqvideo);
|
||||
REGISTER_ENCDEC (TIFF, tiff);
|
||||
REGISTER_DECODER(TMV, tmv);
|
||||
REGISTER_DECODER(TRUEMOTION1, truemotion1);
|
||||
REGISTER_DECODER(TRUEMOTION2, truemotion2);
|
||||
REGISTER_DECODER(TSCC, tscc);
|
||||
REGISTER_DECODER(TSCC2, tscc2);
|
||||
REGISTER_DECODER(TXD, txd);
|
||||
REGISTER_DECODER(ULTI, ulti);
|
||||
REGISTER_ENCDEC (UTVIDEO, utvideo);
|
||||
REGISTER_ENCDEC (V210, v210);
|
||||
REGISTER_DECODER(V210X, v210x);
|
||||
REGISTER_ENCDEC (V308, v308);
|
||||
REGISTER_ENCDEC (V408, v408);
|
||||
REGISTER_ENCDEC (V410, v410);
|
||||
REGISTER_DECODER(VB, vb);
|
||||
REGISTER_DECODER(VBLE, vble);
|
||||
REGISTER_DECODER(VC1, vc1);
|
||||
REGISTER_DECODER(VC1_CRYSTALHD, vc1_crystalhd);
|
||||
REGISTER_DECODER(VC1_VDPAU, vc1_vdpau);
|
||||
REGISTER_DECODER(VC1IMAGE, vc1image);
|
||||
REGISTER_DECODER(VCR1, vcr1);
|
||||
REGISTER_DECODER(VMDVIDEO, vmdvideo);
|
||||
REGISTER_DECODER(VMNC, vmnc);
|
||||
REGISTER_DECODER(VP3, vp3);
|
||||
REGISTER_DECODER(VP5, vp5);
|
||||
REGISTER_DECODER(VP6, vp6);
|
||||
REGISTER_DECODER(VP6A, vp6a);
|
||||
REGISTER_DECODER(VP6F, vp6f);
|
||||
REGISTER_DECODER(VP8, vp8);
|
||||
REGISTER_DECODER(VQA, vqa);
|
||||
REGISTER_DECODER(WEBP, webp);
|
||||
REGISTER_ENCDEC (WMV1, wmv1);
|
||||
REGISTER_ENCDEC (WMV2, wmv2);
|
||||
REGISTER_DECODER(WMV3, wmv3);
|
||||
REGISTER_DECODER(WMV3_CRYSTALHD, wmv3_crystalhd);
|
||||
REGISTER_DECODER(WMV3_VDPAU, wmv3_vdpau);
|
||||
REGISTER_DECODER(WMV3IMAGE, wmv3image);
|
||||
REGISTER_DECODER(WNV1, wnv1);
|
||||
REGISTER_DECODER(XAN_WC3, xan_wc3);
|
||||
REGISTER_DECODER(XAN_WC4, xan_wc4);
|
||||
REGISTER_ENCDEC (XBM, xbm);
|
||||
REGISTER_ENCDEC (XFACE, xface);
|
||||
REGISTER_DECODER(XL, xl);
|
||||
REGISTER_ENCDEC (XWD, xwd);
|
||||
REGISTER_ENCDEC (Y41P, y41p);
|
||||
REGISTER_DECODER(YOP, yop);
|
||||
REGISTER_ENCDEC (YUV4, yuv4);
|
||||
REGISTER_DECODER(ZERO12V, zero12v);
|
||||
REGISTER_DECODER(ZEROCODEC, zerocodec);
|
||||
REGISTER_ENCDEC (ZLIB, zlib);
|
||||
REGISTER_ENCDEC (ZMBV, zmbv);
|
||||
|
||||
/* audio codecs */
|
||||
REGISTER_ENCDEC (AAC, aac);
|
||||
REGISTER_DECODER(AAC_LATM, aac_latm);
|
||||
REGISTER_ENCDEC (AC3, ac3);
|
||||
REGISTER_ENCODER(AC3_FIXED, ac3_fixed);
|
||||
REGISTER_ENCDEC (ALAC, alac);
|
||||
REGISTER_DECODER(ALS, als);
|
||||
REGISTER_DECODER(AMRNB, amrnb);
|
||||
REGISTER_DECODER(AMRWB, amrwb);
|
||||
REGISTER_DECODER(APE, ape);
|
||||
REGISTER_DECODER(ATRAC1, atrac1);
|
||||
REGISTER_DECODER(ATRAC3, atrac3);
|
||||
REGISTER_DECODER(ATRAC3P, atrac3p);
|
||||
REGISTER_DECODER(BINKAUDIO_DCT, binkaudio_dct);
|
||||
REGISTER_DECODER(BINKAUDIO_RDFT, binkaudio_rdft);
|
||||
REGISTER_DECODER(BMV_AUDIO, bmv_audio);
|
||||
REGISTER_DECODER(COOK, cook);
|
||||
REGISTER_ENCDEC (DCA, dca);
|
||||
REGISTER_DECODER(DSICINAUDIO, dsicinaudio);
|
||||
REGISTER_ENCDEC (EAC3, eac3);
|
||||
REGISTER_DECODER(EVRC, evrc);
|
||||
REGISTER_DECODER(FFWAVESYNTH, ffwavesynth);
|
||||
REGISTER_ENCDEC (FLAC, flac);
|
||||
REGISTER_ENCDEC (G723_1, g723_1);
|
||||
REGISTER_DECODER(G729, g729);
|
||||
REGISTER_DECODER(GSM, gsm);
|
||||
REGISTER_DECODER(GSM_MS, gsm_ms);
|
||||
REGISTER_DECODER(IAC, iac);
|
||||
REGISTER_DECODER(IMC, imc);
|
||||
REGISTER_DECODER(MACE3, mace3);
|
||||
REGISTER_DECODER(MACE6, mace6);
|
||||
REGISTER_DECODER(METASOUND, metasound);
|
||||
REGISTER_DECODER(MLP, mlp);
|
||||
REGISTER_DECODER(MP1, mp1);
|
||||
REGISTER_DECODER(MP1FLOAT, mp1float);
|
||||
REGISTER_ENCDEC (MP2, mp2);
|
||||
REGISTER_DECODER(MP2FLOAT, mp2float);
|
||||
REGISTER_ENCODER(MP2FIXED, mp2fixed);
|
||||
REGISTER_DECODER(MP3, mp3);
|
||||
REGISTER_DECODER(MP3FLOAT, mp3float);
|
||||
REGISTER_DECODER(MP3ADU, mp3adu);
|
||||
REGISTER_DECODER(MP3ADUFLOAT, mp3adufloat);
|
||||
REGISTER_DECODER(MP3ON4, mp3on4);
|
||||
REGISTER_DECODER(MP3ON4FLOAT, mp3on4float);
|
||||
REGISTER_DECODER(MPC7, mpc7);
|
||||
REGISTER_DECODER(MPC8, mpc8);
|
||||
REGISTER_ENCDEC (NELLYMOSER, nellymoser);
|
||||
REGISTER_DECODER(PAF_AUDIO, paf_audio);
|
||||
REGISTER_DECODER(QCELP, qcelp);
|
||||
REGISTER_DECODER(QDM2, qdm2);
|
||||
REGISTER_ENCDEC (RA_144, ra_144);
|
||||
REGISTER_DECODER(RA_288, ra_288);
|
||||
REGISTER_DECODER(RALF, ralf);
|
||||
REGISTER_DECODER(SHORTEN, shorten);
|
||||
REGISTER_DECODER(SIPR, sipr);
|
||||
REGISTER_DECODER(SMACKAUD, smackaud);
|
||||
REGISTER_ENCDEC (SONIC, sonic);
|
||||
REGISTER_ENCODER(SONIC_LS, sonic_ls);
|
||||
REGISTER_DECODER(TAK, tak);
|
||||
REGISTER_DECODER(TRUEHD, truehd);
|
||||
REGISTER_DECODER(TRUESPEECH, truespeech);
|
||||
REGISTER_ENCDEC (TTA, tta);
|
||||
REGISTER_DECODER(TWINVQ, twinvq);
|
||||
REGISTER_DECODER(VMDAUDIO, vmdaudio);
|
||||
REGISTER_ENCDEC (VORBIS, vorbis);
|
||||
REGISTER_ENCDEC (WAVPACK, wavpack);
|
||||
REGISTER_DECODER(WMALOSSLESS, wmalossless);
|
||||
REGISTER_DECODER(WMAPRO, wmapro);
|
||||
REGISTER_ENCDEC (WMAV1, wmav1);
|
||||
REGISTER_ENCDEC (WMAV2, wmav2);
|
||||
REGISTER_DECODER(WMAVOICE, wmavoice);
|
||||
REGISTER_DECODER(WS_SND1, ws_snd1);
|
||||
|
||||
/* PCM codecs */
|
||||
REGISTER_ENCDEC (PCM_ALAW, pcm_alaw);
|
||||
REGISTER_DECODER(PCM_BLURAY, pcm_bluray);
|
||||
REGISTER_DECODER(PCM_DVD, pcm_dvd);
|
||||
REGISTER_ENCDEC (PCM_F32BE, pcm_f32be);
|
||||
REGISTER_ENCDEC (PCM_F32LE, pcm_f32le);
|
||||
REGISTER_ENCDEC (PCM_F64BE, pcm_f64be);
|
||||
REGISTER_ENCDEC (PCM_F64LE, pcm_f64le);
|
||||
REGISTER_DECODER(PCM_LXF, pcm_lxf);
|
||||
REGISTER_ENCDEC (PCM_MULAW, pcm_mulaw);
|
||||
REGISTER_ENCDEC (PCM_S8, pcm_s8);
|
||||
REGISTER_ENCDEC (PCM_S8_PLANAR, pcm_s8_planar);
|
||||
REGISTER_ENCDEC (PCM_S16BE, pcm_s16be);
|
||||
REGISTER_ENCDEC (PCM_S16BE_PLANAR, pcm_s16be_planar);
|
||||
REGISTER_ENCDEC (PCM_S16LE, pcm_s16le);
|
||||
REGISTER_ENCDEC (PCM_S16LE_PLANAR, pcm_s16le_planar);
|
||||
REGISTER_ENCDEC (PCM_S24BE, pcm_s24be);
|
||||
REGISTER_ENCDEC (PCM_S24DAUD, pcm_s24daud);
|
||||
REGISTER_ENCDEC (PCM_S24LE, pcm_s24le);
|
||||
REGISTER_ENCDEC (PCM_S24LE_PLANAR, pcm_s24le_planar);
|
||||
REGISTER_ENCDEC (PCM_S32BE, pcm_s32be);
|
||||
REGISTER_ENCDEC (PCM_S32LE, pcm_s32le);
|
||||
REGISTER_ENCDEC (PCM_S32LE_PLANAR, pcm_s32le_planar);
|
||||
REGISTER_ENCDEC (PCM_U8, pcm_u8);
|
||||
REGISTER_ENCDEC (PCM_U16BE, pcm_u16be);
|
||||
REGISTER_ENCDEC (PCM_U16LE, pcm_u16le);
|
||||
REGISTER_ENCDEC (PCM_U24BE, pcm_u24be);
|
||||
REGISTER_ENCDEC (PCM_U24LE, pcm_u24le);
|
||||
REGISTER_ENCDEC (PCM_U32BE, pcm_u32be);
|
||||
REGISTER_ENCDEC (PCM_U32LE, pcm_u32le);
|
||||
REGISTER_DECODER(PCM_ZORK, pcm_zork);
|
||||
|
||||
/* DPCM codecs */
|
||||
REGISTER_DECODER(INTERPLAY_DPCM, interplay_dpcm);
|
||||
REGISTER_ENCDEC (ROQ_DPCM, roq_dpcm);
|
||||
REGISTER_DECODER(SOL_DPCM, sol_dpcm);
|
||||
REGISTER_DECODER(XAN_DPCM, xan_dpcm);
|
||||
|
||||
/* ADPCM codecs */
|
||||
REGISTER_DECODER(ADPCM_4XM, adpcm_4xm);
|
||||
REGISTER_ENCDEC (ADPCM_ADX, adpcm_adx);
|
||||
REGISTER_DECODER(ADPCM_AFC, adpcm_afc);
|
||||
REGISTER_DECODER(ADPCM_CT, adpcm_ct);
|
||||
REGISTER_DECODER(ADPCM_DTK, adpcm_dtk);
|
||||
REGISTER_DECODER(ADPCM_EA, adpcm_ea);
|
||||
REGISTER_DECODER(ADPCM_EA_MAXIS_XA, adpcm_ea_maxis_xa);
|
||||
REGISTER_DECODER(ADPCM_EA_R1, adpcm_ea_r1);
|
||||
REGISTER_DECODER(ADPCM_EA_R2, adpcm_ea_r2);
|
||||
REGISTER_DECODER(ADPCM_EA_R3, adpcm_ea_r3);
|
||||
REGISTER_DECODER(ADPCM_EA_XAS, adpcm_ea_xas);
|
||||
REGISTER_ENCDEC (ADPCM_G722, adpcm_g722);
|
||||
REGISTER_ENCDEC (ADPCM_G726, adpcm_g726);
|
||||
REGISTER_DECODER(ADPCM_G726LE, adpcm_g726le);
|
||||
REGISTER_DECODER(ADPCM_IMA_AMV, adpcm_ima_amv);
|
||||
REGISTER_DECODER(ADPCM_IMA_APC, adpcm_ima_apc);
|
||||
REGISTER_DECODER(ADPCM_IMA_DK3, adpcm_ima_dk3);
|
||||
REGISTER_DECODER(ADPCM_IMA_DK4, adpcm_ima_dk4);
|
||||
REGISTER_DECODER(ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs);
|
||||
REGISTER_DECODER(ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead);
|
||||
REGISTER_DECODER(ADPCM_IMA_ISS, adpcm_ima_iss);
|
||||
REGISTER_DECODER(ADPCM_IMA_OKI, adpcm_ima_oki);
|
||||
REGISTER_ENCDEC (ADPCM_IMA_QT, adpcm_ima_qt);
|
||||
REGISTER_DECODER(ADPCM_IMA_RAD, adpcm_ima_rad);
|
||||
REGISTER_DECODER(ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
|
||||
REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav);
|
||||
REGISTER_DECODER(ADPCM_IMA_WS, adpcm_ima_ws);
|
||||
REGISTER_ENCDEC (ADPCM_MS, adpcm_ms);
|
||||
REGISTER_DECODER(ADPCM_SBPRO_2, adpcm_sbpro_2);
|
||||
REGISTER_DECODER(ADPCM_SBPRO_3, adpcm_sbpro_3);
|
||||
REGISTER_DECODER(ADPCM_SBPRO_4, adpcm_sbpro_4);
|
||||
REGISTER_ENCDEC (ADPCM_SWF, adpcm_swf);
|
||||
REGISTER_DECODER(ADPCM_THP, adpcm_thp);
|
||||
REGISTER_DECODER(ADPCM_XA, adpcm_xa);
|
||||
REGISTER_ENCDEC (ADPCM_YAMAHA, adpcm_yamaha);
|
||||
REGISTER_DECODER(VIMA, vima);
|
||||
|
||||
/* subtitles */
|
||||
REGISTER_ENCDEC (SSA, ssa);
|
||||
REGISTER_ENCDEC (ASS, ass);
|
||||
REGISTER_ENCDEC (DVBSUB, dvbsub);
|
||||
REGISTER_ENCDEC (DVDSUB, dvdsub);
|
||||
REGISTER_DECODER(JACOSUB, jacosub);
|
||||
REGISTER_DECODER(MICRODVD, microdvd);
|
||||
REGISTER_ENCDEC (MOVTEXT, movtext);
|
||||
REGISTER_DECODER(MPL2, mpl2);
|
||||
REGISTER_DECODER(PGSSUB, pgssub);
|
||||
REGISTER_DECODER(PJS, pjs);
|
||||
REGISTER_DECODER(REALTEXT, realtext);
|
||||
REGISTER_DECODER(SAMI, sami);
|
||||
REGISTER_ENCDEC (SRT, srt);
|
||||
REGISTER_ENCDEC (SUBRIP, subrip);
|
||||
REGISTER_DECODER(SUBVIEWER, subviewer);
|
||||
REGISTER_DECODER(SUBVIEWER1, subviewer1);
|
||||
REGISTER_DECODER(TEXT, text);
|
||||
REGISTER_DECODER(VPLAYER, vplayer);
|
||||
REGISTER_DECODER(WEBVTT, webvtt);
|
||||
REGISTER_ENCDEC (XSUB, xsub);
|
||||
|
||||
/* external libraries */
|
||||
REGISTER_DECODER(LIBCELT, libcelt);
|
||||
REGISTER_ENCODER(LIBFAAC, libfaac);
|
||||
REGISTER_ENCDEC (LIBFDK_AAC, libfdk_aac);
|
||||
REGISTER_ENCDEC (LIBGSM, libgsm);
|
||||
REGISTER_ENCDEC (LIBGSM_MS, libgsm_ms);
|
||||
REGISTER_ENCDEC (LIBILBC, libilbc);
|
||||
REGISTER_ENCODER(LIBMP3LAME, libmp3lame);
|
||||
REGISTER_ENCDEC (LIBOPENCORE_AMRNB, libopencore_amrnb);
|
||||
REGISTER_DECODER(LIBOPENCORE_AMRWB, libopencore_amrwb);
|
||||
REGISTER_ENCDEC (LIBOPENJPEG, libopenjpeg);
|
||||
REGISTER_ENCDEC (LIBOPUS, libopus);
|
||||
REGISTER_ENCDEC (LIBSCHROEDINGER, libschroedinger);
|
||||
REGISTER_ENCODER(LIBSHINE, libshine);
|
||||
REGISTER_ENCDEC (LIBSPEEX, libspeex);
|
||||
REGISTER_DECODER(LIBSTAGEFRIGHT_H264, libstagefright_h264);
|
||||
REGISTER_ENCODER(LIBTHEORA, libtheora);
|
||||
REGISTER_ENCODER(LIBTWOLAME, libtwolame);
|
||||
REGISTER_ENCDEC (LIBUTVIDEO, libutvideo);
|
||||
REGISTER_ENCODER(LIBVO_AACENC, libvo_aacenc);
|
||||
REGISTER_ENCODER(LIBVO_AMRWBENC, libvo_amrwbenc);
|
||||
REGISTER_ENCDEC (LIBVORBIS, libvorbis);
|
||||
REGISTER_ENCDEC (LIBVPX_VP8, libvpx_vp8);
|
||||
REGISTER_ENCDEC (LIBVPX_VP9, libvpx_vp9);
|
||||
REGISTER_ENCODER(LIBWAVPACK, libwavpack);
|
||||
REGISTER_ENCODER(LIBWEBP, libwebp);
|
||||
REGISTER_ENCODER(LIBX264, libx264);
|
||||
REGISTER_ENCODER(LIBX264RGB, libx264rgb);
|
||||
REGISTER_ENCODER(LIBX265, libx265);
|
||||
REGISTER_ENCODER(LIBXAVS, libxavs);
|
||||
REGISTER_ENCODER(LIBXVID, libxvid);
|
||||
REGISTER_DECODER(LIBZVBI_TELETEXT, libzvbi_teletext);
|
||||
REGISTER_ENCODER(LIBAACPLUS, libaacplus);
|
||||
|
||||
/* text */
|
||||
REGISTER_DECODER(BINTEXT, bintext);
|
||||
REGISTER_DECODER(XBIN, xbin);
|
||||
REGISTER_DECODER(IDF, idf);
|
||||
|
||||
/* parsers */
|
||||
REGISTER_PARSER(AAC, aac);
|
||||
REGISTER_PARSER(AAC_LATM, aac_latm);
|
||||
REGISTER_PARSER(AC3, ac3);
|
||||
REGISTER_PARSER(ADX, adx);
|
||||
REGISTER_PARSER(BMP, bmp);
|
||||
REGISTER_PARSER(CAVSVIDEO, cavsvideo);
|
||||
REGISTER_PARSER(COOK, cook);
|
||||
REGISTER_PARSER(DCA, dca);
|
||||
REGISTER_PARSER(DIRAC, dirac);
|
||||
REGISTER_PARSER(DNXHD, dnxhd);
|
||||
REGISTER_PARSER(DVBSUB, dvbsub);
|
||||
REGISTER_PARSER(DVDSUB, dvdsub);
|
||||
REGISTER_PARSER(DVD_NAV, dvd_nav);
|
||||
REGISTER_PARSER(FLAC, flac);
|
||||
REGISTER_PARSER(GSM, gsm);
|
||||
REGISTER_PARSER(H261, h261);
|
||||
REGISTER_PARSER(H263, h263);
|
||||
REGISTER_PARSER(H264, h264);
|
||||
REGISTER_PARSER(HEVC, hevc);
|
||||
REGISTER_PARSER(MJPEG, mjpeg);
|
||||
REGISTER_PARSER(MLP, mlp);
|
||||
REGISTER_PARSER(MPEG4VIDEO, mpeg4video);
|
||||
REGISTER_PARSER(MPEGAUDIO, mpegaudio);
|
||||
REGISTER_PARSER(MPEGVIDEO, mpegvideo);
|
||||
REGISTER_PARSER(PNG, png);
|
||||
REGISTER_PARSER(PNM, pnm);
|
||||
REGISTER_PARSER(RV30, rv30);
|
||||
REGISTER_PARSER(RV40, rv40);
|
||||
REGISTER_PARSER(TAK, tak);
|
||||
REGISTER_PARSER(VC1, vc1);
|
||||
REGISTER_PARSER(VORBIS, vorbis);
|
||||
REGISTER_PARSER(VP3, vp3);
|
||||
REGISTER_PARSER(VP8, vp8);
|
||||
REGISTER_PARSER(VP9, vp9);
|
||||
|
||||
/* bitstream filters */
|
||||
REGISTER_BSF(AAC_ADTSTOASC, aac_adtstoasc);
|
||||
REGISTER_BSF(CHOMP, chomp);
|
||||
REGISTER_BSF(DUMP_EXTRADATA, dump_extradata);
|
||||
REGISTER_BSF(H264_MP4TOANNEXB, h264_mp4toannexb);
|
||||
REGISTER_BSF(IMX_DUMP_HEADER, imx_dump_header);
|
||||
REGISTER_BSF(MJPEG2JPEG, mjpeg2jpeg);
|
||||
REGISTER_BSF(MJPEGA_DUMP_HEADER, mjpega_dump_header);
|
||||
REGISTER_BSF(MP3_HEADER_DECOMPRESS, mp3_header_decompress);
|
||||
REGISTER_BSF(MOV2TEXTSUB, mov2textsub);
|
||||
REGISTER_BSF(NOISE, noise);
|
||||
REGISTER_BSF(REMOVE_EXTRADATA, remove_extradata);
|
||||
REGISTER_BSF(TEXT2MOVSUB, text2movsub);
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Shared functions between AMR codecs
|
||||
*
|
||||
* Copyright (c) 2010 Marcelo Galvao Povoa
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_AMR_H
|
||||
#define AVCODEC_AMR_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "avcodec.h"
|
||||
|
||||
#ifdef AMR_USE_16BIT_TABLES
|
||||
#define R_TABLE_TYPE uint16_t
|
||||
#else
|
||||
#define R_TABLE_TYPE uint8_t
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Fill the frame structure variables from bitstream by parsing the
|
||||
* given reordering table that uses the following format:
|
||||
*
|
||||
* Each field (16 bits) in the AMR Frame is stored as:
|
||||
* - one byte for the number of bits in the field
|
||||
* - one byte for the field index
|
||||
* - then, one byte for each bit of the field (from most-significant to least)
|
||||
* of the position of that bit in the AMR frame.
|
||||
*
|
||||
* @param out pointer to the frame struct
|
||||
* @param size the size in bytes of the frame struct
|
||||
* @param data input bitstream after the frame header
|
||||
* @param ord_table the reordering table as above
|
||||
*/
|
||||
static inline void ff_amr_bit_reorder(uint16_t *out, int size,
|
||||
const uint8_t *data,
|
||||
const R_TABLE_TYPE *ord_table)
|
||||
{
|
||||
int field_size;
|
||||
|
||||
memset(out, 0, size);
|
||||
while ((field_size = *ord_table++)) {
|
||||
int field = 0;
|
||||
int field_offset = *ord_table++;
|
||||
while (field_size--) {
|
||||
int bit = *ord_table++;
|
||||
field <<= 1;
|
||||
field |= data[bit >> 3] >> (bit & 7) & 1;
|
||||
}
|
||||
out[field_offset >> 1] = field;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* AVCODEC_AMR_H */
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,165 +0,0 @@
|
|||
/*
|
||||
* common functions for the ATRAC family of decoders
|
||||
*
|
||||
* Copyright (c) 2006-2013 Maxim Poliakovski
|
||||
* Copyright (c) 2006-2008 Benjamin Larsson
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "avcodec.h"
|
||||
#include "atrac.h"
|
||||
|
||||
float ff_atrac_sf_table[64];
|
||||
static float qmf_window[48];
|
||||
|
||||
static const float qmf_48tap_half[24] = {
|
||||
-0.00001461907, -0.00009205479,-0.000056157569,0.00030117269,
|
||||
0.0002422519, -0.00085293897,-0.0005205574, 0.0020340169,
|
||||
0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944,
|
||||
-0.000061169922,-0.01344162, 0.0024626821, 0.021736089,
|
||||
-0.007801671, -0.034090221, 0.01880949, 0.054326009,
|
||||
-0.043596379, -0.099384367, 0.13207909, 0.46424159
|
||||
};
|
||||
|
||||
av_cold void ff_atrac_generate_tables(void)
|
||||
{
|
||||
int i;
|
||||
float s;
|
||||
|
||||
/* Generate scale factors */
|
||||
if (!ff_atrac_sf_table[63])
|
||||
for (i=0 ; i<64 ; i++)
|
||||
ff_atrac_sf_table[i] = pow(2.0, (i - 15) / 3.0);
|
||||
|
||||
/* Generate the QMF window. */
|
||||
if (!qmf_window[47])
|
||||
for (i=0 ; i<24; i++) {
|
||||
s = qmf_48tap_half[i] * 2.0;
|
||||
qmf_window[i] = qmf_window[47 - i] = s;
|
||||
}
|
||||
}
|
||||
|
||||
av_cold void ff_atrac_init_gain_compensation(AtracGCContext *gctx, int id2exp_offset,
|
||||
int loc_scale)
|
||||
{
|
||||
int i;
|
||||
|
||||
gctx->loc_scale = loc_scale;
|
||||
gctx->loc_size = 1 << loc_scale;
|
||||
gctx->id2exp_offset = id2exp_offset;
|
||||
|
||||
/* Generate gain level table. */
|
||||
for (i = 0; i < 16; i++)
|
||||
gctx->gain_tab1[i] = powf(2.0, id2exp_offset - i);
|
||||
|
||||
/* Generate gain interpolation table. */
|
||||
for (i = -15; i < 16; i++)
|
||||
gctx->gain_tab2[i + 15] = powf(2.0, -1.0f / gctx->loc_size * i);
|
||||
}
|
||||
|
||||
void ff_atrac_gain_compensation(AtracGCContext *gctx, float *in, float *prev,
|
||||
AtracGainInfo *gc_now, AtracGainInfo *gc_next,
|
||||
int num_samples, float *out)
|
||||
{
|
||||
float lev, gc_scale, gain_inc;
|
||||
int i, pos, lastpos;
|
||||
|
||||
gc_scale = gc_next->num_points ? gctx->gain_tab1[gc_next->lev_code[0]]
|
||||
: 1.0f;
|
||||
|
||||
if (!gc_now->num_points) {
|
||||
for (pos = 0; pos < num_samples; pos++)
|
||||
out[pos] = in[pos] * gc_scale + prev[pos];
|
||||
} else {
|
||||
pos = 0;
|
||||
|
||||
for (i = 0; i < gc_now->num_points; i++) {
|
||||
lastpos = gc_now->loc_code[i] << gctx->loc_scale;
|
||||
|
||||
lev = gctx->gain_tab1[gc_now->lev_code[i]];
|
||||
gain_inc = gctx->gain_tab2[(i + 1 < gc_now->num_points ? gc_now->lev_code[i + 1]
|
||||
: gctx->id2exp_offset) -
|
||||
gc_now->lev_code[i] + 15];
|
||||
|
||||
/* apply constant gain level and overlap */
|
||||
for (; pos < lastpos; pos++)
|
||||
out[pos] = (in[pos] * gc_scale + prev[pos]) * lev;
|
||||
|
||||
/* interpolate between two different gain levels */
|
||||
for (; pos < lastpos + gctx->loc_size; pos++) {
|
||||
out[pos] = (in[pos] * gc_scale + prev[pos]) * lev;
|
||||
lev *= gain_inc;
|
||||
}
|
||||
}
|
||||
|
||||
for (; pos < num_samples; pos++)
|
||||
out[pos] = in[pos] * gc_scale + prev[pos];
|
||||
}
|
||||
|
||||
/* copy the overlapping part into the delay buffer */
|
||||
memcpy(prev, &in[num_samples], num_samples * sizeof(float));
|
||||
}
|
||||
|
||||
void ff_atrac_iqmf(float *inlo, float *inhi, unsigned int nIn, float *pOut,
|
||||
float *delayBuf, float *temp)
|
||||
{
|
||||
int i, j;
|
||||
float *p1, *p3;
|
||||
|
||||
memcpy(temp, delayBuf, 46*sizeof(float));
|
||||
|
||||
p3 = temp + 46;
|
||||
|
||||
/* loop1 */
|
||||
for(i=0; i<nIn; i+=2){
|
||||
p3[2*i+0] = inlo[i ] + inhi[i ];
|
||||
p3[2*i+1] = inlo[i ] - inhi[i ];
|
||||
p3[2*i+2] = inlo[i+1] + inhi[i+1];
|
||||
p3[2*i+3] = inlo[i+1] - inhi[i+1];
|
||||
}
|
||||
|
||||
/* loop2 */
|
||||
p1 = temp;
|
||||
for (j = nIn; j != 0; j--) {
|
||||
float s1 = 0.0;
|
||||
float s2 = 0.0;
|
||||
|
||||
for (i = 0; i < 48; i += 2) {
|
||||
s1 += p1[i] * qmf_window[i];
|
||||
s2 += p1[i+1] * qmf_window[i+1];
|
||||
}
|
||||
|
||||
pOut[0] = s2;
|
||||
pOut[1] = s1;
|
||||
|
||||
p1 += 2;
|
||||
pOut += 2;
|
||||
}
|
||||
|
||||
/* Update the delay buffer. */
|
||||
memcpy(delayBuf, temp + nIn*2, 46*sizeof(float));
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* common functions for the ATRAC family of decoders
|
||||
*
|
||||
* Copyright (c) 2009-2013 Maxim Poliakovski
|
||||
* Copyright (c) 2009 Benjamin Larsson
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* ATRAC common header
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_ATRAC_H
|
||||
#define AVCODEC_ATRAC_H
|
||||
|
||||
/**
|
||||
* Gain control parameters for one subband.
|
||||
*/
|
||||
typedef struct AtracGainInfo {
|
||||
int num_points; ///< number of gain control points
|
||||
int lev_code[7]; ///< level at corresponding control point
|
||||
int loc_code[7]; ///< location of gain control points
|
||||
} AtracGainInfo;
|
||||
|
||||
/**
|
||||
* Gain compensation context structure.
|
||||
*/
|
||||
typedef struct AtracGCContext {
|
||||
float gain_tab1[16]; ///< gain compensation level table
|
||||
float gain_tab2[31]; ///< gain compensation interpolation table
|
||||
int id2exp_offset; ///< offset for converting level index into level exponent
|
||||
int loc_scale; ///< scale of location code = 2^loc_scale samples
|
||||
int loc_size; ///< size of location code in samples
|
||||
} AtracGCContext;
|
||||
|
||||
extern float ff_atrac_sf_table[64];
|
||||
|
||||
/**
|
||||
* Generate common tables.
|
||||
*/
|
||||
void ff_atrac_generate_tables(void);
|
||||
|
||||
/**
|
||||
* Initialize gain compensation context.
|
||||
*
|
||||
* @param gctx pointer to gain compensation context to initialize
|
||||
* @param id2exp_offset offset for converting level index into level exponent
|
||||
* @param loc_scale location size factor
|
||||
*/
|
||||
void ff_atrac_init_gain_compensation(AtracGCContext *gctx, int id2exp_offset,
|
||||
int loc_scale);
|
||||
|
||||
/**
|
||||
* Apply gain compensation and perform the MDCT overlapping part.
|
||||
*
|
||||
* @param gctx pointer to gain compensation context
|
||||
* @param in input buffer
|
||||
* @param prev previous buffer to perform overlap against
|
||||
* @param gc_now gain control information for current frame
|
||||
* @param gc_next gain control information for next frame
|
||||
* @param num_samples number of samples to process
|
||||
* @param out output data goes here
|
||||
*/
|
||||
void ff_atrac_gain_compensation(AtracGCContext *gctx, float *in, float *prev,
|
||||
AtracGainInfo *gc_now, AtracGainInfo *gc_next,
|
||||
int num_samples, float *out);
|
||||
|
||||
/**
|
||||
* Quadrature mirror synthesis filter.
|
||||
*
|
||||
* @param inlo lower part of spectrum
|
||||
* @param inhi higher part of spectrum
|
||||
* @param nIn size of spectrum buffer
|
||||
* @param pOut out buffer
|
||||
* @param delayBuf delayBuf buffer
|
||||
* @param temp temp buffer
|
||||
*/
|
||||
void ff_atrac_iqmf(float *inlo, float *inhi, unsigned int nIn, float *pOut,
|
||||
float *delayBuf, float *temp);
|
||||
|
||||
#endif /* AVCODEC_ATRAC_H */
|
|
@ -1,943 +0,0 @@
|
|||
/*
|
||||
* ATRAC3 compatible decoder
|
||||
* Copyright (c) 2006-2008 Maxim Poliakovski
|
||||
* Copyright (c) 2006-2008 Benjamin Larsson
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* ATRAC3 compatible decoder.
|
||||
* This decoder handles Sony's ATRAC3 data.
|
||||
*
|
||||
* Container formats used to store ATRAC3 data:
|
||||
* RealMedia (.rm), RIFF WAV (.wav, .at3), Sony OpenMG (.oma, .aa3).
|
||||
*
|
||||
* To use this decoder, a calling application must supply the extradata
|
||||
* bytes provided in the containers above.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libavutil/attributes.h"
|
||||
#include "libavutil/float_dsp.h"
|
||||
#include "libavutil/libm.h"
|
||||
#include "libavutil/internal.h"
|
||||
#include "avcodec.h"
|
||||
#include "bytestream.h"
|
||||
#include "fft.h"
|
||||
#include "fmtconvert.h"
|
||||
#include "get_bits.h"
|
||||
#include "internal.h"
|
||||
|
||||
#include "atrac.h"
|
||||
#include "atrac3data.h"
|
||||
|
||||
#define JOINT_STEREO 0x12
|
||||
#define STEREO 0x2
|
||||
|
||||
#define SAMPLES_PER_FRAME 1024
|
||||
#define MDCT_SIZE 512
|
||||
|
||||
typedef struct GainBlock {
|
||||
AtracGainInfo g_block[4];
|
||||
} GainBlock;
|
||||
|
||||
typedef struct TonalComponent {
|
||||
int pos;
|
||||
int num_coefs;
|
||||
float coef[8];
|
||||
} TonalComponent;
|
||||
|
||||
typedef struct ChannelUnit {
|
||||
int bands_coded;
|
||||
int num_components;
|
||||
float prev_frame[SAMPLES_PER_FRAME];
|
||||
int gc_blk_switch;
|
||||
TonalComponent components[64];
|
||||
GainBlock gain_block[2];
|
||||
|
||||
DECLARE_ALIGNED(32, float, spectrum)[SAMPLES_PER_FRAME];
|
||||
DECLARE_ALIGNED(32, float, imdct_buf)[SAMPLES_PER_FRAME];
|
||||
|
||||
float delay_buf1[46]; ///<qmf delay buffers
|
||||
float delay_buf2[46];
|
||||
float delay_buf3[46];
|
||||
} ChannelUnit;
|
||||
|
||||
typedef struct ATRAC3Context {
|
||||
GetBitContext gb;
|
||||
//@{
|
||||
/** stream data */
|
||||
int coding_mode;
|
||||
|
||||
ChannelUnit *units;
|
||||
//@}
|
||||
//@{
|
||||
/** joint-stereo related variables */
|
||||
int matrix_coeff_index_prev[4];
|
||||
int matrix_coeff_index_now[4];
|
||||
int matrix_coeff_index_next[4];
|
||||
int weighting_delay[6];
|
||||
//@}
|
||||
//@{
|
||||
/** data buffers */
|
||||
uint8_t *decoded_bytes_buffer;
|
||||
float temp_buf[1070];
|
||||
//@}
|
||||
//@{
|
||||
/** extradata */
|
||||
int scrambled_stream;
|
||||
//@}
|
||||
|
||||
AtracGCContext gainc_ctx;
|
||||
FFTContext mdct_ctx;
|
||||
FmtConvertContext fmt_conv;
|
||||
AVFloatDSPContext fdsp;
|
||||
} ATRAC3Context;
|
||||
|
||||
static DECLARE_ALIGNED(32, float, mdct_window)[MDCT_SIZE];
|
||||
static VLC_TYPE atrac3_vlc_table[4096][2];
|
||||
static VLC spectral_coeff_tab[7];
|
||||
|
||||
/**
|
||||
* Regular 512 points IMDCT without overlapping, with the exception of the
|
||||
* swapping of odd bands caused by the reverse spectra of the QMF.
|
||||
*
|
||||
* @param odd_band 1 if the band is an odd band
|
||||
*/
|
||||
static void imlt(ATRAC3Context *q, float *input, float *output, int odd_band)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (odd_band) {
|
||||
/**
|
||||
* Reverse the odd bands before IMDCT, this is an effect of the QMF
|
||||
* transform or it gives better compression to do it this way.
|
||||
* FIXME: It should be possible to handle this in imdct_calc
|
||||
* for that to happen a modification of the prerotation step of
|
||||
* all SIMD code and C code is needed.
|
||||
* Or fix the functions before so they generate a pre reversed spectrum.
|
||||
*/
|
||||
for (i = 0; i < 128; i++)
|
||||
FFSWAP(float, input[i], input[255 - i]);
|
||||
}
|
||||
|
||||
q->mdct_ctx.imdct_calc(&q->mdct_ctx, output, input);
|
||||
|
||||
/* Perform windowing on the output. */
|
||||
q->fdsp.vector_fmul(output, output, mdct_window, MDCT_SIZE);
|
||||
}
|
||||
|
||||
/*
|
||||
* indata descrambling, only used for data coming from the rm container
|
||||
*/
|
||||
static int decode_bytes(const uint8_t *input, uint8_t *out, int bytes)
|
||||
{
|
||||
int i, off;
|
||||
uint32_t c;
|
||||
const uint32_t *buf;
|
||||
uint32_t *output = (uint32_t *)out;
|
||||
|
||||
off = (intptr_t)input & 3;
|
||||
buf = (const uint32_t *)(input - off);
|
||||
if (off)
|
||||
c = av_be2ne32((0x537F6103U >> (off * 8)) | (0x537F6103U << (32 - (off * 8))));
|
||||
else
|
||||
c = av_be2ne32(0x537F6103U);
|
||||
bytes += 3 + off;
|
||||
for (i = 0; i < bytes / 4; i++)
|
||||
output[i] = c ^ buf[i];
|
||||
|
||||
if (off)
|
||||
avpriv_request_sample(NULL, "Offset of %d", off);
|
||||
|
||||
return off;
|
||||
}
|
||||
|
||||
static av_cold void init_imdct_window(void)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
/* generate the mdct window, for details see
|
||||
* http://wiki.multimedia.cx/index.php?title=RealAudio_atrc#Windows */
|
||||
for (i = 0, j = 255; i < 128; i++, j--) {
|
||||
float wi = sin(((i + 0.5) / 256.0 - 0.5) * M_PI) + 1.0;
|
||||
float wj = sin(((j + 0.5) / 256.0 - 0.5) * M_PI) + 1.0;
|
||||
float w = 0.5 * (wi * wi + wj * wj);
|
||||
mdct_window[i] = mdct_window[511 - i] = wi / w;
|
||||
mdct_window[j] = mdct_window[511 - j] = wj / w;
|
||||
}
|
||||
}
|
||||
|
||||
static av_cold int atrac3_decode_close(AVCodecContext *avctx)
|
||||
{
|
||||
ATRAC3Context *q = avctx->priv_data;
|
||||
|
||||
av_free(q->units);
|
||||
av_free(q->decoded_bytes_buffer);
|
||||
|
||||
ff_mdct_end(&q->mdct_ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mantissa decoding
|
||||
*
|
||||
* @param selector which table the output values are coded with
|
||||
* @param coding_flag constant length coding or variable length coding
|
||||
* @param mantissas mantissa output table
|
||||
* @param num_codes number of values to get
|
||||
*/
|
||||
static void read_quant_spectral_coeffs(GetBitContext *gb, int selector,
|
||||
int coding_flag, int *mantissas,
|
||||
int num_codes)
|
||||
{
|
||||
int i, code, huff_symb;
|
||||
|
||||
if (selector == 1)
|
||||
num_codes /= 2;
|
||||
|
||||
if (coding_flag != 0) {
|
||||
/* constant length coding (CLC) */
|
||||
int num_bits = clc_length_tab[selector];
|
||||
|
||||
if (selector > 1) {
|
||||
for (i = 0; i < num_codes; i++) {
|
||||
if (num_bits)
|
||||
code = get_sbits(gb, num_bits);
|
||||
else
|
||||
code = 0;
|
||||
mantissas[i] = code;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < num_codes; i++) {
|
||||
if (num_bits)
|
||||
code = get_bits(gb, num_bits); // num_bits is always 4 in this case
|
||||
else
|
||||
code = 0;
|
||||
mantissas[i * 2 ] = mantissa_clc_tab[code >> 2];
|
||||
mantissas[i * 2 + 1] = mantissa_clc_tab[code & 3];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* variable length coding (VLC) */
|
||||
if (selector != 1) {
|
||||
for (i = 0; i < num_codes; i++) {
|
||||
huff_symb = get_vlc2(gb, spectral_coeff_tab[selector-1].table,
|
||||
spectral_coeff_tab[selector-1].bits, 3);
|
||||
huff_symb += 1;
|
||||
code = huff_symb >> 1;
|
||||
if (huff_symb & 1)
|
||||
code = -code;
|
||||
mantissas[i] = code;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < num_codes; i++) {
|
||||
huff_symb = get_vlc2(gb, spectral_coeff_tab[selector - 1].table,
|
||||
spectral_coeff_tab[selector - 1].bits, 3);
|
||||
mantissas[i * 2 ] = mantissa_vlc_tab[huff_symb * 2 ];
|
||||
mantissas[i * 2 + 1] = mantissa_vlc_tab[huff_symb * 2 + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the quantized band spectrum coefficients
|
||||
*
|
||||
* @return subband count, fix for broken specification/files
|
||||
*/
|
||||
static int decode_spectrum(GetBitContext *gb, float *output)
|
||||
{
|
||||
int num_subbands, coding_mode, i, j, first, last, subband_size;
|
||||
int subband_vlc_index[32], sf_index[32];
|
||||
int mantissas[128];
|
||||
float scale_factor;
|
||||
|
||||
num_subbands = get_bits(gb, 5); // number of coded subbands
|
||||
coding_mode = get_bits1(gb); // coding Mode: 0 - VLC/ 1-CLC
|
||||
|
||||
/* get the VLC selector table for the subbands, 0 means not coded */
|
||||
for (i = 0; i <= num_subbands; i++)
|
||||
subband_vlc_index[i] = get_bits(gb, 3);
|
||||
|
||||
/* read the scale factor indexes from the stream */
|
||||
for (i = 0; i <= num_subbands; i++) {
|
||||
if (subband_vlc_index[i] != 0)
|
||||
sf_index[i] = get_bits(gb, 6);
|
||||
}
|
||||
|
||||
for (i = 0; i <= num_subbands; i++) {
|
||||
first = subband_tab[i ];
|
||||
last = subband_tab[i + 1];
|
||||
|
||||
subband_size = last - first;
|
||||
|
||||
if (subband_vlc_index[i] != 0) {
|
||||
/* decode spectral coefficients for this subband */
|
||||
/* TODO: This can be done faster is several blocks share the
|
||||
* same VLC selector (subband_vlc_index) */
|
||||
read_quant_spectral_coeffs(gb, subband_vlc_index[i], coding_mode,
|
||||
mantissas, subband_size);
|
||||
|
||||
/* decode the scale factor for this subband */
|
||||
scale_factor = ff_atrac_sf_table[sf_index[i]] *
|
||||
inv_max_quant[subband_vlc_index[i]];
|
||||
|
||||
/* inverse quantize the coefficients */
|
||||
for (j = 0; first < last; first++, j++)
|
||||
output[first] = mantissas[j] * scale_factor;
|
||||
} else {
|
||||
/* this subband was not coded, so zero the entire subband */
|
||||
memset(output + first, 0, subband_size * sizeof(*output));
|
||||
}
|
||||
}
|
||||
|
||||
/* clear the subbands that were not coded */
|
||||
first = subband_tab[i];
|
||||
memset(output + first, 0, (SAMPLES_PER_FRAME - first) * sizeof(*output));
|
||||
return num_subbands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the quantized tonal components
|
||||
*
|
||||
* @param components tonal components
|
||||
* @param num_bands number of coded bands
|
||||
*/
|
||||
static int decode_tonal_components(GetBitContext *gb,
|
||||
TonalComponent *components, int num_bands)
|
||||
{
|
||||
int i, b, c, m;
|
||||
int nb_components, coding_mode_selector, coding_mode;
|
||||
int band_flags[4], mantissa[8];
|
||||
int component_count = 0;
|
||||
|
||||
nb_components = get_bits(gb, 5);
|
||||
|
||||
/* no tonal components */
|
||||
if (nb_components == 0)
|
||||
return 0;
|
||||
|
||||
coding_mode_selector = get_bits(gb, 2);
|
||||
if (coding_mode_selector == 2)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
coding_mode = coding_mode_selector & 1;
|
||||
|
||||
for (i = 0; i < nb_components; i++) {
|
||||
int coded_values_per_component, quant_step_index;
|
||||
|
||||
for (b = 0; b <= num_bands; b++)
|
||||
band_flags[b] = get_bits1(gb);
|
||||
|
||||
coded_values_per_component = get_bits(gb, 3);
|
||||
|
||||
quant_step_index = get_bits(gb, 3);
|
||||
if (quant_step_index <= 1)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
if (coding_mode_selector == 3)
|
||||
coding_mode = get_bits1(gb);
|
||||
|
||||
for (b = 0; b < (num_bands + 1) * 4; b++) {
|
||||
int coded_components;
|
||||
|
||||
if (band_flags[b >> 2] == 0)
|
||||
continue;
|
||||
|
||||
coded_components = get_bits(gb, 3);
|
||||
|
||||
for (c = 0; c < coded_components; c++) {
|
||||
TonalComponent *cmp = &components[component_count];
|
||||
int sf_index, coded_values, max_coded_values;
|
||||
float scale_factor;
|
||||
|
||||
sf_index = get_bits(gb, 6);
|
||||
if (component_count >= 64)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
cmp->pos = b * 64 + get_bits(gb, 6);
|
||||
|
||||
max_coded_values = SAMPLES_PER_FRAME - cmp->pos;
|
||||
coded_values = coded_values_per_component + 1;
|
||||
coded_values = FFMIN(max_coded_values, coded_values);
|
||||
|
||||
scale_factor = ff_atrac_sf_table[sf_index] *
|
||||
inv_max_quant[quant_step_index];
|
||||
|
||||
read_quant_spectral_coeffs(gb, quant_step_index, coding_mode,
|
||||
mantissa, coded_values);
|
||||
|
||||
cmp->num_coefs = coded_values;
|
||||
|
||||
/* inverse quant */
|
||||
for (m = 0; m < coded_values; m++)
|
||||
cmp->coef[m] = mantissa[m] * scale_factor;
|
||||
|
||||
component_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return component_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode gain parameters for the coded bands
|
||||
*
|
||||
* @param block the gainblock for the current band
|
||||
* @param num_bands amount of coded bands
|
||||
*/
|
||||
static int decode_gain_control(GetBitContext *gb, GainBlock *block,
|
||||
int num_bands)
|
||||
{
|
||||
int b, j;
|
||||
int *level, *loc;
|
||||
|
||||
AtracGainInfo *gain = block->g_block;
|
||||
|
||||
for (b = 0; b <= num_bands; b++) {
|
||||
gain[b].num_points = get_bits(gb, 3);
|
||||
level = gain[b].lev_code;
|
||||
loc = gain[b].loc_code;
|
||||
|
||||
for (j = 0; j < gain[b].num_points; j++) {
|
||||
level[j] = get_bits(gb, 4);
|
||||
loc[j] = get_bits(gb, 5);
|
||||
if (j && loc[j] <= loc[j - 1])
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear the unused blocks. */
|
||||
for (; b < 4 ; b++)
|
||||
gain[b].num_points = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine the tonal band spectrum and regular band spectrum
|
||||
*
|
||||
* @param spectrum output spectrum buffer
|
||||
* @param num_components number of tonal components
|
||||
* @param components tonal components for this band
|
||||
* @return position of the last tonal coefficient
|
||||
*/
|
||||
static int add_tonal_components(float *spectrum, int num_components,
|
||||
TonalComponent *components)
|
||||
{
|
||||
int i, j, last_pos = -1;
|
||||
float *input, *output;
|
||||
|
||||
for (i = 0; i < num_components; i++) {
|
||||
last_pos = FFMAX(components[i].pos + components[i].num_coefs, last_pos);
|
||||
input = components[i].coef;
|
||||
output = &spectrum[components[i].pos];
|
||||
|
||||
for (j = 0; j < components[i].num_coefs; j++)
|
||||
output[j] += input[j];
|
||||
}
|
||||
|
||||
return last_pos;
|
||||
}
|
||||
|
||||
#define INTERPOLATE(old, new, nsample) \
|
||||
((old) + (nsample) * 0.125 * ((new) - (old)))
|
||||
|
||||
static void reverse_matrixing(float *su1, float *su2, int *prev_code,
|
||||
int *curr_code)
|
||||
{
|
||||
int i, nsample, band;
|
||||
float mc1_l, mc1_r, mc2_l, mc2_r;
|
||||
|
||||
for (i = 0, band = 0; band < 4 * 256; band += 256, i++) {
|
||||
int s1 = prev_code[i];
|
||||
int s2 = curr_code[i];
|
||||
nsample = band;
|
||||
|
||||
if (s1 != s2) {
|
||||
/* Selector value changed, interpolation needed. */
|
||||
mc1_l = matrix_coeffs[s1 * 2 ];
|
||||
mc1_r = matrix_coeffs[s1 * 2 + 1];
|
||||
mc2_l = matrix_coeffs[s2 * 2 ];
|
||||
mc2_r = matrix_coeffs[s2 * 2 + 1];
|
||||
|
||||
/* Interpolation is done over the first eight samples. */
|
||||
for (; nsample < band + 8; nsample++) {
|
||||
float c1 = su1[nsample];
|
||||
float c2 = su2[nsample];
|
||||
c2 = c1 * INTERPOLATE(mc1_l, mc2_l, nsample - band) +
|
||||
c2 * INTERPOLATE(mc1_r, mc2_r, nsample - band);
|
||||
su1[nsample] = c2;
|
||||
su2[nsample] = c1 * 2.0 - c2;
|
||||
}
|
||||
}
|
||||
|
||||
/* Apply the matrix without interpolation. */
|
||||
switch (s2) {
|
||||
case 0: /* M/S decoding */
|
||||
for (; nsample < band + 256; nsample++) {
|
||||
float c1 = su1[nsample];
|
||||
float c2 = su2[nsample];
|
||||
su1[nsample] = c2 * 2.0;
|
||||
su2[nsample] = (c1 - c2) * 2.0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
for (; nsample < band + 256; nsample++) {
|
||||
float c1 = su1[nsample];
|
||||
float c2 = su2[nsample];
|
||||
su1[nsample] = (c1 + c2) * 2.0;
|
||||
su2[nsample] = c2 * -2.0;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
for (; nsample < band + 256; nsample++) {
|
||||
float c1 = su1[nsample];
|
||||
float c2 = su2[nsample];
|
||||
su1[nsample] = c1 + c2;
|
||||
su2[nsample] = c1 - c2;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
av_assert1(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void get_channel_weights(int index, int flag, float ch[2])
|
||||
{
|
||||
if (index == 7) {
|
||||
ch[0] = 1.0;
|
||||
ch[1] = 1.0;
|
||||
} else {
|
||||
ch[0] = (index & 7) / 7.0;
|
||||
ch[1] = sqrt(2 - ch[0] * ch[0]);
|
||||
if (flag)
|
||||
FFSWAP(float, ch[0], ch[1]);
|
||||
}
|
||||
}
|
||||
|
||||
static void channel_weighting(float *su1, float *su2, int *p3)
|
||||
{
|
||||
int band, nsample;
|
||||
/* w[x][y] y=0 is left y=1 is right */
|
||||
float w[2][2];
|
||||
|
||||
if (p3[1] != 7 || p3[3] != 7) {
|
||||
get_channel_weights(p3[1], p3[0], w[0]);
|
||||
get_channel_weights(p3[3], p3[2], w[1]);
|
||||
|
||||
for (band = 256; band < 4 * 256; band += 256) {
|
||||
for (nsample = band; nsample < band + 8; nsample++) {
|
||||
su1[nsample] *= INTERPOLATE(w[0][0], w[0][1], nsample - band);
|
||||
su2[nsample] *= INTERPOLATE(w[1][0], w[1][1], nsample - band);
|
||||
}
|
||||
for(; nsample < band + 256; nsample++) {
|
||||
su1[nsample] *= w[1][0];
|
||||
su2[nsample] *= w[1][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a Sound Unit
|
||||
*
|
||||
* @param snd the channel unit to be used
|
||||
* @param output the decoded samples before IQMF in float representation
|
||||
* @param channel_num channel number
|
||||
* @param coding_mode the coding mode (JOINT_STEREO or regular stereo/mono)
|
||||
*/
|
||||
static int decode_channel_sound_unit(ATRAC3Context *q, GetBitContext *gb,
|
||||
ChannelUnit *snd, float *output,
|
||||
int channel_num, int coding_mode)
|
||||
{
|
||||
int band, ret, num_subbands, last_tonal, num_bands;
|
||||
GainBlock *gain1 = &snd->gain_block[ snd->gc_blk_switch];
|
||||
GainBlock *gain2 = &snd->gain_block[1 - snd->gc_blk_switch];
|
||||
|
||||
if (coding_mode == JOINT_STEREO && channel_num == 1) {
|
||||
if (get_bits(gb, 2) != 3) {
|
||||
av_log(NULL,AV_LOG_ERROR,"JS mono Sound Unit id != 3.\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
} else {
|
||||
if (get_bits(gb, 6) != 0x28) {
|
||||
av_log(NULL,AV_LOG_ERROR,"Sound Unit id != 0x28.\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
||||
|
||||
/* number of coded QMF bands */
|
||||
snd->bands_coded = get_bits(gb, 2);
|
||||
|
||||
ret = decode_gain_control(gb, gain2, snd->bands_coded);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
snd->num_components = decode_tonal_components(gb, snd->components,
|
||||
snd->bands_coded);
|
||||
if (snd->num_components < 0)
|
||||
return snd->num_components;
|
||||
|
||||
num_subbands = decode_spectrum(gb, snd->spectrum);
|
||||
|
||||
/* Merge the decoded spectrum and tonal components. */
|
||||
last_tonal = add_tonal_components(snd->spectrum, snd->num_components,
|
||||
snd->components);
|
||||
|
||||
|
||||
/* calculate number of used MLT/QMF bands according to the amount of coded
|
||||
spectral lines */
|
||||
num_bands = (subband_tab[num_subbands] - 1) >> 8;
|
||||
if (last_tonal >= 0)
|
||||
num_bands = FFMAX((last_tonal + 256) >> 8, num_bands);
|
||||
|
||||
|
||||
/* Reconstruct time domain samples. */
|
||||
for (band = 0; band < 4; band++) {
|
||||
/* Perform the IMDCT step without overlapping. */
|
||||
if (band <= num_bands)
|
||||
imlt(q, &snd->spectrum[band * 256], snd->imdct_buf, band & 1);
|
||||
else
|
||||
memset(snd->imdct_buf, 0, 512 * sizeof(*snd->imdct_buf));
|
||||
|
||||
/* gain compensation and overlapping */
|
||||
ff_atrac_gain_compensation(&q->gainc_ctx, snd->imdct_buf,
|
||||
&snd->prev_frame[band * 256],
|
||||
&gain1->g_block[band], &gain2->g_block[band],
|
||||
256, &output[band * 256]);
|
||||
}
|
||||
|
||||
/* Swap the gain control buffers for the next frame. */
|
||||
snd->gc_blk_switch ^= 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
|
||||
float **out_samples)
|
||||
{
|
||||
ATRAC3Context *q = avctx->priv_data;
|
||||
int ret, i;
|
||||
uint8_t *ptr1;
|
||||
|
||||
if (q->coding_mode == JOINT_STEREO) {
|
||||
/* channel coupling mode */
|
||||
/* decode Sound Unit 1 */
|
||||
init_get_bits(&q->gb, databuf, avctx->block_align * 8);
|
||||
|
||||
ret = decode_channel_sound_unit(q, &q->gb, q->units, out_samples[0], 0,
|
||||
JOINT_STEREO);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
/* Framedata of the su2 in the joint-stereo mode is encoded in
|
||||
* reverse byte order so we need to swap it first. */
|
||||
if (databuf == q->decoded_bytes_buffer) {
|
||||
uint8_t *ptr2 = q->decoded_bytes_buffer + avctx->block_align - 1;
|
||||
ptr1 = q->decoded_bytes_buffer;
|
||||
for (i = 0; i < avctx->block_align / 2; i++, ptr1++, ptr2--)
|
||||
FFSWAP(uint8_t, *ptr1, *ptr2);
|
||||
} else {
|
||||
const uint8_t *ptr2 = databuf + avctx->block_align - 1;
|
||||
for (i = 0; i < avctx->block_align; i++)
|
||||
q->decoded_bytes_buffer[i] = *ptr2--;
|
||||
}
|
||||
|
||||
/* Skip the sync codes (0xF8). */
|
||||
ptr1 = q->decoded_bytes_buffer;
|
||||
for (i = 4; *ptr1 == 0xF8; i++, ptr1++) {
|
||||
if (i >= avctx->block_align)
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
|
||||
/* set the bitstream reader at the start of the second Sound Unit*/
|
||||
init_get_bits8(&q->gb, ptr1, q->decoded_bytes_buffer + avctx->block_align - ptr1);
|
||||
|
||||
/* Fill the Weighting coeffs delay buffer */
|
||||
memmove(q->weighting_delay, &q->weighting_delay[2],
|
||||
4 * sizeof(*q->weighting_delay));
|
||||
q->weighting_delay[4] = get_bits1(&q->gb);
|
||||
q->weighting_delay[5] = get_bits(&q->gb, 3);
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
q->matrix_coeff_index_prev[i] = q->matrix_coeff_index_now[i];
|
||||
q->matrix_coeff_index_now[i] = q->matrix_coeff_index_next[i];
|
||||
q->matrix_coeff_index_next[i] = get_bits(&q->gb, 2);
|
||||
}
|
||||
|
||||
/* Decode Sound Unit 2. */
|
||||
ret = decode_channel_sound_unit(q, &q->gb, &q->units[1],
|
||||
out_samples[1], 1, JOINT_STEREO);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
/* Reconstruct the channel coefficients. */
|
||||
reverse_matrixing(out_samples[0], out_samples[1],
|
||||
q->matrix_coeff_index_prev,
|
||||
q->matrix_coeff_index_now);
|
||||
|
||||
channel_weighting(out_samples[0], out_samples[1], q->weighting_delay);
|
||||
} else {
|
||||
/* normal stereo mode or mono */
|
||||
/* Decode the channel sound units. */
|
||||
for (i = 0; i < avctx->channels; i++) {
|
||||
/* Set the bitstream reader at the start of a channel sound unit. */
|
||||
init_get_bits(&q->gb,
|
||||
databuf + i * avctx->block_align / avctx->channels,
|
||||
avctx->block_align * 8 / avctx->channels);
|
||||
|
||||
ret = decode_channel_sound_unit(q, &q->gb, &q->units[i],
|
||||
out_samples[i], i, q->coding_mode);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* Apply the iQMF synthesis filter. */
|
||||
for (i = 0; i < avctx->channels; i++) {
|
||||
float *p1 = out_samples[i];
|
||||
float *p2 = p1 + 256;
|
||||
float *p3 = p2 + 256;
|
||||
float *p4 = p3 + 256;
|
||||
ff_atrac_iqmf(p1, p2, 256, p1, q->units[i].delay_buf1, q->temp_buf);
|
||||
ff_atrac_iqmf(p4, p3, 256, p3, q->units[i].delay_buf2, q->temp_buf);
|
||||
ff_atrac_iqmf(p1, p3, 512, p1, q->units[i].delay_buf3, q->temp_buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int atrac3_decode_frame(AVCodecContext *avctx, void *data,
|
||||
int *got_frame_ptr, AVPacket *avpkt)
|
||||
{
|
||||
AVFrame *frame = data;
|
||||
const uint8_t *buf = avpkt->data;
|
||||
int buf_size = avpkt->size;
|
||||
ATRAC3Context *q = avctx->priv_data;
|
||||
int ret;
|
||||
const uint8_t *databuf;
|
||||
|
||||
if (buf_size < avctx->block_align) {
|
||||
av_log(avctx, AV_LOG_ERROR,
|
||||
"Frame too small (%d bytes). Truncated file?\n", buf_size);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
/* get output buffer */
|
||||
frame->nb_samples = SAMPLES_PER_FRAME;
|
||||
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
|
||||
return ret;
|
||||
|
||||
/* Check if we need to descramble and what buffer to pass on. */
|
||||
if (q->scrambled_stream) {
|
||||
decode_bytes(buf, q->decoded_bytes_buffer, avctx->block_align);
|
||||
databuf = q->decoded_bytes_buffer;
|
||||
} else {
|
||||
databuf = buf;
|
||||
}
|
||||
|
||||
ret = decode_frame(avctx, databuf, (float **)frame->extended_data);
|
||||
if (ret) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Frame decoding error!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
*got_frame_ptr = 1;
|
||||
|
||||
return avctx->block_align;
|
||||
}
|
||||
|
||||
static av_cold void atrac3_init_static_data(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
init_imdct_window();
|
||||
ff_atrac_generate_tables();
|
||||
|
||||
/* Initialize the VLC tables. */
|
||||
for (i = 0; i < 7; i++) {
|
||||
spectral_coeff_tab[i].table = &atrac3_vlc_table[atrac3_vlc_offs[i]];
|
||||
spectral_coeff_tab[i].table_allocated = atrac3_vlc_offs[i + 1] -
|
||||
atrac3_vlc_offs[i ];
|
||||
init_vlc(&spectral_coeff_tab[i], 9, huff_tab_sizes[i],
|
||||
huff_bits[i], 1, 1,
|
||||
huff_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
|
||||
}
|
||||
}
|
||||
|
||||
static av_cold int atrac3_decode_init(AVCodecContext *avctx)
|
||||
{
|
||||
static int static_init_done;
|
||||
int i, ret;
|
||||
int version, delay, samples_per_frame, frame_factor;
|
||||
const uint8_t *edata_ptr = avctx->extradata;
|
||||
ATRAC3Context *q = avctx->priv_data;
|
||||
|
||||
if (avctx->channels <= 0 || avctx->channels > 2) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Channel configuration error!\n");
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
|
||||
if (!static_init_done)
|
||||
atrac3_init_static_data();
|
||||
static_init_done = 1;
|
||||
|
||||
/* Take care of the codec-specific extradata. */
|
||||
if (avctx->extradata_size == 14) {
|
||||
/* Parse the extradata, WAV format */
|
||||
av_log(avctx, AV_LOG_DEBUG, "[0-1] %d\n",
|
||||
bytestream_get_le16(&edata_ptr)); // Unknown value always 1
|
||||
edata_ptr += 4; // samples per channel
|
||||
q->coding_mode = bytestream_get_le16(&edata_ptr);
|
||||
av_log(avctx, AV_LOG_DEBUG,"[8-9] %d\n",
|
||||
bytestream_get_le16(&edata_ptr)); //Dupe of coding mode
|
||||
frame_factor = bytestream_get_le16(&edata_ptr); // Unknown always 1
|
||||
av_log(avctx, AV_LOG_DEBUG,"[12-13] %d\n",
|
||||
bytestream_get_le16(&edata_ptr)); // Unknown always 0
|
||||
|
||||
/* setup */
|
||||
samples_per_frame = SAMPLES_PER_FRAME * avctx->channels;
|
||||
version = 4;
|
||||
delay = 0x88E;
|
||||
q->coding_mode = q->coding_mode ? JOINT_STEREO : STEREO;
|
||||
q->scrambled_stream = 0;
|
||||
|
||||
if (avctx->block_align != 96 * avctx->channels * frame_factor &&
|
||||
avctx->block_align != 152 * avctx->channels * frame_factor &&
|
||||
avctx->block_align != 192 * avctx->channels * frame_factor) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Unknown frame/channel/frame_factor "
|
||||
"configuration %d/%d/%d\n", avctx->block_align,
|
||||
avctx->channels, frame_factor);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
} else if (avctx->extradata_size == 12 || avctx->extradata_size == 10) {
|
||||
/* Parse the extradata, RM format. */
|
||||
version = bytestream_get_be32(&edata_ptr);
|
||||
samples_per_frame = bytestream_get_be16(&edata_ptr);
|
||||
delay = bytestream_get_be16(&edata_ptr);
|
||||
q->coding_mode = bytestream_get_be16(&edata_ptr);
|
||||
q->scrambled_stream = 1;
|
||||
|
||||
} else {
|
||||
av_log(NULL, AV_LOG_ERROR, "Unknown extradata size %d.\n",
|
||||
avctx->extradata_size);
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
|
||||
/* Check the extradata */
|
||||
|
||||
if (version != 4) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Version %d != 4.\n", version);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (samples_per_frame != SAMPLES_PER_FRAME &&
|
||||
samples_per_frame != SAMPLES_PER_FRAME * 2) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Unknown amount of samples per frame %d.\n",
|
||||
samples_per_frame);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (delay != 0x88E) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Unknown amount of delay %x != 0x88E.\n",
|
||||
delay);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (q->coding_mode == STEREO)
|
||||
av_log(avctx, AV_LOG_DEBUG, "Normal stereo detected.\n");
|
||||
else if (q->coding_mode == JOINT_STEREO) {
|
||||
if (avctx->channels != 2) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Invalid coding mode\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
av_log(avctx, AV_LOG_DEBUG, "Joint stereo detected.\n");
|
||||
} else {
|
||||
av_log(avctx, AV_LOG_ERROR, "Unknown channel coding mode %x!\n",
|
||||
q->coding_mode);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (avctx->block_align >= UINT_MAX / 2)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
q->decoded_bytes_buffer = av_mallocz(FFALIGN(avctx->block_align, 4) +
|
||||
FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
if (q->decoded_bytes_buffer == NULL)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
|
||||
|
||||
/* initialize the MDCT transform */
|
||||
if ((ret = ff_mdct_init(&q->mdct_ctx, 9, 1, 1.0 / 32768)) < 0) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Error initializing MDCT\n");
|
||||
av_freep(&q->decoded_bytes_buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* init the joint-stereo decoding data */
|
||||
q->weighting_delay[0] = 0;
|
||||
q->weighting_delay[1] = 7;
|
||||
q->weighting_delay[2] = 0;
|
||||
q->weighting_delay[3] = 7;
|
||||
q->weighting_delay[4] = 0;
|
||||
q->weighting_delay[5] = 7;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
q->matrix_coeff_index_prev[i] = 3;
|
||||
q->matrix_coeff_index_now[i] = 3;
|
||||
q->matrix_coeff_index_next[i] = 3;
|
||||
}
|
||||
|
||||
ff_atrac_init_gain_compensation(&q->gainc_ctx, 4, 3);
|
||||
avpriv_float_dsp_init(&q->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
|
||||
ff_fmt_convert_init(&q->fmt_conv, avctx);
|
||||
|
||||
q->units = av_mallocz(sizeof(*q->units) * avctx->channels);
|
||||
if (!q->units) {
|
||||
atrac3_decode_close(avctx);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
AVCodec ff_atrac3_decoder = {
|
||||
.name = "atrac3",
|
||||
.long_name = NULL_IF_CONFIG_SMALL("ATRAC3 (Adaptive TRansform Acoustic Coding 3)"),
|
||||
.type = AVMEDIA_TYPE_AUDIO,
|
||||
.id = AV_CODEC_ID_ATRAC3,
|
||||
.priv_data_size = sizeof(ATRAC3Context),
|
||||
.init = atrac3_decode_init,
|
||||
.close = atrac3_decode_close,
|
||||
.decode = atrac3_decode_frame,
|
||||
.capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1,
|
||||
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
|
||||
AV_SAMPLE_FMT_NONE },
|
||||
};
|
|
@ -1,141 +0,0 @@
|
|||
/*
|
||||
* ATRAC3 compatible decoder data
|
||||
* Copyright (c) 2006-2007 Maxim Poliakovski
|
||||
* Copyright (c) 2006-2007 Benjamin Larsson
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* ATRAC3 AKA RealAudio 8 compatible decoder data
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_ATRAC3DATA_H
|
||||
#define AVCODEC_ATRAC3DATA_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* VLC tables */
|
||||
|
||||
static const uint8_t huffcode1[9] = {
|
||||
0x0, 0x4, 0x5, 0xC, 0xD, 0x1C, 0x1D, 0x1E, 0x1F
|
||||
};
|
||||
|
||||
static const uint8_t huffbits1[9] = { 1, 3, 3, 4, 4, 5, 5, 5, 5 };
|
||||
|
||||
static const uint8_t huffcode2[5] = { 0x0, 0x4, 0x5, 0x6, 0x7 };
|
||||
|
||||
static const uint8_t huffbits2[5] = { 1, 3, 3, 3, 3 };
|
||||
|
||||
static const uint8_t huffcode3[7] = { 0x0, 0x4, 0x5, 0xC, 0xD, 0xE, 0xF };
|
||||
|
||||
static const uint8_t huffbits3[7] = { 1, 3, 3, 4, 4, 4, 4 };
|
||||
|
||||
static const uint8_t huffcode4[9] = {
|
||||
0x0, 0x4, 0x5, 0xC, 0xD, 0x1C, 0x1D, 0x1E, 0x1F
|
||||
};
|
||||
|
||||
static const uint8_t huffbits4[9] = { 1, 3, 3, 4, 4, 5, 5, 5, 5 };
|
||||
|
||||
static const uint8_t huffcode5[15] = {
|
||||
0x00, 0x02, 0x03, 0x08, 0x09, 0x0A, 0x0B, 0x1C,
|
||||
0x1D, 0x3C, 0x3D, 0x3E, 0x3F, 0x0C, 0x0D
|
||||
};
|
||||
|
||||
static const uint8_t huffbits5[15] = {
|
||||
2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6, 4, 4
|
||||
};
|
||||
|
||||
static const uint8_t huffcode6[31] = {
|
||||
0x00, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x14,
|
||||
0x15, 0x16, 0x17, 0x18, 0x19, 0x34, 0x35, 0x36,
|
||||
0x37, 0x38, 0x39, 0x3A, 0x3B, 0x78, 0x79, 0x7A,
|
||||
0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x08, 0x09
|
||||
};
|
||||
|
||||
static const uint8_t huffbits6[31] = {
|
||||
3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 4, 4
|
||||
};
|
||||
|
||||
static const uint8_t huffcode7[63] = {
|
||||
0x00, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
|
||||
0x0F, 0x10, 0x11, 0x24, 0x25, 0x26, 0x27, 0x28,
|
||||
0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
|
||||
0x31, 0x32, 0x33, 0x68, 0x69, 0x6A, 0x6B, 0x6C,
|
||||
0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
|
||||
0x75, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2,
|
||||
0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA,
|
||||
0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x02, 0x03
|
||||
};
|
||||
|
||||
static const uint8_t huffbits7[63] = {
|
||||
3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4
|
||||
};
|
||||
|
||||
static const uint8_t huff_tab_sizes[7] = {
|
||||
9, 5, 7, 9, 15, 31, 63,
|
||||
};
|
||||
|
||||
static const uint8_t* const huff_codes[7] = {
|
||||
huffcode1, huffcode2, huffcode3, huffcode4, huffcode5, huffcode6, huffcode7
|
||||
};
|
||||
|
||||
static const uint8_t* const huff_bits[7] = {
|
||||
huffbits1, huffbits2, huffbits3, huffbits4, huffbits5, huffbits6, huffbits7,
|
||||
};
|
||||
|
||||
static const uint16_t atrac3_vlc_offs[9] = {
|
||||
0, 512, 1024, 1536, 2048, 2560, 3072, 3584, 4096
|
||||
};
|
||||
|
||||
/* selector tables */
|
||||
|
||||
static const uint8_t clc_length_tab[8] = { 0, 4, 3, 3, 4, 4, 5, 6 };
|
||||
|
||||
static const int8_t mantissa_clc_tab[4] = { 0, 1, -2, -1 };
|
||||
|
||||
static const int8_t mantissa_vlc_tab[18] = {
|
||||
0, 0, 0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1
|
||||
};
|
||||
|
||||
|
||||
/* tables for the scalefactor decoding */
|
||||
|
||||
static const float inv_max_quant[8] = {
|
||||
0.0, 1.0 / 1.5, 1.0 / 2.5, 1.0 / 3.5,
|
||||
1.0 / 4.5, 1.0 / 7.5, 1.0 / 15.5, 1.0 / 31.5
|
||||
};
|
||||
|
||||
static const uint16_t subband_tab[33] = {
|
||||
0, 8, 16, 24, 32, 40, 48, 56,
|
||||
64, 80, 96, 112, 128, 144, 160, 176,
|
||||
192, 224, 256, 288, 320, 352, 384, 416,
|
||||
448, 480, 512, 576, 640, 704, 768, 896,
|
||||
1024
|
||||
};
|
||||
|
||||
/* joint stereo related tables */
|
||||
static const float matrix_coeffs[8] = {
|
||||
0.0, 2.0, 2.0, 2.0, 0.0, 0.0, 1.0, 1.0
|
||||
};
|
||||
|
||||
#endif /* AVCODEC_ATRAC3DATA_H */
|
File diff suppressed because it is too large
Load diff
|
@ -1,240 +0,0 @@
|
|||
/*
|
||||
* ATRAC3+ compatible decoder
|
||||
*
|
||||
* Copyright (c) 2010-2013 Maxim Poliakovski
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Global structures, constants and data for ATRAC3+ decoder.
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_ATRAC3PLUS_H
|
||||
#define AVCODEC_ATRAC3PLUS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libavutil/float_dsp.h"
|
||||
#include "atrac.h"
|
||||
#include "avcodec.h"
|
||||
#include "fft.h"
|
||||
#include "get_bits.h"
|
||||
|
||||
/** Global unit sizes */
|
||||
#define ATRAC3P_SUBBANDS 16 ///< number of PQF subbands
|
||||
#define ATRAC3P_SUBBAND_SAMPLES 128 ///< number of samples per subband
|
||||
#define ATRAC3P_FRAME_SAMPLES (ATRAC3P_SUBBAND_SAMPLES * ATRAC3P_SUBBANDS)
|
||||
|
||||
#define ATRAC3P_PQF_FIR_LEN 12 ///< length of the prototype FIR of the PQF
|
||||
|
||||
/** Global constants */
|
||||
#define ATRAC3P_POWER_COMP_OFF 15 ///< disable power compensation
|
||||
|
||||
/** ATRAC3+ channel unit types */
|
||||
enum Atrac3pChannelUnitTypes {
|
||||
CH_UNIT_MONO = 0, ///< unit containing one coded channel
|
||||
CH_UNIT_STEREO = 1, ///< unit containing two jointly-coded channels
|
||||
CH_UNIT_EXTENSION = 2, ///< unit containing extension information
|
||||
CH_UNIT_TERMINATOR = 3 ///< unit sequence terminator
|
||||
};
|
||||
|
||||
/** Per-channel IPQF history */
|
||||
typedef struct Atrac3pIPQFChannelCtx {
|
||||
DECLARE_ALIGNED(32, float, buf1)[ATRAC3P_PQF_FIR_LEN * 2][8];
|
||||
DECLARE_ALIGNED(32, float, buf2)[ATRAC3P_PQF_FIR_LEN * 2][8];
|
||||
int pos;
|
||||
} Atrac3pIPQFChannelCtx;
|
||||
|
||||
/** Amplitude envelope of a group of sine waves */
|
||||
typedef struct Atrac3pWaveEnvelope {
|
||||
int has_start_point; ///< indicates start point within the GHA window
|
||||
int has_stop_point; ///< indicates stop point within the GHA window
|
||||
int start_pos; ///< start position expressed in n*4 samples
|
||||
int stop_pos; ///< stop position expressed in n*4 samples
|
||||
} Atrac3pWaveEnvelope;
|
||||
|
||||
/** Parameters of a group of sine waves */
|
||||
typedef struct Atrac3pWavesData {
|
||||
Atrac3pWaveEnvelope pend_env; ///< pending envelope from the previous frame
|
||||
Atrac3pWaveEnvelope curr_env; ///< group envelope from the current frame
|
||||
int num_wavs; ///< number of sine waves in the group
|
||||
int start_index; ///< start index into global tones table for that subband
|
||||
} Atrac3pWavesData;
|
||||
|
||||
/** Parameters of a single sine wave */
|
||||
typedef struct Atrac3pWaveParam {
|
||||
int freq_index; ///< wave frequency index
|
||||
int amp_sf; ///< quantized amplitude scale factor
|
||||
int amp_index; ///< quantized amplitude index
|
||||
int phase_index; ///< quantized phase index
|
||||
} Atrac3pWaveParam;
|
||||
|
||||
/** Sound channel parameters */
|
||||
typedef struct Atrac3pChanParams {
|
||||
int ch_num;
|
||||
int num_coded_vals; ///< number of transmitted quant unit values
|
||||
int fill_mode;
|
||||
int split_point;
|
||||
int table_type; ///< table type: 0 - tone?, 1- noise?
|
||||
int qu_wordlen[32]; ///< array of word lengths for each quant unit
|
||||
int qu_sf_idx[32]; ///< array of scale factor indexes for each quant unit
|
||||
int qu_tab_idx[32]; ///< array of code table indexes for each quant unit
|
||||
int16_t spectrum[2048]; ///< decoded IMDCT spectrum
|
||||
uint8_t power_levs[5]; ///< power compensation levels
|
||||
|
||||
/* imdct window shape history (2 frames) for overlapping. */
|
||||
uint8_t wnd_shape_hist[2][ATRAC3P_SUBBANDS]; ///< IMDCT window shape, 0=sine/1=steep
|
||||
uint8_t *wnd_shape; ///< IMDCT window shape for current frame
|
||||
uint8_t *wnd_shape_prev; ///< IMDCT window shape for previous frame
|
||||
|
||||
/* gain control data history (2 frames) for overlapping. */
|
||||
AtracGainInfo gain_data_hist[2][ATRAC3P_SUBBANDS]; ///< gain control data for all subbands
|
||||
AtracGainInfo *gain_data; ///< gain control data for next frame
|
||||
AtracGainInfo *gain_data_prev; ///< gain control data for previous frame
|
||||
int num_gain_subbands; ///< number of subbands with gain control data
|
||||
|
||||
/* tones data history (2 frames) for overlapping. */
|
||||
Atrac3pWavesData tones_info_hist[2][ATRAC3P_SUBBANDS];
|
||||
Atrac3pWavesData *tones_info;
|
||||
Atrac3pWavesData *tones_info_prev;
|
||||
} Atrac3pChanParams;
|
||||
|
||||
/* Per-unit sine wave parameters */
|
||||
typedef struct Atrac3pWaveSynthParams {
|
||||
int tones_present; ///< 1 - tones info present
|
||||
int amplitude_mode; ///< 1 - low range, 0 - high range
|
||||
int num_tone_bands; ///< number of PQF bands with tones
|
||||
uint8_t tone_sharing[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise tone sharing flags
|
||||
uint8_t tone_master[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise tone channel swapping
|
||||
uint8_t phase_shift[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise 180° phase shifting
|
||||
int tones_index; ///< total sum of tones in this unit
|
||||
Atrac3pWaveParam waves[48];
|
||||
} Atrac3pWaveSynthParams;
|
||||
|
||||
/** Channel unit parameters */
|
||||
typedef struct Atrac3pChanUnitCtx {
|
||||
/* channel unit variables */
|
||||
int unit_type; ///< unit type (mono/stereo)
|
||||
int num_quant_units;
|
||||
int num_subbands;
|
||||
int used_quant_units; ///< number of quant units with coded spectrum
|
||||
int num_coded_subbands; ///< number of subbands with coded spectrum
|
||||
int mute_flag; ///< mute flag
|
||||
int use_full_table; ///< 1 - full table list, 0 - restricted one
|
||||
int noise_present; ///< 1 - global noise info present
|
||||
int noise_level_index; ///< global noise level index
|
||||
int noise_table_index; ///< global noise RNG table index
|
||||
uint8_t swap_channels[ATRAC3P_SUBBANDS]; ///< 1 - perform subband-wise channel swapping
|
||||
uint8_t negate_coeffs[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise IMDCT coefficients negation
|
||||
Atrac3pChanParams channels[2];
|
||||
|
||||
/* Variables related to GHA tones */
|
||||
Atrac3pWaveSynthParams wave_synth_hist[2]; ///< waves synth history for two frames
|
||||
Atrac3pWaveSynthParams *waves_info;
|
||||
Atrac3pWaveSynthParams *waves_info_prev;
|
||||
|
||||
Atrac3pIPQFChannelCtx ipqf_ctx[2];
|
||||
DECLARE_ALIGNED(32, float, prev_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< overlapping buffer
|
||||
} Atrac3pChanUnitCtx;
|
||||
|
||||
/**
|
||||
* Initialize VLC tables for bitstream parsing.
|
||||
*/
|
||||
void ff_atrac3p_init_vlcs(void);
|
||||
|
||||
/**
|
||||
* Decode bitstream data of a channel unit.
|
||||
*
|
||||
* @param[in] gb the GetBit context
|
||||
* @param[in,out] ctx ptr to the channel unit context
|
||||
* @param[in] num_channels number of channels to process
|
||||
* @param[in] avctx ptr to the AVCodecContext
|
||||
* @return result code: 0 = OK, otherwise - error code
|
||||
*/
|
||||
int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
|
||||
int num_channels, AVCodecContext *avctx);
|
||||
|
||||
/**
|
||||
* Initialize IMDCT transform.
|
||||
*
|
||||
* @param[in] avctx ptr to the AVCodecContext
|
||||
* @param[in] mdct_ctx pointer to MDCT transform context
|
||||
*/
|
||||
void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx);
|
||||
|
||||
/**
|
||||
* Initialize sine waves synthesizer.
|
||||
*/
|
||||
void ff_atrac3p_init_wave_synth(void);
|
||||
|
||||
/**
|
||||
* Synthesize sine waves for a particular subband.
|
||||
*
|
||||
* @param[in] ch_unit pointer to the channel unit context
|
||||
* @param[in] fdsp pointer to float DSP context
|
||||
* @param[in] ch_num which channel to process
|
||||
* @param[in] sb which subband to process
|
||||
* @param[out] out receives processed data
|
||||
*/
|
||||
void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *fdsp,
|
||||
int ch_num, int sb, float *out);
|
||||
|
||||
/**
|
||||
* Perform power compensation aka noise dithering.
|
||||
*
|
||||
* @param[in] ctx ptr to the channel context
|
||||
* @param[in] ch_index which channel to process
|
||||
* @param[in,out] sp ptr to channel spectrum to process
|
||||
* @param[in] rng_index indicates which RNG table to use
|
||||
* @param[in] sb_num which subband to process
|
||||
*/
|
||||
void ff_atrac3p_power_compensation(Atrac3pChanUnitCtx *ctx, int ch_index,
|
||||
float *sp, int rng_index, int sb_num);
|
||||
|
||||
/**
|
||||
* Regular IMDCT and windowing without overlapping,
|
||||
* with spectrum reversal in the odd subbands.
|
||||
*
|
||||
* @param[in] fdsp pointer to float DSP context
|
||||
* @param[in] mdct_ctx pointer to MDCT transform context
|
||||
* @param[in] pIn float input
|
||||
* @param[out] pOut float output
|
||||
* @param[in] wind_id which MDCT window to apply
|
||||
* @param[in] sb subband number
|
||||
*/
|
||||
void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, FFTContext *mdct_ctx, float *pIn,
|
||||
float *pOut, int wind_id, int sb);
|
||||
|
||||
/**
|
||||
* Subband synthesis filter based on the polyphase quadrature (pseudo-QMF)
|
||||
* filter bank.
|
||||
*
|
||||
* @param[in] dct_ctx ptr to the pre-initialized IDCT context
|
||||
* @param[in,out] hist ptr to the filter history
|
||||
* @param[in] in input data to process
|
||||
* @param[out] out receives processed data
|
||||
*/
|
||||
void ff_atrac3p_ipqf(FFTContext *dct_ctx, Atrac3pIPQFChannelCtx *hist,
|
||||
const float *in, float *out);
|
||||
|
||||
extern const uint16_t ff_atrac3p_qu_to_spec_pos[33];
|
||||
extern const float ff_atrac3p_sf_tab[64];
|
||||
extern const float ff_atrac3p_mant_tab[8];
|
||||
|
||||
#endif /* AVCODEC_ATRAC3PLUS_H */
|
File diff suppressed because it is too large
Load diff
|
@ -1,396 +0,0 @@
|
|||
/*
|
||||
* ATRAC3+ compatible decoder
|
||||
*
|
||||
* Copyright (c) 2010-2013 Maxim Poliakovski
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Sony ATRAC3+ compatible decoder.
|
||||
*
|
||||
* Container formats used to store its data:
|
||||
* RIFF WAV (.at3) and Sony OpenMG (.oma, .aa3).
|
||||
*
|
||||
* Technical description of this codec can be found here:
|
||||
* http://wiki.multimedia.cx/index.php?title=ATRAC3plus
|
||||
*
|
||||
* Kudos to Benjamin Larsson and Michael Karcher
|
||||
* for their precious technical help!
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libavutil/channel_layout.h"
|
||||
#include "libavutil/float_dsp.h"
|
||||
#include "avcodec.h"
|
||||
#include "get_bits.h"
|
||||
#include "internal.h"
|
||||
#include "atrac.h"
|
||||
#include "atrac3plus.h"
|
||||
|
||||
typedef struct ATRAC3PContext {
|
||||
GetBitContext gb;
|
||||
AVFloatDSPContext fdsp;
|
||||
|
||||
DECLARE_ALIGNED(32, float, samples)[2][ATRAC3P_FRAME_SAMPLES]; ///< quantized MDCT spectrum
|
||||
DECLARE_ALIGNED(32, float, mdct_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< output of the IMDCT
|
||||
DECLARE_ALIGNED(32, float, time_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< output of the gain compensation
|
||||
DECLARE_ALIGNED(32, float, outp_buf)[2][ATRAC3P_FRAME_SAMPLES];
|
||||
|
||||
AtracGCContext gainc_ctx; ///< gain compensation context
|
||||
FFTContext mdct_ctx;
|
||||
FFTContext ipqf_dct_ctx; ///< IDCT context used by IPQF
|
||||
|
||||
Atrac3pChanUnitCtx *ch_units; ///< global channel units
|
||||
|
||||
int num_channel_blocks; ///< number of channel blocks
|
||||
uint8_t channel_blocks[5]; ///< channel configuration descriptor
|
||||
uint64_t my_channel_layout; ///< current channel layout
|
||||
} ATRAC3PContext;
|
||||
|
||||
static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
|
||||
{
|
||||
av_free(((ATRAC3PContext *)(avctx->priv_data))->ch_units);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static av_cold int set_channel_params(ATRAC3PContext *ctx,
|
||||
AVCodecContext *avctx)
|
||||
{
|
||||
memset(ctx->channel_blocks, 0, sizeof(ctx->channel_blocks));
|
||||
|
||||
switch (avctx->channels) {
|
||||
case 1:
|
||||
if (avctx->channel_layout != AV_CH_FRONT_LEFT)
|
||||
avctx->channel_layout = AV_CH_LAYOUT_MONO;
|
||||
|
||||
ctx->num_channel_blocks = 1;
|
||||
ctx->channel_blocks[0] = CH_UNIT_MONO;
|
||||
break;
|
||||
case 2:
|
||||
avctx->channel_layout = AV_CH_LAYOUT_STEREO;
|
||||
ctx->num_channel_blocks = 1;
|
||||
ctx->channel_blocks[0] = CH_UNIT_STEREO;
|
||||
break;
|
||||
case 3:
|
||||
avctx->channel_layout = AV_CH_LAYOUT_SURROUND;
|
||||
ctx->num_channel_blocks = 2;
|
||||
ctx->channel_blocks[0] = CH_UNIT_STEREO;
|
||||
ctx->channel_blocks[1] = CH_UNIT_MONO;
|
||||
break;
|
||||
case 4:
|
||||
avctx->channel_layout = AV_CH_LAYOUT_4POINT0;
|
||||
ctx->num_channel_blocks = 3;
|
||||
ctx->channel_blocks[0] = CH_UNIT_STEREO;
|
||||
ctx->channel_blocks[1] = CH_UNIT_MONO;
|
||||
ctx->channel_blocks[2] = CH_UNIT_MONO;
|
||||
break;
|
||||
case 6:
|
||||
avctx->channel_layout = AV_CH_LAYOUT_5POINT1_BACK;
|
||||
ctx->num_channel_blocks = 4;
|
||||
ctx->channel_blocks[0] = CH_UNIT_STEREO;
|
||||
ctx->channel_blocks[1] = CH_UNIT_MONO;
|
||||
ctx->channel_blocks[2] = CH_UNIT_STEREO;
|
||||
ctx->channel_blocks[3] = CH_UNIT_MONO;
|
||||
break;
|
||||
case 7:
|
||||
avctx->channel_layout = AV_CH_LAYOUT_6POINT1_BACK;
|
||||
ctx->num_channel_blocks = 5;
|
||||
ctx->channel_blocks[0] = CH_UNIT_STEREO;
|
||||
ctx->channel_blocks[1] = CH_UNIT_MONO;
|
||||
ctx->channel_blocks[2] = CH_UNIT_STEREO;
|
||||
ctx->channel_blocks[3] = CH_UNIT_MONO;
|
||||
ctx->channel_blocks[4] = CH_UNIT_MONO;
|
||||
break;
|
||||
case 8:
|
||||
avctx->channel_layout = AV_CH_LAYOUT_7POINT1;
|
||||
ctx->num_channel_blocks = 5;
|
||||
ctx->channel_blocks[0] = CH_UNIT_STEREO;
|
||||
ctx->channel_blocks[1] = CH_UNIT_MONO;
|
||||
ctx->channel_blocks[2] = CH_UNIT_STEREO;
|
||||
ctx->channel_blocks[3] = CH_UNIT_STEREO;
|
||||
ctx->channel_blocks[4] = CH_UNIT_MONO;
|
||||
break;
|
||||
default:
|
||||
av_log(avctx, AV_LOG_ERROR,
|
||||
"Unsupported channel count: %d!\n", avctx->channels);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static av_cold int atrac3p_decode_init(AVCodecContext *avctx)
|
||||
{
|
||||
ATRAC3PContext *ctx = avctx->priv_data;
|
||||
int i, ch, ret;
|
||||
|
||||
if (!avctx->block_align) {
|
||||
av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
|
||||
ff_atrac3p_init_vlcs();
|
||||
|
||||
avpriv_float_dsp_init(&ctx->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
|
||||
|
||||
/* initialize IPQF */
|
||||
ff_mdct_init(&ctx->ipqf_dct_ctx, 5, 1, 32.0 / 32768.0);
|
||||
|
||||
ff_atrac3p_init_imdct(avctx, &ctx->mdct_ctx);
|
||||
|
||||
ff_atrac_init_gain_compensation(&ctx->gainc_ctx, 6, 2);
|
||||
|
||||
ff_atrac3p_init_wave_synth();
|
||||
|
||||
if ((ret = set_channel_params(ctx, avctx)) < 0)
|
||||
return ret;
|
||||
|
||||
ctx->my_channel_layout = avctx->channel_layout;
|
||||
|
||||
ctx->ch_units = av_mallocz(sizeof(*ctx->ch_units) *
|
||||
ctx->num_channel_blocks);
|
||||
if (!ctx->ch_units) {
|
||||
atrac3p_decode_close(avctx);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
for (i = 0; i < ctx->num_channel_blocks; i++) {
|
||||
for (ch = 0; ch < 2; ch++) {
|
||||
ctx->ch_units[i].channels[ch].ch_num = ch;
|
||||
ctx->ch_units[i].channels[ch].wnd_shape = &ctx->ch_units[i].channels[ch].wnd_shape_hist[0][0];
|
||||
ctx->ch_units[i].channels[ch].wnd_shape_prev = &ctx->ch_units[i].channels[ch].wnd_shape_hist[1][0];
|
||||
ctx->ch_units[i].channels[ch].gain_data = &ctx->ch_units[i].channels[ch].gain_data_hist[0][0];
|
||||
ctx->ch_units[i].channels[ch].gain_data_prev = &ctx->ch_units[i].channels[ch].gain_data_hist[1][0];
|
||||
ctx->ch_units[i].channels[ch].tones_info = &ctx->ch_units[i].channels[ch].tones_info_hist[0][0];
|
||||
ctx->ch_units[i].channels[ch].tones_info_prev = &ctx->ch_units[i].channels[ch].tones_info_hist[1][0];
|
||||
}
|
||||
|
||||
ctx->ch_units[i].waves_info = &ctx->ch_units[i].wave_synth_hist[0];
|
||||
ctx->ch_units[i].waves_info_prev = &ctx->ch_units[i].wave_synth_hist[1];
|
||||
}
|
||||
|
||||
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void decode_residual_spectrum(Atrac3pChanUnitCtx *ctx,
|
||||
float out[2][ATRAC3P_FRAME_SAMPLES],
|
||||
int num_channels,
|
||||
AVCodecContext *avctx)
|
||||
{
|
||||
int i, sb, ch, qu, nspeclines, RNG_index;
|
||||
float *dst, q;
|
||||
int16_t *src;
|
||||
/* calculate RNG table index for each subband */
|
||||
int sb_RNG_index[ATRAC3P_SUBBANDS] = { 0 };
|
||||
|
||||
if (ctx->mute_flag) {
|
||||
for (ch = 0; ch < num_channels; ch++)
|
||||
memset(out[ch], 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out[ch]));
|
||||
return;
|
||||
}
|
||||
|
||||
for (qu = 0, RNG_index = 0; qu < ctx->used_quant_units; qu++)
|
||||
RNG_index += ctx->channels[0].qu_sf_idx[qu] +
|
||||
ctx->channels[1].qu_sf_idx[qu];
|
||||
|
||||
for (sb = 0; sb < ctx->num_coded_subbands; sb++, RNG_index += 128)
|
||||
sb_RNG_index[sb] = RNG_index & 0x3FC;
|
||||
|
||||
/* inverse quant and power compensation */
|
||||
for (ch = 0; ch < num_channels; ch++) {
|
||||
/* clear channel's residual spectrum */
|
||||
memset(out[ch], 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out[ch]));
|
||||
|
||||
for (qu = 0; qu < ctx->used_quant_units; qu++) {
|
||||
src = &ctx->channels[ch].spectrum[ff_atrac3p_qu_to_spec_pos[qu]];
|
||||
dst = &out[ch][ff_atrac3p_qu_to_spec_pos[qu]];
|
||||
nspeclines = ff_atrac3p_qu_to_spec_pos[qu + 1] -
|
||||
ff_atrac3p_qu_to_spec_pos[qu];
|
||||
|
||||
if (ctx->channels[ch].qu_wordlen[qu] > 0) {
|
||||
q = ff_atrac3p_sf_tab[ctx->channels[ch].qu_sf_idx[qu]] *
|
||||
ff_atrac3p_mant_tab[ctx->channels[ch].qu_wordlen[qu]];
|
||||
for (i = 0; i < nspeclines; i++)
|
||||
dst[i] = src[i] * q;
|
||||
}
|
||||
}
|
||||
|
||||
for (sb = 0; sb < ctx->num_coded_subbands; sb++)
|
||||
ff_atrac3p_power_compensation(ctx, ch, &out[ch][0],
|
||||
sb_RNG_index[sb], sb);
|
||||
}
|
||||
|
||||
if (ctx->unit_type == CH_UNIT_STEREO) {
|
||||
for (sb = 0; sb < ctx->num_coded_subbands; sb++) {
|
||||
if (ctx->swap_channels[sb]) {
|
||||
for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++)
|
||||
FFSWAP(float, out[0][sb * ATRAC3P_SUBBAND_SAMPLES + i],
|
||||
out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
|
||||
}
|
||||
|
||||
/* flip coefficients' sign if requested */
|
||||
if (ctx->negate_coeffs[sb])
|
||||
for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++)
|
||||
out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i] = -(out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void reconstruct_frame(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit,
|
||||
int num_channels, AVCodecContext *avctx)
|
||||
{
|
||||
int ch, sb;
|
||||
|
||||
for (ch = 0; ch < num_channels; ch++) {
|
||||
for (sb = 0; sb < ch_unit->num_subbands; sb++) {
|
||||
/* inverse transform and windowing */
|
||||
ff_atrac3p_imdct(&ctx->fdsp, &ctx->mdct_ctx,
|
||||
&ctx->samples[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
|
||||
&ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
|
||||
(ch_unit->channels[ch].wnd_shape_prev[sb] << 1) +
|
||||
ch_unit->channels[ch].wnd_shape[sb], sb);
|
||||
|
||||
/* gain compensation and overlapping */
|
||||
ff_atrac_gain_compensation(&ctx->gainc_ctx,
|
||||
&ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
|
||||
&ch_unit->prev_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
|
||||
&ch_unit->channels[ch].gain_data_prev[sb],
|
||||
&ch_unit->channels[ch].gain_data[sb],
|
||||
ATRAC3P_SUBBAND_SAMPLES,
|
||||
&ctx->time_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES]);
|
||||
}
|
||||
|
||||
/* zero unused subbands in both output and overlapping buffers */
|
||||
memset(&ch_unit->prev_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES],
|
||||
0,
|
||||
(ATRAC3P_SUBBANDS - ch_unit->num_subbands) *
|
||||
ATRAC3P_SUBBAND_SAMPLES *
|
||||
sizeof(ch_unit->prev_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES]));
|
||||
memset(&ctx->time_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES],
|
||||
0,
|
||||
(ATRAC3P_SUBBANDS - ch_unit->num_subbands) *
|
||||
ATRAC3P_SUBBAND_SAMPLES *
|
||||
sizeof(ctx->time_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES]));
|
||||
|
||||
/* resynthesize and add tonal signal */
|
||||
if (ch_unit->waves_info->tones_present ||
|
||||
ch_unit->waves_info_prev->tones_present) {
|
||||
for (sb = 0; sb < ch_unit->num_subbands; sb++)
|
||||
if (ch_unit->channels[ch].tones_info[sb].num_wavs ||
|
||||
ch_unit->channels[ch].tones_info_prev[sb].num_wavs) {
|
||||
ff_atrac3p_generate_tones(ch_unit, &ctx->fdsp, ch, sb,
|
||||
&ctx->time_buf[ch][sb * 128]);
|
||||
}
|
||||
}
|
||||
|
||||
/* subband synthesis and acoustic signal output */
|
||||
ff_atrac3p_ipqf(&ctx->ipqf_dct_ctx, &ch_unit->ipqf_ctx[ch],
|
||||
&ctx->time_buf[ch][0], &ctx->outp_buf[ch][0]);
|
||||
}
|
||||
|
||||
/* swap window shape and gain control buffers. */
|
||||
for (ch = 0; ch < num_channels; ch++) {
|
||||
FFSWAP(uint8_t *, ch_unit->channels[ch].wnd_shape,
|
||||
ch_unit->channels[ch].wnd_shape_prev);
|
||||
FFSWAP(AtracGainInfo *, ch_unit->channels[ch].gain_data,
|
||||
ch_unit->channels[ch].gain_data_prev);
|
||||
FFSWAP(Atrac3pWavesData *, ch_unit->channels[ch].tones_info,
|
||||
ch_unit->channels[ch].tones_info_prev);
|
||||
}
|
||||
|
||||
FFSWAP(Atrac3pWaveSynthParams *, ch_unit->waves_info, ch_unit->waves_info_prev);
|
||||
}
|
||||
|
||||
static int atrac3p_decode_frame(AVCodecContext *avctx, void *data,
|
||||
int *got_frame_ptr, AVPacket *avpkt)
|
||||
{
|
||||
ATRAC3PContext *ctx = avctx->priv_data;
|
||||
AVFrame *frame = data;
|
||||
int i, ret, ch_unit_id, ch_block = 0, out_ch_index = 0, channels_to_process;
|
||||
float **samples_p = (float **)frame->extended_data;
|
||||
|
||||
frame->nb_samples = ATRAC3P_FRAME_SAMPLES;
|
||||
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
|
||||
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = init_get_bits8(&ctx->gb, avpkt->data, avpkt->size)) < 0)
|
||||
return ret;
|
||||
|
||||
if (get_bits1(&ctx->gb)) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Invalid start bit!\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
while (get_bits_left(&ctx->gb) >= 2 &&
|
||||
(ch_unit_id = get_bits(&ctx->gb, 2)) != CH_UNIT_TERMINATOR) {
|
||||
if (ch_unit_id == CH_UNIT_EXTENSION) {
|
||||
avpriv_report_missing_feature(avctx, "Channel unit extension");
|
||||
return AVERROR_PATCHWELCOME;
|
||||
}
|
||||
if (ch_block >= ctx->num_channel_blocks ||
|
||||
ctx->channel_blocks[ch_block] != ch_unit_id) {
|
||||
av_log(avctx, AV_LOG_ERROR,
|
||||
"Frame data doesn't match channel configuration!\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
ctx->ch_units[ch_block].unit_type = ch_unit_id;
|
||||
channels_to_process = ch_unit_id + 1;
|
||||
|
||||
if ((ret = ff_atrac3p_decode_channel_unit(&ctx->gb,
|
||||
&ctx->ch_units[ch_block],
|
||||
channels_to_process,
|
||||
avctx)) < 0)
|
||||
return ret;
|
||||
|
||||
decode_residual_spectrum(&ctx->ch_units[ch_block], ctx->samples,
|
||||
channels_to_process, avctx);
|
||||
reconstruct_frame(ctx, &ctx->ch_units[ch_block],
|
||||
channels_to_process, avctx);
|
||||
|
||||
for (i = 0; i < channels_to_process; i++)
|
||||
memcpy(samples_p[out_ch_index + i], ctx->outp_buf[i],
|
||||
ATRAC3P_FRAME_SAMPLES * sizeof(**samples_p));
|
||||
|
||||
ch_block++;
|
||||
out_ch_index += channels_to_process;
|
||||
}
|
||||
|
||||
*got_frame_ptr = 1;
|
||||
|
||||
return avctx->block_align;
|
||||
}
|
||||
|
||||
AVCodec ff_atrac3p_decoder = {
|
||||
.name = "atrac3plus",
|
||||
.long_name = NULL_IF_CONFIG_SMALL("ATRAC3+ (Adaptive TRansform Acoustic Coding 3+)"),
|
||||
.type = AVMEDIA_TYPE_AUDIO,
|
||||
.id = AV_CODEC_ID_ATRAC3P,
|
||||
.priv_data_size = sizeof(ATRAC3PContext),
|
||||
.init = atrac3p_decode_init,
|
||||
.close = atrac3p_decode_close,
|
||||
.decode = atrac3p_decode_frame,
|
||||
};
|
|
@ -1,638 +0,0 @@
|
|||
/*
|
||||
* ATRAC3+ compatible decoder
|
||||
*
|
||||
* Copyright (c) 2010-2013 Maxim Poliakovski
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* DSP functions for ATRAC3+ decoder.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "libavutil/float_dsp.h"
|
||||
#include "avcodec.h"
|
||||
#include "sinewin.h"
|
||||
#include "fft.h"
|
||||
#include "atrac3plus.h"
|
||||
|
||||
/**
|
||||
* Map quant unit number to its position in the spectrum.
|
||||
* To get the number of spectral lines in each quant unit do the following:
|
||||
* num_specs = qu_to_spec_pos[i+1] - qu_to_spec_pos[i]
|
||||
*/
|
||||
const uint16_t ff_atrac3p_qu_to_spec_pos[33] = {
|
||||
0, 16, 32, 48, 64, 80, 96, 112,
|
||||
128, 160, 192, 224, 256, 288, 320, 352,
|
||||
384, 448, 512, 576, 640, 704, 768, 896,
|
||||
1024, 1152, 1280, 1408, 1536, 1664, 1792, 1920,
|
||||
2048
|
||||
};
|
||||
|
||||
/* Scalefactors table. */
|
||||
/* Approx. Equ: pow(2.0, (i - 16.0 + 0.501783948) / 3.0) */
|
||||
const float ff_atrac3p_sf_tab[64] = {
|
||||
0.027852058, 0.0350914, 0.044212341, 0.055704117, 0.0701828,
|
||||
0.088424683, 0.11140823, 0.1403656, 0.17684937, 0.22281647, 0.2807312, 0.35369873,
|
||||
0.44563293, 0.5614624, 0.70739746, 0.89126587, 1.1229248, 1.4147949, 1.7825317,
|
||||
2.2458496, 2.8295898, 3.5650635, 4.4916992, 5.6591797, 7.130127, 8.9833984,
|
||||
11.318359, 14.260254, 17.966797, 22.636719, 28.520508, 35.933594, 45.273438,
|
||||
57.041016, 71.867188, 90.546875, 114.08203, 143.73438, 181.09375, 228.16406,
|
||||
287.46875, 362.1875, 456.32812, 574.9375, 724.375, 912.65625, 1149.875,
|
||||
1448.75, 1825.3125, 2299.75, 2897.5, 3650.625, 4599.5, 5795.0,
|
||||
7301.25, 9199.0, 11590.0, 14602.5, 18398.0, 23180.0, 29205.0,
|
||||
36796.0, 46360.0, 58410.0
|
||||
};
|
||||
|
||||
/* Mantissa table. */
|
||||
/* pow(10, x * log10(2) + 0.05) / 2 / ([1,2,3,5,7,15,31] + 0.5) */
|
||||
const float ff_atrac3p_mant_tab[8] = {
|
||||
0.0,
|
||||
0.74801636,
|
||||
0.44882202,
|
||||
0.32058716,
|
||||
0.20400238,
|
||||
0.1496048,
|
||||
0.07239151,
|
||||
0.035619736
|
||||
};
|
||||
|
||||
#define ATRAC3P_MDCT_SIZE (ATRAC3P_SUBBAND_SAMPLES * 2)
|
||||
|
||||
av_cold void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx)
|
||||
{
|
||||
ff_init_ff_sine_windows(7);
|
||||
ff_init_ff_sine_windows(6);
|
||||
|
||||
/* Initialize the MDCT transform. */
|
||||
ff_mdct_init(mdct_ctx, 8, 1, -1.0);
|
||||
}
|
||||
|
||||
#define TWOPI (2 * M_PI)
|
||||
|
||||
#define DEQUANT_PHASE(ph) (((ph) & 0x1F) << 6)
|
||||
|
||||
static DECLARE_ALIGNED(32, float, sine_table)[2048]; ///< wave table
|
||||
static DECLARE_ALIGNED(32, float, hann_window)[256]; ///< Hann windowing function
|
||||
static float amp_sf_tab[64]; ///< scalefactors for quantized amplitudes
|
||||
|
||||
av_cold void ff_atrac3p_init_wave_synth(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* generate sine wave table */
|
||||
for (i = 0; i < 2048; i++)
|
||||
sine_table[i] = sin(TWOPI * i / 2048);
|
||||
|
||||
/* generate Hann window */
|
||||
for (i = 0; i < 256; i++)
|
||||
hann_window[i] = (1.0f - cos(TWOPI * i / 256.0f)) * 0.5f;
|
||||
|
||||
/* generate amplitude scalefactors table */
|
||||
for (i = 0; i < 64; i++)
|
||||
amp_sf_tab[i] = pow(2.0f, ((double)i - 3) / 4.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Synthesize sine waves according to given parameters.
|
||||
*
|
||||
* @param[in] synth_param ptr to common synthesis parameters
|
||||
* @param[in] waves_info parameters for each sine wave
|
||||
* @param[in] envelope envelope data for all waves in a group
|
||||
* @param[in] phase_shift flag indicates 180° phase shift
|
||||
* @param[in] reg_offset region offset for trimming envelope data
|
||||
* @param[out] out receives sythesized data
|
||||
*/
|
||||
static void waves_synth(Atrac3pWaveSynthParams *synth_param,
|
||||
Atrac3pWavesData *waves_info,
|
||||
Atrac3pWaveEnvelope *envelope,
|
||||
int phase_shift, int reg_offset, float *out)
|
||||
{
|
||||
int i, wn, inc, pos;
|
||||
double amp;
|
||||
Atrac3pWaveParam *wave_param = &synth_param->waves[waves_info->start_index];
|
||||
|
||||
for (wn = 0; wn < waves_info->num_wavs; wn++, wave_param++) {
|
||||
/* amplitude dequantization */
|
||||
amp = amp_sf_tab[wave_param->amp_sf] *
|
||||
(!synth_param->amplitude_mode
|
||||
? (wave_param->amp_index + 1) / 15.13f
|
||||
: 1.0f);
|
||||
|
||||
inc = wave_param->freq_index;
|
||||
pos = DEQUANT_PHASE(wave_param->phase_index) - (reg_offset ^ 128) * inc & 2047;
|
||||
|
||||
/* waveform generation */
|
||||
for (i = 0; i < 128; i++) {
|
||||
out[i] += sine_table[pos] * amp;
|
||||
pos = (pos + inc) & 2047;
|
||||
}
|
||||
}
|
||||
|
||||
/* fade in with steep Hann window if requested */
|
||||
if (envelope->has_start_point) {
|
||||
pos = (envelope->start_pos << 2) - reg_offset;
|
||||
if (pos > 0 && pos <= 128) {
|
||||
memset(out, 0, pos * sizeof(*out));
|
||||
if (!envelope->has_stop_point ||
|
||||
envelope->start_pos != envelope->stop_pos) {
|
||||
out[pos + 0] *= hann_window[0];
|
||||
out[pos + 1] *= hann_window[32];
|
||||
out[pos + 2] *= hann_window[64];
|
||||
out[pos + 3] *= hann_window[96];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* fade out with steep Hann window if requested */
|
||||
if (envelope->has_stop_point) {
|
||||
pos = (envelope->stop_pos + 1 << 2) - reg_offset;
|
||||
if (pos > 0 && pos <= 128) {
|
||||
out[pos - 4] *= hann_window[96];
|
||||
out[pos - 3] *= hann_window[64];
|
||||
out[pos - 2] *= hann_window[32];
|
||||
out[pos - 1] *= hann_window[0];
|
||||
memset(&out[pos], 0, (128 - pos) * sizeof(out[pos]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *fdsp,
|
||||
int ch_num, int sb, float *out)
|
||||
{
|
||||
DECLARE_ALIGNED(32, float, wavreg1)[128] = { 0 };
|
||||
DECLARE_ALIGNED(32, float, wavreg2)[128] = { 0 };
|
||||
int i, reg1_env_nonzero, reg2_env_nonzero;
|
||||
Atrac3pWavesData *tones_now = &ch_unit->channels[ch_num].tones_info_prev[sb];
|
||||
Atrac3pWavesData *tones_next = &ch_unit->channels[ch_num].tones_info[sb];
|
||||
|
||||
/* reconstruct full envelopes for both overlapping regions
|
||||
* from truncated bitstream data */
|
||||
if (tones_next->pend_env.has_start_point &&
|
||||
tones_next->pend_env.start_pos < tones_next->pend_env.stop_pos) {
|
||||
tones_next->curr_env.has_start_point = 1;
|
||||
tones_next->curr_env.start_pos = tones_next->pend_env.start_pos + 32;
|
||||
} else if (tones_now->pend_env.has_start_point) {
|
||||
tones_next->curr_env.has_start_point = 1;
|
||||
tones_next->curr_env.start_pos = tones_now->pend_env.start_pos;
|
||||
} else {
|
||||
tones_next->curr_env.has_start_point = 0;
|
||||
tones_next->curr_env.start_pos = 0;
|
||||
}
|
||||
|
||||
if (tones_now->pend_env.has_stop_point &&
|
||||
tones_now->pend_env.stop_pos >= tones_next->curr_env.start_pos) {
|
||||
tones_next->curr_env.has_stop_point = 1;
|
||||
tones_next->curr_env.stop_pos = tones_now->pend_env.stop_pos;
|
||||
} else if (tones_next->pend_env.has_stop_point) {
|
||||
tones_next->curr_env.has_stop_point = 1;
|
||||
tones_next->curr_env.stop_pos = tones_next->pend_env.stop_pos + 32;
|
||||
} else {
|
||||
tones_next->curr_env.has_stop_point = 0;
|
||||
tones_next->curr_env.stop_pos = 64;
|
||||
}
|
||||
|
||||
/* is the visible part of the envelope non-zero? */
|
||||
reg1_env_nonzero = (tones_now->curr_env.stop_pos < 32) ? 0 : 1;
|
||||
reg2_env_nonzero = (tones_next->curr_env.start_pos >= 32) ? 0 : 1;
|
||||
|
||||
/* synthesize waves for both overlapping regions */
|
||||
if (tones_now->num_wavs && reg1_env_nonzero)
|
||||
waves_synth(ch_unit->waves_info_prev, tones_now, &tones_now->curr_env,
|
||||
ch_unit->waves_info_prev->phase_shift[sb] & ch_num,
|
||||
128, wavreg1);
|
||||
|
||||
if (tones_next->num_wavs && reg2_env_nonzero)
|
||||
waves_synth(ch_unit->waves_info, tones_next, &tones_next->curr_env,
|
||||
ch_unit->waves_info->phase_shift[sb] & ch_num, 0, wavreg2);
|
||||
|
||||
/* Hann windowing for non-faded wave signals */
|
||||
if (tones_now->num_wavs && tones_next->num_wavs &&
|
||||
reg1_env_nonzero && reg2_env_nonzero) {
|
||||
fdsp->vector_fmul(wavreg1, wavreg1, &hann_window[128], 128);
|
||||
fdsp->vector_fmul(wavreg2, wavreg2, hann_window, 128);
|
||||
} else {
|
||||
if (tones_now->num_wavs && !tones_now->curr_env.has_stop_point)
|
||||
fdsp->vector_fmul(wavreg1, wavreg1, &hann_window[128], 128);
|
||||
|
||||
if (tones_next->num_wavs && !tones_next->curr_env.has_start_point)
|
||||
fdsp->vector_fmul(wavreg2, wavreg2, hann_window, 128);
|
||||
}
|
||||
|
||||
/* Overlap and add to residual */
|
||||
for (i = 0; i < 128; i++)
|
||||
out[i] += wavreg1[i] + wavreg2[i];
|
||||
}
|
||||
|
||||
static const int subband_to_powgrp[ATRAC3P_SUBBANDS] = {
|
||||
0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4
|
||||
};
|
||||
|
||||
/* noise table for power compensation */
|
||||
static const float noise_tab[1024] = {
|
||||
-0.01358032, -0.05593872, 0.01696777, -0.14871216, -0.26412964, -0.09893799, 0.25723267,
|
||||
0.02008057, -0.72235107, -0.44351196, -0.22985840, 0.16833496, 0.46902466, 0.05917358,
|
||||
-0.15179443, 0.41299438, -0.01287842, 0.13360596, 0.43557739, -0.09530640, -0.58422852,
|
||||
0.39266968, -0.08343506, -0.25604248, 0.22848511, 0.26013184, -0.65588379, 0.17288208,
|
||||
-0.08673096, -0.05203247, 0.07299805, -0.28665161, -0.35806274, 0.06552124, -0.09387207,
|
||||
0.21099854, -0.28347778, -0.72402954, 0.05050659, -0.10635376, -0.18853760, 0.29724121,
|
||||
0.20703125, -0.29791260, -0.37634277, 0.47970581, -0.09976196, 0.32641602, -0.29248047,
|
||||
-0.28237915, 0.26028442, -0.36157227, 0.22042847, -0.03222656, -0.37268066, -0.03759766,
|
||||
0.09909058, 0.23284912, 0.19320679, 0.14453125, -0.02139282, -0.19702148, 0.31533813,
|
||||
-0.16741943, 0.35031128, -0.35656738, -0.66128540, -0.00701904, 0.20898438, 0.26837158,
|
||||
-0.33706665, -0.04568481, 0.12600708, 0.10284424, 0.07321167, -0.18280029, 0.38101196,
|
||||
0.21301270, 0.04541016, 0.01156616, -0.26391602, -0.02346802, -0.22125244, 0.29760742,
|
||||
-0.36233521, -0.31314087, -0.13967896, -0.11276245, -0.19433594, 0.34490967, 0.02343750,
|
||||
0.21963501, -0.02777100, -0.67678833, -0.08999634, 0.14233398, -0.27697754, 0.51422119,
|
||||
-0.05047607, 0.48327637, 0.37167358, -0.60806274, 0.18728638, -0.15191650, 0.00637817,
|
||||
0.02832031, -0.15618896, 0.60644531, 0.21826172, 0.06384277, -0.31863403, 0.08816528,
|
||||
0.15447998, -0.07015991, -0.08154297, -0.40966797, -0.39785767, -0.11709595, 0.22052002,
|
||||
0.18466187, -0.17257690, 0.03759766, -0.06195068, 0.00433350, 0.12176514, 0.34011841,
|
||||
0.25610352, -0.05294800, 0.41033936, 0.16854858, -0.76187134, 0.13845825, -0.19418335,
|
||||
-0.21524048, -0.44412231, -0.08160400, -0.28195190, -0.01873779, 0.15524292, -0.37438965,
|
||||
-0.44860840, 0.43096924, -0.24746704, 0.49856567, 0.14859009, 0.38159180, 0.20541382,
|
||||
-0.39175415, -0.65850830, -0.43716431, 0.13037109, -0.05111694, 0.39956665, 0.21447754,
|
||||
-0.04861450, 0.33654785, 0.10589600, -0.88085938, -0.30822754, 0.38577271, 0.30047607,
|
||||
0.38836670, 0.09118652, -0.36477661, -0.01641846, -0.23031616, 0.26058960, 0.18859863,
|
||||
-0.21868896, -0.17861938, -0.29754639, 0.09777832, 0.10806274, -0.51605225, 0.00076294,
|
||||
0.13259888, 0.11090088, -0.24084473, 0.24957275, 0.01379395, -0.04141235, -0.04937744,
|
||||
0.57394409, 0.27410889, 0.27587891, 0.45013428, -0.32592773, 0.11160278, -0.00970459,
|
||||
0.29092407, 0.03356934, -0.70925903, 0.04882812, 0.43499756, 0.07720947, -0.27554321,
|
||||
-0.01742554, -0.08413696, -0.04028320, -0.52850342, -0.07330322, 0.05181885, 0.21362305,
|
||||
-0.18765259, 0.07058716, -0.03009033, 0.32662964, 0.27023315, -0.28002930, 0.17568970,
|
||||
0.03338623, 0.30242920, -0.03921509, 0.32174683, -0.23733521, 0.08575439, -0.38269043,
|
||||
0.09194946, -0.07238770, 0.17941284, -0.51278687, -0.25146484, 0.19790649, -0.19195557,
|
||||
0.16549683, 0.42456055, 0.39129639, -0.02868652, 0.17980957, 0.24902344, -0.76583862,
|
||||
-0.20959473, 0.61013794, 0.37011719, 0.36859131, -0.04486084, 0.10678101, -0.15994263,
|
||||
-0.05328369, 0.28463745, -0.06420898, -0.36987305, -0.28009033, -0.11764526, 0.04312134,
|
||||
-0.08038330, 0.04885864, -0.03067017, -0.00042725, 0.34289551, -0.00988770, 0.34838867,
|
||||
0.32516479, -0.16271973, 0.38269043, 0.03240967, 0.12417603, -0.14331055, -0.34902954,
|
||||
-0.18325806, 0.29421997, 0.44284058, 0.75170898, -0.67245483, -0.12176514, 0.27914429,
|
||||
-0.29806519, 0.19863892, 0.30087280, 0.22680664, -0.36633301, -0.32534790, -0.57553101,
|
||||
-0.16641235, 0.43811035, 0.08331299, 0.15942383, 0.26516724, -0.24240112, -0.11761475,
|
||||
-0.16827393, -0.14260864, 0.46343994, 0.11804199, -0.55514526, -0.02520752, -0.14309692,
|
||||
0.00448608, 0.02749634, -0.30545044, 0.70965576, 0.45108032, 0.66439819, -0.68255615,
|
||||
-0.12496948, 0.09146118, -0.21109009, -0.23791504, 0.79943848, -0.35205078, -0.24963379,
|
||||
0.18719482, -0.19079590, 0.07458496, 0.07623291, -0.28781128, -0.37121582, -0.19580078,
|
||||
-0.01773071, -0.16717529, 0.13040161, 0.14672852, 0.42379761, 0.03582764, 0.11431885,
|
||||
0.05145264, 0.44702148, 0.08963013, 0.01367188, -0.54519653, -0.12692261, 0.21176147,
|
||||
0.04925537, 0.30670166, -0.11029053, 0.19555664, -0.27740479, 0.23043823, 0.15554810,
|
||||
-0.19299316, -0.25729370, 0.17800903, -0.03579712, -0.05065918, -0.06933594, -0.09500122,
|
||||
-0.07821655, 0.23889160, -0.31900024, 0.03073120, -0.00415039, 0.61315918, 0.37176514,
|
||||
-0.13442993, -0.15536499, -0.19216919, -0.37899780, 0.19992065, 0.02630615, -0.12573242,
|
||||
0.25927734, -0.02447510, 0.29629517, -0.40731812, -0.17333984, 0.24310303, -0.10607910,
|
||||
0.14828491, 0.08792114, -0.18743896, -0.05572510, -0.04833984, 0.10473633, -0.29028320,
|
||||
-0.67687988, -0.28170776, -0.41687012, 0.05413818, -0.23284912, 0.09555054, -0.08969116,
|
||||
-0.15112305, 0.12738037, 0.35986328, 0.28948975, 0.30691528, 0.23956299, 0.06973267,
|
||||
-0.31198120, -0.18450928, 0.22280884, -0.21600342, 0.23522949, -0.61840820, -0.13012695,
|
||||
0.26412964, 0.47320557, -0.26440430, 0.38757324, 0.17352295, -0.26104736, -0.25866699,
|
||||
-0.12274170, -0.29733276, 0.07687378, 0.18588257, -0.08880615, 0.31185913, 0.05313110,
|
||||
-0.10885620, -0.14901733, -0.22323608, -0.08538818, 0.19812012, 0.19732666, -0.18927002,
|
||||
0.29058838, 0.25555420, -0.48599243, 0.18768311, 0.01345825, 0.34887695, 0.21530151,
|
||||
0.19857788, 0.18661499, -0.01394653, -0.09063721, -0.38781738, 0.27160645, -0.20379639,
|
||||
-0.32119751, -0.23889160, 0.27096558, 0.24951172, 0.07922363, 0.07479858, -0.50946045,
|
||||
0.10220337, 0.58364868, -0.19503784, -0.18560791, -0.01165771, 0.47195435, 0.22430420,
|
||||
-0.38635254, -0.03732300, -0.09179688, 0.06991577, 0.15106201, 0.20605469, -0.05969238,
|
||||
-0.41821289, 0.12231445, -0.04672241, -0.05117798, -0.11523438, -0.51849365, -0.04077148,
|
||||
0.44284058, -0.64086914, 0.17019653, 0.02236938, 0.22848511, -0.23214722, -0.32354736,
|
||||
-0.14068604, -0.29690552, -0.19891357, 0.02774048, -0.20965576, -0.52191162, -0.19299316,
|
||||
-0.07290649, 0.49053955, -0.22302246, 0.05642700, 0.13122559, -0.20819092, -0.83590698,
|
||||
-0.08181763, 0.26797485, -0.00091553, -0.09457397, 0.17089844, -0.27020264, 0.30270386,
|
||||
0.05496216, 0.09564209, -0.08590698, 0.02130127, 0.35931396, 0.21728516, -0.15396118,
|
||||
-0.05053711, 0.02719116, 0.16302490, 0.43212891, 0.10229492, -0.40820312, 0.21646118,
|
||||
0.08435059, -0.11145020, -0.39962769, -0.05618286, -0.10223389, -0.60839844, 0.33724976,
|
||||
-0.06341553, -0.47369385, -0.32852173, 0.05242920, 0.19635010, -0.19137573, -0.67901611,
|
||||
0.16180420, 0.05133057, -0.22283936, 0.09646606, 0.24288940, -0.45007324, 0.08804321,
|
||||
0.14053345, 0.22619629, -0.01000977, 0.36355591, -0.19863892, -0.30364990, -0.24118042,
|
||||
-0.57461548, 0.26498413, 0.04345703, -0.09796143, -0.47714233, -0.23739624, 0.18737793,
|
||||
0.08926392, -0.02795410, 0.00305176, -0.08700562, -0.38711548, 0.03222656, 0.10940552,
|
||||
-0.41906738, -0.01620483, -0.47061157, 0.37985229, -0.21624756, 0.47976685, -0.20046997,
|
||||
-0.62533569, -0.26907349, -0.02877808, 0.00671387, -0.29071045, -0.24685669, -0.15722656,
|
||||
-0.26055908, 0.29968262, 0.28225708, -0.08990479, -0.16748047, -0.46759033, -0.25067139,
|
||||
-0.25183105, -0.45932007, 0.05828857, 0.29006958, 0.23840332, -0.17974854, 0.26931763,
|
||||
0.10696411, -0.06848145, -0.17126465, -0.10522461, -0.55386353, -0.42306519, -0.07608032,
|
||||
0.24380493, 0.38586426, 0.16882324, 0.26751709, 0.17303467, 0.35809326, -0.22094727,
|
||||
-0.30703735, -0.28497314, -0.04321289, 0.15219116, -0.17071533, -0.39334106, 0.03439331,
|
||||
-0.10809326, -0.30590820, 0.26449585, -0.07412720, 0.13638306, -0.01062012, 0.27996826,
|
||||
0.04397583, -0.05557251, -0.56933594, 0.03363037, -0.00949097, 0.52642822, -0.44329834,
|
||||
0.28308105, -0.05499268, -0.23312378, -0.29870605, -0.05123901, 0.26831055, -0.35238647,
|
||||
-0.30993652, 0.34646606, -0.19775391, 0.44595337, 0.13769531, 0.45358276, 0.19961548,
|
||||
0.42681885, 0.15722656, 0.00128174, 0.23757935, 0.40988159, 0.25164795, -0.00732422,
|
||||
-0.12405396, -0.43420410, -0.00402832, 0.34243774, 0.36264038, 0.18807983, -0.09301758,
|
||||
-0.10296631, 0.05532837, -0.31652832, 0.14337158, 0.35040283, 0.32540894, 0.05728149,
|
||||
-0.12030029, -0.25942993, -0.20312500, -0.16491699, -0.46051025, -0.08004761, 0.50772095,
|
||||
0.16168213, 0.28439331, 0.08105469, -0.19104004, 0.38589478, -0.16400146, -0.25454712,
|
||||
0.20281982, -0.20730591, -0.06311035, 0.32937622, 0.15032959, -0.05340576, 0.30487061,
|
||||
-0.11648560, 0.38009644, -0.20062256, 0.43466187, 0.01150513, 0.35754395, -0.13146973,
|
||||
0.67489624, 0.05212402, 0.27914429, -0.39431763, 0.75308228, -0.13366699, 0.24453735,
|
||||
0.42248535, -0.65905762, -0.00546265, -0.03491211, -0.13659668, -0.08294678, -0.45666504,
|
||||
0.27188110, 0.12731934, 0.61148071, 0.10449219, -0.28836060, 0.00091553, 0.24618530,
|
||||
0.13119507, 0.05685425, 0.17355347, 0.42034912, 0.08514404, 0.24536133, 0.18951416,
|
||||
-0.19107056, -0.15036011, 0.02334595, 0.54986572, 0.32321167, -0.16104126, -0.03054810,
|
||||
0.43594360, 0.17309570, 0.61053467, 0.24731445, 0.33334351, 0.15240479, 0.15588379,
|
||||
0.36425781, -0.30407715, -0.13302612, 0.00427246, 0.04171753, -0.33178711, 0.34216309,
|
||||
-0.12463379, -0.02764893, 0.05905151, -0.31436157, 0.16531372, 0.34542847, -0.03292847,
|
||||
0.12527466, -0.12313843, -0.13171387, 0.04757690, -0.45095825, -0.19085693, 0.35342407,
|
||||
-0.23239136, -0.34387207, 0.11264038, -0.15740967, 0.05273438, 0.74942017, 0.21505737,
|
||||
0.08514404, -0.42391968, -0.19531250, 0.35293579, 0.25305176, 0.15731812, -0.70324707,
|
||||
-0.21591187, 0.35604858, 0.14132690, 0.11724854, 0.15853882, -0.24597168, 0.07019043,
|
||||
0.02127075, 0.12658691, 0.06390381, -0.12292480, 0.15441895, -0.47640991, 0.06195068,
|
||||
0.58981323, -0.15151978, -0.03604126, -0.45059204, -0.01672363, -0.46997070, 0.25750732,
|
||||
0.18084717, 0.06661987, 0.13253784, 0.67828369, 0.11370850, 0.11325073, -0.04611206,
|
||||
-0.07791138, -0.36544800, -0.06747437, -0.31594849, 0.16131592, 0.41983032, 0.11071777,
|
||||
-0.36889648, 0.30963135, -0.37875366, 0.58508301, 0.00393677, 0.12338257, 0.03424072,
|
||||
-0.21728516, -0.12838745, -0.46981812, 0.05868530, -0.25015259, 0.27407837, 0.65240479,
|
||||
-0.34429932, -0.15179443, 0.14056396, 0.33505249, 0.28826904, 0.09921265, 0.34390259,
|
||||
0.13656616, -0.23608398, 0.00863647, 0.02627563, -0.19119263, 0.19775391, -0.07214355,
|
||||
0.07809448, 0.03454590, -0.03417969, 0.00033569, -0.23095703, 0.18673706, 0.05798340,
|
||||
0.03814697, -0.04318237, 0.05487061, 0.08633423, 0.55950928, -0.06347656, 0.10333252,
|
||||
0.25305176, 0.05853271, 0.12246704, -0.25543213, -0.34262085, -0.36437988, -0.21304321,
|
||||
-0.05093384, 0.02777100, 0.07620239, -0.21215820, -0.09326172, 0.19021606, -0.40579224,
|
||||
-0.01193237, 0.19845581, -0.35336304, -0.07397461, 0.20104980, 0.08615112, -0.44375610,
|
||||
0.11419678, 0.24453735, -0.16555786, -0.05081177, -0.01406860, 0.27893066, -0.18692017,
|
||||
0.07473755, 0.03451538, -0.39733887, 0.21548462, -0.22534180, -0.39651489, -0.04989624,
|
||||
-0.57662964, 0.06390381, 0.62020874, -0.13470459, 0.04345703, -0.21862793, -0.02789307,
|
||||
0.51696777, -0.27587891, 0.39004517, 0.09857178, -0.00738525, 0.31317139, 0.00048828,
|
||||
-0.46572876, 0.29531860, -0.10009766, -0.27856445, 0.03594971, 0.25048828, -0.74584961,
|
||||
-0.25350952, -0.03302002, 0.31188965, 0.01571655, 0.46710205, 0.21591187, 0.07260132,
|
||||
-0.42132568, -0.53900146, -0.13674927, -0.16571045, -0.34454346, 0.12359619, -0.11184692,
|
||||
0.00967407, 0.34576416, -0.05761719, 0.34848022, 0.17645264, -0.39395142, 0.10339355,
|
||||
0.18215942, 0.20697021, 0.59109497, -0.11560059, -0.07385254, 0.10397339, 0.35437012,
|
||||
-0.22863770, 0.01794434, 0.17559814, -0.17495728, 0.12142944, 0.10928345, -1.00000000,
|
||||
-0.01379395, 0.21237183, -0.27035522, 0.27319336, -0.37066650, 0.41354370, -0.40054321,
|
||||
0.00689697, 0.26321411, 0.39266968, 0.65298462, 0.41625977, -0.13909912, 0.78375244,
|
||||
-0.30941772, 0.20169067, -0.39367676, 0.94021606, -0.24066162, 0.05557251, -0.24533081,
|
||||
-0.05444336, -0.76754761, -0.19375610, -0.11041260, -0.17532349, 0.16006470, 0.02188110,
|
||||
0.17465210, -0.04342651, -0.56777954, -0.40988159, 0.26687622, 0.11700439, -0.00344849,
|
||||
-0.05395508, 0.37426758, -0.40719604, -0.15032959, -0.01660156, 0.04196167, -0.04559326,
|
||||
-0.12969971, 0.12011719, 0.08419800, -0.11199951, 0.35174561, 0.10275269, -0.25686646,
|
||||
0.48446655, 0.03225708, 0.28408813, -0.18701172, 0.36282349, -0.03280640, 0.32302856,
|
||||
0.17233276, 0.48269653, 0.31112671, -0.04946899, 0.12774658, 0.52685547, 0.10211182,
|
||||
0.05953979, 0.05999756, 0.20144653, 0.00744629, 0.27316284, 0.24377441, 0.39672852,
|
||||
0.01702881, -0.35513306, 0.11364746, -0.13555908, 0.48880005, -0.15417480, -0.09149170,
|
||||
-0.02615356, 0.46246338, -0.72250366, 0.22332764, 0.23849487, -0.25686646, -0.08514404,
|
||||
-0.02062988, -0.34494019, -0.02297974, -0.80386353, -0.08074951, -0.12689209, -0.06896973,
|
||||
0.24099731, -0.35650635, -0.09558105, 0.29254150, 0.23132324, -0.16726685, 0.00000000,
|
||||
-0.24237061, 0.30899048, 0.29504395, -0.20898438, 0.17059326, -0.07672119, -0.14395142,
|
||||
0.05572510, 0.20602417, -0.51550293, -0.03167725, -0.48840332, -0.20425415, 0.14144897,
|
||||
0.07275391, -0.76669312, -0.22488403, 0.20651245, 0.03259277, 0.00085449, 0.03039551,
|
||||
0.47555542, 0.38351440
|
||||
};
|
||||
|
||||
/** Noise level table for power compensation.
|
||||
* Equ: pow(2.0f, (double)(6 - i) / 3.0f) where i = 0...15 */
|
||||
static const float pwc_levs[16] = {
|
||||
3.96875, 3.15625, 2.5, 2.0, 1.59375, 1.25, 1.0, 0.78125,
|
||||
0.625, 0.5, 0.40625, 0.3125, 0.25, 0.1875, 0.15625, 0.0
|
||||
};
|
||||
|
||||
/** Map subband number to quant unit number. */
|
||||
static const int subband_to_qu[17] = {
|
||||
0, 8, 12, 16, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
|
||||
};
|
||||
|
||||
void ff_atrac3p_power_compensation(Atrac3pChanUnitCtx *ctx, int ch_index,
|
||||
float *sp, int rng_index, int sb)
|
||||
{
|
||||
AtracGainInfo *g1, *g2;
|
||||
float pwcsp[ATRAC3P_SUBBAND_SAMPLES], *dst, grp_lev, qu_lev;
|
||||
int i, gain_lev, gcv = 0, qu, nsp;
|
||||
int swap_ch = (ctx->unit_type == CH_UNIT_STEREO && ctx->swap_channels[sb]) ? 1 : 0;
|
||||
|
||||
if (ctx->channels[ch_index ^ swap_ch].power_levs[subband_to_powgrp[sb]] == ATRAC3P_POWER_COMP_OFF)
|
||||
return;
|
||||
|
||||
/* generate initial noise spectrum */
|
||||
for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++, rng_index++)
|
||||
pwcsp[i] = noise_tab[rng_index & 0x3FF];
|
||||
|
||||
/* check gain control information */
|
||||
g1 = &ctx->channels[ch_index ^ swap_ch].gain_data[sb];
|
||||
g2 = &ctx->channels[ch_index ^ swap_ch].gain_data_prev[sb];
|
||||
|
||||
gain_lev = (g1->num_points > 0) ? (6 - g1->lev_code[0]) : 0;
|
||||
|
||||
for (i = 0; i < g2->num_points; i++)
|
||||
gcv = FFMAX(gcv, gain_lev - (g2->lev_code[i] - 6));
|
||||
|
||||
for (i = 0; i < g1->num_points; i++)
|
||||
gcv = FFMAX(gcv, 6 - g1->lev_code[i]);
|
||||
|
||||
grp_lev = pwc_levs[ctx->channels[ch_index ^ swap_ch].power_levs[subband_to_powgrp[sb]]] / (1 << gcv);
|
||||
|
||||
/* skip the lowest two quant units (frequencies 0...351 Hz) for subband 0 */
|
||||
for (qu = subband_to_qu[sb] + (!sb ? 2 : 0); qu < subband_to_qu[sb + 1]; qu++) {
|
||||
if (ctx->channels[ch_index].qu_wordlen[qu] <= 0)
|
||||
continue;
|
||||
|
||||
qu_lev = ff_atrac3p_sf_tab[ctx->channels[ch_index].qu_sf_idx[qu]] *
|
||||
ff_atrac3p_mant_tab[ctx->channels[ch_index].qu_wordlen[qu]] /
|
||||
(1 << ctx->channels[ch_index].qu_wordlen[qu]) * grp_lev;
|
||||
|
||||
dst = &sp[ff_atrac3p_qu_to_spec_pos[qu]];
|
||||
nsp = ff_atrac3p_qu_to_spec_pos[qu + 1] - ff_atrac3p_qu_to_spec_pos[qu];
|
||||
|
||||
for (i = 0; i < nsp; i++)
|
||||
dst[i] += pwcsp[i] * qu_lev;
|
||||
}
|
||||
}
|
||||
|
||||
void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, FFTContext *mdct_ctx, float *pIn,
|
||||
float *pOut, int wind_id, int sb)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (sb & 1)
|
||||
for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES / 2; i++)
|
||||
FFSWAP(float, pIn[i], pIn[ATRAC3P_SUBBAND_SAMPLES - 1 - i]);
|
||||
|
||||
mdct_ctx->imdct_calc(mdct_ctx, pOut, pIn);
|
||||
|
||||
/* Perform windowing on the output.
|
||||
* ATRAC3+ uses two different MDCT windows:
|
||||
* - The first one is just the plain sine window of size 256
|
||||
* - The 2nd one is the plain sine window of size 128
|
||||
* wrapped into zero (at the start) and one (at the end) regions.
|
||||
* Both regions are 32 samples long. */
|
||||
if (wind_id & 2) { /* 1st half: steep window */
|
||||
memset(pOut, 0, sizeof(float) * 32);
|
||||
fdsp->vector_fmul(&pOut[32], &pOut[32], ff_sine_64, 64);
|
||||
} else /* 1st half: simple sine window */
|
||||
fdsp->vector_fmul(pOut, pOut, ff_sine_128, ATRAC3P_MDCT_SIZE / 2);
|
||||
|
||||
if (wind_id & 1) { /* 2nd half: steep window */
|
||||
fdsp->vector_fmul_reverse(&pOut[160], &pOut[160], ff_sine_64, 64);
|
||||
memset(&pOut[224], 0, sizeof(float) * 32);
|
||||
} else /* 2nd half: simple sine window */
|
||||
fdsp->vector_fmul_reverse(&pOut[128], &pOut[128], ff_sine_128,
|
||||
ATRAC3P_MDCT_SIZE / 2);
|
||||
}
|
||||
|
||||
/* lookup table for fast modulo 23 op required for cyclic buffers of the IPQF */
|
||||
static const int mod23_lut[26] = {
|
||||
23, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
||||
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0
|
||||
};
|
||||
|
||||
/* First half of the 384-tap IPQF filtering coefficients. */
|
||||
static const float ipqf_coeffs1[ATRAC3P_PQF_FIR_LEN][16] = {
|
||||
{ -5.8336207e-7, -8.0604229e-7, -4.2005411e-7, -4.4400572e-8,
|
||||
3.226247e-8, 3.530856e-8, 1.2660377e-8, 0.000010516783,
|
||||
-0.000011838618, 6.005389e-7, 0.0000014333754, 0.0000023108685,
|
||||
0.0000032569742, 0.0000046192422, 0.0000063894258, 0.0000070302972 },
|
||||
{ -0.0000091622824, -0.000010502935, -0.0000079212787, -0.0000041712024,
|
||||
-0.0000026336629, -0.0000015432918, -5.7168614e-7, 0.0000018111954,
|
||||
0.000023530851, 0.00002780562, 0.000032302323, 0.000036968919,
|
||||
0.000041575615, 0.000045337845, 0.000046043948, 0.000048585582 },
|
||||
{ -0.000064464548, -0.000068306952, -0.000073081472, -0.00007612785,
|
||||
-0.000074850752, -0.000070208509, -0.000062285151, -0.000058270442,
|
||||
-0.000056296329, -0.000049888811, -0.000035615325, -0.000018532943,
|
||||
0.0000016657353, 0.00002610587, 0.000053397067, 0.00008079566 },
|
||||
{ -0.00054488552, -0.00052537228, -0.00049731287, -0.00045778,
|
||||
-0.00040612387, -0.00034301577, -0.00026866337, -0.00018248901,
|
||||
-0.000084307925, 0.000025081157, 0.00014135583, 0.00026649953,
|
||||
0.00039945057, 0.00053928449, 0.00068422867, 0.00083093712 },
|
||||
{ -0.0014771431, -0.001283227, -0.0010566821, -0.00079780724,
|
||||
-0.00050782406, -0.00018855913, 0.00015771533, 0.00052769453,
|
||||
0.00091862219, 0.001326357, 0.0017469483, 0.0021754825,
|
||||
0.0026067684, 0.0030352892, 0.0034549395, 0.0038591374 },
|
||||
{ -0.0022995141, -0.001443546, -0.00049266568, 0.00055068987,
|
||||
0.001682895, 0.0028992873, 0.0041943151, 0.0055614738,
|
||||
0.0069935122, 0.0084823566, 0.010018963, 0.011593862,
|
||||
0.013196872, 0.014817309, 0.016444042, 0.018065533 },
|
||||
{ -0.034426283, -0.034281436, -0.033992987, -0.033563249,
|
||||
-0.032995768, -0.032295227, -0.031467363, -0.030518902,
|
||||
-0.02945766, -0.028291954, -0.027031265, -0.025685543,
|
||||
-0.024265358, -0.022781773, -0.021246184, -0.019670162 },
|
||||
{ -0.0030586775, -0.0037203205, -0.0042847847, -0.0047529764,
|
||||
-0.0051268316, -0.0054091476, -0.0056034233, -0.005714261,
|
||||
-0.0057445862, -0.0057025906, -0.0055920109, -0.0054194843,
|
||||
-0.0051914565, -0.0049146507, -0.0045959447, -0.0042418269 },
|
||||
{ -0.0016376863, -0.0017651899, -0.0018608454, -0.0019252141,
|
||||
-0.0019593791, -0.0019653172, -0.0019450618, -0.0018990048,
|
||||
-0.00183808, -0.0017501717, -0.0016481078, -0.0015320742,
|
||||
-0.0014046903, -0.0012685474, -0.001125814, -0.00097943726 },
|
||||
{ -0.00055432378, -0.00055472925, -0.00054783461, -0.00053276919,
|
||||
-0.00051135791, -0.00048466062, -0.00045358928, -0.00042499689,
|
||||
-0.00036942671, -0.0003392619, -0.00030001783, -0.00025986304,
|
||||
-0.0002197204, -0.00018116167, -0.00014691355, -0.00011279432 },
|
||||
{ -0.000064147389, -0.00006174868, -0.000054267788, -0.000047133824,
|
||||
-0.000042927582, -0.000039477309, -0.000036340745, -0.000029687517,
|
||||
-0.000049787737, -0.000041577889, -0.000033864744, -0.000026534748,
|
||||
-0.000019841305, -0.000014789486, -0.000013131184, -0.0000099198869 },
|
||||
{ -0.0000062990207, -0.0000072701259, -0.000011984052, -0.000017348082,
|
||||
-0.000019907106, -0.000021348773, -0.000021961965, -0.000012203576,
|
||||
-0.000010840992, 4.6299544e-7, 5.2588763e-7, 2.7792686e-7,
|
||||
-2.3649704e-7, -0.0000010897784, -9.171448e-7, -5.22682e-7 }
|
||||
};
|
||||
|
||||
/* Second half of the 384-tap IPQF filtering coefficients. */
|
||||
static const float ipqf_coeffs2[ATRAC3P_PQF_FIR_LEN][16] = {
|
||||
{ 5.22682e-7, 9.171448e-7, 0.0000010897784, 2.3649704e-7,
|
||||
-2.7792686e-7, -5.2588763e-7, -4.6299544e-7, 0.000010840992,
|
||||
-0.000012203576, -0.000021961965, -0.000021348773, -0.000019907106,
|
||||
-0.000017348082, -0.000011984052, -0.0000072701259, -0.0000062990207 },
|
||||
{ 0.0000099198869, 0.000013131184, 0.000014789486, 0.000019841305,
|
||||
0.000026534748, 0.000033864744, 0.000041577889, 0.000049787737,
|
||||
-0.000029687517, -0.000036340745, -0.000039477309, -0.000042927582,
|
||||
-0.000047133824, -0.000054267788, -0.00006174868, -0.000064147389 },
|
||||
{ 0.00011279432, 0.00014691355, 0.00018116167, 0.0002197204,
|
||||
0.00025986304, 0.00030001783, 0.0003392619, 0.00036942671,
|
||||
-0.00042499689, -0.00045358928, -0.00048466062, -0.00051135791,
|
||||
-0.00053276919, -0.00054783461, -0.00055472925, -0.00055432378 },
|
||||
{ 0.00097943726, 0.001125814, 0.0012685474, 0.0014046903,
|
||||
0.0015320742, 0.0016481078, 0.0017501717, 0.00183808,
|
||||
-0.0018990048, -0.0019450618, -0.0019653172, -0.0019593791,
|
||||
-0.0019252141, -0.0018608454, -0.0017651899, -0.0016376863 },
|
||||
{ 0.0042418269, 0.0045959447, 0.0049146507, 0.0051914565,
|
||||
0.0054194843, 0.0055920109, 0.0057025906, 0.0057445862,
|
||||
-0.005714261, -0.0056034233, -0.0054091476, -0.0051268316,
|
||||
-0.0047529764, -0.0042847847, -0.0037203205, -0.0030586775 },
|
||||
{ 0.019670162, 0.021246184, 0.022781773, 0.024265358,
|
||||
0.025685543, 0.027031265, 0.028291954, 0.02945766,
|
||||
-0.030518902, -0.031467363, -0.032295227, -0.032995768,
|
||||
-0.033563249, -0.033992987, -0.034281436, -0.034426283 },
|
||||
{ -0.018065533, -0.016444042, -0.014817309, -0.013196872,
|
||||
-0.011593862, -0.010018963, -0.0084823566, -0.0069935122,
|
||||
0.0055614738, 0.0041943151, 0.0028992873, 0.001682895,
|
||||
0.00055068987, -0.00049266568, -0.001443546, -0.0022995141 },
|
||||
{ -0.0038591374, -0.0034549395, -0.0030352892, -0.0026067684,
|
||||
-0.0021754825, -0.0017469483, -0.001326357, -0.00091862219,
|
||||
0.00052769453, 0.00015771533, -0.00018855913, -0.00050782406,
|
||||
-0.00079780724, -0.0010566821, -0.001283227, -0.0014771431 },
|
||||
{ -0.00083093712, -0.00068422867, -0.00053928449, -0.00039945057,
|
||||
-0.00026649953, -0.00014135583, -0.000025081157, 0.000084307925,
|
||||
-0.00018248901, -0.00026866337, -0.00034301577, -0.00040612387,
|
||||
-0.00045778, -0.00049731287, -0.00052537228, -0.00054488552 },
|
||||
{ -0.00008079566, -0.000053397067, -0.00002610587, -0.0000016657353,
|
||||
0.000018532943, 0.000035615325, 0.000049888811, 0.000056296329,
|
||||
-0.000058270442, -0.000062285151, -0.000070208509, -0.000074850752,
|
||||
-0.00007612785, -0.000073081472, -0.000068306952, -0.000064464548 },
|
||||
{ -0.000048585582, -0.000046043948, -0.000045337845, -0.000041575615,
|
||||
-0.000036968919, -0.000032302323, -0.00002780562, -0.000023530851,
|
||||
0.0000018111954, -5.7168614e-7, -0.0000015432918, -0.0000026336629,
|
||||
-0.0000041712024, -0.0000079212787, -0.000010502935, -0.0000091622824 },
|
||||
{ -0.0000070302972, -0.0000063894258, -0.0000046192422, -0.0000032569742,
|
||||
-0.0000023108685, -0.0000014333754, -6.005389e-7, 0.000011838618,
|
||||
0.000010516783, 1.2660377e-8, 3.530856e-8, 3.226247e-8,
|
||||
-4.4400572e-8, -4.2005411e-7, -8.0604229e-7, -5.8336207e-7 }
|
||||
};
|
||||
|
||||
void ff_atrac3p_ipqf(FFTContext *dct_ctx, Atrac3pIPQFChannelCtx *hist,
|
||||
const float *in, float *out)
|
||||
{
|
||||
int i, s, sb, t, pos_now, pos_next;
|
||||
DECLARE_ALIGNED(32, float, idct_in)[ATRAC3P_SUBBANDS];
|
||||
DECLARE_ALIGNED(32, float, idct_out)[ATRAC3P_SUBBANDS];
|
||||
|
||||
memset(out, 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out));
|
||||
|
||||
for (s = 0; s < ATRAC3P_SUBBAND_SAMPLES; s++) {
|
||||
/* pick up one sample from each subband */
|
||||
for (sb = 0; sb < ATRAC3P_SUBBANDS; sb++)
|
||||
idct_in[sb] = in[sb * ATRAC3P_SUBBAND_SAMPLES + s];
|
||||
|
||||
/* Calculate the sine and cosine part of the PQF using IDCT-IV */
|
||||
dct_ctx->imdct_half(dct_ctx, idct_out, idct_in);
|
||||
|
||||
/* append the result to the history */
|
||||
for (i = 0; i < 8; i++) {
|
||||
hist->buf1[hist->pos][i] = idct_out[i + 8];
|
||||
hist->buf2[hist->pos][i] = idct_out[7 - i];
|
||||
}
|
||||
|
||||
pos_now = hist->pos;
|
||||
pos_next = mod23_lut[pos_now + 2]; // pos_next = (pos_now + 1) % 23;
|
||||
|
||||
for (t = 0; t < ATRAC3P_PQF_FIR_LEN; t++) {
|
||||
for (i = 0; i < 8; i++) {
|
||||
out[s * 16 + i + 0] += hist->buf1[pos_now][i] * ipqf_coeffs1[t][i] +
|
||||
hist->buf2[pos_next][i] * ipqf_coeffs2[t][i];
|
||||
out[s * 16 + i + 8] += hist->buf1[pos_now][7 - i] * ipqf_coeffs1[t][i + 8] +
|
||||
hist->buf2[pos_next][7 - i] * ipqf_coeffs2[t][i + 8];
|
||||
}
|
||||
|
||||
pos_now = mod23_lut[pos_next + 2]; // pos_now = (pos_now + 2) % 23;
|
||||
pos_next = mod23_lut[pos_now + 2]; // pos_next = (pos_next + 2) % 23;
|
||||
}
|
||||
|
||||
hist->pos = mod23_lut[hist->pos]; // hist->pos = (hist->pos - 1) % 23;
|
||||
}
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavutil/attributes.h"
|
||||
#include "libavutil/mem.h"
|
||||
#include "avfft.h"
|
||||
#include "fft.h"
|
||||
#include "rdft.h"
|
||||
#include "dct.h"
|
||||
|
||||
/* FFT */
|
||||
|
||||
FFTContext *av_fft_init(int nbits, int inverse)
|
||||
{
|
||||
FFTContext *s = av_mallocz(sizeof(*s));
|
||||
|
||||
if (s && ff_fft_init(s, nbits, inverse))
|
||||
av_freep(&s);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void av_fft_permute(FFTContext *s, FFTComplex *z)
|
||||
{
|
||||
s->fft_permute(s, z);
|
||||
}
|
||||
|
||||
void av_fft_calc(FFTContext *s, FFTComplex *z)
|
||||
{
|
||||
s->fft_calc(s, z);
|
||||
}
|
||||
|
||||
av_cold void av_fft_end(FFTContext *s)
|
||||
{
|
||||
if (s) {
|
||||
ff_fft_end(s);
|
||||
av_free(s);
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_MDCT
|
||||
|
||||
FFTContext *av_mdct_init(int nbits, int inverse, double scale)
|
||||
{
|
||||
FFTContext *s = av_malloc(sizeof(*s));
|
||||
|
||||
if (s && ff_mdct_init(s, nbits, inverse, scale))
|
||||
av_freep(&s);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
|
||||
{
|
||||
s->imdct_calc(s, output, input);
|
||||
}
|
||||
|
||||
void av_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input)
|
||||
{
|
||||
s->imdct_half(s, output, input);
|
||||
}
|
||||
|
||||
void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
|
||||
{
|
||||
s->mdct_calc(s, output, input);
|
||||
}
|
||||
|
||||
av_cold void av_mdct_end(FFTContext *s)
|
||||
{
|
||||
if (s) {
|
||||
ff_mdct_end(s);
|
||||
av_free(s);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_MDCT */
|
||||
|
||||
#if CONFIG_RDFT
|
||||
|
||||
RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans)
|
||||
{
|
||||
RDFTContext *s = av_malloc(sizeof(*s));
|
||||
|
||||
if (s && ff_rdft_init(s, nbits, trans))
|
||||
av_freep(&s);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void av_rdft_calc(RDFTContext *s, FFTSample *data)
|
||||
{
|
||||
s->rdft_calc(s, data);
|
||||
}
|
||||
|
||||
av_cold void av_rdft_end(RDFTContext *s)
|
||||
{
|
||||
if (s) {
|
||||
ff_rdft_end(s);
|
||||
av_free(s);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_RDFT */
|
||||
|
||||
#if CONFIG_DCT
|
||||
|
||||
DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse)
|
||||
{
|
||||
DCTContext *s = av_malloc(sizeof(*s));
|
||||
|
||||
if (s && ff_dct_init(s, nbits, inverse))
|
||||
av_freep(&s);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void av_dct_calc(DCTContext *s, FFTSample *data)
|
||||
{
|
||||
s->dct_calc(s, data);
|
||||
}
|
||||
|
||||
av_cold void av_dct_end(DCTContext *s)
|
||||
{
|
||||
if (s) {
|
||||
ff_dct_end(s);
|
||||
av_free(s);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_DCT */
|
|
@ -1,565 +0,0 @@
|
|||
/*
|
||||
* AVPacket functions for libavcodec
|
||||
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "libavutil/avassert.h"
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/internal.h"
|
||||
#include "libavutil/mem.h"
|
||||
#include "avcodec.h"
|
||||
#include "bytestream.h"
|
||||
#include "internal.h"
|
||||
|
||||
#if FF_API_DESTRUCT_PACKET
|
||||
|
||||
void av_destruct_packet(AVPacket *pkt)
|
||||
{
|
||||
av_free(pkt->data);
|
||||
pkt->data = NULL;
|
||||
pkt->size = 0;
|
||||
}
|
||||
|
||||
/* a dummy destruct callback for the callers that assume AVPacket.destruct ==
|
||||
* NULL => static data */
|
||||
static void dummy_destruct_packet(AVPacket *pkt)
|
||||
{
|
||||
av_assert0(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
void av_init_packet(AVPacket *pkt)
|
||||
{
|
||||
pkt->pts = AV_NOPTS_VALUE;
|
||||
pkt->dts = AV_NOPTS_VALUE;
|
||||
pkt->pos = -1;
|
||||
pkt->duration = 0;
|
||||
pkt->convergence_duration = 0;
|
||||
pkt->flags = 0;
|
||||
pkt->stream_index = 0;
|
||||
#if FF_API_DESTRUCT_PACKET
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
pkt->destruct = NULL;
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
#endif
|
||||
pkt->buf = NULL;
|
||||
pkt->side_data = NULL;
|
||||
pkt->side_data_elems = 0;
|
||||
}
|
||||
|
||||
static int packet_alloc(AVBufferRef **buf, int size)
|
||||
{
|
||||
int ret;
|
||||
if ((unsigned)size >= (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
ret = av_buffer_realloc(buf, size + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
memset((*buf)->data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_new_packet(AVPacket *pkt, int size)
|
||||
{
|
||||
AVBufferRef *buf = NULL;
|
||||
int ret = packet_alloc(&buf, size);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
av_init_packet(pkt);
|
||||
pkt->buf = buf;
|
||||
pkt->data = buf->data;
|
||||
pkt->size = size;
|
||||
#if FF_API_DESTRUCT_PACKET
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
pkt->destruct = dummy_destruct_packet;
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void av_shrink_packet(AVPacket *pkt, int size)
|
||||
{
|
||||
if (pkt->size <= size)
|
||||
return;
|
||||
pkt->size = size;
|
||||
memset(pkt->data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
}
|
||||
|
||||
int av_grow_packet(AVPacket *pkt, int grow_by)
|
||||
{
|
||||
int new_size;
|
||||
av_assert0((unsigned)pkt->size <= INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
if (!pkt->size)
|
||||
return av_new_packet(pkt, grow_by);
|
||||
if ((unsigned)grow_by >
|
||||
INT_MAX - (pkt->size + FF_INPUT_BUFFER_PADDING_SIZE))
|
||||
return -1;
|
||||
|
||||
new_size = pkt->size + grow_by + FF_INPUT_BUFFER_PADDING_SIZE;
|
||||
if (pkt->buf) {
|
||||
int ret = av_buffer_realloc(&pkt->buf, new_size);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
} else {
|
||||
pkt->buf = av_buffer_alloc(new_size);
|
||||
if (!pkt->buf)
|
||||
return AVERROR(ENOMEM);
|
||||
memcpy(pkt->buf->data, pkt->data, FFMIN(pkt->size, pkt->size + grow_by));
|
||||
#if FF_API_DESTRUCT_PACKET
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
pkt->destruct = dummy_destruct_packet;
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
#endif
|
||||
}
|
||||
pkt->data = pkt->buf->data;
|
||||
pkt->size += grow_by;
|
||||
memset(pkt->data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size)
|
||||
{
|
||||
if (size >= INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
pkt->buf = av_buffer_create(data, size + FF_INPUT_BUFFER_PADDING_SIZE,
|
||||
av_buffer_default_free, NULL, 0);
|
||||
if (!pkt->buf)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
pkt->data = data;
|
||||
pkt->size = size;
|
||||
#if FF_API_DESTRUCT_PACKET
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
pkt->destruct = dummy_destruct_packet;
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define ALLOC_MALLOC(data, size) data = av_malloc(size)
|
||||
#define ALLOC_BUF(data, size) \
|
||||
do { \
|
||||
av_buffer_realloc(&pkt->buf, size); \
|
||||
data = pkt->buf ? pkt->buf->data : NULL; \
|
||||
} while (0)
|
||||
|
||||
#define DUP_DATA(dst, src, size, padding, ALLOC) \
|
||||
do { \
|
||||
void *data; \
|
||||
if (padding) { \
|
||||
if ((unsigned)(size) > \
|
||||
(unsigned)(size) + FF_INPUT_BUFFER_PADDING_SIZE) \
|
||||
goto failed_alloc; \
|
||||
ALLOC(data, size + FF_INPUT_BUFFER_PADDING_SIZE); \
|
||||
} else { \
|
||||
ALLOC(data, size); \
|
||||
} \
|
||||
if (!data) \
|
||||
goto failed_alloc; \
|
||||
memcpy(data, src, size); \
|
||||
if (padding) \
|
||||
memset((uint8_t *)data + size, 0, \
|
||||
FF_INPUT_BUFFER_PADDING_SIZE); \
|
||||
dst = data; \
|
||||
} while (0)
|
||||
|
||||
/* Makes duplicates of data, side_data, but does not copy any other fields */
|
||||
static int copy_packet_data(AVPacket *pkt, AVPacket *src, int dup)
|
||||
{
|
||||
pkt->data = NULL;
|
||||
pkt->side_data = NULL;
|
||||
if (pkt->buf) {
|
||||
AVBufferRef *ref = av_buffer_ref(src->buf);
|
||||
if (!ref)
|
||||
return AVERROR(ENOMEM);
|
||||
pkt->buf = ref;
|
||||
pkt->data = ref->data;
|
||||
} else {
|
||||
DUP_DATA(pkt->data, src->data, pkt->size, 1, ALLOC_BUF);
|
||||
}
|
||||
#if FF_API_DESTRUCT_PACKET
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
pkt->destruct = dummy_destruct_packet;
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
#endif
|
||||
if (pkt->side_data_elems && dup)
|
||||
pkt->side_data = src->side_data;
|
||||
if (pkt->side_data_elems && !dup) {
|
||||
return av_copy_packet_side_data(pkt, src);
|
||||
}
|
||||
return 0;
|
||||
|
||||
failed_alloc:
|
||||
av_free_packet(pkt);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
int av_copy_packet_side_data(AVPacket *pkt, AVPacket *src)
|
||||
{
|
||||
if (src->side_data_elems) {
|
||||
int i;
|
||||
DUP_DATA(pkt->side_data, src->side_data,
|
||||
src->side_data_elems * sizeof(*src->side_data), 0, ALLOC_MALLOC);
|
||||
if (src != pkt) {
|
||||
memset(pkt->side_data, 0,
|
||||
src->side_data_elems * sizeof(*src->side_data));
|
||||
}
|
||||
for (i = 0; i < src->side_data_elems; i++) {
|
||||
DUP_DATA(pkt->side_data[i].data, src->side_data[i].data,
|
||||
src->side_data[i].size, 1, ALLOC_MALLOC);
|
||||
pkt->side_data[i].size = src->side_data[i].size;
|
||||
pkt->side_data[i].type = src->side_data[i].type;
|
||||
}
|
||||
}
|
||||
pkt->side_data_elems = src->side_data_elems;
|
||||
return 0;
|
||||
|
||||
failed_alloc:
|
||||
av_free_packet(pkt);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
int av_dup_packet(AVPacket *pkt)
|
||||
{
|
||||
AVPacket tmp_pkt;
|
||||
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
if (!pkt->buf && pkt->data
|
||||
#if FF_API_DESTRUCT_PACKET
|
||||
&& !pkt->destruct
|
||||
#endif
|
||||
) {
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
tmp_pkt = *pkt;
|
||||
return copy_packet_data(pkt, &tmp_pkt, 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_copy_packet(AVPacket *dst, AVPacket *src)
|
||||
{
|
||||
*dst = *src;
|
||||
return copy_packet_data(dst, src, 0);
|
||||
}
|
||||
|
||||
void av_packet_free_side_data(AVPacket *pkt)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < pkt->side_data_elems; i++)
|
||||
av_free(pkt->side_data[i].data);
|
||||
av_freep(&pkt->side_data);
|
||||
pkt->side_data_elems = 0;
|
||||
}
|
||||
|
||||
void av_free_packet(AVPacket *pkt)
|
||||
{
|
||||
if (pkt) {
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
if (pkt->buf)
|
||||
av_buffer_unref(&pkt->buf);
|
||||
#if FF_API_DESTRUCT_PACKET
|
||||
else if (pkt->destruct)
|
||||
pkt->destruct(pkt);
|
||||
pkt->destruct = NULL;
|
||||
#endif
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
pkt->data = NULL;
|
||||
pkt->size = 0;
|
||||
|
||||
av_packet_free_side_data(pkt);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
|
||||
int size)
|
||||
{
|
||||
int elems = pkt->side_data_elems;
|
||||
|
||||
if ((unsigned)elems + 1 > INT_MAX / sizeof(*pkt->side_data))
|
||||
return NULL;
|
||||
if ((unsigned)size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
|
||||
return NULL;
|
||||
|
||||
pkt->side_data = av_realloc(pkt->side_data,
|
||||
(elems + 1) * sizeof(*pkt->side_data));
|
||||
if (!pkt->side_data)
|
||||
return NULL;
|
||||
|
||||
pkt->side_data[elems].data = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
if (!pkt->side_data[elems].data)
|
||||
return NULL;
|
||||
pkt->side_data[elems].size = size;
|
||||
pkt->side_data[elems].type = type;
|
||||
pkt->side_data_elems++;
|
||||
|
||||
return pkt->side_data[elems].data;
|
||||
}
|
||||
|
||||
uint8_t *av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
|
||||
int *size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < pkt->side_data_elems; i++) {
|
||||
if (pkt->side_data[i].type == type) {
|
||||
if (size)
|
||||
*size = pkt->side_data[i].size;
|
||||
return pkt->side_data[i].data;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define FF_MERGE_MARKER 0x8c4d9d108e25e9feULL
|
||||
|
||||
int av_packet_merge_side_data(AVPacket *pkt){
|
||||
if(pkt->side_data_elems){
|
||||
AVBufferRef *buf;
|
||||
int i;
|
||||
uint8_t *p;
|
||||
uint64_t size= pkt->size + 8LL + FF_INPUT_BUFFER_PADDING_SIZE;
|
||||
AVPacket old= *pkt;
|
||||
for (i=0; i<old.side_data_elems; i++) {
|
||||
size += old.side_data[i].size + 5LL;
|
||||
}
|
||||
if (size > INT_MAX)
|
||||
return AVERROR(EINVAL);
|
||||
buf = av_buffer_alloc(size);
|
||||
if (!buf)
|
||||
return AVERROR(ENOMEM);
|
||||
pkt->buf = buf;
|
||||
pkt->data = p = buf->data;
|
||||
#if FF_API_DESTRUCT_PACKET
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
pkt->destruct = dummy_destruct_packet;
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
#endif
|
||||
pkt->size = size - FF_INPUT_BUFFER_PADDING_SIZE;
|
||||
bytestream_put_buffer(&p, old.data, old.size);
|
||||
for (i=old.side_data_elems-1; i>=0; i--) {
|
||||
bytestream_put_buffer(&p, old.side_data[i].data, old.side_data[i].size);
|
||||
bytestream_put_be32(&p, old.side_data[i].size);
|
||||
*p++ = old.side_data[i].type | ((i==old.side_data_elems-1)*128);
|
||||
}
|
||||
bytestream_put_be64(&p, FF_MERGE_MARKER);
|
||||
av_assert0(p-pkt->data == pkt->size);
|
||||
memset(p, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
av_free_packet(&old);
|
||||
pkt->side_data_elems = 0;
|
||||
pkt->side_data = NULL;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_packet_split_side_data(AVPacket *pkt){
|
||||
if (!pkt->side_data_elems && pkt->size >12 && AV_RB64(pkt->data + pkt->size - 8) == FF_MERGE_MARKER){
|
||||
int i;
|
||||
unsigned int size;
|
||||
uint8_t *p;
|
||||
|
||||
p = pkt->data + pkt->size - 8 - 5;
|
||||
for (i=1; ; i++){
|
||||
size = AV_RB32(p);
|
||||
if (size>INT_MAX || p - pkt->data < size)
|
||||
return 0;
|
||||
if (p[4]&128)
|
||||
break;
|
||||
p-= size+5;
|
||||
}
|
||||
|
||||
pkt->side_data = av_malloc(i * sizeof(*pkt->side_data));
|
||||
if (!pkt->side_data)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
p= pkt->data + pkt->size - 8 - 5;
|
||||
for (i=0; ; i++){
|
||||
size= AV_RB32(p);
|
||||
av_assert0(size<=INT_MAX && p - pkt->data >= size);
|
||||
pkt->side_data[i].data = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
pkt->side_data[i].size = size;
|
||||
pkt->side_data[i].type = p[4]&127;
|
||||
if (!pkt->side_data[i].data)
|
||||
return AVERROR(ENOMEM);
|
||||
memcpy(pkt->side_data[i].data, p-size, size);
|
||||
pkt->size -= size + 5;
|
||||
if(p[4]&128)
|
||||
break;
|
||||
p-= size+5;
|
||||
}
|
||||
pkt->size -= 8;
|
||||
pkt->side_data_elems = i+1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t *av_packet_pack_dictionary(AVDictionary *dict, int *size)
|
||||
{
|
||||
AVDictionaryEntry *t = NULL;
|
||||
uint8_t *data = NULL;
|
||||
*size = 0;
|
||||
|
||||
if (!dict)
|
||||
return NULL;
|
||||
|
||||
while ((t = av_dict_get(dict, "", t, AV_DICT_IGNORE_SUFFIX))) {
|
||||
const size_t keylen = strlen(t->key);
|
||||
const size_t valuelen = strlen(t->value);
|
||||
const size_t new_size = *size + keylen + 1 + valuelen + 1;
|
||||
uint8_t *const new_data = av_realloc(data, new_size);
|
||||
|
||||
if (!new_data)
|
||||
goto fail;
|
||||
data = new_data;
|
||||
if (new_size > INT_MAX)
|
||||
goto fail;
|
||||
|
||||
memcpy(data + *size, t->key, keylen + 1);
|
||||
memcpy(data + *size + keylen + 1, t->value, valuelen + 1);
|
||||
|
||||
*size = new_size;
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
fail:
|
||||
av_freep(&data);
|
||||
*size = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict)
|
||||
{
|
||||
const uint8_t *end = data + size;
|
||||
int ret = 0;
|
||||
|
||||
if (!dict || !data || !size)
|
||||
return ret;
|
||||
if (size && end[-1])
|
||||
return AVERROR_INVALIDDATA;
|
||||
while (data < end) {
|
||||
const uint8_t *key = data;
|
||||
const uint8_t *val = data + strlen(key) + 1;
|
||||
|
||||
if (val >= end)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
ret = av_dict_set(dict, key, val, 0);
|
||||
if (ret < 0)
|
||||
break;
|
||||
data = val + strlen(val) + 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
|
||||
int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < pkt->side_data_elems; i++) {
|
||||
if (pkt->side_data[i].type == type) {
|
||||
if (size > pkt->side_data[i].size)
|
||||
return AVERROR(ENOMEM);
|
||||
pkt->side_data[i].size = size;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return AVERROR(ENOENT);
|
||||
}
|
||||
|
||||
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
|
||||
{
|
||||
int i;
|
||||
|
||||
dst->pts = src->pts;
|
||||
dst->dts = src->dts;
|
||||
dst->pos = src->pos;
|
||||
dst->duration = src->duration;
|
||||
dst->convergence_duration = src->convergence_duration;
|
||||
dst->flags = src->flags;
|
||||
dst->stream_index = src->stream_index;
|
||||
dst->side_data_elems = src->side_data_elems;
|
||||
|
||||
for (i = 0; i < src->side_data_elems; i++) {
|
||||
enum AVPacketSideDataType type = src->side_data[i].type;
|
||||
int size = src->side_data[i].size;
|
||||
uint8_t *src_data = src->side_data[i].data;
|
||||
uint8_t *dst_data = av_packet_new_side_data(dst, type, size);
|
||||
|
||||
if (!dst_data) {
|
||||
av_packet_free_side_data(dst);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
memcpy(dst_data, src_data, size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void av_packet_unref(AVPacket *pkt)
|
||||
{
|
||||
av_packet_free_side_data(pkt);
|
||||
av_buffer_unref(&pkt->buf);
|
||||
av_init_packet(pkt);
|
||||
pkt->data = NULL;
|
||||
pkt->size = 0;
|
||||
}
|
||||
|
||||
int av_packet_ref(AVPacket *dst, AVPacket *src)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = av_packet_copy_props(dst, src);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (!src->buf) {
|
||||
ret = packet_alloc(&dst->buf, src->size);
|
||||
if (ret < 0)
|
||||
goto fail;
|
||||
memcpy(dst->buf->data, src->data, src->size);
|
||||
} else
|
||||
dst->buf = av_buffer_ref(src->buf);
|
||||
|
||||
dst->size = src->size;
|
||||
dst->data = dst->buf->data;
|
||||
return 0;
|
||||
fail:
|
||||
av_packet_free_side_data(dst);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
|
||||
{
|
||||
*dst = *src;
|
||||
av_init_packet(src);
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* AVPicture management routines
|
||||
* Copyright (c) 2001, 2002, 2003 Fabrice Bellard
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* AVPicture management routines
|
||||
*/
|
||||
|
||||
#include "avcodec.h"
|
||||
#include "internal.h"
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/pixdesc.h"
|
||||
#include "libavutil/imgutils.h"
|
||||
#include "libavutil/colorspace.h"
|
||||
|
||||
int avpicture_fill(AVPicture *picture, const uint8_t *ptr,
|
||||
enum AVPixelFormat pix_fmt, int width, int height)
|
||||
{
|
||||
return av_image_fill_arrays(picture->data, picture->linesize,
|
||||
ptr, pix_fmt, width, height, 1);
|
||||
}
|
||||
|
||||
int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt, int width, int height,
|
||||
unsigned char *dest, int dest_size)
|
||||
{
|
||||
return av_image_copy_to_buffer(dest, dest_size,
|
||||
(const uint8_t * const*)src->data, src->linesize,
|
||||
pix_fmt, width, height, 1);
|
||||
}
|
||||
|
||||
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
|
||||
{
|
||||
return av_image_get_buffer_size(pix_fmt, width, height, 1);
|
||||
}
|
||||
|
||||
int avpicture_alloc(AVPicture *picture,
|
||||
enum AVPixelFormat pix_fmt, int width, int height)
|
||||
{
|
||||
int ret = av_image_alloc(picture->data, picture->linesize,
|
||||
width, height, pix_fmt, 1);
|
||||
if (ret < 0) {
|
||||
memset(picture, 0, sizeof(AVPicture));
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void avpicture_free(AVPicture *picture)
|
||||
{
|
||||
av_free(picture->data[0]);
|
||||
}
|
||||
|
||||
void av_picture_copy(AVPicture *dst, const AVPicture *src,
|
||||
enum AVPixelFormat pix_fmt, int width, int height)
|
||||
{
|
||||
av_image_copy(dst->data, dst->linesize, (const uint8_t **)src->data,
|
||||
src->linesize, pix_fmt, width, height);
|
||||
}
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "rnd_avg.h"
|
||||
#include "libavutil/intreadwrite.h"
|
||||
|
||||
#ifndef BIT_DEPTH
|
||||
#define BIT_DEPTH 8
|
||||
#endif
|
||||
|
||||
#ifdef AVCODEC_H264_HIGH_DEPTH_H
|
||||
# undef pixel
|
||||
# undef pixel2
|
||||
# undef pixel4
|
||||
# undef dctcoef
|
||||
# undef INIT_CLIP
|
||||
# undef no_rnd_avg_pixel4
|
||||
# undef rnd_avg_pixel4
|
||||
# undef AV_RN2P
|
||||
# undef AV_RN4P
|
||||
# undef AV_RN4PA
|
||||
# undef AV_WN2P
|
||||
# undef AV_WN4P
|
||||
# undef AV_WN4PA
|
||||
# undef CLIP
|
||||
# undef FUNC
|
||||
# undef FUNCC
|
||||
# undef av_clip_pixel
|
||||
# undef PIXEL_SPLAT_X4
|
||||
#else
|
||||
# define AVCODEC_H264_HIGH_DEPTH_H
|
||||
#endif
|
||||
|
||||
#if BIT_DEPTH > 8
|
||||
# define pixel uint16_t
|
||||
# define pixel2 uint32_t
|
||||
# define pixel4 uint64_t
|
||||
# define dctcoef int32_t
|
||||
|
||||
# define INIT_CLIP
|
||||
# define no_rnd_avg_pixel4 no_rnd_avg64
|
||||
# define rnd_avg_pixel4 rnd_avg64
|
||||
# define AV_RN2P AV_RN32
|
||||
# define AV_RN4P AV_RN64
|
||||
# define AV_RN4PA AV_RN64A
|
||||
# define AV_WN2P AV_WN32
|
||||
# define AV_WN4P AV_WN64
|
||||
# define AV_WN4PA AV_WN64A
|
||||
# define PIXEL_SPLAT_X4(x) ((x)*0x0001000100010001ULL)
|
||||
|
||||
# define av_clip_pixel(a) av_clip_uintp2(a, BIT_DEPTH)
|
||||
# define CLIP(a) av_clip_uintp2(a, BIT_DEPTH)
|
||||
#else
|
||||
# define pixel uint8_t
|
||||
# define pixel2 uint16_t
|
||||
# define pixel4 uint32_t
|
||||
# define dctcoef int16_t
|
||||
|
||||
# define INIT_CLIP
|
||||
# define no_rnd_avg_pixel4 no_rnd_avg32
|
||||
# define rnd_avg_pixel4 rnd_avg32
|
||||
# define AV_RN2P AV_RN16
|
||||
# define AV_RN4P AV_RN32
|
||||
# define AV_RN4PA AV_RN32A
|
||||
# define AV_WN2P AV_WN16
|
||||
# define AV_WN4P AV_WN32
|
||||
# define AV_WN4PA AV_WN32A
|
||||
# define PIXEL_SPLAT_X4(x) ((x)*0x01010101U)
|
||||
|
||||
# define av_clip_pixel(a) av_clip_uint8(a)
|
||||
# define CLIP(a) av_clip_uint8(a)
|
||||
#endif
|
||||
|
||||
#define FUNC3(a, b, c) a ## _ ## b ## c
|
||||
#define FUNC2(a, b, c) FUNC3(a, b, c)
|
||||
#define FUNC(a) FUNC2(a, BIT_DEPTH,)
|
||||
#define FUNCC(a) FUNC2(a, BIT_DEPTH, _c)
|
|
@ -1,360 +0,0 @@
|
|||
/*
|
||||
* Common bit i/o utils
|
||||
* Copyright (c) 2000, 2001 Fabrice Bellard
|
||||
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
* Copyright (c) 2010 Loren Merritt
|
||||
*
|
||||
* alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* bitstream api.
|
||||
*/
|
||||
|
||||
#include "libavutil/atomic.h"
|
||||
#include "libavutil/avassert.h"
|
||||
#include "avcodec.h"
|
||||
#include "mathops.h"
|
||||
#include "get_bits.h"
|
||||
#include "put_bits.h"
|
||||
|
||||
const uint8_t ff_log2_run[41]={
|
||||
0, 0, 0, 0, 1, 1, 1, 1,
|
||||
2, 2, 2, 2, 3, 3, 3, 3,
|
||||
4, 4, 5, 5, 6, 6, 7, 7,
|
||||
8, 9,10,11,12,13,14,15,
|
||||
16,17,18,19,20,21,22,23,
|
||||
24,
|
||||
};
|
||||
|
||||
void avpriv_align_put_bits(PutBitContext *s)
|
||||
{
|
||||
put_bits(s, s->bit_left & 7, 0);
|
||||
}
|
||||
|
||||
void avpriv_put_string(PutBitContext *pb, const char *string,
|
||||
int terminate_string)
|
||||
{
|
||||
while (*string) {
|
||||
put_bits(pb, 8, *string);
|
||||
string++;
|
||||
}
|
||||
if (terminate_string)
|
||||
put_bits(pb, 8, 0);
|
||||
}
|
||||
|
||||
void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
|
||||
{
|
||||
int words = length >> 4;
|
||||
int bits = length & 15;
|
||||
int i;
|
||||
|
||||
if (length == 0)
|
||||
return;
|
||||
|
||||
if (CONFIG_SMALL || words < 16 || put_bits_count(pb) & 7) {
|
||||
for (i = 0; i < words; i++)
|
||||
put_bits(pb, 16, AV_RB16(src + 2 * i));
|
||||
} else {
|
||||
for (i = 0; put_bits_count(pb) & 31; i++)
|
||||
put_bits(pb, 8, src[i]);
|
||||
flush_put_bits(pb);
|
||||
memcpy(put_bits_ptr(pb), src + i, 2 * words - i);
|
||||
skip_put_bytes(pb, 2 * words - i);
|
||||
}
|
||||
|
||||
put_bits(pb, bits, AV_RB16(src + 2 * words) >> (16 - bits));
|
||||
}
|
||||
|
||||
/* VLC decoding */
|
||||
|
||||
#define GET_DATA(v, table, i, wrap, size) \
|
||||
{ \
|
||||
const uint8_t *ptr = (const uint8_t *)table + i * wrap; \
|
||||
switch(size) { \
|
||||
case 1: \
|
||||
v = *(const uint8_t *)ptr; \
|
||||
break; \
|
||||
case 2: \
|
||||
v = *(const uint16_t *)ptr; \
|
||||
break; \
|
||||
default: \
|
||||
v = *(const uint32_t *)ptr; \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
static int alloc_table(VLC *vlc, int size, int use_static)
|
||||
{
|
||||
int index = vlc->table_size;
|
||||
|
||||
vlc->table_size += size;
|
||||
if (vlc->table_size > vlc->table_allocated) {
|
||||
if (use_static)
|
||||
abort(); // cannot do anything, init_vlc() is used with too little memory
|
||||
vlc->table_allocated += (1 << vlc->bits);
|
||||
vlc->table = av_realloc_f(vlc->table, vlc->table_allocated, sizeof(VLC_TYPE) * 2);
|
||||
if (!vlc->table) {
|
||||
vlc->table_allocated = 0;
|
||||
vlc->table_size = 0;
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
static av_always_inline uint32_t bitswap_32(uint32_t x)
|
||||
{
|
||||
return (uint32_t)ff_reverse[ x & 0xFF] << 24 |
|
||||
(uint32_t)ff_reverse[(x >> 8) & 0xFF] << 16 |
|
||||
(uint32_t)ff_reverse[(x >> 16) & 0xFF] << 8 |
|
||||
(uint32_t)ff_reverse[ x >> 24];
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint8_t bits;
|
||||
uint16_t symbol;
|
||||
/** codeword, with the first bit-to-be-read in the msb
|
||||
* (even if intended for a little-endian bitstream reader) */
|
||||
uint32_t code;
|
||||
} VLCcode;
|
||||
|
||||
static int compare_vlcspec(const void *a, const void *b)
|
||||
{
|
||||
const VLCcode *sa = a, *sb = b;
|
||||
return (sa->code >> 1) - (sb->code >> 1);
|
||||
}
|
||||
/**
|
||||
* Build VLC decoding tables suitable for use with get_vlc().
|
||||
*
|
||||
* @param vlc the context to be initted
|
||||
*
|
||||
* @param table_nb_bits max length of vlc codes to store directly in this table
|
||||
* (Longer codes are delegated to subtables.)
|
||||
*
|
||||
* @param nb_codes number of elements in codes[]
|
||||
*
|
||||
* @param codes descriptions of the vlc codes
|
||||
* These must be ordered such that codes going into the same subtable are contiguous.
|
||||
* Sorting by VLCcode.code is sufficient, though not necessary.
|
||||
*/
|
||||
static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
|
||||
VLCcode *codes, int flags)
|
||||
{
|
||||
int table_size, table_index, index, code_prefix, symbol, subtable_bits;
|
||||
int i, j, k, n, nb, inc;
|
||||
uint32_t code;
|
||||
VLC_TYPE (*table)[2];
|
||||
|
||||
table_size = 1 << table_nb_bits;
|
||||
if (table_nb_bits > 30)
|
||||
return -1;
|
||||
table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC);
|
||||
av_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size);
|
||||
if (table_index < 0)
|
||||
return table_index;
|
||||
table = &vlc->table[table_index];
|
||||
|
||||
for (i = 0; i < table_size; i++) {
|
||||
table[i][1] = 0; //bits
|
||||
table[i][0] = -1; //codes
|
||||
}
|
||||
|
||||
/* first pass: map codes and compute auxiliary table sizes */
|
||||
for (i = 0; i < nb_codes; i++) {
|
||||
n = codes[i].bits;
|
||||
code = codes[i].code;
|
||||
symbol = codes[i].symbol;
|
||||
av_dlog(NULL, "i=%d n=%d code=0x%x\n", i, n, code);
|
||||
if (n <= table_nb_bits) {
|
||||
/* no need to add another table */
|
||||
j = code >> (32 - table_nb_bits);
|
||||
nb = 1 << (table_nb_bits - n);
|
||||
inc = 1;
|
||||
if (flags & INIT_VLC_LE) {
|
||||
j = bitswap_32(code);
|
||||
inc = 1 << n;
|
||||
}
|
||||
for (k = 0; k < nb; k++) {
|
||||
av_dlog(NULL, "%4x: code=%d n=%d\n", j, i, n);
|
||||
if (table[j][1] /*bits*/ != 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
table[j][1] = n; //bits
|
||||
table[j][0] = symbol;
|
||||
j += inc;
|
||||
}
|
||||
} else {
|
||||
/* fill auxiliary table recursively */
|
||||
n -= table_nb_bits;
|
||||
code_prefix = code >> (32 - table_nb_bits);
|
||||
subtable_bits = n;
|
||||
codes[i].bits = n;
|
||||
codes[i].code = code << table_nb_bits;
|
||||
for (k = i+1; k < nb_codes; k++) {
|
||||
n = codes[k].bits - table_nb_bits;
|
||||
if (n <= 0)
|
||||
break;
|
||||
code = codes[k].code;
|
||||
if (code >> (32 - table_nb_bits) != code_prefix)
|
||||
break;
|
||||
codes[k].bits = n;
|
||||
codes[k].code = code << table_nb_bits;
|
||||
subtable_bits = FFMAX(subtable_bits, n);
|
||||
}
|
||||
subtable_bits = FFMIN(subtable_bits, table_nb_bits);
|
||||
j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix;
|
||||
table[j][1] = -subtable_bits;
|
||||
av_dlog(NULL, "%4x: n=%d (subtable)\n",
|
||||
j, codes[i].bits + table_nb_bits);
|
||||
index = build_table(vlc, subtable_bits, k-i, codes+i, flags);
|
||||
if (index < 0)
|
||||
return index;
|
||||
/* note: realloc has been done, so reload tables */
|
||||
table = &vlc->table[table_index];
|
||||
table[j][0] = index; //code
|
||||
av_assert0(table[j][0] == index);
|
||||
i = k-1;
|
||||
}
|
||||
}
|
||||
return table_index;
|
||||
}
|
||||
|
||||
|
||||
/* Build VLC decoding tables suitable for use with get_vlc().
|
||||
|
||||
'nb_bits' set thee decoding table size (2^nb_bits) entries. The
|
||||
bigger it is, the faster is the decoding. But it should not be too
|
||||
big to save memory and L1 cache. '9' is a good compromise.
|
||||
|
||||
'nb_codes' : number of vlcs codes
|
||||
|
||||
'bits' : table which gives the size (in bits) of each vlc code.
|
||||
|
||||
'codes' : table which gives the bit pattern of of each vlc code.
|
||||
|
||||
'symbols' : table which gives the values to be returned from get_vlc().
|
||||
|
||||
'xxx_wrap' : give the number of bytes between each entry of the
|
||||
'bits' or 'codes' tables.
|
||||
|
||||
'xxx_size' : gives the number of bytes of each entry of the 'bits'
|
||||
or 'codes' tables.
|
||||
|
||||
'wrap' and 'size' allows to use any memory configuration and types
|
||||
(byte/word/long) to store the 'bits', 'codes', and 'symbols' tables.
|
||||
|
||||
'use_static' should be set to 1 for tables, which should be freed
|
||||
with av_free_static(), 0 if ff_free_vlc() will be used.
|
||||
*/
|
||||
int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
|
||||
const void *bits, int bits_wrap, int bits_size,
|
||||
const void *codes, int codes_wrap, int codes_size,
|
||||
const void *symbols, int symbols_wrap, int symbols_size,
|
||||
int flags)
|
||||
{
|
||||
VLCcode *buf;
|
||||
int i, j, ret;
|
||||
VLCcode localbuf[1500]; // the maximum currently needed is 1296 by rv34
|
||||
void *state;
|
||||
|
||||
vlc->bits = nb_bits;
|
||||
if (flags & INIT_VLC_USE_NEW_STATIC) {
|
||||
while ((state = avpriv_atomic_ptr_cas(&vlc->init_state, NULL, vlc))) {
|
||||
if (state == vlc + 1) {
|
||||
av_assert0(vlc->table_size && vlc->table_size == vlc->table_allocated);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
av_assert0(!vlc->table_size);
|
||||
av_assert0(nb_codes + 1 <= FF_ARRAY_ELEMS(localbuf));
|
||||
buf = localbuf;
|
||||
} else {
|
||||
vlc->table = NULL;
|
||||
vlc->table_allocated = 0;
|
||||
vlc->table_size = 0;
|
||||
|
||||
buf = av_malloc((nb_codes + 1) * sizeof(VLCcode));
|
||||
if (!buf)
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
|
||||
av_assert0(symbols_size <= 2 || !symbols);
|
||||
j = 0;
|
||||
#define COPY(condition)\
|
||||
for (i = 0; i < nb_codes; i++) { \
|
||||
GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size); \
|
||||
if (!(condition)) \
|
||||
continue; \
|
||||
if (buf[j].bits > 3*nb_bits || buf[j].bits>32) { \
|
||||
av_log(NULL, AV_LOG_ERROR, "Too long VLC (%d) in init_vlc\n", buf[j].bits);\
|
||||
if (!(flags & INIT_VLC_USE_NEW_STATIC)) \
|
||||
av_free(buf); \
|
||||
return -1; \
|
||||
} \
|
||||
GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size); \
|
||||
if (buf[j].code >= (1LL<<buf[j].bits)) { \
|
||||
av_log(NULL, AV_LOG_ERROR, "Invalid code in init_vlc\n"); \
|
||||
if (!(flags & INIT_VLC_USE_NEW_STATIC)) \
|
||||
av_free(buf); \
|
||||
return -1; \
|
||||
} \
|
||||
if (flags & INIT_VLC_LE) \
|
||||
buf[j].code = bitswap_32(buf[j].code); \
|
||||
else \
|
||||
buf[j].code <<= 32 - buf[j].bits; \
|
||||
if (symbols) \
|
||||
GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size) \
|
||||
else \
|
||||
buf[j].symbol = i; \
|
||||
j++; \
|
||||
}
|
||||
COPY(buf[j].bits > nb_bits);
|
||||
// qsort is the slowest part of init_vlc, and could probably be improved or avoided
|
||||
qsort(buf, j, sizeof(VLCcode), compare_vlcspec);
|
||||
COPY(buf[j].bits && buf[j].bits <= nb_bits);
|
||||
nb_codes = j;
|
||||
|
||||
ret = build_table(vlc, nb_bits, nb_codes, buf, flags);
|
||||
|
||||
if (flags & INIT_VLC_USE_NEW_STATIC) {
|
||||
if(vlc->table_size != vlc->table_allocated)
|
||||
av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated);
|
||||
state = avpriv_atomic_ptr_cas(&vlc->init_state, vlc, vlc+1);
|
||||
av_assert0(state == vlc);
|
||||
av_assert0(ret >= 0);
|
||||
} else {
|
||||
av_free(buf);
|
||||
if (ret < 0) {
|
||||
av_freep(&vlc->table);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void ff_free_vlc(VLC *vlc)
|
||||
{
|
||||
av_freep(&vlc->table);
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "avcodec.h"
|
||||
#include "libavutil/atomic.h"
|
||||
#include "libavutil/mem.h"
|
||||
|
||||
static AVBitStreamFilter *first_bitstream_filter = NULL;
|
||||
|
||||
AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f)
|
||||
{
|
||||
if (f)
|
||||
return f->next;
|
||||
else
|
||||
return first_bitstream_filter;
|
||||
}
|
||||
|
||||
void av_register_bitstream_filter(AVBitStreamFilter *bsf)
|
||||
{
|
||||
do {
|
||||
bsf->next = first_bitstream_filter;
|
||||
} while(bsf->next != avpriv_atomic_ptr_cas((void * volatile *)&first_bitstream_filter, bsf->next, bsf));
|
||||
}
|
||||
|
||||
AVBitStreamFilterContext *av_bitstream_filter_init(const char *name)
|
||||
{
|
||||
AVBitStreamFilter *bsf = first_bitstream_filter;
|
||||
|
||||
while (bsf) {
|
||||
if (!strcmp(name, bsf->name)) {
|
||||
AVBitStreamFilterContext *bsfc =
|
||||
av_mallocz(sizeof(AVBitStreamFilterContext));
|
||||
bsfc->filter = bsf;
|
||||
bsfc->priv_data =
|
||||
bsf->priv_data_size ? av_mallocz(bsf->priv_data_size) : NULL;
|
||||
return bsfc;
|
||||
}
|
||||
bsf = bsf->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc)
|
||||
{
|
||||
if (!bsfc)
|
||||
return;
|
||||
if (bsfc->filter->close)
|
||||
bsfc->filter->close(bsfc);
|
||||
av_freep(&bsfc->priv_data);
|
||||
av_parser_close(bsfc->parser);
|
||||
av_free(bsfc);
|
||||
}
|
||||
|
||||
int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
|
||||
AVCodecContext *avctx, const char *args,
|
||||
uint8_t **poutbuf, int *poutbuf_size,
|
||||
const uint8_t *buf, int buf_size, int keyframe)
|
||||
{
|
||||
*poutbuf = (uint8_t *)buf;
|
||||
*poutbuf_size = buf_size;
|
||||
return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size,
|
||||
buf, buf_size, keyframe);
|
||||
}
|
|
@ -1,348 +0,0 @@
|
|||
/*
|
||||
* Bytestream functions
|
||||
* copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
|
||||
* Copyright (c) 2012 Aneesh Dogra (lionaneesh) <lionaneesh@gmail.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_BYTESTREAM_H
|
||||
#define AVCODEC_BYTESTREAM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libavutil/avassert.h"
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/intreadwrite.h"
|
||||
|
||||
typedef struct GetByteContext {
|
||||
const uint8_t *buffer, *buffer_end, *buffer_start;
|
||||
} GetByteContext;
|
||||
|
||||
typedef struct PutByteContext {
|
||||
uint8_t *buffer, *buffer_end, *buffer_start;
|
||||
int eof;
|
||||
} PutByteContext;
|
||||
|
||||
#define DEF(type, name, bytes, read, write) \
|
||||
static av_always_inline type bytestream_get_ ## name(const uint8_t **b) \
|
||||
{ \
|
||||
(*b) += bytes; \
|
||||
return read(*b - bytes); \
|
||||
} \
|
||||
static av_always_inline void bytestream_put_ ## name(uint8_t **b, \
|
||||
const type value) \
|
||||
{ \
|
||||
write(*b, value); \
|
||||
(*b) += bytes; \
|
||||
} \
|
||||
static av_always_inline void bytestream2_put_ ## name ## u(PutByteContext *p, \
|
||||
const type value) \
|
||||
{ \
|
||||
bytestream_put_ ## name(&p->buffer, value); \
|
||||
} \
|
||||
static av_always_inline void bytestream2_put_ ## name(PutByteContext *p, \
|
||||
const type value) \
|
||||
{ \
|
||||
if (!p->eof && (p->buffer_end - p->buffer >= bytes)) { \
|
||||
write(p->buffer, value); \
|
||||
p->buffer += bytes; \
|
||||
} else \
|
||||
p->eof = 1; \
|
||||
} \
|
||||
static av_always_inline type bytestream2_get_ ## name ## u(GetByteContext *g) \
|
||||
{ \
|
||||
return bytestream_get_ ## name(&g->buffer); \
|
||||
} \
|
||||
static av_always_inline type bytestream2_get_ ## name(GetByteContext *g) \
|
||||
{ \
|
||||
if (g->buffer_end - g->buffer < bytes) \
|
||||
return 0; \
|
||||
return bytestream2_get_ ## name ## u(g); \
|
||||
} \
|
||||
static av_always_inline type bytestream2_peek_ ## name(GetByteContext *g) \
|
||||
{ \
|
||||
if (g->buffer_end - g->buffer < bytes) \
|
||||
return 0; \
|
||||
return read(g->buffer); \
|
||||
}
|
||||
|
||||
DEF(uint64_t, le64, 8, AV_RL64, AV_WL64)
|
||||
DEF(unsigned int, le32, 4, AV_RL32, AV_WL32)
|
||||
DEF(unsigned int, le24, 3, AV_RL24, AV_WL24)
|
||||
DEF(unsigned int, le16, 2, AV_RL16, AV_WL16)
|
||||
DEF(uint64_t, be64, 8, AV_RB64, AV_WB64)
|
||||
DEF(unsigned int, be32, 4, AV_RB32, AV_WB32)
|
||||
DEF(unsigned int, be24, 3, AV_RB24, AV_WB24)
|
||||
DEF(unsigned int, be16, 2, AV_RB16, AV_WB16)
|
||||
DEF(unsigned int, byte, 1, AV_RB8 , AV_WB8)
|
||||
|
||||
#if HAVE_BIGENDIAN
|
||||
# define bytestream2_get_ne16 bytestream2_get_be16
|
||||
# define bytestream2_get_ne24 bytestream2_get_be24
|
||||
# define bytestream2_get_ne32 bytestream2_get_be32
|
||||
# define bytestream2_get_ne64 bytestream2_get_be64
|
||||
# define bytestream2_get_ne16u bytestream2_get_be16u
|
||||
# define bytestream2_get_ne24u bytestream2_get_be24u
|
||||
# define bytestream2_get_ne32u bytestream2_get_be32u
|
||||
# define bytestream2_get_ne64u bytestream2_get_be64u
|
||||
# define bytestream2_put_ne16 bytestream2_put_be16
|
||||
# define bytestream2_put_ne24 bytestream2_put_be24
|
||||
# define bytestream2_put_ne32 bytestream2_put_be32
|
||||
# define bytestream2_put_ne64 bytestream2_put_be64
|
||||
# define bytestream2_peek_ne16 bytestream2_peek_be16
|
||||
# define bytestream2_peek_ne24 bytestream2_peek_be24
|
||||
# define bytestream2_peek_ne32 bytestream2_peek_be32
|
||||
# define bytestream2_peek_ne64 bytestream2_peek_be64
|
||||
#else
|
||||
# define bytestream2_get_ne16 bytestream2_get_le16
|
||||
# define bytestream2_get_ne24 bytestream2_get_le24
|
||||
# define bytestream2_get_ne32 bytestream2_get_le32
|
||||
# define bytestream2_get_ne64 bytestream2_get_le64
|
||||
# define bytestream2_get_ne16u bytestream2_get_le16u
|
||||
# define bytestream2_get_ne24u bytestream2_get_le24u
|
||||
# define bytestream2_get_ne32u bytestream2_get_le32u
|
||||
# define bytestream2_get_ne64u bytestream2_get_le64u
|
||||
# define bytestream2_put_ne16 bytestream2_put_le16
|
||||
# define bytestream2_put_ne24 bytestream2_put_le24
|
||||
# define bytestream2_put_ne32 bytestream2_put_le32
|
||||
# define bytestream2_put_ne64 bytestream2_put_le64
|
||||
# define bytestream2_peek_ne16 bytestream2_peek_le16
|
||||
# define bytestream2_peek_ne24 bytestream2_peek_le24
|
||||
# define bytestream2_peek_ne32 bytestream2_peek_le32
|
||||
# define bytestream2_peek_ne64 bytestream2_peek_le64
|
||||
#endif
|
||||
|
||||
static av_always_inline void bytestream2_init(GetByteContext *g,
|
||||
const uint8_t *buf,
|
||||
int buf_size)
|
||||
{
|
||||
av_assert0(buf_size >= 0);
|
||||
g->buffer = buf;
|
||||
g->buffer_start = buf;
|
||||
g->buffer_end = buf + buf_size;
|
||||
}
|
||||
|
||||
static av_always_inline void bytestream2_init_writer(PutByteContext *p,
|
||||
uint8_t *buf,
|
||||
int buf_size)
|
||||
{
|
||||
av_assert0(buf_size >= 0);
|
||||
p->buffer = buf;
|
||||
p->buffer_start = buf;
|
||||
p->buffer_end = buf + buf_size;
|
||||
p->eof = 0;
|
||||
}
|
||||
|
||||
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
|
||||
{
|
||||
return g->buffer_end - g->buffer;
|
||||
}
|
||||
|
||||
static av_always_inline unsigned int bytestream2_get_bytes_left_p(PutByteContext *p)
|
||||
{
|
||||
return p->buffer_end - p->buffer;
|
||||
}
|
||||
|
||||
static av_always_inline void bytestream2_skip(GetByteContext *g,
|
||||
unsigned int size)
|
||||
{
|
||||
g->buffer += FFMIN(g->buffer_end - g->buffer, size);
|
||||
}
|
||||
|
||||
static av_always_inline void bytestream2_skipu(GetByteContext *g,
|
||||
unsigned int size)
|
||||
{
|
||||
g->buffer += size;
|
||||
}
|
||||
|
||||
static av_always_inline void bytestream2_skip_p(PutByteContext *p,
|
||||
unsigned int size)
|
||||
{
|
||||
int size2;
|
||||
if (p->eof)
|
||||
return;
|
||||
size2 = FFMIN(p->buffer_end - p->buffer, size);
|
||||
if (size2 != size)
|
||||
p->eof = 1;
|
||||
p->buffer += size2;
|
||||
}
|
||||
|
||||
static av_always_inline int bytestream2_tell(GetByteContext *g)
|
||||
{
|
||||
return (int)(g->buffer - g->buffer_start);
|
||||
}
|
||||
|
||||
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
|
||||
{
|
||||
return (int)(p->buffer - p->buffer_start);
|
||||
}
|
||||
|
||||
static av_always_inline int bytestream2_size(GetByteContext *g)
|
||||
{
|
||||
return (int)(g->buffer_end - g->buffer_start);
|
||||
}
|
||||
|
||||
static av_always_inline int bytestream2_size_p(PutByteContext *p)
|
||||
{
|
||||
return (int)(p->buffer_end - p->buffer_start);
|
||||
}
|
||||
|
||||
static av_always_inline int bytestream2_seek(GetByteContext *g,
|
||||
int offset,
|
||||
int whence)
|
||||
{
|
||||
switch (whence) {
|
||||
case SEEK_CUR:
|
||||
offset = av_clip(offset, -(g->buffer - g->buffer_start),
|
||||
g->buffer_end - g->buffer);
|
||||
g->buffer += offset;
|
||||
break;
|
||||
case SEEK_END:
|
||||
offset = av_clip(offset, -(g->buffer_end - g->buffer_start), 0);
|
||||
g->buffer = g->buffer_end + offset;
|
||||
break;
|
||||
case SEEK_SET:
|
||||
offset = av_clip(offset, 0, g->buffer_end - g->buffer_start);
|
||||
g->buffer = g->buffer_start + offset;
|
||||
break;
|
||||
default:
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
return bytestream2_tell(g);
|
||||
}
|
||||
|
||||
static av_always_inline int bytestream2_seek_p(PutByteContext *p,
|
||||
int offset,
|
||||
int whence)
|
||||
{
|
||||
p->eof = 0;
|
||||
switch (whence) {
|
||||
case SEEK_CUR:
|
||||
if (p->buffer_end - p->buffer < offset)
|
||||
p->eof = 1;
|
||||
offset = av_clip(offset, -(p->buffer - p->buffer_start),
|
||||
p->buffer_end - p->buffer);
|
||||
p->buffer += offset;
|
||||
break;
|
||||
case SEEK_END:
|
||||
if (offset > 0)
|
||||
p->eof = 1;
|
||||
offset = av_clip(offset, -(p->buffer_end - p->buffer_start), 0);
|
||||
p->buffer = p->buffer_end + offset;
|
||||
break;
|
||||
case SEEK_SET:
|
||||
if (p->buffer_end - p->buffer_start < offset)
|
||||
p->eof = 1;
|
||||
offset = av_clip(offset, 0, p->buffer_end - p->buffer_start);
|
||||
p->buffer = p->buffer_start + offset;
|
||||
break;
|
||||
default:
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
return bytestream2_tell_p(p);
|
||||
}
|
||||
|
||||
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g,
|
||||
uint8_t *dst,
|
||||
unsigned int size)
|
||||
{
|
||||
int size2 = FFMIN(g->buffer_end - g->buffer, size);
|
||||
memcpy(dst, g->buffer, size2);
|
||||
g->buffer += size2;
|
||||
return size2;
|
||||
}
|
||||
|
||||
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g,
|
||||
uint8_t *dst,
|
||||
unsigned int size)
|
||||
{
|
||||
memcpy(dst, g->buffer, size);
|
||||
g->buffer += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p,
|
||||
const uint8_t *src,
|
||||
unsigned int size)
|
||||
{
|
||||
int size2;
|
||||
if (p->eof)
|
||||
return 0;
|
||||
size2 = FFMIN(p->buffer_end - p->buffer, size);
|
||||
if (size2 != size)
|
||||
p->eof = 1;
|
||||
memcpy(p->buffer, src, size2);
|
||||
p->buffer += size2;
|
||||
return size2;
|
||||
}
|
||||
|
||||
static av_always_inline unsigned int bytestream2_put_bufferu(PutByteContext *p,
|
||||
const uint8_t *src,
|
||||
unsigned int size)
|
||||
{
|
||||
memcpy(p->buffer, src, size);
|
||||
p->buffer += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
static av_always_inline void bytestream2_set_buffer(PutByteContext *p,
|
||||
const uint8_t c,
|
||||
unsigned int size)
|
||||
{
|
||||
int size2;
|
||||
if (p->eof)
|
||||
return;
|
||||
size2 = FFMIN(p->buffer_end - p->buffer, size);
|
||||
if (size2 != size)
|
||||
p->eof = 1;
|
||||
memset(p->buffer, c, size2);
|
||||
p->buffer += size2;
|
||||
}
|
||||
|
||||
static av_always_inline void bytestream2_set_bufferu(PutByteContext *p,
|
||||
const uint8_t c,
|
||||
unsigned int size)
|
||||
{
|
||||
memset(p->buffer, c, size);
|
||||
p->buffer += size;
|
||||
}
|
||||
|
||||
static av_always_inline unsigned int bytestream2_get_eof(PutByteContext *p)
|
||||
{
|
||||
return p->eof;
|
||||
}
|
||||
|
||||
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b,
|
||||
uint8_t *dst,
|
||||
unsigned int size)
|
||||
{
|
||||
memcpy(dst, *b, size);
|
||||
(*b) += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
static av_always_inline void bytestream_put_buffer(uint8_t **b,
|
||||
const uint8_t *src,
|
||||
unsigned int size)
|
||||
{
|
||||
memcpy(*b, src, size);
|
||||
(*b) += size;
|
||||
}
|
||||
|
||||
#endif /* AVCODEC_BYTESTREAM_H */
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Header file for hardcoded AAC cube-root table
|
||||
*
|
||||
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_CBRT_TABLEGEN_H
|
||||
#define AVCODEC_CBRT_TABLEGEN_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#if CONFIG_HARDCODED_TABLES
|
||||
#define cbrt_tableinit()
|
||||
#include "libavcodec/cbrt_tables.h"
|
||||
#else
|
||||
static uint32_t cbrt_tab[1 << 13];
|
||||
|
||||
static void cbrt_tableinit(void)
|
||||
{
|
||||
if (!cbrt_tab[(1<<13) - 1]) {
|
||||
int i;
|
||||
for (i = 0; i < 1<<13; i++) {
|
||||
union {
|
||||
float f;
|
||||
uint32_t i;
|
||||
} f;
|
||||
f.f = cbrtf(i) * i;
|
||||
cbrt_tab[i] = f.i;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_HARDCODED_TABLES */
|
||||
|
||||
#endif /* AVCODEC_CBRT_TABLEGEN_H */
|
|
@ -1,221 +0,0 @@
|
|||
/*
|
||||
* various filters for ACELP-based codecs
|
||||
*
|
||||
* Copyright (c) 2008 Vladimir Voroshilov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "avcodec.h"
|
||||
#include "celp_filters.h"
|
||||
#include "libavutil/avassert.h"
|
||||
#include "libavutil/common.h"
|
||||
|
||||
void ff_celp_convolve_circ(int16_t* fc_out, const int16_t* fc_in,
|
||||
const int16_t* filter, int len)
|
||||
{
|
||||
int i, k;
|
||||
|
||||
memset(fc_out, 0, len * sizeof(int16_t));
|
||||
|
||||
/* Since there are few pulses over an entire subframe (i.e. almost
|
||||
all fc_in[i] are zero) it is faster to loop over fc_in first. */
|
||||
for (i = 0; i < len; i++) {
|
||||
if (fc_in[i]) {
|
||||
for (k = 0; k < i; k++)
|
||||
fc_out[k] += (fc_in[i] * filter[len + k - i]) >> 15;
|
||||
|
||||
for (k = i; k < len; k++)
|
||||
fc_out[k] += (fc_in[i] * filter[ k - i]) >> 15;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ff_celp_circ_addf(float *out, const float *in,
|
||||
const float *lagged, int lag, float fac, int n)
|
||||
{
|
||||
int k;
|
||||
for (k = 0; k < lag; k++)
|
||||
out[k] = in[k] + fac * lagged[n + k - lag];
|
||||
for (; k < n; k++)
|
||||
out[k] = in[k] + fac * lagged[ k - lag];
|
||||
}
|
||||
|
||||
int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs,
|
||||
const int16_t *in, int buffer_length,
|
||||
int filter_length, int stop_on_overflow,
|
||||
int shift, int rounder)
|
||||
{
|
||||
int i,n;
|
||||
|
||||
for (n = 0; n < buffer_length; n++) {
|
||||
int sum = -rounder, sum1;
|
||||
for (i = 1; i <= filter_length; i++)
|
||||
sum += filter_coeffs[i-1] * out[n-i];
|
||||
|
||||
sum1 = ((-sum >> 12) + in[n]) >> shift;
|
||||
sum = av_clip_int16(sum1);
|
||||
|
||||
if (stop_on_overflow && sum != sum1)
|
||||
return 1;
|
||||
|
||||
out[n] = sum;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs,
|
||||
const float* in, int buffer_length,
|
||||
int filter_length)
|
||||
{
|
||||
int i,n;
|
||||
|
||||
#if 0 // Unoptimized code path for improved readability
|
||||
for (n = 0; n < buffer_length; n++) {
|
||||
out[n] = in[n];
|
||||
for (i = 1; i <= filter_length; i++)
|
||||
out[n] -= filter_coeffs[i-1] * out[n-i];
|
||||
}
|
||||
#else
|
||||
float out0, out1, out2, out3;
|
||||
float old_out0, old_out1, old_out2, old_out3;
|
||||
float a,b,c;
|
||||
|
||||
a = filter_coeffs[0];
|
||||
b = filter_coeffs[1];
|
||||
c = filter_coeffs[2];
|
||||
b -= filter_coeffs[0] * filter_coeffs[0];
|
||||
c -= filter_coeffs[1] * filter_coeffs[0];
|
||||
c -= filter_coeffs[0] * b;
|
||||
|
||||
av_assert2((filter_length&1)==0 && filter_length>=4);
|
||||
|
||||
old_out0 = out[-4];
|
||||
old_out1 = out[-3];
|
||||
old_out2 = out[-2];
|
||||
old_out3 = out[-1];
|
||||
for (n = 0; n <= buffer_length - 4; n+=4) {
|
||||
float tmp0,tmp1,tmp2;
|
||||
float val;
|
||||
|
||||
out0 = in[0];
|
||||
out1 = in[1];
|
||||
out2 = in[2];
|
||||
out3 = in[3];
|
||||
|
||||
out0 -= filter_coeffs[2] * old_out1;
|
||||
out1 -= filter_coeffs[2] * old_out2;
|
||||
out2 -= filter_coeffs[2] * old_out3;
|
||||
|
||||
out0 -= filter_coeffs[1] * old_out2;
|
||||
out1 -= filter_coeffs[1] * old_out3;
|
||||
|
||||
out0 -= filter_coeffs[0] * old_out3;
|
||||
|
||||
val = filter_coeffs[3];
|
||||
|
||||
out0 -= val * old_out0;
|
||||
out1 -= val * old_out1;
|
||||
out2 -= val * old_out2;
|
||||
out3 -= val * old_out3;
|
||||
|
||||
for (i = 5; i < filter_length; i += 2) {
|
||||
old_out3 = out[-i];
|
||||
val = filter_coeffs[i-1];
|
||||
|
||||
out0 -= val * old_out3;
|
||||
out1 -= val * old_out0;
|
||||
out2 -= val * old_out1;
|
||||
out3 -= val * old_out2;
|
||||
|
||||
old_out2 = out[-i-1];
|
||||
|
||||
val = filter_coeffs[i];
|
||||
|
||||
out0 -= val * old_out2;
|
||||
out1 -= val * old_out3;
|
||||
out2 -= val * old_out0;
|
||||
out3 -= val * old_out1;
|
||||
|
||||
FFSWAP(float, old_out0, old_out2);
|
||||
old_out1 = old_out3;
|
||||
}
|
||||
|
||||
tmp0 = out0;
|
||||
tmp1 = out1;
|
||||
tmp2 = out2;
|
||||
|
||||
out3 -= a * tmp2;
|
||||
out2 -= a * tmp1;
|
||||
out1 -= a * tmp0;
|
||||
|
||||
out3 -= b * tmp1;
|
||||
out2 -= b * tmp0;
|
||||
|
||||
out3 -= c * tmp0;
|
||||
|
||||
|
||||
out[0] = out0;
|
||||
out[1] = out1;
|
||||
out[2] = out2;
|
||||
out[3] = out3;
|
||||
|
||||
old_out0 = out0;
|
||||
old_out1 = out1;
|
||||
old_out2 = out2;
|
||||
old_out3 = out3;
|
||||
|
||||
out += 4;
|
||||
in += 4;
|
||||
}
|
||||
|
||||
out -= n;
|
||||
in -= n;
|
||||
for (; n < buffer_length; n++) {
|
||||
out[n] = in[n];
|
||||
for (i = 1; i <= filter_length; i++)
|
||||
out[n] -= filter_coeffs[i-1] * out[n-i];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ff_celp_lp_zero_synthesis_filterf(float *out, const float *filter_coeffs,
|
||||
const float *in, int buffer_length,
|
||||
int filter_length)
|
||||
{
|
||||
int i,n;
|
||||
|
||||
for (n = 0; n < buffer_length; n++) {
|
||||
out[n] = in[n];
|
||||
for (i = 1; i <= filter_length; i++)
|
||||
out[n] += filter_coeffs[i-1] * in[n-i];
|
||||
}
|
||||
}
|
||||
|
||||
void ff_celp_filter_init(CELPFContext *c)
|
||||
{
|
||||
c->celp_lp_synthesis_filterf = ff_celp_lp_synthesis_filterf;
|
||||
c->celp_lp_zero_synthesis_filterf = ff_celp_lp_zero_synthesis_filterf;
|
||||
|
||||
if(HAVE_MIPSFPU)
|
||||
ff_celp_filter_init_mips(c);
|
||||
}
|
|
@ -1,169 +0,0 @@
|
|||
/*
|
||||
* various filters for CELP-based codecs
|
||||
*
|
||||
* Copyright (c) 2008 Vladimir Voroshilov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_CELP_FILTERS_H
|
||||
#define AVCODEC_CELP_FILTERS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct CELPFContext {
|
||||
/**
|
||||
* LP synthesis filter.
|
||||
* @param[out] out pointer to output buffer
|
||||
* - the array out[-filter_length, -1] must
|
||||
* contain the previous result of this filter
|
||||
* @param filter_coeffs filter coefficients.
|
||||
* @param in input signal
|
||||
* @param buffer_length amount of data to process
|
||||
* @param filter_length filter length (10 for 10th order LP filter). Must be
|
||||
* greater than 4 and even.
|
||||
*
|
||||
* @note Output buffer must contain filter_length samples of past
|
||||
* speech data before pointer.
|
||||
*
|
||||
* Routine applies 1/A(z) filter to given speech data.
|
||||
*/
|
||||
void (*celp_lp_synthesis_filterf)(float *out, const float *filter_coeffs,
|
||||
const float *in, int buffer_length,
|
||||
int filter_length);
|
||||
|
||||
/**
|
||||
* LP zero synthesis filter.
|
||||
* @param[out] out pointer to output buffer
|
||||
* @param filter_coeffs filter coefficients.
|
||||
* @param in input signal
|
||||
* - the array in[-filter_length, -1] must
|
||||
* contain the previous input of this filter
|
||||
* @param buffer_length amount of data to process (should be a multiple of eight)
|
||||
* @param filter_length filter length (10 for 10th order LP filter;
|
||||
* should be a multiple of two)
|
||||
*
|
||||
* @note Output buffer must contain filter_length samples of past
|
||||
* speech data before pointer.
|
||||
*
|
||||
* Routine applies A(z) filter to given speech data.
|
||||
*/
|
||||
void (*celp_lp_zero_synthesis_filterf)(float *out, const float *filter_coeffs,
|
||||
const float *in, int buffer_length,
|
||||
int filter_length);
|
||||
|
||||
}CELPFContext;
|
||||
|
||||
/**
|
||||
* Initialize CELPFContext.
|
||||
*/
|
||||
void ff_celp_filter_init(CELPFContext *c);
|
||||
void ff_celp_filter_init_mips(CELPFContext *c);
|
||||
|
||||
/**
|
||||
* Circularly convolve fixed vector with a phase dispersion impulse
|
||||
* response filter (D.6.2 of G.729 and 6.1.5 of AMR).
|
||||
* @param fc_out vector with filter applied
|
||||
* @param fc_in source vector
|
||||
* @param filter phase filter coefficients
|
||||
*
|
||||
* fc_out[n] = sum(i,0,len-1){ fc_in[i] * filter[(len + n - i)%len] }
|
||||
*
|
||||
* @note fc_in and fc_out should not overlap!
|
||||
*/
|
||||
void ff_celp_convolve_circ(int16_t *fc_out, const int16_t *fc_in,
|
||||
const int16_t *filter, int len);
|
||||
|
||||
/**
|
||||
* Add an array to a rotated array.
|
||||
*
|
||||
* out[k] = in[k] + fac * lagged[k-lag] with wrap-around
|
||||
*
|
||||
* @param out result vector
|
||||
* @param in samples to be added unfiltered
|
||||
* @param lagged samples to be rotated, multiplied and added
|
||||
* @param lag lagged vector delay in the range [0, n]
|
||||
* @param fac scalefactor for lagged samples
|
||||
* @param n number of samples
|
||||
*/
|
||||
void ff_celp_circ_addf(float *out, const float *in,
|
||||
const float *lagged, int lag, float fac, int n);
|
||||
|
||||
/**
|
||||
* LP synthesis filter.
|
||||
* @param[out] out pointer to output buffer
|
||||
* @param filter_coeffs filter coefficients (-0x8000 <= (3.12) < 0x8000)
|
||||
* @param in input signal
|
||||
* @param buffer_length amount of data to process
|
||||
* @param filter_length filter length (10 for 10th order LP filter)
|
||||
* @param stop_on_overflow 1 - return immediately if overflow occurs
|
||||
* 0 - ignore overflows
|
||||
* @param shift the result is shifted right by this value
|
||||
* @param rounder the amount to add for rounding (usually 0x800 or 0xfff)
|
||||
*
|
||||
* @return 1 if overflow occurred, 0 - otherwise
|
||||
*
|
||||
* @note Output buffer must contain filter_length samples of past
|
||||
* speech data before pointer.
|
||||
*
|
||||
* Routine applies 1/A(z) filter to given speech data.
|
||||
*/
|
||||
int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs,
|
||||
const int16_t *in, int buffer_length,
|
||||
int filter_length, int stop_on_overflow,
|
||||
int shift, int rounder);
|
||||
|
||||
/**
|
||||
* LP synthesis filter.
|
||||
* @param[out] out pointer to output buffer
|
||||
* - the array out[-filter_length, -1] must
|
||||
* contain the previous result of this filter
|
||||
* @param filter_coeffs filter coefficients.
|
||||
* @param in input signal
|
||||
* @param buffer_length amount of data to process
|
||||
* @param filter_length filter length (10 for 10th order LP filter). Must be
|
||||
* greater than 4 and even.
|
||||
*
|
||||
* @note Output buffer must contain filter_length samples of past
|
||||
* speech data before pointer.
|
||||
*
|
||||
* Routine applies 1/A(z) filter to given speech data.
|
||||
*/
|
||||
void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs,
|
||||
const float *in, int buffer_length,
|
||||
int filter_length);
|
||||
|
||||
/**
|
||||
* LP zero synthesis filter.
|
||||
* @param[out] out pointer to output buffer
|
||||
* @param filter_coeffs filter coefficients.
|
||||
* @param in input signal
|
||||
* - the array in[-filter_length, -1] must
|
||||
* contain the previous input of this filter
|
||||
* @param buffer_length amount of data to process
|
||||
* @param filter_length filter length (10 for 10th order LP filter)
|
||||
*
|
||||
* @note Output buffer must contain filter_length samples of past
|
||||
* speech data before pointer.
|
||||
*
|
||||
* Routine applies A(z) filter to given speech data.
|
||||
*/
|
||||
void ff_celp_lp_zero_synthesis_filterf(float *out, const float *filter_coeffs,
|
||||
const float *in, int buffer_length,
|
||||
int filter_length);
|
||||
|
||||
#endif /* AVCODEC_CELP_FILTERS_H */
|
|
@ -1,126 +0,0 @@
|
|||
/*
|
||||
* Various fixed-point math operations
|
||||
*
|
||||
* Copyright (c) 2008 Vladimir Voroshilov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "libavutil/avassert.h"
|
||||
#include "avcodec.h"
|
||||
#include "mathops.h"
|
||||
#include "celp_math.h"
|
||||
#include "libavutil/common.h"
|
||||
|
||||
static const uint16_t exp2a[]=
|
||||
{
|
||||
0, 1435, 2901, 4400, 5931, 7496, 9096, 10730,
|
||||
12400, 14106, 15850, 17632, 19454, 21315, 23216, 25160,
|
||||
27146, 29175, 31249, 33368, 35534, 37747, 40009, 42320,
|
||||
44682, 47095, 49562, 52082, 54657, 57289, 59979, 62727,
|
||||
};
|
||||
|
||||
static const uint16_t exp2b[]=
|
||||
{
|
||||
3, 712, 1424, 2134, 2845, 3557, 4270, 4982,
|
||||
5696, 6409, 7124, 7839, 8554, 9270, 9986, 10704,
|
||||
11421, 12138, 12857, 13576, 14295, 15014, 15734, 16455,
|
||||
17176, 17898, 18620, 19343, 20066, 20790, 21514, 22238,
|
||||
};
|
||||
|
||||
int ff_exp2(uint16_t power)
|
||||
{
|
||||
unsigned int result= exp2a[power>>10] + 0x10000;
|
||||
|
||||
av_assert2(power <= 0x7fff);
|
||||
|
||||
result= (result<<3) + ((result*exp2b[(power>>5)&31])>>17);
|
||||
return result + ((result*(power&31)*89)>>22);
|
||||
}
|
||||
|
||||
/**
|
||||
* Table used to compute log2(x)
|
||||
*
|
||||
* tab_log2[i] = (1<<15) * log2(1 + i/32), i=0..32
|
||||
*/
|
||||
static const uint16_t tab_log2[33] =
|
||||
{
|
||||
#ifdef G729_BITEXACT
|
||||
0, 1455, 2866, 4236, 5568, 6863, 8124, 9352,
|
||||
10549, 11716, 12855, 13967, 15054, 16117, 17156, 18172,
|
||||
19167, 20142, 21097, 22033, 22951, 23852, 24735, 25603,
|
||||
26455, 27291, 28113, 28922, 29716, 30497, 31266, 32023, 32767,
|
||||
#else
|
||||
4, 1459, 2870, 4240, 5572, 6867, 8127, 9355,
|
||||
10552, 11719, 12858, 13971, 15057, 16120, 17158, 18175,
|
||||
19170, 20145, 21100, 22036, 22954, 23854, 24738, 25605,
|
||||
26457, 27294, 28116, 28924, 29719, 30500, 31269, 32025, 32769,
|
||||
#endif
|
||||
};
|
||||
|
||||
int ff_log2_q15(uint32_t value)
|
||||
{
|
||||
uint8_t power_int;
|
||||
uint8_t frac_x0;
|
||||
uint16_t frac_dx;
|
||||
|
||||
// Stripping zeros from beginning
|
||||
power_int = av_log2(value);
|
||||
value <<= (31 - power_int);
|
||||
|
||||
// b31 is always non-zero now
|
||||
frac_x0 = (value & 0x7c000000) >> 26; // b26-b31 and [32..63] -> [0..31]
|
||||
frac_dx = (value & 0x03fff800) >> 11;
|
||||
|
||||
value = tab_log2[frac_x0];
|
||||
value += (frac_dx * (tab_log2[frac_x0+1] - tab_log2[frac_x0])) >> 15;
|
||||
|
||||
return (power_int << 15) + value;
|
||||
}
|
||||
|
||||
int64_t ff_dot_product(const int16_t *a, const int16_t *b, int length)
|
||||
{
|
||||
int i;
|
||||
int64_t sum = 0;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
sum += MUL16(a[i], b[i]);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
float ff_dot_productf(const float* a, const float* b, int length)
|
||||
{
|
||||
float sum = 0;
|
||||
int i;
|
||||
|
||||
for(i=0; i<length; i++)
|
||||
sum += a[i] * b[i];
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
void ff_celp_math_init(CELPMContext *c)
|
||||
{
|
||||
c->dot_productf = ff_dot_productf;
|
||||
|
||||
if(HAVE_MIPSFPU)
|
||||
ff_celp_math_init_mips(c);
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* Various fixed-point math operations
|
||||
*
|
||||
* Copyright (c) 2008 Vladimir Voroshilov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_CELP_MATH_H
|
||||
#define AVCODEC_CELP_MATH_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct CELPMContext {
|
||||
/**
|
||||
* Return the dot product.
|
||||
* @param a input data array
|
||||
* @param b input data array
|
||||
* @param length number of elements
|
||||
*
|
||||
* @return dot product = sum of elementwise products
|
||||
*/
|
||||
float (*dot_productf)(const float* a, const float* b, int length);
|
||||
|
||||
}CELPMContext;
|
||||
|
||||
/**
|
||||
* Initialize CELPMContext.
|
||||
*/
|
||||
void ff_celp_math_init(CELPMContext *c);
|
||||
void ff_celp_math_init_mips(CELPMContext *c);
|
||||
|
||||
/**
|
||||
* fixed-point implementation of exp2(x) in [0; 1] domain.
|
||||
* @param power argument to exp2, 0 <= power <= 0x7fff
|
||||
*
|
||||
* @return value of (1<<20) * exp2(power / (1<<15))
|
||||
* 0x8000c <= result <= 0xfffea
|
||||
*/
|
||||
int ff_exp2(uint16_t power);
|
||||
|
||||
/**
|
||||
* Calculate log2(x).
|
||||
* @param value function argument, 0 < value <= 7fff ffff
|
||||
*
|
||||
* @return value of (1<<15) * log2(value)
|
||||
*/
|
||||
int ff_log2_q15(uint32_t value);
|
||||
|
||||
/**
|
||||
* Shift value left or right depending on sign of offset parameter.
|
||||
* @param value value to shift
|
||||
* @param offset shift offset
|
||||
*
|
||||
* @return value << offset, if offset>=0; value >> -offset - otherwise
|
||||
*/
|
||||
static inline int bidir_sal(int value, int offset)
|
||||
{
|
||||
if(offset < 0) return value >> -offset;
|
||||
else return value << offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the dot product of 2 int16_t vectors.
|
||||
* @param a input data array
|
||||
* @param b input data array
|
||||
* @param length number of elements
|
||||
*
|
||||
* @return dot product = sum of elementwise products
|
||||
*/
|
||||
int64_t ff_dot_product(const int16_t *a, const int16_t *b, int length);
|
||||
|
||||
/**
|
||||
* Return the dot product.
|
||||
* @param a input data array
|
||||
* @param b input data array
|
||||
* @param length number of elements
|
||||
*
|
||||
* @return dot product = sum of elementwise products
|
||||
*/
|
||||
float ff_dot_productf(const float* a, const float* b, int length);
|
||||
|
||||
#endif /* AVCODEC_CELP_MATH_H */
|
File diff suppressed because it is too large
Load diff
|
@ -1,94 +0,0 @@
|
|||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_COPY_BLOCK_H
|
||||
#define AVCODEC_COPY_BLOCK_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libavutil/intreadwrite.h"
|
||||
|
||||
static inline void copy_block2(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<h; i++)
|
||||
{
|
||||
AV_COPY16U(dst, src);
|
||||
dst+=dstStride;
|
||||
src+=srcStride;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void copy_block4(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<h; i++)
|
||||
{
|
||||
AV_COPY32U(dst, src);
|
||||
dst+=dstStride;
|
||||
src+=srcStride;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void copy_block8(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<h; i++)
|
||||
{
|
||||
AV_COPY64U(dst, src);
|
||||
dst+=dstStride;
|
||||
src+=srcStride;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void copy_block16(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<h; i++)
|
||||
{
|
||||
AV_COPY128U(dst, src);
|
||||
dst+=dstStride;
|
||||
src+=srcStride;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void copy_block9(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<h; i++)
|
||||
{
|
||||
AV_COPY64U(dst, src);
|
||||
dst[8]= src[8];
|
||||
dst+=dstStride;
|
||||
src+=srcStride;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void copy_block17(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<h; i++)
|
||||
{
|
||||
AV_COPY128U(dst, src);
|
||||
dst[16]= src[16];
|
||||
dst+=dstStride;
|
||||
src+=srcStride;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* AVCODEC_COPY_BLOCK_H */
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* DCA compatible decoder data
|
||||
* Copyright (C) 2004 Gildas Bazin
|
||||
* Copyright (C) 2004 Benjamin Zores
|
||||
* Copyright (C) 2006 Benjamin Larsson
|
||||
* Copyright (C) 2007 Konstantin Shishkov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libavutil/error.h"
|
||||
|
||||
#include "dca.h"
|
||||
#include "put_bits.h"
|
||||
|
||||
const uint32_t avpriv_dca_sample_rates[16] =
|
||||
{
|
||||
0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
|
||||
12000, 24000, 48000, 96000, 192000
|
||||
};
|
||||
|
||||
int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
|
||||
int max_size)
|
||||
{
|
||||
uint32_t mrk;
|
||||
int i, tmp;
|
||||
const uint16_t *ssrc = (const uint16_t *) src;
|
||||
uint16_t *sdst = (uint16_t *) dst;
|
||||
PutBitContext pb;
|
||||
|
||||
if ((unsigned) src_size > (unsigned) max_size)
|
||||
src_size = max_size;
|
||||
|
||||
mrk = AV_RB32(src);
|
||||
switch (mrk) {
|
||||
case DCA_MARKER_RAW_BE:
|
||||
memcpy(dst, src, src_size);
|
||||
return src_size;
|
||||
case DCA_MARKER_RAW_LE:
|
||||
for (i = 0; i < (src_size + 1) >> 1; i++)
|
||||
*sdst++ = av_bswap16(*ssrc++);
|
||||
return src_size;
|
||||
case DCA_MARKER_14B_BE:
|
||||
case DCA_MARKER_14B_LE:
|
||||
init_put_bits(&pb, dst, max_size);
|
||||
for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
|
||||
tmp = ((mrk == DCA_MARKER_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
|
||||
put_bits(&pb, 14, tmp);
|
||||
}
|
||||
flush_put_bits(&pb);
|
||||
return (put_bits_count(&pb) + 7) >> 3;
|
||||
default:
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* DCA compatible decoder
|
||||
* Copyright (C) 2004 Gildas Bazin
|
||||
* Copyright (C) 2004 Benjamin Zores
|
||||
* Copyright (C) 2006 Benjamin Larsson
|
||||
* Copyright (C) 2007 Konstantin Shishkov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_DCA_H
|
||||
#define AVCODEC_DCA_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "libavutil/internal.h"
|
||||
|
||||
/** DCA syncwords, also used for bitstream type detection */
|
||||
#define DCA_MARKER_RAW_BE 0x7FFE8001
|
||||
#define DCA_MARKER_RAW_LE 0xFE7F0180
|
||||
#define DCA_MARKER_14B_BE 0x1FFFE800
|
||||
#define DCA_MARKER_14B_LE 0xFF1F00E8
|
||||
|
||||
/** DCA-HD specific block starts with this marker. */
|
||||
#define DCA_HD_MARKER 0x64582025
|
||||
|
||||
extern av_export const uint32_t avpriv_dca_sample_rates[16];
|
||||
|
||||
/**
|
||||
* Convert bitstream to one representation based on sync marker
|
||||
*/
|
||||
int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
|
||||
int max_size);
|
||||
|
||||
#endif /* AVCODEC_DCA_H */
|
|
@ -1,172 +0,0 @@
|
|||
/*
|
||||
* DCA parser
|
||||
* Copyright (C) 2004 Gildas Bazin
|
||||
* Copyright (C) 2004 Benjamin Zores
|
||||
* Copyright (C) 2006 Benjamin Larsson
|
||||
* Copyright (C) 2007 Konstantin Shishkov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "parser.h"
|
||||
#include "dca.h"
|
||||
#include "get_bits.h"
|
||||
|
||||
typedef struct DCAParseContext {
|
||||
ParseContext pc;
|
||||
uint32_t lastmarker;
|
||||
int size;
|
||||
int framesize;
|
||||
int hd_pos;
|
||||
} DCAParseContext;
|
||||
|
||||
#define IS_MARKER(state, i, buf, buf_size) \
|
||||
((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \
|
||||
|| (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \
|
||||
|| state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE || state == DCA_HD_MARKER)
|
||||
|
||||
/**
|
||||
* Find the end of the current frame in the bitstream.
|
||||
* @return the position of the first byte of the next frame, or -1
|
||||
*/
|
||||
static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf,
|
||||
int buf_size)
|
||||
{
|
||||
int start_found, i;
|
||||
uint32_t state;
|
||||
ParseContext *pc = &pc1->pc;
|
||||
|
||||
start_found = pc->frame_start_found;
|
||||
state = pc->state;
|
||||
|
||||
i = 0;
|
||||
if (!start_found) {
|
||||
for (i = 0; i < buf_size; i++) {
|
||||
state = (state << 8) | buf[i];
|
||||
if (IS_MARKER(state, i, buf, buf_size)) {
|
||||
if (!pc1->lastmarker || state == pc1->lastmarker || pc1->lastmarker == DCA_HD_MARKER) {
|
||||
start_found = 1;
|
||||
pc1->lastmarker = state;
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (start_found) {
|
||||
for (; i < buf_size; i++) {
|
||||
pc1->size++;
|
||||
state = (state << 8) | buf[i];
|
||||
if (state == DCA_HD_MARKER && !pc1->hd_pos)
|
||||
pc1->hd_pos = pc1->size;
|
||||
if (IS_MARKER(state, i, buf, buf_size) && (state == pc1->lastmarker || pc1->lastmarker == DCA_HD_MARKER)) {
|
||||
if(pc1->framesize > pc1->size)
|
||||
continue;
|
||||
pc->frame_start_found = 0;
|
||||
pc->state = -1;
|
||||
pc1->size = 0;
|
||||
return i - 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
pc->frame_start_found = start_found;
|
||||
pc->state = state;
|
||||
return END_NOT_FOUND;
|
||||
}
|
||||
|
||||
static av_cold int dca_parse_init(AVCodecParserContext * s)
|
||||
{
|
||||
DCAParseContext *pc1 = s->priv_data;
|
||||
|
||||
pc1->lastmarker = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dca_parse_params(const uint8_t *buf, int buf_size, int *duration,
|
||||
int *sample_rate, int *framesize)
|
||||
{
|
||||
GetBitContext gb;
|
||||
uint8_t hdr[12 + FF_INPUT_BUFFER_PADDING_SIZE] = { 0 };
|
||||
int ret, sample_blocks, sr_code;
|
||||
|
||||
if (buf_size < 12)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
if ((ret = ff_dca_convert_bitstream(buf, 12, hdr, 12)) < 0)
|
||||
return ret;
|
||||
|
||||
init_get_bits(&gb, hdr, 96);
|
||||
|
||||
skip_bits_long(&gb, 39);
|
||||
sample_blocks = get_bits(&gb, 7) + 1;
|
||||
if (sample_blocks < 8)
|
||||
return AVERROR_INVALIDDATA;
|
||||
*duration = 256 * (sample_blocks / 8);
|
||||
|
||||
*framesize = get_bits(&gb, 14) + 1;
|
||||
if (*framesize < 95)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
skip_bits(&gb, 6);
|
||||
sr_code = get_bits(&gb, 4);
|
||||
*sample_rate = avpriv_dca_sample_rates[sr_code];
|
||||
if (*sample_rate == 0)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dca_parse(AVCodecParserContext * s,
|
||||
AVCodecContext * avctx,
|
||||
const uint8_t ** poutbuf, int *poutbuf_size,
|
||||
const uint8_t * buf, int buf_size)
|
||||
{
|
||||
DCAParseContext *pc1 = s->priv_data;
|
||||
ParseContext *pc = &pc1->pc;
|
||||
int next, duration, sample_rate;
|
||||
|
||||
if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
|
||||
next = buf_size;
|
||||
} else {
|
||||
next = dca_find_frame_end(pc1, buf, buf_size);
|
||||
|
||||
if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
|
||||
*poutbuf = NULL;
|
||||
*poutbuf_size = 0;
|
||||
return buf_size;
|
||||
}
|
||||
}
|
||||
|
||||
/* read the duration and sample rate from the frame header */
|
||||
if (!dca_parse_params(buf, buf_size, &duration, &sample_rate, &pc1->framesize)) {
|
||||
s->duration = duration;
|
||||
avctx->sample_rate = sample_rate;
|
||||
} else
|
||||
s->duration = 0;
|
||||
|
||||
*poutbuf = buf;
|
||||
*poutbuf_size = buf_size;
|
||||
return next;
|
||||
}
|
||||
|
||||
AVCodecParser ff_dca_parser = {
|
||||
.codec_ids = { AV_CODEC_ID_DTS },
|
||||
.priv_data_size = sizeof(DCAParseContext),
|
||||
.parser_init = dca_parse_init,
|
||||
.parser_parse = dca_parse,
|
||||
.parser_close = ff_parse_close,
|
||||
};
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004 Gildas Bazin
|
||||
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "libavutil/attributes.h"
|
||||
#include "libavutil/intreadwrite.h"
|
||||
#include "dcadsp.h"
|
||||
|
||||
static void decode_hf_c(float dst[DCA_SUBBANDS][8],
|
||||
const int32_t vq_num[DCA_SUBBANDS],
|
||||
const int8_t hf_vq[1024][32], intptr_t vq_offset,
|
||||
int32_t scale[DCA_SUBBANDS][2],
|
||||
intptr_t start, intptr_t end)
|
||||
{
|
||||
int i, l;
|
||||
|
||||
for (l = start; l < end; l++) {
|
||||
/* 1 vector -> 32 samples but we only need the 8 samples
|
||||
* for this subsubframe. */
|
||||
const int8_t *ptr = &hf_vq[vq_num[l]][vq_offset];
|
||||
float fscale = scale[l][0] * (1 / 16.0);
|
||||
for (i = 0; i < 8; i++)
|
||||
dst[l][i] = ptr[i] * fscale;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
dca_lfe_fir(float *out, const float *in, const float *coefs,
|
||||
int decifactor)
|
||||
{
|
||||
float *out2 = out + 2 * decifactor - 1;
|
||||
int num_coeffs = 256 / decifactor;
|
||||
int j, k;
|
||||
|
||||
/* One decimated sample generates 2*decifactor interpolated ones */
|
||||
for (k = 0; k < decifactor; k++) {
|
||||
float v0 = 0.0;
|
||||
float v1 = 0.0;
|
||||
for (j = 0; j < num_coeffs; j++, coefs++) {
|
||||
v0 += in[-j] * *coefs;
|
||||
v1 += in[j + 1 - num_coeffs] * *coefs;
|
||||
}
|
||||
*out++ = v0;
|
||||
*out2-- = v1;
|
||||
}
|
||||
}
|
||||
|
||||
static void dca_qmf_32_subbands(float samples_in[32][8], int sb_act,
|
||||
SynthFilterContext *synth, FFTContext *imdct,
|
||||
float synth_buf_ptr[512],
|
||||
int *synth_buf_offset, float synth_buf2[32],
|
||||
const float window[512], float *samples_out,
|
||||
float raXin[32], float scale)
|
||||
{
|
||||
int i;
|
||||
int subindex;
|
||||
|
||||
for (i = sb_act; i < 32; i++)
|
||||
raXin[i] = 0.0;
|
||||
|
||||
/* Reconstructed channel sample index */
|
||||
for (subindex = 0; subindex < 8; subindex++) {
|
||||
/* Load in one sample from each subband and clear inactive subbands */
|
||||
for (i = 0; i < sb_act; i++) {
|
||||
unsigned sign = (i - 1) & 2;
|
||||
uint32_t v = AV_RN32A(&samples_in[i][subindex]) ^ sign << 30;
|
||||
AV_WN32A(&raXin[i], v);
|
||||
}
|
||||
|
||||
synth->synth_filter_float(imdct, synth_buf_ptr, synth_buf_offset,
|
||||
synth_buf2, window, samples_out, raXin, scale);
|
||||
samples_out += 32;
|
||||
}
|
||||
}
|
||||
|
||||
static void dca_lfe_fir0_c(float *out, const float *in, const float *coefs)
|
||||
{
|
||||
dca_lfe_fir(out, in, coefs, 32);
|
||||
}
|
||||
|
||||
static void dca_lfe_fir1_c(float *out, const float *in, const float *coefs)
|
||||
{
|
||||
dca_lfe_fir(out, in, coefs, 64);
|
||||
}
|
||||
|
||||
av_cold void ff_dcadsp_init(DCADSPContext *s)
|
||||
{
|
||||
s->lfe_fir[0] = dca_lfe_fir0_c;
|
||||
s->lfe_fir[1] = dca_lfe_fir1_c;
|
||||
s->qmf_32_subbands = dca_qmf_32_subbands;
|
||||
s->decode_hf = decode_hf_c;
|
||||
if (ARCH_ARM) ff_dcadsp_init_arm(s);
|
||||
if (ARCH_X86) ff_dcadsp_init_x86(s);
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_DCADSP_H
|
||||
#define AVCODEC_DCADSP_H
|
||||
|
||||
#include "avfft.h"
|
||||
#include "synth_filter.h"
|
||||
|
||||
#define DCA_SUBBANDS 64
|
||||
|
||||
typedef struct DCADSPContext {
|
||||
void (*lfe_fir[2])(float *out, const float *in, const float *coefs);
|
||||
void (*qmf_32_subbands)(float samples_in[32][8], int sb_act,
|
||||
SynthFilterContext *synth, FFTContext *imdct,
|
||||
float synth_buf_ptr[512],
|
||||
int *synth_buf_offset, float synth_buf2[32],
|
||||
const float window[512], float *samples_out,
|
||||
float raXin[32], float scale);
|
||||
void (*decode_hf)(float dst[DCA_SUBBANDS][8],
|
||||
const int32_t vq_num[DCA_SUBBANDS],
|
||||
const int8_t hf_vq[1024][32], intptr_t vq_offset,
|
||||
int32_t scale[DCA_SUBBANDS][2],
|
||||
intptr_t start, intptr_t end);
|
||||
} DCADSPContext;
|
||||
|
||||
void ff_dcadsp_init(DCADSPContext *s);
|
||||
void ff_dcadsp_init_arm(DCADSPContext *s);
|
||||
void ff_dcadsp_init_x86(DCADSPContext *s);
|
||||
|
||||
#endif /* AVCODEC_DCADSP_H */
|
File diff suppressed because it is too large
Load diff
|
@ -1,222 +0,0 @@
|
|||
/*
|
||||
* (I)DCT Transforms
|
||||
* Copyright (c) 2009 Peter Ross <pross@xvid.org>
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
* Copyright (c) 2010 Vitor Sessak
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* (Inverse) Discrete Cosine Transforms. These are also known as the
|
||||
* type II and type III DCTs respectively.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libavutil/mathematics.h"
|
||||
#include "dct.h"
|
||||
#include "dct32.h"
|
||||
|
||||
/* sin((M_PI * x / (2 * n)) */
|
||||
#define SIN(s, n, x) (s->costab[(n) - (x)])
|
||||
|
||||
/* cos((M_PI * x / (2 * n)) */
|
||||
#define COS(s, n, x) (s->costab[x])
|
||||
|
||||
static void dst_calc_I_c(DCTContext *ctx, FFTSample *data)
|
||||
{
|
||||
int n = 1 << ctx->nbits;
|
||||
int i;
|
||||
|
||||
data[0] = 0;
|
||||
for (i = 1; i < n / 2; i++) {
|
||||
float tmp1 = data[i ];
|
||||
float tmp2 = data[n - i];
|
||||
float s = SIN(ctx, n, 2 * i);
|
||||
|
||||
s *= tmp1 + tmp2;
|
||||
tmp1 = (tmp1 - tmp2) * 0.5f;
|
||||
data[i] = s + tmp1;
|
||||
data[n - i] = s - tmp1;
|
||||
}
|
||||
|
||||
data[n / 2] *= 2;
|
||||
ctx->rdft.rdft_calc(&ctx->rdft, data);
|
||||
|
||||
data[0] *= 0.5f;
|
||||
|
||||
for (i = 1; i < n - 2; i += 2) {
|
||||
data[i + 1] += data[i - 1];
|
||||
data[i] = -data[i + 2];
|
||||
}
|
||||
|
||||
data[n - 1] = 0;
|
||||
}
|
||||
|
||||
static void dct_calc_I_c(DCTContext *ctx, FFTSample *data)
|
||||
{
|
||||
int n = 1 << ctx->nbits;
|
||||
int i;
|
||||
float next = -0.5f * (data[0] - data[n]);
|
||||
|
||||
for (i = 0; i < n / 2; i++) {
|
||||
float tmp1 = data[i];
|
||||
float tmp2 = data[n - i];
|
||||
float s = SIN(ctx, n, 2 * i);
|
||||
float c = COS(ctx, n, 2 * i);
|
||||
|
||||
c *= tmp1 - tmp2;
|
||||
s *= tmp1 - tmp2;
|
||||
|
||||
next += c;
|
||||
|
||||
tmp1 = (tmp1 + tmp2) * 0.5f;
|
||||
data[i] = tmp1 - s;
|
||||
data[n - i] = tmp1 + s;
|
||||
}
|
||||
|
||||
ctx->rdft.rdft_calc(&ctx->rdft, data);
|
||||
data[n] = data[1];
|
||||
data[1] = next;
|
||||
|
||||
for (i = 3; i <= n; i += 2)
|
||||
data[i] = data[i - 2] - data[i];
|
||||
}
|
||||
|
||||
static void dct_calc_III_c(DCTContext *ctx, FFTSample *data)
|
||||
{
|
||||
int n = 1 << ctx->nbits;
|
||||
int i;
|
||||
|
||||
float next = data[n - 1];
|
||||
float inv_n = 1.0f / n;
|
||||
|
||||
for (i = n - 2; i >= 2; i -= 2) {
|
||||
float val1 = data[i];
|
||||
float val2 = data[i - 1] - data[i + 1];
|
||||
float c = COS(ctx, n, i);
|
||||
float s = SIN(ctx, n, i);
|
||||
|
||||
data[i] = c * val1 + s * val2;
|
||||
data[i + 1] = s * val1 - c * val2;
|
||||
}
|
||||
|
||||
data[1] = 2 * next;
|
||||
|
||||
ctx->rdft.rdft_calc(&ctx->rdft, data);
|
||||
|
||||
for (i = 0; i < n / 2; i++) {
|
||||
float tmp1 = data[i] * inv_n;
|
||||
float tmp2 = data[n - i - 1] * inv_n;
|
||||
float csc = ctx->csc2[i] * (tmp1 - tmp2);
|
||||
|
||||
tmp1 += tmp2;
|
||||
data[i] = tmp1 + csc;
|
||||
data[n - i - 1] = tmp1 - csc;
|
||||
}
|
||||
}
|
||||
|
||||
static void dct_calc_II_c(DCTContext *ctx, FFTSample *data)
|
||||
{
|
||||
int n = 1 << ctx->nbits;
|
||||
int i;
|
||||
float next;
|
||||
|
||||
for (i = 0; i < n / 2; i++) {
|
||||
float tmp1 = data[i];
|
||||
float tmp2 = data[n - i - 1];
|
||||
float s = SIN(ctx, n, 2 * i + 1);
|
||||
|
||||
s *= tmp1 - tmp2;
|
||||
tmp1 = (tmp1 + tmp2) * 0.5f;
|
||||
|
||||
data[i] = tmp1 + s;
|
||||
data[n-i-1] = tmp1 - s;
|
||||
}
|
||||
|
||||
ctx->rdft.rdft_calc(&ctx->rdft, data);
|
||||
|
||||
next = data[1] * 0.5;
|
||||
data[1] *= -1;
|
||||
|
||||
for (i = n - 2; i >= 0; i -= 2) {
|
||||
float inr = data[i ];
|
||||
float ini = data[i + 1];
|
||||
float c = COS(ctx, n, i);
|
||||
float s = SIN(ctx, n, i);
|
||||
|
||||
data[i] = c * inr + s * ini;
|
||||
data[i + 1] = next;
|
||||
|
||||
next += s * inr - c * ini;
|
||||
}
|
||||
}
|
||||
|
||||
static void dct32_func(DCTContext *ctx, FFTSample *data)
|
||||
{
|
||||
ctx->dct32(data, data);
|
||||
}
|
||||
|
||||
av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
|
||||
{
|
||||
int n = 1 << nbits;
|
||||
int i;
|
||||
|
||||
memset(s, 0, sizeof(*s));
|
||||
|
||||
s->nbits = nbits;
|
||||
s->inverse = inverse;
|
||||
|
||||
if (inverse == DCT_II && nbits == 5) {
|
||||
s->dct_calc = dct32_func;
|
||||
} else {
|
||||
ff_init_ff_cos_tabs(nbits + 2);
|
||||
|
||||
s->costab = ff_cos_tabs[nbits + 2];
|
||||
s->csc2 = av_malloc(n / 2 * sizeof(FFTSample));
|
||||
|
||||
if (ff_rdft_init(&s->rdft, nbits, inverse == DCT_III) < 0) {
|
||||
av_free(s->csc2);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < n / 2; i++)
|
||||
s->csc2[i] = 0.5 / sin((M_PI / (2 * n) * (2 * i + 1)));
|
||||
|
||||
switch (inverse) {
|
||||
case DCT_I : s->dct_calc = dct_calc_I_c; break;
|
||||
case DCT_II : s->dct_calc = dct_calc_II_c; break;
|
||||
case DCT_III: s->dct_calc = dct_calc_III_c; break;
|
||||
case DST_I : s->dct_calc = dst_calc_I_c; break;
|
||||
}
|
||||
}
|
||||
|
||||
s->dct32 = ff_dct32_float;
|
||||
if (ARCH_X86)
|
||||
ff_dct_init_x86(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
av_cold void ff_dct_end(DCTContext *s)
|
||||
{
|
||||
ff_rdft_end(&s->rdft);
|
||||
av_free(s->csc2);
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* (I)DCT Transforms
|
||||
* Copyright (c) 2009 Peter Ross <pross@xvid.org>
|
||||
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
|
||||
* Copyright (c) 2010 Vitor Sessak
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_DCT_H
|
||||
#define AVCODEC_DCT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "rdft.h"
|
||||
|
||||
struct DCTContext {
|
||||
int nbits;
|
||||
int inverse;
|
||||
RDFTContext rdft;
|
||||
const float *costab;
|
||||
FFTSample *csc2;
|
||||
void (*dct_calc)(struct DCTContext *s, FFTSample *data);
|
||||
void (*dct32)(FFTSample *out, const FFTSample *in);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set up DCT.
|
||||
* @param nbits size of the input array:
|
||||
* (1 << nbits) for DCT-II, DCT-III and DST-I
|
||||
* (1 << nbits) + 1 for DCT-I
|
||||
*
|
||||
* @note the first element of the input of DST-I is ignored
|
||||
*/
|
||||
int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType type);
|
||||
void ff_dct_end (DCTContext *s);
|
||||
|
||||
void ff_dct_init_x86(DCTContext *s);
|
||||
|
||||
void ff_fdct_ifast(int16_t *data);
|
||||
void ff_fdct_ifast248(int16_t *data);
|
||||
void ff_jpeg_fdct_islow_8(int16_t *data);
|
||||
void ff_jpeg_fdct_islow_10(int16_t *data);
|
||||
void ff_fdct248_islow_8(int16_t *data);
|
||||
void ff_fdct248_islow_10(int16_t *data);
|
||||
|
||||
void ff_j_rev_dct(int16_t *data);
|
||||
void ff_j_rev_dct4(int16_t *data);
|
||||
void ff_j_rev_dct2(int16_t *data);
|
||||
void ff_j_rev_dct1(int16_t *data);
|
||||
|
||||
void ff_fdct_mmx(int16_t *block);
|
||||
void ff_fdct_mmxext(int16_t *block);
|
||||
void ff_fdct_sse2(int16_t *block);
|
||||
|
||||
#endif /* AVCODEC_DCT_H */
|
|
@ -1,276 +0,0 @@
|
|||
/*
|
||||
* Template for the Discrete Cosine Transform for 32 samples
|
||||
* Copyright (c) 2001, 2002 Fabrice Bellard
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "dct32.h"
|
||||
#include "mathops.h"
|
||||
|
||||
#if DCT32_FLOAT
|
||||
# define dct32 ff_dct32_float
|
||||
# define FIXHR(x) ((float)(x))
|
||||
# define MULH3(x, y, s) ((s)*(y)*(x))
|
||||
# define INTFLOAT float
|
||||
#else
|
||||
# define dct32 ff_dct32_fixed
|
||||
# define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5))
|
||||
# define MULH3(x, y, s) MULH((s)*(x), y)
|
||||
# define INTFLOAT int
|
||||
#endif
|
||||
|
||||
|
||||
/* tab[i][j] = 1.0 / (2.0 * cos(pi*(2*k+1) / 2^(6 - j))) */
|
||||
|
||||
/* cos(i*pi/64) */
|
||||
|
||||
#define COS0_0 FIXHR(0.50060299823519630134/2)
|
||||
#define COS0_1 FIXHR(0.50547095989754365998/2)
|
||||
#define COS0_2 FIXHR(0.51544730992262454697/2)
|
||||
#define COS0_3 FIXHR(0.53104259108978417447/2)
|
||||
#define COS0_4 FIXHR(0.55310389603444452782/2)
|
||||
#define COS0_5 FIXHR(0.58293496820613387367/2)
|
||||
#define COS0_6 FIXHR(0.62250412303566481615/2)
|
||||
#define COS0_7 FIXHR(0.67480834145500574602/2)
|
||||
#define COS0_8 FIXHR(0.74453627100229844977/2)
|
||||
#define COS0_9 FIXHR(0.83934964541552703873/2)
|
||||
#define COS0_10 FIXHR(0.97256823786196069369/2)
|
||||
#define COS0_11 FIXHR(1.16943993343288495515/4)
|
||||
#define COS0_12 FIXHR(1.48416461631416627724/4)
|
||||
#define COS0_13 FIXHR(2.05778100995341155085/8)
|
||||
#define COS0_14 FIXHR(3.40760841846871878570/8)
|
||||
#define COS0_15 FIXHR(10.19000812354805681150/32)
|
||||
|
||||
#define COS1_0 FIXHR(0.50241928618815570551/2)
|
||||
#define COS1_1 FIXHR(0.52249861493968888062/2)
|
||||
#define COS1_2 FIXHR(0.56694403481635770368/2)
|
||||
#define COS1_3 FIXHR(0.64682178335999012954/2)
|
||||
#define COS1_4 FIXHR(0.78815462345125022473/2)
|
||||
#define COS1_5 FIXHR(1.06067768599034747134/4)
|
||||
#define COS1_6 FIXHR(1.72244709823833392782/4)
|
||||
#define COS1_7 FIXHR(5.10114861868916385802/16)
|
||||
|
||||
#define COS2_0 FIXHR(0.50979557910415916894/2)
|
||||
#define COS2_1 FIXHR(0.60134488693504528054/2)
|
||||
#define COS2_2 FIXHR(0.89997622313641570463/2)
|
||||
#define COS2_3 FIXHR(2.56291544774150617881/8)
|
||||
|
||||
#define COS3_0 FIXHR(0.54119610014619698439/2)
|
||||
#define COS3_1 FIXHR(1.30656296487637652785/4)
|
||||
|
||||
#define COS4_0 FIXHR(0.70710678118654752439/2)
|
||||
|
||||
/* butterfly operator */
|
||||
#define BF(a, b, c, s)\
|
||||
{\
|
||||
tmp0 = val##a + val##b;\
|
||||
tmp1 = val##a - val##b;\
|
||||
val##a = tmp0;\
|
||||
val##b = MULH3(tmp1, c, 1<<(s));\
|
||||
}
|
||||
|
||||
#define BF0(a, b, c, s)\
|
||||
{\
|
||||
tmp0 = tab[a] + tab[b];\
|
||||
tmp1 = tab[a] - tab[b];\
|
||||
val##a = tmp0;\
|
||||
val##b = MULH3(tmp1, c, 1<<(s));\
|
||||
}
|
||||
|
||||
#define BF1(a, b, c, d)\
|
||||
{\
|
||||
BF(a, b, COS4_0, 1);\
|
||||
BF(c, d,-COS4_0, 1);\
|
||||
val##c += val##d;\
|
||||
}
|
||||
|
||||
#define BF2(a, b, c, d)\
|
||||
{\
|
||||
BF(a, b, COS4_0, 1);\
|
||||
BF(c, d,-COS4_0, 1);\
|
||||
val##c += val##d;\
|
||||
val##a += val##c;\
|
||||
val##c += val##b;\
|
||||
val##b += val##d;\
|
||||
}
|
||||
|
||||
#define ADD(a, b) val##a += val##b
|
||||
|
||||
/* DCT32 without 1/sqrt(2) coef zero scaling. */
|
||||
void dct32(INTFLOAT *out, const INTFLOAT *tab)
|
||||
{
|
||||
INTFLOAT tmp0, tmp1;
|
||||
|
||||
INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 ,
|
||||
val8 , val9 , val10, val11, val12, val13, val14, val15,
|
||||
val16, val17, val18, val19, val20, val21, val22, val23,
|
||||
val24, val25, val26, val27, val28, val29, val30, val31;
|
||||
|
||||
/* pass 1 */
|
||||
BF0( 0, 31, COS0_0 , 1);
|
||||
BF0(15, 16, COS0_15, 5);
|
||||
/* pass 2 */
|
||||
BF( 0, 15, COS1_0 , 1);
|
||||
BF(16, 31,-COS1_0 , 1);
|
||||
/* pass 1 */
|
||||
BF0( 7, 24, COS0_7 , 1);
|
||||
BF0( 8, 23, COS0_8 , 1);
|
||||
/* pass 2 */
|
||||
BF( 7, 8, COS1_7 , 4);
|
||||
BF(23, 24,-COS1_7 , 4);
|
||||
/* pass 3 */
|
||||
BF( 0, 7, COS2_0 , 1);
|
||||
BF( 8, 15,-COS2_0 , 1);
|
||||
BF(16, 23, COS2_0 , 1);
|
||||
BF(24, 31,-COS2_0 , 1);
|
||||
/* pass 1 */
|
||||
BF0( 3, 28, COS0_3 , 1);
|
||||
BF0(12, 19, COS0_12, 2);
|
||||
/* pass 2 */
|
||||
BF( 3, 12, COS1_3 , 1);
|
||||
BF(19, 28,-COS1_3 , 1);
|
||||
/* pass 1 */
|
||||
BF0( 4, 27, COS0_4 , 1);
|
||||
BF0(11, 20, COS0_11, 2);
|
||||
/* pass 2 */
|
||||
BF( 4, 11, COS1_4 , 1);
|
||||
BF(20, 27,-COS1_4 , 1);
|
||||
/* pass 3 */
|
||||
BF( 3, 4, COS2_3 , 3);
|
||||
BF(11, 12,-COS2_3 , 3);
|
||||
BF(19, 20, COS2_3 , 3);
|
||||
BF(27, 28,-COS2_3 , 3);
|
||||
/* pass 4 */
|
||||
BF( 0, 3, COS3_0 , 1);
|
||||
BF( 4, 7,-COS3_0 , 1);
|
||||
BF( 8, 11, COS3_0 , 1);
|
||||
BF(12, 15,-COS3_0 , 1);
|
||||
BF(16, 19, COS3_0 , 1);
|
||||
BF(20, 23,-COS3_0 , 1);
|
||||
BF(24, 27, COS3_0 , 1);
|
||||
BF(28, 31,-COS3_0 , 1);
|
||||
|
||||
|
||||
|
||||
/* pass 1 */
|
||||
BF0( 1, 30, COS0_1 , 1);
|
||||
BF0(14, 17, COS0_14, 3);
|
||||
/* pass 2 */
|
||||
BF( 1, 14, COS1_1 , 1);
|
||||
BF(17, 30,-COS1_1 , 1);
|
||||
/* pass 1 */
|
||||
BF0( 6, 25, COS0_6 , 1);
|
||||
BF0( 9, 22, COS0_9 , 1);
|
||||
/* pass 2 */
|
||||
BF( 6, 9, COS1_6 , 2);
|
||||
BF(22, 25,-COS1_6 , 2);
|
||||
/* pass 3 */
|
||||
BF( 1, 6, COS2_1 , 1);
|
||||
BF( 9, 14,-COS2_1 , 1);
|
||||
BF(17, 22, COS2_1 , 1);
|
||||
BF(25, 30,-COS2_1 , 1);
|
||||
|
||||
/* pass 1 */
|
||||
BF0( 2, 29, COS0_2 , 1);
|
||||
BF0(13, 18, COS0_13, 3);
|
||||
/* pass 2 */
|
||||
BF( 2, 13, COS1_2 , 1);
|
||||
BF(18, 29,-COS1_2 , 1);
|
||||
/* pass 1 */
|
||||
BF0( 5, 26, COS0_5 , 1);
|
||||
BF0(10, 21, COS0_10, 1);
|
||||
/* pass 2 */
|
||||
BF( 5, 10, COS1_5 , 2);
|
||||
BF(21, 26,-COS1_5 , 2);
|
||||
/* pass 3 */
|
||||
BF( 2, 5, COS2_2 , 1);
|
||||
BF(10, 13,-COS2_2 , 1);
|
||||
BF(18, 21, COS2_2 , 1);
|
||||
BF(26, 29,-COS2_2 , 1);
|
||||
/* pass 4 */
|
||||
BF( 1, 2, COS3_1 , 2);
|
||||
BF( 5, 6,-COS3_1 , 2);
|
||||
BF( 9, 10, COS3_1 , 2);
|
||||
BF(13, 14,-COS3_1 , 2);
|
||||
BF(17, 18, COS3_1 , 2);
|
||||
BF(21, 22,-COS3_1 , 2);
|
||||
BF(25, 26, COS3_1 , 2);
|
||||
BF(29, 30,-COS3_1 , 2);
|
||||
|
||||
/* pass 5 */
|
||||
BF1( 0, 1, 2, 3);
|
||||
BF2( 4, 5, 6, 7);
|
||||
BF1( 8, 9, 10, 11);
|
||||
BF2(12, 13, 14, 15);
|
||||
BF1(16, 17, 18, 19);
|
||||
BF2(20, 21, 22, 23);
|
||||
BF1(24, 25, 26, 27);
|
||||
BF2(28, 29, 30, 31);
|
||||
|
||||
/* pass 6 */
|
||||
|
||||
ADD( 8, 12);
|
||||
ADD(12, 10);
|
||||
ADD(10, 14);
|
||||
ADD(14, 9);
|
||||
ADD( 9, 13);
|
||||
ADD(13, 11);
|
||||
ADD(11, 15);
|
||||
|
||||
out[ 0] = val0;
|
||||
out[16] = val1;
|
||||
out[ 8] = val2;
|
||||
out[24] = val3;
|
||||
out[ 4] = val4;
|
||||
out[20] = val5;
|
||||
out[12] = val6;
|
||||
out[28] = val7;
|
||||
out[ 2] = val8;
|
||||
out[18] = val9;
|
||||
out[10] = val10;
|
||||
out[26] = val11;
|
||||
out[ 6] = val12;
|
||||
out[22] = val13;
|
||||
out[14] = val14;
|
||||
out[30] = val15;
|
||||
|
||||
ADD(24, 28);
|
||||
ADD(28, 26);
|
||||
ADD(26, 30);
|
||||
ADD(30, 25);
|
||||
ADD(25, 29);
|
||||
ADD(29, 27);
|
||||
ADD(27, 31);
|
||||
|
||||
out[ 1] = val16 + val24;
|
||||
out[17] = val17 + val25;
|
||||
out[ 9] = val18 + val26;
|
||||
out[25] = val19 + val27;
|
||||
out[ 5] = val20 + val28;
|
||||
out[21] = val21 + val29;
|
||||
out[13] = val22 + val30;
|
||||
out[29] = val23 + val31;
|
||||
out[ 3] = val24 + val20;
|
||||
out[19] = val25 + val21;
|
||||
out[11] = val26 + val22;
|
||||
out[27] = val27 + val23;
|
||||
out[ 7] = val28 + val18;
|
||||
out[23] = val29 + val19;
|
||||
out[15] = val30 + val17;
|
||||
out[31] = val31;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_DCT32_H
|
||||
#define AVCODEC_DCT32_H
|
||||
|
||||
void ff_dct32_float(float *dst, const float *src);
|
||||
void ff_dct32_fixed(int *dst, const int *src);
|
||||
|
||||
#endif
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#define DCT32_FLOAT 1
|
||||
#include "dct32.c"
|
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
* reference discrete cosine transform (double precision)
|
||||
* Copyright (C) 2009 Dylan Yudaken
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* reference discrete cosine transform (double precision)
|
||||
*
|
||||
* @author Dylan Yudaken (dyudaken at gmail)
|
||||
*
|
||||
* @note This file could be optimized a lot, but is for
|
||||
* reference and so readability is better.
|
||||
*/
|
||||
|
||||
#include "libavutil/mathematics.h"
|
||||
#include "dctref.h"
|
||||
|
||||
static double coefficients[8 * 8];
|
||||
|
||||
/**
|
||||
* Initialize the double precision discrete cosine transform
|
||||
* functions fdct & idct.
|
||||
*/
|
||||
av_cold void ff_ref_dct_init(void)
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (j = 0; j < 8; ++j) {
|
||||
coefficients[j] = sqrt(0.125);
|
||||
for (i = 8; i < 64; i += 8) {
|
||||
coefficients[i + j] = 0.5 * cos(i * (j + 0.5) * M_PI / 64.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform 8x8 block of data with a double precision forward DCT <br>
|
||||
* This is a reference implementation.
|
||||
*
|
||||
* @param block pointer to 8x8 block of data to transform
|
||||
*/
|
||||
void ff_ref_fdct(short *block)
|
||||
{
|
||||
/* implement the equation: block = coefficients * block * coefficients' */
|
||||
|
||||
unsigned int i, j, k;
|
||||
double out[8 * 8];
|
||||
|
||||
/* out = coefficients * block */
|
||||
for (i = 0; i < 64; i += 8) {
|
||||
for (j = 0; j < 8; ++j) {
|
||||
double tmp = 0;
|
||||
for (k = 0; k < 8; ++k) {
|
||||
tmp += coefficients[i + k] * block[k * 8 + j];
|
||||
}
|
||||
out[i + j] = tmp * 8;
|
||||
}
|
||||
}
|
||||
|
||||
/* block = out * (coefficients') */
|
||||
for (j = 0; j < 8; ++j) {
|
||||
for (i = 0; i < 64; i += 8) {
|
||||
double tmp = 0;
|
||||
for (k = 0; k < 8; ++k) {
|
||||
tmp += out[i + k] * coefficients[j * 8 + k];
|
||||
}
|
||||
block[i + j] = floor(tmp + 0.499999999999);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform 8x8 block of data with a double precision inverse DCT <br>
|
||||
* This is a reference implementation.
|
||||
*
|
||||
* @param block pointer to 8x8 block of data to transform
|
||||
*/
|
||||
void ff_ref_idct(short *block)
|
||||
{
|
||||
/* implement the equation: block = (coefficients') * block * coefficients */
|
||||
|
||||
unsigned int i, j, k;
|
||||
double out[8 * 8];
|
||||
|
||||
/* out = block * coefficients */
|
||||
for (i = 0; i < 64; i += 8) {
|
||||
for (j = 0; j < 8; ++j) {
|
||||
double tmp = 0;
|
||||
for (k = 0; k < 8; ++k) {
|
||||
tmp += block[i + k] * coefficients[k * 8 + j];
|
||||
}
|
||||
out[i + j] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
/* block = (coefficients') * out */
|
||||
for (i = 0; i < 8; ++i) {
|
||||
for (j = 0; j < 8; ++j) {
|
||||
double tmp = 0;
|
||||
for (k = 0; k < 64; k += 8) {
|
||||
tmp += coefficients[k + i] * out[k + j];
|
||||
}
|
||||
block[i * 8 + j] = floor(tmp + 0.5);
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue