mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 779997 - Import SoundTouch Library in the tree. r=
This commit is contained in:
parent
4c5557e3c7
commit
4107bd8751
@ -54,6 +54,7 @@
|
|||||||
@BINPATH@/@DLL_PREFIX@xpcom@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@xpcom@DLL_SUFFIX@
|
||||||
@BINPATH@/@DLL_PREFIX@nspr4@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@nspr4@DLL_SUFFIX@
|
||||||
@BINPATH@/@DLL_PREFIX@mozalloc@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@mozalloc@DLL_SUFFIX@
|
||||||
|
@BINPATH@/@DLL_PREFIX@soundtouch@DLL_SUFFIX@
|
||||||
#ifdef XP_MACOSX
|
#ifdef XP_MACOSX
|
||||||
@BINPATH@/XUL
|
@BINPATH@/XUL
|
||||||
#else
|
#else
|
||||||
|
@ -54,6 +54,7 @@
|
|||||||
@BINPATH@/@DLL_PREFIX@gkmedias@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@gkmedias@DLL_SUFFIX@
|
||||||
#endif
|
#endif
|
||||||
@BINPATH@/@DLL_PREFIX@mozalloc@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@mozalloc@DLL_SUFFIX@
|
||||||
|
@BINPATH@/@DLL_PREFIX@soundtouch@DLL_SUFFIX@
|
||||||
#ifdef MOZ_SHARED_MOZGLUE
|
#ifdef MOZ_SHARED_MOZGLUE
|
||||||
@BINPATH@/@DLL_PREFIX@mozglue@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@mozglue@DLL_SUFFIX@
|
||||||
#endif
|
#endif
|
||||||
|
@ -981,6 +981,8 @@ plstr.h
|
|||||||
plarenas.h
|
plarenas.h
|
||||||
plarena.h
|
plarena.h
|
||||||
plhash.h
|
plhash.h
|
||||||
|
speex/speex_resampler.h
|
||||||
|
soundtouch/SoundTouch.h
|
||||||
#if MOZ_NATIVE_PNG==1
|
#if MOZ_NATIVE_PNG==1
|
||||||
png.h
|
png.h
|
||||||
#endif
|
#endif
|
||||||
@ -1053,7 +1055,6 @@ vpx/vpx_encoder.h
|
|||||||
vpx/vp8cx.h
|
vpx/vp8cx.h
|
||||||
vpx/vp8dx.h
|
vpx/vp8dx.h
|
||||||
sydneyaudio/sydney_audio.h
|
sydneyaudio/sydney_audio.h
|
||||||
speex/speex_resampler.h
|
|
||||||
vorbis/codec.h
|
vorbis/codec.h
|
||||||
theora/theoradec.h
|
theora/theoradec.h
|
||||||
tremor/ivorbiscodec.h
|
tremor/ivorbiscodec.h
|
||||||
|
15
configure.in
15
configure.in
@ -4225,6 +4225,7 @@ MOZ_OGG=1
|
|||||||
MOZ_RAW=
|
MOZ_RAW=
|
||||||
MOZ_SYDNEYAUDIO=
|
MOZ_SYDNEYAUDIO=
|
||||||
MOZ_SPEEX_RESAMPLER=1
|
MOZ_SPEEX_RESAMPLER=1
|
||||||
|
MOZ_SOUNDTOUCH=1
|
||||||
MOZ_CUBEB=
|
MOZ_CUBEB=
|
||||||
MOZ_VORBIS=
|
MOZ_VORBIS=
|
||||||
MOZ_TREMOR=
|
MOZ_TREMOR=
|
||||||
@ -5580,6 +5581,19 @@ if test -n "$MOZ_SPEEX_RESAMPLER"; then
|
|||||||
AC_DEFINE(MOZ_SPEEX_RESAMPLER)
|
AC_DEFINE(MOZ_SPEEX_RESAMPLER)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test -n "$MOZ_SOUNDTOUCH"; then
|
||||||
|
AC_DEFINE(MOZ_SOUNDTOUCH)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "$GNU_CC" -a "$OS_ARCH" = "WINNT"; then
|
||||||
|
SOUNDTOUCH_LIBS='$(LIBXUL_DIST)/lib/$(LIB_PREFIX)soundtouch.$(LIB_SUFFIX)'
|
||||||
|
else
|
||||||
|
SOUNDTOUCH_LIBS='-lsoundtouch'
|
||||||
|
fi
|
||||||
|
AC_SUBST(SOUNDTOUCH_CFLAGS)
|
||||||
|
AC_SUBST(SOUNDTOUCH_LIBS)
|
||||||
|
AC_SUBST(SOUNDTOUCH_CONFIG)
|
||||||
|
|
||||||
if test -n "$MOZ_CUBEB"; then
|
if test -n "$MOZ_CUBEB"; then
|
||||||
case "$target" in
|
case "$target" in
|
||||||
*-android*|*-linuxandroid*)
|
*-android*|*-linuxandroid*)
|
||||||
@ -8653,6 +8667,7 @@ AC_SUBST(MOZ_APP_EXTRA_LIBS)
|
|||||||
AC_SUBST(MOZ_MEDIA)
|
AC_SUBST(MOZ_MEDIA)
|
||||||
AC_SUBST(MOZ_SYDNEYAUDIO)
|
AC_SUBST(MOZ_SYDNEYAUDIO)
|
||||||
AC_SUBST(MOZ_SPEEX_RESAMPLER)
|
AC_SUBST(MOZ_SPEEX_RESAMPLER)
|
||||||
|
AC_SUBST(MOZ_SOUNDTOUCH)
|
||||||
AC_SUBST(MOZ_CUBEB)
|
AC_SUBST(MOZ_CUBEB)
|
||||||
AC_SUBST(MOZ_WAVE)
|
AC_SUBST(MOZ_WAVE)
|
||||||
AC_SUBST(MOZ_VORBIS)
|
AC_SUBST(MOZ_VORBIS)
|
||||||
|
@ -981,6 +981,8 @@ plstr.h
|
|||||||
plarenas.h
|
plarenas.h
|
||||||
plarena.h
|
plarena.h
|
||||||
plhash.h
|
plhash.h
|
||||||
|
speex/speex_resampler.h
|
||||||
|
soundtouch/SoundTouch.h
|
||||||
#if MOZ_NATIVE_PNG==1
|
#if MOZ_NATIVE_PNG==1
|
||||||
png.h
|
png.h
|
||||||
#endif
|
#endif
|
||||||
@ -1053,7 +1055,6 @@ vpx/vpx_encoder.h
|
|||||||
vpx/vp8cx.h
|
vpx/vp8cx.h
|
||||||
vpx/vp8dx.h
|
vpx/vp8dx.h
|
||||||
sydneyaudio/sydney_audio.h
|
sydneyaudio/sydney_audio.h
|
||||||
speex/speex_resampler.h
|
|
||||||
vorbis/codec.h
|
vorbis/codec.h
|
||||||
theora/theoradec.h
|
theora/theoradec.h
|
||||||
tremor/ivorbiscodec.h
|
tremor/ivorbiscodec.h
|
||||||
|
4
media/libsoundtouch/AUTHORS
Normal file
4
media/libsoundtouch/AUTHORS
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
The SoundTouch Library
|
||||||
|
Copyright © Olli Parviainen 2001-2012
|
||||||
|
|
||||||
|
http://www.surina.net/soundtouch/
|
458
media/libsoundtouch/LICENSE
Normal file
458
media/libsoundtouch/LICENSE
Normal file
@ -0,0 +1,458 @@
|
|||||||
|
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 authoried 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
|
17
media/libsoundtouch/Makefile.in
Normal file
17
media/libsoundtouch/Makefile.in
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
DEPTH = ../..
|
||||||
|
topsrcdir = @top_srcdir@
|
||||||
|
srcdir = @srcdir@
|
||||||
|
VPATH = @srcdir@
|
||||||
|
|
||||||
|
include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
|
MODULE = soundtouch
|
||||||
|
|
||||||
|
DIRS = src \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/rules.mk
|
8
media/libsoundtouch/README_MOZILLA
Normal file
8
media/libsoundtouch/README_MOZILLA
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
These files are from the SoundTouch library (http://www.surina.net/soundtouch/),
|
||||||
|
and are extracted from the revision r143 of the svn repository at
|
||||||
|
https://soundtouch.svn.sourceforge.net/svnroot/soundtouch/trunk.
|
||||||
|
|
||||||
|
The whole library is not used, only the relevant files are imported in the tree,
|
||||||
|
using the script `update.sh`. Some changes have been made to the files, using
|
||||||
|
the patch `moz-libsoundtouch.patch`. We also use a custom soundtouch_config.h.
|
||||||
|
|
509
media/libsoundtouch/moz-libsoundtouch.patch
Normal file
509
media/libsoundtouch/moz-libsoundtouch.patch
Normal file
@ -0,0 +1,509 @@
|
|||||||
|
unchanged:
|
||||||
|
--- /src/STTypes.h 2012-08-02 10:04:06.301691592 -0700
|
||||||
|
+++ /src/STTypes.h
|
||||||
|
@@ -42,21 +42,13 @@
|
||||||
|
typedef unsigned int uint;
|
||||||
|
typedef unsigned long ulong;
|
||||||
|
|
||||||
|
-#ifdef __GNUC__
|
||||||
|
- // In GCC, include soundtouch_config.h made by config scritps
|
||||||
|
- #include "soundtouch_config.h"
|
||||||
|
-#endif
|
||||||
|
-
|
||||||
|
-#ifndef _WINDEF_
|
||||||
|
- // if these aren't defined already by Windows headers, define now
|
||||||
|
-
|
||||||
|
- typedef int BOOL;
|
||||||
|
-
|
||||||
|
- #define FALSE 0
|
||||||
|
- #define TRUE 1
|
||||||
|
-
|
||||||
|
-#endif // _WINDEF_
|
||||||
|
+#include "soundtouch_config.h"
|
||||||
|
|
||||||
|
+#ifdef WIN32
|
||||||
|
+#define EXPORT __declspec(dllexport)
|
||||||
|
+#else
|
||||||
|
+#define EXPORT
|
||||||
|
+#endif
|
||||||
|
|
||||||
|
namespace soundtouch
|
||||||
|
{
|
||||||
|
@@ -82,7 +74,7 @@
|
||||||
|
/// also in GNU environment, then please #undef the INTEGER_SAMPLE
|
||||||
|
/// and FLOAT_SAMPLE defines first as in comments above.
|
||||||
|
//#define SOUNDTOUCH_INTEGER_SAMPLES 1 //< 16bit integer samples
|
||||||
|
- #define SOUNDTOUCH_FLOAT_SAMPLES 1 //< 32bit float samples
|
||||||
|
+ #define SOUNDTOUCH_FLOAT_SAMPLES 1 //< 32bit float samples
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@@ -144,10 +136,10 @@
|
||||||
|
|
||||||
|
#endif // SOUNDTOUCH_INTEGER_SAMPLES
|
||||||
|
|
||||||
|
-};
|
||||||
|
+}
|
||||||
|
|
||||||
|
// define ST_NO_EXCEPTION_HANDLING switch to disable throwing std exceptions:
|
||||||
|
-// #define ST_NO_EXCEPTION_HANDLING 1
|
||||||
|
+#define ST_NO_EXCEPTION_HANDLING 1
|
||||||
|
#ifdef ST_NO_EXCEPTION_HANDLING
|
||||||
|
// Exceptions disabled. Throw asserts instead if enabled.
|
||||||
|
#include <assert.h>
|
||||||
|
--- /src/SoundTouch.h 2012-08-02 10:04:06.301691592 -0700
|
||||||
|
+++ /src/SoundTouch.h
|
||||||
|
@@ -141,7 +141,7 @@
|
||||||
|
/// tempo/pitch/rate/samplerate settings.
|
||||||
|
#define SETTING_NOMINAL_OUTPUT_SEQUENCE 7
|
||||||
|
|
||||||
|
-class SoundTouch : public FIFOProcessor
|
||||||
|
+class EXPORT SoundTouch : public FIFOProcessor
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
/// Rate transposer class instance
|
||||||
|
@@ -160,7 +160,7 @@
|
||||||
|
float virtualPitch;
|
||||||
|
|
||||||
|
/// Flag: Has sample rate been set?
|
||||||
|
- BOOL bSrateSet;
|
||||||
|
+ bool bSrateSet;
|
||||||
|
|
||||||
|
/// Calculates effective rate & tempo valuescfrom 'virtualRate', 'virtualTempo' and
|
||||||
|
/// 'virtualPitch' parameters.
|
||||||
|
@@ -247,8 +247,8 @@
|
||||||
|
/// Changes a setting controlling the processing system behaviour. See the
|
||||||
|
/// 'SETTING_...' defines for available setting ID's.
|
||||||
|
///
|
||||||
|
- /// \return 'TRUE' if the setting was succesfully changed
|
||||||
|
- BOOL setSetting(int settingId, ///< Setting ID number. see SETTING_... defines.
|
||||||
|
+ /// \return 'true' if the setting was succesfully changed
|
||||||
|
+ bool setSetting(int settingId, ///< Setting ID number. see SETTING_... defines.
|
||||||
|
int value ///< New setting value.
|
||||||
|
);
|
||||||
|
|
||||||
|
--- /src/RateTransposer.cpp
|
||||||
|
+++ /src/RateTransposer.cpp
|
||||||
|
@@ -120,17 +120,17 @@ RateTransposer *RateTransposer::newInsta
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
RateTransposer::RateTransposer() : FIFOProcessor(&outputBuffer)
|
||||||
|
{
|
||||||
|
numChannels = 2;
|
||||||
|
- bUseAAFilter = TRUE;
|
||||||
|
+ bUseAAFilter = true;
|
||||||
|
fRate = 0;
|
||||||
|
|
||||||
|
// Instantiates the anti-alias filter with default tap length
|
||||||
|
// of 32
|
||||||
|
pAAFilter = new AAFilter(32);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -138,24 +138,24 @@ RateTransposer::RateTransposer() : FIFOP
|
||||||
|
RateTransposer::~RateTransposer()
|
||||||
|
{
|
||||||
|
delete pAAFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// Enables/disables the anti-alias filter. Zero to disable, nonzero to enable
|
||||||
|
-void RateTransposer::enableAAFilter(BOOL newMode)
|
||||||
|
+void RateTransposer::enableAAFilter(bool newMode)
|
||||||
|
{
|
||||||
|
bUseAAFilter = newMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Returns nonzero if anti-alias filter is enabled.
|
||||||
|
-BOOL RateTransposer::isAAFilterEnabled() const
|
||||||
|
+bool RateTransposer::isAAFilterEnabled() const
|
||||||
|
{
|
||||||
|
return bUseAAFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AAFilter *RateTransposer::getAAFilter()
|
||||||
|
{
|
||||||
|
return pAAFilter;
|
||||||
|
@@ -281,17 +281,17 @@ void RateTransposer::processSamples(cons
|
||||||
|
uint count;
|
||||||
|
uint sizeReq;
|
||||||
|
|
||||||
|
if (nSamples == 0) return;
|
||||||
|
assert(pAAFilter);
|
||||||
|
|
||||||
|
// If anti-alias filter is turned off, simply transpose without applying
|
||||||
|
// the filter
|
||||||
|
- if (bUseAAFilter == FALSE)
|
||||||
|
+ if (bUseAAFilter == false)
|
||||||
|
{
|
||||||
|
sizeReq = (uint)((float)nSamples / fRate + 1.0f);
|
||||||
|
count = transpose(outputBuffer.ptrEnd(sizeReq), src, nSamples);
|
||||||
|
outputBuffer.putSamples(count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transpose with anti-alias filter
|
||||||
|
--- /src/RateTransposer.h
|
||||||
|
+++ /src/RateTransposer.h
|
||||||
|
@@ -76,17 +76,17 @@ protected:
|
||||||
|
FIFOSampleBuffer storeBuffer;
|
||||||
|
|
||||||
|
/// Buffer for keeping samples between transposing & anti-alias filter
|
||||||
|
FIFOSampleBuffer tempBuffer;
|
||||||
|
|
||||||
|
/// Output sample buffer
|
||||||
|
FIFOSampleBuffer outputBuffer;
|
||||||
|
|
||||||
|
- BOOL bUseAAFilter;
|
||||||
|
+ bool bUseAAFilter;
|
||||||
|
|
||||||
|
virtual void resetRegisters() = 0;
|
||||||
|
|
||||||
|
virtual uint transposeStereo(SAMPLETYPE *dest,
|
||||||
|
const SAMPLETYPE *src,
|
||||||
|
uint numSamples) = 0;
|
||||||
|
virtual uint transposeMono(SAMPLETYPE *dest,
|
||||||
|
const SAMPLETYPE *src,
|
||||||
|
@@ -126,20 +126,20 @@ public:
|
||||||
|
|
||||||
|
/// Returns the store buffer object
|
||||||
|
FIFOSamplePipe *getStore() { return &storeBuffer; };
|
||||||
|
|
||||||
|
/// Return anti-alias filter object
|
||||||
|
AAFilter *getAAFilter();
|
||||||
|
|
||||||
|
/// Enables/disables the anti-alias filter. Zero to disable, nonzero to enable
|
||||||
|
- void enableAAFilter(BOOL newMode);
|
||||||
|
+ void enableAAFilter(bool newMode);
|
||||||
|
|
||||||
|
/// Returns nonzero if anti-alias filter is enabled.
|
||||||
|
- BOOL isAAFilterEnabled() const;
|
||||||
|
+ bool isAAFilterEnabled() const;
|
||||||
|
|
||||||
|
/// Sets new target rate. Normal rate = 1.0, smaller values represent slower
|
||||||
|
/// rate, larger faster rates.
|
||||||
|
virtual void setRate(float newRate);
|
||||||
|
|
||||||
|
/// Sets the number of channels, 1 = mono, 2 = stereo
|
||||||
|
void setChannels(int channels);
|
||||||
|
|
||||||
|
--- /src/SoundTouch.cpp
|
||||||
|
+++ /src/SoundTouch.cpp
|
||||||
|
@@ -106,17 +106,17 @@ SoundTouch::SoundTouch()
|
||||||
|
|
||||||
|
virtualPitch =
|
||||||
|
virtualRate =
|
||||||
|
virtualTempo = 1.0;
|
||||||
|
|
||||||
|
calcEffectiveRateAndTempo();
|
||||||
|
|
||||||
|
channels = 0;
|
||||||
|
- bSrateSet = FALSE;
|
||||||
|
+ bSrateSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SoundTouch::~SoundTouch()
|
||||||
|
{
|
||||||
|
delete pRateTransposer;
|
||||||
|
delete pTDStretch;
|
||||||
|
@@ -277,27 +277,27 @@ void SoundTouch::calcEffectiveRateAndTem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Sets sample rate.
|
||||||
|
void SoundTouch::setSampleRate(uint srate)
|
||||||
|
{
|
||||||
|
- bSrateSet = TRUE;
|
||||||
|
+ bSrateSet = true;
|
||||||
|
// set sample rate, leave other tempo changer parameters as they are.
|
||||||
|
pTDStretch->setParameters((int)srate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Adds 'numSamples' pcs of samples from the 'samples' memory position into
|
||||||
|
// the input of the object.
|
||||||
|
void SoundTouch::putSamples(const SAMPLETYPE *samples, uint nSamples)
|
||||||
|
{
|
||||||
|
- if (bSrateSet == FALSE)
|
||||||
|
+ if (bSrateSet == false)
|
||||||
|
{
|
||||||
|
ST_THROW_RT_ERROR("SoundTouch : Sample rate not defined");
|
||||||
|
}
|
||||||
|
else if (channels == 0)
|
||||||
|
{
|
||||||
|
ST_THROW_RT_ERROR("SoundTouch : Number of channels not defined");
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -382,57 +382,57 @@ void SoundTouch::flush()
|
||||||
|
pTDStretch->clearInput();
|
||||||
|
// yet leave the 'tempoChanger' output intouched as that's where the
|
||||||
|
// flushed samples are!
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Changes a setting controlling the processing system behaviour. See the
|
||||||
|
// 'SETTING_...' defines for available setting ID's.
|
||||||
|
-BOOL SoundTouch::setSetting(int settingId, int value)
|
||||||
|
+bool SoundTouch::setSetting(int settingId, int value)
|
||||||
|
{
|
||||||
|
int sampleRate, sequenceMs, seekWindowMs, overlapMs;
|
||||||
|
|
||||||
|
// read current tdstretch routine parameters
|
||||||
|
pTDStretch->getParameters(&sampleRate, &sequenceMs, &seekWindowMs, &overlapMs);
|
||||||
|
|
||||||
|
switch (settingId)
|
||||||
|
{
|
||||||
|
case SETTING_USE_AA_FILTER :
|
||||||
|
// enables / disabless anti-alias filter
|
||||||
|
- pRateTransposer->enableAAFilter((value != 0) ? TRUE : FALSE);
|
||||||
|
- return TRUE;
|
||||||
|
+ pRateTransposer->enableAAFilter((value != 0) ? true : false);
|
||||||
|
+ return true;
|
||||||
|
|
||||||
|
case SETTING_AA_FILTER_LENGTH :
|
||||||
|
// sets anti-alias filter length
|
||||||
|
pRateTransposer->getAAFilter()->setLength(value);
|
||||||
|
- return TRUE;
|
||||||
|
+ return true;
|
||||||
|
|
||||||
|
case SETTING_USE_QUICKSEEK :
|
||||||
|
// enables / disables tempo routine quick seeking algorithm
|
||||||
|
- pTDStretch->enableQuickSeek((value != 0) ? TRUE : FALSE);
|
||||||
|
- return TRUE;
|
||||||
|
+ pTDStretch->enableQuickSeek((value != 0) ? true : false);
|
||||||
|
+ return true;
|
||||||
|
|
||||||
|
case SETTING_SEQUENCE_MS:
|
||||||
|
// change time-stretch sequence duration parameter
|
||||||
|
pTDStretch->setParameters(sampleRate, value, seekWindowMs, overlapMs);
|
||||||
|
- return TRUE;
|
||||||
|
+ return true;
|
||||||
|
|
||||||
|
case SETTING_SEEKWINDOW_MS:
|
||||||
|
// change time-stretch seek window length parameter
|
||||||
|
pTDStretch->setParameters(sampleRate, sequenceMs, value, overlapMs);
|
||||||
|
- return TRUE;
|
||||||
|
+ return true;
|
||||||
|
|
||||||
|
case SETTING_OVERLAP_MS:
|
||||||
|
// change time-stretch overlap length parameter
|
||||||
|
pTDStretch->setParameters(sampleRate, sequenceMs, seekWindowMs, value);
|
||||||
|
- return TRUE;
|
||||||
|
+ return true;
|
||||||
|
|
||||||
|
default :
|
||||||
|
- return FALSE;
|
||||||
|
+ return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Reads a setting controlling the processing system behaviour. See the
|
||||||
|
// 'SETTING_...' defines for available setting ID's.
|
||||||
|
//
|
||||||
|
// Returns the setting value.
|
||||||
|
--- /src/TDStretch.cpp
|
||||||
|
+++ /src/TDStretch.cpp
|
||||||
|
@@ -81,25 +81,25 @@ static const short _scanOffsets[5][24]={
|
||||||
|
*
|
||||||
|
* Implementation of the class 'TDStretch'
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
TDStretch::TDStretch() : FIFOProcessor(&outputBuffer)
|
||||||
|
{
|
||||||
|
- bQuickSeek = FALSE;
|
||||||
|
+ bQuickSeek = false;
|
||||||
|
channels = 2;
|
||||||
|
|
||||||
|
pMidBuffer = NULL;
|
||||||
|
pMidBufferUnaligned = NULL;
|
||||||
|
overlapLength = 0;
|
||||||
|
|
||||||
|
- bAutoSeqSetting = TRUE;
|
||||||
|
- bAutoSeekSetting = TRUE;
|
||||||
|
+ bAutoSeqSetting = true;
|
||||||
|
+ bAutoSeekSetting = true;
|
||||||
|
|
||||||
|
// outDebt = 0;
|
||||||
|
skipFract = 0;
|
||||||
|
|
||||||
|
tempo = 1.0f;
|
||||||
|
setParameters(44100, DEFAULT_SEQUENCE_MS, DEFAULT_SEEKWINDOW_MS, DEFAULT_OVERLAP_MS);
|
||||||
|
setTempo(1.0f);
|
||||||
|
|
||||||
|
@@ -129,33 +129,33 @@ void TDStretch::setParameters(int aSampl
|
||||||
|
{
|
||||||
|
// accept only positive parameter values - if zero or negative, use old values instead
|
||||||
|
if (aSampleRate > 0) this->sampleRate = aSampleRate;
|
||||||
|
if (aOverlapMS > 0) this->overlapMs = aOverlapMS;
|
||||||
|
|
||||||
|
if (aSequenceMS > 0)
|
||||||
|
{
|
||||||
|
this->sequenceMs = aSequenceMS;
|
||||||
|
- bAutoSeqSetting = FALSE;
|
||||||
|
+ bAutoSeqSetting = false;
|
||||||
|
}
|
||||||
|
else if (aSequenceMS == 0)
|
||||||
|
{
|
||||||
|
// if zero, use automatic setting
|
||||||
|
- bAutoSeqSetting = TRUE;
|
||||||
|
+ bAutoSeqSetting = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aSeekWindowMS > 0)
|
||||||
|
{
|
||||||
|
this->seekWindowMs = aSeekWindowMS;
|
||||||
|
- bAutoSeekSetting = FALSE;
|
||||||
|
+ bAutoSeekSetting = false;
|
||||||
|
}
|
||||||
|
else if (aSeekWindowMS == 0)
|
||||||
|
{
|
||||||
|
// if zero, use automatic setting
|
||||||
|
- bAutoSeekSetting = TRUE;
|
||||||
|
+ bAutoSeekSetting = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
calcSeqParameters();
|
||||||
|
|
||||||
|
calculateOverlapLength(overlapMs);
|
||||||
|
|
||||||
|
// set tempo to recalculate 'sampleReq'
|
||||||
|
setTempo(tempo);
|
||||||
|
@@ -229,24 +229,24 @@ void TDStretch::clear()
|
||||||
|
outputBuffer.clear();
|
||||||
|
clearInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Enables/disables the quick position seeking algorithm. Zero to disable, nonzero
|
||||||
|
// to enable
|
||||||
|
-void TDStretch::enableQuickSeek(BOOL enable)
|
||||||
|
+void TDStretch::enableQuickSeek(bool enable)
|
||||||
|
{
|
||||||
|
bQuickSeek = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Returns nonzero if the quick seeking algorithm is enabled.
|
||||||
|
-BOOL TDStretch::isQuickSeekEnabled() const
|
||||||
|
+bool TDStretch::isQuickSeekEnabled() const
|
||||||
|
{
|
||||||
|
return bQuickSeek;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Seeks for the optimal overlap-mixing position.
|
||||||
|
int TDStretch::seekBestOverlapPosition(const SAMPLETYPE *refPos)
|
||||||
|
{
|
||||||
|
--- /src/TDStretch.h
|
||||||
|
+++ /src/TDStretch.h
|
||||||
|
@@ -120,24 +120,24 @@ protected:
|
||||||
|
int seekLength;
|
||||||
|
int seekWindowLength;
|
||||||
|
int overlapDividerBits;
|
||||||
|
int slopingDivider;
|
||||||
|
float nominalSkip;
|
||||||
|
float skipFract;
|
||||||
|
FIFOSampleBuffer outputBuffer;
|
||||||
|
FIFOSampleBuffer inputBuffer;
|
||||||
|
- BOOL bQuickSeek;
|
||||||
|
+ bool bQuickSeek;
|
||||||
|
|
||||||
|
int sampleRate;
|
||||||
|
int sequenceMs;
|
||||||
|
int seekWindowMs;
|
||||||
|
int overlapMs;
|
||||||
|
- BOOL bAutoSeqSetting;
|
||||||
|
- BOOL bAutoSeekSetting;
|
||||||
|
+ bool bAutoSeqSetting;
|
||||||
|
+ bool bAutoSeekSetting;
|
||||||
|
|
||||||
|
void acceptNewOverlapLength(int newOverlapLength);
|
||||||
|
|
||||||
|
virtual void clearCrossCorrState();
|
||||||
|
void calculateOverlapLength(int overlapMs);
|
||||||
|
|
||||||
|
virtual double calcCrossCorr(const SAMPLETYPE *mixingPos, const SAMPLETYPE *compare) const;
|
||||||
|
|
||||||
|
@@ -188,20 +188,20 @@ public:
|
||||||
|
/// Clears the input buffer
|
||||||
|
void clearInput();
|
||||||
|
|
||||||
|
/// Sets the number of channels, 1 = mono, 2 = stereo
|
||||||
|
void setChannels(int numChannels);
|
||||||
|
|
||||||
|
/// Enables/disables the quick position seeking algorithm. Zero to disable,
|
||||||
|
/// nonzero to enable
|
||||||
|
- void enableQuickSeek(BOOL enable);
|
||||||
|
+ void enableQuickSeek(bool enable);
|
||||||
|
|
||||||
|
/// Returns nonzero if the quick seeking algorithm is enabled.
|
||||||
|
- BOOL isQuickSeekEnabled() const;
|
||||||
|
+ bool isQuickSeekEnabled() const;
|
||||||
|
|
||||||
|
/// Sets routine control parameters. These control are certain time constants
|
||||||
|
/// defining how the sound is stretched to the desired duration.
|
||||||
|
//
|
||||||
|
/// 'sampleRate' = sample rate of the sound
|
||||||
|
/// 'sequenceMS' = one processing sequence length in milliseconds
|
||||||
|
/// 'seekwindowMS' = seeking window length for scanning the best overlapping
|
||||||
|
/// position
|
||||||
|
only in patch2:
|
||||||
|
--- /src/cpu_detect_x86.cpp 2012-04-12 19:52:12.743376976 -0700
|
||||||
|
+++ /src/cpu_detect_x86.cpp 2012-08-02 09:54:24.561712171 -0700
|
||||||
|
@@ -38,30 +38,35 @@
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "cpu_detect.h"
|
||||||
|
#include "STTypes.h"
|
||||||
|
|
||||||
|
#if defined(SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS)
|
||||||
|
-
|
||||||
|
- #if defined(__GNUC__) && defined(__i386__)
|
||||||
|
- // gcc
|
||||||
|
+ #if defined(__GNUC__)
|
||||||
|
+ // gcc and clang
|
||||||
|
#include "cpuid.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_M_IX86)
|
||||||
|
// windows
|
||||||
|
#include <intrin.h>
|
||||||
|
- #define bit_MMX (1 << 23)
|
||||||
|
- #define bit_SSE (1 << 25)
|
||||||
|
- #define bit_SSE2 (1 << 26)
|
||||||
|
#endif
|
||||||
|
-
|
||||||
|
+ // If we still don't have the macros, define them (Windows, MacOS)
|
||||||
|
+ #ifndef bit_MMX
|
||||||
|
+ #define bit_MMX (1 << 23)
|
||||||
|
+ #endif
|
||||||
|
+ #ifndef bit_SSE
|
||||||
|
+ #define bit_SSE (1 << 25)
|
||||||
|
+ #endif
|
||||||
|
+ #ifndef bit_SSE2
|
||||||
|
+ #define bit_SSE2 (1 << 26)
|
||||||
|
+ #endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// processor instructions extension detection routines
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
184
media/libsoundtouch/src/AAFilter.cpp
Normal file
184
media/libsoundtouch/src/AAFilter.cpp
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// FIR low-pass (anti-alias) filter with filter coefficient design routine and
|
||||||
|
/// MMX optimization.
|
||||||
|
///
|
||||||
|
/// Anti-alias filter is used to prevent folding of high frequencies when
|
||||||
|
/// transposing the sample rate with interpolation.
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2009-01-11 03:34:24 -0800 (Sun, 11 Jan 2009) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: AAFilter.cpp 45 2009-01-11 11:34:24Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <memory.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "AAFilter.h"
|
||||||
|
#include "FIRFilter.h"
|
||||||
|
|
||||||
|
using namespace soundtouch;
|
||||||
|
|
||||||
|
#define PI 3.141592655357989
|
||||||
|
#define TWOPI (2 * PI)
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* Implementation of the class 'AAFilter'
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
AAFilter::AAFilter(uint len)
|
||||||
|
{
|
||||||
|
pFIR = FIRFilter::newInstance();
|
||||||
|
cutoffFreq = 0.5;
|
||||||
|
setLength(len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AAFilter::~AAFilter()
|
||||||
|
{
|
||||||
|
delete pFIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sets new anti-alias filter cut-off edge frequency, scaled to
|
||||||
|
// sampling frequency (nyquist frequency = 0.5).
|
||||||
|
// The filter will cut frequencies higher than the given frequency.
|
||||||
|
void AAFilter::setCutoffFreq(double newCutoffFreq)
|
||||||
|
{
|
||||||
|
cutoffFreq = newCutoffFreq;
|
||||||
|
calculateCoeffs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sets number of FIR filter taps
|
||||||
|
void AAFilter::setLength(uint newLength)
|
||||||
|
{
|
||||||
|
length = newLength;
|
||||||
|
calculateCoeffs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Calculates coefficients for a low-pass FIR filter using Hamming window
|
||||||
|
void AAFilter::calculateCoeffs()
|
||||||
|
{
|
||||||
|
uint i;
|
||||||
|
double cntTemp, temp, tempCoeff,h, w;
|
||||||
|
double fc2, wc;
|
||||||
|
double scaleCoeff, sum;
|
||||||
|
double *work;
|
||||||
|
SAMPLETYPE *coeffs;
|
||||||
|
|
||||||
|
assert(length >= 2);
|
||||||
|
assert(length % 4 == 0);
|
||||||
|
assert(cutoffFreq >= 0);
|
||||||
|
assert(cutoffFreq <= 0.5);
|
||||||
|
|
||||||
|
work = new double[length];
|
||||||
|
coeffs = new SAMPLETYPE[length];
|
||||||
|
|
||||||
|
fc2 = 2.0 * cutoffFreq;
|
||||||
|
wc = PI * fc2;
|
||||||
|
tempCoeff = TWOPI / (double)length;
|
||||||
|
|
||||||
|
sum = 0;
|
||||||
|
for (i = 0; i < length; i ++)
|
||||||
|
{
|
||||||
|
cntTemp = (double)i - (double)(length / 2);
|
||||||
|
|
||||||
|
temp = cntTemp * wc;
|
||||||
|
if (temp != 0)
|
||||||
|
{
|
||||||
|
h = fc2 * sin(temp) / temp; // sinc function
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
h = 1.0;
|
||||||
|
}
|
||||||
|
w = 0.54 + 0.46 * cos(tempCoeff * cntTemp); // hamming window
|
||||||
|
|
||||||
|
temp = w * h;
|
||||||
|
work[i] = temp;
|
||||||
|
|
||||||
|
// calc net sum of coefficients
|
||||||
|
sum += temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure the sum of coefficients is larger than zero
|
||||||
|
assert(sum > 0);
|
||||||
|
|
||||||
|
// ensure we've really designed a lowpass filter...
|
||||||
|
assert(work[length/2] > 0);
|
||||||
|
assert(work[length/2 + 1] > -1e-6);
|
||||||
|
assert(work[length/2 - 1] > -1e-6);
|
||||||
|
|
||||||
|
// Calculate a scaling coefficient in such a way that the result can be
|
||||||
|
// divided by 16384
|
||||||
|
scaleCoeff = 16384.0f / sum;
|
||||||
|
|
||||||
|
for (i = 0; i < length; i ++)
|
||||||
|
{
|
||||||
|
// scale & round to nearest integer
|
||||||
|
temp = work[i] * scaleCoeff;
|
||||||
|
temp += (temp >= 0) ? 0.5 : -0.5;
|
||||||
|
// ensure no overfloods
|
||||||
|
assert(temp >= -32768 && temp <= 32767);
|
||||||
|
coeffs[i] = (SAMPLETYPE)temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set coefficients. Use divide factor 14 => divide result by 2^14 = 16384
|
||||||
|
pFIR->setCoefficients(coeffs, length, 14);
|
||||||
|
|
||||||
|
delete[] work;
|
||||||
|
delete[] coeffs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Applies the filter to the given sequence of samples.
|
||||||
|
// Note : The amount of outputted samples is by value of 'filter length'
|
||||||
|
// smaller than the amount of input samples.
|
||||||
|
uint AAFilter::evaluate(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples, uint numChannels) const
|
||||||
|
{
|
||||||
|
return pFIR->evaluate(dest, src, numSamples, numChannels);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint AAFilter::getLength() const
|
||||||
|
{
|
||||||
|
return pFIR->getLength();
|
||||||
|
}
|
91
media/libsoundtouch/src/AAFilter.h
Normal file
91
media/libsoundtouch/src/AAFilter.h
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// Sampled sound tempo changer/time stretch algorithm. Changes the sound tempo
|
||||||
|
/// while maintaining the original pitch by using a time domain WSOLA-like method
|
||||||
|
/// with several performance-increasing tweaks.
|
||||||
|
///
|
||||||
|
/// Anti-alias filter is used to prevent folding of high frequencies when
|
||||||
|
/// transposing the sample rate with interpolation.
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2008-02-10 08:26:55 -0800 (Sun, 10 Feb 2008) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: AAFilter.h 11 2008-02-10 16:26:55Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef AAFilter_H
|
||||||
|
#define AAFilter_H
|
||||||
|
|
||||||
|
#include "STTypes.h"
|
||||||
|
|
||||||
|
namespace soundtouch
|
||||||
|
{
|
||||||
|
|
||||||
|
class AAFilter
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
class FIRFilter *pFIR;
|
||||||
|
|
||||||
|
/// Low-pass filter cut-off frequency, negative = invalid
|
||||||
|
double cutoffFreq;
|
||||||
|
|
||||||
|
/// num of filter taps
|
||||||
|
uint length;
|
||||||
|
|
||||||
|
/// Calculate the FIR coefficients realizing the given cutoff-frequency
|
||||||
|
void calculateCoeffs();
|
||||||
|
public:
|
||||||
|
AAFilter(uint length);
|
||||||
|
|
||||||
|
~AAFilter();
|
||||||
|
|
||||||
|
/// Sets new anti-alias filter cut-off edge frequency, scaled to sampling
|
||||||
|
/// frequency (nyquist frequency = 0.5). The filter will cut off the
|
||||||
|
/// frequencies than that.
|
||||||
|
void setCutoffFreq(double newCutoffFreq);
|
||||||
|
|
||||||
|
/// Sets number of FIR filter taps, i.e. ~filter complexity
|
||||||
|
void setLength(uint newLength);
|
||||||
|
|
||||||
|
uint getLength() const;
|
||||||
|
|
||||||
|
/// Applies the filter to the given sequence of samples.
|
||||||
|
/// Note : The amount of outputted samples is by value of 'filter length'
|
||||||
|
/// smaller than the amount of input samples.
|
||||||
|
uint evaluate(SAMPLETYPE *dest,
|
||||||
|
const SAMPLETYPE *src,
|
||||||
|
uint numSamples,
|
||||||
|
uint numChannels) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
274
media/libsoundtouch/src/FIFOSampleBuffer.cpp
Normal file
274
media/libsoundtouch/src/FIFOSampleBuffer.cpp
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// A buffer class for temporarily storaging sound samples, operates as a
|
||||||
|
/// first-in-first-out pipe.
|
||||||
|
///
|
||||||
|
/// Samples are added to the end of the sample buffer with the 'putSamples'
|
||||||
|
/// function, and are received from the beginning of the buffer by calling
|
||||||
|
/// the 'receiveSamples' function. The class automatically removes the
|
||||||
|
/// outputted samples from the buffer, as well as grows the buffer size
|
||||||
|
/// whenever necessary.
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2012-06-13 12:29:53 -0700 (Wed, 13 Jun 2012) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: FIFOSampleBuffer.cpp 143 2012-06-13 19:29:53Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "FIFOSampleBuffer.h"
|
||||||
|
|
||||||
|
using namespace soundtouch;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
FIFOSampleBuffer::FIFOSampleBuffer(int numChannels)
|
||||||
|
{
|
||||||
|
assert(numChannels > 0);
|
||||||
|
sizeInBytes = 0; // reasonable initial value
|
||||||
|
buffer = NULL;
|
||||||
|
bufferUnaligned = NULL;
|
||||||
|
samplesInBuffer = 0;
|
||||||
|
bufferPos = 0;
|
||||||
|
channels = (uint)numChannels;
|
||||||
|
ensureCapacity(32); // allocate initial capacity
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
FIFOSampleBuffer::~FIFOSampleBuffer()
|
||||||
|
{
|
||||||
|
delete[] bufferUnaligned;
|
||||||
|
bufferUnaligned = NULL;
|
||||||
|
buffer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Sets number of channels, 1 = mono, 2 = stereo
|
||||||
|
void FIFOSampleBuffer::setChannels(int numChannels)
|
||||||
|
{
|
||||||
|
uint usedBytes;
|
||||||
|
|
||||||
|
assert(numChannels > 0);
|
||||||
|
usedBytes = channels * samplesInBuffer;
|
||||||
|
channels = (uint)numChannels;
|
||||||
|
samplesInBuffer = usedBytes / channels;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if output location pointer 'bufferPos' isn't zero, 'rewinds' the buffer and
|
||||||
|
// zeroes this pointer by copying samples from the 'bufferPos' pointer
|
||||||
|
// location on to the beginning of the buffer.
|
||||||
|
void FIFOSampleBuffer::rewind()
|
||||||
|
{
|
||||||
|
if (buffer && bufferPos)
|
||||||
|
{
|
||||||
|
memmove(buffer, ptrBegin(), sizeof(SAMPLETYPE) * channels * samplesInBuffer);
|
||||||
|
bufferPos = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Adds 'numSamples' pcs of samples from the 'samples' memory position to
|
||||||
|
// the sample buffer.
|
||||||
|
void FIFOSampleBuffer::putSamples(const SAMPLETYPE *samples, uint nSamples)
|
||||||
|
{
|
||||||
|
memcpy(ptrEnd(nSamples), samples, sizeof(SAMPLETYPE) * nSamples * channels);
|
||||||
|
samplesInBuffer += nSamples;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Increases the number of samples in the buffer without copying any actual
|
||||||
|
// samples.
|
||||||
|
//
|
||||||
|
// This function is used to update the number of samples in the sample buffer
|
||||||
|
// when accessing the buffer directly with 'ptrEnd' function. Please be
|
||||||
|
// careful though!
|
||||||
|
void FIFOSampleBuffer::putSamples(uint nSamples)
|
||||||
|
{
|
||||||
|
uint req;
|
||||||
|
|
||||||
|
req = samplesInBuffer + nSamples;
|
||||||
|
ensureCapacity(req);
|
||||||
|
samplesInBuffer += nSamples;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Returns a pointer to the end of the used part of the sample buffer (i.e.
|
||||||
|
// where the new samples are to be inserted). This function may be used for
|
||||||
|
// inserting new samples into the sample buffer directly. Please be careful!
|
||||||
|
//
|
||||||
|
// Parameter 'slackCapacity' tells the function how much free capacity (in
|
||||||
|
// terms of samples) there _at least_ should be, in order to the caller to
|
||||||
|
// succesfully insert all the required samples to the buffer. When necessary,
|
||||||
|
// the function grows the buffer size to comply with this requirement.
|
||||||
|
//
|
||||||
|
// When using this function as means for inserting new samples, also remember
|
||||||
|
// to increase the sample count afterwards, by calling the
|
||||||
|
// 'putSamples(numSamples)' function.
|
||||||
|
SAMPLETYPE *FIFOSampleBuffer::ptrEnd(uint slackCapacity)
|
||||||
|
{
|
||||||
|
ensureCapacity(samplesInBuffer + slackCapacity);
|
||||||
|
return buffer + samplesInBuffer * channels;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Returns a pointer to the beginning of the currently non-outputted samples.
|
||||||
|
// This function is provided for accessing the output samples directly.
|
||||||
|
// Please be careful!
|
||||||
|
//
|
||||||
|
// When using this function to output samples, also remember to 'remove' the
|
||||||
|
// outputted samples from the buffer by calling the
|
||||||
|
// 'receiveSamples(numSamples)' function
|
||||||
|
SAMPLETYPE *FIFOSampleBuffer::ptrBegin()
|
||||||
|
{
|
||||||
|
assert(buffer);
|
||||||
|
return buffer + bufferPos * channels;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Ensures that the buffer has enought capacity, i.e. space for _at least_
|
||||||
|
// 'capacityRequirement' number of samples. The buffer is grown in steps of
|
||||||
|
// 4 kilobytes to eliminate the need for frequently growing up the buffer,
|
||||||
|
// as well as to round the buffer size up to the virtual memory page size.
|
||||||
|
void FIFOSampleBuffer::ensureCapacity(uint capacityRequirement)
|
||||||
|
{
|
||||||
|
SAMPLETYPE *tempUnaligned, *temp;
|
||||||
|
|
||||||
|
if (capacityRequirement > getCapacity())
|
||||||
|
{
|
||||||
|
// enlarge the buffer in 4kbyte steps (round up to next 4k boundary)
|
||||||
|
sizeInBytes = (capacityRequirement * channels * sizeof(SAMPLETYPE) + 4095) & (uint)-4096;
|
||||||
|
assert(sizeInBytes % 2 == 0);
|
||||||
|
tempUnaligned = new SAMPLETYPE[sizeInBytes / sizeof(SAMPLETYPE) + 16 / sizeof(SAMPLETYPE)];
|
||||||
|
if (tempUnaligned == NULL)
|
||||||
|
{
|
||||||
|
ST_THROW_RT_ERROR("Couldn't allocate memory!\n");
|
||||||
|
}
|
||||||
|
// Align the buffer to begin at 16byte cache line boundary for optimal performance
|
||||||
|
temp = (SAMPLETYPE *)(((ulong)tempUnaligned + 15) & (ulong)-16);
|
||||||
|
if (samplesInBuffer)
|
||||||
|
{
|
||||||
|
memcpy(temp, ptrBegin(), samplesInBuffer * channels * sizeof(SAMPLETYPE));
|
||||||
|
}
|
||||||
|
delete[] bufferUnaligned;
|
||||||
|
buffer = temp;
|
||||||
|
bufferUnaligned = tempUnaligned;
|
||||||
|
bufferPos = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// simply rewind the buffer (if necessary)
|
||||||
|
rewind();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Returns the current buffer capacity in terms of samples
|
||||||
|
uint FIFOSampleBuffer::getCapacity() const
|
||||||
|
{
|
||||||
|
return sizeInBytes / (channels * sizeof(SAMPLETYPE));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Returns the number of samples currently in the buffer
|
||||||
|
uint FIFOSampleBuffer::numSamples() const
|
||||||
|
{
|
||||||
|
return samplesInBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Output samples from beginning of the sample buffer. Copies demanded number
|
||||||
|
// of samples to output and removes them from the sample buffer. If there
|
||||||
|
// are less than 'numsample' samples in the buffer, returns all available.
|
||||||
|
//
|
||||||
|
// Returns number of samples copied.
|
||||||
|
uint FIFOSampleBuffer::receiveSamples(SAMPLETYPE *output, uint maxSamples)
|
||||||
|
{
|
||||||
|
uint num;
|
||||||
|
|
||||||
|
num = (maxSamples > samplesInBuffer) ? samplesInBuffer : maxSamples;
|
||||||
|
|
||||||
|
memcpy(output, ptrBegin(), channels * sizeof(SAMPLETYPE) * num);
|
||||||
|
return receiveSamples(num);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Removes samples from the beginning of the sample buffer without copying them
|
||||||
|
// anywhere. Used to reduce the number of samples in the buffer, when accessing
|
||||||
|
// the sample buffer with the 'ptrBegin' function.
|
||||||
|
uint FIFOSampleBuffer::receiveSamples(uint maxSamples)
|
||||||
|
{
|
||||||
|
if (maxSamples >= samplesInBuffer)
|
||||||
|
{
|
||||||
|
uint temp;
|
||||||
|
|
||||||
|
temp = samplesInBuffer;
|
||||||
|
samplesInBuffer = 0;
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
samplesInBuffer -= maxSamples;
|
||||||
|
bufferPos += maxSamples;
|
||||||
|
|
||||||
|
return maxSamples;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Returns nonzero if the sample buffer is empty
|
||||||
|
int FIFOSampleBuffer::isEmpty() const
|
||||||
|
{
|
||||||
|
return (samplesInBuffer == 0) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Clears the sample buffer
|
||||||
|
void FIFOSampleBuffer::clear()
|
||||||
|
{
|
||||||
|
samplesInBuffer = 0;
|
||||||
|
bufferPos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// allow trimming (downwards) amount of samples in pipeline.
|
||||||
|
/// Returns adjusted amount of samples
|
||||||
|
uint FIFOSampleBuffer::adjustAmountOfSamples(uint numSamples)
|
||||||
|
{
|
||||||
|
if (numSamples < samplesInBuffer)
|
||||||
|
{
|
||||||
|
samplesInBuffer = numSamples;
|
||||||
|
}
|
||||||
|
return samplesInBuffer;
|
||||||
|
}
|
||||||
|
|
178
media/libsoundtouch/src/FIFOSampleBuffer.h
Normal file
178
media/libsoundtouch/src/FIFOSampleBuffer.h
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// A buffer class for temporarily storaging sound samples, operates as a
|
||||||
|
/// first-in-first-out pipe.
|
||||||
|
///
|
||||||
|
/// Samples are added to the end of the sample buffer with the 'putSamples'
|
||||||
|
/// function, and are received from the beginning of the buffer by calling
|
||||||
|
/// the 'receiveSamples' function. The class automatically removes the
|
||||||
|
/// output samples from the buffer as well as grows the storage size
|
||||||
|
/// whenever necessary.
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2012-06-13 12:29:53 -0700 (Wed, 13 Jun 2012) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: FIFOSampleBuffer.h 143 2012-06-13 19:29:53Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef FIFOSampleBuffer_H
|
||||||
|
#define FIFOSampleBuffer_H
|
||||||
|
|
||||||
|
#include "FIFOSamplePipe.h"
|
||||||
|
|
||||||
|
namespace soundtouch
|
||||||
|
{
|
||||||
|
|
||||||
|
/// Sample buffer working in FIFO (first-in-first-out) principle. The class takes
|
||||||
|
/// care of storage size adjustment and data moving during input/output operations.
|
||||||
|
///
|
||||||
|
/// Notice that in case of stereo audio, one sample is considered to consist of
|
||||||
|
/// both channel data.
|
||||||
|
class FIFOSampleBuffer : public FIFOSamplePipe
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
/// Sample buffer.
|
||||||
|
SAMPLETYPE *buffer;
|
||||||
|
|
||||||
|
// Raw unaligned buffer memory. 'buffer' is made aligned by pointing it to first
|
||||||
|
// 16-byte aligned location of this buffer
|
||||||
|
SAMPLETYPE *bufferUnaligned;
|
||||||
|
|
||||||
|
/// Sample buffer size in bytes
|
||||||
|
uint sizeInBytes;
|
||||||
|
|
||||||
|
/// How many samples are currently in buffer.
|
||||||
|
uint samplesInBuffer;
|
||||||
|
|
||||||
|
/// Channels, 1=mono, 2=stereo.
|
||||||
|
uint channels;
|
||||||
|
|
||||||
|
/// Current position pointer to the buffer. This pointer is increased when samples are
|
||||||
|
/// removed from the pipe so that it's necessary to actually rewind buffer (move data)
|
||||||
|
/// only new data when is put to the pipe.
|
||||||
|
uint bufferPos;
|
||||||
|
|
||||||
|
/// Rewind the buffer by moving data from position pointed by 'bufferPos' to real
|
||||||
|
/// beginning of the buffer.
|
||||||
|
void rewind();
|
||||||
|
|
||||||
|
/// Ensures that the buffer has capacity for at least this many samples.
|
||||||
|
void ensureCapacity(uint capacityRequirement);
|
||||||
|
|
||||||
|
/// Returns current capacity.
|
||||||
|
uint getCapacity() const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/// Constructor
|
||||||
|
FIFOSampleBuffer(int numChannels = 2 ///< Number of channels, 1=mono, 2=stereo.
|
||||||
|
///< Default is stereo.
|
||||||
|
);
|
||||||
|
|
||||||
|
/// destructor
|
||||||
|
~FIFOSampleBuffer();
|
||||||
|
|
||||||
|
/// Returns a pointer to the beginning of the output samples.
|
||||||
|
/// This function is provided for accessing the output samples directly.
|
||||||
|
/// Please be careful for not to corrupt the book-keeping!
|
||||||
|
///
|
||||||
|
/// When using this function to output samples, also remember to 'remove' the
|
||||||
|
/// output samples from the buffer by calling the
|
||||||
|
/// 'receiveSamples(numSamples)' function
|
||||||
|
virtual SAMPLETYPE *ptrBegin();
|
||||||
|
|
||||||
|
/// Returns a pointer to the end of the used part of the sample buffer (i.e.
|
||||||
|
/// where the new samples are to be inserted). This function may be used for
|
||||||
|
/// inserting new samples into the sample buffer directly. Please be careful
|
||||||
|
/// not corrupt the book-keeping!
|
||||||
|
///
|
||||||
|
/// When using this function as means for inserting new samples, also remember
|
||||||
|
/// to increase the sample count afterwards, by calling the
|
||||||
|
/// 'putSamples(numSamples)' function.
|
||||||
|
SAMPLETYPE *ptrEnd(
|
||||||
|
uint slackCapacity ///< How much free capacity (in samples) there _at least_
|
||||||
|
///< should be so that the caller can succesfully insert the
|
||||||
|
///< desired samples to the buffer. If necessary, the function
|
||||||
|
///< grows the buffer size to comply with this requirement.
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Adds 'numSamples' pcs of samples from the 'samples' memory position to
|
||||||
|
/// the sample buffer.
|
||||||
|
virtual void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples.
|
||||||
|
uint numSamples ///< Number of samples to insert.
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Adjusts the book-keeping to increase number of samples in the buffer without
|
||||||
|
/// copying any actual samples.
|
||||||
|
///
|
||||||
|
/// This function is used to update the number of samples in the sample buffer
|
||||||
|
/// when accessing the buffer directly with 'ptrEnd' function. Please be
|
||||||
|
/// careful though!
|
||||||
|
virtual void putSamples(uint numSamples ///< Number of samples been inserted.
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Output samples from beginning of the sample buffer. Copies requested samples to
|
||||||
|
/// output buffer and removes them from the sample buffer. If there are less than
|
||||||
|
/// 'numsample' samples in the buffer, returns all that available.
|
||||||
|
///
|
||||||
|
/// \return Number of samples returned.
|
||||||
|
virtual uint receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples.
|
||||||
|
uint maxSamples ///< How many samples to receive at max.
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Adjusts book-keeping so that given number of samples are removed from beginning of the
|
||||||
|
/// sample buffer without copying them anywhere.
|
||||||
|
///
|
||||||
|
/// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
|
||||||
|
/// with 'ptrBegin' function.
|
||||||
|
virtual uint receiveSamples(uint maxSamples ///< Remove this many samples from the beginning of pipe.
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Returns number of samples currently available.
|
||||||
|
virtual uint numSamples() const;
|
||||||
|
|
||||||
|
/// Sets number of channels, 1 = mono, 2 = stereo.
|
||||||
|
void setChannels(int numChannels);
|
||||||
|
|
||||||
|
/// Returns nonzero if there aren't any samples available for outputting.
|
||||||
|
virtual int isEmpty() const;
|
||||||
|
|
||||||
|
/// Clears all the samples.
|
||||||
|
virtual void clear();
|
||||||
|
|
||||||
|
/// allow trimming (downwards) amount of samples in pipeline.
|
||||||
|
/// Returns adjusted amount of samples
|
||||||
|
uint adjustAmountOfSamples(uint numSamples);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
234
media/libsoundtouch/src/FIFOSamplePipe.h
Normal file
234
media/libsoundtouch/src/FIFOSamplePipe.h
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// 'FIFOSamplePipe' : An abstract base class for classes that manipulate sound
|
||||||
|
/// samples by operating like a first-in-first-out pipe: New samples are fed
|
||||||
|
/// into one end of the pipe with the 'putSamples' function, and the processed
|
||||||
|
/// samples are received from the other end with the 'receiveSamples' function.
|
||||||
|
///
|
||||||
|
/// 'FIFOProcessor' : A base class for classes the do signal processing with
|
||||||
|
/// the samples while operating like a first-in-first-out pipe. When samples
|
||||||
|
/// are input with the 'putSamples' function, the class processes them
|
||||||
|
/// and moves the processed samples to the given 'output' pipe object, which
|
||||||
|
/// may be either another processing stage, or a fifo sample buffer object.
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2012-06-13 12:29:53 -0700 (Wed, 13 Jun 2012) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: FIFOSamplePipe.h 143 2012-06-13 19:29:53Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef FIFOSamplePipe_H
|
||||||
|
#define FIFOSamplePipe_H
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "STTypes.h"
|
||||||
|
|
||||||
|
namespace soundtouch
|
||||||
|
{
|
||||||
|
|
||||||
|
/// Abstract base class for FIFO (first-in-first-out) sample processing classes.
|
||||||
|
class FIFOSamplePipe
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// virtual default destructor
|
||||||
|
virtual ~FIFOSamplePipe() {}
|
||||||
|
|
||||||
|
|
||||||
|
/// Returns a pointer to the beginning of the output samples.
|
||||||
|
/// This function is provided for accessing the output samples directly.
|
||||||
|
/// Please be careful for not to corrupt the book-keeping!
|
||||||
|
///
|
||||||
|
/// When using this function to output samples, also remember to 'remove' the
|
||||||
|
/// output samples from the buffer by calling the
|
||||||
|
/// 'receiveSamples(numSamples)' function
|
||||||
|
virtual SAMPLETYPE *ptrBegin() = 0;
|
||||||
|
|
||||||
|
/// Adds 'numSamples' pcs of samples from the 'samples' memory position to
|
||||||
|
/// the sample buffer.
|
||||||
|
virtual void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples.
|
||||||
|
uint numSamples ///< Number of samples to insert.
|
||||||
|
) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// Moves samples from the 'other' pipe instance to this instance.
|
||||||
|
void moveSamples(FIFOSamplePipe &other ///< Other pipe instance where from the receive the data.
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int oNumSamples = other.numSamples();
|
||||||
|
|
||||||
|
putSamples(other.ptrBegin(), oNumSamples);
|
||||||
|
other.receiveSamples(oNumSamples);
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Output samples from beginning of the sample buffer. Copies requested samples to
|
||||||
|
/// output buffer and removes them from the sample buffer. If there are less than
|
||||||
|
/// 'numsample' samples in the buffer, returns all that available.
|
||||||
|
///
|
||||||
|
/// \return Number of samples returned.
|
||||||
|
virtual uint receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples.
|
||||||
|
uint maxSamples ///< How many samples to receive at max.
|
||||||
|
) = 0;
|
||||||
|
|
||||||
|
/// Adjusts book-keeping so that given number of samples are removed from beginning of the
|
||||||
|
/// sample buffer without copying them anywhere.
|
||||||
|
///
|
||||||
|
/// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
|
||||||
|
/// with 'ptrBegin' function.
|
||||||
|
virtual uint receiveSamples(uint maxSamples ///< Remove this many samples from the beginning of pipe.
|
||||||
|
) = 0;
|
||||||
|
|
||||||
|
/// Returns number of samples currently available.
|
||||||
|
virtual uint numSamples() const = 0;
|
||||||
|
|
||||||
|
// Returns nonzero if there aren't any samples available for outputting.
|
||||||
|
virtual int isEmpty() const = 0;
|
||||||
|
|
||||||
|
/// Clears all the samples.
|
||||||
|
virtual void clear() = 0;
|
||||||
|
|
||||||
|
/// allow trimming (downwards) amount of samples in pipeline.
|
||||||
|
/// Returns adjusted amount of samples
|
||||||
|
virtual uint adjustAmountOfSamples(uint numSamples) = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// Base-class for sound processing routines working in FIFO principle. With this base
|
||||||
|
/// class it's easy to implement sound processing stages that can be chained together,
|
||||||
|
/// so that samples that are fed into beginning of the pipe automatically go through
|
||||||
|
/// all the processing stages.
|
||||||
|
///
|
||||||
|
/// When samples are input to this class, they're first processed and then put to
|
||||||
|
/// the FIFO pipe that's defined as output of this class. This output pipe can be
|
||||||
|
/// either other processing stage or a FIFO sample buffer.
|
||||||
|
class FIFOProcessor :public FIFOSamplePipe
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
/// Internal pipe where processed samples are put.
|
||||||
|
FIFOSamplePipe *output;
|
||||||
|
|
||||||
|
/// Sets output pipe.
|
||||||
|
void setOutPipe(FIFOSamplePipe *pOutput)
|
||||||
|
{
|
||||||
|
assert(output == NULL);
|
||||||
|
assert(pOutput != NULL);
|
||||||
|
output = pOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Constructor. Doesn't define output pipe; it has to be set be
|
||||||
|
/// 'setOutPipe' function.
|
||||||
|
FIFOProcessor()
|
||||||
|
{
|
||||||
|
output = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Constructor. Configures output pipe.
|
||||||
|
FIFOProcessor(FIFOSamplePipe *pOutput ///< Output pipe.
|
||||||
|
)
|
||||||
|
{
|
||||||
|
output = pOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Destructor.
|
||||||
|
virtual ~FIFOProcessor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Returns a pointer to the beginning of the output samples.
|
||||||
|
/// This function is provided for accessing the output samples directly.
|
||||||
|
/// Please be careful for not to corrupt the book-keeping!
|
||||||
|
///
|
||||||
|
/// When using this function to output samples, also remember to 'remove' the
|
||||||
|
/// output samples from the buffer by calling the
|
||||||
|
/// 'receiveSamples(numSamples)' function
|
||||||
|
virtual SAMPLETYPE *ptrBegin()
|
||||||
|
{
|
||||||
|
return output->ptrBegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/// Output samples from beginning of the sample buffer. Copies requested samples to
|
||||||
|
/// output buffer and removes them from the sample buffer. If there are less than
|
||||||
|
/// 'numsample' samples in the buffer, returns all that available.
|
||||||
|
///
|
||||||
|
/// \return Number of samples returned.
|
||||||
|
virtual uint receiveSamples(SAMPLETYPE *outBuffer, ///< Buffer where to copy output samples.
|
||||||
|
uint maxSamples ///< How many samples to receive at max.
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return output->receiveSamples(outBuffer, maxSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Adjusts book-keeping so that given number of samples are removed from beginning of the
|
||||||
|
/// sample buffer without copying them anywhere.
|
||||||
|
///
|
||||||
|
/// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
|
||||||
|
/// with 'ptrBegin' function.
|
||||||
|
virtual uint receiveSamples(uint maxSamples ///< Remove this many samples from the beginning of pipe.
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return output->receiveSamples(maxSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Returns number of samples currently available.
|
||||||
|
virtual uint numSamples() const
|
||||||
|
{
|
||||||
|
return output->numSamples();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Returns nonzero if there aren't any samples available for outputting.
|
||||||
|
virtual int isEmpty() const
|
||||||
|
{
|
||||||
|
return output->isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// allow trimming (downwards) amount of samples in pipeline.
|
||||||
|
/// Returns adjusted amount of samples
|
||||||
|
virtual uint adjustAmountOfSamples(uint numSamples)
|
||||||
|
{
|
||||||
|
return output->adjustAmountOfSamples(numSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
259
media/libsoundtouch/src/FIRFilter.cpp
Normal file
259
media/libsoundtouch/src/FIRFilter.cpp
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// General FIR digital filter routines with MMX optimization.
|
||||||
|
///
|
||||||
|
/// Note : MMX optimized functions reside in a separate, platform-specific file,
|
||||||
|
/// e.g. 'mmx_win.cpp' or 'mmx_gcc.cpp'
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2011-09-02 11:56:11 -0700 (Fri, 02 Sep 2011) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: FIRFilter.cpp 131 2011-09-02 18:56:11Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <memory.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "FIRFilter.h"
|
||||||
|
#include "cpu_detect.h"
|
||||||
|
|
||||||
|
using namespace soundtouch;
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* Implementation of the class 'FIRFilter'
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
FIRFilter::FIRFilter()
|
||||||
|
{
|
||||||
|
resultDivFactor = 0;
|
||||||
|
resultDivider = 0;
|
||||||
|
length = 0;
|
||||||
|
lengthDiv8 = 0;
|
||||||
|
filterCoeffs = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FIRFilter::~FIRFilter()
|
||||||
|
{
|
||||||
|
delete[] filterCoeffs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Usual C-version of the filter routine for stereo sound
|
||||||
|
uint FIRFilter::evaluateFilterStereo(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples) const
|
||||||
|
{
|
||||||
|
uint i, j, end;
|
||||||
|
LONG_SAMPLETYPE suml, sumr;
|
||||||
|
#ifdef SOUNDTOUCH_FLOAT_SAMPLES
|
||||||
|
// when using floating point samples, use a scaler instead of a divider
|
||||||
|
// because division is much slower operation than multiplying.
|
||||||
|
double dScaler = 1.0 / (double)resultDivider;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
assert(length != 0);
|
||||||
|
assert(src != NULL);
|
||||||
|
assert(dest != NULL);
|
||||||
|
assert(filterCoeffs != NULL);
|
||||||
|
|
||||||
|
end = 2 * (numSamples - length);
|
||||||
|
|
||||||
|
for (j = 0; j < end; j += 2)
|
||||||
|
{
|
||||||
|
const SAMPLETYPE *ptr;
|
||||||
|
|
||||||
|
suml = sumr = 0;
|
||||||
|
ptr = src + j;
|
||||||
|
|
||||||
|
for (i = 0; i < length; i += 4)
|
||||||
|
{
|
||||||
|
// loop is unrolled by factor of 4 here for efficiency
|
||||||
|
suml += ptr[2 * i + 0] * filterCoeffs[i + 0] +
|
||||||
|
ptr[2 * i + 2] * filterCoeffs[i + 1] +
|
||||||
|
ptr[2 * i + 4] * filterCoeffs[i + 2] +
|
||||||
|
ptr[2 * i + 6] * filterCoeffs[i + 3];
|
||||||
|
sumr += ptr[2 * i + 1] * filterCoeffs[i + 0] +
|
||||||
|
ptr[2 * i + 3] * filterCoeffs[i + 1] +
|
||||||
|
ptr[2 * i + 5] * filterCoeffs[i + 2] +
|
||||||
|
ptr[2 * i + 7] * filterCoeffs[i + 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
|
||||||
|
suml >>= resultDivFactor;
|
||||||
|
sumr >>= resultDivFactor;
|
||||||
|
// saturate to 16 bit integer limits
|
||||||
|
suml = (suml < -32768) ? -32768 : (suml > 32767) ? 32767 : suml;
|
||||||
|
// saturate to 16 bit integer limits
|
||||||
|
sumr = (sumr < -32768) ? -32768 : (sumr > 32767) ? 32767 : sumr;
|
||||||
|
#else
|
||||||
|
suml *= dScaler;
|
||||||
|
sumr *= dScaler;
|
||||||
|
#endif // SOUNDTOUCH_INTEGER_SAMPLES
|
||||||
|
dest[j] = (SAMPLETYPE)suml;
|
||||||
|
dest[j + 1] = (SAMPLETYPE)sumr;
|
||||||
|
}
|
||||||
|
return numSamples - length;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Usual C-version of the filter routine for mono sound
|
||||||
|
uint FIRFilter::evaluateFilterMono(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples) const
|
||||||
|
{
|
||||||
|
uint i, j, end;
|
||||||
|
LONG_SAMPLETYPE sum;
|
||||||
|
#ifdef SOUNDTOUCH_FLOAT_SAMPLES
|
||||||
|
// when using floating point samples, use a scaler instead of a divider
|
||||||
|
// because division is much slower operation than multiplying.
|
||||||
|
double dScaler = 1.0 / (double)resultDivider;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
assert(length != 0);
|
||||||
|
|
||||||
|
end = numSamples - length;
|
||||||
|
for (j = 0; j < end; j ++)
|
||||||
|
{
|
||||||
|
sum = 0;
|
||||||
|
for (i = 0; i < length; i += 4)
|
||||||
|
{
|
||||||
|
// loop is unrolled by factor of 4 here for efficiency
|
||||||
|
sum += src[i + 0] * filterCoeffs[i + 0] +
|
||||||
|
src[i + 1] * filterCoeffs[i + 1] +
|
||||||
|
src[i + 2] * filterCoeffs[i + 2] +
|
||||||
|
src[i + 3] * filterCoeffs[i + 3];
|
||||||
|
}
|
||||||
|
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
|
||||||
|
sum >>= resultDivFactor;
|
||||||
|
// saturate to 16 bit integer limits
|
||||||
|
sum = (sum < -32768) ? -32768 : (sum > 32767) ? 32767 : sum;
|
||||||
|
#else
|
||||||
|
sum *= dScaler;
|
||||||
|
#endif // SOUNDTOUCH_INTEGER_SAMPLES
|
||||||
|
dest[j] = (SAMPLETYPE)sum;
|
||||||
|
src ++;
|
||||||
|
}
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Set filter coeffiecients and length.
|
||||||
|
//
|
||||||
|
// Throws an exception if filter length isn't divisible by 8
|
||||||
|
void FIRFilter::setCoefficients(const SAMPLETYPE *coeffs, uint newLength, uint uResultDivFactor)
|
||||||
|
{
|
||||||
|
assert(newLength > 0);
|
||||||
|
if (newLength % 8) ST_THROW_RT_ERROR("FIR filter length not divisible by 8");
|
||||||
|
|
||||||
|
lengthDiv8 = newLength / 8;
|
||||||
|
length = lengthDiv8 * 8;
|
||||||
|
assert(length == newLength);
|
||||||
|
|
||||||
|
resultDivFactor = uResultDivFactor;
|
||||||
|
resultDivider = (SAMPLETYPE)::pow(2.0, (int)resultDivFactor);
|
||||||
|
|
||||||
|
delete[] filterCoeffs;
|
||||||
|
filterCoeffs = new SAMPLETYPE[length];
|
||||||
|
memcpy(filterCoeffs, coeffs, length * sizeof(SAMPLETYPE));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint FIRFilter::getLength() const
|
||||||
|
{
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Applies the filter to the given sequence of samples.
|
||||||
|
//
|
||||||
|
// Note : The amount of outputted samples is by value of 'filter_length'
|
||||||
|
// smaller than the amount of input samples.
|
||||||
|
uint FIRFilter::evaluate(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples, uint numChannels) const
|
||||||
|
{
|
||||||
|
assert(numChannels == 1 || numChannels == 2);
|
||||||
|
|
||||||
|
assert(length > 0);
|
||||||
|
assert(lengthDiv8 * 8 == length);
|
||||||
|
if (numSamples < length) return 0;
|
||||||
|
if (numChannels == 2)
|
||||||
|
{
|
||||||
|
return evaluateFilterStereo(dest, src, numSamples);
|
||||||
|
} else {
|
||||||
|
return evaluateFilterMono(dest, src, numSamples);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Operator 'new' is overloaded so that it automatically creates a suitable instance
|
||||||
|
// depending on if we've a MMX-capable CPU available or not.
|
||||||
|
void * FIRFilter::operator new(size_t s)
|
||||||
|
{
|
||||||
|
// Notice! don't use "new FIRFilter" directly, use "newInstance" to create a new instance instead!
|
||||||
|
ST_THROW_RT_ERROR("Error in FIRFilter::new: Don't use 'new FIRFilter', use 'newInstance' member instead!");
|
||||||
|
return newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FIRFilter * FIRFilter::newInstance()
|
||||||
|
{
|
||||||
|
uint uExtensions;
|
||||||
|
|
||||||
|
uExtensions = detectCPUextensions();
|
||||||
|
|
||||||
|
// Check if MMX/SSE instruction set extensions supported by CPU
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_ALLOW_MMX
|
||||||
|
// MMX routines available only with integer sample types
|
||||||
|
if (uExtensions & SUPPORT_MMX)
|
||||||
|
{
|
||||||
|
return ::new FIRFilterMMX;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif // SOUNDTOUCH_ALLOW_MMX
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_ALLOW_SSE
|
||||||
|
if (uExtensions & SUPPORT_SSE)
|
||||||
|
{
|
||||||
|
// SSE support
|
||||||
|
return ::new FIRFilterSSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif // SOUNDTOUCH_ALLOW_SSE
|
||||||
|
|
||||||
|
{
|
||||||
|
// ISA optimizations not supported, use plain C version
|
||||||
|
return ::new FIRFilter;
|
||||||
|
}
|
||||||
|
}
|
145
media/libsoundtouch/src/FIRFilter.h
Normal file
145
media/libsoundtouch/src/FIRFilter.h
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// General FIR digital filter routines with MMX optimization.
|
||||||
|
///
|
||||||
|
/// Note : MMX optimized functions reside in a separate, platform-specific file,
|
||||||
|
/// e.g. 'mmx_win.cpp' or 'mmx_gcc.cpp'
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2011-02-13 11:13:57 -0800 (Sun, 13 Feb 2011) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: FIRFilter.h 104 2011-02-13 19:13:57Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef FIRFilter_H
|
||||||
|
#define FIRFilter_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include "STTypes.h"
|
||||||
|
|
||||||
|
namespace soundtouch
|
||||||
|
{
|
||||||
|
|
||||||
|
class FIRFilter
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
// Number of FIR filter taps
|
||||||
|
uint length;
|
||||||
|
// Number of FIR filter taps divided by 8
|
||||||
|
uint lengthDiv8;
|
||||||
|
|
||||||
|
// Result divider factor in 2^k format
|
||||||
|
uint resultDivFactor;
|
||||||
|
|
||||||
|
// Result divider value.
|
||||||
|
SAMPLETYPE resultDivider;
|
||||||
|
|
||||||
|
// Memory for filter coefficients
|
||||||
|
SAMPLETYPE *filterCoeffs;
|
||||||
|
|
||||||
|
virtual uint evaluateFilterStereo(SAMPLETYPE *dest,
|
||||||
|
const SAMPLETYPE *src,
|
||||||
|
uint numSamples) const;
|
||||||
|
virtual uint evaluateFilterMono(SAMPLETYPE *dest,
|
||||||
|
const SAMPLETYPE *src,
|
||||||
|
uint numSamples) const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
FIRFilter();
|
||||||
|
virtual ~FIRFilter();
|
||||||
|
|
||||||
|
/// Operator 'new' is overloaded so that it automatically creates a suitable instance
|
||||||
|
/// depending on if we've a MMX-capable CPU available or not.
|
||||||
|
static void * operator new(size_t s);
|
||||||
|
|
||||||
|
static FIRFilter *newInstance();
|
||||||
|
|
||||||
|
/// Applies the filter to the given sequence of samples.
|
||||||
|
/// Note : The amount of outputted samples is by value of 'filter_length'
|
||||||
|
/// smaller than the amount of input samples.
|
||||||
|
///
|
||||||
|
/// \return Number of samples copied to 'dest'.
|
||||||
|
uint evaluate(SAMPLETYPE *dest,
|
||||||
|
const SAMPLETYPE *src,
|
||||||
|
uint numSamples,
|
||||||
|
uint numChannels) const;
|
||||||
|
|
||||||
|
uint getLength() const;
|
||||||
|
|
||||||
|
virtual void setCoefficients(const SAMPLETYPE *coeffs,
|
||||||
|
uint newLength,
|
||||||
|
uint uResultDivFactor);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Optional subclasses that implement CPU-specific optimizations:
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_ALLOW_MMX
|
||||||
|
|
||||||
|
/// Class that implements MMX optimized functions exclusive for 16bit integer samples type.
|
||||||
|
class FIRFilterMMX : public FIRFilter
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
short *filterCoeffsUnalign;
|
||||||
|
short *filterCoeffsAlign;
|
||||||
|
|
||||||
|
virtual uint evaluateFilterStereo(short *dest, const short *src, uint numSamples) const;
|
||||||
|
public:
|
||||||
|
FIRFilterMMX();
|
||||||
|
~FIRFilterMMX();
|
||||||
|
|
||||||
|
virtual void setCoefficients(const short *coeffs, uint newLength, uint uResultDivFactor);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SOUNDTOUCH_ALLOW_MMX
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_ALLOW_SSE
|
||||||
|
/// Class that implements SSE optimized functions exclusive for floating point samples type.
|
||||||
|
class FIRFilterSSE : public FIRFilter
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
float *filterCoeffsUnalign;
|
||||||
|
float *filterCoeffsAlign;
|
||||||
|
|
||||||
|
virtual uint evaluateFilterStereo(float *dest, const float *src, uint numSamples) const;
|
||||||
|
public:
|
||||||
|
FIRFilterSSE();
|
||||||
|
~FIRFilterSSE();
|
||||||
|
|
||||||
|
virtual void setCoefficients(const float *coeffs, uint newLength, uint uResultDivFactor);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SOUNDTOUCH_ALLOW_SSE
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FIRFilter_H
|
69
media/libsoundtouch/src/Makefile.in
Normal file
69
media/libsoundtouch/src/Makefile.in
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
DEPTH = @DEPTH@
|
||||||
|
topsrcdir = @top_srcdir@
|
||||||
|
srcdir = @srcdir@
|
||||||
|
VPATH = @srcdir@
|
||||||
|
|
||||||
|
include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
|
MODULE = soundtouch
|
||||||
|
LIBRARY_NAME = soundtouch
|
||||||
|
SHORT_LIBNAME = soundt
|
||||||
|
FORCE_SHARED_LIB = 1
|
||||||
|
VISIBILITY_FLAGS =
|
||||||
|
EXPORTS_NAMESPACES = soundtouch
|
||||||
|
|
||||||
|
ifeq ($(OS_ARCH),WINNT)
|
||||||
|
ifndef GNU_CC
|
||||||
|
RCFILE = $(srcdir)/soundtouch.rc
|
||||||
|
RESFILE = $(srcdir)/soundtouch.res
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
EXTRA_DSO_LDOPTS += $(MOZALLOC_LIB)
|
||||||
|
|
||||||
|
# Use abort() instead of exception in SoundTouch.
|
||||||
|
DEFINES += -DST_NO_EXCEPTION_HANDLING=1
|
||||||
|
|
||||||
|
EXPORTS_soundtouch = SoundTouch.h \
|
||||||
|
STTypes.h \
|
||||||
|
FIFOSamplePipe.h \
|
||||||
|
soundtouch_config.h \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
CPPSRCS = AAFilter.cpp \
|
||||||
|
cpu_detect_x86.cpp \
|
||||||
|
FIFOSampleBuffer.cpp \
|
||||||
|
FIRFilter.cpp \
|
||||||
|
RateTransposer.cpp \
|
||||||
|
SoundTouch.cpp \
|
||||||
|
TDStretch.cpp \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
ifneq (,$(INTEL_ARCHITECTURE))
|
||||||
|
ifdef MOZ_SAMPLE_TYPE_FLOAT32
|
||||||
|
CPPSRCS += sse_optimized.cpp
|
||||||
|
else
|
||||||
|
CPPSRCS += mmx_optimized.cpp
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
SOUNDTOUCH_LIBS = $(DLL_PREFIX)soundtouch$(DLL_SUFFIX)
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/rules.mk
|
||||||
|
|
||||||
|
ifneq (,$(INTEL_ARCHITECTURE))
|
||||||
|
ifdef GNU_CC
|
||||||
|
mmx_optimized.$(OBJ_SUFFIX): CXXFLAGS+=-msse2
|
||||||
|
sse_optimized.$(OBJ_SUFFIX): CXXFLAGS+=-msse2
|
||||||
|
endif
|
||||||
|
ifdef SOLARIS_SUNPRO_CXX
|
||||||
|
mmx_optimized.$(OBJ_SUFFIX): OS_CXXFLAGS += -xarch=sse2 -xO4
|
||||||
|
sse_optimized.$(OBJ_SUFFIX): OS_CXXFLAGS += -xarch=sse2 -xO4
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
626
media/libsoundtouch/src/RateTransposer.cpp
Normal file
626
media/libsoundtouch/src/RateTransposer.cpp
Normal file
@ -0,0 +1,626 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// Sample rate transposer. Changes sample rate by using linear interpolation
|
||||||
|
/// together with anti-alias filtering (first order interpolation with anti-
|
||||||
|
/// alias filtering should be quite adequate for this application)
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2011-09-02 11:56:11 -0700 (Fri, 02 Sep 2011) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: RateTransposer.cpp 131 2011-09-02 18:56:11Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <memory.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "RateTransposer.h"
|
||||||
|
#include "AAFilter.h"
|
||||||
|
|
||||||
|
using namespace soundtouch;
|
||||||
|
|
||||||
|
|
||||||
|
/// A linear samplerate transposer class that uses integer arithmetics.
|
||||||
|
/// for the transposing.
|
||||||
|
class RateTransposerInteger : public RateTransposer
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
int iSlopeCount;
|
||||||
|
int iRate;
|
||||||
|
SAMPLETYPE sPrevSampleL, sPrevSampleR;
|
||||||
|
|
||||||
|
virtual void resetRegisters();
|
||||||
|
|
||||||
|
virtual uint transposeStereo(SAMPLETYPE *dest,
|
||||||
|
const SAMPLETYPE *src,
|
||||||
|
uint numSamples);
|
||||||
|
virtual uint transposeMono(SAMPLETYPE *dest,
|
||||||
|
const SAMPLETYPE *src,
|
||||||
|
uint numSamples);
|
||||||
|
|
||||||
|
public:
|
||||||
|
RateTransposerInteger();
|
||||||
|
virtual ~RateTransposerInteger();
|
||||||
|
|
||||||
|
/// Sets new target rate. Normal rate = 1.0, smaller values represent slower
|
||||||
|
/// rate, larger faster rates.
|
||||||
|
virtual void setRate(float newRate);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// A linear samplerate transposer class that uses floating point arithmetics
|
||||||
|
/// for the transposing.
|
||||||
|
class RateTransposerFloat : public RateTransposer
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
float fSlopeCount;
|
||||||
|
SAMPLETYPE sPrevSampleL, sPrevSampleR;
|
||||||
|
|
||||||
|
virtual void resetRegisters();
|
||||||
|
|
||||||
|
virtual uint transposeStereo(SAMPLETYPE *dest,
|
||||||
|
const SAMPLETYPE *src,
|
||||||
|
uint numSamples);
|
||||||
|
virtual uint transposeMono(SAMPLETYPE *dest,
|
||||||
|
const SAMPLETYPE *src,
|
||||||
|
uint numSamples);
|
||||||
|
|
||||||
|
public:
|
||||||
|
RateTransposerFloat();
|
||||||
|
virtual ~RateTransposerFloat();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Operator 'new' is overloaded so that it automatically creates a suitable instance
|
||||||
|
// depending on if we've a MMX/SSE/etc-capable CPU available or not.
|
||||||
|
void * RateTransposer::operator new(size_t s)
|
||||||
|
{
|
||||||
|
ST_THROW_RT_ERROR("Error in RateTransoser::new: don't use \"new TDStretch\" directly, use \"newInstance\" to create a new instance instead!");
|
||||||
|
return newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RateTransposer *RateTransposer::newInstance()
|
||||||
|
{
|
||||||
|
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
|
||||||
|
return ::new RateTransposerInteger;
|
||||||
|
#else
|
||||||
|
return ::new RateTransposerFloat;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
RateTransposer::RateTransposer() : FIFOProcessor(&outputBuffer)
|
||||||
|
{
|
||||||
|
numChannels = 2;
|
||||||
|
bUseAAFilter = true;
|
||||||
|
fRate = 0;
|
||||||
|
|
||||||
|
// Instantiates the anti-alias filter with default tap length
|
||||||
|
// of 32
|
||||||
|
pAAFilter = new AAFilter(32);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RateTransposer::~RateTransposer()
|
||||||
|
{
|
||||||
|
delete pAAFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// Enables/disables the anti-alias filter. Zero to disable, nonzero to enable
|
||||||
|
void RateTransposer::enableAAFilter(bool newMode)
|
||||||
|
{
|
||||||
|
bUseAAFilter = newMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Returns nonzero if anti-alias filter is enabled.
|
||||||
|
bool RateTransposer::isAAFilterEnabled() const
|
||||||
|
{
|
||||||
|
return bUseAAFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AAFilter *RateTransposer::getAAFilter()
|
||||||
|
{
|
||||||
|
return pAAFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sets new target iRate. Normal iRate = 1.0, smaller values represent slower
|
||||||
|
// iRate, larger faster iRates.
|
||||||
|
void RateTransposer::setRate(float newRate)
|
||||||
|
{
|
||||||
|
double fCutoff;
|
||||||
|
|
||||||
|
fRate = newRate;
|
||||||
|
|
||||||
|
// design a new anti-alias filter
|
||||||
|
if (newRate > 1.0f)
|
||||||
|
{
|
||||||
|
fCutoff = 0.5f / newRate;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fCutoff = 0.5f * newRate;
|
||||||
|
}
|
||||||
|
pAAFilter->setCutoffFreq(fCutoff);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Outputs as many samples of the 'outputBuffer' as possible, and if there's
|
||||||
|
// any room left, outputs also as many of the incoming samples as possible.
|
||||||
|
// The goal is to drive the outputBuffer empty.
|
||||||
|
//
|
||||||
|
// It's allowed for 'output' and 'input' parameters to point to the same
|
||||||
|
// memory position.
|
||||||
|
/*
|
||||||
|
void RateTransposer::flushStoreBuffer()
|
||||||
|
{
|
||||||
|
if (storeBuffer.isEmpty()) return;
|
||||||
|
|
||||||
|
outputBuffer.moveSamples(storeBuffer);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// Adds 'nSamples' pcs of samples from the 'samples' memory position into
|
||||||
|
// the input of the object.
|
||||||
|
void RateTransposer::putSamples(const SAMPLETYPE *samples, uint nSamples)
|
||||||
|
{
|
||||||
|
processSamples(samples, nSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Transposes up the sample rate, causing the observed playback 'rate' of the
|
||||||
|
// sound to decrease
|
||||||
|
void RateTransposer::upsample(const SAMPLETYPE *src, uint nSamples)
|
||||||
|
{
|
||||||
|
uint count, sizeTemp, num;
|
||||||
|
|
||||||
|
// If the parameter 'uRate' value is smaller than 'SCALE', first transpose
|
||||||
|
// the samples and then apply the anti-alias filter to remove aliasing.
|
||||||
|
|
||||||
|
// First check that there's enough room in 'storeBuffer'
|
||||||
|
// (+16 is to reserve some slack in the destination buffer)
|
||||||
|
sizeTemp = (uint)((float)nSamples / fRate + 16.0f);
|
||||||
|
|
||||||
|
// Transpose the samples, store the result into the end of "storeBuffer"
|
||||||
|
count = transpose(storeBuffer.ptrEnd(sizeTemp), src, nSamples);
|
||||||
|
storeBuffer.putSamples(count);
|
||||||
|
|
||||||
|
// Apply the anti-alias filter to samples in "store output", output the
|
||||||
|
// result to "dest"
|
||||||
|
num = storeBuffer.numSamples();
|
||||||
|
count = pAAFilter->evaluate(outputBuffer.ptrEnd(num),
|
||||||
|
storeBuffer.ptrBegin(), num, (uint)numChannels);
|
||||||
|
outputBuffer.putSamples(count);
|
||||||
|
|
||||||
|
// Remove the processed samples from "storeBuffer"
|
||||||
|
storeBuffer.receiveSamples(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Transposes down the sample rate, causing the observed playback 'rate' of the
|
||||||
|
// sound to increase
|
||||||
|
void RateTransposer::downsample(const SAMPLETYPE *src, uint nSamples)
|
||||||
|
{
|
||||||
|
uint count, sizeTemp;
|
||||||
|
|
||||||
|
// If the parameter 'uRate' value is larger than 'SCALE', first apply the
|
||||||
|
// anti-alias filter to remove high frequencies (prevent them from folding
|
||||||
|
// over the lover frequencies), then transpose.
|
||||||
|
|
||||||
|
// Add the new samples to the end of the storeBuffer
|
||||||
|
storeBuffer.putSamples(src, nSamples);
|
||||||
|
|
||||||
|
// Anti-alias filter the samples to prevent folding and output the filtered
|
||||||
|
// data to tempBuffer. Note : because of the FIR filter length, the
|
||||||
|
// filtering routine takes in 'filter_length' more samples than it outputs.
|
||||||
|
assert(tempBuffer.isEmpty());
|
||||||
|
sizeTemp = storeBuffer.numSamples();
|
||||||
|
|
||||||
|
count = pAAFilter->evaluate(tempBuffer.ptrEnd(sizeTemp),
|
||||||
|
storeBuffer.ptrBegin(), sizeTemp, (uint)numChannels);
|
||||||
|
|
||||||
|
if (count == 0) return;
|
||||||
|
|
||||||
|
// Remove the filtered samples from 'storeBuffer'
|
||||||
|
storeBuffer.receiveSamples(count);
|
||||||
|
|
||||||
|
// Transpose the samples (+16 is to reserve some slack in the destination buffer)
|
||||||
|
sizeTemp = (uint)((float)nSamples / fRate + 16.0f);
|
||||||
|
count = transpose(outputBuffer.ptrEnd(sizeTemp), tempBuffer.ptrBegin(), count);
|
||||||
|
outputBuffer.putSamples(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Transposes sample rate by applying anti-alias filter to prevent folding.
|
||||||
|
// Returns amount of samples returned in the "dest" buffer.
|
||||||
|
// The maximum amount of samples that can be returned at a time is set by
|
||||||
|
// the 'set_returnBuffer_size' function.
|
||||||
|
void RateTransposer::processSamples(const SAMPLETYPE *src, uint nSamples)
|
||||||
|
{
|
||||||
|
uint count;
|
||||||
|
uint sizeReq;
|
||||||
|
|
||||||
|
if (nSamples == 0) return;
|
||||||
|
assert(pAAFilter);
|
||||||
|
|
||||||
|
// If anti-alias filter is turned off, simply transpose without applying
|
||||||
|
// the filter
|
||||||
|
if (bUseAAFilter == false)
|
||||||
|
{
|
||||||
|
sizeReq = (uint)((float)nSamples / fRate + 1.0f);
|
||||||
|
count = transpose(outputBuffer.ptrEnd(sizeReq), src, nSamples);
|
||||||
|
outputBuffer.putSamples(count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transpose with anti-alias filter
|
||||||
|
if (fRate < 1.0f)
|
||||||
|
{
|
||||||
|
upsample(src, nSamples);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
downsample(src, nSamples);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Transposes the sample rate of the given samples using linear interpolation.
|
||||||
|
// Returns the number of samples returned in the "dest" buffer
|
||||||
|
inline uint RateTransposer::transpose(SAMPLETYPE *dest, const SAMPLETYPE *src, uint nSamples)
|
||||||
|
{
|
||||||
|
if (numChannels == 2)
|
||||||
|
{
|
||||||
|
return transposeStereo(dest, src, nSamples);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return transposeMono(dest, src, nSamples);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Sets the number of channels, 1 = mono, 2 = stereo
|
||||||
|
void RateTransposer::setChannels(int nChannels)
|
||||||
|
{
|
||||||
|
assert(nChannels > 0);
|
||||||
|
if (numChannels == nChannels) return;
|
||||||
|
|
||||||
|
assert(nChannels == 1 || nChannels == 2);
|
||||||
|
numChannels = nChannels;
|
||||||
|
|
||||||
|
storeBuffer.setChannels(numChannels);
|
||||||
|
tempBuffer.setChannels(numChannels);
|
||||||
|
outputBuffer.setChannels(numChannels);
|
||||||
|
|
||||||
|
// Inits the linear interpolation registers
|
||||||
|
resetRegisters();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Clears all the samples in the object
|
||||||
|
void RateTransposer::clear()
|
||||||
|
{
|
||||||
|
outputBuffer.clear();
|
||||||
|
storeBuffer.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Returns nonzero if there aren't any samples available for outputting.
|
||||||
|
int RateTransposer::isEmpty() const
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
|
||||||
|
res = FIFOProcessor::isEmpty();
|
||||||
|
if (res == 0) return 0;
|
||||||
|
return storeBuffer.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// RateTransposerInteger - integer arithmetic implementation
|
||||||
|
//
|
||||||
|
|
||||||
|
/// fixed-point interpolation routine precision
|
||||||
|
#define SCALE 65536
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
RateTransposerInteger::RateTransposerInteger() : RateTransposer()
|
||||||
|
{
|
||||||
|
// Notice: use local function calling syntax for sake of clarity,
|
||||||
|
// to indicate the fact that C++ constructor can't call virtual functions.
|
||||||
|
RateTransposerInteger::resetRegisters();
|
||||||
|
RateTransposerInteger::setRate(1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RateTransposerInteger::~RateTransposerInteger()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void RateTransposerInteger::resetRegisters()
|
||||||
|
{
|
||||||
|
iSlopeCount = 0;
|
||||||
|
sPrevSampleL =
|
||||||
|
sPrevSampleR = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Transposes the sample rate of the given samples using linear interpolation.
|
||||||
|
// 'Mono' version of the routine. Returns the number of samples returned in
|
||||||
|
// the "dest" buffer
|
||||||
|
uint RateTransposerInteger::transposeMono(SAMPLETYPE *dest, const SAMPLETYPE *src, uint nSamples)
|
||||||
|
{
|
||||||
|
unsigned int i, used;
|
||||||
|
LONG_SAMPLETYPE temp, vol1;
|
||||||
|
|
||||||
|
if (nSamples == 0) return 0; // no samples, no work
|
||||||
|
|
||||||
|
used = 0;
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
// Process the last sample saved from the previous call first...
|
||||||
|
while (iSlopeCount <= SCALE)
|
||||||
|
{
|
||||||
|
vol1 = (LONG_SAMPLETYPE)(SCALE - iSlopeCount);
|
||||||
|
temp = vol1 * sPrevSampleL + iSlopeCount * src[0];
|
||||||
|
dest[i] = (SAMPLETYPE)(temp / SCALE);
|
||||||
|
i++;
|
||||||
|
iSlopeCount += iRate;
|
||||||
|
}
|
||||||
|
// now always (iSlopeCount > SCALE)
|
||||||
|
iSlopeCount -= SCALE;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
while (iSlopeCount > SCALE)
|
||||||
|
{
|
||||||
|
iSlopeCount -= SCALE;
|
||||||
|
used ++;
|
||||||
|
if (used >= nSamples - 1) goto end;
|
||||||
|
}
|
||||||
|
vol1 = (LONG_SAMPLETYPE)(SCALE - iSlopeCount);
|
||||||
|
temp = src[used] * vol1 + iSlopeCount * src[used + 1];
|
||||||
|
dest[i] = (SAMPLETYPE)(temp / SCALE);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
iSlopeCount += iRate;
|
||||||
|
}
|
||||||
|
end:
|
||||||
|
// Store the last sample for the next round
|
||||||
|
sPrevSampleL = src[nSamples - 1];
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Transposes the sample rate of the given samples using linear interpolation.
|
||||||
|
// 'Stereo' version of the routine. Returns the number of samples returned in
|
||||||
|
// the "dest" buffer
|
||||||
|
uint RateTransposerInteger::transposeStereo(SAMPLETYPE *dest, const SAMPLETYPE *src, uint nSamples)
|
||||||
|
{
|
||||||
|
unsigned int srcPos, i, used;
|
||||||
|
LONG_SAMPLETYPE temp, vol1;
|
||||||
|
|
||||||
|
if (nSamples == 0) return 0; // no samples, no work
|
||||||
|
|
||||||
|
used = 0;
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
// Process the last sample saved from the sPrevSampleLious call first...
|
||||||
|
while (iSlopeCount <= SCALE)
|
||||||
|
{
|
||||||
|
vol1 = (LONG_SAMPLETYPE)(SCALE - iSlopeCount);
|
||||||
|
temp = vol1 * sPrevSampleL + iSlopeCount * src[0];
|
||||||
|
dest[2 * i] = (SAMPLETYPE)(temp / SCALE);
|
||||||
|
temp = vol1 * sPrevSampleR + iSlopeCount * src[1];
|
||||||
|
dest[2 * i + 1] = (SAMPLETYPE)(temp / SCALE);
|
||||||
|
i++;
|
||||||
|
iSlopeCount += iRate;
|
||||||
|
}
|
||||||
|
// now always (iSlopeCount > SCALE)
|
||||||
|
iSlopeCount -= SCALE;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
while (iSlopeCount > SCALE)
|
||||||
|
{
|
||||||
|
iSlopeCount -= SCALE;
|
||||||
|
used ++;
|
||||||
|
if (used >= nSamples - 1) goto end;
|
||||||
|
}
|
||||||
|
srcPos = 2 * used;
|
||||||
|
vol1 = (LONG_SAMPLETYPE)(SCALE - iSlopeCount);
|
||||||
|
temp = src[srcPos] * vol1 + iSlopeCount * src[srcPos + 2];
|
||||||
|
dest[2 * i] = (SAMPLETYPE)(temp / SCALE);
|
||||||
|
temp = src[srcPos + 1] * vol1 + iSlopeCount * src[srcPos + 3];
|
||||||
|
dest[2 * i + 1] = (SAMPLETYPE)(temp / SCALE);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
iSlopeCount += iRate;
|
||||||
|
}
|
||||||
|
end:
|
||||||
|
// Store the last sample for the next round
|
||||||
|
sPrevSampleL = src[2 * nSamples - 2];
|
||||||
|
sPrevSampleR = src[2 * nSamples - 1];
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Sets new target iRate. Normal iRate = 1.0, smaller values represent slower
|
||||||
|
// iRate, larger faster iRates.
|
||||||
|
void RateTransposerInteger::setRate(float newRate)
|
||||||
|
{
|
||||||
|
iRate = (int)(newRate * SCALE + 0.5f);
|
||||||
|
RateTransposer::setRate(newRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// RateTransposerFloat - floating point arithmetic implementation
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
RateTransposerFloat::RateTransposerFloat() : RateTransposer()
|
||||||
|
{
|
||||||
|
// Notice: use local function calling syntax for sake of clarity,
|
||||||
|
// to indicate the fact that C++ constructor can't call virtual functions.
|
||||||
|
RateTransposerFloat::resetRegisters();
|
||||||
|
RateTransposerFloat::setRate(1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RateTransposerFloat::~RateTransposerFloat()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void RateTransposerFloat::resetRegisters()
|
||||||
|
{
|
||||||
|
fSlopeCount = 0;
|
||||||
|
sPrevSampleL =
|
||||||
|
sPrevSampleR = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Transposes the sample rate of the given samples using linear interpolation.
|
||||||
|
// 'Mono' version of the routine. Returns the number of samples returned in
|
||||||
|
// the "dest" buffer
|
||||||
|
uint RateTransposerFloat::transposeMono(SAMPLETYPE *dest, const SAMPLETYPE *src, uint nSamples)
|
||||||
|
{
|
||||||
|
unsigned int i, used;
|
||||||
|
|
||||||
|
used = 0;
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
// Process the last sample saved from the previous call first...
|
||||||
|
while (fSlopeCount <= 1.0f)
|
||||||
|
{
|
||||||
|
dest[i] = (SAMPLETYPE)((1.0f - fSlopeCount) * sPrevSampleL + fSlopeCount * src[0]);
|
||||||
|
i++;
|
||||||
|
fSlopeCount += fRate;
|
||||||
|
}
|
||||||
|
fSlopeCount -= 1.0f;
|
||||||
|
|
||||||
|
if (nSamples > 1)
|
||||||
|
{
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
while (fSlopeCount > 1.0f)
|
||||||
|
{
|
||||||
|
fSlopeCount -= 1.0f;
|
||||||
|
used ++;
|
||||||
|
if (used >= nSamples - 1) goto end;
|
||||||
|
}
|
||||||
|
dest[i] = (SAMPLETYPE)((1.0f - fSlopeCount) * src[used] + fSlopeCount * src[used + 1]);
|
||||||
|
i++;
|
||||||
|
fSlopeCount += fRate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end:
|
||||||
|
// Store the last sample for the next round
|
||||||
|
sPrevSampleL = src[nSamples - 1];
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Transposes the sample rate of the given samples using linear interpolation.
|
||||||
|
// 'Mono' version of the routine. Returns the number of samples returned in
|
||||||
|
// the "dest" buffer
|
||||||
|
uint RateTransposerFloat::transposeStereo(SAMPLETYPE *dest, const SAMPLETYPE *src, uint nSamples)
|
||||||
|
{
|
||||||
|
unsigned int srcPos, i, used;
|
||||||
|
|
||||||
|
if (nSamples == 0) return 0; // no samples, no work
|
||||||
|
|
||||||
|
used = 0;
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
// Process the last sample saved from the sPrevSampleLious call first...
|
||||||
|
while (fSlopeCount <= 1.0f)
|
||||||
|
{
|
||||||
|
dest[2 * i] = (SAMPLETYPE)((1.0f - fSlopeCount) * sPrevSampleL + fSlopeCount * src[0]);
|
||||||
|
dest[2 * i + 1] = (SAMPLETYPE)((1.0f - fSlopeCount) * sPrevSampleR + fSlopeCount * src[1]);
|
||||||
|
i++;
|
||||||
|
fSlopeCount += fRate;
|
||||||
|
}
|
||||||
|
// now always (iSlopeCount > 1.0f)
|
||||||
|
fSlopeCount -= 1.0f;
|
||||||
|
|
||||||
|
if (nSamples > 1)
|
||||||
|
{
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
while (fSlopeCount > 1.0f)
|
||||||
|
{
|
||||||
|
fSlopeCount -= 1.0f;
|
||||||
|
used ++;
|
||||||
|
if (used >= nSamples - 1) goto end;
|
||||||
|
}
|
||||||
|
srcPos = 2 * used;
|
||||||
|
|
||||||
|
dest[2 * i] = (SAMPLETYPE)((1.0f - fSlopeCount) * src[srcPos]
|
||||||
|
+ fSlopeCount * src[srcPos + 2]);
|
||||||
|
dest[2 * i + 1] = (SAMPLETYPE)((1.0f - fSlopeCount) * src[srcPos + 1]
|
||||||
|
+ fSlopeCount * src[srcPos + 3]);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
fSlopeCount += fRate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end:
|
||||||
|
// Store the last sample for the next round
|
||||||
|
sPrevSampleL = src[2 * nSamples - 2];
|
||||||
|
sPrevSampleR = src[2 * nSamples - 1];
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
159
media/libsoundtouch/src/RateTransposer.h
Normal file
159
media/libsoundtouch/src/RateTransposer.h
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// Sample rate transposer. Changes sample rate by using linear interpolation
|
||||||
|
/// together with anti-alias filtering (first order interpolation with anti-
|
||||||
|
/// alias filtering should be quite adequate for this application).
|
||||||
|
///
|
||||||
|
/// Use either of the derived classes of 'RateTransposerInteger' or
|
||||||
|
/// 'RateTransposerFloat' for corresponding integer/floating point tranposing
|
||||||
|
/// algorithm implementation.
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2009-02-21 08:00:14 -0800 (Sat, 21 Feb 2009) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: RateTransposer.h 63 2009-02-21 16:00:14Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef RateTransposer_H
|
||||||
|
#define RateTransposer_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include "AAFilter.h"
|
||||||
|
#include "FIFOSamplePipe.h"
|
||||||
|
#include "FIFOSampleBuffer.h"
|
||||||
|
|
||||||
|
#include "STTypes.h"
|
||||||
|
|
||||||
|
namespace soundtouch
|
||||||
|
{
|
||||||
|
|
||||||
|
/// A common linear samplerate transposer class.
|
||||||
|
///
|
||||||
|
/// Note: Use function "RateTransposer::newInstance()" to create a new class
|
||||||
|
/// instance instead of the "new" operator; that function automatically
|
||||||
|
/// chooses a correct implementation depending on if integer or floating
|
||||||
|
/// arithmetics are to be used.
|
||||||
|
class RateTransposer : public FIFOProcessor
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
/// Anti-alias filter object
|
||||||
|
AAFilter *pAAFilter;
|
||||||
|
|
||||||
|
float fRate;
|
||||||
|
|
||||||
|
int numChannels;
|
||||||
|
|
||||||
|
/// Buffer for collecting samples to feed the anti-alias filter between
|
||||||
|
/// two batches
|
||||||
|
FIFOSampleBuffer storeBuffer;
|
||||||
|
|
||||||
|
/// Buffer for keeping samples between transposing & anti-alias filter
|
||||||
|
FIFOSampleBuffer tempBuffer;
|
||||||
|
|
||||||
|
/// Output sample buffer
|
||||||
|
FIFOSampleBuffer outputBuffer;
|
||||||
|
|
||||||
|
bool bUseAAFilter;
|
||||||
|
|
||||||
|
virtual void resetRegisters() = 0;
|
||||||
|
|
||||||
|
virtual uint transposeStereo(SAMPLETYPE *dest,
|
||||||
|
const SAMPLETYPE *src,
|
||||||
|
uint numSamples) = 0;
|
||||||
|
virtual uint transposeMono(SAMPLETYPE *dest,
|
||||||
|
const SAMPLETYPE *src,
|
||||||
|
uint numSamples) = 0;
|
||||||
|
inline uint transpose(SAMPLETYPE *dest,
|
||||||
|
const SAMPLETYPE *src,
|
||||||
|
uint numSamples);
|
||||||
|
|
||||||
|
void downsample(const SAMPLETYPE *src,
|
||||||
|
uint numSamples);
|
||||||
|
void upsample(const SAMPLETYPE *src,
|
||||||
|
uint numSamples);
|
||||||
|
|
||||||
|
/// Transposes sample rate by applying anti-alias filter to prevent folding.
|
||||||
|
/// Returns amount of samples returned in the "dest" buffer.
|
||||||
|
/// The maximum amount of samples that can be returned at a time is set by
|
||||||
|
/// the 'set_returnBuffer_size' function.
|
||||||
|
void processSamples(const SAMPLETYPE *src,
|
||||||
|
uint numSamples);
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
RateTransposer();
|
||||||
|
virtual ~RateTransposer();
|
||||||
|
|
||||||
|
/// Operator 'new' is overloaded so that it automatically creates a suitable instance
|
||||||
|
/// depending on if we're to use integer or floating point arithmetics.
|
||||||
|
static void *operator new(size_t s);
|
||||||
|
|
||||||
|
/// Use this function instead of "new" operator to create a new instance of this class.
|
||||||
|
/// This function automatically chooses a correct implementation, depending on if
|
||||||
|
/// integer ot floating point arithmetics are to be used.
|
||||||
|
static RateTransposer *newInstance();
|
||||||
|
|
||||||
|
/// Returns the output buffer object
|
||||||
|
FIFOSamplePipe *getOutput() { return &outputBuffer; };
|
||||||
|
|
||||||
|
/// Returns the store buffer object
|
||||||
|
FIFOSamplePipe *getStore() { return &storeBuffer; };
|
||||||
|
|
||||||
|
/// Return anti-alias filter object
|
||||||
|
AAFilter *getAAFilter();
|
||||||
|
|
||||||
|
/// Enables/disables the anti-alias filter. Zero to disable, nonzero to enable
|
||||||
|
void enableAAFilter(bool newMode);
|
||||||
|
|
||||||
|
/// Returns nonzero if anti-alias filter is enabled.
|
||||||
|
bool isAAFilterEnabled() const;
|
||||||
|
|
||||||
|
/// Sets new target rate. Normal rate = 1.0, smaller values represent slower
|
||||||
|
/// rate, larger faster rates.
|
||||||
|
virtual void setRate(float newRate);
|
||||||
|
|
||||||
|
/// Sets the number of channels, 1 = mono, 2 = stereo
|
||||||
|
void setChannels(int channels);
|
||||||
|
|
||||||
|
/// Adds 'numSamples' pcs of samples from the 'samples' memory position into
|
||||||
|
/// the input of the object.
|
||||||
|
void putSamples(const SAMPLETYPE *samples, uint numSamples);
|
||||||
|
|
||||||
|
/// Clears all the samples in the object
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
/// Returns nonzero if there aren't any samples available for outputting.
|
||||||
|
int isEmpty() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
159
media/libsoundtouch/src/STTypes.h
Normal file
159
media/libsoundtouch/src/STTypes.h
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// Common type definitions for SoundTouch audio processing library.
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2012-04-01 10:01:42 -0700 (Sun, 01 Apr 2012) $
|
||||||
|
// File revision : $Revision: 3 $
|
||||||
|
//
|
||||||
|
// $Id: STTypes.h 136 2012-04-01 17:01:42Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef STTypes_H
|
||||||
|
#define STTypes_H
|
||||||
|
|
||||||
|
typedef unsigned int uint;
|
||||||
|
typedef unsigned long ulong;
|
||||||
|
|
||||||
|
#include "soundtouch_config.h"
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define EXPORT __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace soundtouch
|
||||||
|
{
|
||||||
|
/// Activate these undef's to overrule the possible sampletype
|
||||||
|
/// setting inherited from some other header file:
|
||||||
|
//#undef SOUNDTOUCH_INTEGER_SAMPLES
|
||||||
|
//#undef SOUNDTOUCH_FLOAT_SAMPLES
|
||||||
|
|
||||||
|
#if !(SOUNDTOUCH_INTEGER_SAMPLES || SOUNDTOUCH_FLOAT_SAMPLES)
|
||||||
|
|
||||||
|
/// Choose either 32bit floating point or 16bit integer sampletype
|
||||||
|
/// by choosing one of the following defines, unless this selection
|
||||||
|
/// has already been done in some other file.
|
||||||
|
////
|
||||||
|
/// Notes:
|
||||||
|
/// - In Windows environment, choose the sample format with the
|
||||||
|
/// following defines.
|
||||||
|
/// - In GNU environment, the floating point samples are used by
|
||||||
|
/// default, but integer samples can be chosen by giving the
|
||||||
|
/// following switch to the configure script:
|
||||||
|
/// ./configure --enable-integer-samples
|
||||||
|
/// However, if you still prefer to select the sample format here
|
||||||
|
/// also in GNU environment, then please #undef the INTEGER_SAMPLE
|
||||||
|
/// and FLOAT_SAMPLE defines first as in comments above.
|
||||||
|
//#define SOUNDTOUCH_INTEGER_SAMPLES 1 //< 16bit integer samples
|
||||||
|
#define SOUNDTOUCH_FLOAT_SAMPLES 1 //< 32bit float samples
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (_M_IX86 || __i386__ || __x86_64__ || _M_X64)
|
||||||
|
/// Define this to allow X86-specific assembler/intrinsic optimizations.
|
||||||
|
/// Notice that library contains also usual C++ versions of each of these
|
||||||
|
/// these routines, so if you're having difficulties getting the optimized
|
||||||
|
/// routines compiled for whatever reason, you may disable these optimizations
|
||||||
|
/// to make the library compile.
|
||||||
|
|
||||||
|
#define SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS 1
|
||||||
|
|
||||||
|
/// In GNU environment, allow the user to override this setting by
|
||||||
|
/// giving the following switch to the configure script:
|
||||||
|
/// ./configure --disable-x86-optimizations
|
||||||
|
/// ./configure --enable-x86-optimizations=no
|
||||||
|
#ifdef SOUNDTOUCH_DISABLE_X86_OPTIMIZATIONS
|
||||||
|
#undef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
/// Always disable optimizations when not using a x86 systems.
|
||||||
|
#undef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// If defined, allows the SIMD-optimized routines to take minor shortcuts
|
||||||
|
// for improved performance. Undefine to require faithfully similar SIMD
|
||||||
|
// calculations as in normal C implementation.
|
||||||
|
#define SOUNDTOUCH_ALLOW_NONEXACT_SIMD_OPTIMIZATION 1
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
|
||||||
|
// 16bit integer sample type
|
||||||
|
typedef short SAMPLETYPE;
|
||||||
|
// data type for sample accumulation: Use 32bit integer to prevent overflows
|
||||||
|
typedef long LONG_SAMPLETYPE;
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_FLOAT_SAMPLES
|
||||||
|
// check that only one sample type is defined
|
||||||
|
#error "conflicting sample types defined"
|
||||||
|
#endif // SOUNDTOUCH_FLOAT_SAMPLES
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
|
||||||
|
// Allow MMX optimizations
|
||||||
|
#define SOUNDTOUCH_ALLOW_MMX 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
// floating point samples
|
||||||
|
typedef float SAMPLETYPE;
|
||||||
|
// data type for sample accumulation: Use double to utilize full precision.
|
||||||
|
typedef double LONG_SAMPLETYPE;
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
|
||||||
|
// Allow SSE optimizations
|
||||||
|
#define SOUNDTOUCH_ALLOW_SSE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // SOUNDTOUCH_INTEGER_SAMPLES
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// define ST_NO_EXCEPTION_HANDLING switch to disable throwing std exceptions:
|
||||||
|
#define ST_NO_EXCEPTION_HANDLING 1
|
||||||
|
#ifdef ST_NO_EXCEPTION_HANDLING
|
||||||
|
// Exceptions disabled. Throw asserts instead if enabled.
|
||||||
|
#include <assert.h>
|
||||||
|
#define ST_THROW_RT_ERROR(x) {assert((const char *)x);}
|
||||||
|
#else
|
||||||
|
// use c++ standard exceptions
|
||||||
|
#include <stdexcept>
|
||||||
|
#define ST_THROW_RT_ERROR(x) {throw std::runtime_error(x);}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// When this #define is active, eliminates a clicking sound when the "rate" or "pitch"
|
||||||
|
// parameter setting crosses from value <1 to >=1 or vice versa during processing.
|
||||||
|
// Default is off as such crossover is untypical case and involves a slight sound
|
||||||
|
// quality compromise.
|
||||||
|
//#define SOUNDTOUCH_PREVENT_CLICK_AT_RATE_CROSSOVER 1
|
||||||
|
|
||||||
|
#endif
|
501
media/libsoundtouch/src/SoundTouch.cpp
Normal file
501
media/libsoundtouch/src/SoundTouch.cpp
Normal file
@ -0,0 +1,501 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// SoundTouch - main class for tempo/pitch/rate adjusting routines.
|
||||||
|
///
|
||||||
|
/// Notes:
|
||||||
|
/// - Initialize the SoundTouch object instance by setting up the sound stream
|
||||||
|
/// parameters with functions 'setSampleRate' and 'setChannels', then set
|
||||||
|
/// desired tempo/pitch/rate settings with the corresponding functions.
|
||||||
|
///
|
||||||
|
/// - The SoundTouch class behaves like a first-in-first-out pipeline: The
|
||||||
|
/// samples that are to be processed are fed into one of the pipe by calling
|
||||||
|
/// function 'putSamples', while the ready processed samples can be read
|
||||||
|
/// from the other end of the pipeline with function 'receiveSamples'.
|
||||||
|
///
|
||||||
|
/// - The SoundTouch processing classes require certain sized 'batches' of
|
||||||
|
/// samples in order to process the sound. For this reason the classes buffer
|
||||||
|
/// incoming samples until there are enough of samples available for
|
||||||
|
/// processing, then they carry out the processing step and consequently
|
||||||
|
/// make the processed samples available for outputting.
|
||||||
|
///
|
||||||
|
/// - For the above reason, the processing routines introduce a certain
|
||||||
|
/// 'latency' between the input and output, so that the samples input to
|
||||||
|
/// SoundTouch may not be immediately available in the output, and neither
|
||||||
|
/// the amount of outputtable samples may not immediately be in direct
|
||||||
|
/// relationship with the amount of previously input samples.
|
||||||
|
///
|
||||||
|
/// - The tempo/pitch/rate control parameters can be altered during processing.
|
||||||
|
/// Please notice though that they aren't currently protected by semaphores,
|
||||||
|
/// so in multi-thread application external semaphore protection may be
|
||||||
|
/// required.
|
||||||
|
///
|
||||||
|
/// - This class utilizes classes 'TDStretch' for tempo change (without modifying
|
||||||
|
/// pitch) and 'RateTransposer' for changing the playback rate (that is, both
|
||||||
|
/// tempo and pitch in the same ratio) of the sound. The third available control
|
||||||
|
/// 'pitch' (change pitch but maintain tempo) is produced by a combination of
|
||||||
|
/// combining the two other controls.
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2012-06-13 12:29:53 -0700 (Wed, 13 Jun 2012) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: SoundTouch.cpp 143 2012-06-13 19:29:53Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "SoundTouch.h"
|
||||||
|
#include "TDStretch.h"
|
||||||
|
#include "RateTransposer.h"
|
||||||
|
#include "cpu_detect.h"
|
||||||
|
|
||||||
|
using namespace soundtouch;
|
||||||
|
|
||||||
|
/// test if two floating point numbers are equal
|
||||||
|
#define TEST_FLOAT_EQUAL(a, b) (fabs(a - b) < 1e-10)
|
||||||
|
|
||||||
|
|
||||||
|
/// Print library version string for autoconf
|
||||||
|
extern "C" void soundtouch_ac_test()
|
||||||
|
{
|
||||||
|
printf("SoundTouch Version: %s\n",SOUNDTOUCH_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SoundTouch::SoundTouch()
|
||||||
|
{
|
||||||
|
// Initialize rate transposer and tempo changer instances
|
||||||
|
|
||||||
|
pRateTransposer = RateTransposer::newInstance();
|
||||||
|
pTDStretch = TDStretch::newInstance();
|
||||||
|
|
||||||
|
setOutPipe(pTDStretch);
|
||||||
|
|
||||||
|
rate = tempo = 0;
|
||||||
|
|
||||||
|
virtualPitch =
|
||||||
|
virtualRate =
|
||||||
|
virtualTempo = 1.0;
|
||||||
|
|
||||||
|
calcEffectiveRateAndTempo();
|
||||||
|
|
||||||
|
channels = 0;
|
||||||
|
bSrateSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SoundTouch::~SoundTouch()
|
||||||
|
{
|
||||||
|
delete pRateTransposer;
|
||||||
|
delete pTDStretch;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// Get SoundTouch library version string
|
||||||
|
const char *SoundTouch::getVersionString()
|
||||||
|
{
|
||||||
|
static const char *_version = SOUNDTOUCH_VERSION;
|
||||||
|
|
||||||
|
return _version;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Get SoundTouch library version Id
|
||||||
|
uint SoundTouch::getVersionId()
|
||||||
|
{
|
||||||
|
return SOUNDTOUCH_VERSION_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Sets the number of channels, 1 = mono, 2 = stereo
|
||||||
|
void SoundTouch::setChannels(uint numChannels)
|
||||||
|
{
|
||||||
|
if (numChannels != 1 && numChannels != 2)
|
||||||
|
{
|
||||||
|
ST_THROW_RT_ERROR("Illegal number of channels");
|
||||||
|
}
|
||||||
|
channels = numChannels;
|
||||||
|
pRateTransposer->setChannels((int)numChannels);
|
||||||
|
pTDStretch->setChannels((int)numChannels);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sets new rate control value. Normal rate = 1.0, smaller values
|
||||||
|
// represent slower rate, larger faster rates.
|
||||||
|
void SoundTouch::setRate(float newRate)
|
||||||
|
{
|
||||||
|
virtualRate = newRate;
|
||||||
|
calcEffectiveRateAndTempo();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sets new rate control value as a difference in percents compared
|
||||||
|
// to the original rate (-50 .. +100 %)
|
||||||
|
void SoundTouch::setRateChange(float newRate)
|
||||||
|
{
|
||||||
|
virtualRate = 1.0f + 0.01f * newRate;
|
||||||
|
calcEffectiveRateAndTempo();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sets new tempo control value. Normal tempo = 1.0, smaller values
|
||||||
|
// represent slower tempo, larger faster tempo.
|
||||||
|
void SoundTouch::setTempo(float newTempo)
|
||||||
|
{
|
||||||
|
virtualTempo = newTempo;
|
||||||
|
calcEffectiveRateAndTempo();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sets new tempo control value as a difference in percents compared
|
||||||
|
// to the original tempo (-50 .. +100 %)
|
||||||
|
void SoundTouch::setTempoChange(float newTempo)
|
||||||
|
{
|
||||||
|
virtualTempo = 1.0f + 0.01f * newTempo;
|
||||||
|
calcEffectiveRateAndTempo();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sets new pitch control value. Original pitch = 1.0, smaller values
|
||||||
|
// represent lower pitches, larger values higher pitch.
|
||||||
|
void SoundTouch::setPitch(float newPitch)
|
||||||
|
{
|
||||||
|
virtualPitch = newPitch;
|
||||||
|
calcEffectiveRateAndTempo();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sets pitch change in octaves compared to the original pitch
|
||||||
|
// (-1.00 .. +1.00)
|
||||||
|
void SoundTouch::setPitchOctaves(float newPitch)
|
||||||
|
{
|
||||||
|
virtualPitch = (float)exp(0.69314718056f * newPitch);
|
||||||
|
calcEffectiveRateAndTempo();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sets pitch change in semi-tones compared to the original pitch
|
||||||
|
// (-12 .. +12)
|
||||||
|
void SoundTouch::setPitchSemiTones(int newPitch)
|
||||||
|
{
|
||||||
|
setPitchOctaves((float)newPitch / 12.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SoundTouch::setPitchSemiTones(float newPitch)
|
||||||
|
{
|
||||||
|
setPitchOctaves(newPitch / 12.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Calculates 'effective' rate and tempo values from the
|
||||||
|
// nominal control values.
|
||||||
|
void SoundTouch::calcEffectiveRateAndTempo()
|
||||||
|
{
|
||||||
|
float oldTempo = tempo;
|
||||||
|
float oldRate = rate;
|
||||||
|
|
||||||
|
tempo = virtualTempo / virtualPitch;
|
||||||
|
rate = virtualPitch * virtualRate;
|
||||||
|
|
||||||
|
if (!TEST_FLOAT_EQUAL(rate,oldRate)) pRateTransposer->setRate(rate);
|
||||||
|
if (!TEST_FLOAT_EQUAL(tempo, oldTempo)) pTDStretch->setTempo(tempo);
|
||||||
|
|
||||||
|
#ifndef SOUNDTOUCH_PREVENT_CLICK_AT_RATE_CROSSOVER
|
||||||
|
if (rate <= 1.0f)
|
||||||
|
{
|
||||||
|
if (output != pTDStretch)
|
||||||
|
{
|
||||||
|
FIFOSamplePipe *tempoOut;
|
||||||
|
|
||||||
|
assert(output == pRateTransposer);
|
||||||
|
// move samples in the current output buffer to the output of pTDStretch
|
||||||
|
tempoOut = pTDStretch->getOutput();
|
||||||
|
tempoOut->moveSamples(*output);
|
||||||
|
// move samples in pitch transposer's store buffer to tempo changer's input
|
||||||
|
pTDStretch->moveSamples(*pRateTransposer->getStore());
|
||||||
|
|
||||||
|
output = pTDStretch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
if (output != pRateTransposer)
|
||||||
|
{
|
||||||
|
FIFOSamplePipe *transOut;
|
||||||
|
|
||||||
|
assert(output == pTDStretch);
|
||||||
|
// move samples in the current output buffer to the output of pRateTransposer
|
||||||
|
transOut = pRateTransposer->getOutput();
|
||||||
|
transOut->moveSamples(*output);
|
||||||
|
// move samples in tempo changer's input to pitch transposer's input
|
||||||
|
pRateTransposer->moveSamples(*pTDStretch->getInput());
|
||||||
|
|
||||||
|
output = pRateTransposer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Sets sample rate.
|
||||||
|
void SoundTouch::setSampleRate(uint srate)
|
||||||
|
{
|
||||||
|
bSrateSet = true;
|
||||||
|
// set sample rate, leave other tempo changer parameters as they are.
|
||||||
|
pTDStretch->setParameters((int)srate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Adds 'numSamples' pcs of samples from the 'samples' memory position into
|
||||||
|
// the input of the object.
|
||||||
|
void SoundTouch::putSamples(const SAMPLETYPE *samples, uint nSamples)
|
||||||
|
{
|
||||||
|
if (bSrateSet == false)
|
||||||
|
{
|
||||||
|
ST_THROW_RT_ERROR("SoundTouch : Sample rate not defined");
|
||||||
|
}
|
||||||
|
else if (channels == 0)
|
||||||
|
{
|
||||||
|
ST_THROW_RT_ERROR("SoundTouch : Number of channels not defined");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transpose the rate of the new samples if necessary
|
||||||
|
/* Bypass the nominal setting - can introduce a click in sound when tempo/pitch control crosses the nominal value...
|
||||||
|
if (rate == 1.0f)
|
||||||
|
{
|
||||||
|
// The rate value is same as the original, simply evaluate the tempo changer.
|
||||||
|
assert(output == pTDStretch);
|
||||||
|
if (pRateTransposer->isEmpty() == 0)
|
||||||
|
{
|
||||||
|
// yet flush the last samples in the pitch transposer buffer
|
||||||
|
// (may happen if 'rate' changes from a non-zero value to zero)
|
||||||
|
pTDStretch->moveSamples(*pRateTransposer);
|
||||||
|
}
|
||||||
|
pTDStretch->putSamples(samples, nSamples);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
#ifndef SOUNDTOUCH_PREVENT_CLICK_AT_RATE_CROSSOVER
|
||||||
|
else if (rate <= 1.0f)
|
||||||
|
{
|
||||||
|
// transpose the rate down, output the transposed sound to tempo changer buffer
|
||||||
|
assert(output == pTDStretch);
|
||||||
|
pRateTransposer->putSamples(samples, nSamples);
|
||||||
|
pTDStretch->moveSamples(*pRateTransposer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
// evaluate the tempo changer, then transpose the rate up,
|
||||||
|
assert(output == pRateTransposer);
|
||||||
|
pTDStretch->putSamples(samples, nSamples);
|
||||||
|
pRateTransposer->moveSamples(*pTDStretch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Flushes the last samples from the processing pipeline to the output.
|
||||||
|
// Clears also the internal processing buffers.
|
||||||
|
//
|
||||||
|
// Note: This function is meant for extracting the last samples of a sound
|
||||||
|
// stream. This function may introduce additional blank samples in the end
|
||||||
|
// of the sound stream, and thus it's not recommended to call this function
|
||||||
|
// in the middle of a sound stream.
|
||||||
|
void SoundTouch::flush()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int nUnprocessed;
|
||||||
|
int nOut;
|
||||||
|
SAMPLETYPE buff[64*2]; // note: allocate 2*64 to cater 64 sample frames of stereo sound
|
||||||
|
|
||||||
|
// check how many samples still await processing, and scale
|
||||||
|
// that by tempo & rate to get expected output sample count
|
||||||
|
nUnprocessed = numUnprocessedSamples();
|
||||||
|
nUnprocessed = (int)((double)nUnprocessed / (tempo * rate) + 0.5);
|
||||||
|
|
||||||
|
nOut = numSamples(); // ready samples currently in buffer ...
|
||||||
|
nOut += nUnprocessed; // ... and how many we expect there to be in the end
|
||||||
|
|
||||||
|
memset(buff, 0, 64 * channels * sizeof(SAMPLETYPE));
|
||||||
|
// "Push" the last active samples out from the processing pipeline by
|
||||||
|
// feeding blank samples into the processing pipeline until new,
|
||||||
|
// processed samples appear in the output (not however, more than
|
||||||
|
// 8ksamples in any case)
|
||||||
|
for (i = 0; i < 128; i ++)
|
||||||
|
{
|
||||||
|
putSamples(buff, 64);
|
||||||
|
if ((int)numSamples() >= nOut)
|
||||||
|
{
|
||||||
|
// Enough new samples have appeared into the output!
|
||||||
|
// As samples come from processing with bigger chunks, now truncate it
|
||||||
|
// back to maximum "nOut" samples to improve duration accuracy
|
||||||
|
adjustAmountOfSamples(nOut);
|
||||||
|
|
||||||
|
// finish
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear working buffers
|
||||||
|
pRateTransposer->clear();
|
||||||
|
pTDStretch->clearInput();
|
||||||
|
// yet leave the 'tempoChanger' output intouched as that's where the
|
||||||
|
// flushed samples are!
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Changes a setting controlling the processing system behaviour. See the
|
||||||
|
// 'SETTING_...' defines for available setting ID's.
|
||||||
|
bool SoundTouch::setSetting(int settingId, int value)
|
||||||
|
{
|
||||||
|
int sampleRate, sequenceMs, seekWindowMs, overlapMs;
|
||||||
|
|
||||||
|
// read current tdstretch routine parameters
|
||||||
|
pTDStretch->getParameters(&sampleRate, &sequenceMs, &seekWindowMs, &overlapMs);
|
||||||
|
|
||||||
|
switch (settingId)
|
||||||
|
{
|
||||||
|
case SETTING_USE_AA_FILTER :
|
||||||
|
// enables / disabless anti-alias filter
|
||||||
|
pRateTransposer->enableAAFilter((value != 0) ? true : false);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case SETTING_AA_FILTER_LENGTH :
|
||||||
|
// sets anti-alias filter length
|
||||||
|
pRateTransposer->getAAFilter()->setLength(value);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case SETTING_USE_QUICKSEEK :
|
||||||
|
// enables / disables tempo routine quick seeking algorithm
|
||||||
|
pTDStretch->enableQuickSeek((value != 0) ? true : false);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case SETTING_SEQUENCE_MS:
|
||||||
|
// change time-stretch sequence duration parameter
|
||||||
|
pTDStretch->setParameters(sampleRate, value, seekWindowMs, overlapMs);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case SETTING_SEEKWINDOW_MS:
|
||||||
|
// change time-stretch seek window length parameter
|
||||||
|
pTDStretch->setParameters(sampleRate, sequenceMs, value, overlapMs);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case SETTING_OVERLAP_MS:
|
||||||
|
// change time-stretch overlap length parameter
|
||||||
|
pTDStretch->setParameters(sampleRate, sequenceMs, seekWindowMs, value);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default :
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Reads a setting controlling the processing system behaviour. See the
|
||||||
|
// 'SETTING_...' defines for available setting ID's.
|
||||||
|
//
|
||||||
|
// Returns the setting value.
|
||||||
|
int SoundTouch::getSetting(int settingId) const
|
||||||
|
{
|
||||||
|
int temp;
|
||||||
|
|
||||||
|
switch (settingId)
|
||||||
|
{
|
||||||
|
case SETTING_USE_AA_FILTER :
|
||||||
|
return (uint)pRateTransposer->isAAFilterEnabled();
|
||||||
|
|
||||||
|
case SETTING_AA_FILTER_LENGTH :
|
||||||
|
return pRateTransposer->getAAFilter()->getLength();
|
||||||
|
|
||||||
|
case SETTING_USE_QUICKSEEK :
|
||||||
|
return (uint) pTDStretch->isQuickSeekEnabled();
|
||||||
|
|
||||||
|
case SETTING_SEQUENCE_MS:
|
||||||
|
pTDStretch->getParameters(NULL, &temp, NULL, NULL);
|
||||||
|
return temp;
|
||||||
|
|
||||||
|
case SETTING_SEEKWINDOW_MS:
|
||||||
|
pTDStretch->getParameters(NULL, NULL, &temp, NULL);
|
||||||
|
return temp;
|
||||||
|
|
||||||
|
case SETTING_OVERLAP_MS:
|
||||||
|
pTDStretch->getParameters(NULL, NULL, NULL, &temp);
|
||||||
|
return temp;
|
||||||
|
|
||||||
|
case SETTING_NOMINAL_INPUT_SEQUENCE :
|
||||||
|
return pTDStretch->getInputSampleReq();
|
||||||
|
|
||||||
|
case SETTING_NOMINAL_OUTPUT_SEQUENCE :
|
||||||
|
return pTDStretch->getOutputBatchSize();
|
||||||
|
|
||||||
|
default :
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Clears all the samples in the object's output and internal processing
|
||||||
|
// buffers.
|
||||||
|
void SoundTouch::clear()
|
||||||
|
{
|
||||||
|
pRateTransposer->clear();
|
||||||
|
pTDStretch->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// Returns number of samples currently unprocessed.
|
||||||
|
uint SoundTouch::numUnprocessedSamples() const
|
||||||
|
{
|
||||||
|
FIFOSamplePipe * psp;
|
||||||
|
if (pTDStretch)
|
||||||
|
{
|
||||||
|
psp = pTDStretch->getInput();
|
||||||
|
if (psp)
|
||||||
|
{
|
||||||
|
return psp->numSamples();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
277
media/libsoundtouch/src/SoundTouch.h
Normal file
277
media/libsoundtouch/src/SoundTouch.h
Normal file
@ -0,0 +1,277 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// SoundTouch - main class for tempo/pitch/rate adjusting routines.
|
||||||
|
///
|
||||||
|
/// Notes:
|
||||||
|
/// - Initialize the SoundTouch object instance by setting up the sound stream
|
||||||
|
/// parameters with functions 'setSampleRate' and 'setChannels', then set
|
||||||
|
/// desired tempo/pitch/rate settings with the corresponding functions.
|
||||||
|
///
|
||||||
|
/// - The SoundTouch class behaves like a first-in-first-out pipeline: The
|
||||||
|
/// samples that are to be processed are fed into one of the pipe by calling
|
||||||
|
/// function 'putSamples', while the ready processed samples can be read
|
||||||
|
/// from the other end of the pipeline with function 'receiveSamples'.
|
||||||
|
///
|
||||||
|
/// - The SoundTouch processing classes require certain sized 'batches' of
|
||||||
|
/// samples in order to process the sound. For this reason the classes buffer
|
||||||
|
/// incoming samples until there are enough of samples available for
|
||||||
|
/// processing, then they carry out the processing step and consequently
|
||||||
|
/// make the processed samples available for outputting.
|
||||||
|
///
|
||||||
|
/// - For the above reason, the processing routines introduce a certain
|
||||||
|
/// 'latency' between the input and output, so that the samples input to
|
||||||
|
/// SoundTouch may not be immediately available in the output, and neither
|
||||||
|
/// the amount of outputtable samples may not immediately be in direct
|
||||||
|
/// relationship with the amount of previously input samples.
|
||||||
|
///
|
||||||
|
/// - The tempo/pitch/rate control parameters can be altered during processing.
|
||||||
|
/// Please notice though that they aren't currently protected by semaphores,
|
||||||
|
/// so in multi-thread application external semaphore protection may be
|
||||||
|
/// required.
|
||||||
|
///
|
||||||
|
/// - This class utilizes classes 'TDStretch' for tempo change (without modifying
|
||||||
|
/// pitch) and 'RateTransposer' for changing the playback rate (that is, both
|
||||||
|
/// tempo and pitch in the same ratio) of the sound. The third available control
|
||||||
|
/// 'pitch' (change pitch but maintain tempo) is produced by a combination of
|
||||||
|
/// combining the two other controls.
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2012-04-04 12:47:28 -0700 (Wed, 04 Apr 2012) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: SoundTouch.h 141 2012-04-04 19:47:28Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef SoundTouch_H
|
||||||
|
#define SoundTouch_H
|
||||||
|
|
||||||
|
#include "FIFOSamplePipe.h"
|
||||||
|
#include "STTypes.h"
|
||||||
|
|
||||||
|
namespace soundtouch
|
||||||
|
{
|
||||||
|
|
||||||
|
/// Soundtouch library version string
|
||||||
|
#define SOUNDTOUCH_VERSION "1.7.0"
|
||||||
|
|
||||||
|
/// SoundTouch library version id
|
||||||
|
#define SOUNDTOUCH_VERSION_ID (10700)
|
||||||
|
|
||||||
|
//
|
||||||
|
// Available setting IDs for the 'setSetting' & 'get_setting' functions:
|
||||||
|
|
||||||
|
/// Enable/disable anti-alias filter in pitch transposer (0 = disable)
|
||||||
|
#define SETTING_USE_AA_FILTER 0
|
||||||
|
|
||||||
|
/// Pitch transposer anti-alias filter length (8 .. 128 taps, default = 32)
|
||||||
|
#define SETTING_AA_FILTER_LENGTH 1
|
||||||
|
|
||||||
|
/// Enable/disable quick seeking algorithm in tempo changer routine
|
||||||
|
/// (enabling quick seeking lowers CPU utilization but causes a minor sound
|
||||||
|
/// quality compromising)
|
||||||
|
#define SETTING_USE_QUICKSEEK 2
|
||||||
|
|
||||||
|
/// Time-stretch algorithm single processing sequence length in milliseconds. This determines
|
||||||
|
/// to how long sequences the original sound is chopped in the time-stretch algorithm.
|
||||||
|
/// See "STTypes.h" or README for more information.
|
||||||
|
#define SETTING_SEQUENCE_MS 3
|
||||||
|
|
||||||
|
/// Time-stretch algorithm seeking window length in milliseconds for algorithm that finds the
|
||||||
|
/// best possible overlapping location. This determines from how wide window the algorithm
|
||||||
|
/// may look for an optimal joining location when mixing the sound sequences back together.
|
||||||
|
/// See "STTypes.h" or README for more information.
|
||||||
|
#define SETTING_SEEKWINDOW_MS 4
|
||||||
|
|
||||||
|
/// Time-stretch algorithm overlap length in milliseconds. When the chopped sound sequences
|
||||||
|
/// are mixed back together, to form a continuous sound stream, this parameter defines over
|
||||||
|
/// how long period the two consecutive sequences are let to overlap each other.
|
||||||
|
/// See "STTypes.h" or README for more information.
|
||||||
|
#define SETTING_OVERLAP_MS 5
|
||||||
|
|
||||||
|
|
||||||
|
/// Call "getSetting" with this ID to query nominal average processing sequence
|
||||||
|
/// size in samples. This value tells approcimate value how many input samples
|
||||||
|
/// SoundTouch needs to gather before it does DSP processing run for the sample batch.
|
||||||
|
///
|
||||||
|
/// Notices:
|
||||||
|
/// - This is read-only parameter, i.e. setSetting ignores this parameter
|
||||||
|
/// - Returned value is approximate average value, exact processing batch
|
||||||
|
/// size may wary from time to time
|
||||||
|
/// - This parameter value is not constant but may change depending on
|
||||||
|
/// tempo/pitch/rate/samplerate settings.
|
||||||
|
#define SETTING_NOMINAL_INPUT_SEQUENCE 6
|
||||||
|
|
||||||
|
|
||||||
|
/// Call "getSetting" with this ID to query nominal average processing output
|
||||||
|
/// size in samples. This value tells approcimate value how many output samples
|
||||||
|
/// SoundTouch outputs once it does DSP processing run for a batch of input samples.
|
||||||
|
///
|
||||||
|
/// Notices:
|
||||||
|
/// - This is read-only parameter, i.e. setSetting ignores this parameter
|
||||||
|
/// - Returned value is approximate average value, exact processing batch
|
||||||
|
/// size may wary from time to time
|
||||||
|
/// - This parameter value is not constant but may change depending on
|
||||||
|
/// tempo/pitch/rate/samplerate settings.
|
||||||
|
#define SETTING_NOMINAL_OUTPUT_SEQUENCE 7
|
||||||
|
|
||||||
|
class EXPORT SoundTouch : public FIFOProcessor
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
/// Rate transposer class instance
|
||||||
|
class RateTransposer *pRateTransposer;
|
||||||
|
|
||||||
|
/// Time-stretch class instance
|
||||||
|
class TDStretch *pTDStretch;
|
||||||
|
|
||||||
|
/// Virtual pitch parameter. Effective rate & tempo are calculated from these parameters.
|
||||||
|
float virtualRate;
|
||||||
|
|
||||||
|
/// Virtual pitch parameter. Effective rate & tempo are calculated from these parameters.
|
||||||
|
float virtualTempo;
|
||||||
|
|
||||||
|
/// Virtual pitch parameter. Effective rate & tempo are calculated from these parameters.
|
||||||
|
float virtualPitch;
|
||||||
|
|
||||||
|
/// Flag: Has sample rate been set?
|
||||||
|
bool bSrateSet;
|
||||||
|
|
||||||
|
/// Calculates effective rate & tempo valuescfrom 'virtualRate', 'virtualTempo' and
|
||||||
|
/// 'virtualPitch' parameters.
|
||||||
|
void calcEffectiveRateAndTempo();
|
||||||
|
|
||||||
|
protected :
|
||||||
|
/// Number of channels
|
||||||
|
uint channels;
|
||||||
|
|
||||||
|
/// Effective 'rate' value calculated from 'virtualRate', 'virtualTempo' and 'virtualPitch'
|
||||||
|
float rate;
|
||||||
|
|
||||||
|
/// Effective 'tempo' value calculated from 'virtualRate', 'virtualTempo' and 'virtualPitch'
|
||||||
|
float tempo;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SoundTouch();
|
||||||
|
virtual ~SoundTouch();
|
||||||
|
|
||||||
|
/// Get SoundTouch library version string
|
||||||
|
static const char *getVersionString();
|
||||||
|
|
||||||
|
/// Get SoundTouch library version Id
|
||||||
|
static uint getVersionId();
|
||||||
|
|
||||||
|
/// Sets new rate control value. Normal rate = 1.0, smaller values
|
||||||
|
/// represent slower rate, larger faster rates.
|
||||||
|
void setRate(float newRate);
|
||||||
|
|
||||||
|
/// Sets new tempo control value. Normal tempo = 1.0, smaller values
|
||||||
|
/// represent slower tempo, larger faster tempo.
|
||||||
|
void setTempo(float newTempo);
|
||||||
|
|
||||||
|
/// Sets new rate control value as a difference in percents compared
|
||||||
|
/// to the original rate (-50 .. +100 %)
|
||||||
|
void setRateChange(float newRate);
|
||||||
|
|
||||||
|
/// Sets new tempo control value as a difference in percents compared
|
||||||
|
/// to the original tempo (-50 .. +100 %)
|
||||||
|
void setTempoChange(float newTempo);
|
||||||
|
|
||||||
|
/// Sets new pitch control value. Original pitch = 1.0, smaller values
|
||||||
|
/// represent lower pitches, larger values higher pitch.
|
||||||
|
void setPitch(float newPitch);
|
||||||
|
|
||||||
|
/// Sets pitch change in octaves compared to the original pitch
|
||||||
|
/// (-1.00 .. +1.00)
|
||||||
|
void setPitchOctaves(float newPitch);
|
||||||
|
|
||||||
|
/// Sets pitch change in semi-tones compared to the original pitch
|
||||||
|
/// (-12 .. +12)
|
||||||
|
void setPitchSemiTones(int newPitch);
|
||||||
|
void setPitchSemiTones(float newPitch);
|
||||||
|
|
||||||
|
/// Sets the number of channels, 1 = mono, 2 = stereo
|
||||||
|
void setChannels(uint numChannels);
|
||||||
|
|
||||||
|
/// Sets sample rate.
|
||||||
|
void setSampleRate(uint srate);
|
||||||
|
|
||||||
|
/// Flushes the last samples from the processing pipeline to the output.
|
||||||
|
/// Clears also the internal processing buffers.
|
||||||
|
//
|
||||||
|
/// Note: This function is meant for extracting the last samples of a sound
|
||||||
|
/// stream. This function may introduce additional blank samples in the end
|
||||||
|
/// of the sound stream, and thus it's not recommended to call this function
|
||||||
|
/// in the middle of a sound stream.
|
||||||
|
void flush();
|
||||||
|
|
||||||
|
/// Adds 'numSamples' pcs of samples from the 'samples' memory position into
|
||||||
|
/// the input of the object. Notice that sample rate _has_to_ be set before
|
||||||
|
/// calling this function, otherwise throws a runtime_error exception.
|
||||||
|
virtual void putSamples(
|
||||||
|
const SAMPLETYPE *samples, ///< Pointer to sample buffer.
|
||||||
|
uint numSamples ///< Number of samples in buffer. Notice
|
||||||
|
///< that in case of stereo-sound a single sample
|
||||||
|
///< contains data for both channels.
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Clears all the samples in the object's output and internal processing
|
||||||
|
/// buffers.
|
||||||
|
virtual void clear();
|
||||||
|
|
||||||
|
/// Changes a setting controlling the processing system behaviour. See the
|
||||||
|
/// 'SETTING_...' defines for available setting ID's.
|
||||||
|
///
|
||||||
|
/// \return 'true' if the setting was succesfully changed
|
||||||
|
bool setSetting(int settingId, ///< Setting ID number. see SETTING_... defines.
|
||||||
|
int value ///< New setting value.
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Reads a setting controlling the processing system behaviour. See the
|
||||||
|
/// 'SETTING_...' defines for available setting ID's.
|
||||||
|
///
|
||||||
|
/// \return the setting value.
|
||||||
|
int getSetting(int settingId ///< Setting ID number, see SETTING_... defines.
|
||||||
|
) const;
|
||||||
|
|
||||||
|
/// Returns number of samples currently unprocessed.
|
||||||
|
virtual uint numUnprocessedSamples() const;
|
||||||
|
|
||||||
|
|
||||||
|
/// Other handy functions that are implemented in the ancestor classes (see
|
||||||
|
/// classes 'FIFOProcessor' and 'FIFOSamplePipe')
|
||||||
|
///
|
||||||
|
/// - receiveSamples() : Use this function to receive 'ready' processed samples from SoundTouch.
|
||||||
|
/// - numSamples() : Get number of 'ready' samples that can be received with
|
||||||
|
/// function 'receiveSamples()'
|
||||||
|
/// - isEmpty() : Returns nonzero if there aren't any 'ready' samples.
|
||||||
|
/// - clear() : Clears all samples from ready/processing buffers.
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
808
media/libsoundtouch/src/TDStretch.cpp
Normal file
808
media/libsoundtouch/src/TDStretch.cpp
Normal file
@ -0,0 +1,808 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// Sampled sound tempo changer/time stretch algorithm. Changes the sound tempo
|
||||||
|
/// while maintaining the original pitch by using a time domain WSOLA-like
|
||||||
|
/// method with several performance-increasing tweaks.
|
||||||
|
///
|
||||||
|
/// Note : MMX optimized functions reside in a separate, platform-specific
|
||||||
|
/// file, e.g. 'mmx_win.cpp' or 'mmx_gcc.cpp'
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2012-04-01 12:49:30 -0700 (Sun, 01 Apr 2012) $
|
||||||
|
// File revision : $Revision: 1.12 $
|
||||||
|
//
|
||||||
|
// $Id: TDStretch.cpp 137 2012-04-01 19:49:30Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
#include "STTypes.h"
|
||||||
|
#include "cpu_detect.h"
|
||||||
|
#include "TDStretch.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
using namespace soundtouch;
|
||||||
|
|
||||||
|
#define max(x, y) (((x) > (y)) ? (x) : (y))
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* Constant definitions
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
// Table for the hierarchical mixing position seeking algorithm
|
||||||
|
static const short _scanOffsets[5][24]={
|
||||||
|
{ 124, 186, 248, 310, 372, 434, 496, 558, 620, 682, 744, 806,
|
||||||
|
868, 930, 992, 1054, 1116, 1178, 1240, 1302, 1364, 1426, 1488, 0},
|
||||||
|
{-100, -75, -50, -25, 25, 50, 75, 100, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
|
{ -20, -15, -10, -5, 5, 10, 15, 20, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
|
{ -4, -3, -2, -1, 1, 2, 3, 4, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
|
{ 121, 114, 97, 114, 98, 105, 108, 32, 104, 99, 117, 111,
|
||||||
|
116, 100, 110, 117, 111, 115, 0, 0, 0, 0, 0, 0}};
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* Implementation of the class 'TDStretch'
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
TDStretch::TDStretch() : FIFOProcessor(&outputBuffer)
|
||||||
|
{
|
||||||
|
bQuickSeek = false;
|
||||||
|
channels = 2;
|
||||||
|
|
||||||
|
pMidBuffer = NULL;
|
||||||
|
pMidBufferUnaligned = NULL;
|
||||||
|
overlapLength = 0;
|
||||||
|
|
||||||
|
bAutoSeqSetting = true;
|
||||||
|
bAutoSeekSetting = true;
|
||||||
|
|
||||||
|
// outDebt = 0;
|
||||||
|
skipFract = 0;
|
||||||
|
|
||||||
|
tempo = 1.0f;
|
||||||
|
setParameters(44100, DEFAULT_SEQUENCE_MS, DEFAULT_SEEKWINDOW_MS, DEFAULT_OVERLAP_MS);
|
||||||
|
setTempo(1.0f);
|
||||||
|
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TDStretch::~TDStretch()
|
||||||
|
{
|
||||||
|
delete[] pMidBufferUnaligned;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sets routine control parameters. These control are certain time constants
|
||||||
|
// defining how the sound is stretched to the desired duration.
|
||||||
|
//
|
||||||
|
// 'sampleRate' = sample rate of the sound
|
||||||
|
// 'sequenceMS' = one processing sequence length in milliseconds (default = 82 ms)
|
||||||
|
// 'seekwindowMS' = seeking window length for scanning the best overlapping
|
||||||
|
// position (default = 28 ms)
|
||||||
|
// 'overlapMS' = overlapping length (default = 12 ms)
|
||||||
|
|
||||||
|
void TDStretch::setParameters(int aSampleRate, int aSequenceMS,
|
||||||
|
int aSeekWindowMS, int aOverlapMS)
|
||||||
|
{
|
||||||
|
// accept only positive parameter values - if zero or negative, use old values instead
|
||||||
|
if (aSampleRate > 0) this->sampleRate = aSampleRate;
|
||||||
|
if (aOverlapMS > 0) this->overlapMs = aOverlapMS;
|
||||||
|
|
||||||
|
if (aSequenceMS > 0)
|
||||||
|
{
|
||||||
|
this->sequenceMs = aSequenceMS;
|
||||||
|
bAutoSeqSetting = false;
|
||||||
|
}
|
||||||
|
else if (aSequenceMS == 0)
|
||||||
|
{
|
||||||
|
// if zero, use automatic setting
|
||||||
|
bAutoSeqSetting = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aSeekWindowMS > 0)
|
||||||
|
{
|
||||||
|
this->seekWindowMs = aSeekWindowMS;
|
||||||
|
bAutoSeekSetting = false;
|
||||||
|
}
|
||||||
|
else if (aSeekWindowMS == 0)
|
||||||
|
{
|
||||||
|
// if zero, use automatic setting
|
||||||
|
bAutoSeekSetting = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
calcSeqParameters();
|
||||||
|
|
||||||
|
calculateOverlapLength(overlapMs);
|
||||||
|
|
||||||
|
// set tempo to recalculate 'sampleReq'
|
||||||
|
setTempo(tempo);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// Get routine control parameters, see setParameters() function.
|
||||||
|
/// Any of the parameters to this function can be NULL, in such case corresponding parameter
|
||||||
|
/// value isn't returned.
|
||||||
|
void TDStretch::getParameters(int *pSampleRate, int *pSequenceMs, int *pSeekWindowMs, int *pOverlapMs) const
|
||||||
|
{
|
||||||
|
if (pSampleRate)
|
||||||
|
{
|
||||||
|
*pSampleRate = sampleRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pSequenceMs)
|
||||||
|
{
|
||||||
|
*pSequenceMs = (bAutoSeqSetting) ? (USE_AUTO_SEQUENCE_LEN) : sequenceMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pSeekWindowMs)
|
||||||
|
{
|
||||||
|
*pSeekWindowMs = (bAutoSeekSetting) ? (USE_AUTO_SEEKWINDOW_LEN) : seekWindowMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pOverlapMs)
|
||||||
|
{
|
||||||
|
*pOverlapMs = overlapMs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Overlaps samples in 'midBuffer' with the samples in 'pInput'
|
||||||
|
void TDStretch::overlapMono(SAMPLETYPE *pOutput, const SAMPLETYPE *pInput) const
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
SAMPLETYPE m1, m2;
|
||||||
|
|
||||||
|
m1 = (SAMPLETYPE)0;
|
||||||
|
m2 = (SAMPLETYPE)overlapLength;
|
||||||
|
|
||||||
|
for (i = 0; i < overlapLength ; i ++)
|
||||||
|
{
|
||||||
|
pOutput[i] = (pInput[i] * m1 + pMidBuffer[i] * m2 ) / overlapLength;
|
||||||
|
m1 += 1;
|
||||||
|
m2 -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TDStretch::clearMidBuffer()
|
||||||
|
{
|
||||||
|
memset(pMidBuffer, 0, 2 * sizeof(SAMPLETYPE) * overlapLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TDStretch::clearInput()
|
||||||
|
{
|
||||||
|
inputBuffer.clear();
|
||||||
|
clearMidBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Clears the sample buffers
|
||||||
|
void TDStretch::clear()
|
||||||
|
{
|
||||||
|
outputBuffer.clear();
|
||||||
|
clearInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Enables/disables the quick position seeking algorithm. Zero to disable, nonzero
|
||||||
|
// to enable
|
||||||
|
void TDStretch::enableQuickSeek(bool enable)
|
||||||
|
{
|
||||||
|
bQuickSeek = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Returns nonzero if the quick seeking algorithm is enabled.
|
||||||
|
bool TDStretch::isQuickSeekEnabled() const
|
||||||
|
{
|
||||||
|
return bQuickSeek;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Seeks for the optimal overlap-mixing position.
|
||||||
|
int TDStretch::seekBestOverlapPosition(const SAMPLETYPE *refPos)
|
||||||
|
{
|
||||||
|
if (bQuickSeek)
|
||||||
|
{
|
||||||
|
return seekBestOverlapPositionQuick(refPos);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return seekBestOverlapPositionFull(refPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Overlaps samples in 'midBuffer' with the samples in 'pInputBuffer' at position
|
||||||
|
// of 'ovlPos'.
|
||||||
|
inline void TDStretch::overlap(SAMPLETYPE *pOutput, const SAMPLETYPE *pInput, uint ovlPos) const
|
||||||
|
{
|
||||||
|
if (channels == 2)
|
||||||
|
{
|
||||||
|
// stereo sound
|
||||||
|
overlapStereo(pOutput, pInput + 2 * ovlPos);
|
||||||
|
} else {
|
||||||
|
// mono sound.
|
||||||
|
overlapMono(pOutput, pInput + ovlPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Seeks for the optimal overlap-mixing position. The 'stereo' version of the
|
||||||
|
// routine
|
||||||
|
//
|
||||||
|
// The best position is determined as the position where the two overlapped
|
||||||
|
// sample sequences are 'most alike', in terms of the highest cross-correlation
|
||||||
|
// value over the overlapping period
|
||||||
|
int TDStretch::seekBestOverlapPositionFull(const SAMPLETYPE *refPos)
|
||||||
|
{
|
||||||
|
int bestOffs;
|
||||||
|
double bestCorr, corr;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
bestCorr = FLT_MIN;
|
||||||
|
bestOffs = 0;
|
||||||
|
|
||||||
|
// Scans for the best correlation value by testing each possible position
|
||||||
|
// over the permitted range.
|
||||||
|
for (i = 0; i < seekLength; i ++)
|
||||||
|
{
|
||||||
|
// Calculates correlation value for the mixing position corresponding
|
||||||
|
// to 'i'
|
||||||
|
corr = calcCrossCorr(refPos + channels * i, pMidBuffer);
|
||||||
|
// heuristic rule to slightly favour values close to mid of the range
|
||||||
|
double tmp = (double)(2 * i - seekLength) / (double)seekLength;
|
||||||
|
corr = ((corr + 0.1) * (1.0 - 0.25 * tmp * tmp));
|
||||||
|
|
||||||
|
// Checks for the highest correlation value
|
||||||
|
if (corr > bestCorr)
|
||||||
|
{
|
||||||
|
bestCorr = corr;
|
||||||
|
bestOffs = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// clear cross correlation routine state if necessary (is so e.g. in MMX routines).
|
||||||
|
clearCrossCorrState();
|
||||||
|
|
||||||
|
return bestOffs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Seeks for the optimal overlap-mixing position. The 'stereo' version of the
|
||||||
|
// routine
|
||||||
|
//
|
||||||
|
// The best position is determined as the position where the two overlapped
|
||||||
|
// sample sequences are 'most alike', in terms of the highest cross-correlation
|
||||||
|
// value over the overlapping period
|
||||||
|
int TDStretch::seekBestOverlapPositionQuick(const SAMPLETYPE *refPos)
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
int bestOffs;
|
||||||
|
double bestCorr, corr;
|
||||||
|
int scanCount, corrOffset, tempOffset;
|
||||||
|
|
||||||
|
bestCorr = FLT_MIN;
|
||||||
|
bestOffs = _scanOffsets[0][0];
|
||||||
|
corrOffset = 0;
|
||||||
|
tempOffset = 0;
|
||||||
|
|
||||||
|
// Scans for the best correlation value using four-pass hierarchical search.
|
||||||
|
//
|
||||||
|
// The look-up table 'scans' has hierarchical position adjusting steps.
|
||||||
|
// In first pass the routine searhes for the highest correlation with
|
||||||
|
// relatively coarse steps, then rescans the neighbourhood of the highest
|
||||||
|
// correlation with better resolution and so on.
|
||||||
|
for (scanCount = 0;scanCount < 4; scanCount ++)
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (_scanOffsets[scanCount][j])
|
||||||
|
{
|
||||||
|
tempOffset = corrOffset + _scanOffsets[scanCount][j];
|
||||||
|
if (tempOffset >= seekLength) break;
|
||||||
|
|
||||||
|
// Calculates correlation value for the mixing position corresponding
|
||||||
|
// to 'tempOffset'
|
||||||
|
corr = (double)calcCrossCorr(refPos + channels * tempOffset, pMidBuffer);
|
||||||
|
// heuristic rule to slightly favour values close to mid of the range
|
||||||
|
double tmp = (double)(2 * tempOffset - seekLength) / seekLength;
|
||||||
|
corr = ((corr + 0.1) * (1.0 - 0.25 * tmp * tmp));
|
||||||
|
|
||||||
|
// Checks for the highest correlation value
|
||||||
|
if (corr > bestCorr)
|
||||||
|
{
|
||||||
|
bestCorr = corr;
|
||||||
|
bestOffs = tempOffset;
|
||||||
|
}
|
||||||
|
j ++;
|
||||||
|
}
|
||||||
|
corrOffset = bestOffs;
|
||||||
|
}
|
||||||
|
// clear cross correlation routine state if necessary (is so e.g. in MMX routines).
|
||||||
|
clearCrossCorrState();
|
||||||
|
|
||||||
|
return bestOffs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// clear cross correlation routine state if necessary
|
||||||
|
void TDStretch::clearCrossCorrState()
|
||||||
|
{
|
||||||
|
// default implementation is empty.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Calculates processing sequence length according to tempo setting
|
||||||
|
void TDStretch::calcSeqParameters()
|
||||||
|
{
|
||||||
|
// Adjust tempo param according to tempo, so that variating processing sequence length is used
|
||||||
|
// at varius tempo settings, between the given low...top limits
|
||||||
|
#define AUTOSEQ_TEMPO_LOW 0.5 // auto setting low tempo range (-50%)
|
||||||
|
#define AUTOSEQ_TEMPO_TOP 2.0 // auto setting top tempo range (+100%)
|
||||||
|
|
||||||
|
// sequence-ms setting values at above low & top tempo
|
||||||
|
#define AUTOSEQ_AT_MIN 125.0
|
||||||
|
#define AUTOSEQ_AT_MAX 50.0
|
||||||
|
#define AUTOSEQ_K ((AUTOSEQ_AT_MAX - AUTOSEQ_AT_MIN) / (AUTOSEQ_TEMPO_TOP - AUTOSEQ_TEMPO_LOW))
|
||||||
|
#define AUTOSEQ_C (AUTOSEQ_AT_MIN - (AUTOSEQ_K) * (AUTOSEQ_TEMPO_LOW))
|
||||||
|
|
||||||
|
// seek-window-ms setting values at above low & top tempo
|
||||||
|
#define AUTOSEEK_AT_MIN 25.0
|
||||||
|
#define AUTOSEEK_AT_MAX 15.0
|
||||||
|
#define AUTOSEEK_K ((AUTOSEEK_AT_MAX - AUTOSEEK_AT_MIN) / (AUTOSEQ_TEMPO_TOP - AUTOSEQ_TEMPO_LOW))
|
||||||
|
#define AUTOSEEK_C (AUTOSEEK_AT_MIN - (AUTOSEEK_K) * (AUTOSEQ_TEMPO_LOW))
|
||||||
|
|
||||||
|
#define CHECK_LIMITS(x, mi, ma) (((x) < (mi)) ? (mi) : (((x) > (ma)) ? (ma) : (x)))
|
||||||
|
|
||||||
|
double seq, seek;
|
||||||
|
|
||||||
|
if (bAutoSeqSetting)
|
||||||
|
{
|
||||||
|
seq = AUTOSEQ_C + AUTOSEQ_K * tempo;
|
||||||
|
seq = CHECK_LIMITS(seq, AUTOSEQ_AT_MAX, AUTOSEQ_AT_MIN);
|
||||||
|
sequenceMs = (int)(seq + 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bAutoSeekSetting)
|
||||||
|
{
|
||||||
|
seek = AUTOSEEK_C + AUTOSEEK_K * tempo;
|
||||||
|
seek = CHECK_LIMITS(seek, AUTOSEEK_AT_MAX, AUTOSEEK_AT_MIN);
|
||||||
|
seekWindowMs = (int)(seek + 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update seek window lengths
|
||||||
|
seekWindowLength = (sampleRate * sequenceMs) / 1000;
|
||||||
|
if (seekWindowLength < 2 * overlapLength)
|
||||||
|
{
|
||||||
|
seekWindowLength = 2 * overlapLength;
|
||||||
|
}
|
||||||
|
seekLength = (sampleRate * seekWindowMs) / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sets new target tempo. Normal tempo = 'SCALE', smaller values represent slower
|
||||||
|
// tempo, larger faster tempo.
|
||||||
|
void TDStretch::setTempo(float newTempo)
|
||||||
|
{
|
||||||
|
int intskip;
|
||||||
|
|
||||||
|
tempo = newTempo;
|
||||||
|
|
||||||
|
// Calculate new sequence duration
|
||||||
|
calcSeqParameters();
|
||||||
|
|
||||||
|
// Calculate ideal skip length (according to tempo value)
|
||||||
|
nominalSkip = tempo * (seekWindowLength - overlapLength);
|
||||||
|
intskip = (int)(nominalSkip + 0.5f);
|
||||||
|
|
||||||
|
// Calculate how many samples are needed in the 'inputBuffer' to
|
||||||
|
// process another batch of samples
|
||||||
|
//sampleReq = max(intskip + overlapLength, seekWindowLength) + seekLength / 2;
|
||||||
|
sampleReq = max(intskip + overlapLength, seekWindowLength) + seekLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sets the number of channels, 1 = mono, 2 = stereo
|
||||||
|
void TDStretch::setChannels(int numChannels)
|
||||||
|
{
|
||||||
|
assert(numChannels > 0);
|
||||||
|
if (channels == numChannels) return;
|
||||||
|
assert(numChannels == 1 || numChannels == 2);
|
||||||
|
|
||||||
|
channels = numChannels;
|
||||||
|
inputBuffer.setChannels(channels);
|
||||||
|
outputBuffer.setChannels(channels);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// nominal tempo, no need for processing, just pass the samples through
|
||||||
|
// to outputBuffer
|
||||||
|
/*
|
||||||
|
void TDStretch::processNominalTempo()
|
||||||
|
{
|
||||||
|
assert(tempo == 1.0f);
|
||||||
|
|
||||||
|
if (bMidBufferDirty)
|
||||||
|
{
|
||||||
|
// If there are samples in pMidBuffer waiting for overlapping,
|
||||||
|
// do a single sliding overlapping with them in order to prevent a
|
||||||
|
// clicking distortion in the output sound
|
||||||
|
if (inputBuffer.numSamples() < overlapLength)
|
||||||
|
{
|
||||||
|
// wait until we've got overlapLength input samples
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Mix the samples in the beginning of 'inputBuffer' with the
|
||||||
|
// samples in 'midBuffer' using sliding overlapping
|
||||||
|
overlap(outputBuffer.ptrEnd(overlapLength), inputBuffer.ptrBegin(), 0);
|
||||||
|
outputBuffer.putSamples(overlapLength);
|
||||||
|
inputBuffer.receiveSamples(overlapLength);
|
||||||
|
clearMidBuffer();
|
||||||
|
// now we've caught the nominal sample flow and may switch to
|
||||||
|
// bypass mode
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simply bypass samples from input to output
|
||||||
|
outputBuffer.moveSamples(inputBuffer);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// Processes as many processing frames of the samples 'inputBuffer', store
|
||||||
|
// the result into 'outputBuffer'
|
||||||
|
void TDStretch::processSamples()
|
||||||
|
{
|
||||||
|
int ovlSkip, offset;
|
||||||
|
int temp;
|
||||||
|
|
||||||
|
/* Removed this small optimization - can introduce a click to sound when tempo setting
|
||||||
|
crosses the nominal value
|
||||||
|
if (tempo == 1.0f)
|
||||||
|
{
|
||||||
|
// tempo not changed from the original, so bypass the processing
|
||||||
|
processNominalTempo();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Process samples as long as there are enough samples in 'inputBuffer'
|
||||||
|
// to form a processing frame.
|
||||||
|
while ((int)inputBuffer.numSamples() >= sampleReq)
|
||||||
|
{
|
||||||
|
// If tempo differs from the normal ('SCALE'), scan for the best overlapping
|
||||||
|
// position
|
||||||
|
offset = seekBestOverlapPosition(inputBuffer.ptrBegin());
|
||||||
|
|
||||||
|
// Mix the samples in the 'inputBuffer' at position of 'offset' with the
|
||||||
|
// samples in 'midBuffer' using sliding overlapping
|
||||||
|
// ... first partially overlap with the end of the previous sequence
|
||||||
|
// (that's in 'midBuffer')
|
||||||
|
overlap(outputBuffer.ptrEnd((uint)overlapLength), inputBuffer.ptrBegin(), (uint)offset);
|
||||||
|
outputBuffer.putSamples((uint)overlapLength);
|
||||||
|
|
||||||
|
// ... then copy sequence samples from 'inputBuffer' to output:
|
||||||
|
|
||||||
|
// length of sequence
|
||||||
|
temp = (seekWindowLength - 2 * overlapLength);
|
||||||
|
|
||||||
|
// crosscheck that we don't have buffer overflow...
|
||||||
|
if ((int)inputBuffer.numSamples() < (offset + temp + overlapLength * 2))
|
||||||
|
{
|
||||||
|
continue; // just in case, shouldn't really happen
|
||||||
|
}
|
||||||
|
|
||||||
|
outputBuffer.putSamples(inputBuffer.ptrBegin() + channels * (offset + overlapLength), (uint)temp);
|
||||||
|
|
||||||
|
// Copies the end of the current sequence from 'inputBuffer' to
|
||||||
|
// 'midBuffer' for being mixed with the beginning of the next
|
||||||
|
// processing sequence and so on
|
||||||
|
assert((offset + temp + overlapLength * 2) <= (int)inputBuffer.numSamples());
|
||||||
|
memcpy(pMidBuffer, inputBuffer.ptrBegin() + channels * (offset + temp + overlapLength),
|
||||||
|
channels * sizeof(SAMPLETYPE) * overlapLength);
|
||||||
|
|
||||||
|
// Remove the processed samples from the input buffer. Update
|
||||||
|
// the difference between integer & nominal skip step to 'skipFract'
|
||||||
|
// in order to prevent the error from accumulating over time.
|
||||||
|
skipFract += nominalSkip; // real skip size
|
||||||
|
ovlSkip = (int)skipFract; // rounded to integer skip
|
||||||
|
skipFract -= ovlSkip; // maintain the fraction part, i.e. real vs. integer skip
|
||||||
|
inputBuffer.receiveSamples((uint)ovlSkip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Adds 'numsamples' pcs of samples from the 'samples' memory position into
|
||||||
|
// the input of the object.
|
||||||
|
void TDStretch::putSamples(const SAMPLETYPE *samples, uint nSamples)
|
||||||
|
{
|
||||||
|
// Add the samples into the input buffer
|
||||||
|
inputBuffer.putSamples(samples, nSamples);
|
||||||
|
// Process the samples in input buffer
|
||||||
|
processSamples();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// Set new overlap length parameter & reallocate RefMidBuffer if necessary.
|
||||||
|
void TDStretch::acceptNewOverlapLength(int newOverlapLength)
|
||||||
|
{
|
||||||
|
int prevOvl;
|
||||||
|
|
||||||
|
assert(newOverlapLength >= 0);
|
||||||
|
prevOvl = overlapLength;
|
||||||
|
overlapLength = newOverlapLength;
|
||||||
|
|
||||||
|
if (overlapLength > prevOvl)
|
||||||
|
{
|
||||||
|
delete[] pMidBufferUnaligned;
|
||||||
|
|
||||||
|
pMidBufferUnaligned = new SAMPLETYPE[overlapLength * 2 + 16 / sizeof(SAMPLETYPE)];
|
||||||
|
// ensure that 'pMidBuffer' is aligned to 16 byte boundary for efficiency
|
||||||
|
pMidBuffer = (SAMPLETYPE *)((((ulong)pMidBufferUnaligned) + 15) & (ulong)-16);
|
||||||
|
|
||||||
|
clearMidBuffer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Operator 'new' is overloaded so that it automatically creates a suitable instance
|
||||||
|
// depending on if we've a MMX/SSE/etc-capable CPU available or not.
|
||||||
|
void * TDStretch::operator new(size_t s)
|
||||||
|
{
|
||||||
|
// Notice! don't use "new TDStretch" directly, use "newInstance" to create a new instance instead!
|
||||||
|
ST_THROW_RT_ERROR("Error in TDStretch::new: Don't use 'new TDStretch' directly, use 'newInstance' member instead!");
|
||||||
|
return newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TDStretch * TDStretch::newInstance()
|
||||||
|
{
|
||||||
|
uint uExtensions;
|
||||||
|
|
||||||
|
uExtensions = detectCPUextensions();
|
||||||
|
|
||||||
|
// Check if MMX/SSE instruction set extensions supported by CPU
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_ALLOW_MMX
|
||||||
|
// MMX routines available only with integer sample types
|
||||||
|
if (uExtensions & SUPPORT_MMX)
|
||||||
|
{
|
||||||
|
return ::new TDStretchMMX;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif // SOUNDTOUCH_ALLOW_MMX
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_ALLOW_SSE
|
||||||
|
if (uExtensions & SUPPORT_SSE)
|
||||||
|
{
|
||||||
|
// SSE support
|
||||||
|
return ::new TDStretchSSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif // SOUNDTOUCH_ALLOW_SSE
|
||||||
|
|
||||||
|
{
|
||||||
|
// ISA optimizations not supported, use plain C version
|
||||||
|
return ::new TDStretch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Integer arithmetics specific algorithm implementations.
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
|
||||||
|
|
||||||
|
// Overlaps samples in 'midBuffer' with the samples in 'input'. The 'Stereo'
|
||||||
|
// version of the routine.
|
||||||
|
void TDStretch::overlapStereo(short *poutput, const short *input) const
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
short temp;
|
||||||
|
int cnt2;
|
||||||
|
|
||||||
|
for (i = 0; i < overlapLength ; i ++)
|
||||||
|
{
|
||||||
|
temp = (short)(overlapLength - i);
|
||||||
|
cnt2 = 2 * i;
|
||||||
|
poutput[cnt2] = (input[cnt2] * i + pMidBuffer[cnt2] * temp ) / overlapLength;
|
||||||
|
poutput[cnt2 + 1] = (input[cnt2 + 1] * i + pMidBuffer[cnt2 + 1] * temp ) / overlapLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculates the x having the closest 2^x value for the given value
|
||||||
|
static int _getClosest2Power(double value)
|
||||||
|
{
|
||||||
|
return (int)(log(value) / log(2.0) + 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Calculates overlap period length in samples.
|
||||||
|
/// Integer version rounds overlap length to closest power of 2
|
||||||
|
/// for a divide scaling operation.
|
||||||
|
void TDStretch::calculateOverlapLength(int aoverlapMs)
|
||||||
|
{
|
||||||
|
int newOvl;
|
||||||
|
|
||||||
|
assert(aoverlapMs >= 0);
|
||||||
|
|
||||||
|
// calculate overlap length so that it's power of 2 - thus it's easy to do
|
||||||
|
// integer division by right-shifting. Term "-1" at end is to account for
|
||||||
|
// the extra most significatnt bit left unused in result by signed multiplication
|
||||||
|
overlapDividerBits = _getClosest2Power((sampleRate * aoverlapMs) / 1000.0) - 1;
|
||||||
|
if (overlapDividerBits > 9) overlapDividerBits = 9;
|
||||||
|
if (overlapDividerBits < 3) overlapDividerBits = 3;
|
||||||
|
newOvl = (int)pow(2.0, (int)overlapDividerBits + 1); // +1 => account for -1 above
|
||||||
|
|
||||||
|
acceptNewOverlapLength(newOvl);
|
||||||
|
|
||||||
|
// calculate sloping divider so that crosscorrelation operation won't
|
||||||
|
// overflow 32-bit register. Max. sum of the crosscorrelation sum without
|
||||||
|
// divider would be 2^30*(N^3-N)/3, where N = overlap length
|
||||||
|
slopingDivider = (newOvl * newOvl - 1) / 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double TDStretch::calcCrossCorr(const short *mixingPos, const short *compare) const
|
||||||
|
{
|
||||||
|
long corr;
|
||||||
|
long norm;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
corr = norm = 0;
|
||||||
|
// Same routine for stereo and mono. For stereo, unroll loop for better
|
||||||
|
// efficiency and gives slightly better resolution against rounding.
|
||||||
|
// For mono it same routine, just unrolls loop by factor of 4
|
||||||
|
for (i = 0; i < channels * overlapLength; i += 4)
|
||||||
|
{
|
||||||
|
corr += (mixingPos[i] * compare[i] +
|
||||||
|
mixingPos[i + 1] * compare[i + 1] +
|
||||||
|
mixingPos[i + 2] * compare[i + 2] +
|
||||||
|
mixingPos[i + 3] * compare[i + 3]) >> overlapDividerBits;
|
||||||
|
norm += (mixingPos[i] * mixingPos[i] +
|
||||||
|
mixingPos[i + 1] * mixingPos[i + 1] +
|
||||||
|
mixingPos[i + 2] * mixingPos[i + 2] +
|
||||||
|
mixingPos[i + 3] * mixingPos[i + 3]) >> overlapDividerBits;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalize result by dividing by sqrt(norm) - this step is easiest
|
||||||
|
// done using floating point operation
|
||||||
|
if (norm == 0) norm = 1; // to avoid div by zero
|
||||||
|
return (double)corr / sqrt((double)norm);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SOUNDTOUCH_INTEGER_SAMPLES
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Floating point arithmetics specific algorithm implementations.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_FLOAT_SAMPLES
|
||||||
|
|
||||||
|
// Overlaps samples in 'midBuffer' with the samples in 'pInput'
|
||||||
|
void TDStretch::overlapStereo(float *pOutput, const float *pInput) const
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
float fScale;
|
||||||
|
float f1;
|
||||||
|
float f2;
|
||||||
|
|
||||||
|
fScale = 1.0f / (float)overlapLength;
|
||||||
|
|
||||||
|
f1 = 0;
|
||||||
|
f2 = 1.0f;
|
||||||
|
|
||||||
|
for (i = 0; i < 2 * (int)overlapLength ; i += 2)
|
||||||
|
{
|
||||||
|
pOutput[i + 0] = pInput[i + 0] * f1 + pMidBuffer[i + 0] * f2;
|
||||||
|
pOutput[i + 1] = pInput[i + 1] * f1 + pMidBuffer[i + 1] * f2;
|
||||||
|
|
||||||
|
f1 += fScale;
|
||||||
|
f2 -= fScale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Calculates overlapInMsec period length in samples.
|
||||||
|
void TDStretch::calculateOverlapLength(int overlapInMsec)
|
||||||
|
{
|
||||||
|
int newOvl;
|
||||||
|
|
||||||
|
assert(overlapInMsec >= 0);
|
||||||
|
newOvl = (sampleRate * overlapInMsec) / 1000;
|
||||||
|
if (newOvl < 16) newOvl = 16;
|
||||||
|
|
||||||
|
// must be divisible by 8
|
||||||
|
newOvl -= newOvl % 8;
|
||||||
|
|
||||||
|
acceptNewOverlapLength(newOvl);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double TDStretch::calcCrossCorr(const float *mixingPos, const float *compare) const
|
||||||
|
{
|
||||||
|
double corr;
|
||||||
|
double norm;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
corr = norm = 0;
|
||||||
|
// Same routine for stereo and mono. For Stereo, unroll by factor of 2.
|
||||||
|
// For mono it's same routine yet unrollsd by factor of 4.
|
||||||
|
for (i = 0; i < channels * overlapLength; i += 4)
|
||||||
|
{
|
||||||
|
corr += mixingPos[i] * compare[i] +
|
||||||
|
mixingPos[i + 1] * compare[i + 1];
|
||||||
|
|
||||||
|
norm += mixingPos[i] * mixingPos[i] +
|
||||||
|
mixingPos[i + 1] * mixingPos[i + 1];
|
||||||
|
|
||||||
|
// unroll the loop for better CPU efficiency:
|
||||||
|
corr += mixingPos[i + 2] * compare[i + 2] +
|
||||||
|
mixingPos[i + 3] * compare[i + 3];
|
||||||
|
|
||||||
|
norm += mixingPos[i + 2] * mixingPos[i + 2] +
|
||||||
|
mixingPos[i + 3] * mixingPos[i + 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (norm < 1e-9) norm = 1.0; // to avoid div by zero
|
||||||
|
return corr / sqrt(norm);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SOUNDTOUCH_FLOAT_SAMPLES
|
268
media/libsoundtouch/src/TDStretch.h
Normal file
268
media/libsoundtouch/src/TDStretch.h
Normal file
@ -0,0 +1,268 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// Sampled sound tempo changer/time stretch algorithm. Changes the sound tempo
|
||||||
|
/// while maintaining the original pitch by using a time domain WSOLA-like method
|
||||||
|
/// with several performance-increasing tweaks.
|
||||||
|
///
|
||||||
|
/// Note : MMX/SSE optimized functions reside in separate, platform-specific files
|
||||||
|
/// 'mmx_optimized.cpp' and 'sse_optimized.cpp'
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2012-04-01 12:49:30 -0700 (Sun, 01 Apr 2012) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: TDStretch.h 137 2012-04-01 19:49:30Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef TDStretch_H
|
||||||
|
#define TDStretch_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include "STTypes.h"
|
||||||
|
#include "RateTransposer.h"
|
||||||
|
#include "FIFOSamplePipe.h"
|
||||||
|
|
||||||
|
namespace soundtouch
|
||||||
|
{
|
||||||
|
|
||||||
|
/// Default values for sound processing parameters:
|
||||||
|
/// Notice that the default parameters are tuned for contemporary popular music
|
||||||
|
/// processing. For speech processing applications these parameters suit better:
|
||||||
|
/// #define DEFAULT_SEQUENCE_MS 40
|
||||||
|
/// #define DEFAULT_SEEKWINDOW_MS 15
|
||||||
|
/// #define DEFAULT_OVERLAP_MS 8
|
||||||
|
///
|
||||||
|
|
||||||
|
/// Default length of a single processing sequence, in milliseconds. This determines to how
|
||||||
|
/// long sequences the original sound is chopped in the time-stretch algorithm.
|
||||||
|
///
|
||||||
|
/// The larger this value is, the lesser sequences are used in processing. In principle
|
||||||
|
/// a bigger value sounds better when slowing down tempo, but worse when increasing tempo
|
||||||
|
/// and vice versa.
|
||||||
|
///
|
||||||
|
/// Increasing this value reduces computational burden & vice versa.
|
||||||
|
//#define DEFAULT_SEQUENCE_MS 40
|
||||||
|
#define DEFAULT_SEQUENCE_MS USE_AUTO_SEQUENCE_LEN
|
||||||
|
|
||||||
|
/// Giving this value for the sequence length sets automatic parameter value
|
||||||
|
/// according to tempo setting (recommended)
|
||||||
|
#define USE_AUTO_SEQUENCE_LEN 0
|
||||||
|
|
||||||
|
/// Seeking window default length in milliseconds for algorithm that finds the best possible
|
||||||
|
/// overlapping location. This determines from how wide window the algorithm may look for an
|
||||||
|
/// optimal joining location when mixing the sound sequences back together.
|
||||||
|
///
|
||||||
|
/// The bigger this window setting is, the higher the possibility to find a better mixing
|
||||||
|
/// position will become, but at the same time large values may cause a "drifting" artifact
|
||||||
|
/// because consequent sequences will be taken at more uneven intervals.
|
||||||
|
///
|
||||||
|
/// If there's a disturbing artifact that sounds as if a constant frequency was drifting
|
||||||
|
/// around, try reducing this setting.
|
||||||
|
///
|
||||||
|
/// Increasing this value increases computational burden & vice versa.
|
||||||
|
//#define DEFAULT_SEEKWINDOW_MS 15
|
||||||
|
#define DEFAULT_SEEKWINDOW_MS USE_AUTO_SEEKWINDOW_LEN
|
||||||
|
|
||||||
|
/// Giving this value for the seek window length sets automatic parameter value
|
||||||
|
/// according to tempo setting (recommended)
|
||||||
|
#define USE_AUTO_SEEKWINDOW_LEN 0
|
||||||
|
|
||||||
|
/// Overlap length in milliseconds. When the chopped sound sequences are mixed back together,
|
||||||
|
/// to form a continuous sound stream, this parameter defines over how long period the two
|
||||||
|
/// consecutive sequences are let to overlap each other.
|
||||||
|
///
|
||||||
|
/// This shouldn't be that critical parameter. If you reduce the DEFAULT_SEQUENCE_MS setting
|
||||||
|
/// by a large amount, you might wish to try a smaller value on this.
|
||||||
|
///
|
||||||
|
/// Increasing this value increases computational burden & vice versa.
|
||||||
|
#define DEFAULT_OVERLAP_MS 8
|
||||||
|
|
||||||
|
|
||||||
|
/// Class that does the time-stretch (tempo change) effect for the processed
|
||||||
|
/// sound.
|
||||||
|
class TDStretch : public FIFOProcessor
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
int channels;
|
||||||
|
int sampleReq;
|
||||||
|
float tempo;
|
||||||
|
|
||||||
|
SAMPLETYPE *pMidBuffer;
|
||||||
|
SAMPLETYPE *pMidBufferUnaligned;
|
||||||
|
int overlapLength;
|
||||||
|
int seekLength;
|
||||||
|
int seekWindowLength;
|
||||||
|
int overlapDividerBits;
|
||||||
|
int slopingDivider;
|
||||||
|
float nominalSkip;
|
||||||
|
float skipFract;
|
||||||
|
FIFOSampleBuffer outputBuffer;
|
||||||
|
FIFOSampleBuffer inputBuffer;
|
||||||
|
bool bQuickSeek;
|
||||||
|
|
||||||
|
int sampleRate;
|
||||||
|
int sequenceMs;
|
||||||
|
int seekWindowMs;
|
||||||
|
int overlapMs;
|
||||||
|
bool bAutoSeqSetting;
|
||||||
|
bool bAutoSeekSetting;
|
||||||
|
|
||||||
|
void acceptNewOverlapLength(int newOverlapLength);
|
||||||
|
|
||||||
|
virtual void clearCrossCorrState();
|
||||||
|
void calculateOverlapLength(int overlapMs);
|
||||||
|
|
||||||
|
virtual double calcCrossCorr(const SAMPLETYPE *mixingPos, const SAMPLETYPE *compare) const;
|
||||||
|
|
||||||
|
virtual int seekBestOverlapPositionFull(const SAMPLETYPE *refPos);
|
||||||
|
virtual int seekBestOverlapPositionQuick(const SAMPLETYPE *refPos);
|
||||||
|
int seekBestOverlapPosition(const SAMPLETYPE *refPos);
|
||||||
|
|
||||||
|
virtual void overlapStereo(SAMPLETYPE *output, const SAMPLETYPE *input) const;
|
||||||
|
virtual void overlapMono(SAMPLETYPE *output, const SAMPLETYPE *input) const;
|
||||||
|
|
||||||
|
void clearMidBuffer();
|
||||||
|
void overlap(SAMPLETYPE *output, const SAMPLETYPE *input, uint ovlPos) const;
|
||||||
|
|
||||||
|
void calcSeqParameters();
|
||||||
|
|
||||||
|
/// Changes the tempo of the given sound samples.
|
||||||
|
/// Returns amount of samples returned in the "output" buffer.
|
||||||
|
/// The maximum amount of samples that can be returned at a time is set by
|
||||||
|
/// the 'set_returnBuffer_size' function.
|
||||||
|
void processSamples();
|
||||||
|
|
||||||
|
public:
|
||||||
|
TDStretch();
|
||||||
|
virtual ~TDStretch();
|
||||||
|
|
||||||
|
/// Operator 'new' is overloaded so that it automatically creates a suitable instance
|
||||||
|
/// depending on if we've a MMX/SSE/etc-capable CPU available or not.
|
||||||
|
static void *operator new(size_t s);
|
||||||
|
|
||||||
|
/// Use this function instead of "new" operator to create a new instance of this class.
|
||||||
|
/// This function automatically chooses a correct feature set depending on if the CPU
|
||||||
|
/// supports MMX/SSE/etc extensions.
|
||||||
|
static TDStretch *newInstance();
|
||||||
|
|
||||||
|
/// Returns the output buffer object
|
||||||
|
FIFOSamplePipe *getOutput() { return &outputBuffer; };
|
||||||
|
|
||||||
|
/// Returns the input buffer object
|
||||||
|
FIFOSamplePipe *getInput() { return &inputBuffer; };
|
||||||
|
|
||||||
|
/// Sets new target tempo. Normal tempo = 'SCALE', smaller values represent slower
|
||||||
|
/// tempo, larger faster tempo.
|
||||||
|
void setTempo(float newTempo);
|
||||||
|
|
||||||
|
/// Returns nonzero if there aren't any samples available for outputting.
|
||||||
|
virtual void clear();
|
||||||
|
|
||||||
|
/// Clears the input buffer
|
||||||
|
void clearInput();
|
||||||
|
|
||||||
|
/// Sets the number of channels, 1 = mono, 2 = stereo
|
||||||
|
void setChannels(int numChannels);
|
||||||
|
|
||||||
|
/// Enables/disables the quick position seeking algorithm. Zero to disable,
|
||||||
|
/// nonzero to enable
|
||||||
|
void enableQuickSeek(bool enable);
|
||||||
|
|
||||||
|
/// Returns nonzero if the quick seeking algorithm is enabled.
|
||||||
|
bool isQuickSeekEnabled() const;
|
||||||
|
|
||||||
|
/// Sets routine control parameters. These control are certain time constants
|
||||||
|
/// defining how the sound is stretched to the desired duration.
|
||||||
|
//
|
||||||
|
/// 'sampleRate' = sample rate of the sound
|
||||||
|
/// 'sequenceMS' = one processing sequence length in milliseconds
|
||||||
|
/// 'seekwindowMS' = seeking window length for scanning the best overlapping
|
||||||
|
/// position
|
||||||
|
/// 'overlapMS' = overlapping length
|
||||||
|
void setParameters(int sampleRate, ///< Samplerate of sound being processed (Hz)
|
||||||
|
int sequenceMS = -1, ///< Single processing sequence length (ms)
|
||||||
|
int seekwindowMS = -1, ///< Offset seeking window length (ms)
|
||||||
|
int overlapMS = -1 ///< Sequence overlapping length (ms)
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Get routine control parameters, see setParameters() function.
|
||||||
|
/// Any of the parameters to this function can be NULL, in such case corresponding parameter
|
||||||
|
/// value isn't returned.
|
||||||
|
void getParameters(int *pSampleRate, int *pSequenceMs, int *pSeekWindowMs, int *pOverlapMs) const;
|
||||||
|
|
||||||
|
/// Adds 'numsamples' pcs of samples from the 'samples' memory position into
|
||||||
|
/// the input of the object.
|
||||||
|
virtual void putSamples(
|
||||||
|
const SAMPLETYPE *samples, ///< Input sample data
|
||||||
|
uint numSamples ///< Number of samples in 'samples' so that one sample
|
||||||
|
///< contains both channels if stereo
|
||||||
|
);
|
||||||
|
|
||||||
|
/// return nominal input sample requirement for triggering a processing batch
|
||||||
|
int getInputSampleReq() const
|
||||||
|
{
|
||||||
|
return (int)(nominalSkip + 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// return nominal output sample amount when running a processing batch
|
||||||
|
int getOutputBatchSize() const
|
||||||
|
{
|
||||||
|
return seekWindowLength - overlapLength;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Implementation-specific class declarations:
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_ALLOW_MMX
|
||||||
|
/// Class that implements MMX optimized routines for 16bit integer samples type.
|
||||||
|
class TDStretchMMX : public TDStretch
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
double calcCrossCorr(const short *mixingPos, const short *compare) const;
|
||||||
|
virtual void overlapStereo(short *output, const short *input) const;
|
||||||
|
virtual void clearCrossCorrState();
|
||||||
|
};
|
||||||
|
#endif /// SOUNDTOUCH_ALLOW_MMX
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_ALLOW_SSE
|
||||||
|
/// Class that implements SSE optimized routines for floating point samples type.
|
||||||
|
class TDStretchSSE : public TDStretch
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
double calcCrossCorr(const float *mixingPos, const float *compare) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /// SOUNDTOUCH_ALLOW_SSE
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif /// TDStretch_H
|
62
media/libsoundtouch/src/cpu_detect.h
Normal file
62
media/libsoundtouch/src/cpu_detect.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// A header file for detecting the Intel MMX instructions set extension.
|
||||||
|
///
|
||||||
|
/// Please see 'mmx_win.cpp', 'mmx_cpp.cpp' and 'mmx_non_x86.cpp' for the
|
||||||
|
/// routine implementations for x86 Windows, x86 gnu version and non-x86
|
||||||
|
/// platforms, respectively.
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2008-02-10 08:26:55 -0800 (Sun, 10 Feb 2008) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: cpu_detect.h 11 2008-02-10 16:26:55Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef _CPU_DETECT_H_
|
||||||
|
#define _CPU_DETECT_H_
|
||||||
|
|
||||||
|
#include "STTypes.h"
|
||||||
|
|
||||||
|
#define SUPPORT_MMX 0x0001
|
||||||
|
#define SUPPORT_3DNOW 0x0002
|
||||||
|
#define SUPPORT_ALTIVEC 0x0004
|
||||||
|
#define SUPPORT_SSE 0x0008
|
||||||
|
#define SUPPORT_SSE2 0x0010
|
||||||
|
|
||||||
|
/// Checks which instruction set extensions are supported by the CPU.
|
||||||
|
///
|
||||||
|
/// \return A bitmask of supported extensions, see SUPPORT_... defines.
|
||||||
|
uint detectCPUextensions(void);
|
||||||
|
|
||||||
|
/// Disables given set of instruction extensions. See SUPPORT_... defines.
|
||||||
|
void disableExtensions(uint wDisableMask);
|
||||||
|
|
||||||
|
#endif // _CPU_DETECT_H_
|
144
media/libsoundtouch/src/cpu_detect_x86.cpp
Normal file
144
media/libsoundtouch/src/cpu_detect_x86.cpp
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// Generic version of the x86 CPU extension detection routine.
|
||||||
|
///
|
||||||
|
/// This file is for GNU & other non-Windows compilers, see 'cpu_detect_x86_win.cpp'
|
||||||
|
/// for the Microsoft compiler version.
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2012-04-01 13:00:09 -0700 (Sun, 01 Apr 2012) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: cpu_detect_x86.cpp 138 2012-04-01 20:00:09Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "cpu_detect.h"
|
||||||
|
#include "STTypes.h"
|
||||||
|
|
||||||
|
#if defined(SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS)
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
// gcc and clang
|
||||||
|
#include "cpuid.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_M_IX86)
|
||||||
|
// windows
|
||||||
|
#include <intrin.h>
|
||||||
|
#endif
|
||||||
|
// If we still don't have the macros, define them (Windows, MacOS)
|
||||||
|
#ifndef bit_MMX
|
||||||
|
#define bit_MMX (1 << 23)
|
||||||
|
#endif
|
||||||
|
#ifndef bit_SSE
|
||||||
|
#define bit_SSE (1 << 25)
|
||||||
|
#endif
|
||||||
|
#ifndef bit_SSE2
|
||||||
|
#define bit_SSE2 (1 << 26)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// processor instructions extension detection routines
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Flag variable indicating whick ISA extensions are disabled (for debugging)
|
||||||
|
static uint _dwDisabledISA = 0x00; // 0xffffffff; //<- use this to disable all extensions
|
||||||
|
|
||||||
|
// Disables given set of instruction extensions. See SUPPORT_... defines.
|
||||||
|
void disableExtensions(uint dwDisableMask)
|
||||||
|
{
|
||||||
|
_dwDisabledISA = dwDisableMask;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// Checks which instruction set extensions are supported by the CPU.
|
||||||
|
uint detectCPUextensions(void)
|
||||||
|
{
|
||||||
|
/// If building for a 64bit system (no Itanium) and the user wants optimizations.
|
||||||
|
/// Return the OR of SUPPORT_{MMX,SSE,SSE2}. 11001 or 0x19.
|
||||||
|
/// Keep the _dwDisabledISA test (2 more operations, could be eliminated).
|
||||||
|
#if ((defined(__GNUC__) && defined(__x86_64__)) \
|
||||||
|
|| defined(_M_X64)) \
|
||||||
|
&& defined(SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS)
|
||||||
|
return 0x19 & ~_dwDisabledISA;
|
||||||
|
|
||||||
|
/// If building for a 32bit system and the user wants optimizations.
|
||||||
|
/// Keep the _dwDisabledISA test (2 more operations, could be eliminated).
|
||||||
|
#elif ((defined(__GNUC__) && defined(__i386__)) \
|
||||||
|
|| defined(_M_IX86)) \
|
||||||
|
&& defined(SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS)
|
||||||
|
|
||||||
|
if (_dwDisabledISA == 0xffffffff) return 0;
|
||||||
|
|
||||||
|
uint res = 0;
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
// GCC version of cpuid. Requires GCC 4.3.0 or later for __cpuid intrinsic support.
|
||||||
|
uint eax, ebx, ecx, edx; // unsigned int is the standard type. uint is defined by the compiler and not guaranteed to be portable.
|
||||||
|
|
||||||
|
// Check if no cpuid support.
|
||||||
|
if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx)) return 0; // always disable extensions.
|
||||||
|
|
||||||
|
if (edx & bit_MMX) res = res | SUPPORT_MMX;
|
||||||
|
if (edx & bit_SSE) res = res | SUPPORT_SSE;
|
||||||
|
if (edx & bit_SSE2) res = res | SUPPORT_SSE2;
|
||||||
|
|
||||||
|
#else
|
||||||
|
// Window / VS version of cpuid. Notice that Visual Studio 2005 or later required
|
||||||
|
// for __cpuid intrinsic support.
|
||||||
|
int reg[4] = {-1};
|
||||||
|
|
||||||
|
// Check if no cpuid support.
|
||||||
|
__cpuid(reg,0);
|
||||||
|
if ((unsigned int)reg[0] == 0) return 0; // always disable extensions.
|
||||||
|
|
||||||
|
__cpuid(reg,1);
|
||||||
|
if ((unsigned int)reg[3] & bit_MMX) res = res | SUPPORT_MMX;
|
||||||
|
if ((unsigned int)reg[3] & bit_SSE) res = res | SUPPORT_SSE;
|
||||||
|
if ((unsigned int)reg[3] & bit_SSE2) res = res | SUPPORT_SSE2;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return res & ~_dwDisabledISA;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/// One of these is true:
|
||||||
|
/// 1) We don't want optimizations.
|
||||||
|
/// 2) Using an unsupported compiler.
|
||||||
|
/// 3) Running on a non-x86 platform.
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
317
media/libsoundtouch/src/mmx_optimized.cpp
Normal file
317
media/libsoundtouch/src/mmx_optimized.cpp
Normal file
@ -0,0 +1,317 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// MMX optimized routines. All MMX optimized functions have been gathered into
|
||||||
|
/// this single source code file, regardless to their class or original source
|
||||||
|
/// code file, in order to ease porting the library to other compiler and
|
||||||
|
/// processor platforms.
|
||||||
|
///
|
||||||
|
/// The MMX-optimizations are programmed using MMX compiler intrinsics that
|
||||||
|
/// are supported both by Microsoft Visual C++ and GCC compilers, so this file
|
||||||
|
/// should compile with both toolsets.
|
||||||
|
///
|
||||||
|
/// NOTICE: If using Visual Studio 6.0, you'll need to install the "Visual C++
|
||||||
|
/// 6.0 processor pack" update to support compiler intrinsic syntax. The update
|
||||||
|
/// is available for download at Microsoft Developers Network, see here:
|
||||||
|
/// http://msdn.microsoft.com/en-us/vstudio/aa718349.aspx
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2012-04-01 12:49:30 -0700 (Sun, 01 Apr 2012) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: mmx_optimized.cpp 137 2012-04-01 19:49:30Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "STTypes.h"
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_ALLOW_MMX
|
||||||
|
// MMX routines available only with integer sample type
|
||||||
|
|
||||||
|
using namespace soundtouch;
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// implementation of MMX optimized functions of class 'TDStretchMMX'
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "TDStretch.h"
|
||||||
|
#include <mmintrin.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
|
// Calculates cross correlation of two buffers
|
||||||
|
double TDStretchMMX::calcCrossCorr(const short *pV1, const short *pV2) const
|
||||||
|
{
|
||||||
|
const __m64 *pVec1, *pVec2;
|
||||||
|
__m64 shifter;
|
||||||
|
__m64 accu, normaccu;
|
||||||
|
long corr, norm;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
pVec1 = (__m64*)pV1;
|
||||||
|
pVec2 = (__m64*)pV2;
|
||||||
|
|
||||||
|
shifter = _m_from_int(overlapDividerBits);
|
||||||
|
normaccu = accu = _mm_setzero_si64();
|
||||||
|
|
||||||
|
// Process 4 parallel sets of 2 * stereo samples or 4 * mono samples
|
||||||
|
// during each round for improved CPU-level parallellization.
|
||||||
|
for (i = 0; i < channels * overlapLength / 16; i ++)
|
||||||
|
{
|
||||||
|
__m64 temp, temp2;
|
||||||
|
|
||||||
|
// dictionary of instructions:
|
||||||
|
// _m_pmaddwd : 4*16bit multiply-add, resulting two 32bits = [a0*b0+a1*b1 ; a2*b2+a3*b3]
|
||||||
|
// _mm_add_pi32 : 2*32bit add
|
||||||
|
// _m_psrad : 32bit right-shift
|
||||||
|
|
||||||
|
temp = _mm_add_pi32(_mm_madd_pi16(pVec1[0], pVec2[0]),
|
||||||
|
_mm_madd_pi16(pVec1[1], pVec2[1]));
|
||||||
|
temp2 = _mm_add_pi32(_mm_madd_pi16(pVec1[0], pVec1[0]),
|
||||||
|
_mm_madd_pi16(pVec1[1], pVec1[1]));
|
||||||
|
accu = _mm_add_pi32(accu, _mm_sra_pi32(temp, shifter));
|
||||||
|
normaccu = _mm_add_pi32(normaccu, _mm_sra_pi32(temp2, shifter));
|
||||||
|
|
||||||
|
temp = _mm_add_pi32(_mm_madd_pi16(pVec1[2], pVec2[2]),
|
||||||
|
_mm_madd_pi16(pVec1[3], pVec2[3]));
|
||||||
|
temp2 = _mm_add_pi32(_mm_madd_pi16(pVec1[2], pVec1[2]),
|
||||||
|
_mm_madd_pi16(pVec1[3], pVec1[3]));
|
||||||
|
accu = _mm_add_pi32(accu, _mm_sra_pi32(temp, shifter));
|
||||||
|
normaccu = _mm_add_pi32(normaccu, _mm_sra_pi32(temp2, shifter));
|
||||||
|
|
||||||
|
pVec1 += 4;
|
||||||
|
pVec2 += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy hi-dword of mm0 to lo-dword of mm1, then sum mmo+mm1
|
||||||
|
// and finally store the result into the variable "corr"
|
||||||
|
|
||||||
|
accu = _mm_add_pi32(accu, _mm_srli_si64(accu, 32));
|
||||||
|
corr = _m_to_int(accu);
|
||||||
|
|
||||||
|
normaccu = _mm_add_pi32(normaccu, _mm_srli_si64(normaccu, 32));
|
||||||
|
norm = _m_to_int(normaccu);
|
||||||
|
|
||||||
|
// Clear MMS state
|
||||||
|
_m_empty();
|
||||||
|
|
||||||
|
// Normalize result by dividing by sqrt(norm) - this step is easiest
|
||||||
|
// done using floating point operation
|
||||||
|
if (norm == 0) norm = 1; // to avoid div by zero
|
||||||
|
|
||||||
|
return (double)corr / sqrt((double)norm);
|
||||||
|
// Note: Warning about the missing EMMS instruction is harmless
|
||||||
|
// as it'll be called elsewhere.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TDStretchMMX::clearCrossCorrState()
|
||||||
|
{
|
||||||
|
// Clear MMS state
|
||||||
|
_m_empty();
|
||||||
|
//_asm EMMS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// MMX-optimized version of the function overlapStereo
|
||||||
|
void TDStretchMMX::overlapStereo(short *output, const short *input) const
|
||||||
|
{
|
||||||
|
const __m64 *pVinput, *pVMidBuf;
|
||||||
|
__m64 *pVdest;
|
||||||
|
__m64 mix1, mix2, adder, shifter;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
pVinput = (const __m64*)input;
|
||||||
|
pVMidBuf = (const __m64*)pMidBuffer;
|
||||||
|
pVdest = (__m64*)output;
|
||||||
|
|
||||||
|
// mix1 = mixer values for 1st stereo sample
|
||||||
|
// mix1 = mixer values for 2nd stereo sample
|
||||||
|
// adder = adder for updating mixer values after each round
|
||||||
|
|
||||||
|
mix1 = _mm_set_pi16(0, overlapLength, 0, overlapLength);
|
||||||
|
adder = _mm_set_pi16(1, -1, 1, -1);
|
||||||
|
mix2 = _mm_add_pi16(mix1, adder);
|
||||||
|
adder = _mm_add_pi16(adder, adder);
|
||||||
|
|
||||||
|
// Overlaplength-division by shifter. "+1" is to account for "-1" deduced in
|
||||||
|
// overlapDividerBits calculation earlier.
|
||||||
|
shifter = _m_from_int(overlapDividerBits + 1);
|
||||||
|
|
||||||
|
for (i = 0; i < overlapLength / 4; i ++)
|
||||||
|
{
|
||||||
|
__m64 temp1, temp2;
|
||||||
|
|
||||||
|
// load & shuffle data so that input & mixbuffer data samples are paired
|
||||||
|
temp1 = _mm_unpacklo_pi16(pVMidBuf[0], pVinput[0]); // = i0l m0l i0r m0r
|
||||||
|
temp2 = _mm_unpackhi_pi16(pVMidBuf[0], pVinput[0]); // = i1l m1l i1r m1r
|
||||||
|
|
||||||
|
// temp = (temp .* mix) >> shifter
|
||||||
|
temp1 = _mm_sra_pi32(_mm_madd_pi16(temp1, mix1), shifter);
|
||||||
|
temp2 = _mm_sra_pi32(_mm_madd_pi16(temp2, mix2), shifter);
|
||||||
|
pVdest[0] = _mm_packs_pi32(temp1, temp2); // pack 2*2*32bit => 4*16bit
|
||||||
|
|
||||||
|
// update mix += adder
|
||||||
|
mix1 = _mm_add_pi16(mix1, adder);
|
||||||
|
mix2 = _mm_add_pi16(mix2, adder);
|
||||||
|
|
||||||
|
// --- second round begins here ---
|
||||||
|
|
||||||
|
// load & shuffle data so that input & mixbuffer data samples are paired
|
||||||
|
temp1 = _mm_unpacklo_pi16(pVMidBuf[1], pVinput[1]); // = i2l m2l i2r m2r
|
||||||
|
temp2 = _mm_unpackhi_pi16(pVMidBuf[1], pVinput[1]); // = i3l m3l i3r m3r
|
||||||
|
|
||||||
|
// temp = (temp .* mix) >> shifter
|
||||||
|
temp1 = _mm_sra_pi32(_mm_madd_pi16(temp1, mix1), shifter);
|
||||||
|
temp2 = _mm_sra_pi32(_mm_madd_pi16(temp2, mix2), shifter);
|
||||||
|
pVdest[1] = _mm_packs_pi32(temp1, temp2); // pack 2*2*32bit => 4*16bit
|
||||||
|
|
||||||
|
// update mix += adder
|
||||||
|
mix1 = _mm_add_pi16(mix1, adder);
|
||||||
|
mix2 = _mm_add_pi16(mix2, adder);
|
||||||
|
|
||||||
|
pVinput += 2;
|
||||||
|
pVMidBuf += 2;
|
||||||
|
pVdest += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
_m_empty(); // clear MMS state
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// implementation of MMX optimized functions of class 'FIRFilter'
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "FIRFilter.h"
|
||||||
|
|
||||||
|
|
||||||
|
FIRFilterMMX::FIRFilterMMX() : FIRFilter()
|
||||||
|
{
|
||||||
|
filterCoeffsUnalign = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FIRFilterMMX::~FIRFilterMMX()
|
||||||
|
{
|
||||||
|
delete[] filterCoeffsUnalign;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// (overloaded) Calculates filter coefficients for MMX routine
|
||||||
|
void FIRFilterMMX::setCoefficients(const short *coeffs, uint newLength, uint uResultDivFactor)
|
||||||
|
{
|
||||||
|
uint i;
|
||||||
|
FIRFilter::setCoefficients(coeffs, newLength, uResultDivFactor);
|
||||||
|
|
||||||
|
// Ensure that filter coeffs array is aligned to 16-byte boundary
|
||||||
|
delete[] filterCoeffsUnalign;
|
||||||
|
filterCoeffsUnalign = new short[2 * newLength + 8];
|
||||||
|
filterCoeffsAlign = (short *)(((ulong)filterCoeffsUnalign + 15) & -16);
|
||||||
|
|
||||||
|
// rearrange the filter coefficients for mmx routines
|
||||||
|
for (i = 0;i < length; i += 4)
|
||||||
|
{
|
||||||
|
filterCoeffsAlign[2 * i + 0] = coeffs[i + 0];
|
||||||
|
filterCoeffsAlign[2 * i + 1] = coeffs[i + 2];
|
||||||
|
filterCoeffsAlign[2 * i + 2] = coeffs[i + 0];
|
||||||
|
filterCoeffsAlign[2 * i + 3] = coeffs[i + 2];
|
||||||
|
|
||||||
|
filterCoeffsAlign[2 * i + 4] = coeffs[i + 1];
|
||||||
|
filterCoeffsAlign[2 * i + 5] = coeffs[i + 3];
|
||||||
|
filterCoeffsAlign[2 * i + 6] = coeffs[i + 1];
|
||||||
|
filterCoeffsAlign[2 * i + 7] = coeffs[i + 3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// mmx-optimized version of the filter routine for stereo sound
|
||||||
|
uint FIRFilterMMX::evaluateFilterStereo(short *dest, const short *src, uint numSamples) const
|
||||||
|
{
|
||||||
|
// Create stack copies of the needed member variables for asm routines :
|
||||||
|
uint i, j;
|
||||||
|
__m64 *pVdest = (__m64*)dest;
|
||||||
|
|
||||||
|
if (length < 2) return 0;
|
||||||
|
|
||||||
|
for (i = 0; i < (numSamples - length) / 2; i ++)
|
||||||
|
{
|
||||||
|
__m64 accu1;
|
||||||
|
__m64 accu2;
|
||||||
|
const __m64 *pVsrc = (const __m64*)src;
|
||||||
|
const __m64 *pVfilter = (const __m64*)filterCoeffsAlign;
|
||||||
|
|
||||||
|
accu1 = accu2 = _mm_setzero_si64();
|
||||||
|
for (j = 0; j < lengthDiv8 * 2; j ++)
|
||||||
|
{
|
||||||
|
__m64 temp1, temp2;
|
||||||
|
|
||||||
|
temp1 = _mm_unpacklo_pi16(pVsrc[0], pVsrc[1]); // = l2 l0 r2 r0
|
||||||
|
temp2 = _mm_unpackhi_pi16(pVsrc[0], pVsrc[1]); // = l3 l1 r3 r1
|
||||||
|
|
||||||
|
accu1 = _mm_add_pi32(accu1, _mm_madd_pi16(temp1, pVfilter[0])); // += l2*f2+l0*f0 r2*f2+r0*f0
|
||||||
|
accu1 = _mm_add_pi32(accu1, _mm_madd_pi16(temp2, pVfilter[1])); // += l3*f3+l1*f1 r3*f3+r1*f1
|
||||||
|
|
||||||
|
temp1 = _mm_unpacklo_pi16(pVsrc[1], pVsrc[2]); // = l4 l2 r4 r2
|
||||||
|
|
||||||
|
accu2 = _mm_add_pi32(accu2, _mm_madd_pi16(temp2, pVfilter[0])); // += l3*f2+l1*f0 r3*f2+r1*f0
|
||||||
|
accu2 = _mm_add_pi32(accu2, _mm_madd_pi16(temp1, pVfilter[1])); // += l4*f3+l2*f1 r4*f3+r2*f1
|
||||||
|
|
||||||
|
// accu1 += l2*f2+l0*f0 r2*f2+r0*f0
|
||||||
|
// += l3*f3+l1*f1 r3*f3+r1*f1
|
||||||
|
|
||||||
|
// accu2 += l3*f2+l1*f0 r3*f2+r1*f0
|
||||||
|
// l4*f3+l2*f1 r4*f3+r2*f1
|
||||||
|
|
||||||
|
pVfilter += 2;
|
||||||
|
pVsrc += 2;
|
||||||
|
}
|
||||||
|
// accu >>= resultDivFactor
|
||||||
|
accu1 = _mm_srai_pi32(accu1, resultDivFactor);
|
||||||
|
accu2 = _mm_srai_pi32(accu2, resultDivFactor);
|
||||||
|
|
||||||
|
// pack 2*2*32bits => 4*16 bits
|
||||||
|
pVdest[0] = _mm_packs_pi32(accu1, accu2);
|
||||||
|
src += 4;
|
||||||
|
pVdest ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
_m_empty(); // clear emms state
|
||||||
|
|
||||||
|
return (numSamples & 0xfffffffe) - length;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SOUNDTOUCH_ALLOW_MMX
|
53
media/libsoundtouch/src/soundtouch.rc
Normal file
53
media/libsoundtouch/src/soundtouch.rc
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
|
||||||
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
#include<winver.h>
|
||||||
|
|
||||||
|
// Note: if you contain versioning information in an included
|
||||||
|
// RC script, it will be discarded
|
||||||
|
// Use module.ver to explicitly set these values
|
||||||
|
|
||||||
|
// Do not edit this file. Changes won't affect the build.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Version
|
||||||
|
//
|
||||||
|
VS_VERSION_INFO VERSIONINFO
|
||||||
|
FILEVERSION 1,7,0,0
|
||||||
|
PRODUCTVERSION 1,7,0,0
|
||||||
|
FILEFLAGSMASK 0x17L
|
||||||
|
#ifdef _DEBUG
|
||||||
|
FILEFLAGS 0x1L
|
||||||
|
#else
|
||||||
|
FILEFLAGS 0x0L
|
||||||
|
#endif
|
||||||
|
FILEOS 0x4L
|
||||||
|
FILETYPE 0x2L
|
||||||
|
FILESUBTYPE 0x0L
|
||||||
|
BEGIN
|
||||||
|
BLOCK "StringFileInfo"
|
||||||
|
BEGIN
|
||||||
|
BLOCK "000004b0"
|
||||||
|
BEGIN
|
||||||
|
VALUE "Comments", "SoundTouch Library licensed for 3rd party applications subject to LGPL license v2.1. Visit http://www.surina.net/soundtouch for more information about the SoundTouch library."
|
||||||
|
VALUE "FileDescription", "SoundTouch Dynamic Link Library"
|
||||||
|
VALUE "FileVersion", "1, 7, 0, 0"
|
||||||
|
VALUE "InternalName", "SoundTouch"
|
||||||
|
VALUE "LegalCopyright", "Copyright (C) Olli Parviainen 1999-2012"
|
||||||
|
VALUE "OriginalFilename", "SoundTouch.dll"
|
||||||
|
VALUE "ProductName", " SoundTouch Dynamic Link Library"
|
||||||
|
VALUE "ProductVersion", "1, 7, 0, 0"
|
||||||
|
END
|
||||||
|
END
|
||||||
|
BLOCK "VarFileInfo"
|
||||||
|
BEGIN
|
||||||
|
VALUE "Translation", 0x0, 1200
|
||||||
|
END
|
||||||
|
END
|
||||||
|
|
19
media/libsoundtouch/src/soundtouch_config.h
Normal file
19
media/libsoundtouch/src/soundtouch_config.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "mozilla/SSE.h"
|
||||||
|
|
||||||
|
#ifdef MOZ_SAMPLE_TYPE_FLOAT32
|
||||||
|
#define SOUNDTOUCH_FLOAT_SAMPLES 1
|
||||||
|
#else
|
||||||
|
#define SOUNDTOUCH_INTEGER_SAMPLES 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MOZILLA_PRESUME_SSE
|
||||||
|
#ifdef MOZ_SAMPLE_TYPE_FLOAT32
|
||||||
|
#define SOUNDTOUCH_DISABLE_X86_OPTIMIZATIONS 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MOZILLA_PRESUME_MMX
|
||||||
|
#ifdef MOZ_SAMPLE_TYPE_S16LE
|
||||||
|
#define SOUNDTOUCH_DISABLE_X86_OPTIMIZATIONS 1
|
||||||
|
#endif
|
||||||
|
#endif
|
361
media/libsoundtouch/src/sse_optimized.cpp
Normal file
361
media/libsoundtouch/src/sse_optimized.cpp
Normal file
@ -0,0 +1,361 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// SSE optimized routines for Pentium-III, Athlon-XP and later CPUs. All SSE
|
||||||
|
/// optimized functions have been gathered into this single source
|
||||||
|
/// code file, regardless to their class or original source code file, in order
|
||||||
|
/// to ease porting the library to other compiler and processor platforms.
|
||||||
|
///
|
||||||
|
/// The SSE-optimizations are programmed using SSE compiler intrinsics that
|
||||||
|
/// are supported both by Microsoft Visual C++ and GCC compilers, so this file
|
||||||
|
/// should compile with both toolsets.
|
||||||
|
///
|
||||||
|
/// NOTICE: If using Visual Studio 6.0, you'll need to install the "Visual C++
|
||||||
|
/// 6.0 processor pack" update to support SSE instruction set. The update is
|
||||||
|
/// available for download at Microsoft Developers Network, see here:
|
||||||
|
/// http://msdn.microsoft.com/en-us/vstudio/aa718349.aspx
|
||||||
|
///
|
||||||
|
/// If the above URL is expired or removed, go to "http://msdn.microsoft.com" and
|
||||||
|
/// perform a search with keywords "processor pack".
|
||||||
|
///
|
||||||
|
/// Author : Copyright (c) Olli Parviainen
|
||||||
|
/// Author e-mail : oparviai 'at' iki.fi
|
||||||
|
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Last changed : $Date: 2012-04-01 12:49:30 -0700 (Sun, 01 Apr 2012) $
|
||||||
|
// File revision : $Revision: 4 $
|
||||||
|
//
|
||||||
|
// $Id: sse_optimized.cpp 137 2012-04-01 19:49:30Z oparviai $
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// License :
|
||||||
|
//
|
||||||
|
// SoundTouch audio processing library
|
||||||
|
// Copyright (c) Olli Parviainen
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "cpu_detect.h"
|
||||||
|
#include "STTypes.h"
|
||||||
|
|
||||||
|
using namespace soundtouch;
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_ALLOW_SSE
|
||||||
|
|
||||||
|
// SSE routines available only with float sample type
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// implementation of SSE optimized functions of class 'TDStretchSSE'
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "TDStretch.h"
|
||||||
|
#include <xmmintrin.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
// Calculates cross correlation of two buffers
|
||||||
|
double TDStretchSSE::calcCrossCorr(const float *pV1, const float *pV2) const
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
const float *pVec1;
|
||||||
|
const __m128 *pVec2;
|
||||||
|
__m128 vSum, vNorm;
|
||||||
|
|
||||||
|
// Note. It means a major slow-down if the routine needs to tolerate
|
||||||
|
// unaligned __m128 memory accesses. It's way faster if we can skip
|
||||||
|
// unaligned slots and use _mm_load_ps instruction instead of _mm_loadu_ps.
|
||||||
|
// This can mean up to ~ 10-fold difference (incl. part of which is
|
||||||
|
// due to skipping every second round for stereo sound though).
|
||||||
|
//
|
||||||
|
// Compile-time define SOUNDTOUCH_ALLOW_NONEXACT_SIMD_OPTIMIZATION is provided
|
||||||
|
// for choosing if this little cheating is allowed.
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_ALLOW_NONEXACT_SIMD_OPTIMIZATION
|
||||||
|
// Little cheating allowed, return valid correlation only for
|
||||||
|
// aligned locations, meaning every second round for stereo sound.
|
||||||
|
|
||||||
|
#define _MM_LOAD _mm_load_ps
|
||||||
|
|
||||||
|
if (((ulong)pV1) & 15) return -1e50; // skip unaligned locations
|
||||||
|
|
||||||
|
#else
|
||||||
|
// No cheating allowed, use unaligned load & take the resulting
|
||||||
|
// performance hit.
|
||||||
|
#define _MM_LOAD _mm_loadu_ps
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ensure overlapLength is divisible by 8
|
||||||
|
assert((overlapLength % 8) == 0);
|
||||||
|
|
||||||
|
// Calculates the cross-correlation value between 'pV1' and 'pV2' vectors
|
||||||
|
// Note: pV2 _must_ be aligned to 16-bit boundary, pV1 need not.
|
||||||
|
pVec1 = (const float*)pV1;
|
||||||
|
pVec2 = (const __m128*)pV2;
|
||||||
|
vSum = vNorm = _mm_setzero_ps();
|
||||||
|
|
||||||
|
// Unroll the loop by factor of 4 * 4 operations. Use same routine for
|
||||||
|
// stereo & mono, for mono it just means twice the amount of unrolling.
|
||||||
|
for (i = 0; i < channels * overlapLength / 16; i ++)
|
||||||
|
{
|
||||||
|
__m128 vTemp;
|
||||||
|
// vSum += pV1[0..3] * pV2[0..3]
|
||||||
|
vTemp = _MM_LOAD(pVec1);
|
||||||
|
vSum = _mm_add_ps(vSum, _mm_mul_ps(vTemp ,pVec2[0]));
|
||||||
|
vNorm = _mm_add_ps(vNorm, _mm_mul_ps(vTemp ,vTemp));
|
||||||
|
|
||||||
|
// vSum += pV1[4..7] * pV2[4..7]
|
||||||
|
vTemp = _MM_LOAD(pVec1 + 4);
|
||||||
|
vSum = _mm_add_ps(vSum, _mm_mul_ps(vTemp, pVec2[1]));
|
||||||
|
vNorm = _mm_add_ps(vNorm, _mm_mul_ps(vTemp ,vTemp));
|
||||||
|
|
||||||
|
// vSum += pV1[8..11] * pV2[8..11]
|
||||||
|
vTemp = _MM_LOAD(pVec1 + 8);
|
||||||
|
vSum = _mm_add_ps(vSum, _mm_mul_ps(vTemp, pVec2[2]));
|
||||||
|
vNorm = _mm_add_ps(vNorm, _mm_mul_ps(vTemp ,vTemp));
|
||||||
|
|
||||||
|
// vSum += pV1[12..15] * pV2[12..15]
|
||||||
|
vTemp = _MM_LOAD(pVec1 + 12);
|
||||||
|
vSum = _mm_add_ps(vSum, _mm_mul_ps(vTemp, pVec2[3]));
|
||||||
|
vNorm = _mm_add_ps(vNorm, _mm_mul_ps(vTemp ,vTemp));
|
||||||
|
|
||||||
|
pVec1 += 16;
|
||||||
|
pVec2 += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return value = vSum[0] + vSum[1] + vSum[2] + vSum[3]
|
||||||
|
float *pvNorm = (float*)&vNorm;
|
||||||
|
double norm = sqrt(pvNorm[0] + pvNorm[1] + pvNorm[2] + pvNorm[3]);
|
||||||
|
if (norm < 1e-9) norm = 1.0; // to avoid div by zero
|
||||||
|
|
||||||
|
float *pvSum = (float*)&vSum;
|
||||||
|
return (double)(pvSum[0] + pvSum[1] + pvSum[2] + pvSum[3]) / norm;
|
||||||
|
|
||||||
|
/* This is approximately corresponding routine in C-language yet without normalization:
|
||||||
|
double corr, norm;
|
||||||
|
uint i;
|
||||||
|
|
||||||
|
// Calculates the cross-correlation value between 'pV1' and 'pV2' vectors
|
||||||
|
corr = norm = 0.0;
|
||||||
|
for (i = 0; i < channels * overlapLength / 16; i ++)
|
||||||
|
{
|
||||||
|
corr += pV1[0] * pV2[0] +
|
||||||
|
pV1[1] * pV2[1] +
|
||||||
|
pV1[2] * pV2[2] +
|
||||||
|
pV1[3] * pV2[3] +
|
||||||
|
pV1[4] * pV2[4] +
|
||||||
|
pV1[5] * pV2[5] +
|
||||||
|
pV1[6] * pV2[6] +
|
||||||
|
pV1[7] * pV2[7] +
|
||||||
|
pV1[8] * pV2[8] +
|
||||||
|
pV1[9] * pV2[9] +
|
||||||
|
pV1[10] * pV2[10] +
|
||||||
|
pV1[11] * pV2[11] +
|
||||||
|
pV1[12] * pV2[12] +
|
||||||
|
pV1[13] * pV2[13] +
|
||||||
|
pV1[14] * pV2[14] +
|
||||||
|
pV1[15] * pV2[15];
|
||||||
|
|
||||||
|
for (j = 0; j < 15; j ++) norm += pV1[j] * pV1[j];
|
||||||
|
|
||||||
|
pV1 += 16;
|
||||||
|
pV2 += 16;
|
||||||
|
}
|
||||||
|
return corr / sqrt(norm);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// implementation of SSE optimized functions of class 'FIRFilter'
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "FIRFilter.h"
|
||||||
|
|
||||||
|
FIRFilterSSE::FIRFilterSSE() : FIRFilter()
|
||||||
|
{
|
||||||
|
filterCoeffsAlign = NULL;
|
||||||
|
filterCoeffsUnalign = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FIRFilterSSE::~FIRFilterSSE()
|
||||||
|
{
|
||||||
|
delete[] filterCoeffsUnalign;
|
||||||
|
filterCoeffsAlign = NULL;
|
||||||
|
filterCoeffsUnalign = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// (overloaded) Calculates filter coefficients for SSE routine
|
||||||
|
void FIRFilterSSE::setCoefficients(const float *coeffs, uint newLength, uint uResultDivFactor)
|
||||||
|
{
|
||||||
|
uint i;
|
||||||
|
float fDivider;
|
||||||
|
|
||||||
|
FIRFilter::setCoefficients(coeffs, newLength, uResultDivFactor);
|
||||||
|
|
||||||
|
// Scale the filter coefficients so that it won't be necessary to scale the filtering result
|
||||||
|
// also rearrange coefficients suitably for SSE
|
||||||
|
// Ensure that filter coeffs array is aligned to 16-byte boundary
|
||||||
|
delete[] filterCoeffsUnalign;
|
||||||
|
filterCoeffsUnalign = new float[2 * newLength + 4];
|
||||||
|
filterCoeffsAlign = (float *)(((unsigned long)filterCoeffsUnalign + 15) & (ulong)-16);
|
||||||
|
|
||||||
|
fDivider = (float)resultDivider;
|
||||||
|
|
||||||
|
// rearrange the filter coefficients for mmx routines
|
||||||
|
for (i = 0; i < newLength; i ++)
|
||||||
|
{
|
||||||
|
filterCoeffsAlign[2 * i + 0] =
|
||||||
|
filterCoeffsAlign[2 * i + 1] = coeffs[i + 0] / fDivider;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// SSE-optimized version of the filter routine for stereo sound
|
||||||
|
uint FIRFilterSSE::evaluateFilterStereo(float *dest, const float *source, uint numSamples) const
|
||||||
|
{
|
||||||
|
int count = (int)((numSamples - length) & (uint)-2);
|
||||||
|
int j;
|
||||||
|
|
||||||
|
assert(count % 2 == 0);
|
||||||
|
|
||||||
|
if (count < 2) return 0;
|
||||||
|
|
||||||
|
assert(source != NULL);
|
||||||
|
assert(dest != NULL);
|
||||||
|
assert((length % 8) == 0);
|
||||||
|
assert(filterCoeffsAlign != NULL);
|
||||||
|
assert(((ulong)filterCoeffsAlign) % 16 == 0);
|
||||||
|
|
||||||
|
// filter is evaluated for two stereo samples with each iteration, thus use of 'j += 2'
|
||||||
|
for (j = 0; j < count; j += 2)
|
||||||
|
{
|
||||||
|
const float *pSrc;
|
||||||
|
const __m128 *pFil;
|
||||||
|
__m128 sum1, sum2;
|
||||||
|
uint i;
|
||||||
|
|
||||||
|
pSrc = (const float*)source; // source audio data
|
||||||
|
pFil = (const __m128*)filterCoeffsAlign; // filter coefficients. NOTE: Assumes coefficients
|
||||||
|
// are aligned to 16-byte boundary
|
||||||
|
sum1 = sum2 = _mm_setzero_ps();
|
||||||
|
|
||||||
|
for (i = 0; i < length / 8; i ++)
|
||||||
|
{
|
||||||
|
// Unroll loop for efficiency & calculate filter for 2*2 stereo samples
|
||||||
|
// at each pass
|
||||||
|
|
||||||
|
// sum1 is accu for 2*2 filtered stereo sound data at the primary sound data offset
|
||||||
|
// sum2 is accu for 2*2 filtered stereo sound data for the next sound sample offset.
|
||||||
|
|
||||||
|
sum1 = _mm_add_ps(sum1, _mm_mul_ps(_mm_loadu_ps(pSrc) , pFil[0]));
|
||||||
|
sum2 = _mm_add_ps(sum2, _mm_mul_ps(_mm_loadu_ps(pSrc + 2), pFil[0]));
|
||||||
|
|
||||||
|
sum1 = _mm_add_ps(sum1, _mm_mul_ps(_mm_loadu_ps(pSrc + 4), pFil[1]));
|
||||||
|
sum2 = _mm_add_ps(sum2, _mm_mul_ps(_mm_loadu_ps(pSrc + 6), pFil[1]));
|
||||||
|
|
||||||
|
sum1 = _mm_add_ps(sum1, _mm_mul_ps(_mm_loadu_ps(pSrc + 8) , pFil[2]));
|
||||||
|
sum2 = _mm_add_ps(sum2, _mm_mul_ps(_mm_loadu_ps(pSrc + 10), pFil[2]));
|
||||||
|
|
||||||
|
sum1 = _mm_add_ps(sum1, _mm_mul_ps(_mm_loadu_ps(pSrc + 12), pFil[3]));
|
||||||
|
sum2 = _mm_add_ps(sum2, _mm_mul_ps(_mm_loadu_ps(pSrc + 14), pFil[3]));
|
||||||
|
|
||||||
|
pSrc += 16;
|
||||||
|
pFil += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now sum1 and sum2 both have a filtered 2-channel sample each, but we still need
|
||||||
|
// to sum the two hi- and lo-floats of these registers together.
|
||||||
|
|
||||||
|
// post-shuffle & add the filtered values and store to dest.
|
||||||
|
_mm_storeu_ps(dest, _mm_add_ps(
|
||||||
|
_mm_shuffle_ps(sum1, sum2, _MM_SHUFFLE(1,0,3,2)), // s2_1 s2_0 s1_3 s1_2
|
||||||
|
_mm_shuffle_ps(sum1, sum2, _MM_SHUFFLE(3,2,1,0)) // s2_3 s2_2 s1_1 s1_0
|
||||||
|
));
|
||||||
|
source += 4;
|
||||||
|
dest += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ideas for further improvement:
|
||||||
|
// 1. If it could be guaranteed that 'source' were always aligned to 16-byte
|
||||||
|
// boundary, a faster aligned '_mm_load_ps' instruction could be used.
|
||||||
|
// 2. If it could be guaranteed that 'dest' were always aligned to 16-byte
|
||||||
|
// boundary, a faster '_mm_store_ps' instruction could be used.
|
||||||
|
|
||||||
|
return (uint)count;
|
||||||
|
|
||||||
|
/* original routine in C-language. please notice the C-version has differently
|
||||||
|
organized coefficients though.
|
||||||
|
double suml1, suml2;
|
||||||
|
double sumr1, sumr2;
|
||||||
|
uint i, j;
|
||||||
|
|
||||||
|
for (j = 0; j < count; j += 2)
|
||||||
|
{
|
||||||
|
const float *ptr;
|
||||||
|
const float *pFil;
|
||||||
|
|
||||||
|
suml1 = sumr1 = 0.0;
|
||||||
|
suml2 = sumr2 = 0.0;
|
||||||
|
ptr = src;
|
||||||
|
pFil = filterCoeffs;
|
||||||
|
for (i = 0; i < lengthLocal; i ++)
|
||||||
|
{
|
||||||
|
// unroll loop for efficiency.
|
||||||
|
|
||||||
|
suml1 += ptr[0] * pFil[0] +
|
||||||
|
ptr[2] * pFil[2] +
|
||||||
|
ptr[4] * pFil[4] +
|
||||||
|
ptr[6] * pFil[6];
|
||||||
|
|
||||||
|
sumr1 += ptr[1] * pFil[1] +
|
||||||
|
ptr[3] * pFil[3] +
|
||||||
|
ptr[5] * pFil[5] +
|
||||||
|
ptr[7] * pFil[7];
|
||||||
|
|
||||||
|
suml2 += ptr[8] * pFil[0] +
|
||||||
|
ptr[10] * pFil[2] +
|
||||||
|
ptr[12] * pFil[4] +
|
||||||
|
ptr[14] * pFil[6];
|
||||||
|
|
||||||
|
sumr2 += ptr[9] * pFil[1] +
|
||||||
|
ptr[11] * pFil[3] +
|
||||||
|
ptr[13] * pFil[5] +
|
||||||
|
ptr[15] * pFil[7];
|
||||||
|
|
||||||
|
ptr += 16;
|
||||||
|
pFil += 8;
|
||||||
|
}
|
||||||
|
dest[0] = (float)suml1;
|
||||||
|
dest[1] = (float)sumr1;
|
||||||
|
dest[2] = (float)suml2;
|
||||||
|
dest[3] = (float)sumr2;
|
||||||
|
|
||||||
|
src += 4;
|
||||||
|
dest += 4;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SOUNDTOUCH_ALLOW_SSE
|
40
media/libsoundtouch/update.sh
Normal file
40
media/libsoundtouch/update.sh
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
# Usage: ./update.sh <SoundTouch_src_directory>
|
||||||
|
#
|
||||||
|
# Copies the needed files from a directory containing the original
|
||||||
|
# soundtouch sources that we need for HTML5 media playback rate change.
|
||||||
|
|
||||||
|
cp $1/COPYING.TXT .
|
||||||
|
cp $1/source/SoundTouch/AAFilter.cpp src
|
||||||
|
cp $1/source/SoundTouch/AAFilter.h src
|
||||||
|
cp $1/source/SoundTouch/cpu_detect.h src
|
||||||
|
cp $1/source/SoundTouch/cpu_detect_x86.cpp src
|
||||||
|
cp $1/source/SoundTouch/FIFOSampleBuffer.cpp src
|
||||||
|
cp $1/source/SoundTouch/FIRFilter.cpp src
|
||||||
|
cp $1/source/SoundTouch/FIRFilter.h src
|
||||||
|
cp $1/source/SoundTouch/mmx_optimized.cpp src
|
||||||
|
cp $1/source/SoundTouch/RateTransposer.cpp src
|
||||||
|
cp $1/source/SoundTouch/RateTransposer.h src
|
||||||
|
cp $1/source/SoundTouch/SoundTouch.cpp src
|
||||||
|
cp $1/source/SoundTouch/sse_optimized.cpp src
|
||||||
|
cp $1/source/SoundTouch/TDStretch.cpp src
|
||||||
|
cp $1/source/SoundTouch/TDStretch.h src
|
||||||
|
cp $1/include/SoundTouch.h src
|
||||||
|
cp $1/include/FIFOSampleBuffer.h src
|
||||||
|
cp $1/include/FIFOSamplePipe.h src
|
||||||
|
cp $1/include/SoundTouch.h src
|
||||||
|
cp $1/include/STTypes.h src
|
||||||
|
|
||||||
|
# Remote the Windows line ending characters from the files.
|
||||||
|
for i in src/*
|
||||||
|
do
|
||||||
|
cat $i | tr -d '\015' > $i.lf
|
||||||
|
mv $i.lf $i
|
||||||
|
done
|
||||||
|
|
||||||
|
# Patch the imported files.
|
||||||
|
patch -p1 < moz-libsoundtouch.patch
|
||||||
|
|
@ -40,6 +40,7 @@
|
|||||||
@BINPATH@/@DLL_PREFIX@xpcom@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@xpcom@DLL_SUFFIX@
|
||||||
@BINPATH@/@DLL_PREFIX@nspr4@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@nspr4@DLL_SUFFIX@
|
||||||
@BINPATH@/@DLL_PREFIX@mozalloc@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@mozalloc@DLL_SUFFIX@
|
||||||
|
@BINPATH@/@DLL_PREFIX@soundtouch@DLL_SUFFIX@
|
||||||
@BINPATH@/@DLL_PREFIX@mozglue@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@mozglue@DLL_SUFFIX@
|
||||||
@BINPATH@/@DLL_PREFIX@omxplugin@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@omxplugin@DLL_SUFFIX@
|
||||||
@BINPATH@/@DLL_PREFIX@xul@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@xul@DLL_SUFFIX@
|
||||||
|
@ -51,6 +51,7 @@
|
|||||||
@BINPATH@/@DLL_PREFIX@xpcom@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@xpcom@DLL_SUFFIX@
|
||||||
@BINPATH@/@DLL_PREFIX@nspr4@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@nspr4@DLL_SUFFIX@
|
||||||
@BINPATH@/@DLL_PREFIX@mozalloc@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@mozalloc@DLL_SUFFIX@
|
||||||
|
@BINPATH@/@DLL_PREFIX@soundtouch@DLL_SUFFIX@
|
||||||
@BINPATH@/@DLL_PREFIX@mozglue@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@mozglue@DLL_SUFFIX@
|
||||||
@BINPATH@/@DLL_PREFIX@omxplugin@DLL_SUFFIX@
|
@BINPATH@/@DLL_PREFIX@omxplugin@DLL_SUFFIX@
|
||||||
#ifdef XP_MACOSX
|
#ifdef XP_MACOSX
|
||||||
|
@ -87,6 +87,7 @@
|
|||||||
<li><a href="about:license#libffi">libffi License</a></li>
|
<li><a href="about:license#libffi">libffi License</a></li>
|
||||||
<li><a href="about:license#libjingle">libjingle License</a></li>
|
<li><a href="about:license#libjingle">libjingle License</a></li>
|
||||||
<li><a href="about:license#libnestegg">libnestegg License</a></li>
|
<li><a href="about:license#libnestegg">libnestegg License</a></li>
|
||||||
|
<li><a href="about:license#libsoundtouch">libsoundtouch License</a></li>
|
||||||
<li><a href="about:license#libsrtp">libsrtp License</a></li>
|
<li><a href="about:license#libsrtp">libsrtp License</a></li>
|
||||||
<li><a href="about:license#libunwind">libunwind License</a></li>
|
<li><a href="about:license#libunwind">libunwind License</a></li>
|
||||||
<li><a href="about:license#libyuv">libyuv License</a></li>
|
<li><a href="about:license#libyuv">libyuv License</a></li>
|
||||||
@ -1967,6 +1968,32 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
<h1><a id="libsoundtouch"></a>libsoundtouch License</h1>
|
||||||
|
|
||||||
|
<p>This license applies to certain files in the directory
|
||||||
|
<span class="path">media/libsoundtouch/src/</span>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
The SoundTouch Library Copyright © Olli Parviainen 2001-2012
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
<h1><a id="libsrtp"></a>libsrtp License</h1>
|
<h1><a id="libsrtp"></a>libsrtp License</h1>
|
||||||
|
|
||||||
<p>This license applies to files in the directory
|
<p>This license applies to files in the directory
|
||||||
|
@ -358,6 +358,7 @@ EXTRA_DSO_LDOPTS += \
|
|||||||
$(MOZ_CAIRO_OSLIBS) \
|
$(MOZ_CAIRO_OSLIBS) \
|
||||||
$(MOZ_APP_EXTRA_LIBS) \
|
$(MOZ_APP_EXTRA_LIBS) \
|
||||||
$(SQLITE_LIBS) \
|
$(SQLITE_LIBS) \
|
||||||
|
$(SOUNDTOUCH_LIBS) \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
ifdef MOZ_NATIVE_JPEG
|
ifdef MOZ_NATIVE_JPEG
|
||||||
|
@ -262,6 +262,7 @@ DIST_FILES += \
|
|||||||
libplc4.so \
|
libplc4.so \
|
||||||
libplds4.so \
|
libplds4.so \
|
||||||
libmozsqlite3.so \
|
libmozsqlite3.so \
|
||||||
|
libsoundtouch.so \
|
||||||
libnssutil3.so \
|
libnssutil3.so \
|
||||||
libnss3.so \
|
libnss3.so \
|
||||||
libssl3.so \
|
libssl3.so \
|
||||||
|
@ -1737,3 +1737,11 @@ if [ "$MOZ_SPEEX_RESAMPLER" ]; then
|
|||||||
media/libspeex_resampler/src/Makefile
|
media/libspeex_resampler/src/Makefile
|
||||||
"
|
"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$MOZ_SOUNDTOUCH" ]; then
|
||||||
|
add_makefiles "
|
||||||
|
media/libsoundtouch/Makefile
|
||||||
|
media/libsoundtouch/src/Makefile
|
||||||
|
"
|
||||||
|
fi
|
||||||
|
|
||||||
|
@ -151,6 +151,12 @@ tier_platform_dirs += \
|
|||||||
$(NULL)
|
$(NULL)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifdef MOZ_SOUNDTOUCH
|
||||||
|
tier_platform_dirs += \
|
||||||
|
media/libsoundtouch \
|
||||||
|
$(NULL)
|
||||||
|
endif
|
||||||
|
|
||||||
ifdef MOZ_CUBEB
|
ifdef MOZ_CUBEB
|
||||||
tier_platform_dirs += \
|
tier_platform_dirs += \
|
||||||
media/libcubeb \
|
media/libcubeb \
|
||||||
|
Loading…
Reference in New Issue
Block a user