summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2019-11-03 15:36:47 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2019-11-03 15:36:47 +0100
commit76288efeead86fd5799d9771e50bf3222aaa8e71 (patch)
tree5a30f504041907fd60379138619a0c3aeff1839f
Import from zita-resampler-1.6.0.tar.bz2HEADmaster
-rw-r--r--AUTHORS1
-rw-r--r--COPYING674
-rw-r--r--INSTALL31
-rw-r--r--README45
-rw-r--r--apps/Makefile73
-rw-r--r--apps/audiofile.cc326
-rw-r--r--apps/audiofile.h137
-rw-r--r--apps/dither.cc127
-rw-r--r--apps/dither.h59
-rw-r--r--apps/zresample.190
-rw-r--r--apps/zresample.cc302
-rw-r--r--apps/zretune.179
-rw-r--r--apps/zretune.cc265
-rw-r--r--docs/filt1.pngbin0 -> 9528 bytes
-rw-r--r--docs/filt2.pngbin0 -> 3117 bytes
-rw-r--r--docs/inpdist.pngbin0 -> 14940 bytes
-rw-r--r--docs/resampler.html574
-rw-r--r--docs/src-1kHz.pngbin0 -> 34429 bytes
-rw-r--r--docs/zita-1kHz.pngbin0 -> 34459 bytes
-rw-r--r--docs/zitadocs.css18
-rw-r--r--libs/Makefile69
-rw-r--r--libs/Makefile-linux69
-rw-r--r--libs/Makefile-osx74
-rw-r--r--libs/cresampler.cc192
-rw-r--r--libs/resampler-table.cc161
-rw-r--r--libs/resampler.cc263
-rw-r--r--libs/vresampler.cc272
-rw-r--r--libs/zita-resampler/cresampler.h65
-rw-r--r--libs/zita-resampler/resampler-table.h80
-rw-r--r--libs/zita-resampler/resampler.h76
-rw-r--r--libs/zita-resampler/vresampler.h84
31 files changed, 4206 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..7ae6190
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Fons Adriaensen <fons@linuxaudio.org>
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..b71e6fa
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,31 @@
+Dependencies
+------------
+
+The zita-resampler library does not depend on any
+non-standard libraries.
+
+The 'zresample' and 'zretune' application depend on libsndfile
+and the corresponding headers.
+
+Installing the library
+----------------------
+
+To make and install the library, cd to the libs directory,
+make, sudo make install. This will install the lib and
+header file in /usr/lib and /usr/include. To install in
+any other directory, modify the definition of 'PREFIX' in
+the Makefile.
+After the install you can do a 'make clean' to return the
+libs directory to its original state.
+
+
+Installing the application(s)
+----------------------------
+
+To make and install the application(s), you first need to
+make and install the library. Then cd to the apps directory,
+make, sudo make install. This will install the apps in
+/usr/local/bin. To install in other any directory, modify
+the definition of 'PREFIX' in the Makefile.
+After the install you can do a 'make clean' to return the
+apps directory to its original state.
diff --git a/README b/README
new file mode 100644
index 0000000..c2cde14
--- /dev/null
+++ b/README
@@ -0,0 +1,45 @@
+Zita-resampler is a C++ library for sample rate conversion of
+audio signals. Full documentation is available in HTML format,
+see the 'docs' directory.
+
+
+Release 1.6.0 (16/10/2016)
+---------------------------
+
+* Added VResampler::set_phase ().
+
+
+Release 1.2.0 (25/09/2012)
+---------------------------
+
+* Added the zretune application and its manpage.
+
+
+Release 1.1.0 (26/01/2012)
+---------------------------
+
+* VResampler class added - provides arbitrary and variable
+ resampling ratio, see docs.
+
+* This release is NOT binary compatible with previous ones
+ (0.x.x) and requires recompilation of applications using it.
+
+* This release is API compatible with the previous one. But if
+ you are using the now deprecated filtlen() function please
+ replace this by inpsize() which provides the same information.
+
+* The inpdist() function has been added, see docs.
+
+* The ratio_a() and ratio_b() calls have been removed, if this
+ is a problem (I'd be surprised) they can be added again.
+
+* The include files are now in $PREFIX/include/zita-resampler/.
+ Please DO remove any old ones manually after installing this
+ version. Compiling using the old includes and linking with
+ the new library will create havoc.
+
+* #defines and static functions are added for compile time and
+ run time version checking, see resampler-table.h.
+
+--
+FA
diff --git a/apps/Makefile b/apps/Makefile
new file mode 100644
index 0000000..f009937
--- /dev/null
+++ b/apps/Makefile
@@ -0,0 +1,73 @@
+# ----------------------------------------------------------------------------
+#
+# Copyright (C) 2006-2011 Fons Adriaensen <fons@linuxaudio.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http:#www.gnu.org/licenses/>.
+#
+# ----------------------------------------------------------------------------
+
+
+PREFIX = /usr/local
+SUFFIX := $(shell uname -m | sed -e 's/^unknown/$//' -e 's/^i.86/$//' -e 's/^x86_64/$/64/')
+LIBDIR = lib$(SUFFIX)
+DISTDIR = zresample-$(VERSION)
+VERSION = 1.6.0
+MANDIR = /usr/share/man/man1
+LDFLAGS += -L$(PREFIX)/$(LIBDIR)
+CPPFLAGS += -MMD -MP -DVERSION=\"$(VERSION)\"
+CXXFLAGS += -O3 -ffast-math -Wall
+CXXFLAGS += -march=native
+
+
+all: zresample zretune zresample.1.gz zretune.1.gz
+
+
+ZRESAMPLE_O = zresample.o audiofile.o dither.o
+zresample: LDLIBS += -lzita-resampler -lsndfile -lrt
+zresample: $(ZRESAMPLE_O)
+ g++ $(LDFLAGS) -o $@ $(ZRESAMPLE_O) $(LDLIBS)
+$(ZRESAMPLE_O):
+-include $(ZRESAMPLE_O:%.o=%.d)
+
+
+ZRETUNE_O = zretune.o audiofile.o dither.o
+zretune: LDLIBS += -lzita-resampler -lsndfile -lrt
+zretune: $(ZRETUNE_O)
+ g++ $(LDFLAGS) -o $@ $(ZRETUNE_O) $(LDLIBS)
+$(ZRETUNE_O):
+-include $(ZRETUNE_O:%.o=%.d)
+
+
+zresample.1.gz: zresample.1
+ gzip -c zresample.1 > zresample.1.gz
+
+zretune.1.gz: zretune.1
+ gzip -c zretune.1 > zretune.1.gz
+
+
+install: all
+ install -Dm 755 zresample $(DESTDIR)$(PREFIX)/bin/zresample
+ install -Dm 755 zretune $(DESTDIR)$(PREFIX)/bin/zretune
+ install -Dm 644 zresample.1.gz $(DESTDIR)$(MANDIR)/zresample.1.gz
+ install -Dm 644 zretune.1.gz $(DESTDIR)$(MANDIR)/zretune.1.gz
+
+uninstall:
+ /bin/rm -f $(DESTDIR)$(PREFIX)/bin/zresample
+ /bin/rm -f $(DESTDIR)$(PREFIX)/bin/zretune
+ /bin/rm -f $(MANDIR)/zresample.1.gz
+ /bin/rm -f $(MANDIR)/zretune.1.gz
+
+clean:
+ /bin/rm -f *~ *.o *.a *.d *.so *.gz zresample zretune
+
diff --git a/apps/audiofile.cc b/apps/audiofile.cc
new file mode 100644
index 0000000..ecf124b
--- /dev/null
+++ b/apps/audiofile.cc
@@ -0,0 +1,326 @@
+// -------------------------------------------------------------------------
+//
+// Copyright (C) 2009-2014 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+// -------------------------------------------------------------------------
+
+
+#include <stdlib.h>
+#include <string.h>
+#include "audiofile.h"
+
+
+const char *Audiofile::_typestr [] = { "other", "caf", "wav", "amb", "aiff", "flac" };
+const char *Audiofile::_formstr [] = { "other", "16bit", "24bit", "32bit", "float" };
+const char *Audiofile::_dithstr [] = { "none", "rect", "tri", "lips" };
+
+
+
+Audiofile::Audiofile (void) :
+ _sndfile (0),
+ _dith_proc (0),
+ _dith_buff (0),
+ _data_buff (0)
+{
+ clear ();
+}
+
+
+Audiofile::~Audiofile (void)
+{
+ close ();
+}
+
+
+int Audiofile::enc_type (const char *s)
+{
+ for (int i = 1; i < 6; i++) if (!strcmp (s, _typestr [i])) return i;
+ return -1;
+}
+
+
+int Audiofile::enc_form (const char *s)
+{
+ for (int i = 1; i < 5; i++) if (!strcmp (s, _formstr [i])) return i;
+ return -1;
+}
+
+
+int Audiofile::enc_dith (const char *s)
+{
+ for (int i = 0; i < 4; i++) if (!strcmp (s, _dithstr [i])) return i;
+ return -1;
+}
+
+
+void Audiofile::clear (void)
+{
+ _mode = MODE_NONE;
+ _type = TYPE_OTHER;
+ _form = FORM_OTHER;
+ _rate = 0;
+ _chan = 0;
+ _size = 0;
+ _dith_type = 0;
+ delete[] _dith_proc;
+ delete[] _dith_buff;
+ delete[] _data_buff;
+ _dith_proc = 0;
+ _dith_buff = 0;
+ _data_buff = 0;
+}
+
+
+int Audiofile::open_read (const char *name)
+{
+ SF_INFO I;
+
+ if (_mode) return ERR_MODE;
+ if ((_sndfile = sf_open (name, SFM_READ, &I)) == 0) return ERR_OPEN;
+
+ _mode = MODE_READ;
+ switch (I.format & SF_FORMAT_TYPEMASK)
+ {
+ case SF_FORMAT_CAF:
+ _type = TYPE_CAF;
+ break;
+ case SF_FORMAT_WAV:
+ _type = TYPE_WAV;
+ break;
+ case SF_FORMAT_WAVEX:
+ if (sf_command (_sndfile, SFC_WAVEX_GET_AMBISONIC, 0, 0) == SF_AMBISONIC_B_FORMAT)
+ _type = TYPE_AMB;
+ else
+ _type = TYPE_WAV;
+ break;
+ case SF_FORMAT_AIFF:
+ _type = TYPE_AIFF;
+ break;
+ case SF_FORMAT_FLAC:
+ _type = TYPE_FLAC;
+ break;
+ default:
+ _type = TYPE_OTHER;
+ }
+ switch (I.format & SF_FORMAT_SUBMASK)
+ {
+ case SF_FORMAT_PCM_16:
+ _form = FORM_16BIT;
+ break;
+ case SF_FORMAT_PCM_24:
+ _form = FORM_24BIT;
+ break;
+ case SF_FORMAT_PCM_32:
+ _form = FORM_32BIT;
+ break;
+ case SF_FORMAT_FLOAT:
+ _form = FORM_FLOAT;
+ break;
+ default:
+ _form = FORM_OTHER;
+ }
+ _rate = I.samplerate;
+ _chan = I.channels;
+ _size = I.frames;
+
+ return 0;
+}
+
+
+int Audiofile::open_write (const char *name, int type, int form, int rate, int chan)
+{
+ SF_INFO I;
+
+ if (_mode) return ERR_MODE;
+ if ((rate < 1) || (chan < 1)) return ERR_OPEN;
+
+ switch (type)
+ {
+ case TYPE_CAF:
+ I.format = SF_FORMAT_CAF;
+ break;
+ case TYPE_WAV:
+ case TYPE_AMB:
+ I.format = (chan > 2) ? SF_FORMAT_WAVEX : SF_FORMAT_WAV;
+ break;
+ case TYPE_AIFF:
+ I.format = SF_FORMAT_AIFF;
+ break;
+ case TYPE_FLAC:
+ I.format = SF_FORMAT_FLAC;
+ break;
+ default:
+ return ERR_TYPE;
+ }
+ switch (form)
+ {
+ case FORM_16BIT:
+ I.format |= SF_FORMAT_PCM_16;
+ break;
+ case FORM_24BIT:
+ I.format |= SF_FORMAT_PCM_24;
+ break;
+ case FORM_32BIT:
+ I.format |= SF_FORMAT_PCM_32;
+ break;
+ case FORM_FLOAT:
+ I.format |= SF_FORMAT_FLOAT;
+ break;
+ default:
+ return ERR_FORM;
+ }
+ I.samplerate = rate;
+ I.channels = chan;
+ I.sections = 1;
+ if ((_sndfile = sf_open (name, SFM_WRITE, &I)) == 0) return ERR_OPEN;
+ if (type == TYPE_AMB)
+ {
+ sf_command (_sndfile, SFC_WAVEX_SET_AMBISONIC, 0, SF_AMBISONIC_B_FORMAT);
+ }
+
+ _mode = MODE_WRITE;
+ _type = type;
+ _form = form;
+ _rate = rate;
+ _chan = chan;
+
+ return 0;
+}
+
+
+float *Audiofile::get_buffer (void)
+{
+ if (_mode == MODE_NONE) return 0;
+ if (_data_buff == 0) _data_buff = new float [_chan * BUFFSIZE];
+ return _data_buff;
+}
+
+
+int Audiofile::set_dither (int type)
+{
+ if (_mode != MODE_WRITE) return ERR_MODE;
+ if (_form != FORM_16BIT) return ERR_FORM;
+ if (type == DITHER_NONE)
+ {
+ delete[] _dith_proc;
+ delete[] _dith_buff;
+ _dith_proc = 0;
+ _dith_buff = 0;
+ }
+ else if (_dith_type == DITHER_NONE)
+ {
+ _dith_proc = new Dither [_chan];
+ _dith_buff = new int16_t [_chan * BUFFSIZE];
+ }
+ _dith_type = type;
+ return 0;
+}
+
+
+int Audiofile::close (void)
+{
+ if (_sndfile)
+ {
+ sf_close (_sndfile);
+ _sndfile = 0;
+ }
+ clear ();
+ return 0;
+}
+
+
+int64_t Audiofile::seek (int64_t posit, int mode)
+{
+ if (!_sndfile) return ERR_MODE;
+ if (sf_seek (_sndfile, posit, mode) != posit) return ERR_SEEK;
+ return 0;
+}
+
+
+int Audiofile::read (float *data, uint64_t frames)
+{
+ if (_mode != MODE_READ) return ERR_MODE;
+ return sf_readf_float (_sndfile, data, frames);
+}
+
+
+int Audiofile::write (float *data, uint64_t frames)
+{
+ int i;
+ uint32_t k, n, r;
+ float *p, v;
+ int16_t *q;
+ Dither *D;
+
+ if (_mode != MODE_WRITE) return ERR_MODE;
+ if (_dith_type == DITHER_NONE)
+ {
+ if (_form != FORM_FLOAT)
+ {
+ for (i = 0; i < _chan; i++)
+ {
+ p = data + i;
+ for (k = 0; k < frames; k++)
+ {
+ v = *p;
+ if (v > 1.0f) v = 1.0f;
+ else if (v < -1.0f) v = -1.0f;
+ *p = v;
+ p += _chan;
+ }
+ }
+ }
+ return sf_writef_float (_sndfile, data, frames);
+ }
+ else
+ {
+ n = 0;
+ while (frames)
+ {
+ k = (frames > BUFFSIZE) ? BUFFSIZE : frames;
+ p = data;
+ q = _dith_buff;
+ D = _dith_proc;
+ for (i = 0; i < _chan; i++)
+ {
+ switch (_dith_type)
+ {
+ case DITHER_RECT:
+ D->proc_rectangular (k, p, q, _chan, _chan);
+ break;
+ case DITHER_TRIA:
+ D->proc_triangular (k, p, q, _chan, _chan);
+ break;
+ case DITHER_LIPS:
+ D->proc_lipschitz (k, p, q, _chan, _chan);
+ break;
+ }
+ p++;
+ q++;
+ D++;
+ }
+ r = sf_writef_short (_sndfile, _dith_buff, k);
+ n += r;
+ if (r != k) return n;
+ data += k * _chan;
+ frames -= k;
+ }
+ }
+ return 0;
+}
+
+
diff --git a/apps/audiofile.h b/apps/audiofile.h
new file mode 100644
index 0000000..aaf7ec0
--- /dev/null
+++ b/apps/audiofile.h
@@ -0,0 +1,137 @@
+// -------------------------------------------------------------------------
+//
+// Copyright (C) 2009-2014 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+// -------------------------------------------------------------------------
+
+
+#ifndef __AUDIOFILE_H
+#define __AUDIOFILE_H
+
+
+#include <stdio.h>
+#include <stdint.h>
+#include <sndfile.h>
+#include "dither.h"
+
+
+class Audiofile
+{
+public:
+
+ enum
+ {
+ MODE_NONE,
+ MODE_READ,
+ MODE_WRITE
+ };
+
+ enum
+ {
+ TYPE_OTHER,
+ TYPE_CAF,
+ TYPE_WAV,
+ TYPE_AMB,
+ TYPE_AIFF,
+ TYPE_FLAC
+ };
+
+ enum
+ {
+ FORM_OTHER,
+ FORM_16BIT,
+ FORM_24BIT,
+ FORM_32BIT,
+ FORM_FLOAT,
+ };
+
+ enum
+ {
+ DITHER_NONE,
+ DITHER_RECT,
+ DITHER_TRIA,
+ DITHER_LIPS,
+ };
+
+ enum
+ {
+ ERR_NONE = 0,
+ ERR_MODE = -1,
+ ERR_TYPE = -2,
+ ERR_FORM = -3,
+ ERR_OPEN = -4,
+ ERR_SEEK = -5,
+ ERR_DATA = -6,
+ ERR_READ = -7,
+ ERR_WRITE = -8
+ };
+
+ enum { BUFFSIZE = 1024 };
+
+ Audiofile (void);
+ ~Audiofile (void);
+
+ int mode (void) const { return _mode; }
+ int type (void) const { return _type; }
+ int form (void) const { return _form; }
+ int rate (void) const { return _rate; }
+ int chan (void) const { return _chan; }
+ uint64_t size (void) const { return _size; }
+
+ const char *typestr (void) const { return _typestr [_type]; }
+ const char *formstr (void) const { return _formstr [_form]; }
+ const char *dithstr (void) const { return _dithstr [_dith_type]; }
+
+ int enc_type (const char *s);
+ int enc_form (const char *s);
+ int enc_dith (const char *s);
+
+ int open_read (const char *name);
+ int open_write (const char *name, int type, int form, int rate, int chan);
+ int close (void);
+ int set_dither (int type);
+ float *get_buffer (void);
+
+ int64_t seek (int64_t posit, int mode = SEEK_SET);
+ int read (float *data, uint64_t frames);
+ int write (float *data, uint64_t frames);
+
+
+private:
+
+ void clear (void);
+
+ SNDFILE *_sndfile;
+ int _mode;
+ int _type;
+ int _form;
+ int _rate;
+ int _chan;
+ uint64_t _size;
+ int _dith_type;
+ Dither *_dith_proc;
+ int16_t *_dith_buff;
+ float *_data_buff;
+
+ static const char *_typestr [];
+ static const char *_formstr [];
+ static const char *_dithstr [];
+};
+
+
+#endif
+
diff --git a/apps/dither.cc b/apps/dither.cc
new file mode 100644
index 0000000..c85b296
--- /dev/null
+++ b/apps/dither.cc
@@ -0,0 +1,127 @@
+// -------------------------------------------------------------------------
+//
+// Copyright (C) 2010-2014 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+// -------------------------------------------------------------------------
+
+
+#include <string.h>
+#include <math.h>
+#include "dither.h"
+
+
+float Dither::_div = 0;
+
+#define SCALE 32768.0f
+#define LIMIT 32767
+
+
+
+Dither::Dither (void)
+{
+ reset ();
+ _div = ldexpf (1.0f, 32);
+}
+
+
+void Dither::reset (void)
+{
+ memset (_err, 0, (SIZE + 4) * sizeof(float));
+ _ind = SIZE - 1;
+ _ran = 1234567;
+}
+
+
+void Dither::proc_rectangular (int nsam, const float *srce, int16_t *dest, int ds, int dd)
+{
+ float v, r;
+ int16_t k;
+
+ while (nsam--)
+ {
+ r = genrand () - 0.5f;
+ v = *srce * SCALE + r;
+ k = lrintf (v);
+ if (k < -LIMIT) k = -LIMIT;
+ else if (k > LIMIT) k = LIMIT;
+ *dest = k;
+ srce += ds;
+ dest += dd;
+ }
+}
+
+
+void Dither::proc_triangular (int nsam, const float *srce, int16_t *dest, int ds, int dd)
+{
+ float v, r0, r1;
+ int16_t k;
+
+ r1 = *_err;
+ while (nsam--)
+ {
+ r0 = genrand ();
+ v = *srce * SCALE + r0 - r1;
+ r1 = r0;
+ k = lrintf (v);
+ if (k < -LIMIT) k = -LIMIT;
+ else if (k > LIMIT) k = LIMIT;
+ *dest = k;
+ srce += ds;
+ dest += dd;
+ }
+ *_err = r1;
+}
+
+
+void Dither::proc_lipschitz (int nsam, const float *srce, int16_t *dest, int ds, int dd)
+{
+ float e, u, v, *p;
+ int i;
+ int16_t k;
+
+ i = _ind;
+ while (nsam--)
+ {
+ p = _err + i;
+ u = *srce * SCALE
+ - 2.033f * p [0]
+ + 2.165f * p [1]
+ - 1.959f * p [2]
+ + 1.590f * p [3]
+ - 0.615f * p [4];
+ v = u + genrand () - genrand ();
+ k = lrintf (v);
+ e = k - u;
+ if (k < -LIMIT) k = -LIMIT;
+ else if (k > LIMIT) k = LIMIT;
+ *dest = k;
+ if (--i < 0)
+ {
+ _err [SIZE + 0] = _err [0];
+ _err [SIZE + 1] = _err [1];
+ _err [SIZE + 2] = _err [2];
+ _err [SIZE + 3] = _err [3];
+ i += SIZE;
+ }
+ _err [i] = e;
+ srce += ds;
+ dest += dd;
+ }
+ _ind = i;
+}
+
+
diff --git a/apps/dither.h b/apps/dither.h
new file mode 100644
index 0000000..d03ca8c
--- /dev/null
+++ b/apps/dither.h
@@ -0,0 +1,59 @@
+// -------------------------------------------------------------------------
+//
+// Copyright (C) 2010-2014 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+// -------------------------------------------------------------------------
+
+
+#ifndef __DITHER_H
+#define __DITHER_H
+
+
+#include <stdint.h>
+
+
+class Dither
+{
+public:
+
+ Dither (void);
+ void reset (void);
+ void proc_rectangular (int nsam, const float *srce, int16_t *dest, int ds, int dd);
+ void proc_triangular (int nsam, const float *srce, int16_t *dest, int ds, int dd);
+ void proc_lipschitz (int nsam, const float *srce, int16_t *dest, int ds, int dd);
+
+private:
+
+ enum { SIZE = 64 };
+
+ float genrand (void)
+ {
+ _ran *= 1103515245;
+ _ran += 12345;
+ return _ran / _div;
+ }
+
+ float _err [SIZE + 4];
+ int _ind;
+ uint32_t _ran;
+
+ static float _div;
+};
+
+
+#endif
+
diff --git a/apps/zresample.1 b/apps/zresample.1
new file mode 100644
index 0000000..70cc7cf
--- /dev/null
+++ b/apps/zresample.1
@@ -0,0 +1,90 @@
+.TH zresample 1 "May 2010" "version 0.0.1" "USER COMMANDS"
+.SH NAME
+zresample \- resample and change sample format of audio files
+.SH SYNOPSIS
+.B zresample
+[options] input-file output-file
+.SH DESCRIPTION
+.B zresample
+copies an audio file, changing the sample rate and/or the
+sample format. For 16-bit output it can also dither the
+audio signal. Input can be any audio file readable by the
+libsndfile library. The output file type is either WAV, WAVEX,
+CAF, AIFF or FLAC.
+.SH OPTIONS
+.TP
+.B --help
+Display a short help text.
+.TP
+.B --rate sample-rate
+Set the output sample rate.
+.B Zresample
+uses the zita-resampler library which means that not all
+combinations of input/output sample rate will be accepted.
+The resample ratio must be a reducable to a fraction
+.B a/b
+with both
+.B a
+and
+.B b
+less than or equal to 1000.
+.TP
+.B --gain gain
+Gain in dB, default zero.
+.SS Output file type
+.TP
+.B --wav
+Produce a WAV file, or for more than 2 channels, a WAVEX file.
+This is the default.
+.TP
+.B --amb
+Produce a WAVEX file with the Ambisonic GUID. Such files should
+have the
+.B .amb
+filename extension.
+.TP
+.B --caf
+Produce a Core Audio file.
+.TP
+.B --aiff
+Produce an AIFF file.
+.TP
+.B --flac
+Produce a FLAC file.
+.SS Output sample format
+.TP
+.B --16bit
+Output sample format is signed 16-bit. This option also
+enables the use of dithering, described below.
+.TP
+.B --24bit
+Output sample format is 24-bit. This is the default.
+.TP
+.B --float
+Output sample format is 32-bit floating point.
+.SS Dithering
+.TP
+.B --rec
+Add white dithering noise with a rectangular distribution. This
+is the best option if the output data is going to processed again,
+but in that case it would be advisable to use 24-bit or float.
+.TP
+.B --tri
+Add filtered noise with a triangular distribution. Compared to the
+rectangular dither this reduces the noise density in the lower
+frequency range.
+.TP
+.B --lips
+This uses the optimal error feedback filter described by
+Stanley Lipschitz. This is recommended is the output is the
+final distribution format, e.g. for a CD.
+.SS Timing
+.TP
+.B --pad
+Insert zero valued input samples at the start and end so that the output
+includes the full symmetric filter response even for the first and last
+samples.
+.SH EXIT STATUS
+Zero in case there are no errors, non-zero otherwise.
+.SH AUTHOR
+Fons Adriaensen (fons (at) linuxaudio.org)
diff --git a/apps/zresample.cc b/apps/zresample.cc
new file mode 100644
index 0000000..474bee8
--- /dev/null
+++ b/apps/zresample.cc
@@ -0,0 +1,302 @@
+// ----------------------------------------------------------------------------
+//
+// Copyright (C) 2006-2011 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// ----------------------------------------------------------------------------
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <math.h>
+#include <zita-resampler/resampler.h>
+#include "audiofile.h"
+
+
+enum { HELP, CAF, WAV, AMB, AIFF, FLAC, BIT16, BIT24, FLOAT, RATE, GAIN, REC, TRI, LIPS, PAD };
+enum { BUFFSIZE = 0x4000, FILTSIZE = 96 };
+
+
+static unsigned int type = Audiofile::TYPE_WAV;
+static unsigned int form = Audiofile::FORM_24BIT;
+static unsigned int rout = 0;
+static unsigned int dith = Audiofile::DITHER_NONE;
+static float gain = 0.0f;
+static bool zpad = false;
+
+
+static void help (void)
+{
+ fprintf (stderr, "\nzresample %s\n", VERSION);
+ fprintf (stderr, "(C) 2007-2015 Fons Adriaensen <fons@linuxaudio.org>\n");
+ fprintf (stderr, "Usage: zresample <options> <input file> <output file>.\n");
+ fprintf (stderr, "Options:\n");
+ fprintf (stderr, " Display this text: --help\n");
+ fprintf (stderr, " Output file type: --caf, --wav, --amb, --aiff, --flac\n");
+ fprintf (stderr, " Output sample rate: --rate <sample rate>\n");
+ fprintf (stderr, " Additional gain (dB): --gain [0.0]\n");
+ fprintf (stderr, " Output sample format: --16bit, --24bit, --float\n");
+ fprintf (stderr, " Dither type (16 bit): --rec, --tri, --lips\n");
+ fprintf (stderr, " Add zero padding : --pad\n");
+ fprintf (stderr, "The default output file format is wav, 24-bit, no dithering.\n");
+ fprintf (stderr, "Integer output formats are clipped, float output is not.\n\n");
+ exit (1);
+}
+
+
+static struct option options [] =
+{
+ { "help", 0, 0, HELP },
+ { "caf", 0, 0, CAF },
+ { "wav", 0, 0, WAV },
+ { "amb", 0, 0, AMB },
+ { "aiff", 0, 0, AIFF },
+ { "flac", 0, 0, FLAC },
+ { "16bit", 0, 0, BIT16 },
+ { "24bit", 0, 0, BIT24 },
+ { "float", 0, 0, FLOAT },
+ { "rate", 1, 0, RATE },
+ { "gain", 1, 0, GAIN },
+ { "rec", 0, 0, REC },
+ { "tri", 0, 0, TRI },
+ { "lips", 0, 0, LIPS },
+ { "pad", 0, 0, PAD },
+ { 0, 0, 0, 0 }
+};
+
+
+static void procoptions (int ac, char *av [])
+{
+ int k;
+
+ while ((k = getopt_long (ac, av, "", options, 0)) != -1)
+ {
+ switch (k)
+ {
+ case '?':
+ case HELP:
+ help ();
+ break;
+ case CAF:
+ type = Audiofile::TYPE_CAF;
+ break;
+ case WAV:
+ type = Audiofile::TYPE_WAV;
+ break;
+ case AMB:
+ type = Audiofile::TYPE_AMB;
+ break;
+ case AIFF:
+ type = Audiofile::TYPE_AIFF;
+ break;
+ case FLAC:
+ type = Audiofile::TYPE_FLAC;
+ break;
+ case BIT16:
+ form = Audiofile::FORM_16BIT;
+ break;
+ case BIT24:
+ form = Audiofile::FORM_24BIT;
+ break;
+ case FLOAT:
+ form = Audiofile::FORM_FLOAT;
+ break;
+ case RATE:
+ if (sscanf (optarg, "%d", &rout) != 1)
+ {
+ fprintf (stderr, "Illegal value for --rate option: '%s'.\n", optarg);
+ exit (1);
+ }
+ break;
+ case GAIN:
+ if (sscanf (optarg, "%f", &gain) != 1)
+ {
+ fprintf (stderr, "Illegal value for --gain option: '%s'.\n", optarg);
+ exit (1);
+ }
+ break;
+ case REC:
+ dith = Audiofile::DITHER_RECT;
+ break;
+ case TRI:
+ dith = Audiofile::DITHER_TRIA;
+ break;
+ case LIPS:
+ dith = Audiofile::DITHER_LIPS;
+ break;
+ case PAD:
+ zpad = true;
+ break;
+ }
+ }
+}
+
+
+int main (int ac, char *av [])
+{
+ Audiofile Ainp;
+ Audiofile Aout;
+ Resampler R;
+ unsigned int i, k, chan, rinp, z1, z2;
+ float *inpb, *outb;
+ bool done;
+
+ procoptions (ac, av);
+ if (ac - optind < 2)
+ {
+ fprintf (stderr, "Missing arguments, try --help.\n");
+ return 1;
+ }
+ if (ac - optind > 2 )
+ {
+ fprintf (stderr, "Too many arguments, try --help.\n");
+ return 1;
+ }
+
+ if (Ainp.open_read (av [optind]))
+ {
+ fprintf (stderr, "Can't open input file '%s'.\n", av [optind]);
+ return 1;
+ }
+
+ chan = Ainp.chan ();
+ rinp = Ainp.rate ();
+ if (rout == 0) rout = rinp;
+
+ if (rout != rinp)
+ {
+ if ((rinp < 8000) || (rinp > 192000))
+ {
+ fprintf (stderr, "Input sample %d rate is out of range.\n", rinp);
+ Ainp.close ();
+ return 1;
+ }
+ if ((rout < 8000) || (rout > 192000))
+ {
+ fprintf (stderr, "Output sample rate %d is out of range.\n", rout);
+ Ainp.close ();
+ return 1;
+ }
+ if (R.setup (rinp, rout, chan, FILTSIZE))
+ {
+ fprintf (stderr, "Sample rate ratio %d/%d is not supported.\n", rout, rinp);
+ Ainp.close ();
+ return 1;
+ }
+ }
+
+ optind++;
+ if (Aout.open_write (av [optind], type, form, rout, chan))
+ {
+ fprintf (stderr, "Can't open output file '%s'.\n", av [optind]);
+ Ainp.close ();
+ return 1;
+ }
+ if (dith != Audiofile::DITHER_NONE)
+ {
+ Aout.set_dither (dith);
+ }
+
+ if (zpad)
+ {
+ z1 = R.inpsize () - 1;
+ z2 = R.inpsize () - 1;
+ }
+ else
+ {
+ z1 = R.inpsize () / 2 - 1;
+ z2 = R.inpsize () / 2;
+ }
+
+ gain = powf (10.0f, 0.05f * gain);
+ inpb = new float [chan * BUFFSIZE];
+ if (rout != rinp)
+ {
+ outb = new float [chan * BUFFSIZE];
+ // Insert zero samples at start.
+ R.inp_count = z1;
+ R.inp_data = 0;
+ R.out_count = BUFFSIZE;
+ R.out_data = outb;
+ done = false;
+ while (true)
+ {
+ R.process ();
+ if (R.inp_count == 0)
+ {
+ // Input buffer empty, read more samples, insert
+ // zeros at the end, or terminate.
+ if (done)
+ {
+ // We already inserted final zero samples.
+ // Write out any remaining output samples and terminate.
+ Aout.write (outb, BUFFSIZE - R.out_count);
+ break;
+ }
+ k = Ainp.read (inpb, BUFFSIZE);
+ if (k)
+ {
+ if (fabsf (gain - 1.0f) > 1e-3f)
+ {
+ for (i = 0; i < k; i++) inpb [i] *= gain;
+ }
+ // Process next 'k' input samples.
+ R.inp_count = k;
+ R.inp_data = inpb;
+ }
+ else
+ {
+ // At end of input, insert zero samples.
+ R.inp_count = z2;
+ R.inp_data = 0;
+ done = true;
+ }
+ }
+ if (R.out_count == 0)
+ {
+ // Output buffer full, write to file.
+ Aout.write (outb, BUFFSIZE);
+ R.out_count = BUFFSIZE;
+ R.out_data = outb;
+ }
+ }
+ delete[] outb;
+ }
+ else
+ {
+ // No resampling, just copy.
+ while (1)
+ {
+ k = Ainp.read (inpb, BUFFSIZE);
+ if (k)
+ {
+ if (fabsf (gain - 1.0f) > 1e-3f)
+ {
+ for (i = 0; i < k; i++) inpb [i] *= gain;
+ }
+ Aout.write (inpb, k);
+ }
+ else break;
+ }
+ }
+
+ Ainp.close ();
+ Aout.close ();
+ delete[] inpb;
+
+ return 0;
+}
diff --git a/apps/zretune.1 b/apps/zretune.1
new file mode 100644
index 0000000..f4147cd
--- /dev/null
+++ b/apps/zretune.1
@@ -0,0 +1,79 @@
+.TH zretune 1 "Sect 2012" "version 0.0.1" "USER COMMANDS"
+.SH NAME
+zretune \- resample an audio file in order to change its pitch
+.SH SYNOPSIS
+.B zretune
+[options] input-file output-file
+.SH DESCRIPTION
+.B zretune
+resamples an audio file by a the inverse of a ratio expressed in cents,
+without changing the nominal sample rate. The result is to change the
+musical pitch and lenght of the file. Input can be any audio file
+readable by the libsndfile library. The output file type is either
+WAV, WAVEX, CAF, AIFF or FLAC.
+.SH OPTIONS
+.TP
+.B --help
+Display a short help text.
+.TP
+.B --cent pitch change in cents
+The number of cents by which the pitch is changed. The accepted
+range is +/- 1200 cents, the useful range in practice will be
+something like +/- 100 cents.
+.SS Output file type
+.TP
+.B --wav
+Produce a WAV file, or for more than 2 channels, a WAVEX file.
+This is the default.
+.TP
+.B --amb
+Produce a WAVEX file with the Ambisonic GUID. Such files should
+have the
+.B .amb
+filename extension.
+.TP
+.B --caf
+Produce a Core Audio file.
+.TP
+.B --aiff
+Produce an AIFF file.
+.TP
+.B --flac
+Produce a FLAC file.
+.SS Output sample format
+.TP
+.B --16bit
+Output sample format is signed 16-bit. This option also
+enables the use of dithering, described below.
+.TP
+.B --24bit
+Output sample format is 24-bit. This is the default.
+.TP
+.B --float
+Output sample format is 32-bit floating point.
+.SS Dithering
+.TP
+.B --rec
+Add white dithering noise with a rectangular distribution. This
+is the best option if the output data is going to processed again,
+but in that case it would be advisable to use 24-bit or float.
+.TP
+.B --tri
+Add filtered noise with a triangular distribution. Compared to the
+rectangular dither this reduces the noise density in the lower
+frequency range.
+.TP
+.B --lips
+This uses the optimal error feedback filter described by
+Stanley Lipschitz. This is recommended is the output is the
+final distribution format, e.g. for a CD.
+.SS Timing
+.TP
+.B --pad
+Insert zero valued input samples at the start and end so that the output
+includes the full symmetric filter response even for the first and last
+samples.
+.SH EXIT STATUS
+Zero in case there are no errors, non-zero otherwise.
+.SH AUTHOR
+Fons Adriaensen (fons (at) linuxaudio.org)
diff --git a/apps/zretune.cc b/apps/zretune.cc
new file mode 100644
index 0000000..a605a01
--- /dev/null
+++ b/apps/zretune.cc
@@ -0,0 +1,265 @@
+// ----------------------------------------------------------------------------
+//
+// Copyright (C) 2006-2011 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// ----------------------------------------------------------------------------
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <math.h>
+#include <zita-resampler/vresampler.h>
+#include "audiofile.h"
+
+
+enum { HELP, CAF, WAV, AMB, AIFF, FLAC, BIT16, BIT24, FLOAT, CENT, REC, TRI, LIPS, PAD };
+enum { BUFFSIZE = 0x4000, FILTSIZE = 96 };
+
+
+static unsigned int type = Audiofile::TYPE_WAV;
+static unsigned int form = Audiofile::FORM_24BIT;
+static double cent = 0;
+static unsigned int dith = Audiofile::DITHER_NONE;
+static bool zpad = false;
+
+
+static void help (void)
+{
+ fprintf (stderr, "\nzretune %s\n", VERSION);
+ fprintf (stderr, "(C) 2007-2012 Fons Adriaensen <fons@linuxaudio.org>\n");
+ fprintf (stderr, "Usage: zretune <options> <input file> <output file>.\n");
+ fprintf (stderr, "Options:\n");
+ fprintf (stderr, " Display this text: --help\n");
+ fprintf (stderr, " Output file type: --caf, --wav, --amb, --aiff, --flac\n");
+ fprintf (stderr, " Resampling ratio: --cent <pitch change>\n");
+ fprintf (stderr, " Output sample format: --16bit, --24bit, --float\n");
+ fprintf (stderr, " Dither type (16 bit): --rec, --tri, --lips\n");
+ fprintf (stderr, " Add zero padding : --pad\n");
+ fprintf (stderr, "The default output file format is wav, 24-bit, no dithering.\n");
+ fprintf (stderr, "Integer output formats are clipped, float output is not.\n\n");
+ exit (1);
+}
+
+
+static struct option options [] =
+{
+ { "help", 0, 0, HELP },
+ { "caf", 0, 0, CAF },
+ { "wav", 0, 0, WAV },
+ { "amb", 0, 0, AMB },
+ { "aiff", 0, 0, AIFF },
+ { "flac", 0, 0, FLAC },
+ { "16bit", 0, 0, BIT16 },
+ { "24bit", 0, 0, BIT24 },
+ { "float", 0, 0, FLOAT },
+ { "cent", 1, 0, CENT },
+ { "rec", 0, 0, REC },
+ { "tri", 0, 0, TRI },
+ { "lips", 0, 0, LIPS },
+ { "pad", 0, 0, PAD },
+ { 0, 0, 0, 0 }
+};
+
+
+static void procoptions (int ac, char *av [])
+{
+ int k;
+
+ while ((k = getopt_long (ac, av, "", options, 0)) != -1)
+ {
+ switch (k)
+ {
+ case '?':
+ case HELP:
+ help ();
+ break;
+ case CAF:
+ type = Audiofile::TYPE_CAF;
+ break;
+ case WAV:
+ type = Audiofile::TYPE_WAV;
+ break;
+ case AMB:
+ type = Audiofile::TYPE_AMB;
+ break;
+ case AIFF:
+ type = Audiofile::TYPE_AIFF;
+ break;
+ case FLAC:
+ type = Audiofile::TYPE_FLAC;
+ break;
+ case BIT16:
+ form = Audiofile::FORM_16BIT;
+ break;
+ case BIT24:
+ form = Audiofile::FORM_24BIT;
+ break;
+ case FLOAT:
+ form = Audiofile::FORM_FLOAT;
+ break;
+ case CENT:
+ if (sscanf (optarg, "%lf", &cent) != 1)
+ {
+ fprintf (stderr, "Illegal value for --rate option: '%s'.\n", optarg);
+ exit (1);
+ }
+ break;
+ case REC:
+ dith = Audiofile::DITHER_RECT;
+ break;
+ case TRI:
+ dith = Audiofile::DITHER_TRIA;
+ break;
+ case LIPS:
+ dith = Audiofile::DITHER_LIPS;
+ break;
+ case PAD:
+ zpad = true;
+ break;
+ }
+ }
+}
+
+
+int main (int ac, char *av [])
+{
+ Audiofile Ainp;
+ Audiofile Aout;
+ VResampler R;
+ unsigned int k, chan, z1, z2;
+ float *inpb, *outb;
+ bool done;
+ double ratio;
+
+ procoptions (ac, av);
+ if (ac - optind < 2)
+ {
+ fprintf (stderr, "Missing arguments, try --help.\n");
+ return 1;
+ }
+ if (ac - optind > 2 )
+ {
+ fprintf (stderr, "Too many arguments, try --help.\n");
+ return 1;
+ }
+
+ if (Ainp.open_read (av [optind]))
+ {
+ fprintf (stderr, "Can't open input file '%s'.\n", av [optind]);
+ return 1;
+ }
+
+ if ((cent < -1200) || (cent > 1200))
+ {
+ fprintf (stderr, "Pitch change %3.1lf is out of range.\n", cent);
+ Ainp.close ();
+ return 1;
+ }
+ ratio = pow (2.0, -cent / 1200.0);
+ R.setup (ratio, Ainp.chan (), FILTSIZE);
+
+ optind++;
+ if (Aout.open_write (av [optind], type, form, Ainp.rate(), Ainp.chan ()))
+ {
+ fprintf (stderr, "Can't open output file '%s'.\n", av [optind]);
+ Ainp.close ();
+ return 1;
+ }
+ if (dith != Audiofile::DITHER_NONE)
+ {
+ Aout.set_dither (dith);
+ }
+
+ if (zpad)
+ {
+ z1 = R.inpsize () - 1;
+ z2 = R.inpsize () - 1;
+ }
+ else
+ {
+ z1 = R.inpsize () / 2 - 1;
+ z2 = R.inpsize () / 2;
+ }
+
+ chan = Ainp.chan ();
+ inpb = new float [chan * BUFFSIZE];
+ if (cent != 0.0)
+ {
+ outb = new float [chan * BUFFSIZE];
+ // Insert zero samples at start.
+ R.inp_count = z1;
+ R.inp_data = 0;
+ R.out_count = BUFFSIZE;
+ R.out_data = outb;
+ done = false;
+ while (true)
+ {
+ R.process ();
+ if (R.inp_count == 0)
+ {
+ // Input buffer empty, read more samples, insert
+ // zeros at the end, or terminate.
+ if (done)
+ {
+ // We already inserted final zero samples.
+ // Write out any remaining output samples and terminate.
+ Aout.write (outb, BUFFSIZE - R.out_count);
+ break;
+ }
+ k = Ainp.read (inpb, BUFFSIZE);
+ if (k)
+ {
+ // Process next 'k' input samples.
+ R.inp_count = k;
+ R.inp_data = inpb;
+ }
+ else
+ {
+ // At end of input, insert zero samples.
+ R.inp_count = z2;
+ R.inp_data = 0;
+ done = true;
+ }
+ }
+ if (R.out_count == 0)
+ {
+ // Output buffer full, write to file.
+ Aout.write (outb, BUFFSIZE);
+ R.out_count = BUFFSIZE;
+ R.out_data = outb;
+ }
+ }
+ delete[] outb;
+ }
+ else
+ {
+ // No resampling, just copy.
+ while (1)
+ {
+ k = Ainp.read (inpb, BUFFSIZE);
+ if (k) Aout.write (inpb, k);
+ else break;
+ }
+ }
+
+ Ainp.close ();
+ Aout.close ();
+ delete[] inpb;
+
+ return 0;
+}
diff --git a/docs/filt1.png b/docs/filt1.png
new file mode 100644
index 0000000..0fdd30c
--- /dev/null
+++ b/docs/filt1.png
Binary files differ
diff --git a/docs/filt2.png b/docs/filt2.png
new file mode 100644
index 0000000..4a5bf5b
--- /dev/null
+++ b/docs/filt2.png
Binary files differ
diff --git a/docs/inpdist.png b/docs/inpdist.png
new file mode 100644
index 0000000..5a89018
--- /dev/null
+++ b/docs/inpdist.png
Binary files differ
diff --git a/docs/resampler.html b/docs/resampler.html
new file mode 100644
index 0000000..eb608e0
--- /dev/null
+++ b/docs/resampler.html
@@ -0,0 +1,574 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+ <title>Zita-resampler.</title>
+ <meta name="Author" content="Fons Adriaensen (fons@linuxaudio.org)">
+ <meta name="Description" content="The zita-resampler library.">
+ <meta name="Keywords" content="resampling sound audio dsp linux">
+ <link rel=StyleSheet href="zitadocs.css" type="text/css" media="all">
+</head>
+
+<body>
+
+
+<h1>Libzita-resampler</h1>
+<ul>
+<li><a href = "#introduction">Introduction</a>
+<li><a href = "#algorithm">The algorithm</a>
+<li><a href = "#description">API description</a>
+<li><a href = "#reference">API reference</a>
+</ul>
+
+<br>
+<a name = "introduction"></a>
+<h2>Introduction</h2>
+<p>
+Libzita-resampler is a C++ library for resampling audio signals. It is designed
+to be used within a real-time processing context, to be fast, and to provide
+high-quality sample rate conversion.
+</p>
+<p>
+The library operates on signals represented in single-precision floating point
+format. For multichannel operation both the input and output signals are
+assumed to be stored as interleaved samples.
+</p>
+<p>
+The API allows a trade-off between quality and CPU load. For the latter
+a range of approximately 1:6 is available. Even at the highest quality
+setting libzita-resampler will be faster than most similar libraries
+providing the same quality, e.g. libsamplerate.
+</p>
+<p>
+In many real-time resampling applications (e.g. an audio player), processing
+is driven by the ouput sample rate: each processing period requires a fixed
+number of output samples, and the input side has to adapt, providing whatever
+number of samples required. The inverse situation (less common, but possible)
+would be e.g. a recording application that writes an audio file at a rate that
+is different from the hardware sample rate. In that case the number of input
+samples is fixed for each processing period. The API provided by libzita-resampler
+is fully symmetric in this respect - it handles both situations in the exactly the
+same way, using the same application code.
+</p>
+<p>
+Libzita-resampler provides two classes:
+</p>
+<p>
+The <b>Resampler</b> class performs resampling at a fixed ratio <b>F_out / F_in</b>
+which is required to be <b>&ge; 1/16</b> and be reducible to the form <b> b / a</b>
+with <b>a, b</b> integer and <b>b &le; 1000</b>. This includes all the 'standard'
+ratios, e.g. 96000 / 44100 = 320 / 147. These restrictions allow for a more efficient
+implementation.
+</p>
+<p>
+The <b>VResampler</b> class provides an arbitrary ratio <b>r</b> in the range
+<b>1/16 &le; r &le; 64</b> and which can variable within a range of <b>0.95 to
+16.0</b> w.r.t. the originally configured one. The lower limit here is necessary
+because this class still uses a fixed multiphase filter, with only the phase step
+being variable. This class was developed for converting between two nominally fixed
+sample rates with a ratio which is not known exactly and may even drift slowly, e.g.
+when combining sound cards wich do not have a common word clock. This resampler is
+somewhat less efficient than the fixed ratio one since it has to interpolate filter
+coefficients, but the difference is marginal when used on multichannel signals.
+</p>
+<p>
+Both classes provide essentially the same API, with only small differences
+where necessary.
+
+<br>
+<a name = "algorithm"></a>
+<h2>The algorithm</h2>
+<p>
+Libzita-resampler implements <b>constant bandwidth resampling</b>. In contrast
+to e.g. cubic interpolation it does not consider the actual shape of the
+waveform represented by the input samples, but rather operates in the spectral
+domain.
+</p>
+<p>
+Let
+<ul>
+<li><b>F_in, F_out</b>&nbsp &nbsp be the input and output sample rates,</li>
+<li><b>F_min</b>&nbsp &nbsp the lower of the two,</li>
+<li><b>F_lcm</b>&nbsp &nbsp their lowest common multiple,</li>
+<li><b>b = F_lcm / F_in</b>,</li>
+<li><b>a = F_lcm / F_out</b></li>.
+</ul>
+<p>
+Then the calculation performed by zita-resampler is equivalent to:
+</p>
+<ul>
+<li>upsampling to a rate of <b>F_lcm</b> by inserting <b>b - 1</b>
+zero-valued samples after each input sample,</li>
+<li>low-pass filtering of the upsampled signal to remove everything
+above <b>F_min / 2</b>,</li>
+<li>retaining only the first of each series of <b>a</b> filtered
+samples.</li>
+</ul>
+<p>
+This is of course not how things are implemented in the resampler code.
+Only those samples that are actually output are computed, and the inserted
+zeros are never used. In practice this means there is a set of <b>b</b>
+different FIR filters that each output one sample in turn, in round-robin
+fashion. All these filters have the same frequency response, but different
+delays that correspond to the relative position in time of the input and
+output samples.
+</p>
+<p>
+A real-world filter can't be perfect, it is always a compromise between
+complexity (CPU load) and performance. In the context of resampling this
+compromise manifests itself as deviations from the ideally flat frequency
+response, and as aliasing - the same phenomenon that occurs with AD and
+DA conversion. For aliasing, two cases need to be considered:
+</p>
+<p>
+<b>Upsampling.</b> In this case <b>F_min = F_in</b>, and input signals
+below but near to <b>F_in / 2</b> will also appear in the output
+just above this frequency. This is similar to DA conversion.
+</p>
+<p>
+<b>Downsampling.</b> In this case <b>F_min = F_out</b>, and input signals
+above but near to <b>F_out / 2</b> will also appear in the output
+just below this frequency. This is similar to AD conversion.
+</p>
+<p>
+In the design of zita-resampler it was assumed that in most cases
+conversion will be between the 'standard' audio sample rates (44.1,
+48, 88.2, 96, 192 kHz), and that consequently frequency response
+errors and aliasing will occur only above the upper limit of the
+audible frequency range. Given this assumption, some pragmatic
+trade-offs can be made.
+</p>
+<p>
+The filter used by libzita-resampler is dimensioned to reach an
+attenuation of 60dB at the Nyquist frequency. The initialisation
+function takes a parameter named <b>hlen</b> that is in fact half
+the length of the symmetrical FIR filter expressend in samples at
+the rate <b>F_min</b>. The valid range for <b>hlen</b> is 16 to 96.
+The figure below shows the filter responses for <b>hlen</b> = 32,
+48, and 96. The <b>x</b> axis is <b>F / F_min</b>, the <b>y</b> axis
+is in dB. The lower part of the traces is the mirrored continuation
+of the response above the Nyquist frequency, i.e. the aliasing.
+Note that 20 kHz corresponds to x = 0.416 for a sample rate of 48 kHz,
+and to x = 0.454 for a sample rate of 44.1 kHz.
+</p>
+<p>
+<img src="filt1.png">
+</p>
+<p>
+<br>
+The same traces with a reduced vertical range, showing the passband
+response.
+</p>
+<p>
+<img src="filt2.png">
+</p>
+<p>
+From these figures it should be clear that <b>hlen = 32</b> should
+provide very high quality for <b>F_min</b> equal to 48 kHz or higher,
+while <b>hlen = 48</b> should be sufficient for an <b>F_min</b> of
+44.1 kHz. The validity of these assumptions was confirmed by a series
+of listening tests. If fact the conclusion of these test was that even
+at 44.1 kHz the subjects (all audio specialists or musicians) could not
+detect any significant difference between <b>hlen</b> values of 32 and 96.
+</p>
+
+<br>
+<a name = "description"></a>
+<h2>API description</h2>
+<p>
+The constructors of both classes do not initialise the object for a particular
+resampling rate, quality or number of channels - this is done by a separate
+function member which can be used as many times as necessary. This means you
+can allocate <b>(V)Resampler</b> objects before the actual resampling parameters
+are known.
+</p>
+<p>
+The <b>setup ()</b> member initialises a resampler for a combination of input
+sample rate, output sample rate, number of channels, and filter length. This
+function allocates and computes the filter coefficient tables and is definitely
+not RT-safe. The actual tables will be shared with other resampler instances if
+possible - the library maintains a reference-counted collection of them. After
+the initialisation by <b>setup ()</b>, the <b>process ()</b> member can be called
+repeatedly to actually resample audio signals. This function is RT-safe and
+can be used within e.g. a JACK callback. The <b>clear ()</b> member restores
+the object to the initial state it has after construction, and is also called
+from the destructor. You can safely call <b>setup ()</b> again without first
+calling <b>clear ()</b> - doing this avoids recomputation of the filter
+coefficients in some cases.
+</p>
+<p>
+Both classes have four public data members which are used as input and output
+parameters of <b>process ()</b>, in the same way as you would use a C struct
+to pass parameters. These are:
+</p>
+<pre>
+ unsigned int inp_count; // number of frames in the input buffer
+ unsigned int out_count; // number of frames in the output buffer
+ float *inp_data; // pointer to first input frame
+ float *out_data; // pointer to first output frame
+</pre>
+<p>
+As <b>process ()</b> does its work, it increments the pointers and decrements the
+counts. The call returns when either of the counts is zero, i.e. when the input
+buffer is empty or the output buffer is full. You should then take appropriate
+action and if necessary call <b>process ()</b> again.
+</p>
+<p>
+When <b>process ()</b> returns, the four parameter values exactly reflect
+those parts of both buffers <b>that have not yet been used</b>.
+One of them will be fully used, with the corresponding count being zero.
+The remaining part of the other, pointed to by the returned pointer, can
+always be replaced before the next call to <b>process ()</b>, but this is
+entirely optional.
+</p>
+<p>
+When for example <b>inp_count</b> is zero, you have to fill the input buffer
+again, or provide a new one, and re-initialise the input count and pointer.
+If at that time <b>out_count</b> is not zero, you can either leave the output
+parameters as they are for the next call to <b>process ()</b>, or you could
+empty the part of the output buffer that has been filled and re-use it from
+the start, or provide a completely different one.
+</p>
+<p>
+The same applies to the input buffer when it is not empty on return of
+<b>process ()</b>: it can be left alone or be replaced. A number of input
+samples is stored internally between <b>process ()</b> calls as part of the
+resampler state, but this never includes samples that have not yet been used.
+So you can 'revise' the input data, starting from the frame pointed to by the
+returned <b>inp_data</b>, up to the last moment.
+</p>
+<p>
+All this means that both classes will interface easily with fixed input and
+output buffers, with dynamically generated input signals, and also with
+lock-free circular buffers.
+</p>
+<p>
+Either of the two pointers can be NULL. When <b>inp_data</b> is zero, the effect
+is to insert zero-valued input samples, as if you had supplied a zero-filled
+buffer of length <b>inp_count</b>. When <b>out_data</b> is zero, input samples
+will be consumed, the internal state of the resampler will advance normally
+and <b>out_count</b> will decrement, but no output samples are written (in
+fact they are not even computed).
+</p>
+<a name = "padding"></a>
+<p>
+Note that libzita-resampler does <b>not</b> automatically insert zero-valued
+input samples at the start and end of the resampling process. The API makes it
+easy to add such padding, and doing this is left entirely up to the user.
+</p>
+<p>
+The <b>inpsize ()</b> member returns the lenght of the FIR filter expressed in
+input samples. At least this number of samples is required to produce an output
+sample. If <b>k</b> is the value returned by this function, then
+</p>
+<ul>
+<li>inserting <b>k / 2 - 1</b> zero-valued samples at the start will align the
+first input and output samples,</li>
+<li>inserting <b>k - 1</b> zero valued samples will ensure that the output
+includes the full filter response for the first input sample.</li>
+</ul>
+<p>
+Similar considerations apply at the end of the input data:
+</p>
+<ul>
+<li>inserting <b>k / 2</b> zero-valued samples at the end will ensure
+that the last output sample produced will correspond to a position as close
+as possible but not past the last real input sample,</li>
+<li>inserting <b>k - 1</b> zero valued samples will ensure that the output
+includes the full filter response for the last real input sample.</li>
+</ul>
+<p>
+<a name = "inpdist"></a>
+The <b>inpdist ()</b> member returns the distance or delay expressed in sample
+periods at the input rate, between the first output sample that will be ouput
+by the next call to <b>process ()</b> and the first input sample that will be
+read (i.e. that is not yet part of the internal state).
+<br><br>
+In the picture below, the red dots represent input samples and the blue ones
+are the output. Solid dots are samples already used or output. After a call
+to process () the resampler object remains in a state ready to produce the next
+output sample, except that it may have to input one or more new samples first.
+The filter is aligned with the next output sample. In this case one more input
+sample is required to compute it, and the input distance is 2.7.
+</p>
+<p>
+<img src="inpdist.png">
+</p>
+<p>
+After a resampler is prefilled with <b>inpsize () / 2 - 1</b> samples as described
+above, <b>inpdist ()</b> will be zero - the first output sample corresponds exactly
+to the first input. Note that without prefilling the distance is negative, which
+means that the first output sample corresponds to some point past the start of the
+input data.
+</p>
+<p>
+The 'resample' application supplied with the library sources provides
+an example of how to use the <b>Resampler</b> class. For an example
+using <b>VResampler</b> you can have a look at zita_a2j and zita_ja2.
+</p>
+
+<br>
+<a name = "reference"></a>
+<h2>API reference</h2>
+<p>
+Public function members of the <b>Resampler</b> and <b>VResampler</b> classes.
+Functions listed without a class prefix are available for both classes.
+</p>
+<ul>
+<li><a href = "#resampler">Resampler ()</a>
+<li><a href = "#resampler">~Resampler ()</a>
+<li><a href = "#vresampler">VResampler ()</a>
+<li><a href = "#vresampler">~VResampler ()</a>
+<li><a href = "#res_setup">Reampler::setup ()</a>
+<li><a href = "#vres_setup">VResampler::setup ()</a>
+<li><a href = "#clear">clear ()</a>
+<li><a href = "#reset">reset ()</a>
+<li><a href = "#process">process ()</a>
+<li><a href = "#nchan">nchan ()</a>
+<li><a href = "#inpsize">inpsize ()</a>
+<li><a href = "#inpdist">inpdist ()</a>
+<li><a href = "#vres_set_rratio">VResampler::set_rratio ()</a>
+<li><a href = "#vres_set_rrfilt">VResampler::set_rrfilt ()</a>
+</ul>
+<p>
+Public data members of the <b>Resampler</b> and <b>VResampler</b> classes.
+</p>
+<ul>
+<li><a href = "#inp_count">inp_count</a>
+<li><a href = "#out_count">out_count</a>
+<li><a href = "#inp_data">inp_data</a>
+<li><a href = "#out_data">out_data</a>
+</ul>
+
+<a name="resampler"></a>
+<br><p class="apihdr">Resampler (void);<br>~Resampler (void);</p>
+<p>
+<b>Description:</b> Constructor and destructor. The constructor just creates an object that takes
+almost no memory but needs to be configured by <a href="#setup"><b>setup ()</b></a> before it
+can be used. The destructor calls <a href="#clear"><b>clear ()</b></a>.
+<br><br>
+<b>RT-safe:</b> No
+</p>
+
+<a name="vresampler"></a>
+<br><p class="apihdr">VResampler (void);<br>~VResampler (void);</p>
+<p>
+<b>Description:</b> Constructor and destructor. The constructor just creates an object that takes
+almost no memory but needs to be configured by <a href="#setup"><b>setup ()</b></a> before it
+can be used. The destructor calls <a href="#clear"><b>clear ()</b></a>.
+<br><br>
+<b>RT-safe:</b> No
+</p>
+
+<a name="res_setup"></a>
+<br><p class="apihdr">int &nbsp Resampler::setup (unsigned int &nbsp fs_inp, unsigned int fs_out, unsigned int nchan, unsigned int hlen);</p>
+<p>
+<b>Description:</b> Configures the object for a combination of input / output sample rates, number
+of channels, and filter lenght.<br>If the parameters are OK, creates the filter coefficient tables
+or re-uses existing ones, allocates some internal resources, and returns via <a href="#reset">
+<b>reset ()</b></a>.
+<br><br>
+<b>Parameters:</b>
+</p>
+<p class="indent">
+<b>fs_inp, fs_out:</b> The input and output sample rates. The ratio <b>fs_out
+/ fs_inp</b> must be <b> &ge; 1/16</b> and reducible to the form <b>b / a</b>
+with <b>a, b</b> integer and <b>b &le; 1000</b>.
+<br><br>
+<b>nchan:</b> Number of channels, must not be zero.
+<br><br>
+<b>hlen:</b> Half the lenght of the filter expressed in samples at the lower of
+input and output rates. This parameter determines the 'quality' as explained
+<a href="#algorithm">here</a>. For any fixed combination of the other parameters,
+cpu load will be roughly proportional to <b>hlen</b>. The valid range is
+<b>16 &le; hlen &le; 96</b>.
+</p>
+<p>
+<b>Returns:</b> Zero on success, non-zero otherwise.
+<br><br>
+<b>Remark:</b> It is perfectly safe to call this function again without
+having called <a href="#clear"><b>clear ()</b></a> first. If only the number
+of channels is changed, doing this will avoid recalculation of the filter tables
+even if they are not shared.
+<br><br>
+<b>RT-safe:</b> No
+</p>
+
+<a name="vres_setup"></a>
+<br><p class="apihdr">int &nbsp VResampler::setup (double ratio, unsigned int nchan, unsigned int hlen);</p>
+<p>
+<b>Description:</b> Configures the object for a combination of resampling ratio, number of channels,
+and filter lenght.<br>If the parameters are OK, creates the filter coefficient tables or re-uses
+existing ones, allocates some internal resources, and returns via <a href="#reset">
+<b>reset ()</b></a>.
+<br><br>
+<b>Parameters:</b>
+</p>
+<p class="indent">
+<b>ratio:</b> The resampling ratio wich must be between <b>1/16</b> and <b>64</b>.
+<br><br>
+<b>nchan:</b> Number of channels, must not be zero.
+<br><br>
+<b>hlen:</b> Half the lenght of the filter expressed in samples at the lower of
+the input and output rates. This parameter determines the 'quality' as explained
+<a href="#algorithm">here</a>. For any fixed combination of the other parameters,
+cpu load will be roughly proportional to <b>hlen</b>. The valid range is
+<b>16 &le; hlen &le; 96</b>.
+</p>
+<p>
+<b>Returns:</b> Zero on success, non-zero otherwise.
+<br><br>
+<b>Remark:</b> It is perfectly safe to call this function again without
+having called <a href="#clear"><b>clear ()</b></a> first. If only the number
+of channels is changed, doing this will avoid recalculation of the filter tables
+even if they are not shared.
+<br><br>
+<b>RT-safe:</b> No
+</p>
+
+<a name="clear"></a>
+<br><p class="apihdr">void &nbsp clear (void);</p>
+<p>
+<b>Description:</b> Deallocates resources (if not shared) and returns the object to
+the unconfigured state as after construction. Also called by the destructor.
+<br><br>
+<b>RT-safe:</b> No
+</p>
+
+<a name="reset"></a>
+<br><p class="apihdr">int &nbsp reset (void);</p>
+<p>
+<b>Description:</b> Resets the internal state of the resampler. Any stored
+input samples are cleared, the filter phase and the four <a href="#inp_count">
+public data members</a> are set to zero. This should be called before starting
+resampling a new stream with the same configuration as the previous one.
+<br><br>
+<b>Returns:</b> Zero if the resampler is configured , non-zero otherwise.
+<br><br>
+<b>RT-safe:</b> Yes.
+</p>
+
+<a name="process"></a>
+<br><p class="apihdr">int &nbsp process (void);</p>
+<p>
+<b>Description:</b> Resamles the input signal until either the input buffer
+is empty or the output buffer is full. Information on the input and output
+buffers is passed to this function using the four <a href="#inp_count"> public
+data members</a> described below. The same four values are updated on return.
+<br><br>
+<b>Returns:</b> Zero if the resampler is configured, non-zero otherwise.
+<br><br>
+<b>RT-safe:</b> Yes.
+</p>
+
+<a name="nchan"></a>
+<br><p class="apihdr">int &nbsp nchan (void);</p>
+<p>
+<b>Description:</b> Accessor.
+<br><br>
+<b>Returns:</b> The number of channels the resampler is configured for,
+or zero if it is unconfigured. Input and output buffers are assumed to contain
+this number of channels in interleaved format.
+<br><br>
+<b>RT-safe:</b> Yes
+</p>
+
+<a name="inpsize"></a>
+<br><p class="apihdr">int &nbsp inpisze (void);</p>
+<p>
+<b>Description:</b> Accessor.
+<br><br>
+<b>Returns:</b> If the resampler is configured, the lenght of the
+finite impulse filter expressed in samples at the input sample rate,
+or zero otherwise. This value may be used to determine the number of
+silence samples to insert at the start and end when resampling e.g.
+an impulse response. See <a href="#padding">here</a> for more about this.
+This function was called 'filtlen ()' in previous releases.
+<br><br>
+<b>RT-safe:</b> Yes
+</p>
+
+<a name="inpdist"></a>
+<br><p class="apihdr">double &nbsp inpdist (void);</p>
+<p>
+<b>Description:</b> Accessor.
+<br><br>
+<b>Returns:</b> If the resampler is configured, the distance between
+the next output sample and the next input sample, expressed in sample
+periods at the input rate, zero otherwise. See <a href="#inpdist">
+here</a> for more about this.
+<br><br>
+<b>RT-safe:</b> Yes
+</p>
+
+<a name="vres_set_rratio"></a>
+<br><p class="apihdr">void &nbsp VResampler::set_rratio (double ratio);</p>
+<p>
+<b>Description:</b> Sets the resampling ratio relative to the one configured
+by <a href="#vres_setup"> setup ()</a>. The valid range is <b>0.95 &le;
+ratio &le; 16</b>.
+<br><br>
+<b>Parameters:</b>
+</p>
+<p class="indent">
+<b>ratio:</b> The relative resampling ratio.
+</p>
+<p>
+<b>RT-safe:</b> Yes
+</p>
+
+<a name="vres_set_rrfilt"></a>
+<br><p class="apihdr">void &nbsp VResampler::set_rrfilt (double time);</p>
+<p>
+<b>Description:</b> Sets the time constant of the first order filter applied
+on values set by <a href="#vres_set_rratio"> set_rratio ()</a>. The time is
+expressed as sample periods at the output rate. The default is zero, which
+means changes are applied instantly.
+<br><br>
+<b>Parameters:</b>
+</p>
+<p class="indent">
+<b>time:</b> The filter time constant.
+</p>
+<p>
+<b>RT-safe:</b> Yes
+</p>
+
+<a name="inp_count"></a>
+<br><p class="apihdr">unsigned int &nbsp inp_count;</p>
+<p>
+<b>Description:</b> Data member, input / output parameter of the <a href="#process">
+process ()</a> function. This value is always equal to the number of frames in the
+input buffer that have not yet been read by the process () function. It should be set
+to the number of available frames before calling process ().
+</p>
+
+<a name="out_count"></a>
+<br><p class="apihdr">unsigned int &nbsp out_count;</p>
+<p>
+<b>Description:</b> Data member, input / output parameter of the <a href="#process">
+process ()</a> function. This value is always equal to the number of frames in the
+output buffer that have not yet been written by the process () function. It should be
+set to the size of the output buffer before calling process ().
+</p>
+
+<a name="inp_data"></a>
+<br><p class="apihdr">float &nbsp *inp_data;</p>
+<p>
+<b>Description:</b> Data member, input / output parameter of the <a href="#process">
+process ()</a> function. If not zero (NULL), this points to the next frame in the
+input buffer that will be read by process (). If set to zero (NULL), the resampler
+will proceed normally but use zero-valued samples as input (still counted by
+<b>inp_count</b>).
+</p>
+
+<a name="out_data"></a>
+<br><p class="apihdr">float &nbsp *out_data;</p>
+<p>
+<b>Description:</b> Data member, input / output parameter of the <a href="#process">
+process ()</a> function. If not zero (NULL), this points to the next frame in the
+output buffer that will be written by process (). If set to zero (NULL), the resampler
+will proceed normally but the output is discarded (but still counted by <b>out_count</b>).
+</p>
+
+</body>
+</html>
diff --git a/docs/src-1kHz.png b/docs/src-1kHz.png
new file mode 100644
index 0000000..18b450a
--- /dev/null
+++ b/docs/src-1kHz.png
Binary files differ
diff --git a/docs/zita-1kHz.png b/docs/zita-1kHz.png
new file mode 100644
index 0000000..4028fa4
--- /dev/null
+++ b/docs/zita-1kHz.png
Binary files differ
diff --git a/docs/zitadocs.css b/docs/zitadocs.css
new file mode 100644
index 0000000..8afb88d
--- /dev/null
+++ b/docs/zitadocs.css
@@ -0,0 +1,18 @@
+body { background: white; color: black; font-family: arial, helvetica, sans-serif; }
+center { font-family: arial, helvetica, sans-serif; }
+p { font-family: arial, helvetica, sans-serif; text-align: left; margin-left: 3%; margin-right: 3%; }
+td { font-family: arial, helvetica, sans-serif; background: white; color: black; }
+ul { font-family: arial, helvetica, sans-serif; text-align: left; margin-left: 3%; margin-right: 6%; }
+ol { font-family: arial, helvetica, sans-serif; text-align: left; margin-left: 3%; margin-right: 6%; }
+dl { font-family: arial, helvetica, sans-serif; text-align: left; margin-left: 3%; margin-right: 3%; }
+h1 { font-size: xx-large; background: #8080FF; color: white; text-align: left; padding-left: 20; }
+h2 { font-size: x-large; background: #8080FF; color: white; text-align: left; padding-left: 20; }
+h3 { font-size: large; background: #8080FF; color: white; text-align: left; padding-left: 20; }
+pre { font-family: courier, monospace; font-size: medium; }
+a:link { color: #008000; }
+a:visited { color: #008000; }
+a:active { color: #FF00FF; }
+a:hover { background-color: #80FF80; color: black; }
+.apihdr { background: #E0E0FF; color: black; text-align: left; padding: 5; }
+.indent { font-family: arial, helvetica, sans-serif; text-align: left; margin-left: 50; margin-right: 50; }
+
diff --git a/libs/Makefile b/libs/Makefile
new file mode 100644
index 0000000..15b0471
--- /dev/null
+++ b/libs/Makefile
@@ -0,0 +1,69 @@
+# ----------------------------------------------------------------------------
+#
+# Copyright (C) 2006-2012 Fons Adriaensen <fons@linuxaudio.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# ----------------------------------------------------------------------------
+
+
+# Modify as required.
+#
+PREFIX = /usr/local
+SUFFIX := $(shell uname -m | sed -e 's/^unknown/$//' -e 's/^i.86/$//' -e 's/^x86_64/$/64/')
+LIBDIR = lib$(SUFFIX)
+
+MAJVERS = 1
+MINVERS = 6.0
+VERSION = $(MAJVERS).$(MINVERS)
+DISTDIR = zita-resampler-$(VERSION)
+
+
+CPPFLAGS += -I. -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS
+CXXFLAGS += -Wall -fPIC -O2 -ffast-math
+CXXFLAGS += -march=native
+LDFLAGS +=
+LDLIBS +=
+
+
+ZITA-RESAMPLER_SO = libzita-resampler.so
+ZITA-RESAMPLER_MAJ = $(ZITA-RESAMPLER_SO).$(MAJVERS)
+ZITA-RESAMPLER_MIN = $(ZITA-RESAMPLER_MAJ).$(MINVERS)
+ZITA-RESAMPLER_DEP =
+ZITA-RESAMPLER_O = resampler.o vresampler.o resampler-table.o cresampler.o
+ZITA-RESAMPLER_H = zita-resampler/resampler.h zita-resampler/resampler-table.h \
+ zita-resampler/vresampler.h zita-resampler/cresampler.h
+
+
+$(ZITA-RESAMPLER_MIN): $(ZITA-RESAMPLER_O)
+ g++ -shared $(LDFLAGS) -Wl,-soname,$(ZITA-RESAMPLER_MAJ) -o $(ZITA-RESAMPLER_MIN) $(ZITA-RESAMPLER_O) $(ZITA-RESAMPLER_DEP)
+
+$(ZITA-RESAMPLER_O): $(ZITA-RESAMPLER_H)
+
+
+install: $(ZITA-RESAMPLER_MIN)
+ install -d $(DESTDIR)$(PREFIX)/include/zita-resampler
+ install -d $(DESTDIR)$(PREFIX)/$(LIBDIR)
+ install -m 644 $(ZITA-RESAMPLER_H) $(DESTDIR)$(PREFIX)/include/zita-resampler
+ install -m 644 $(ZITA-RESAMPLER_MIN) $(DESTDIR)$(PREFIX)/$(LIBDIR)
+ ln -sf $(ZITA-RESAMPLER_MIN) $(DESTDIR)$(PREFIX)/$(LIBDIR)/$(ZITA-RESAMPLER_SO)
+ ldconfig
+
+uninstall:
+ /bin/rm -rf $(DESTDIR)$(PREFIX)/include/zita-resampler
+ /bin/rm -rf $(DESTDIR)$(PREFIX)/$(LIBDIR)/libzita-resampler*
+
+clean:
+ /bin/rm -rf *~ *.o *.a *.d *.so.* zita-resampler/*~
+
diff --git a/libs/Makefile-linux b/libs/Makefile-linux
new file mode 100644
index 0000000..15b0471
--- /dev/null
+++ b/libs/Makefile-linux
@@ -0,0 +1,69 @@
+# ----------------------------------------------------------------------------
+#
+# Copyright (C) 2006-2012 Fons Adriaensen <fons@linuxaudio.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# ----------------------------------------------------------------------------
+
+
+# Modify as required.
+#
+PREFIX = /usr/local
+SUFFIX := $(shell uname -m | sed -e 's/^unknown/$//' -e 's/^i.86/$//' -e 's/^x86_64/$/64/')
+LIBDIR = lib$(SUFFIX)
+
+MAJVERS = 1
+MINVERS = 6.0
+VERSION = $(MAJVERS).$(MINVERS)
+DISTDIR = zita-resampler-$(VERSION)
+
+
+CPPFLAGS += -I. -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS
+CXXFLAGS += -Wall -fPIC -O2 -ffast-math
+CXXFLAGS += -march=native
+LDFLAGS +=
+LDLIBS +=
+
+
+ZITA-RESAMPLER_SO = libzita-resampler.so
+ZITA-RESAMPLER_MAJ = $(ZITA-RESAMPLER_SO).$(MAJVERS)
+ZITA-RESAMPLER_MIN = $(ZITA-RESAMPLER_MAJ).$(MINVERS)
+ZITA-RESAMPLER_DEP =
+ZITA-RESAMPLER_O = resampler.o vresampler.o resampler-table.o cresampler.o
+ZITA-RESAMPLER_H = zita-resampler/resampler.h zita-resampler/resampler-table.h \
+ zita-resampler/vresampler.h zita-resampler/cresampler.h
+
+
+$(ZITA-RESAMPLER_MIN): $(ZITA-RESAMPLER_O)
+ g++ -shared $(LDFLAGS) -Wl,-soname,$(ZITA-RESAMPLER_MAJ) -o $(ZITA-RESAMPLER_MIN) $(ZITA-RESAMPLER_O) $(ZITA-RESAMPLER_DEP)
+
+$(ZITA-RESAMPLER_O): $(ZITA-RESAMPLER_H)
+
+
+install: $(ZITA-RESAMPLER_MIN)
+ install -d $(DESTDIR)$(PREFIX)/include/zita-resampler
+ install -d $(DESTDIR)$(PREFIX)/$(LIBDIR)
+ install -m 644 $(ZITA-RESAMPLER_H) $(DESTDIR)$(PREFIX)/include/zita-resampler
+ install -m 644 $(ZITA-RESAMPLER_MIN) $(DESTDIR)$(PREFIX)/$(LIBDIR)
+ ln -sf $(ZITA-RESAMPLER_MIN) $(DESTDIR)$(PREFIX)/$(LIBDIR)/$(ZITA-RESAMPLER_SO)
+ ldconfig
+
+uninstall:
+ /bin/rm -rf $(DESTDIR)$(PREFIX)/include/zita-resampler
+ /bin/rm -rf $(DESTDIR)$(PREFIX)/$(LIBDIR)/libzita-resampler*
+
+clean:
+ /bin/rm -rf *~ *.o *.a *.d *.so.* zita-resampler/*~
+
diff --git a/libs/Makefile-osx b/libs/Makefile-osx
new file mode 100644
index 0000000..02d4252
--- /dev/null
+++ b/libs/Makefile-osx
@@ -0,0 +1,74 @@
+# ----------------------------------------------------------------------------
+#
+# Copyright (C) 2006-2014 Fons Adriaensen <fons@linuxaudio.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# ----------------------------------------------------------------------------
+
+
+# Modify as required.
+#
+PREFIX = /usr/local
+#SUFFIX := $(shell uname -m | sed -e 's/^unknown/$//' -e 's/^i.86/$//' -e 's/^x86_64/$/64/')
+LIBDIR = lib$(SUFFIX)
+
+MAJVERS = 1
+MINVERS = 6.0
+VERSION = $(MAJVERS).$(MINVERS)
+DISTDIR = zita-resampler-$(VERSION)
+
+
+CPPFLAGS += -I. -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS
+CXXFLAGS += -Wall -dynamic -O2 -ffast-math
+CXXFLAGS += -march=native
+LDFLAGS +=
+LDLIBS +=
+
+ZITA-RESAMPLER_l = libzita-resampler
+ZITA-RESAMPLER_SO = $(ZITA-RESAMPLER_l).dylib
+ZITA-RESAMPLER_MAJ = $(ZITA-RESAMPLER_l).$(MAJVERS).dylib
+ZITA-RESAMPLER_MIN = $(ZITA-RESAMPLER_l).$(MAJVERS).$(MINVERS).dylib
+ZITA-RESAMPLER_DEP =
+ZITA-RESAMPLER_O = resampler.o vresampler.o resampler-table.o cresampler.o
+ZITA-RESAMPLER_H = zita-resampler/resampler.h zita-resampler/resampler-table.h \
+ zita-resampler/vresampler.h zita-resampler/cresampler.h
+
+
+$(ZITA-RESAMPLER_MIN): $(ZITA-RESAMPLER_O)
+ g++ -dynamiclib -flat_namespace \
+ -current_version $(MAJVERS).$(MINVERS) \
+ -compatibility_version $(MAJVERS) \
+ -o $(ZITA-RESAMPLER_MIN) \
+ $(ZITA-RESAMPLER_O) $(ZITA-RESAMPLER_DEP) $(LDFLAGS)
+
+
+$(ZITA-RESAMPLER_O): $(ZITA-RESAMPLER_H)
+
+
+install: $(ZITA-RESAMPLER_MIN)
+ install -d $(DESTDIR)$(PREFIX)/include/zita-resampler
+ install -d $(DESTDIR)$(PREFIX)/$(LIBDIR)
+ install -m 644 $(ZITA-RESAMPLER_H) $(DESTDIR)$(PREFIX)/include/zita-resampler
+ install -m 644 $(ZITA-RESAMPLER_MIN) $(DESTDIR)$(PREFIX)/$(LIBDIR)
+ ln -sf $(ZITA-RESAMPLER_MIN) $(DESTDIR)$(PREFIX)/$(LIBDIR)/$(ZITA-RESAMPLER_MAJ)
+ ln -sf $(ZITA-RESAMPLER_MIN) $(DESTDIR)$(PREFIX)/$(LIBDIR)/$(ZITA-RESAMPLER_SO)
+
+uninstall:
+ /bin/rm -rf $(DESTDIR)$(PREFIX)/include/zita-resampler
+ /bin/rm -rf $(DESTDIR)$(PREFIX)/$(LIBDIR)/libzita-resampler*
+
+clean:
+ /bin/rm -rf *~ *.o *.a *.d *.so.* *.so *.dylib zita-resampler/*~
+
diff --git a/libs/cresampler.cc b/libs/cresampler.cc
new file mode 100644
index 0000000..ca3cabf
--- /dev/null
+++ b/libs/cresampler.cc
@@ -0,0 +1,192 @@
+// ----------------------------------------------------------------------------
+//
+// Copyright (C) 2013 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// ----------------------------------------------------------------------------
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <zita-resampler/cresampler.h>
+
+
+CResampler::CResampler (void) :
+ _nchan (0),
+ _buff (0)
+{
+ reset ();
+}
+
+
+CResampler::~CResampler (void)
+{
+ clear ();
+}
+
+
+int CResampler::setup (double ratio,
+ unsigned int nchan)
+{
+ if (! nchan) return 1;
+ clear ();
+ _inmax = 50;
+ _buff = new float [nchan * (3 + _inmax)];
+ _nchan = nchan;
+ _pstep = 1 / ratio;
+ return reset ();
+}
+
+
+void CResampler::clear (void)
+{
+ delete[] _buff;
+ _buff = 0;
+ _nchan = 0;
+ _inmax = 0;
+ _pstep = 0;
+ reset ();
+}
+
+
+void CResampler::set_phase (double p)
+{
+ _phase = p - floor (p);
+}
+
+
+void CResampler::set_ratio (double r)
+{
+ _pstep = 1.0 / r;
+}
+
+
+double CResampler::inpdist (void) const
+{
+ return (int)(3 - _nread) - _phase;
+}
+
+
+int CResampler::inpsize (void) const
+{
+ return 4;
+}
+
+
+int CResampler::reset (void)
+{
+ inp_count = 0;
+ out_count = 0;
+ inp_data = 0;
+ out_data = 0;
+ _index = 0;
+ _phase = 0;
+ _nread = 4;
+ _nzero = 0;
+ return 0;
+}
+
+
+int CResampler::process (void)
+{
+ unsigned int in, nr, n, c;
+ int nz;
+ double ph;
+ float *pb, a, b, d, m0, m1, m2, m3;
+
+ in = _index;
+ nr = _nread;
+ nz = _nzero;
+ ph = _phase;
+ pb = _buff + in * _nchan;
+
+ while (out_count)
+ {
+ if (nr)
+ {
+ if (inp_count == 0) break;
+ n = (4 - nr) * _nchan;
+ if (inp_data)
+ {
+ for (c = 0; c < _nchan; c++) pb [n + c] = inp_data [c];
+ inp_data += _nchan;
+ nz = 0;
+ }
+ else
+ {
+ for (c = 0; c < _nchan; c++) pb [n + c] = 0;
+ if (nz < 4) nz++;
+ }
+ nr--;
+ inp_count--;
+ }
+ else
+ {
+ n = _nchan;
+ if (out_data)
+ {
+ if (nz < 4)
+ {
+ a = ph;
+ b = 1 - a;
+ d = a * b / 2;
+ m0 = -d * b;
+ m1 = b + (3 * b - 1) * d;
+ m2 = a + (3 * a - 1) * d;
+ m3 = -d * a;
+ for (c = 0; c < n; c++)
+ {
+ *out_data++ = m0 * pb [0]
+ + m1 * pb [n]
+ + m2 * pb [2 * n]
+ + m3 * pb [3 * n];
+ pb++;
+ }
+ pb -= n;
+ }
+ else
+ {
+ for (c = 0; c < n; c++) *out_data++ = 0;
+ }
+ }
+ out_count--;
+
+ ph += _pstep;
+ if (ph >= 1.0)
+ {
+ nr = (unsigned int) floor (ph);
+ ph -= nr;
+ in += nr;
+ pb += nr * _nchan;
+ if (in >= _inmax)
+ {
+ memcpy (_buff, pb, (4 - nr) * _nchan * sizeof (float));
+ in = 0;
+ pb = _buff;
+ }
+ }
+ }
+ }
+
+ _index = in;
+ _nread = nr;
+ _nzero = nz;
+ _phase = ph;
+
+ return 0;
+}
+
diff --git a/libs/resampler-table.cc b/libs/resampler-table.cc
new file mode 100644
index 0000000..daaf9f3
--- /dev/null
+++ b/libs/resampler-table.cc
@@ -0,0 +1,161 @@
+// ----------------------------------------------------------------------------
+//
+// Copyright (C) 2006-2012 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// ----------------------------------------------------------------------------
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <zita-resampler/resampler-table.h>
+
+
+int zita_resampler_major_version (void)
+{
+ return ZITA_RESAMPLER_MAJOR_VERSION;
+}
+
+
+int zita_resampler_minor_version (void)
+{
+ return ZITA_RESAMPLER_MINOR_VERSION;
+}
+
+
+static double sinc (double x)
+{
+ x = fabs (x);
+ if (x < 1e-6) return 1.0;
+ x *= M_PI;
+ return sin (x) / x;
+}
+
+
+static double wind (double x)
+{
+ x = fabs (x);
+ if (x >= 1.0) return 0.0f;
+ x *= M_PI;
+ return 0.384 + 0.500 * cos (x) + 0.116 * cos (2 * x);
+}
+
+
+
+Resampler_table *Resampler_table::_list = 0;
+Resampler_mutex Resampler_table::_mutex;
+
+
+Resampler_table::Resampler_table (double fr, unsigned int hl, unsigned int np) :
+ _next (0),
+ _refc (0),
+ _fr (fr),
+ _hl (hl),
+ _np (np)
+{
+ unsigned int i, j;
+ double t;
+ float *p;
+
+ _ctab = new float [hl * (np + 1)];
+ p = _ctab;
+ for (j = 0; j <= np; j++)
+ {
+ t = (double) j / (double) np;
+ for (i = 0; i < hl; i++)
+ {
+ p [hl - i - 1] = (float)(fr * sinc (t * fr) * wind (t / hl));
+ t += 1;
+ }
+ p += hl;
+ }
+}
+
+
+Resampler_table::~Resampler_table (void)
+{
+ delete[] _ctab;
+}
+
+
+Resampler_table *Resampler_table::create (double fr, unsigned int hl, unsigned int np)
+{
+ Resampler_table *P;
+
+ _mutex.lock ();
+ P = _list;
+ while (P)
+ {
+ if ((fr >= P->_fr * 0.999) && (fr <= P->_fr * 1.001) && (hl == P->_hl) && (np == P->_np))
+ {
+ P->_refc++;
+ _mutex.unlock ();
+ return P;
+ }
+ P = P->_next;
+ }
+ P = new Resampler_table (fr, hl, np);
+ P->_refc = 1;
+ P->_next = _list;
+ _list = P;
+ _mutex.unlock ();
+ return P;
+}
+
+
+void Resampler_table::destroy (Resampler_table *T)
+{
+ Resampler_table *P, *Q;
+
+ _mutex.lock ();
+ if (T)
+ {
+ T->_refc--;
+ if (T->_refc == 0)
+ {
+ P = _list;
+ Q = 0;
+ while (P)
+ {
+ if (P == T)
+ {
+ if (Q) Q->_next = T->_next;
+ else _list = T->_next;
+ break;
+ }
+ Q = P;
+ P = P->_next;
+ }
+ delete T;
+ }
+ }
+ _mutex.unlock ();
+}
+
+
+void Resampler_table::print_list (void)
+{
+ Resampler_table *P;
+
+ printf ("Resampler table\n----\n");
+ for (P = _list; P; P = P->_next)
+ {
+ printf ("refc = %3d fr = %10.6lf hl = %4d np = %4d\n", P->_refc, P->_fr, P->_hl, P->_np);
+ }
+ printf ("----\n\n");
+}
+
diff --git a/libs/resampler.cc b/libs/resampler.cc
new file mode 100644
index 0000000..097acfd
--- /dev/null
+++ b/libs/resampler.cc
@@ -0,0 +1,263 @@
+// ----------------------------------------------------------------------------
+//
+// Copyright (C) 2006-2012 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// ----------------------------------------------------------------------------
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <zita-resampler/resampler.h>
+
+
+static unsigned int gcd (unsigned int a, unsigned int b)
+{
+ if (a == 0) return b;
+ if (b == 0) return a;
+ while (1)
+ {
+ if (a > b)
+ {
+ a = a % b;
+ if (a == 0) return b;
+ if (a == 1) return 1;
+ }
+ else
+ {
+ b = b % a;
+ if (b == 0) return a;
+ if (b == 1) return 1;
+ }
+ }
+ return 1;
+}
+
+
+Resampler::Resampler (void) :
+ _table (0),
+ _nchan (0),
+ _buff (0)
+{
+ reset ();
+}
+
+
+Resampler::~Resampler (void)
+{
+ clear ();
+}
+
+
+int Resampler::setup (unsigned int fs_inp,
+ unsigned int fs_out,
+ unsigned int nchan,
+ unsigned int hlen)
+{
+ if ((hlen < 8) || (hlen > 96)) return 1;
+ return setup (fs_inp, fs_out, nchan, hlen, 1.0 - 2.6 / hlen);
+}
+
+
+int Resampler::setup (unsigned int fs_inp,
+ unsigned int fs_out,
+ unsigned int nchan,
+ unsigned int hlen,
+ double frel)
+{
+ unsigned int g, h, k, n, s;
+ double r;
+ float *B = 0;
+ Resampler_table *T = 0;
+
+ k = s = 0;
+ if (fs_inp && fs_out && nchan)
+ {
+ r = (double) fs_out / (double) fs_inp;
+ g = gcd (fs_out, fs_inp);
+ n = fs_out / g;
+ s = fs_inp / g;
+ if ((16 * r >= 1) && (n <= 1000))
+ {
+ h = hlen;
+ k = 250;
+ if (r < 1)
+ {
+ frel *= r;
+ h = (unsigned int)(ceil (h / r));
+ k = (unsigned int)(ceil (k / r));
+ }
+ T = Resampler_table::create (frel, h, n);
+ B = new float [nchan * (2 * h - 1 + k)];
+ }
+ }
+ clear ();
+ if (T)
+ {
+ _table = T;
+ _buff = B;
+ _nchan = nchan;
+ _inmax = k;
+ _pstep = s;
+ return reset ();
+ }
+ else return 1;
+}
+
+
+void Resampler::clear (void)
+{
+ Resampler_table::destroy (_table);
+ delete[] _buff;
+ _buff = 0;
+ _table = 0;
+ _nchan = 0;
+ _inmax = 0;
+ _pstep = 0;
+ reset ();
+}
+
+
+double Resampler::inpdist (void) const
+{
+ if (!_table) return 0;
+ return (int)(_table->_hl + 1 - _nread) - (double)_phase / _table->_np;
+}
+
+
+int Resampler::inpsize (void) const
+{
+ if (!_table) return 0;
+ return 2 * _table->_hl;
+}
+
+
+int Resampler::reset (void)
+{
+ if (!_table) return 1;
+
+ inp_count = 0;
+ out_count = 0;
+ inp_data = 0;
+ out_data = 0;
+ _index = 0;
+ _nread = 0;
+ _nzero = 0;
+ _phase = 0;
+ if (_table)
+ {
+ _nread = 2 * _table->_hl;
+ return 0;
+ }
+ return 1;
+}
+
+
+int Resampler::process (void)
+{
+ unsigned int hl, ph, np, dp, in, nr, nz, i, n, c;
+ float *p1, *p2;
+
+ if (!_table) return 1;
+
+ hl = _table->_hl;
+ np = _table->_np;
+ dp = _pstep;
+ in = _index;
+ nr = _nread;
+ ph = _phase;
+ nz = _nzero;
+ n = (2 * hl - nr) * _nchan;
+ p1 = _buff + in * _nchan;
+ p2 = p1 + n;
+
+ while (out_count)
+ {
+ if (nr)
+ {
+ if (inp_count == 0) break;
+ if (inp_data)
+ {
+ for (c = 0; c < _nchan; c++) p2 [c] = inp_data [c];
+ inp_data += _nchan;
+ nz = 0;
+ }
+ else
+ {
+ for (c = 0; c < _nchan; c++) p2 [c] = 0;
+ if (nz < 2 * hl) nz++;
+ }
+ nr--;
+ p2 += _nchan;
+ inp_count--;
+ }
+ else
+ {
+ if (out_data)
+ {
+ if (nz < 2 * hl)
+ {
+ float *c1 = _table->_ctab + hl * ph;
+ float *c2 = _table->_ctab + hl * (np - ph);
+ for (c = 0; c < _nchan; c++)
+ {
+ float *q1 = p1 + c;
+ float *q2 = p2 + c;
+ float s = 1e-20f;
+ for (i = 0; i < hl; i++)
+ {
+ q2 -= _nchan;
+ s += *q1 * c1 [i] + *q2 * c2 [i];
+ q1 += _nchan;
+ }
+ *out_data++ = s - 1e-20f;
+ }
+ }
+ else
+ {
+ for (c = 0; c < _nchan; c++) *out_data++ = 0;
+ }
+ }
+ out_count--;
+
+ ph += dp;
+ if (ph >= np)
+ {
+ nr = ph / np;
+ ph -= nr * np;
+ in += nr;
+ p1 += nr * _nchan;;
+ if (in >= _inmax)
+ {
+ n = (2 * hl - nr) * _nchan;
+ memcpy (_buff, p1, n * sizeof (float));
+ in = 0;
+ p1 = _buff;
+ p2 = p1 + n;
+ }
+ }
+ }
+ }
+ _index = in;
+ _nread = nr;
+ _phase = ph;
+ _nzero = nz;
+
+ return 0;
+}
+
+
diff --git a/libs/vresampler.cc b/libs/vresampler.cc
new file mode 100644
index 0000000..c4e5ea3
--- /dev/null
+++ b/libs/vresampler.cc
@@ -0,0 +1,272 @@
+// ----------------------------------------------------------------------------
+//
+// Copyright (C) 2006-2013 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// ----------------------------------------------------------------------------
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <zita-resampler/vresampler.h>
+
+
+VResampler::VResampler (void) :
+ _table (0),
+ _nchan (0),
+ _buff (0),
+ _c1 (0),
+ _c2 (0)
+{
+ reset ();
+}
+
+
+VResampler::~VResampler (void)
+{
+ clear ();
+}
+
+
+int VResampler::setup (double ratio,
+ unsigned int nchan,
+ unsigned int hlen)
+{
+ if ((hlen < 8) || (hlen > 96) || (16 * ratio < 1) || (ratio > 256)) return 1;
+ return setup (ratio, nchan, hlen, 1.0 - 2.6 / hlen);
+}
+
+
+int VResampler::setup (double ratio,
+ unsigned int nchan,
+ unsigned int hlen,
+ double frel)
+{
+ unsigned int h, k, n;
+ double s;
+ Resampler_table *T = 0;
+
+ if (! nchan) return 1;
+ n = NPHASE;
+ s = n / ratio;
+ h = hlen;
+ k = 250;
+ if (ratio < 1)
+ {
+ frel *= ratio;
+ h = (unsigned int)(ceil (h / ratio));
+ k = (unsigned int)(ceil (k / ratio));
+ }
+ T = Resampler_table::create (frel, h, n);
+ clear ();
+ if (T)
+ {
+ _table = T;
+ _buff = new float [nchan * (2 * h - 1 + k)];
+ _c1 = new float [2 * h];
+ _c2 = new float [2 * h];
+ _nchan = nchan;
+ _inmax = k;
+ _ratio = ratio;
+ _pstep = s;
+ _qstep = s;
+ _wstep = 1;
+ return reset ();
+ }
+ else return 1;
+}
+
+
+void VResampler::clear (void)
+{
+ Resampler_table::destroy (_table);
+ delete[] _buff;
+ delete[] _c1;
+ delete[] _c2;
+ _buff = 0;
+ _c1 = 0;
+ _c2 = 0;
+ _table = 0;
+ _nchan = 0;
+ _inmax = 0;
+ _pstep = 0;
+ _qstep = 0;
+ _wstep = 1;
+ reset ();
+}
+
+
+void VResampler::set_phase (double p)
+{
+ if (!_table) return;
+ _phase = (p - floor (p)) * _table->_np;
+}
+
+
+void VResampler::set_rrfilt (double t)
+{
+ if (!_table) return;
+ _wstep = (t < 1) ? 1 : 1 - exp (-1 / t);
+}
+
+
+void VResampler::set_rratio (double r)
+{
+ if (!_table) return;
+ if (r > 16.0) r = 16.0;
+ if (r < 0.95) r = 0.95;
+ _qstep = _table->_np / (_ratio * r);
+}
+
+
+double VResampler::inpdist (void) const
+{
+ if (!_table) return 0;
+ return (int)(_table->_hl + 1 - _nread) - _phase / _table->_np;
+}
+
+
+int VResampler::inpsize (void) const
+{
+ if (!_table) return 0;
+ return 2 * _table->_hl;
+}
+
+
+int VResampler::reset (void)
+{
+ if (!_table) return 1;
+
+ inp_count = 0;
+ out_count = 0;
+ inp_data = 0;
+ out_data = 0;
+ _index = 0;
+ _phase = 0;
+ _nread = 2 * _table->_hl;
+ _nzero = 0;
+ return 0;
+}
+
+
+int VResampler::process (void)
+{
+ unsigned int k, np, in, nr, n, c;
+ int i, hl, nz;
+ double ph, dp, dd;
+ float a, b, *p1, *p2, *q1, *q2;
+
+ if (!_table) return 1;
+
+ hl = _table->_hl;
+ np = _table->_np;
+ in = _index;
+ nr = _nread;
+ nz = _nzero;
+ ph = _phase;
+ dp = _pstep;
+ n = (2 * hl - nr) * _nchan;
+ p1 = _buff + in * _nchan;
+ p2 = p1 + n;
+
+ while (out_count)
+ {
+ if (nr)
+ {
+ if (inp_count == 0) break;
+ if (inp_data)
+ {
+ for (c = 0; c < _nchan; c++) p2 [c] = inp_data [c];
+ inp_data += _nchan;
+ nz = 0;
+ }
+ else
+ {
+ for (c = 0; c < _nchan; c++) p2 [c] = 0;
+ if (nz < 2 * hl) nz++;
+ }
+ nr--;
+ p2 += _nchan;
+ inp_count--;
+ }
+ else
+ {
+ if (out_data)
+ {
+ if (nz < 2 * hl)
+ {
+ k = (unsigned int) ph;
+ b = (float)(ph - k);
+ a = 1.0f - b;
+ q1 = _table->_ctab + hl * k;
+ q2 = _table->_ctab + hl * (np - k);
+ for (i = 0; i < hl; i++)
+ {
+ _c1 [i] = a * q1 [i] + b * q1 [i + hl];
+ _c2 [i] = a * q2 [i] + b * q2 [i - hl];
+ }
+ for (c = 0; c < _nchan; c++)
+ {
+ q1 = p1 + c;
+ q2 = p2 + c;
+ a = 1e-25f;
+ for (i = 0; i < hl; i++)
+ {
+ q2 -= _nchan;
+ a += *q1 * _c1 [i] + *q2 * _c2 [i];
+ q1 += _nchan;
+ }
+ *out_data++ = a - 1e-25f;
+ }
+ }
+ else
+ {
+ for (c = 0; c < _nchan; c++) *out_data++ = 0;
+ }
+ }
+ out_count--;
+
+ dd = _qstep - dp;
+ if (fabs (dd) < 1e-30) dp = _qstep;
+ else dp += _wstep * dd;
+ ph += dp;
+ if (ph >= np)
+ {
+ nr = (unsigned int) floor( ph / np);
+ ph -= nr * np;;
+ in += nr;
+ p1 += nr * _nchan;;
+ if (in >= _inmax)
+ {
+ n = (2 * hl - nr) * _nchan;
+ memcpy (_buff, p1, n * sizeof (float));
+ in = 0;
+ p1 = _buff;
+ p2 = p1 + n;
+ }
+ }
+ }
+ }
+ _index = in;
+ _nread = nr;
+ _phase = ph;
+ _pstep = dp;
+ _nzero = nz;
+
+ return 0;
+}
+
diff --git a/libs/zita-resampler/cresampler.h b/libs/zita-resampler/cresampler.h
new file mode 100644
index 0000000..b51ed44
--- /dev/null
+++ b/libs/zita-resampler/cresampler.h
@@ -0,0 +1,65 @@
+// ----------------------------------------------------------------------------
+//
+// Copyright (C) 2013 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// ----------------------------------------------------------------------------
+
+
+#ifndef __CRESAMPLER_H
+#define __CRESAMPLER_H
+
+
+class CResampler
+{
+public:
+
+ CResampler (void);
+ ~CResampler (void);
+
+ int setup (double ratio,
+ unsigned int nchan);
+
+ void clear (void);
+ int reset (void);
+ int nchan (void) const { return _nchan; }
+ int inpsize (void) const;
+ double inpdist (void) const;
+ int process (void);
+
+ void set_ratio (double r);
+ void set_phase (double p);
+
+ unsigned int inp_count;
+ unsigned int out_count;
+ float *inp_data;
+ float *out_data;
+ void *inp_list;
+ void *out_list;
+
+private:
+
+ unsigned int _nchan;
+ unsigned int _inmax;
+ unsigned int _index;
+ unsigned int _nread;
+ unsigned int _nzero;
+ double _phase;
+ double _pstep;
+ float *_buff;
+};
+
+
+#endif
diff --git a/libs/zita-resampler/resampler-table.h b/libs/zita-resampler/resampler-table.h
new file mode 100644
index 0000000..22e694a
--- /dev/null
+++ b/libs/zita-resampler/resampler-table.h
@@ -0,0 +1,80 @@
+// ----------------------------------------------------------------------------
+//
+// Copyright (C) 2006-2012 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// ----------------------------------------------------------------------------
+
+
+#ifndef __RESAMPLER_TABLE_H
+#define __RESAMPLER_TABLE_H
+
+
+#include <pthread.h>
+
+
+#define ZITA_RESAMPLER_MAJOR_VERSION 1
+#define ZITA_RESAMPLER_MINOR_VERSION 6
+
+
+extern int zita_resampler_major_version (void);
+extern int zita_resampler_minor_version (void);
+
+
+class Resampler_mutex
+{
+private:
+
+ friend class Resampler_table;
+
+ Resampler_mutex (void) { pthread_mutex_init (&_mutex, 0); }
+ ~Resampler_mutex (void) { pthread_mutex_destroy (&_mutex); }
+ void lock (void) { pthread_mutex_lock (&_mutex); }
+ void unlock (void) { pthread_mutex_unlock (&_mutex); }
+
+ pthread_mutex_t _mutex;
+};
+
+
+class Resampler_table
+{
+public:
+
+ static void print_list (void);
+
+private:
+
+ Resampler_table (double fr, unsigned int hl, unsigned int np);
+ ~Resampler_table (void);
+
+ friend class Resampler;
+ friend class VResampler;
+
+ Resampler_table *_next;
+ unsigned int _refc;
+ float *_ctab;
+ double _fr;
+ unsigned int _hl;
+ unsigned int _np;
+
+ static Resampler_table *create (double fr, unsigned int hl, unsigned int np);
+ static void destroy (Resampler_table *T);
+
+ static Resampler_table *_list;
+ static Resampler_mutex _mutex;
+};
+
+
+#endif
diff --git a/libs/zita-resampler/resampler.h b/libs/zita-resampler/resampler.h
new file mode 100644
index 0000000..5dbff4f
--- /dev/null
+++ b/libs/zita-resampler/resampler.h
@@ -0,0 +1,76 @@
+// ----------------------------------------------------------------------------
+//
+// Copyright (C) 2006-2012 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// ----------------------------------------------------------------------------
+
+
+#ifndef __RESAMPLER_H
+#define __RESAMPLER_H
+
+
+#include <zita-resampler/resampler-table.h>
+
+
+class Resampler
+{
+public:
+
+ Resampler (void);
+ ~Resampler (void);
+
+ int setup (unsigned int fs_inp,
+ unsigned int fs_out,
+ unsigned int nchan,
+ unsigned int hlen);
+
+ int setup (unsigned int fs_inp,
+ unsigned int fs_out,
+ unsigned int nchan,
+ unsigned int hlen,
+ double frel);
+
+ void clear (void);
+ int reset (void);
+ int nchan (void) const { return _nchan; }
+ int filtlen (void) const { return inpsize (); } // Deprecated
+ int inpsize (void) const;
+ double inpdist (void) const;
+ int process (void);
+
+ unsigned int inp_count;
+ unsigned int out_count;
+ float *inp_data;
+ float *out_data;
+ void *inp_list;
+ void *out_list;
+
+private:
+
+ Resampler_table *_table;
+ unsigned int _nchan;
+ unsigned int _inmax;
+ unsigned int _index;
+ unsigned int _nread;
+ unsigned int _nzero;
+ unsigned int _phase;
+ unsigned int _pstep;
+ float *_buff;
+ void *_dummy [8];
+};
+
+
+#endif
diff --git a/libs/zita-resampler/vresampler.h b/libs/zita-resampler/vresampler.h
new file mode 100644
index 0000000..95fefc4
--- /dev/null
+++ b/libs/zita-resampler/vresampler.h
@@ -0,0 +1,84 @@
+// ----------------------------------------------------------------------------
+//
+// Copyright (C) 2006-2012 Fons Adriaensen <fons@linuxaudio.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// ----------------------------------------------------------------------------
+
+
+#ifndef __VRESAMPLER_H
+#define __VRESAMPLER_H
+
+
+#include <zita-resampler/resampler-table.h>
+
+
+class VResampler
+{
+public:
+
+ VResampler (void);
+ ~VResampler (void);
+
+ int setup (double ratio,
+ unsigned int nchan,
+ unsigned int hlen);
+
+ int setup (double ratio,
+ unsigned int nchan,
+ unsigned int hlen,
+ double frel);
+
+ void clear (void);
+ int reset (void);
+ int nchan (void) const { return _nchan; }
+ int inpsize (void) const;
+ double inpdist (void) const;
+ int process (void);
+
+ void set_phase (double p);
+ void set_rrfilt (double t);
+ void set_rratio (double r);
+
+ unsigned int inp_count;
+ unsigned int out_count;
+ float *inp_data;
+ float *out_data;
+ void *inp_list;
+ void *out_list;
+
+private:
+
+ enum { NPHASE = 256 };
+
+ Resampler_table *_table;
+ unsigned int _nchan;
+ unsigned int _inmax;
+ unsigned int _index;
+ unsigned int _nread;
+ unsigned int _nzero;
+ double _ratio;
+ double _phase;
+ double _pstep;
+ double _qstep;
+ double _wstep;
+ float *_buff;
+ float *_c1;
+ float *_c2;
+ void *_dummy [8];
+};
+
+
+#endif