* AUTHORS:
authorjtorra <n770galaxy@gmail.com>
Wed, 9 Jul 2008 09:52:20 +0000 (09:52 +0000)
committerjtorra <n770galaxy@gmail.com>
Wed, 9 Jul 2008 09:52:20 +0000 (09:52 +0000)
* COPYING:
* INSTALL:
* Makefile.am:
* NEWS:
* README:
* autogen.sh:
* configure.ac:
* debian/Makefile.am:
* debian/changelog:
* debian/control:
* debian/copyright:
* debian/files:
* debian/postinst:
* debian/rules:
* debian/substvars:
* debian/tuner.links:
* m4/Makefile.am:
* m4/as-compiler-flag.m4:
* m4/as-version.m4:
* src/Makefile.am:
* src/_kiss_fft_guts.h:
* src/demo-audiotest.c:
* src/demo-tuner.c:
* src/gstpitch.c:
* src/gstpitch.h:
* src/gsttonesrc.c:
* src/gsttonesrc.h:
* src/kiss_fft.c:
* src/kiss_fft.h:
* src/tuner.c:
* src/tuner26.png:
* src/tuner40.png:
* src/tuner64.png:
* tuner.desktop:
* debian/rules (svn:executable):
* src/tuner64.png (svn:mime-type):
* src/tuner26.png (svn:mime-type):
* src/tuner40.png (svn:mime-type):
* autogen.sh (svn:executable):
* m4/as-compiler-flag.m4 (added):
* m4/as-version.m4 (added):
* m4/Makefile.am (added):
* debian/control (added):
* debian/files (added):
* debian/postinst (added):
* debian/changelog (added):
* debian/copyright (added):
* debian/Makefile.am (added):
* debian/rules (added):
* debian/tuner.links (added):
* debian/substvars (added):
* configure.ac (added):
* AUTHORS (added):
* tuner.desktop (added):
* INSTALL (added):
* src/_kiss_fft_guts.h (added):
* src/demo-tuner.c (added):
* src/gsttonesrc.h (added):
* src/demo-audiotest.c (added):
* src/tuner40.png (added):
* src/gstpitch.c (added):
* src/tuner26.png (added):
* src/kiss_fft.c (added):
* src/Makefile.am (added):
* src/tuner64.png (added):
* src/gstpitch.h (added):
* src/gsttonesrc.c (added):
* src/kiss_fft.h (added):
* src/tuner.c (added):
* ChangeLog (added):
* COPYING (added):
* Makefile.am (added):
* autogen.sh (added):
* NEWS (added):
* README (added):
Initial import to garage svn.

git-svn-id: file:///svnroot/tunertool/trunk@4 4bb5ff34-d565-4b58-9699-12000fa1827a

36 files changed:
AUTHORS [new file with mode: 0644]
COPYING [new file with mode: 0644]
ChangeLog [new file with mode: 0644]
INSTALL [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
NEWS [new file with mode: 0644]
README [new file with mode: 0644]
autogen.sh [new file with mode: 0755]
configure.ac [new file with mode: 0644]
debian/Makefile.am [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/copyright [new file with mode: 0644]
debian/files [new file with mode: 0644]
debian/postinst [new file with mode: 0644]
debian/rules [new file with mode: 0755]
debian/substvars [new file with mode: 0644]
debian/tuner.links [new file with mode: 0644]
m4/Makefile.am [new file with mode: 0644]
m4/as-compiler-flag.m4 [new file with mode: 0644]
m4/as-version.m4 [new file with mode: 0644]
src/Makefile.am [new file with mode: 0644]
src/_kiss_fft_guts.h [new file with mode: 0644]
src/demo-audiotest.c [new file with mode: 0644]
src/demo-tuner.c [new file with mode: 0644]
src/gstpitch.c [new file with mode: 0644]
src/gstpitch.h [new file with mode: 0644]
src/gsttonesrc.c [new file with mode: 0644]
src/gsttonesrc.h [new file with mode: 0644]
src/kiss_fft.c [new file with mode: 0644]
src/kiss_fft.h [new file with mode: 0644]
src/tuner.c [new file with mode: 0644]
src/tuner26.png [new file with mode: 0644]
src/tuner40.png [new file with mode: 0644]
src/tuner64.png [new file with mode: 0644]
tuner.desktop [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..49fa5b4
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Josep Torra <j.torra@telefonica.net>
diff --git a/COPYING b/COPYING
new file mode 100644 (file)
index 0000000..87d2f27
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,447 @@
+GNU LESSER GENERAL PUBLIC LICENSE
+Version 2.1, February 1999
+
+
+Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+Everyone is permitted to copy and distribute verbatim copies
+of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+as the successor of the GNU Library Public License, version 2, hence
+the version number 2.1.]
+
+Preamble
+The licenses for most software are designed to take away your freedom
+to share and change it. By contrast, the GNU General Public Licenses
+are intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.
+
+This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations
+below.
+
+When we speak of free software, we are referring to freedom of use, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish); that you receive source code or can get it
+if you want it; that you can change the software and use pieces of it
+in new free programs; and that you are informed that you can do these
+things.
+
+To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+For example, if you distribute copies of the library, whether gratis or
+for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+To protect each distributor, we want to make it very clear that there
+is no warranty for the free library. Also, if the library is modified
+by someone else and passed on, the recipients should know that what
+they have is not the original version, so that the original author's
+reputation will not be affected by problems that might be introduced by
+others.
+
+Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that any
+patent license obtained for a version of the library must be consistent
+with the full freedom of use specified in this license.
+
+Most GNU software, including some libraries, is covered by the ordinary
+GNU General Public License. This license, the GNU Lesser General Public
+License, applies to certain designated libraries, and is quite
+different from the ordinary General Public License. We use this license
+for certain libraries in order to permit linking those libraries into
+non-free programs.
+
+When a program is linked with a library, whether statically or using a
+shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less of
+an advantage over competing non-free programs. These disadvantages are
+the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it
+becomes a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free library
+does the same job as widely used non-free libraries. In this case,
+there is little to gain by limiting the free library to free software
+only, so we use the Lesser General Public License.
+
+In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of free
+software. For example, permission to use the GNU C Library in non-free
+programs enables many more people to use the whole GNU operating
+system, as well as its variant, the GNU/Linux operating system.
+
+Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run that
+program using a modified version of the Library.
+
+The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+
+TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or other
+authorized party saying it may be distributed under the terms of this
+Lesser General Public License (also called "this License"). Each
+licensee is addressed as "you".
+
+A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+The "Library", below, refers to any such software library or work which
+has been distributed under these terms. A "work based on the Library"
+means either the Library or any derivative work under copyright law:
+that is to say, a work containing the Library or a portion of it,
+either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+"Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control
+compilation and installation of the library.
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of running
+a program using the Library is not restricted, and output from such a
+program is covered only if its contents constitute a work based on the
+Library (independent of the use of the Library in a tool for writing
+it). Whether that is true depends on what the Library does and what the
+program that uses the Library does.
+
+1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and distribute a copy of this License along with the Library.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+2. You may modify your copy or copies of the Library or any portion of
+it, thus forming a work based on the Library, and copy and distribute
+such modifications or work under the terms of Section 1 above, provided
+that you also meet all of these conditions:
+
+
+a) The modified work must itself be a software library.
+b) You must cause the files modified to carry prominent notices stating
+that you changed the files and the date of any change.
+c) You must cause the whole of the work to be licensed at no charge to
+all third parties under the terms of this License.
+d) If a facility in the modified Library refers to a function or a
+table of data to be supplied by an application program that uses the
+facility, other than as an argument passed when the facility is
+invoked, then you must make a good faith effort to ensure that, in the
+event an application does not supply such function or table, the
+facility still operates, and performs whatever part of its purpose
+remains meaningful.
+(For example, a function in a library to compute square roots has a
+purpose that is entirely well-defined independent of the application.
+Therefore, Subsection 2d requires that any application-supplied
+function or table used by this function must be optional: if the
+application does not supply it, the square root function must still
+compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of a
+storage or distribution medium does not bring the other work under the
+scope of this License.
+
+3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+Once this change is made in a given copy, it is irreversible for that
+copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+This option is useful when you wish to copy part of the code of the
+Library into a program that is not a library.
+
+4. You may copy and distribute the Library (or a portion or derivative
+of it, under Section 2) in object code or executable form under the
+terms of Sections 1 and 2 above provided that you accompany it with the
+complete corresponding machine-readable source code, which must be
+distributed under the terms of Sections 1 and 2 above on a medium
+customarily used for software interchange.
+
+If distribution of object code is made by offering access to copy from
+a designated place, then offering equivalent access to copy the source
+code from the same place satisfies the requirement to distribute the
+source code, even though third parties are not compelled to copy the
+source along with the object code.
+
+5. A program that contains no derivative of any portion of the Library,
+but is designed to work with the Library by being compiled or linked
+with it, is called a "work that uses the Library". Such a work, in
+isolation, is not a derivative work of the Library, and therefore falls
+outside the scope of this License.
+
+However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License. Section
+6 states terms for distribution of such executables.
+
+When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+If such an object file uses only numerical parameters, data structure
+layouts and accessors, and small macros and small inline functions (ten
+lines or less in length), then the use of the object file is
+unrestricted, regardless of whether it is legally a derivative work.
+(Executables containing this object code plus portions of the Library
+will still fall under Section 6.)
+
+Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6, whether
+or not they are linked directly with the Library itself.
+
+6. As an exception to the Sections above, you may also combine or link
+a "work that uses the Library" with the Library to produce a work
+containing portions of the Library, and distribute that work under
+terms of your choice, provided that the terms permit modification of
+the work for the customer's own use and reverse engineering for
+debugging such modifications.
+
+You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+
+a) Accompany the work with the complete corresponding machine-readable
+source code for the Library including whatever changes were used in the
+work (which must be distributed under Sections 1 and 2 above); and, if
+the work is an executable linked with the Library, with the complete
+machine-readable "work that uses the Library", as object code and/or
+source code, so that the user can modify the Library and then relink to
+produce a modified executable containing the modified Library. (It is
+understood that the user who changes the contents of definitions files
+in the Library will not necessarily be able to recompile the
+application to use the modified definitions.)
+b) Use a suitable shared library mechanism for linking with the
+Library. A suitable mechanism is one that (1) uses at run time a copy
+of the library already present on the user's computer system, rather
+than copying library functions into the executable, and (2) will
+operate properly with a modified version of the library, if the user
+installs one, as long as the modified version is interface-compatible
+with the version that the work was made with.
+c) Accompany the work with a written offer, valid for at least three
+years, to give the same user the materials specified in Subsection 6a,
+above, for a charge no more than the cost of performing this
+distribution.
+d) If distribution of the work is made by offering access to copy from
+a designated place, offer equivalent access to copy the above specified
+materials from the same place.
+e) Verify that the user has already received a copy of these materials
+or that you have already sent this user a copy.
+For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies the
+executable.
+
+It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise permitted,
+and provided that you do these two things:
+
+
+a) Accompany the combined library with a copy of the same work based on
+the Library, uncombined with any other library facilities. This must be
+distributed under the terms of the Sections above.
+b) Give prominent notice with the combined library of the fact that
+part of it is a work based on the Library, and explaining where to find
+the accompanying uncombined form of the same work.
+8. You may not copy, modify, sublicense, link with, or distribute the
+Library except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense, link with, or distribute the
+Library is void, and will automatically terminate your rights under
+this License. However, parties who have received copies, or rights,
+from you under this License will not have their licenses terminated so
+long as such parties remain in full compliance.
+
+9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying the
+Library or works based on it.
+
+10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent license
+would not permit royalty-free redistribution of the Library by all
+those who receive copies directly or indirectly through you, then the
+only way you could satisfy both it and this License would be to refrain
+entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply, and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is implemented
+by public license practices. Many people have made generous
+contributions to the wide range of software distributed through that
+system in reliance on consistent application of that system; it is up
+to the author/donor to decide if he or she is willing to distribute
+software through any other system and a licensee cannot impose that
+choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may
+add an explicit geographical distribution limitation excluding those
+countries, so that distribution is permitted only in or among countries
+not thus excluded. In such case, this License incorporates the
+limitation as if written in the body of this License.
+
+13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time. Such
+new versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a license
+version number, you may choose any version ever published by the Free
+Software Foundation.
+
+14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free Software
+Foundation; we sometimes make exceptions for this. Our decision will be
+guided by the two goals of preserving the free status of all
+derivatives of our free software and of promoting the sharing and reuse
+of software generally.
+
+NO WARRANTY
+
+15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND,
+EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
+ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH
+YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
+NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+
+END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/ChangeLog b/ChangeLog
new file mode 100644 (file)
index 0000000..4acf1a2
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,80 @@
+2008-07-09  Josep Torra,  <j.torra@telefonica.net>
+
+       * AUTHORS:
+       * COPYING:
+       * INSTALL:
+       * Makefile.am:
+       * NEWS:
+       * README:
+       * autogen.sh:
+       * configure.ac:
+       * debian/Makefile.am:
+       * debian/changelog:
+       * debian/control:
+       * debian/copyright:
+       * debian/files:
+       * debian/postinst:
+       * debian/rules:
+       * debian/substvars:
+       * debian/tuner.links:
+       * m4/Makefile.am:
+       * m4/as-compiler-flag.m4:
+       * m4/as-version.m4:
+       * src/Makefile.am:
+       * src/_kiss_fft_guts.h:
+       * src/demo-audiotest.c:
+       * src/demo-tuner.c:
+       * src/gstpitch.c:
+       * src/gstpitch.h:
+       * src/gsttonesrc.c:
+       * src/gsttonesrc.h:
+       * src/kiss_fft.c:
+       * src/kiss_fft.h:
+       * src/tuner.c:
+       * src/tuner26.png:
+       * src/tuner40.png:
+       * src/tuner64.png:
+       * tuner.desktop:
+       * debian/rules (svn:executable):
+       * src/tuner64.png (svn:mime-type):
+       * src/tuner26.png (svn:mime-type):
+       * src/tuner40.png (svn:mime-type):
+       * autogen.sh (svn:executable):
+       * m4/as-compiler-flag.m4 (added):
+       * m4/as-version.m4 (added):
+       * m4/Makefile.am (added):
+       * debian/control (added):
+       * debian/files (added):
+       * debian/postinst (added):
+       * debian/changelog (added):
+       * debian/copyright (added):
+       * debian/Makefile.am (added):
+       * debian/rules (added):
+       * debian/tuner.links (added):
+       * debian/substvars (added):
+       * configure.ac (added):
+       * AUTHORS (added):
+       * tuner.desktop (added):
+       * INSTALL (added):
+       * src/_kiss_fft_guts.h (added):
+       * src/demo-tuner.c (added):
+       * src/gsttonesrc.h (added):
+       * src/demo-audiotest.c (added):
+       * src/tuner40.png (added):
+       * src/gstpitch.c (added):
+       * src/tuner26.png (added):
+       * src/kiss_fft.c (added):
+       * src/Makefile.am (added):
+       * src/tuner64.png (added):
+       * src/gstpitch.h (added):
+       * src/gsttonesrc.c (added):
+       * src/kiss_fft.h (added):
+       * src/tuner.c (added):
+       * ChangeLog (added):
+       * COPYING (added):
+       * Makefile.am (added):
+       * autogen.sh (added):
+       * NEWS (added):
+       * README (added):
+
+       Initial import to garage svn.
diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..23e5f25
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,236 @@
+Installation Instructions
+*************************
+
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free
+Software Foundation, Inc.
+
+This file is free documentation; the Free Software Foundation gives
+unlimited permission to copy, distribute and modify it.
+
+Basic Installation
+==================
+
+These are generic installation instructions.
+
+   The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation.  It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions.  Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, and a
+file `config.log' containing compiler output (useful mainly for
+debugging `configure').
+
+   It can also use an optional file (typically called `config.cache'
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
+the results of its tests to speed up reconfiguring.  (Caching is
+disabled by default to prevent problems with accidental use of stale
+cache files.)
+
+   If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release.  If you are using the cache, and at
+some point `config.cache' contains results you don't want to keep, you
+may remove or edit it.
+
+   The file `configure.ac' (or `configure.in') is used to create
+`configure' by a program called `autoconf'.  You only need
+`configure.ac' if you want to change it or regenerate `configure' using
+a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+  1. `cd' to the directory containing the package's source code and type
+     `./configure' to configure the package for your system.  If you're
+     using `csh' on an old version of System V, you might need to type
+     `sh ./configure' instead to prevent `csh' from trying to execute
+     `configure' itself.
+
+     Running `configure' takes awhile.  While running, it prints some
+     messages telling which features it is checking for.
+
+  2. Type `make' to compile the package.
+
+  3. Optionally, type `make check' to run any self-tests that come with
+     the package.
+
+  4. Type `make install' to install the programs and any data files and
+     documentation.
+
+  5. You can remove the program binaries and object files from the
+     source code directory by typing `make clean'.  To also remove the
+     files that `configure' created (so you can compile the package for
+     a different kind of computer), type `make distclean'.  There is
+     also a `make maintainer-clean' target, but that is intended mainly
+     for the package's developers.  If you use it, you may have to get
+     all sorts of other programs in order to regenerate files that came
+     with the distribution.
+
+Compilers and Options
+=====================
+
+Some systems require unusual options for compilation or linking that the
+`configure' script does not know about.  Run `./configure --help' for
+details on some of the pertinent environment variables.
+
+   You can give `configure' initial values for configuration parameters
+by setting variables in the command line or in the environment.  Here
+is an example:
+
+     ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
+
+   *Note Defining Variables::, for more details.
+
+Compiling For Multiple Architectures
+====================================
+
+You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory.  To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'.  `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script.  `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+   If you have to use a `make' that does not support the `VPATH'
+variable, you have to compile the package for one architecture at a
+time in the source code directory.  After you have installed the
+package for one architecture, use `make distclean' before reconfiguring
+for another architecture.
+
+Installation Names
+==================
+
+By default, `make install' installs the package's commands under
+`/usr/local/bin', include files under `/usr/local/include', etc.  You
+can specify an installation prefix other than `/usr/local' by giving
+`configure' the option `--prefix=PREFIX'.
+
+   You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files.  If you
+pass the option `--exec-prefix=PREFIX' to `configure', the package uses
+PREFIX as the prefix for installing programs and libraries.
+Documentation and other data files still use the regular prefix.
+
+   In addition, if you use an unusual directory layout you can give
+options like `--bindir=DIR' to specify different values for particular
+kinds of files.  Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+   If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System).  The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+   For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+There may be some features `configure' cannot figure out automatically,
+but needs to determine by the type of machine the package will run on.
+Usually, assuming the package is built to be run on the _same_
+architectures, `configure' can figure that out, but if it prints a
+message saying it cannot guess the machine type, give it the
+`--build=TYPE' option.  TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name which has the form:
+
+     CPU-COMPANY-SYSTEM
+
+where SYSTEM can have one of these forms:
+
+     OS KERNEL-OS
+
+   See the file `config.sub' for the possible values of each field.  If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the machine type.
+
+   If you are _building_ compiler tools for cross-compiling, you should
+use the option `--target=TYPE' to select the type of system they will
+produce code for.
+
+   If you want to _use_ a cross compiler, that generates code for a
+platform different from the build platform, you should specify the
+"host" platform (i.e., that on which the generated programs will
+eventually be run) with `--host=TYPE'.
+
+Sharing Defaults
+================
+
+If you want to set default values for `configure' scripts to share, you
+can create a site shell script called `config.site' that gives default
+values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists.  Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Defining Variables
+==================
+
+Variables not defined in a site shell script can be set in the
+environment passed to `configure'.  However, some packages may run
+configure again during the build, and the customized values of these
+variables may be lost.  In order to avoid this problem, you should set
+them in the `configure' command line, using `VAR=value'.  For example:
+
+     ./configure CC=/usr/local2/bin/gcc
+
+causes the specified `gcc' to be used as the C compiler (unless it is
+overridden in the site shell script).  Here is a another example:
+
+     /bin/bash ./configure CONFIG_SHELL=/bin/bash
+
+Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent
+configuration-related scripts to be executed by `/bin/bash'.
+
+`configure' Invocation
+======================
+
+`configure' recognizes the following options to control how it operates.
+
+`--help'
+`-h'
+     Print a summary of the options to `configure', and exit.
+
+`--version'
+`-V'
+     Print the version of Autoconf used to generate the `configure'
+     script, and exit.
+
+`--cache-file=FILE'
+     Enable the cache: use and save the results of the tests in FILE,
+     traditionally `config.cache'.  FILE defaults to `/dev/null' to
+     disable caching.
+
+`--config-cache'
+`-C'
+     Alias for `--cache-file=config.cache'.
+
+`--quiet'
+`--silent'
+`-q'
+     Do not print messages saying which checks are being made.  To
+     suppress all normal output, redirect it to `/dev/null' (any error
+     messages will still be shown).
+
+`--srcdir=DIR'
+     Look for the package's source code in directory DIR.  Usually
+     `configure' can determine that directory automatically.
+
+`configure' also accepts some other, not widely useful, options.  Run
+`configure --help' for more details.
+
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..9ac2ef6
--- /dev/null
@@ -0,0 +1,3 @@
+SUBDIRS = m4 debian src 
+
+EXTRA_DIST = autogen.sh gst-autogen.sh tuner.desktop
diff --git a/NEWS b/NEWS
new file mode 100644 (file)
index 0000000..3474a99
--- /dev/null
+++ b/NEWS
@@ -0,0 +1 @@
+Nothing much yet.
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..5e2ff17
--- /dev/null
+++ b/README
@@ -0,0 +1,13 @@
+Tuner is a simple tool to help tuning instruments.
+
+It's based on gstreamer and uses kissfft to perform a FFT on the signal
+captured on the microphone, extract the fundamental frequency and
+correlate it with a table that associate frequencies and musical
+tones.
+
+It was primarilly written as a self introductory project on gstreamer.
+
+Enjoy with this in your tablet :)
+
+Josep Torra <j.torra@telefonica.net>
+
diff --git a/autogen.sh b/autogen.sh
new file mode 100755 (executable)
index 0000000..9d84a03
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/sh
+# you can either set the environment variables AUTOCONF and AUTOMAKE
+# to the right versions, or leave them unset and get the RedHat 7.3 defaults
+
+DIE=0
+package=gst-plugin
+srcfile=src/main.c
+
+# autogen.sh helper functions (copied from GStreamer's common/ CVS module)
+if test ! -f ./gst-autogen.sh;
+then
+  echo There is something wrong with your source tree.
+  echo You are either missing ./gst-autogen.sh or not
+  echo running autogen.sh from the top-level source
+  echo directory.
+  exit 1
+fi
+. ./gst-autogen.sh
+
+CONFIGURE_DEF_OPT='--enable-maintainer-mode --enable-debug'
+
+autogen_options $@
+
+echo -n "+ check for build tools"
+if test ! -z "$NOCHECK"; then echo " skipped"; else  echo; fi
+version_check "autoconf" "$AUTOCONF autoconf autoconf259 autoconf257 autoconf-2.54 autoconf-2.53 autoconf-2.52" \
+              "ftp://ftp.gnu.org/pub/gnu/autoconf/" 2 52 || DIE=1
+version_check "automake" "$AUTOMAKE automake automake-1.9 automake19 automake-1.7 automake-1.6 automake-1.5" \
+              "ftp://ftp.gnu.org/pub/gnu/automake/" 1 7 || DIE=1
+###version_check "autopoint" "autopoint" \
+###              "ftp://ftp.gnu.org/pub/gnu/gettext/" 0 11 5 || DIE=1
+version_check "libtoolize" "$LIBTOOLIZE libtoolize glibtoolize" \
+              "ftp://ftp.gnu.org/pub/gnu/libtool/" 1 5 0 || DIE=1
+version_check "pkg-config" "" \
+              "http://www.freedesktop.org/software/pkgconfig" 0 8 0 || DIE=1
+
+die_check $DIE
+
+autoconf_2_52d_check || DIE=1
+aclocal_check || DIE=1
+autoheader_check || DIE=1
+
+die_check $DIE
+
+# if no arguments specified then this will be printed
+if test -z "$*"; then
+  echo "+ checking for autogen.sh options"
+  echo "  This autogen script will automatically run ./configure as:"
+  echo "  ./configure $CONFIGURE_DEF_OPT"
+  echo "  To pass any additional options, please specify them on the $0"
+  echo "  command line."
+fi
+
+tool_run "$aclocal" "-I m4/ $ACLOCAL_FLAGS"
+tool_run "$libtoolize" "--copy --force"
+tool_run "$autoheader"
+tool_run "$autoconf"
+tool_run "$automake" "-a -c"
+
+# if enable exists, add an -enable option for each of the lines in that file
+if test -f enable; then
+  for a in `cat enable`; do
+    CONFIGURE_FILE_OPT="--enable-$a"
+  done
+fi
+
+# if disable exists, add an -disable option for each of the lines in that file
+if test -f disable; then
+  for a in `cat disable`; do
+    CONFIGURE_FILE_OPT="$CONFIGURE_FILE_OPT --disable-$a"
+  done
+fi
+
+test -n "$NOCONFIGURE" && {
+  echo "+ skipping configure stage for package $package, as requested."
+  echo "+ autogen.sh done."
+  exit 0
+}
+
+echo "+ running configure ... "
+test ! -z "$CONFIGURE_DEF_OPT" && echo "  ./configure default flags: $CONFIGURE_DEF_OPT"
+test ! -z "$CONFIGURE_EXT_OPT" && echo "  ./configure external flags: $CONFIGURE_EXT_OPT"
+test ! -z "$CONFIGURE_FILE_OPT" && echo "  ./configure enable/disable flags: $CONFIGURE_FILE_OPT"
+echo
+
+./configure $CONFIGURE_DEF_OPT $CONFIGURE_EXT_OPT $CONFIGURE_FILE_OPT || {
+        echo "  configure failed"
+        exit 1
+}
+
+echo "Now type 'make' to compile $package."
diff --git a/configure.ac b/configure.ac
new file mode 100644 (file)
index 0000000..51e0aa5
--- /dev/null
@@ -0,0 +1,206 @@
+AC_INIT
+
+dnl versions of gstreamer and plugins-base
+GST_MAJORMINOR=0.10
+GST_REQUIRED=0.10.0
+GSTPB_REQUIRED=0.10.0
+
+dnl fill in your package name and version here
+dnl the fourth (nano) number should be 0 for a release, 1 for CVS,
+dnl and 2... for a prerelease
+
+dnl when going to/from release please set the nano correctly !
+dnl releases only do Wall, cvs and prerelease does Werror too
+AS_VERSION(tuner, GST_PLUGIN_VERSION, 0, 0, 4, 0,
+    GST_PLUGIN_CVS="no", GST_PLUGIN_CVS="yes")
+
+dnl AM_MAINTAINER_MODE provides the option to enable maintainer mode
+AM_MAINTAINER_MODE
+
+AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
+
+dnl make aclocal work in maintainer mode
+AC_SUBST(ACLOCAL_AMFLAGS, "-I m4")
+
+AM_CONFIG_HEADER(config.h)
+
+dnl check for tools
+AC_PROG_CC
+AC_PROG_LIBTOOL
+
+
+dnl Enable Hildon GUI
+AC_ARG_WITH(hildon,
+    AC_HELP_STRING([--with-hildon],
+        [Turn on/off use of Hildon GUI (default=no)]),
+        [if test "x$withval" = "xyes"; then test_hildon=true; fi])
+
+dnl Enable Maemo specific issues
+AC_ARG_WITH(maemo,
+    AC_HELP_STRING([--with-maemo],
+        [Turn on/off use of Maemo related code (default=no)]),
+        [if test "x$withval" = "xyes"; then enable_maemo=true; fi])
+
+
+dnl decide on error flags
+AS_COMPILER_FLAG(-Wall, GST_WALL="yes", GST_WALL="no")
+                                                                                
+if test "x$GST_WALL" = "xyes"; then
+   GST_ERROR="$GST_ERROR -Wall"
+                                                                                
+   if test "x$GST_CVS" = "xyes"; then
+     AS_COMPILER_FLAG(-Werror,GST_ERROR="$GST_ERROR -Werror",GST_ERROR="$GST_ERROR")
+   fi
+fi
+
+dnl Check for pkgconfig first
+AC_CHECK_PROG(HAVE_PKGCONFIG, pkg-config, yes, no)
+
+dnl Give error and exit if we don't have pkgconfig
+if test "x$HAVE_PKGCONFIG" = "xno"; then
+  AC_MSG_ERROR(you need to have pkgconfig installed !)
+fi
+
+dnl Now we're ready to ask for gstreamer libs and cflags
+dnl And we can also ask for the right version of gstreamer
+
+
+PKG_CHECK_MODULES(GST, \
+  gstreamer-$GST_MAJORMINOR >= $GST_REQUIRED,
+  HAVE_GST=yes,HAVE_GST=no)
+
+dnl Give error and exit if we don't have gstreamer
+if test "x$HAVE_GST" = "xno"; then
+  AC_MSG_ERROR(you need gstreamer development packages installed !)
+fi
+
+
+dnl Check for Maemo required packages
+
+if test "x$enable_maemo" = "xtrue"; then
+  test_hildon=true
+  AC_DEFINE(MAEMO, 1, [Turn on Maemo dependecies])
+fi
+
+if test "x$test_hildon" = "xtrue"; then
+  dnl try if hildon is available in the form previous IT2K8
+  PKG_CHECK_MODULES(HILDON, hildon-libs >= 0.12.0,
+    HAVE_HILDON=yes, HAVE_HILDON=no)
+
+  if test "x$HAVE_HILDON" = "xno"; then
+    dnl if fail try for IT2K8
+    PKG_CHECK_MODULES(HILDON, hildon-1 >= 0.9.9,
+      HAVE_HILDON=yes, HAVE_HILDON=no)
+    AC_DEFINE(HILDON, 1, [Version of hildon libraries])
+  else
+    AC_DEFINE(HILDON, 0, [Version of hildon libraries])
+  fi
+
+  if test "x$HAVE_HILDON" = "xno"; then
+    AC_MSG_ERROR(you need hildon development packages installed !)
+  fi
+
+  PKG_CHECK_MODULES(OSSO, libosso >= 0.9.19)
+
+  MAEMO_CFLAGS="$HILDON_CFLAGS $OSSO_CFLAGS"
+  MAEMO_LIBS="$HILDON_LIBS $OSSO_LIBS"
+fi
+
+dnl make MAEMO_CFLAGS and MAEMO_LIBS available
+AC_SUBST(MAEMO_CFLAGS)
+AC_SUBST(MAEMO_LIBS)
+
+dnl append GST_ERROR cflags to GST_CFLAGS
+GST_CFLAGS="$GST_CFLAGS $GST_ERROR"
+
+dnl make GST_CFLAGS and GST_LIBS available
+AC_SUBST(GST_CFLAGS)
+AC_SUBST(GST_LIBS)
+
+dnl make GST_MAJORMINOR available in Makefile.am
+AC_SUBST(GST_MAJORMINOR)
+
+dnl If we need them, we can also use the base class libraries
+PKG_CHECK_MODULES(GST_BASE, gstreamer-base-$GST_MAJORMINOR >= $GST_REQUIRED,
+                  HAVE_GST_BASE=yes, HAVE_GST_BASE=no)
+
+dnl Give a warning if we don't have gstreamer libs
+dnl you can turn this into an error if you need them
+if test "x$HAVE_GST_BASE" = "xno"; then
+  AC_MSG_NOTICE(no GStreamer base class libraries found (gstreamer-base-$GST_MAJORMINOR))
+fi
+
+dnl make _CFLAGS and _LIBS available
+AC_SUBST(GST_BASE_CFLAGS)
+AC_SUBST(GST_BASE_LIBS)
+
+dnl If we need them, we can also use the gstreamer-plugins-base libraries
+PKG_CHECK_MODULES(GSTPB_BASE,
+                  gstreamer-plugins-base-$GST_MAJORMINOR >= $GSTPB_REQUIRED,
+                  HAVE_GSTPB_BASE=yes, HAVE_GSTPB_BASE=no)
+
+dnl Give a warning if we don't have gstreamer libs
+dnl you can turn this into an error if you need them
+if test "x$HAVE_GSTPB_BASE" = "xno"; then
+  AC_MSG_NOTICE(no GStreamer Plugins Base libraries found (gstreamer-plugins-base-$GST_MAJORMINOR))
+fi
+
+dnl make _CFLAGS and _LIBS available
+AC_SUBST(GSTPB_BASE_CFLAGS)
+AC_SUBST(GSTPB_BASE_LIBS)
+
+dnl If we need them, we can also use the gstreamer-controller libraries
+PKG_CHECK_MODULES(GSTCTRL,
+                  gstreamer-controller-$GST_MAJORMINOR >= $GSTPB_REQUIRED,
+                  HAVE_GSTCTRL=yes, HAVE_GSTCTRL=no)
+
+dnl Give a warning if we don't have gstreamer-controller
+dnl you can turn this into an error if you need them
+if test "x$HAVE_GSTCTRL" = "xno"; then
+  AC_MSG_NOTICE(no GStreamer Controller libraries found (gstreamer-controller-$GST_MAJORMINOR))
+fi
+
+dnl make _CFLAGS and _LIBS available
+AC_SUBST(GSTCTRL_CFLAGS)
+AC_SUBST(GSTCTRL_LIBS)
+
+dnl GTK is optional and used in examples
+HAVE_GTK=NO
+PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.2.0, HAVE_GTK_22=yes, HAVE_GTK_22=no)
+if test "x$HAVE_GTK_22" = "xyes"; then
+  HAVE_GTK=yes
+  GTK_VERSION=`$PKG_CONFIG --variable=gtk_binary_version gtk+-2.0`
+  AC_SUBST(GTK_VERSION)
+  GTK_PREFIX=`$PKG_CONFIG --variable=prefix gdk-pixbuf-2.0`
+  AC_SUBST(GTK_BASE_DIR)
+  GDK_PIXBUF_LIBDIR=`$PKG_CONFIG --variable=libdir gdk-pixbuf-2.0`
+  GDK_PIXBUF_PREFIXDIR=`$PKG_CONFIG --variable=prefix gdk-pixbuf-2.0`
+  AC_SUBST(GTK_BASE_DIR)
+else
+  PKG_CHECK_MODULES(GTK2, gtk+-2.0, HAVE_GTK_20=yes, HAVE_GTK_20=no)
+fi
+if test "x$HAVE_GTK_20" = "xyes"; then
+  HAVE_GTK=yes
+fi
+GTK_CFLAGS=$GTK2_CFLAGS
+GTK_LIBS=$GTK2_LIBS
+AC_SUBST(GTK_LIBS)
+AC_SUBST(GTK_CFLAGS)
+AC_SUBST(HAVE_GTK)
+AM_CONDITIONAL(HAVE_GTK, test "x$HAVE_GTK" = "xyes")
+
+dnl set the plugindir where plugins should be installed
+if test "x${prefix}" = "x$HOME"; then
+  plugindir="$HOME/.gstreamer-$GST_MAJORMINOR/plugins"
+else
+  plugindir="\$(libdir)/gstreamer-$GST_MAJORMINOR"
+fi
+AC_SUBST(plugindir)
+
+dnl set proper LDFLAGS for plugins
+GST_PLUGIN_LDFLAGS='-module -avoid-version -export-symbols-regex [_]*\(gst_\|Gst\|GST_\).*'
+AC_SUBST(GST_PLUGIN_LDFLAGS)
+
+AC_OUTPUT(Makefile m4/Makefile debian/Makefile src/Makefile)
+
+
diff --git a/debian/Makefile.am b/debian/Makefile.am
new file mode 100644 (file)
index 0000000..76e362b
--- /dev/null
@@ -0,0 +1 @@
+EXTRA_DIST = changelog control copyright files postinst rules substvars tuner.links
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..ce32767
--- /dev/null
@@ -0,0 +1,28 @@
+tuner (0.0.4) unstable; urgency=low
+
+  * added calibration and some code clean up. Patch provided by Jari Tenhunen.
+  * some more clean up.
+  * kissfft gstreamer element renamed.
+  * added a replacement for audiotestsrc, now dependency is removed. 
+
+ -- Josep Torra <jtorra@uoc.edu>  Fri,  27 Jun 2008 07:00:00 +0100
+
+tuner (0.0.3) unstable; urgency=low
+
+  * make it compile in Chinook.
+  * added some libtool stuff.
+  * convert the kissfft plugin to static.
+
+ -- Josep Torra <jtorra@uoc.edu>  Fri,  05 Jan 2008 10:17:00 +0100
+
+tuner (0.0.2) unstable; urgency=low
+
+  * piano keyboard added.
+
+ -- Josep Torra <jtorra@uoc.edu>  Tue,  02 Aug 2006 18:32:00 +0100
+
+tuner (0.0.1) unstable; urgency=low
+
+  * first release for maemo tuner tool.
+
+ -- Josep Torra <jtorra@uoc.edu>  Tue,  01 Aug 2006 20:00:00 +0100
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..5127ee7
--- /dev/null
@@ -0,0 +1,21 @@
+Source: tuner
+Section: user/extra
+Priority: optional
+Maintainer: Josep Torra <jtorra@uoc.edu>
+Build-Depends: debhelper (>= 4.0.0), libgtk2.0-dev, libosso-dev (>= 1)
+Standards-Version: 3.6.0
+
+Package: tuner
+Architecture: any
+Pre-Depends: maemo-select-menu-location
+Depends: ${shlibs:Depends}
+Description: Tuner is a helper tool for tuning instruments.
+XB-Maemo-Icon-26:
+  iVBORw0KGgoAAAANSUhEUgAAABoAAAAaBAMAAABbZFH9AAAAMFBMVEUAAACA
+  AAAAgACAgAAAAICAAIAAgIDAwMCAgID/AAAA/wD//wAAAP//AP8A//////9P
+  EyZJAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1F
+  B9YHFAYKBwXuSNEAAACPSURBVBjTVY8xDsNQCEO9haGSr5rxj2w/W6+UA/Qw
+  bMlQiZI0kB+2J4xt4G5eA3fhg3Qka0wxjN4VSaGDFFknZa47mWnKpFhu0DsB
+  h20lCNA1KcqstjAJr9UnTSLg+3kZBIYunP8JX7o0uXb2YWT2Uh62rb8vlxjD
+  2RX16ZFxkzUM5NPCgcR1pG0keyjD4webUwgZdzW9EgAAAABJRU5ErkJggg==
+
diff --git a/debian/copyright b/debian/copyright
new file mode 100644 (file)
index 0000000..80e8951
--- /dev/null
@@ -0,0 +1,7 @@
+This package was debianized by Josep Torra <jtorra@uoc.edu> on
+Tue, 19 Dec 2007 20:00:00 +0100.
+
+This package is licensed under the GNU LGPL license
+For further information please refer to the COPYING file
+
+
diff --git a/debian/files b/debian/files
new file mode 100644 (file)
index 0000000..cf9687a
--- /dev/null
@@ -0,0 +1 @@
+tuner_0.0.4_armel.deb user/extra optional
diff --git a/debian/postinst b/debian/postinst
new file mode 100644 (file)
index 0000000..6a2bab5
--- /dev/null
@@ -0,0 +1,14 @@
+#! /bin/sh
+gtk-update-icon-cache -f /usr/share/icons/hicolor
+
+# Now we are ready to let the user move the entry around, but only if
+# this is a new install
+
+oldversion="$2"
+if [ -z "$oldversion" ]; then
+  maemo-select-menu-location tuner.desktop
+fi
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..dc00473
--- /dev/null
@@ -0,0 +1,95 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# GNU copyright 1997 to 1999 by Joey Hess.
+
+# Uncomment this to turn on verbose mode.
+export DH_VERBOSE=1
+
+# These are used for cross-compiling and for saving the configure script
+# from having to guess our platform (since we know it already)
+DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
+DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
+
+CFLAGS = -Wall -g -mcpu=arm926ej-s 
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+       CFLAGS += -O0
+else
+       CFLAGS += -O2
+endif
+ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
+       INSTALL_PROGRAM += -s
+endif
+
+config.status: configure
+       dh_testdir
+       # Add here commands to configure the package.
+       CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) \
+     --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man \
+     --infodir=\$${prefix}/share/info --with-maemo
+
+configure:
+       ./autogen.sh
+
+
+build: build-stamp
+
+build-stamp:  config.status
+       dh_testdir
+
+       # Add here commands to compile the package.
+       $(MAKE) 
+       touch build-stamp
+
+clean:
+       dh_testdir
+       dh_testroot
+       rm -f build-stamp 
+
+       # Add here commands to clean up after the build process.
+       -$(MAKE) distclean
+
+       dh_clean 
+
+install: build
+       dh_testdir
+       dh_testroot
+       dh_clean -k 
+       dh_installdirs
+       dh_link
+
+       # Add here commands to install the package
+       mkdir -p $(CURDIR)/debian/tmp/usr
+       mkdir -p $(CURDIR)/debian/tmp/usr/share/applications/hildon
+       mkdir -p $(CURDIR)/debian/tmp/usr/share/icons/hicolor/26x26/hildon
+       mkdir -p $(CURDIR)/debian/tmp/usr/share/icons/hicolor/40x40/hildon
+       mkdir -p $(CURDIR)/debian/tmp/usr/share/icons/hicolor/scalable/hildon
+       cp $(CURDIR)/src/tuner26.png $(CURDIR)/debian/tmp/usr/share/icons/hicolor/26x26/hildon/pkg_tuner.png
+       cp $(CURDIR)/src/tuner40.png $(CURDIR)/debian/tmp/usr/share/icons/hicolor/40x40/hildon/pkg_tuner.png
+       cp $(CURDIR)/src/tuner64.png $(CURDIR)/debian/tmp/usr/share/icons/hicolor/scalable/hildon/pkg_tuner.png
+       cp $(CURDIR)/tuner.desktop $(CURDIR)/debian/tmp/usr/share/applications/hildon/tuner.desktop
+       mkdir -p $(CURDIR)/debian/tmp/usr/bin
+       cp $(CURDIR)/src/tuner $(CURDIR)/debian/tmp/usr/bin
+       strip $(CURDIR)/debian/tmp/usr/bin/tuner
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+       dh_testdir
+       dh_testroot
+       dh_link
+       dh_strip
+       dh_compress
+       dh_fixperms
+       dh_installdeb
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
diff --git a/debian/substvars b/debian/substvars
new file mode 100644 (file)
index 0000000..4ab3ba7
--- /dev/null
@@ -0,0 +1 @@
+shlibs:Depends=libatk1.0-0 (>= 1.12.2), libc6 (>= 2.5.0-1), libcairo2 (>= 1.4.10), libdbus-1-3 (>= 0.94), libdbus-glib-1-2 (>= 0.74), libglib2.0-0 (>= 2.12.12-1osso3), libgstreamer0.10-0 (>= 0.10.9), libgtk2.0-0 (>= 2:2.10.12-0osso15), libhildon1 (>= 1.0.11), libosso1 (>= 2.13), libpango1.0-0 (>= 1.16.4), libxml2
diff --git a/debian/tuner.links b/debian/tuner.links
new file mode 100644 (file)
index 0000000..fad5160
--- /dev/null
@@ -0,0 +1 @@
+/usr/share/applications/hildon/tuner.desktop etc/others-menu/extra_applications/0112_tuner.desktop
diff --git a/m4/Makefile.am b/m4/Makefile.am
new file mode 100644 (file)
index 0000000..4a44032
--- /dev/null
@@ -0,0 +1 @@
+EXTRA_DIST = as-version.m4 as-compiler-flag.m4
diff --git a/m4/as-compiler-flag.m4 b/m4/as-compiler-flag.m4
new file mode 100644 (file)
index 0000000..2f0ba19
--- /dev/null
@@ -0,0 +1,25 @@
+dnl as-compiler-flag.m4 0.0.1
+dnl autostars m4 macro for detection of compiler flags
+dnl
+dnl ds@schleef.org
+
+AC_DEFUN([AS_COMPILER_FLAG],
+[
+  AC_MSG_CHECKING([to see if compiler understands $1])
+
+  save_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS $1"
+
+  AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
+  CFLAGS="$save_CFLAGS"
+
+  if test "X$flag_ok" = Xyes ; then
+    $2
+    true
+  else
+    $3
+    true
+  fi
+  AC_MSG_RESULT([$flag_ok])
+])
+
diff --git a/m4/as-version.m4 b/m4/as-version.m4
new file mode 100644 (file)
index 0000000..0bee437
--- /dev/null
@@ -0,0 +1,66 @@
+dnl as-version.m4 0.1.0
+
+dnl autostars m4 macro for versioning
+
+dnl Thomas Vander Stichele <thomas at apestaart dot org>
+
+dnl $Id: as-version.m4,v 1.2 2004-09-17 22:18:03 leroutier Exp $
+
+dnl AS_VERSION(PACKAGE, PREFIX, MAJOR, MINOR, MICRO, NANO,
+dnl            ACTION-IF-NO-NANO, [ACTION-IF-NANO])
+
+dnl example
+dnl AS_VERSION(gstreamer, GST_VERSION, 0, 3, 2,)
+dnl for a 0.3.2 release version
+
+dnl this macro
+dnl - defines [$PREFIX]_MAJOR, MINOR and MICRO
+dnl - if NANO is empty, then we're in release mode, else in cvs/dev mode
+dnl - defines [$PREFIX], VERSION, and [$PREFIX]_RELEASE
+dnl - executes the relevant action
+dnl - AC_SUBST's PACKAGE, VERSION, [$PREFIX] and [$PREFIX]_RELEASE
+dnl   as well as the little ones
+dnl - doesn't call AM_INIT_AUTOMAKE anymore because it prevents
+dnl   maintainer mode from running ok
+dnl
+dnl don't forget to put #undef [$2] and [$2]_RELEASE in acconfig.h
+dnl if you use acconfig.h
+
+AC_DEFUN([AS_VERSION],
+[
+  PACKAGE=[$1]
+  [$2]_MAJOR=[$3]
+  [$2]_MINOR=[$4]
+  [$2]_MICRO=[$5]
+  NANO=[$6]
+  [$2]_NANO=$NANO
+  if test "x$NANO" = "x" || test "x$NANO" = "x0";
+  then
+      AC_MSG_NOTICE(configuring [$1] for release)
+      VERSION=[$3].[$4].[$5]
+      [$2]_RELEASE=1
+      dnl execute action
+      ifelse([$7], , :, [$7])
+  else
+      AC_MSG_NOTICE(configuring [$1] for development with nano $NANO)
+      VERSION=[$3].[$4].[$5].$NANO
+      [$2]_RELEASE=0.`date +%Y%m%d.%H%M%S`
+      dnl execute action
+      ifelse([$8], , :, [$8])
+  fi
+
+  [$2]=$VERSION
+  AC_DEFINE_UNQUOTED([$2], "$[$2]", [Define the version])
+  AC_SUBST([$2])
+  AC_DEFINE_UNQUOTED([$2]_RELEASE, "$[$2]_RELEASE", [Define the release version])
+  AC_SUBST([$2]_RELEASE)
+
+  AC_SUBST([$2]_MAJOR)
+  AC_SUBST([$2]_MINOR)
+  AC_SUBST([$2]_MICRO)
+  AC_SUBST([$2]_NANO)
+  AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Define the package name])
+  AC_SUBST(PACKAGE)
+  AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Define the version])
+  AC_SUBST(VERSION)
+])
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644 (file)
index 0000000..5ee52df
--- /dev/null
@@ -0,0 +1,46 @@
+# plugindir is set in configure
+
+# change libgstplugin.la to something more suitable
+noinst_LTLIBRARIES = libgstpitch.la libgsttonesrc.la
+
+# for the next set of variables, rename the prefix if you renamed the .la
+
+# sources used to compile this plug-in
+libgstpitch_la_SOURCES = gstpitch.c kiss_fft.c
+# flags used to compile this plugin
+# add other _CFLAGS and _LIBS as needed
+libgstpitch_la_CFLAGS = $(GSTPB_BASE_CFLAGS) $(GST_BASE_CFLAGS) \
+       $(GSTCTRL_CFLAGS) $(GST_CFLAGS) -DFIXED_POINT=16
+libgstpitch_la_LIBADD = $(GSTPB_BASE_LIBS) $(GST_BASE_LIBS) \
+       $(GSTCTRL_LIBS) $(GST_LIBS)
+libgstpitch_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+
+libgsttonesrc_la_SOURCES = gsttonesrc.c
+libgsttonesrc_la_CFLAGS = $(GSTPB_BASE_CFLAGS) $(GST_BASE_CFLAGS) \
+       $(GSTCTRL_CFLAGS) $(GST_CFLAGS) -DFIXED_POINT=16
+libgsttonesrc_la_LIBADD = $(GSTPB_BASE_LIBS) $(GST_BASE_LIBS) \
+       $(GSTCTRL_LIBS) $(GST_LIBS)
+libgsttonesrc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+
+# headers we need but don't want installed
+noinst_HEADERS = gstpitch.h gsttonesrc.h kiss_fft.h _kiss_fft_guts.h
+EXTRA_DIST = tuner26.png  tuner40.png  tuner64.png
+
+if HAVE_GTK
+noinst_PROGRAMS = demo-audiotest demo-tuner tuner
+endif
+
+demo_audiotest_SOURCES = demo-audiotest.c
+demo_audiotest_CFLAGS  = $(GST_CFLAGS) $(GTK_CFLAGS) 
+demo_audiotest_LDFLAGS = $(GST_LIBS) $(GTK_LIBS)
+
+demo_tuner_SOURCES = demo-tuner.c
+demo_tuner_CFLAGS  = $(GST_CFLAGS) $(GTK_CFLAGS) 
+demo_tuner_LDFLAGS = $(GST_LIBS) $(GTK_LIBS)
+
+tuner_SOURCES = tuner.c
+tuner_DEPENDENCIES = $(top_builddir)/src/libgstpitch.la $(top_builddir)/src/libgsttonesrc.la
+tuner_CFLAGS  = $(GST_CFLAGS) $(GTK_CFLAGS) $(MAEMO_CFLAGS) -D_GNU_SOURCE
+tuner_LDADD = $(GST_LIBS) $(GTK_LIBS) $(MAEMO_LIBS) $(top_builddir)/src/libgstpitch.la $(top_builddir)/src/libgsttonesrc.la
+
+
diff --git a/src/_kiss_fft_guts.h b/src/_kiss_fft_guts.h
new file mode 100644 (file)
index 0000000..e0c7447
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+Copyright (c) 2003-2004, Mark Borgerding
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+    * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* kiss_fft.h
+   defines kiss_fft_scalar as either short or a float type
+   and defines
+   typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */
+#include "kiss_fft.h"
+#include <limits.h>
+
+#define MAXFACTORS 32
+/* e.g. an fft of length 128 has 4 factors 
+ as far as kissfft is concerned
+ 4*4*4*2
+ */
+
+struct kiss_fft_state
+{
+  int nfft;
+  int inverse;
+  int factors[2 * MAXFACTORS];
+  kiss_fft_cpx twiddles[1];
+};
+
+/*
+  Explanation of macros dealing with complex math:
+
+   C_MUL(m,a,b)         : m = a*b
+   C_FIXDIV( c , div )  : if a fixed point impl., c /= div. noop otherwise
+   C_SUB( res, a,b)     : res = a - b
+   C_SUBFROM( res , a)  : res -= a
+   C_ADDTO( res , a)    : res += a
+ * */
+#ifdef FIXED_POINT
+#if (FIXED_POINT==32)
+# define FRACBITS 31
+# define SAMPPROD int64_t
+#define SAMP_MAX 2147483647
+#else
+# define FRACBITS 15
+# define SAMPPROD int32_t
+#define SAMP_MAX 32767
+#endif
+
+#define SAMP_MIN -SAMP_MAX
+
+#if defined(CHECK_OVERFLOW)
+#  define CHECK_OVERFLOW_OP(a,op,b)  \
+       if ( (SAMPPROD)(a) op (SAMPPROD)(b) > SAMP_MAX || (SAMPPROD)(a) op (SAMPPROD)(b) < SAMP_MIN ) { \
+               fprintf(stderr,"WARNING:overflow @ " __FILE__ "(%d): (%d " #op" %d) = %ld\n",__LINE__,(a),(b),(SAMPPROD)(a) op (SAMPPROD)(b) );  }
+#endif
+
+
+#   define smul(a,b) ( (SAMPPROD)(a)*(b) )
+#   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
+
+#   define S_MUL(a,b) sround( smul(a,b) )
+
+#   define C_MUL(m,a,b) \
+      do{ (m).r = sround( smul((a).r,(b).r) - smul((a).i,(b).i) ); \
+          (m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); }while(0)
+
+#   define DIVSCALAR(x,k) \
+       (x) = sround( smul(  x, SAMP_MAX/k ) )
+
+#   define C_FIXDIV(c,div) \
+       do {    DIVSCALAR( (c).r , div);  \
+               DIVSCALAR( (c).i  , div); }while (0)
+
+#   define C_MULBYSCALAR( c, s ) \
+    do{ (c).r =  sround( smul( (c).r , s ) ) ;\
+        (c).i =  sround( smul( (c).i , s ) ) ; }while(0)
+
+#else /* not FIXED_POINT */
+
+#   define S_MUL(a,b) ( (a)*(b) )
+#define C_MUL(m,a,b) \
+    do{ (m).r = (a).r*(b).r - (a).i*(b).i;\
+        (m).i = (a).r*(b).i + (a).i*(b).r; }while(0)
+#   define C_FIXDIV(c,div)      /* NOOP */
+#   define C_MULBYSCALAR( c, s ) \
+    do{ (c).r *= (s);\
+        (c).i *= (s); }while(0)
+#endif
+
+#ifndef CHECK_OVERFLOW_OP
+#  define CHECK_OVERFLOW_OP(a,op,b)     /* noop */
+#endif
+
+#define  C_ADD( res, a,b)\
+    do { \
+           CHECK_OVERFLOW_OP((a).r,+,(b).r)\
+           CHECK_OVERFLOW_OP((a).i,+,(b).i)\
+           (res).r=(a).r+(b).r;  (res).i=(a).i+(b).i; \
+    }while(0)
+#define  C_SUB( res, a,b)\
+    do { \
+           CHECK_OVERFLOW_OP((a).r,-,(b).r)\
+           CHECK_OVERFLOW_OP((a).i,-,(b).i)\
+           (res).r=(a).r-(b).r;  (res).i=(a).i-(b).i; \
+    }while(0)
+#define C_ADDTO( res , a)\
+    do { \
+           CHECK_OVERFLOW_OP((res).r,+,(a).r)\
+           CHECK_OVERFLOW_OP((res).i,+,(a).i)\
+           (res).r += (a).r;  (res).i += (a).i;\
+    }while(0)
+
+#define C_SUBFROM( res , a)\
+    do {\
+           CHECK_OVERFLOW_OP((res).r,-,(a).r)\
+           CHECK_OVERFLOW_OP((res).i,-,(a).i)\
+           (res).r -= (a).r;  (res).i -= (a).i; \
+    }while(0)
+
+
+#ifdef FIXED_POINT
+#  define KISS_FFT_COS(phase)  floor(.5+SAMP_MAX * cos (phase))
+#  define KISS_FFT_SIN(phase)  floor(.5+SAMP_MAX * sin (phase))
+#  define HALF_OF(x) ((x)>>1)
+#elif defined(USE_SIMD)
+#  define KISS_FFT_COS(phase) _mm_set1_ps( cos(phase) )
+#  define KISS_FFT_SIN(phase) _mm_set1_ps( sin(phase) )
+#  define HALF_OF(x) ((x)*_mm_set1_ps(.5))
+#else
+#  define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase)
+#  define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase)
+#  define HALF_OF(x) ((x)*.5)
+#endif
+
+#define  kf_cexp(x,phase) \
+       do{ \
+               (x)->r = KISS_FFT_COS(phase);\
+               (x)->i = KISS_FFT_SIN(phase);\
+       }while(0)
+
+
+/* a debugging function */
+#define pcpx(c)\
+    fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) )
diff --git a/src/demo-audiotest.c b/src/demo-audiotest.c
new file mode 100644 (file)
index 0000000..89eee71
--- /dev/null
@@ -0,0 +1,140 @@
+/* GStreamer
+ * Copyright (C) 2006 Josep Torra <j.torra@telefonica.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <math.h>
+#include <gst/gst.h>
+#include <gtk/gtk.h>
+
+#define DEFAULT_AUDIOSINK "alsasink"
+
+GtkWidget *lblFrequency;
+
+static void
+on_window_destroy (GtkObject * object, gpointer user_data)
+{
+  gtk_main_quit ();
+}
+
+/* control audiotestsrc frequency */
+static void
+on_frequency_changed (GtkRange * range, gpointer user_data)
+{
+  GstElement *machine = GST_ELEMENT (user_data);
+  gdouble value = gtk_range_get_value (range);
+
+  g_object_set (machine, "freq", value, NULL);
+}
+
+/* control audiotestsrc frequency */
+static void
+update_frequency (gint frequency)
+{
+  gchar *buffer;
+  gchar freq[5];
+
+  g_snprintf (freq, 5, "%d", frequency);
+  buffer = g_strconcat ("Frequency is ", freq, NULL);
+  gtk_label_set_text (GTK_LABEL (lblFrequency), buffer);
+  g_free (buffer);
+}
+
+/* receive spectral data from element message */
+gboolean
+message_handler (GstBus * bus, GstMessage * message, gpointer data)
+{
+  if (message->type == GST_MESSAGE_ELEMENT) {
+    const GstStructure *s = gst_message_get_structure (message);
+    const gchar *name = gst_structure_get_name (s);
+
+    if (strcmp (name, "kissfft") == 0) {
+      gint frequency;
+
+      frequency = g_value_get_int (gst_structure_get_value (s, "frequency"));
+      update_frequency (frequency);
+    }
+  }
+  /* we handled the message we want, and ignored the ones we didn't want.
+   * so the core can unref the message for us */
+  return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+  GstElement *bin;
+  GstElement *src, *kissfft, *sink;
+  GstBus *bus;
+  GtkWidget *appwindow, *vbox, *widget;
+
+  gst_init (&argc, &argv);
+  gtk_init (&argc, &argv);
+
+  bin = gst_pipeline_new ("bin");
+
+  src = gst_element_factory_make ("audiotestsrc", "src");
+
+  kissfft = gst_element_factory_make ("kissfft", "kissfft");
+  g_object_set (G_OBJECT (kissfft), "nfft", 1024, "message", TRUE, "minfreq",
+      220, "maxfreq", 1500, NULL);
+
+  sink = gst_element_factory_make (DEFAULT_AUDIOSINK, "sink");
+
+  gst_bin_add_many (GST_BIN (bin), src, kissfft, sink, NULL);
+  if (!gst_element_link_many (src, kissfft, sink, NULL)) {
+    fprintf (stderr, "cant link elements\n");
+    exit (1);
+  }
+
+  bus = gst_element_get_bus (bin);
+  gst_bus_add_watch (bus, message_handler, NULL);
+  gst_object_unref (bus);
+
+  appwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  g_signal_connect (G_OBJECT (appwindow), "destroy",
+      G_CALLBACK (on_window_destroy), NULL);
+  vbox = gtk_vbox_new (FALSE, 6);
+
+  widget = gtk_hscale_new_with_range (50.0, 2000.0, 10);
+  gtk_widget_set_size_request (widget, 300, -1);
+  gtk_scale_set_draw_value (GTK_SCALE (widget), TRUE);
+  gtk_scale_set_value_pos (GTK_SCALE (widget), GTK_POS_TOP);
+  gtk_range_set_value (GTK_RANGE (widget), 440.0);
+  g_signal_connect (G_OBJECT (widget), "value-changed",
+      G_CALLBACK (on_frequency_changed), (gpointer) src);
+  gtk_container_add (GTK_CONTAINER (vbox), widget);
+
+  lblFrequency = gtk_label_new ("Frequency is ");
+  gtk_container_add (GTK_CONTAINER (vbox), lblFrequency);
+
+  gtk_container_add (GTK_CONTAINER (appwindow), vbox);
+  gtk_widget_show_all (appwindow);
+
+  gst_element_set_state (bin, GST_STATE_PLAYING);
+  gtk_main ();
+  gst_element_set_state (bin, GST_STATE_NULL);
+
+  gst_object_unref (bin);
+
+  return 0;
+}
diff --git a/src/demo-tuner.c b/src/demo-tuner.c
new file mode 100644 (file)
index 0000000..0801b13
--- /dev/null
@@ -0,0 +1,123 @@
+/* GStreamer
+ * Copyright (C) 2006 Josep Torra <j.torra@telefonica.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <math.h>
+#include <gst/gst.h>
+#include <gtk/gtk.h>
+
+#define DEFAULT_AUDIOSRC "alsasrc"
+
+GtkWidget *lblFrequency;
+
+static void
+on_window_destroy (GtkObject * object, gpointer user_data)
+{
+  gtk_main_quit ();
+}
+
+/* update frequency label */
+static void
+update_frequency (gint frequency)
+{
+  gchar *buffer;
+  gchar freq[5];
+
+  g_snprintf (freq, 5, "%d", frequency);
+  buffer = g_strconcat ("Frequency is ", freq, NULL);
+  gtk_label_set_text (GTK_LABEL (lblFrequency), buffer);
+  g_free (buffer);
+}
+
+/* receive spectral data from element message */
+gboolean
+message_handler (GstBus * bus, GstMessage * message, gpointer data)
+{
+  if (message->type == GST_MESSAGE_ELEMENT) {
+    const GstStructure *s = gst_message_get_structure (message);
+    const gchar *name = gst_structure_get_name (s);
+
+    if (strcmp (name, "kissfft") == 0) {
+      gint frequency;
+
+      frequency = g_value_get_int (gst_structure_get_value (s, "frequency"));
+      update_frequency (frequency);
+    }
+  }
+  /* we handled the message we want, and ignored the ones we didn't want.
+   * so the core can unref the message for us */
+  return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+  GstElement *bin;
+  GstElement *src, *kissfft, *sink;
+  GstBus *bus;
+  GtkWidget *appwindow, *vbox;
+
+  gst_init (&argc, &argv);
+  gtk_init (&argc, &argv);
+
+  bin = gst_pipeline_new ("bin");
+
+  src = gst_element_factory_make (DEFAULT_AUDIOSRC, "src");
+
+  kissfft = gst_element_factory_make ("kissfft", "kissfft");
+  g_object_set (G_OBJECT (kissfft), "nfft", 16000, "message", TRUE, "minfreq",
+      220, "maxfreq", 1500, NULL);
+
+  sink = gst_element_factory_make ("fakesink", "sink");
+  g_object_set (G_OBJECT (sink), "silent", 1, NULL);
+
+  gst_bin_add_many (GST_BIN (bin), src, kissfft, sink, NULL);
+  if (!gst_element_link_many (src, kissfft, sink, NULL)) {
+    fprintf (stderr, "cant link elements\n");
+    exit (1);
+  }
+
+  bus = gst_element_get_bus (bin);
+  gst_bus_add_watch (bus, message_handler, NULL);
+  gst_object_unref (bus);
+
+  appwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  g_signal_connect (G_OBJECT (appwindow), "destroy",
+      G_CALLBACK (on_window_destroy), NULL);
+  vbox = gtk_vbox_new (FALSE, 6);
+
+  lblFrequency = gtk_label_new ("Frequency is ");
+  gtk_widget_set_size_request (lblFrequency, 300, -1);
+  gtk_container_add (GTK_CONTAINER (vbox), lblFrequency);
+
+  gtk_container_add (GTK_CONTAINER (appwindow), vbox);
+  gtk_widget_show_all (appwindow);
+
+  gst_element_set_state (bin, GST_STATE_PLAYING);
+  gtk_main ();
+  gst_element_set_state (bin, GST_STATE_NULL);
+
+  gst_object_unref (bin);
+
+  return 0;
+}
diff --git a/src/gstpitch.c b/src/gstpitch.c
new file mode 100644 (file)
index 0000000..53202ac
--- /dev/null
@@ -0,0 +1,389 @@
+/*
+ * GStreamer
+ * Copyright (C) 2006 Josep Torra <j.torra@telefonica.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/audio/audio.h>
+
+#include "gstpitch.h"
+
+GST_DEBUG_CATEGORY_STATIC (gst_pitch_debug);
+#define GST_CAT_DEFAULT gst_pitch_debug
+
+/* Filter signals and args */
+enum
+{
+  PROP_0,
+  PROP_SIGNAL_FFREQ,
+  PROP_SIGNAL_INTERVAL,
+  PROP_SIGNAL_MINFREQ,
+  PROP_SIGNAL_MAXFREQ,
+  PROP_NFFT
+};
+
+static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("audio/x-raw-int, "
+        "rate = (int) [ 1, MAX ], "
+        "channels = (int) [1, MAX], "
+        "endianness = (int) BYTE_ORDER, "
+        "width = (int) 16, " "depth = (int) 16, " "signed = (boolean) true")
+    );
+
+static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("audio/x-raw-int, "
+        "rate = (int) [ 1, MAX ], "
+        "channels = (int) [1, MAX], "
+        "endianness = (int) BYTE_ORDER, "
+        "width = (int) 16, " "depth = (int) 16, " "signed = (boolean) true")
+    );
+
+#define DEBUG_INIT(bla) \
+  GST_DEBUG_CATEGORY_INIT (gst_pitch_debug, "Pitch", 0, "fundamental frequency plugin");
+
+GST_BOILERPLATE_FULL (GstPitch, gst_pitch, GstBaseTransform,
+    GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
+
+static void gst_pitch_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec);
+static void gst_pitch_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec);
+static void gst_pitch_dispose (GObject * object);
+
+static gboolean gst_pitch_set_caps (GstBaseTransform * trans, GstCaps * in,
+    GstCaps * out);
+static gboolean gst_pitch_start (GstBaseTransform * trans);
+
+static GstFlowReturn gst_pitch_transform_ip (GstBaseTransform * trans,
+    GstBuffer * in);
+
+/* GObject vmethod implementations */
+
+static void
+gst_pitch_base_init (gpointer klass)
+{
+  static GstElementDetails element_details = {
+    "Pitch analyzer",
+    "Filter/Analyzer/Audio",
+    "Run an FFT on the audio signal, output fundamental frequency",
+    "Josep Torra <j.torra@telefonica.net>"
+  };
+  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&src_template));
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&sink_template));
+  gst_element_class_set_details (element_class, &element_details);
+}
+
+static void
+gst_pitch_class_init (GstPitchClass * klass)
+{
+  GObjectClass *gobject_class;
+  GstBaseTransformClass *trans_class = GST_BASE_TRANSFORM_CLASS (klass);
+
+  gobject_class = (GObjectClass *) klass;
+  gobject_class->set_property = gst_pitch_set_property;
+  gobject_class->get_property = gst_pitch_get_property;
+  gobject_class->dispose = gst_pitch_dispose;
+
+  trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_pitch_set_caps);
+  trans_class->start = GST_DEBUG_FUNCPTR (gst_pitch_start);
+  trans_class->transform_ip = GST_DEBUG_FUNCPTR (gst_pitch_transform_ip);
+  trans_class->passthrough_on_same_caps = TRUE;
+
+  g_object_class_install_property (gobject_class, PROP_SIGNAL_FFREQ,
+      g_param_spec_boolean ("message", "Message",
+          "Post a fundamental frequency message for each passed interval",
+          TRUE, G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_SIGNAL_INTERVAL,
+      g_param_spec_uint64 ("interval", "Interval",
+          "Interval of time between message posts (in nanoseconds)",
+          1, G_MAXUINT64, GST_SECOND / 10, G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_SIGNAL_MINFREQ,
+      g_param_spec_int ("minfreq", "MinFreq",
+          "Initial scan frequency, default 30 Hz",
+          1, G_MAXINT, 30, G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_SIGNAL_MAXFREQ,
+      g_param_spec_int ("maxfreq", "MaxFreq",
+          "Final scan frequency, default 1500 Hz",
+          1, G_MAXINT, 1500, G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_NFFT,
+      g_param_spec_int ("nfft", "NFFT",
+          "Number of samples taken for FFT",
+          1, G_MAXINT, 1024, G_PARAM_READWRITE));
+
+  GST_BASE_TRANSFORM_CLASS (klass)->transform_ip =
+      GST_DEBUG_FUNCPTR (gst_pitch_transform_ip);
+}
+
+static void
+gst_pitch_init (GstPitch * filter, GstPitchClass * klass)
+{
+  filter->adapter = gst_adapter_new ();
+
+  filter->minfreq = 30;
+  filter->maxfreq = 1500;
+  filter->nfft = 1024;
+  filter->message = TRUE;
+  filter->interval = GST_SECOND / 10;
+
+  filter->fft_cfg = kiss_fft_alloc (filter->nfft, 0, NULL, NULL);
+  filter->signal =
+      (kiss_fft_cpx *) g_malloc (filter->nfft * sizeof (kiss_fft_cpx));
+  filter->spectrum =
+      (kiss_fft_cpx *) g_malloc (filter->nfft * sizeof (kiss_fft_cpx));
+}
+
+static void
+gst_pitch_dispose (GObject * object)
+{
+  GstPitch *filter = GST_PITCH (object);
+
+  if (filter->adapter) {
+    g_object_unref (filter->adapter);
+    filter->adapter = NULL;
+  }
+
+  g_free (filter->fft_cfg);
+  g_free (filter->signal);
+  g_free (filter->spectrum);
+
+  kiss_fft_cleanup ();
+
+  G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+gst_pitch_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstPitch *filter = GST_PITCH (object);
+
+  switch (prop_id) {
+    case PROP_SIGNAL_FFREQ:
+      filter->message = g_value_get_boolean (value);
+      break;
+    case PROP_SIGNAL_INTERVAL:
+      filter->interval = gst_guint64_to_gdouble (g_value_get_uint64 (value));
+      break;
+    case PROP_SIGNAL_MINFREQ:
+      filter->minfreq = g_value_get_int (value);
+      break;
+    case PROP_SIGNAL_MAXFREQ:
+      filter->maxfreq = g_value_get_int (value);
+      break;
+    case PROP_NFFT:
+      filter->nfft = g_value_get_int (value);
+      g_free (filter->fft_cfg);
+      g_free (filter->signal);
+      g_free (filter->spectrum);
+      filter->fft_cfg = kiss_fft_alloc (filter->nfft, 0, NULL, NULL);
+      filter->signal =
+          (kiss_fft_cpx *) g_malloc (filter->nfft * sizeof (kiss_fft_cpx));
+      filter->spectrum =
+          (kiss_fft_cpx *) g_malloc (filter->nfft * sizeof (kiss_fft_cpx));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+gst_pitch_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstPitch *filter = GST_PITCH (object);
+
+  switch (prop_id) {
+    case PROP_SIGNAL_FFREQ:
+      g_value_set_boolean (value, filter->message);
+      break;
+    case PROP_SIGNAL_INTERVAL:
+      g_value_set_uint64 (value, filter->interval);
+      break;
+    case PROP_SIGNAL_MINFREQ:
+      g_value_set_int (value, filter->minfreq);
+      break;
+    case PROP_SIGNAL_MAXFREQ:
+      g_value_set_int (value, filter->maxfreq);
+      break;
+    case PROP_NFFT:
+      g_value_set_int (value, filter->nfft);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static gboolean
+gst_pitch_set_caps (GstBaseTransform * trans, GstCaps * in, GstCaps * out)
+{
+  GstPitch *filter = GST_PITCH (trans);
+  GstStructure *structure;
+
+  structure = gst_caps_get_structure (in, 0);
+  gst_structure_get_int (structure, "rate", &filter->rate);
+  gst_structure_get_int (structure, "width", &filter->width);
+  gst_structure_get_int (structure, "channels", &filter->channels);
+
+  return TRUE;
+}
+
+static gboolean
+gst_pitch_start (GstBaseTransform * trans)
+{
+  GstPitch *filter = GST_PITCH (trans);
+
+  gst_adapter_clear (filter->adapter);
+  filter->num_frames = 0;
+
+  return TRUE;
+}
+
+static GstMessage *
+gst_pitch_message_new (GstPitch * filter)
+{
+  GstStructure *s;
+  gint i, min_i, max_i;
+  gint frequency, frequency_module, module;
+
+  /* Extract fundamental frequency */
+  frequency = 0;
+  frequency_module = 0;
+  min_i = filter->minfreq * filter->nfft / filter->rate;
+  max_i = filter->maxfreq * filter->nfft / filter->rate;
+  GST_DEBUG_OBJECT (filter, "min_freq = %d, max_freq = %d", filter->minfreq,
+      filter->maxfreq);
+  GST_DEBUG_OBJECT (filter, "min_i = %d, max_i = %d", min_i, max_i);
+  for (i = min_i; (i <= max_i) && (i < filter->nfft); i++) {
+    module = (filter->spectrum[i].r * filter->spectrum[i].r);
+    module += (filter->spectrum[i].i * filter->spectrum[i].i);
+
+    if (module > 0)
+      GST_DEBUG_OBJECT (filter, "module[%d] = %d", i, module);
+
+    if (module > frequency_module) {
+      frequency_module = module;
+      frequency = i;
+    }
+  }
+
+  frequency = frequency * filter->rate / filter->nfft;
+
+  GST_DEBUG_OBJECT (filter, "preparing message, frequency = %d ", frequency);
+
+  s = gst_structure_new ("pitch", "frequency", G_TYPE_INT, frequency, NULL);
+
+  return gst_message_new_element (GST_OBJECT (filter), s);
+}
+
+/* GstBaseTransform vmethod implementations */
+
+/* this function does the actual processing
+ */
+static GstFlowReturn
+gst_pitch_transform_ip (GstBaseTransform * trans, GstBuffer * in)
+{
+  GstPitch *filter = GST_PITCH (trans);
+  gint16 *samples;
+  gint wanted;
+  gint i, j, k;
+  gint32 acc;
+
+  GST_DEBUG ("transform : %ld bytes", GST_BUFFER_SIZE (in));
+
+  gst_adapter_push (filter->adapter, gst_buffer_ref (in));
+  /* required number of bytes */
+  wanted = filter->channels * filter->nfft * 2;
+
+  while (gst_adapter_available (filter->adapter) > wanted) {
+
+    GST_DEBUG ("  adapter loop");
+    samples = (gint16 *) gst_adapter_take (filter->adapter, wanted);
+
+    for (i = 0, j = 0; i < filter->nfft; i++) {
+      for (k = 0, acc = 0; k < filter->channels; k++)
+        acc += samples[j++];
+      filter->signal[i].r = (kiss_fft_scalar) (acc / filter->channels);
+    }
+
+    GST_DEBUG ("  fft");
+
+    kiss_fft (filter->fft_cfg, filter->signal, filter->spectrum);
+
+    GST_DEBUG ("  send message? %d", filter->num_frames);
+    filter->num_frames += filter->nfft;
+    /* do we need to message ? */
+    if (filter->num_frames >=
+        GST_CLOCK_TIME_TO_FRAMES (filter->interval, filter->rate)) {
+      if (filter->message) {
+        GstMessage *m = gst_pitch_message_new (filter);
+
+        GST_DEBUG ("  sending message");
+        gst_element_post_message (GST_ELEMENT (filter), m);
+      }
+      filter->num_frames = 0;
+    }
+  }
+
+  return GST_FLOW_OK;
+}
+
+
+/* entry point to initialize the plug-in
+ * initialize the plug-in itself
+ * register the element factories and pad templates
+ * register the features
+ *
+ * exchange the string 'plugin' with your elemnt name
+ */
+/* static */ gboolean
+plugin_pitch_init (GstPlugin * plugin)
+{
+  return gst_element_register (plugin, "pitch", GST_RANK_NONE, GST_TYPE_PITCH);
+}
+
+/* this is the structure that gstreamer looks for to register plugins
+ *
+ * exchange the strings 'plugin' and 'Template plugin' with you plugin name and
+ * description
+ */
+#if 0
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+    GST_VERSION_MINOR,
+    "pitch",
+    "Run an FFT on the audio signal, output fundamental frequency",
+    plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
+#endif
diff --git a/src/gstpitch.h b/src/gstpitch.h
new file mode 100644 (file)
index 0000000..4067c8f
--- /dev/null
@@ -0,0 +1,79 @@
+/* 
+ * GStreamer
+ * Copyright (C) 2006 Josep Torra <j.torra@telefonica.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GST_PITCH_H__
+#define __GST_PITCH_H__
+
+#include <gst/gst.h>
+#include <gst/base/gstadapter.h>
+#include <gst/base/gstbasetransform.h>
+
+#include "kiss_fft.h"
+
+G_BEGIN_DECLS
+#define GST_TYPE_PITCH \
+  (gst_pitch_get_type())
+#define GST_PITCH(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PITCH,GstPitch))
+#define GST_PITCH_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PITCH,GstPitchClass))
+#define GST_IS_PLUGIN_TEMPLATE(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PITCH))
+#define GST_IS_PLUGIN_TEMPLATE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PITCH))
+typedef struct _GstPitch GstPitch;
+typedef struct _GstPitchClass GstPitchClass;
+
+struct _GstPitch
+{
+  GstBaseTransform element;
+
+  GstPad *sinkpad, *srcpad;
+  GstAdapter *adapter;
+
+  /* properties */
+  gboolean message;             /* whether or not to post messages */
+  gdouble interval;             /* how many seconds between emits */
+  gint minfreq;                 /* initial frequency on scan for fundamental frequency */
+  gint maxfreq;                 /* final frequency on scan for fundamental frequency */
+  gint nfft;                    /* number of samples taken for FFT */
+
+  /* <private> */
+  gint rate;                    /* caps variables */
+  gint width;
+  gint channels;
+
+  gint num_frames;              /* frame count (1 sample per channel) */
+  /* since last emit */
+
+  kiss_fft_cfg fft_cfg;
+  kiss_fft_cpx *signal;
+  kiss_fft_cpx *spectrum;
+};
+
+struct _GstPitchClass
+{
+  GstBaseTransformClass parent_class;
+};
+
+GType gst_pithc_get_type (void);
+
+G_END_DECLS
+#endif /* __GST_PITCH_H__ */
diff --git a/src/gsttonesrc.c b/src/gsttonesrc.c
new file mode 100644 (file)
index 0000000..e5057c9
--- /dev/null
@@ -0,0 +1,365 @@
+/* Derived code of GStreamer - AudioTestSrc element
+ * Copyright (C) 2005 Stefan Kost <ensonic@users.sf.net>
+ * Copyright (C) 2008 Josep Torra <j.torra@telefonica.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+#include <gst/controller/gstcontroller.h>
+
+#include "gsttonesrc.h"
+
+#ifndef M_PI
+#define M_PI  3.14159265358979323846
+#endif
+
+#ifndef M_PI_2
+#define M_PI_2  1.57079632679489661923
+#endif
+
+#define M_PI_M2 ( M_PI + M_PI )
+
+GST_DEBUG_CATEGORY_STATIC (tone_src_debug);
+#define GST_CAT_DEFAULT tone_src_debug
+
+static const GstElementDetails gst_tone_src_details =
+GST_ELEMENT_DETAILS ("Tone source",
+    "Source/Audio",
+    "Creates audio test signals of given frequency and volume",
+    "Stefan Kost <ensonic@users.sf.net>");
+
+
+enum
+{
+  PROP_0,
+  PROP_SAMPLES_PER_BUFFER,
+  PROP_FREQ,
+  PROP_VOLUME,
+};
+
+
+static GstStaticPadTemplate gst_tone_src_src_template =
+    GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("audio/x-raw-int, "
+        "endianness = (int) BYTE_ORDER, "
+        "signed = (boolean) true, "
+        "width = (int) 16, "
+        "depth = (int) 16, "
+        "rate = (int) [ 1, MAX ], "
+        "channels = (int) 1; "
+        "audio/x-raw-int, "
+        "endianness = (int) BYTE_ORDER, "
+        "signed = (boolean) true, "
+        "width = (int) 32, "
+        "depth = (int) 32,"
+        "rate = (int) [ 1, MAX ], "
+        "channels = (int) 1; "
+        "audio/x-raw-float, "
+        "endianness = (int) BYTE_ORDER, "
+        "width = (int) { 32, 64 }, "
+        "rate = (int) [ 1, MAX ], " "channels = (int) 1")
+    );
+
+
+GST_BOILERPLATE (GstToneSrc, gst_tone_src, GstBaseSrc, GST_TYPE_BASE_SRC);
+
+static void gst_tone_src_set_property (GObject * object,
+    guint prop_id, const GValue * value, GParamSpec * pspec);
+static void gst_tone_src_get_property (GObject * object,
+    guint prop_id, GValue * value, GParamSpec * pspec);
+
+static gboolean gst_tone_src_setcaps (GstBaseSrc * basesrc, GstCaps * caps);
+static void gst_tone_src_src_fixate (GstPad * pad, GstCaps * caps);
+
+static GstFlowReturn gst_tone_src_create (GstBaseSrc * basesrc,
+    guint64 offset, guint length, GstBuffer ** buffer);
+
+#define DEFINE_OSCILATOR(type,scale) \
+static void \
+gst_tone_src_create_oscilator_##type (GstToneSrc * src, g##type * samples) \
+{ \
+  gint i; \
+  gdouble step, amp; \
+  \
+  step = M_PI_M2 * src->freq / src->samplerate; \
+  amp = src->volume * scale; \
+  \
+  for (i = 0; i < src->generate_samples_per_buffer; i++) { \
+    src->accumulator += step; \
+    if (src->accumulator >= M_PI_M2) \
+      src->accumulator -= M_PI_M2; \
+    \
+    samples[i] = (g##type) (sin (src->accumulator) * amp); \
+  } \
+}
+
+DEFINE_OSCILATOR (int16, 32767.0);
+DEFINE_OSCILATOR (int32, 2147483647.0);
+DEFINE_OSCILATOR (float, 1.0);
+DEFINE_OSCILATOR (double, 1.0);
+
+static ProcessFunc oscilator_funcs[] = {
+  (ProcessFunc) gst_tone_src_create_oscilator_int16,
+  (ProcessFunc) gst_tone_src_create_oscilator_int32,
+  (ProcessFunc) gst_tone_src_create_oscilator_float,
+  (ProcessFunc) gst_tone_src_create_oscilator_double
+};
+
+static void
+gst_tone_src_base_init (gpointer g_class)
+{
+  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&gst_tone_src_src_template));
+  gst_element_class_set_details (element_class, &gst_tone_src_details);
+}
+
+static void
+gst_tone_src_class_init (GstToneSrcClass * klass)
+{
+  GObjectClass *gobject_class;
+  GstBaseSrcClass *gstbasesrc_class;
+
+  gobject_class = (GObjectClass *) klass;
+  gstbasesrc_class = (GstBaseSrcClass *) klass;
+
+  gobject_class->set_property = gst_tone_src_set_property;
+  gobject_class->get_property = gst_tone_src_get_property;
+
+  g_object_class_install_property (gobject_class, PROP_SAMPLES_PER_BUFFER,
+      g_param_spec_int ("samplesperbuffer", "Samples per buffer",
+          "Number of samples in each outgoing buffer",
+          1, G_MAXINT, 1024, G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class, PROP_FREQ,
+      g_param_spec_double ("freq", "Frequency", "Frequency of test signal",
+          0.0, 20000.0, 440.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+  g_object_class_install_property (gobject_class, PROP_VOLUME,
+      g_param_spec_double ("volume", "Volume", "Volume of test signal", 0.0,
+          1.0, 0.8, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+
+  gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_tone_src_setcaps);
+  gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_tone_src_create);
+}
+
+static void
+gst_tone_src_init (GstToneSrc * src, GstToneSrcClass * g_class)
+{
+  GstPad *pad = GST_BASE_SRC_PAD (src);
+
+  gst_pad_set_fixatecaps_function (pad, gst_tone_src_src_fixate);
+
+  src->samplerate = 44100;
+  src->format = GST_TONE_SRC_FORMAT_NONE;
+  src->volume = 0.8;
+  src->freq = 440.0;
+
+  /* we operate in time */
+  gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
+  gst_base_src_set_live (GST_BASE_SRC (src), FALSE);
+
+  src->samples_per_buffer = 1024;
+  src->generate_samples_per_buffer = src->samples_per_buffer;
+}
+
+static void
+gst_tone_src_src_fixate (GstPad * pad, GstCaps * caps)
+{
+  GstToneSrc *src = GST_TONE_SRC (GST_PAD_PARENT (pad));
+  const gchar *name;
+  GstStructure *structure;
+
+  structure = gst_caps_get_structure (caps, 0);
+
+  gst_structure_fixate_field_nearest_int (structure, "rate", src->samplerate);
+
+  name = gst_structure_get_name (structure);
+  if (strcmp (name, "audio/x-raw-int") == 0)
+    gst_structure_fixate_field_nearest_int (structure, "width", 32);
+  else if (strcmp (name, "audio/x-raw-float") == 0)
+    gst_structure_fixate_field_nearest_int (structure, "width", 64);
+}
+
+static gboolean
+gst_tone_src_setcaps (GstBaseSrc * basesrc, GstCaps * caps)
+{
+  GstToneSrc *src = GST_TONE_SRC (basesrc);
+  const GstStructure *structure;
+  const gchar *name;
+  gint width;
+  gboolean ret;
+
+  structure = gst_caps_get_structure (caps, 0);
+  ret = gst_structure_get_int (structure, "rate", &src->samplerate);
+
+  name = gst_structure_get_name (structure);
+  if (strcmp (name, "audio/x-raw-int") == 0) {
+    ret &= gst_structure_get_int (structure, "width", &width);
+    src->format = (width == 32) ? GST_TONE_SRC_FORMAT_S32 :
+        GST_TONE_SRC_FORMAT_S16;
+  } else {
+    ret &= gst_structure_get_int (structure, "width", &width);
+    src->format = (width == 32) ? GST_TONE_SRC_FORMAT_F32 :
+        GST_TONE_SRC_FORMAT_F64;
+  }
+
+  src->process = oscilator_funcs[src->format];
+
+  return ret;
+}
+
+
+
+static GstFlowReturn
+gst_tone_src_create (GstBaseSrc * basesrc, guint64 offset,
+    guint length, GstBuffer ** buffer)
+{
+  GstFlowReturn res;
+  GstToneSrc *src;
+  GstBuffer *buf;
+  GstClockTime next_time;
+  gint64 n_samples;
+  gint sample_size;
+
+  src = GST_TONE_SRC (basesrc);
+
+  /* allocate a new buffer suitable for this pad */
+  switch (src->format) {
+    case GST_TONE_SRC_FORMAT_S16:
+      sample_size = sizeof (gint16);
+      break;
+    case GST_TONE_SRC_FORMAT_S32:
+      sample_size = sizeof (gint32);
+      break;
+    case GST_TONE_SRC_FORMAT_F32:
+      sample_size = sizeof (gfloat);
+      break;
+    case GST_TONE_SRC_FORMAT_F64:
+      sample_size = sizeof (gdouble);
+      break;
+    default:
+      sample_size = -1;
+      GST_ELEMENT_ERROR (src, CORE, NEGOTIATION, (NULL),
+          ("format wasn't negotiated before get function"));
+      return GST_FLOW_NOT_NEGOTIATED;
+      break;
+  }
+
+  n_samples = src->n_samples + src->samples_per_buffer;
+  next_time = gst_util_uint64_scale (n_samples, GST_SECOND,
+      (guint64) src->samplerate);
+
+  if ((res = gst_pad_alloc_buffer (basesrc->srcpad, src->n_samples,
+              src->generate_samples_per_buffer * sample_size,
+              GST_PAD_CAPS (basesrc->srcpad), &buf)) != GST_FLOW_OK) {
+    return res;
+  }
+
+  GST_BUFFER_TIMESTAMP (buf) = src->timestamp_offset + src->running_time;
+  GST_BUFFER_OFFSET_END (buf) = n_samples;
+  GST_BUFFER_DURATION (buf) = next_time - src->running_time;
+
+  gst_object_sync_values (G_OBJECT (src), src->running_time);
+
+  src->running_time = next_time;
+  src->n_samples = n_samples;
+
+  GST_LOG_OBJECT (src, "generating %u samples at ts %" GST_TIME_FORMAT,
+      length, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
+
+  src->process (src, GST_BUFFER_DATA (buf));
+
+  if (G_UNLIKELY ((src->volume == 0.0))) {
+    GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_GAP);
+  }
+
+  *buffer = buf;
+
+  return GST_FLOW_OK;
+}
+
+static void
+gst_tone_src_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstToneSrc *src = GST_TONE_SRC (object);
+
+  switch (prop_id) {
+    case PROP_SAMPLES_PER_BUFFER:
+      src->samples_per_buffer = g_value_get_int (value);
+      break;
+    case PROP_FREQ:
+      src->freq = g_value_get_double (value);
+      break;
+    case PROP_VOLUME:
+      src->volume = g_value_get_double (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+gst_tone_src_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstToneSrc *src = GST_TONE_SRC (object);
+
+  switch (prop_id) {
+    case PROP_SAMPLES_PER_BUFFER:
+      g_value_set_int (value, src->samples_per_buffer);
+      break;
+    case PROP_FREQ:
+      g_value_set_double (value, src->freq);
+      break;
+    case PROP_VOLUME:
+      g_value_set_double (value, src->volume);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+/*static*/ gboolean
+plugin_tonesrc_init (GstPlugin * plugin)
+{
+  /* initialize gst controller library */
+  gst_controller_init (NULL, NULL);
+
+  GST_DEBUG_CATEGORY_INIT (tone_src_debug, "tonesrc", 0, "Audio Test Source");
+
+  return gst_element_register (plugin, "tonesrc",
+      GST_RANK_NONE, GST_TYPE_TONE_SRC);
+}
+
+/*
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+    GST_VERSION_MINOR,
+    "tonesrc",
+    "Creates audio test signals of given frequency and volume",
+    plugin_init, VERSION, "LGPL", NULL, NULL);
+*/
diff --git a/src/gsttonesrc.h b/src/gsttonesrc.h
new file mode 100644 (file)
index 0000000..70ed02b
--- /dev/null
@@ -0,0 +1,95 @@
+/* GStreamer
+ * Copyright (C) 2005 Stefan Kost <ensonic@users.sf.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GST_TONE_SRC_H__
+#define __GST_TONE_SRC_H__
+
+
+#include <gst/gst.h>
+#include <gst/base/gstbasesrc.h>
+
+G_BEGIN_DECLS
+#define GST_TYPE_TONE_SRC \
+  (gst_tone_src_get_type())
+#define GST_TONE_SRC(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_TONE_SRC,GstToneSrc))
+#define GST_TONE_SRC_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_TONE_SRC,GstToneSrcClass))
+#define GST_IS_TONE_SRC(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_TONE_SRC))
+#define GST_IS_TONE_SRC_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TONE_SRC))
+    typedef enum
+{
+  GST_TONE_SRC_FORMAT_NONE = -1,
+  GST_TONE_SRC_FORMAT_S16 = 0,
+  GST_TONE_SRC_FORMAT_S32,
+  GST_TONE_SRC_FORMAT_F32,
+  GST_TONE_SRC_FORMAT_F64
+} GstToneSrcFormat;
+
+typedef struct _GstToneSrc GstToneSrc;
+typedef struct _GstToneSrcClass GstToneSrcClass;
+
+typedef void (*ProcessFunc) (GstToneSrc *, guint8 *);
+
+/**
+ * GstToneSrc:
+ *
+ * audiotestsrc object structure.
+ */
+struct _GstToneSrc
+{
+  GstBaseSrc parent;
+
+  ProcessFunc process;
+
+  /* parameters */
+  gdouble volume;
+  gdouble freq;
+
+  /* audio parameters */
+  gint samplerate;
+  gint samples_per_buffer;
+  GstToneSrcFormat format;
+
+  /*< private > */
+  gboolean tags_pushed;         /* send tags just once ? */
+
+  GstClockTimeDiff timestamp_offset;    /* base offset */
+  GstClockTime running_time;    /* total running time */
+  gint64 n_samples;             /* total samples sent */
+  gint64 n_samples_stop;
+
+  gboolean eos_reached;
+  gint generate_samples_per_buffer;     /* used to generate a partial buffer */
+
+  /* waveform specific context data */
+  gdouble accumulator;          /* phase angle */
+};
+
+struct _GstToneSrcClass
+{
+  GstBaseSrcClass parent_class;
+};
+
+GType gst_tone_src_get_type (void);
+
+G_END_DECLS
+#endif /* __GST_TONE_SRC_H__ */
diff --git a/src/kiss_fft.c b/src/kiss_fft.c
new file mode 100644 (file)
index 0000000..1ea5705
--- /dev/null
@@ -0,0 +1,431 @@
+/*
+Copyright (c) 2003-2004, Mark Borgerding
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+    * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#include "_kiss_fft_guts.h"
+/* The guts header contains all the multiplication and addition macros that are defined for
+ fixed or floating point complex numbers.  It also delares the kf_ internal functions.
+ */
+
+static kiss_fft_cpx *scratchbuf = NULL;
+static size_t nscratchbuf = 0;
+static kiss_fft_cpx *tmpbuf = NULL;
+static size_t ntmpbuf = 0;
+
+#define CHECKBUF(buf,nbuf,n) \
+    do { \
+        if ( nbuf < (size_t)(n) ) {\
+            free(buf); \
+            buf = (kiss_fft_cpx*)KISS_FFT_MALLOC(sizeof(kiss_fft_cpx)*(n)); \
+            nbuf = (size_t)(n); \
+        } \
+   }while(0)
+
+
+static void
+kf_bfly2 (kiss_fft_cpx * Fout,
+    const size_t fstride, const kiss_fft_cfg st, int m)
+{
+  kiss_fft_cpx *Fout2;
+  kiss_fft_cpx *tw1 = st->twiddles;
+  kiss_fft_cpx t;
+
+  Fout2 = Fout + m;
+  do {
+    C_FIXDIV (*Fout, 2);
+    C_FIXDIV (*Fout2, 2);
+
+    C_MUL (t, *Fout2, *tw1);
+    tw1 += fstride;
+    C_SUB (*Fout2, *Fout, t);
+    C_ADDTO (*Fout, t);
+    ++Fout2;
+    ++Fout;
+  } while (--m);
+}
+
+static void
+kf_bfly4 (kiss_fft_cpx * Fout,
+    const size_t fstride, const kiss_fft_cfg st, const size_t m)
+{
+  kiss_fft_cpx *tw1, *tw2, *tw3;
+  kiss_fft_cpx scratch[6];
+  size_t k = m;
+  const size_t m2 = 2 * m;
+  const size_t m3 = 3 * m;
+
+  tw3 = tw2 = tw1 = st->twiddles;
+
+  do {
+    C_FIXDIV (*Fout, 4);
+    C_FIXDIV (Fout[m], 4);
+    C_FIXDIV (Fout[m2], 4);
+    C_FIXDIV (Fout[m3], 4);
+
+    C_MUL (scratch[0], Fout[m], *tw1);
+    C_MUL (scratch[1], Fout[m2], *tw2);
+    C_MUL (scratch[2], Fout[m3], *tw3);
+
+    C_SUB (scratch[5], *Fout, scratch[1]);
+    C_ADDTO (*Fout, scratch[1]);
+    C_ADD (scratch[3], scratch[0], scratch[2]);
+    C_SUB (scratch[4], scratch[0], scratch[2]);
+    C_SUB (Fout[m2], *Fout, scratch[3]);
+    tw1 += fstride;
+    tw2 += fstride * 2;
+    tw3 += fstride * 3;
+    C_ADDTO (*Fout, scratch[3]);
+
+    if (st->inverse) {
+      Fout[m].r = scratch[5].r - scratch[4].i;
+      Fout[m].i = scratch[5].i + scratch[4].r;
+      Fout[m3].r = scratch[5].r + scratch[4].i;
+      Fout[m3].i = scratch[5].i - scratch[4].r;
+    } else {
+      Fout[m].r = scratch[5].r + scratch[4].i;
+      Fout[m].i = scratch[5].i - scratch[4].r;
+      Fout[m3].r = scratch[5].r - scratch[4].i;
+      Fout[m3].i = scratch[5].i + scratch[4].r;
+    }
+    ++Fout;
+  } while (--k);
+}
+
+static void
+kf_bfly3 (kiss_fft_cpx * Fout,
+    const size_t fstride, const kiss_fft_cfg st, size_t m)
+{
+  size_t k = m;
+  const size_t m2 = 2 * m;
+  kiss_fft_cpx *tw1, *tw2;
+  kiss_fft_cpx scratch[5];
+  kiss_fft_cpx epi3;
+
+  epi3 = st->twiddles[fstride * m];
+
+  tw1 = tw2 = st->twiddles;
+
+  do {
+    C_FIXDIV (*Fout, 3);
+    C_FIXDIV (Fout[m], 3);
+    C_FIXDIV (Fout[m2], 3);
+
+    C_MUL (scratch[1], Fout[m], *tw1);
+    C_MUL (scratch[2], Fout[m2], *tw2);
+
+    C_ADD (scratch[3], scratch[1], scratch[2]);
+    C_SUB (scratch[0], scratch[1], scratch[2]);
+    tw1 += fstride;
+    tw2 += fstride * 2;
+
+    Fout[m].r = Fout->r - HALF_OF (scratch[3].r);
+    Fout[m].i = Fout->i - HALF_OF (scratch[3].i);
+
+    C_MULBYSCALAR (scratch[0], epi3.i);
+
+    C_ADDTO (*Fout, scratch[3]);
+
+    Fout[m2].r = Fout[m].r + scratch[0].i;
+    Fout[m2].i = Fout[m].i - scratch[0].r;
+
+    Fout[m].r -= scratch[0].i;
+    Fout[m].i += scratch[0].r;
+
+    ++Fout;
+  } while (--k);
+}
+
+static void
+kf_bfly5 (kiss_fft_cpx * Fout,
+    const size_t fstride, const kiss_fft_cfg st, int m)
+{
+  kiss_fft_cpx *Fout0, *Fout1, *Fout2, *Fout3, *Fout4;
+  int u;
+  kiss_fft_cpx scratch[13];
+  kiss_fft_cpx *twiddles = st->twiddles;
+  kiss_fft_cpx *tw;
+  kiss_fft_cpx ya, yb;
+
+  ya = twiddles[fstride * m];
+  yb = twiddles[fstride * 2 * m];
+
+  Fout0 = Fout;
+  Fout1 = Fout0 + m;
+  Fout2 = Fout0 + 2 * m;
+  Fout3 = Fout0 + 3 * m;
+  Fout4 = Fout0 + 4 * m;
+
+  tw = st->twiddles;
+  for (u = 0; u < m; ++u) {
+    C_FIXDIV (*Fout0, 5);
+    C_FIXDIV (*Fout1, 5);
+    C_FIXDIV (*Fout2, 5);
+    C_FIXDIV (*Fout3, 5);
+    C_FIXDIV (*Fout4, 5);
+    scratch[0] = *Fout0;
+
+    C_MUL (scratch[1], *Fout1, tw[u * fstride]);
+    C_MUL (scratch[2], *Fout2, tw[2 * u * fstride]);
+    C_MUL (scratch[3], *Fout3, tw[3 * u * fstride]);
+    C_MUL (scratch[4], *Fout4, tw[4 * u * fstride]);
+
+    C_ADD (scratch[7], scratch[1], scratch[4]);
+    C_SUB (scratch[10], scratch[1], scratch[4]);
+    C_ADD (scratch[8], scratch[2], scratch[3]);
+    C_SUB (scratch[9], scratch[2], scratch[3]);
+
+    Fout0->r += scratch[7].r + scratch[8].r;
+    Fout0->i += scratch[7].i + scratch[8].i;
+
+    scratch[5].r =
+        scratch[0].r + S_MUL (scratch[7].r, ya.r) + S_MUL (scratch[8].r, yb.r);
+    scratch[5].i =
+        scratch[0].i + S_MUL (scratch[7].i, ya.r) + S_MUL (scratch[8].i, yb.r);
+
+    scratch[6].r = S_MUL (scratch[10].i, ya.i) + S_MUL (scratch[9].i, yb.i);
+    scratch[6].i = -S_MUL (scratch[10].r, ya.i) - S_MUL (scratch[9].r, yb.i);
+
+    C_SUB (*Fout1, scratch[5], scratch[6]);
+    C_ADD (*Fout4, scratch[5], scratch[6]);
+
+    scratch[11].r =
+        scratch[0].r + S_MUL (scratch[7].r, yb.r) + S_MUL (scratch[8].r, ya.r);
+    scratch[11].i =
+        scratch[0].i + S_MUL (scratch[7].i, yb.r) + S_MUL (scratch[8].i, ya.r);
+    scratch[12].r = -S_MUL (scratch[10].i, yb.i) + S_MUL (scratch[9].i, ya.i);
+    scratch[12].i = S_MUL (scratch[10].r, yb.i) - S_MUL (scratch[9].r, ya.i);
+
+    C_ADD (*Fout2, scratch[11], scratch[12]);
+    C_SUB (*Fout3, scratch[11], scratch[12]);
+
+    ++Fout0;
+    ++Fout1;
+    ++Fout2;
+    ++Fout3;
+    ++Fout4;
+  }
+}
+
+/* perform the butterfly for one stage of a mixed radix FFT */
+static void
+kf_bfly_generic (kiss_fft_cpx * Fout,
+    const size_t fstride, const kiss_fft_cfg st, int m, int p)
+{
+  int u, k, q1, q;
+  kiss_fft_cpx *twiddles = st->twiddles;
+  kiss_fft_cpx t;
+  int Norig = st->nfft;
+
+  CHECKBUF (scratchbuf, nscratchbuf, p);
+
+  for (u = 0; u < m; ++u) {
+    k = u;
+    for (q1 = 0; q1 < p; ++q1) {
+      scratchbuf[q1] = Fout[k];
+      C_FIXDIV (scratchbuf[q1], p);
+      k += m;
+    }
+
+    k = u;
+    for (q1 = 0; q1 < p; ++q1) {
+      int twidx = 0;
+
+      Fout[k] = scratchbuf[0];
+      for (q = 1; q < p; ++q) {
+        twidx += fstride * k;
+        if (twidx >= Norig)
+          twidx -= Norig;
+        C_MUL (t, scratchbuf[q], twiddles[twidx]);
+        C_ADDTO (Fout[k], t);
+      }
+      k += m;
+    }
+  }
+}
+
+static void
+kf_work (kiss_fft_cpx * Fout,
+    const kiss_fft_cpx * f,
+    const size_t fstride, int in_stride, int *factors, const kiss_fft_cfg st)
+{
+  kiss_fft_cpx *Fout_beg = Fout;
+  const int p = *factors++;     /* the radix  */
+  const int m = *factors++;     /* stage's fft length/p */
+  const kiss_fft_cpx *Fout_end = Fout + p * m;
+
+  if (m == 1) {
+    do {
+      *Fout = *f;
+      f += fstride * in_stride;
+    } while (++Fout != Fout_end);
+  } else {
+    do {
+      kf_work (Fout, f, fstride * p, in_stride, factors, st);
+      f += fstride * in_stride;
+    } while ((Fout += m) != Fout_end);
+  }
+
+  Fout = Fout_beg;
+
+  switch (p) {
+    case 2:
+      kf_bfly2 (Fout, fstride, st, m);
+      break;
+    case 3:
+      kf_bfly3 (Fout, fstride, st, m);
+      break;
+    case 4:
+      kf_bfly4 (Fout, fstride, st, m);
+      break;
+    case 5:
+      kf_bfly5 (Fout, fstride, st, m);
+      break;
+    default:
+      kf_bfly_generic (Fout, fstride, st, m, p);
+      break;
+  }
+}
+
+/*  facbuf is populated by p1,m1,p2,m2, ...
+    where 
+    p[i] * m[i] = m[i-1]
+    m0 = n                  */
+static void
+kf_factor (int n, int *facbuf)
+{
+  int p = 4;
+  double floor_sqrt;
+
+  floor_sqrt = floor (sqrt ((double) n));
+
+  /*factor out powers of 4, powers of 2, then any remaining primes */
+  do {
+    while (n % p) {
+      switch (p) {
+        case 4:
+          p = 2;
+          break;
+        case 2:
+          p = 3;
+          break;
+        default:
+          p += 2;
+          break;
+      }
+      if (p > floor_sqrt)
+        p = n;                  /* no more factors, skip to end */
+    }
+    n /= p;
+    *facbuf++ = p;
+    *facbuf++ = n;
+  } while (n > 1);
+}
+
+/*
+ *
+ * User-callable function to allocate all necessary storage space for the fft.
+ *
+ * The return value is a contiguous block of memory, allocated with malloc.  As such,
+ * It can be freed with free(), rather than a kiss_fft-specific function.
+ * */
+kiss_fft_cfg
+kiss_fft_alloc (int nfft, int inverse_fft, void *mem, size_t * lenmem)
+{
+  kiss_fft_cfg st = NULL;
+  size_t memneeded = sizeof (struct kiss_fft_state)
+      + sizeof (kiss_fft_cpx) * (nfft - 1);     /* twiddle factors */
+
+  if (lenmem == NULL) {
+    st = (kiss_fft_cfg) KISS_FFT_MALLOC (memneeded);
+  } else {
+    if (mem != NULL && *lenmem >= memneeded)
+      st = (kiss_fft_cfg) mem;
+    *lenmem = memneeded;
+  }
+  if (st) {
+    int i;
+
+    st->nfft = nfft;
+    st->inverse = inverse_fft;
+
+    for (i = 0; i < nfft; ++i) {
+      const double pi =
+          3.141592653589793238462643383279502884197169399375105820974944;
+      double phase = -2 * pi * i / nfft;
+
+      if (st->inverse)
+        phase *= -1;
+      kf_cexp (st->twiddles + i, phase);
+    }
+
+    kf_factor (nfft, st->factors);
+  }
+  return st;
+}
+
+
+
+
+void
+kiss_fft_stride (kiss_fft_cfg st, const kiss_fft_cpx * fin, kiss_fft_cpx * fout,
+    int in_stride)
+{
+  if (fin == fout) {
+    CHECKBUF (tmpbuf, ntmpbuf, st->nfft);
+    kf_work (tmpbuf, fin, 1, in_stride, st->factors, st);
+    memcpy (fout, tmpbuf, sizeof (kiss_fft_cpx) * st->nfft);
+  } else {
+    kf_work (fout, fin, 1, in_stride, st->factors, st);
+  }
+}
+
+void
+kiss_fft (kiss_fft_cfg cfg, const kiss_fft_cpx * fin, kiss_fft_cpx * fout)
+{
+  kiss_fft_stride (cfg, fin, fout, 1);
+}
+
+
+/* not really necessary to call, but if someone is doing in-place ffts, they may want to free the 
+   buffers from CHECKBUF
+ */
+void
+kiss_fft_cleanup (void)
+{
+  free (scratchbuf);
+  scratchbuf = NULL;
+  nscratchbuf = 0;
+  free (tmpbuf);
+  tmpbuf = NULL;
+  ntmpbuf = 0;
+}
+
+int
+kiss_fft_next_fast_size (int n)
+{
+  while (1) {
+    int m = n;
+
+    while ((m % 2) == 0)
+      m /= 2;
+    while ((m % 3) == 0)
+      m /= 3;
+    while ((m % 5) == 0)
+      m /= 5;
+    if (m <= 1)
+      break;                    /* n is completely factorable by twos, threes, and fives */
+    n++;
+  }
+  return n;
+}
diff --git a/src/kiss_fft.h b/src/kiss_fft.h
new file mode 100644 (file)
index 0000000..75a4b69
--- /dev/null
@@ -0,0 +1,124 @@
+#ifndef KISS_FFT_H
+#define KISS_FFT_H
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <memory.h>
+#include <malloc.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/*
+ ATTENTION!
+ If you would like a :
+ -- a utility that will handle the caching of fft objects
+ -- real-only (no imaginary time component ) FFT
+ -- a multi-dimensional FFT
+ -- a command-line utility to perform ffts
+ -- a command-line utility to perform fast-convolution filtering
+
+ Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c
+  in the tools/ directory.
+*/
+
+#ifdef USE_SIMD
+# include <xmmintrin.h>
+# define kiss_fft_scalar __m128
+#define KISS_FFT_MALLOC(nbytes) memalign(16,nbytes)
+#else
+#define KISS_FFT_MALLOC malloc
+#endif
+
+
+#ifdef FIXED_POINT
+#include <sys/types.h>
+# if (FIXED_POINT == 32)
+#  define kiss_fft_scalar int32_t
+# else
+#  define kiss_fft_scalar int16_t
+# endif
+#else
+# ifndef kiss_fft_scalar
+/*  default is float */
+#   define kiss_fft_scalar float
+# endif
+#endif
+
+  typedef struct
+  {
+    kiss_fft_scalar r;
+    kiss_fft_scalar i;
+  } kiss_fft_cpx;
+
+  typedef struct kiss_fft_state *kiss_fft_cfg;
+
+/* 
+ *  kiss_fft_alloc
+ *  
+ *  Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
+ *
+ *  typical usage:      kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL);
+ *
+ *  The return value from fft_alloc is a cfg buffer used internally
+ *  by the fft routine or NULL.
+ *
+ *  If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc.
+ *  The returned value should be free()d when done to avoid memory leaks.
+ *  
+ *  The state can be placed in a user supplied buffer 'mem':
+ *  If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
+ *      then the function places the cfg in mem and the size used in *lenmem
+ *      and returns mem.
+ *  
+ *  If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
+ *      then the function returns NULL and places the minimum cfg 
+ *      buffer size in *lenmem.
+ * */
+
+  kiss_fft_cfg kiss_fft_alloc (int nfft, int inverse_fft, void *mem,
+      size_t * lenmem);
+
+/*
+ * kiss_fft(cfg,in_out_buf)
+ *
+ * Perform an FFT on a complex input buffer.
+ * for a forward FFT,
+ * fin should be  f[0] , f[1] , ... ,f[nfft-1]
+ * fout will be   F[0] , F[1] , ... ,F[nfft-1]
+ * Note that each element is complex and can be accessed like
+    f[k].r and f[k].i
+ * */
+  void kiss_fft (kiss_fft_cfg cfg, const kiss_fft_cpx * fin,
+      kiss_fft_cpx * fout);
+
+/*
+ A more generic version of the above function. It reads its input from every Nth sample.
+ * */
+  void kiss_fft_stride (kiss_fft_cfg cfg, const kiss_fft_cpx * fin,
+      kiss_fft_cpx * fout, int fin_stride);
+
+/* If kiss_fft_alloc allocated a buffer, it is one contiguous 
+   buffer and can be simply free()d when no longer needed*/
+#define kiss_fft_free free
+
+/*
+ Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up 
+ your compiler output to call this before you exit.
+*/
+  void kiss_fft_cleanup (void);
+
+
+/*
+ * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5)
+ */
+  int kiss_fft_next_fast_size (int n);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/tuner.c b/src/tuner.c
new file mode 100644 (file)
index 0000000..795406f
--- /dev/null
@@ -0,0 +1,637 @@
+/* vim: set sts=2 sw=2 et: */
+/* Tuner
+ * Copyright (C) 2006 Josep Torra <j.torra@telefonica.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define TUNER_VERSION "0.4"
+
+#ifdef HILDON
+#  if HILDON==1
+#    include <hildon/hildon-program.h>
+#    include <hildon/hildon-number-editor.h>
+#  elif defined(MAEMO1)
+#    include <hildon-widgets/hildon-app.h>
+#    include <hildon-widgets/hildon-appview.h>
+#  else
+#    include <hildon-widgets/hildon-program.h>
+#  endif
+
+#include <libosso.h>
+
+#define OSSO_PACKAGE "tuner-tool"
+#define OSSO_VERSION TUNER_VERSION
+
+#endif /* ifdef HILDON */
+
+#ifdef MAEMO
+# define DEFAULT_AUDIOSRC "dsppcmsrc"
+# define DEFAULT_AUDIOSINK "dsppcmsink"
+#else
+# define DEFAULT_AUDIOSRC "alsasrc"
+# define DEFAULT_AUDIOSINK "alsasink"
+#endif
+
+
+#include <string.h>
+#include <math.h>
+#include <gst/gst.h>
+#include <gtk/gtk.h>
+
+#define between(x,a,b) (((x)>=(a)) && ((x)<=(b)))
+
+#define MAGIC (1.059463094359f) /* 2^(1/2) */
+
+extern gboolean plugin_pitch_init (GstPlugin * plugin);
+extern gboolean plugin_tonesrc_init (GstPlugin * plugin);
+
+typedef struct
+{
+  const gchar *name;
+  gfloat frequency;
+} Note;
+
+enum
+{
+  NUM_NOTES = 96
+};
+
+enum
+{
+  CALIB_MIN = 430,
+  CALIB_MAX = 450,
+  CALIB_DEFAULT = 440
+};
+
+#define NUM_LEDS (66)
+
+static Note equal_tempered_scale[] = {
+  {"C0", 16.35},
+  {"C#0/Db0", 17.32},
+  {"D0", 18.35},
+  {"D#0/Eb0", 19.45},
+  {"E0", 20.60},
+  {"F0", 21.83},
+  {"F#0/Gb0", 23.12},
+  {"G0", 24.50},
+  {"G#0/Ab0", 25.96},
+  {"A0", 27.50},
+  {"A#0/Bb0", 29.14},
+  {"B0", 30.87},
+  {"C1", 32.70},
+  {"C#1/Db1", 34.65},
+  {"D1", 36.71},
+  {"D#1/Eb1", 38.89},
+  {"E1", 41.20},
+  {"F1", 43.65},
+  {"F#1/Gb1", 46.25},
+  {"G1", 49.00},
+  {"G#1/Ab1", 51.91},
+  {"A1", 55.00},
+  {"A#1/Bb1", 58.27},
+  {"B1", 61.74},
+  {"C2", 65.41},
+  {"C#2/Db2", 69.30},
+  {"D2", 73.42},
+  {"D#2/Eb2", 77.78},
+  {"E2", 82.41},
+  {"F2", 87.31},
+  {"F#2/Gb2", 92.50},
+  {"G2", 98.00},
+  {"G#2/Ab2", 103.83},
+  {"A2", 110.00},
+  {"A#2/Bb2", 116.54},
+  {"B2", 123.47},
+  {"C3", 130.81},
+  {"C#3/Db3", 138.59},
+  {"D3", 146.83},
+  {"D#3/Eb3", 155.56},
+  {"E3", 164.81},
+  {"F3", 174.61},
+  {"F#3/Gb3", 185.00},
+  {"G3", 196.00},
+  {"G#3/Ab3", 207.65},
+  {"A3", 220.00},
+  {"A#3/Bb3", 233.08},
+  {"B3", 246.94},
+  {"C4", 261.63},
+  {"C#4/Db4", 277.18},
+  {"D4", 293.66},
+  {"D#4/Eb4", 311.13},
+  {"E4", 329.63},
+  {"F4", 349.23},
+  {"F#4/Gb4", 369.99},
+  {"G4", 392.00},
+  {"G#4/Ab4", 415.30},
+  {"A4", 440.00},
+  {"A#4/Bb4", 466.16},
+  {"B4", 493.88},
+  {"C5", 523.25},
+  {"C#5/Db5", 554.37},
+  {"D5", 587.33},
+  {"D#5/Eb5", 622.25},
+  {"E5", 659.26},
+  {"F5", 698.46},
+  {"F#5/Gb5", 739.99},
+  {"G5", 783.99},
+  {"G#5/Ab5", 830.61},
+  {"A5", 880.00},
+  {"A#5/Bb5", 932.33},
+  {"B5", 987.77},
+  {"C6", 1046.50},
+  {"C#6/Db6", 1108.73},
+  {"D6", 1174.66},
+  {"D#6/Eb6", 1244.51},
+  {"E6", 1318.51},
+  {"F6", 1396.91},
+  {"F#6/Gb6", 1479.98},
+  {"G6", 1567.98},
+  {"G#6/Ab6", 1661.22},
+  {"A6", 1760.00},
+  {"A#6/Bb6", 1864.66},
+  {"B6", 1975.53},
+  {"C7", 2093.00},
+  {"C#7/Db7", 2217.46},
+  {"D7", 2349.32},
+  {"D#7/Eb7", 2489.02},
+  {"E7", 2637.02},
+  {"F7", 2793.83},
+  {"F#7/Gb7", 2959.96},
+  {"G7", 3135.96},
+  {"G#7/Ab7", 3322.44},
+  {"A7", 3520.00},
+  {"A#7/Bb7", 3729.31},
+  {"B7", 3951.07},
+};
+
+static GdkColor ledOnColor = { 0, 0 * 255, 180 * 255, 95 * 255 };
+static GdkColor ledOnColor2 = { 0, 180 * 255, 180 * 255, 0 * 255 };
+static GdkColor ledOffColor = { 0, 80 * 255, 80 * 255, 80 * 255 };
+
+GtkWidget *mainWin;
+GtkWidget *targetFrequency;
+GtkWidget *currentFrequency;
+GtkWidget *drawingarea1;
+GtkWidget *drawingarea2;
+
+static void
+recalculate_scale (double a4)
+{
+  int i;
+
+  for (i = 0; i < NUM_NOTES; i++) {
+    equal_tempered_scale[i].frequency = a4 * pow (MAGIC, i - 57);
+    /* fprintf(stdout, "%s: %.2f\n", equal_tempered_scale[i].name, equal_tempered_scale[i].frequency); */
+  }
+}
+
+#ifdef HILDON
+static void
+fix_hildon_number_editor (GtkWidget * widget, gpointer data)
+{
+  if (GTK_IS_EDITABLE (widget)) {
+    gtk_editable_set_editable (GTK_EDITABLE (widget), FALSE);
+    g_object_set (G_OBJECT (widget), "can-focus", FALSE, NULL);
+  }
+}
+#endif
+
+static void
+calibration_changed (GObject * object, GParamSpec * pspec, gpointer user_data)
+{
+  gint value;
+
+#ifdef HILDON
+  value = hildon_number_editor_get_value (HILDON_NUMBER_EDITOR (object));
+#else
+  value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (object));
+#endif
+
+  if (value >= CALIB_MIN && value <= CALIB_MAX) {
+    recalculate_scale (value);
+    g_debug ("Calibration changed to %d Hz", value);
+  }
+}
+
+static void
+on_window_destroy (GtkObject * object, gpointer user_data)
+{
+  gtk_main_quit ();
+}
+
+static void
+draw_leds (gint n)
+{
+  gint i, j, k;
+  static GdkGC *gc = NULL;
+
+  if (!gc) {
+    gc = gdk_gc_new (drawingarea1->window);
+  }
+  gdk_gc_set_rgb_fg_color (gc, &drawingarea1->style->fg[0]);
+
+  gdk_draw_rectangle (drawingarea1->window, gc, TRUE, 0, 0,
+      drawingarea1->allocation.width, drawingarea1->allocation.height);
+
+  if (abs (n) > (NUM_LEDS / 2))
+    n = n / n * (NUM_LEDS / 2);
+
+  if (n > 0) {
+    j = NUM_LEDS / 2 + 1;
+    k = NUM_LEDS / 2 + n;
+  } else {
+    j = NUM_LEDS / 2 + n;
+    k = NUM_LEDS / 2 - 1;
+  }
+
+  // Draw all leds
+  for (i = 0; i < NUM_LEDS; i++) {
+    if (i == NUM_LEDS / 2) {
+      if (n == 0)
+        gdk_gc_set_rgb_fg_color (gc, &ledOnColor2);
+      else
+        gdk_gc_set_rgb_fg_color (gc, &ledOffColor);
+
+      gdk_draw_rectangle (drawingarea1->window, gc, TRUE, (i * 10) + 8, 2, 4,
+          36);
+    } else {
+      if ((i >= j) && (i <= k))
+        gdk_gc_set_rgb_fg_color (gc, &ledOnColor);
+      else
+        gdk_gc_set_rgb_fg_color (gc, &ledOffColor);
+
+      gdk_draw_rectangle (drawingarea1->window, gc, TRUE, (i * 10) + 6, 10, 8,
+          20);
+    }
+  }
+}
+
+/* update frequency info */
+static void
+update_frequency (gint frequency)
+{
+  gchar *buffer;
+  gint i, j;
+  gfloat diff, min_diff;
+
+  min_diff = fabs (frequency - (equal_tempered_scale[0].frequency - 10));
+  for (i = j = 0; i < NUM_NOTES; i++) {
+    diff = fabs (frequency - equal_tempered_scale[i].frequency);
+    if (diff <= min_diff) {
+      min_diff = diff;
+      j = i;
+    } else {
+      break;
+    }
+  }
+
+  buffer =
+      g_strdup_printf ("Nearest note is %s with %.2f Hz frequency",
+      equal_tempered_scale[j].name, equal_tempered_scale[j].frequency);
+  gtk_label_set_text (GTK_LABEL (targetFrequency), buffer);
+  g_free (buffer);
+
+  buffer = g_strdup_printf ("Played frequency is %d Hz", frequency);
+  gtk_label_set_text (GTK_LABEL (currentFrequency), buffer);
+  g_free (buffer);
+
+  draw_leds ((gint) roundf (min_diff));
+}
+
+/* receive spectral data from element message */
+gboolean
+message_handler (GstBus * bus, GstMessage * message, gpointer data)
+{
+  if (message->type == GST_MESSAGE_ELEMENT) {
+    const GstStructure *s = gst_message_get_structure (message);
+    const gchar *name = gst_structure_get_name (s);
+
+    if (strcmp (name, "pitch") == 0) {
+      gint frequency;
+
+      frequency = g_value_get_int (gst_structure_get_value (s, "frequency"));
+      update_frequency (frequency);
+    }
+  }
+  /* we handled the message we want, and ignored the ones we didn't want.
+   * so the core can unref the message for us */
+  return TRUE;
+}
+
+gfloat
+keynote2freq (gint x, gint y)
+{
+  gint i, j, height, found;
+  gfloat frequency = 0;
+
+  height = drawingarea2->allocation.height;
+
+  j = 0;
+  found = 0;
+  for (i = 0; i < 15; i++) {
+    // Test for a white key  
+    j++;
+    if (between (x, i * 45, i * 45 + 44) && between (y, 0, height))
+      found = j;
+    // Test for a black key
+    if (((i % 7) != 2) && ((i % 7) != 6) && (i != 14)) {
+      j++;
+      if (between (x, 24 + i * 45, 24 + i * 45 + 42)
+          && between (y, 0, height / 2))
+        found = j;
+    }
+    if (found) {
+      frequency = equal_tempered_scale[48 + found - 1].frequency;
+      break;
+    }
+  }
+  return frequency;
+}
+
+static gboolean
+expose_event (GtkWidget * widget, GdkEventExpose * event)
+{
+  gint i;
+  static GdkGC *gc = NULL;
+
+  if (!gc) {
+    gc = gdk_gc_new (drawingarea2->window);
+  }
+  gdk_gc_set_rgb_fg_color (gc, &drawingarea2->style->fg[0]);
+
+  gdk_draw_rectangle (drawingarea2->window, gc, FALSE, 0, 0,
+      drawingarea2->allocation.width - 1, drawingarea2->allocation.height - 1);
+
+  for (i = 0; i < 14; i++)
+    gdk_draw_rectangle (drawingarea2->window, gc, FALSE, i * 45, 0,
+        45, drawingarea2->allocation.height - 1);
+
+  for (i = 0; i < 14; i++) {
+    if (((i % 7) != 2) && ((i % 7) != 6))
+      gdk_draw_rectangle (drawingarea2->window, gc, TRUE, 24 + i * 45, 0,
+          42, drawingarea2->allocation.height / 2);
+  }
+  return FALSE;
+}
+
+static gboolean
+key_press_event (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
+{
+  GstElement *piano = GST_ELEMENT (user_data);
+
+  if (event->button == 1) {
+    g_object_set (piano, "freq", (gdouble) keynote2freq (event->x, event->y),
+        "volume", 0.8, NULL);
+  }
+
+  return TRUE;
+}
+
+static gboolean
+key_release_event (GtkWidget * widget, GdkEventButton * event,
+    gpointer user_data)
+{
+  GstElement *piano = GST_ELEMENT (user_data);
+
+  if (event->button == 1) {
+    g_object_set (piano, "volume", 0.0, NULL);
+  }
+
+  return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+#ifdef HILDON
+#if defined(MAEMO1)
+  HildonApp *app = NULL;
+  HildonAppView *view = NULL;
+#else
+  HildonProgram *app = NULL;
+  HildonWindow *view = NULL;
+#endif
+  osso_context_t *osso_context = NULL;  /* handle to osso */
+#endif
+
+  GstElement *bin1, *bin2;
+  GstElement *src1, *pitch, *sink1;
+  GstElement *src2, *sink2;
+  GstBus *bus;
+
+  GtkWidget *mainBox;
+  GtkWidget *box;
+  GtkWidget *label;
+  GtkWidget *alignment;
+  GtkWidget *calibrate;
+  GtkWidget *sep;
+
+#ifndef HILDON
+  GdkPixbuf *icon = NULL;
+  GError *error = NULL;
+#endif
+  gboolean piano_enabled = TRUE;
+
+  /* Init GStreamer */
+  gst_init (&argc, &argv);
+  /* Register the GStreamer plugins */
+  plugin_pitch_init (NULL);
+  plugin_tonesrc_init (NULL);
+
+  recalculate_scale (CALIB_DEFAULT);
+
+  /* Init the gtk - must be called before any hildon stuff */
+  gtk_init (&argc, &argv);
+
+#ifdef HILDON
+#if defined(MAEMO1)
+  /* Create the hildon application and setup the title */
+  app = HILDON_APP (hildon_app_new ());
+  hildon_app_set_title (app, "Tuner Tool");
+  hildon_app_set_two_part_title (app, TRUE);
+#else
+  app = HILDON_PROGRAM (hildon_program_get_instance ());
+  g_set_application_name ("Tuner Tool");
+#endif
+
+  /* Initialize maemo application */
+  osso_context = osso_initialize (OSSO_PACKAGE, OSSO_VERSION, TRUE, NULL);
+
+  /* Check that initialization was ok */
+  if (osso_context == NULL) {
+    g_print ("Bummer, osso failed\n");
+  }
+  g_assert (osso_context);
+
+  mainBox = gtk_vbox_new (FALSE, 0);
+  gtk_container_set_border_width (GTK_CONTAINER (mainBox), 0);
+#if defined(MAEMO1)
+  view = HILDON_APPVIEW (hildon_appview_new ("Tuner"));
+  hildon_appview_set_fullscreen_key_allowed (view, TRUE);
+  mainWin = GTK_WIDGET (app);
+#else
+  view = HILDON_WINDOW (hildon_window_new ());
+  mainWin = GTK_WIDGET (view);
+#endif
+#else
+  mainWin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  gtk_window_set_title (GTK_WINDOW (mainWin), "Tuner " TUNER_VERSION);
+  icon = gdk_pixbuf_new_from_file ("tuner64.png", &error);
+  if (icon != NULL) {
+    g_print ("Setting icon\n");
+    gtk_window_set_icon (GTK_WINDOW (mainWin), icon);
+  }
+  mainBox = gtk_vbox_new (FALSE, 0);
+  gtk_container_set_border_width (GTK_CONTAINER (mainBox), 0);
+#endif
+
+  /* Bin for tuner functionality */
+  bin1 = gst_pipeline_new ("bin1");
+
+  src1 = gst_element_factory_make (DEFAULT_AUDIOSRC, "src1");
+  pitch = gst_element_factory_make ("pitch", "pitch");
+  g_object_set (G_OBJECT (pitch), "nfft", 8000, "message", TRUE, "minfreq", 10,
+      "maxfreq", 4000, "interval", GST_SECOND, NULL);
+
+  sink1 = gst_element_factory_make ("fakesink", "sink1");
+  g_object_set (G_OBJECT (sink1), "silent", 1, NULL);
+
+  gst_bin_add_many (GST_BIN (bin1), src1, pitch, sink1, NULL);
+  if (!gst_element_link_many (src1, pitch, sink1, NULL)) {
+    fprintf (stderr, "cant link elements\n");
+    exit (1);
+  }
+
+  bus = gst_element_get_bus (bin1);
+  gst_bus_add_watch (bus, message_handler, NULL);
+  gst_object_unref (bus);
+
+  /* Bin for piano functionality */
+  bin2 = gst_pipeline_new ("bin2");
+
+  //src2 = gst_element_factory_make ("audiotestsrc", "src2");
+  //g_object_set (G_OBJECT (src2), "volume", 0.0, "wave", 7, NULL);
+  src2 = gst_element_factory_make ("tonesrc", "src2");
+  g_object_set (G_OBJECT (src2), "volume", 0.0, NULL);
+  sink2 = gst_element_factory_make (DEFAULT_AUDIOSINK, "sink2");
+
+  gst_bin_add_many (GST_BIN (bin2), src2, sink2, NULL);
+  if (!gst_element_link_many (src2, sink2, NULL)) {
+    piano_enabled = FALSE;
+  }
+
+  /* GUI */
+  g_signal_connect (G_OBJECT (mainWin), "destroy",
+      G_CALLBACK (on_window_destroy), NULL);
+
+  /* Note label */
+  targetFrequency = gtk_label_new ("");
+  gtk_box_pack_start (GTK_BOX (mainBox), targetFrequency, FALSE, FALSE, 5);
+
+  /* Leds */
+  drawingarea1 = gtk_drawing_area_new ();
+  gtk_widget_set_size_request (drawingarea1, 636, 40);
+  gtk_box_pack_start (GTK_BOX (mainBox), drawingarea1, FALSE, FALSE, 5);
+
+  /* Current frequency lable */
+  currentFrequency = gtk_label_new ("");
+  gtk_box_pack_start (GTK_BOX (mainBox), currentFrequency, FALSE, FALSE, 5);
+
+  /* Calibration spinner */
+  box = gtk_hbox_new (FALSE, 0);
+  alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
+  label = gtk_label_new ("Calibration");
+  gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 5);
+
+#ifdef HILDON
+  calibrate = hildon_number_editor_new (CALIB_MIN, CALIB_MAX);
+  hildon_number_editor_set_value (HILDON_NUMBER_EDITOR (calibrate),
+      CALIB_DEFAULT);
+  /* we don't want that ugly cursor there */
+  gtk_container_forall (GTK_CONTAINER (calibrate),
+      (GtkCallback) fix_hildon_number_editor, NULL);
+  g_signal_connect (G_OBJECT (calibrate), "notify::value",
+      G_CALLBACK (calibration_changed), NULL);
+#else
+  calibrate = gtk_spin_button_new_with_range (CALIB_MIN, CALIB_MAX, 1);
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (calibrate), CALIB_DEFAULT);
+  g_signal_connect (G_OBJECT (calibrate), "value_changed",
+      G_CALLBACK (calibration_changed), NULL);
+#endif
+  gtk_box_pack_start (GTK_BOX (box), calibrate, FALSE, FALSE, 5);
+  gtk_container_add (GTK_CONTAINER (alignment), box);
+  gtk_box_pack_start (GTK_BOX (mainBox), alignment, FALSE, FALSE, 5);
+
+  /* Separator */
+  sep = gtk_hseparator_new ();
+
+  /* Credits */
+  gtk_box_pack_start (GTK_BOX (mainBox), sep, FALSE, FALSE, 5);
+
+  label = gtk_label_new ("Tuner Tool developed by Josep Torra.\n"
+      "http://n770galaxy.blogspot.com/");
+  gtk_box_pack_start (GTK_BOX (mainBox), label, FALSE, FALSE, 5);
+
+  /* Piano keyboard */
+  drawingarea2 = gtk_drawing_area_new ();
+  gtk_widget_set_size_request (drawingarea2, 636, 130);
+  gtk_box_pack_start (GTK_BOX (mainBox), drawingarea2, FALSE, FALSE, 5);
+
+  g_signal_connect (G_OBJECT (drawingarea2), "expose_event",
+      G_CALLBACK (expose_event), NULL);
+  if (piano_enabled) {
+    g_signal_connect (G_OBJECT (drawingarea2), "button_press_event",
+        G_CALLBACK (key_press_event), (gpointer) src2);
+
+    g_signal_connect (G_OBJECT (drawingarea2), "button_release_event",
+        G_CALLBACK (key_release_event), (gpointer) src2);
+
+    gtk_widget_set_events (drawingarea2, GDK_EXPOSURE_MASK
+        | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
+  } else {
+    gtk_widget_set_events (drawingarea2, GDK_EXPOSURE_MASK);
+  }
+#ifdef HILDON
+  gtk_container_add (GTK_CONTAINER (view), mainBox);
+#if defined(MAEMO1)
+  hildon_app_set_appview (app, view);
+  gtk_widget_show_all (GTK_WIDGET (app));
+#else
+  hildon_program_add_window (app, view);
+  gtk_widget_show_all (GTK_WIDGET (view));
+#endif
+#else
+  gtk_container_add (GTK_CONTAINER (mainWin), mainBox);
+  gtk_widget_show_all (GTK_WIDGET (mainWin));
+#endif
+
+  gst_element_set_state (bin1, GST_STATE_PLAYING);
+  gst_element_set_state (bin2, GST_STATE_PLAYING);
+  gtk_main ();
+  gst_element_set_state (bin2, GST_STATE_NULL);
+  gst_element_set_state (bin1, GST_STATE_NULL);
+
+  gst_object_unref (bin1);
+  gst_object_unref (bin2);
+
+  return 0;
+}
diff --git a/src/tuner26.png b/src/tuner26.png
new file mode 100644 (file)
index 0000000..772bbe0
Binary files /dev/null and b/src/tuner26.png differ
diff --git a/src/tuner40.png b/src/tuner40.png
new file mode 100644 (file)
index 0000000..0190c89
Binary files /dev/null and b/src/tuner40.png differ
diff --git a/src/tuner64.png b/src/tuner64.png
new file mode 100644 (file)
index 0000000..ca9f3cc
Binary files /dev/null and b/src/tuner64.png differ
diff --git a/tuner.desktop b/tuner.desktop
new file mode 100644 (file)
index 0000000..7932be0
--- /dev/null
@@ -0,0 +1,12 @@
+[Desktop Entry]
+Version=1.0
+Encoding=UTF-8
+Type=Application
+Exec=/usr/bin/tuner
+StartupWMClass=tuner
+Icon=pkg_tuner
+X-Window-Icon=tn-bookmarks-link
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
+Terminal=false
+Name=Tuner