From 8003ea1e0e2655b06b9c59459eaa2da81c6a02c3 Mon Sep 17 00:00:00 2001 From: Dominik Schnitzer Date: Fri, 10 Jan 2014 15:33:58 +0100 Subject: [PATCH] Initial import of musly 0.1 --- AUTHORS | 2 + CMakeLists.txt | 55 + COPYING | 373 +++++ Doxyfile | 1872 ++++++++++++++++++++++++++ cmake/FindEigen3.cmake | 80 ++ cmake/FindLibAV.cmake | 221 +++ config.h.in | 10 + doc/MIREX-DistanceMatrix.md | 71 + include/CMakeLists.txt | 10 + include/minilog.h | 246 ++++ include/musly/musly.h | 387 ++++++ include/musly/musly_types.h | 57 + libmusly/CMakeLists.txt | 41 + libmusly/decoder.cpp | 26 + libmusly/decoder.h | 44 + libmusly/decoders/libav_0_8.cpp | 280 ++++ libmusly/decoders/libav_0_8.h | 45 + libmusly/discretecosinetransform.cpp | 50 + libmusly/discretecosinetransform.h | 42 + libmusly/gaussian.h | 26 + libmusly/gaussianstatistics.cpp | 246 ++++ libmusly/gaussianstatistics.h | 60 + libmusly/kissfft/CHANGELOG | 123 ++ libmusly/kissfft/COPYING | 11 + libmusly/kissfft/README | 134 ++ libmusly/kissfft/README.simd | 78 ++ libmusly/kissfft/TIPS | 39 + libmusly/kissfft/_kiss_fft_guts.h | 164 +++ libmusly/kissfft/kiss_fft.c | 408 ++++++ libmusly/kissfft/kiss_fft.h | 124 ++ libmusly/kissfft/kiss_fftr.c | 159 +++ libmusly/kissfft/kiss_fftr.h | 46 + libmusly/lib.cpp | 353 +++++ libmusly/libresample/CMakeLists.txt | 15 + libmusly/libresample/LICENSE.txt | 463 +++++++ libmusly/libresample/README.txt | 84 ++ libmusly/libresample/filterkit.c | 215 +++ libmusly/libresample/filterkit.h | 28 + libmusly/libresample/libresample.h | 44 + libmusly/libresample/resample.c | 347 +++++ libmusly/libresample/resample_defs.h | 86 ++ libmusly/libresample/resamplesubs.c | 123 ++ libmusly/melspectrum.cpp | 98 ++ libmusly/melspectrum.h | 54 + libmusly/method.cpp | 109 ++ libmusly/method.h | 173 +++ libmusly/methods/mandelellis.cpp | 158 +++ libmusly/methods/mandelellis.h | 85 ++ libmusly/methods/timbre.cpp | 207 +++ libmusly/methods/timbre.h | 95 ++ libmusly/mfcc.cpp | 33 + libmusly/mfcc.h | 45 + libmusly/mutualproximity.cpp | 147 ++ libmusly/mutualproximity.h | 67 + libmusly/plugins.cpp | 118 ++ libmusly/plugins.h | 86 ++ libmusly/powerspectrum.cpp | 87 ++ libmusly/powerspectrum.h | 78 ++ libmusly/resampler.cpp | 76 ++ libmusly/resampler.h | 38 + libmusly/windowfunction.cpp | 28 + libmusly/windowfunction.h | 31 + musly/CMakeLists.txt | 20 + musly/collectionfile.cpp | 202 +++ musly/collectionfile.h | 72 + musly/fileiterator.cpp | 165 +++ musly/fileiterator.h | 43 + musly/main.cpp | 677 ++++++++++ musly/programoptions.cpp | 192 +++ musly/programoptions.h | 54 + musly/tools.cpp | 102 ++ musly/tools.h | 42 + 72 files changed, 10670 insertions(+) create mode 100644 AUTHORS create mode 100644 CMakeLists.txt create mode 100644 COPYING create mode 100644 Doxyfile create mode 100644 cmake/FindEigen3.cmake create mode 100644 cmake/FindLibAV.cmake create mode 100644 config.h.in create mode 100644 doc/MIREX-DistanceMatrix.md create mode 100644 include/CMakeLists.txt create mode 100644 include/minilog.h create mode 100644 include/musly/musly.h create mode 100644 include/musly/musly_types.h create mode 100644 libmusly/CMakeLists.txt create mode 100644 libmusly/decoder.cpp create mode 100644 libmusly/decoder.h create mode 100644 libmusly/decoders/libav_0_8.cpp create mode 100644 libmusly/decoders/libav_0_8.h create mode 100644 libmusly/discretecosinetransform.cpp create mode 100644 libmusly/discretecosinetransform.h create mode 100644 libmusly/gaussian.h create mode 100644 libmusly/gaussianstatistics.cpp create mode 100644 libmusly/gaussianstatistics.h create mode 100644 libmusly/kissfft/CHANGELOG create mode 100644 libmusly/kissfft/COPYING create mode 100644 libmusly/kissfft/README create mode 100644 libmusly/kissfft/README.simd create mode 100644 libmusly/kissfft/TIPS create mode 100644 libmusly/kissfft/_kiss_fft_guts.h create mode 100644 libmusly/kissfft/kiss_fft.c create mode 100644 libmusly/kissfft/kiss_fft.h create mode 100644 libmusly/kissfft/kiss_fftr.c create mode 100644 libmusly/kissfft/kiss_fftr.h create mode 100644 libmusly/lib.cpp create mode 100644 libmusly/libresample/CMakeLists.txt create mode 100644 libmusly/libresample/LICENSE.txt create mode 100644 libmusly/libresample/README.txt create mode 100644 libmusly/libresample/filterkit.c create mode 100644 libmusly/libresample/filterkit.h create mode 100644 libmusly/libresample/libresample.h create mode 100644 libmusly/libresample/resample.c create mode 100644 libmusly/libresample/resample_defs.h create mode 100644 libmusly/libresample/resamplesubs.c create mode 100644 libmusly/melspectrum.cpp create mode 100644 libmusly/melspectrum.h create mode 100644 libmusly/method.cpp create mode 100644 libmusly/method.h create mode 100644 libmusly/methods/mandelellis.cpp create mode 100644 libmusly/methods/mandelellis.h create mode 100644 libmusly/methods/timbre.cpp create mode 100644 libmusly/methods/timbre.h create mode 100644 libmusly/mfcc.cpp create mode 100644 libmusly/mfcc.h create mode 100644 libmusly/mutualproximity.cpp create mode 100644 libmusly/mutualproximity.h create mode 100644 libmusly/plugins.cpp create mode 100644 libmusly/plugins.h create mode 100644 libmusly/powerspectrum.cpp create mode 100644 libmusly/powerspectrum.h create mode 100644 libmusly/resampler.cpp create mode 100644 libmusly/resampler.h create mode 100644 libmusly/windowfunction.cpp create mode 100644 libmusly/windowfunction.h create mode 100644 musly/CMakeLists.txt create mode 100644 musly/collectionfile.cpp create mode 100644 musly/collectionfile.h create mode 100644 musly/fileiterator.cpp create mode 100644 musly/fileiterator.h create mode 100644 musly/main.cpp create mode 100644 musly/programoptions.cpp create mode 100644 musly/programoptions.h create mode 100644 musly/tools.cpp create mode 100644 musly/tools.h diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..97d44b4 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +2013-2014, Dominik Schnitzer +http://www.schnitzer.at/dominik diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8be1eb1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,55 @@ +# CMake buildfile generator file. +# Process with cmake to create your desired buildfiles. +# +# (c) 2013-2014, Dominik Schnitzer + +cmake_minimum_required(VERSION 2.8) + +project(musly) + +set(MUSLY_VERSION_MAJOR 0) +set(MUSLY_VERSION_MINOR 1) +set(MUSLY_VERSION "${MUSLY_VERSION_MAJOR}.${MUSLY_VERSION_MINOR}") + +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + add_definitions(-Wall -g) +elseif (CMAKE_BUILD_TYPE STREQUAL "Release") + add_definitions(-DNDEBUG -O3) +else () + add_definitions(-DNDEBUG -Wall -g -O3) +endif () + +option(BUILD_STATIC "Make a static build" OFF) +if (BUILD_STATIC) + set(BUILD_SHARED_LIBS OFF) + + # remove -Wl,-Bdynamic + set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) + set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS) +else () + set(BUILD_SHARED_LIBS ON) +endif () + +set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) + +find_package(Eigen3 REQUIRED) +find_package(LibAV 0.8 COMPONENTS avcodec avformat avutil REQUIRED) + +configure_file( + "${PROJECT_SOURCE_DIR}/config.h.in" + "${PROJECT_BINARY_DIR}/config.h") + +include_directories( + "${PROJECT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/include") + +add_subdirectory(libmusly) +add_subdirectory(musly) +add_subdirectory(include) + +# Documentation +set(musly_DOC_FILES AUTHORS COPYING README) +set(musly_DOC_PATH "share/doc/musly") +install(FILES ${musly_DOC_FILES} + DESTINATION ${musly_DOC_PATH}) + diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..14e2f77 --- /dev/null +++ b/COPYING @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/Doxyfile b/Doxyfile new file mode 100644 index 0000000..357aa95 --- /dev/null +++ b/Doxyfile @@ -0,0 +1,1872 @@ +# Doxyfile 1.8.3.1 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# http://www.gnu.org/software/libiconv for the list of possible encodings. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or sequence of words) that should +# identify the project. Note that if you do not use Doxywizard you need +# to put quotes around the project name if it contains spaces. + +PROJECT_NAME = "Musly Library Interface" + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer +# a quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = "Music Similarity Library" + +# With the PROJECT_LOGO tag one can specify an logo or icon that is +# included in the documentation. The maximum height of the logo should not +# exceed 55 pixels and the maximum width should not exceed 200 pixels. +# Doxygen will copy the logo to the output directory. + +PROJECT_LOGO = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = /home/dominik/Temp/dtest + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, +# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, +# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English +# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, +# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, +# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. Note that you specify absolute paths here, but also +# relative paths, which will be relative from the directory where doxygen is +# started. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful if your file system +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like regular Qt-style comments +# (thus requiring an explicit @brief command for a brief description.) + +JAVADOC_AUTOBRIEF = YES + +# If the QT_AUTOBRIEF tag is set to YES then Doxygen will +# interpret the first line (until the first dot) of a Qt-style +# comment as the brief description. If set to NO, the comments +# will behave just like regular Qt-style comments (thus requiring +# an explicit \brief command for a brief description.) + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# This tag can be used to specify a number of word-keyword mappings (TCL only). +# A mapping has the form "name=value". For example adding +# "class=itcl::class" will allow you to use the command class in the +# itcl::class meaning. + +TCL_SUBST = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for +# Java. For instance, namespaces will be presented as packages, qualified +# scopes will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources only. Doxygen will then generate output that is more tailored for +# Fortran. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for +# VHDL. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, +# and language is one of the parsers supported by doxygen: IDL, Java, +# Javascript, CSharp, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, +# C++. For instance to make doxygen treat .inc files as Fortran files (default +# is PHP), and .f files as C (default is Fortran), use: inc=Fortran f=C. Note +# that for custom extensions you also need to set FILE_PATTERNS otherwise the +# files are not read by doxygen. + +EXTENSION_MAPPING = + +# If MARKDOWN_SUPPORT is enabled (the default) then doxygen pre-processes all +# comments according to the Markdown format, which allows for more readable +# documentation. See http://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you +# can mix doxygen, HTML, and XML commands with Markdown formatting. +# Disable only in case of backward compatibilities issues. + +MARKDOWN_SUPPORT = YES + +# When enabled doxygen tries to link words that correspond to documented classes, +# or namespaces to their corresponding documentation. Such a link can be +# prevented in individual cases by by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also makes the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. +# Doxygen will parse them like normal C++ but will assume all classes use public +# instead of private inheritance when no explicit protection keyword is present. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES (the +# default) will make doxygen replace the get and set methods by a property in +# the documentation. This will only work if the methods are indeed getting or +# setting a simple type. If this is not the case, or you want to show the +# methods anyway, you should set this option to NO. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and +# unions are shown inside the group in which they are included (e.g. using +# @ingroup) instead of on a separate page (for HTML and Man pages) or +# section (for LaTeX and RTF). + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and +# unions with only public data fields will be shown inline in the documentation +# of the scope in which they are defined (i.e. file, namespace, or group +# documentation), provided this scope is documented. If set to NO (the default), +# structs, classes, and unions are shown on a separate page (for HTML and Man +# pages) or section (for LaTeX and RTF). + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum +# is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically +# be useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. + +TYPEDEF_HIDES_STRUCT = NO + +# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to +# determine which symbols to keep in memory and which to flush to disk. +# When the cache is full, less often used symbols will be written to disk. +# For small to medium size projects (<1000 input files) the default value is +# probably good enough. For larger projects a too small cache size can cause +# doxygen to be busy swapping symbols to and from disk most of the time +# causing a significant performance penalty. +# If the system has enough physical memory increasing the cache will improve the +# performance by keeping more symbols in memory. Note that the value works on +# a logarithmic scale so increasing the size by one will roughly double the +# memory usage. The cache size is given by this formula: +# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, +# corresponding to a cache size of 2^16 = 65536 symbols. + +SYMBOL_CACHE_SIZE = 0 + +# Similar to the SYMBOL_CACHE_SIZE the size of the symbol lookup cache can be +# set using LOOKUP_CACHE_SIZE. This cache is used to resolve symbols given +# their name and scope. Since this can be an expensive process and often the +# same symbol appear multiple times in the code, doxygen keeps a cache of +# pre-resolved symbols. If the cache is too small doxygen will become slower. +# If the cache is too large, memory is wasted. The cache size is given by this +# formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range is 0..9, the default is 0, +# corresponding to a cache size of 2^16 = 65536 symbols. + +LOOKUP_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal +# scope will be included in the documentation. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base +# name of the file that contains the anonymous namespace. By default +# anonymous namespaces are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = NO + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = YES + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen +# will list include files with double quotes in the documentation +# rather than with sharp brackets. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen +# will sort the (brief and detailed) documentation of class members so that +# constructors and destructors are listed first. If set to NO (the default) +# the constructors will appear in the respective orders defined by +# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. +# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO +# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the +# hierarchy of group names into alphabetical order. If set to NO (the default) +# the group names will appear in their defined order. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to +# do proper type resolution of all parameters of a function it will reject a +# match between the prototype and the implementation of a member function even +# if there is only one candidate or it is obvious which candidate to choose +# by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen +# will still accept a match between prototype and implementation in such cases. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if section-label ... \endif +# and \cond section-label ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or macro consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and macros in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. +# This will remove the Files entry from the Quick Index and from the +# Folder Tree View (if specified). The default is YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the +# Namespaces page. This will remove the Namespaces entry from the Quick Index +# and from the Folder Tree View (if specified). The default is YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. +# You can optionally specify a file name after the option, if omitted +# DoxygenLayout.xml will be used as the name of the layout file. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files +# containing the references data. This must be a list of .bib files. The +# .bib extension is automatically appended if omitted. Using this command +# requires the bibtex tool to be installed. See also +# http://en.wikipedia.org/wiki/BibTeX for more info. For LaTeX the style +# of the bibliography can be controlled using LATEX_BIB_STYLE. To use this +# feature you need bibtex and perl available in the search path. Do not use +# file names with spaces, bibtex cannot handle them. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# The WARN_NO_PARAMDOC option can be enabled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = include/musly \ + README.md + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is +# also the default input encoding. Doxygen uses libiconv (or the iconv built +# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for +# the list of possible encodings. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh +# *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py +# *.f90 *.f *.for *.vhd *.vhdl + +FILE_PATTERNS = *.cpp \ + *.h \ + *.md + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = * + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty or if +# non of the patterns match the file name, INPUT_FILTER is applied. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) +# and it is also possible to disable source filtering for a specific pattern +# using *.ext= (so without naming a filter). This option only has effect when +# FILTER_SOURCE_FILES is enabled. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MD_FILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page (index.html). +# This can be useful if you have a project on for instance GitHub and want reuse +# the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = README.md + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C, C++ and Fortran comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentation. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. Note that when using a custom header you are responsible +# for the proper inclusion of any scripts and style sheets that doxygen +# needs, which is dependent on the configuration options used. +# It is advised to generate a default header using "doxygen -w html +# header.html footer.html stylesheet.css YourConfigFile" and then modify +# that header. Note that the header is subject to change so you typically +# have to redo this when upgrading to a newer version of doxygen or when +# changing the value of configuration settings such as GENERATE_TREEVIEW! + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If left blank doxygen will +# generate a default style sheet. Note that it is recommended to use +# HTML_EXTRA_STYLESHEET instead of this one, as it is more robust and this +# tag will in the future become obsolete. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional +# user-defined cascading style sheet that is included after the standard +# style sheets created by doxygen. Using this option one can overrule +# certain style aspects. This is preferred over using HTML_STYLESHEET +# since it does not replace the standard style sheet and is therefor more +# robust against future updates. Doxygen will copy the style sheet file to +# the output directory. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath$ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that +# the files will be copied as-is; there are no commands or markers available. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. +# Doxygen will adjust the colors in the style sheet and background images +# according to this color. Hue is specified as an angle on a colorwheel, +# see http://en.wikipedia.org/wiki/Hue for more information. +# For instance the value 0 represents red, 60 is yellow, 120 is green, +# 180 is cyan, 240 is blue, 300 purple, and 360 is red again. +# The allowed range is 0 to 359. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of +# the colors in the HTML output. For a value of 0 the output will use +# grayscales only. A value of 255 will produce the most vivid colors. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to +# the luminance component of the colors in the HTML output. Values below +# 100 gradually make the output lighter, whereas values above 100 make +# the output darker. The value divided by 100 is the actual gamma applied, +# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, +# and 100 does not change the gamma. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting +# this to NO can help when comparing the output of multiple runs. + +HTML_TIMESTAMP = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. + +HTML_DYNAMIC_SECTIONS = NO + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of +# entries shown in the various tree structured indices initially; the user +# can expand and collapse entries dynamically later on. Doxygen will expand +# the tree to such a level that at most the specified number of entries are +# visible (unless a fully collapsed tree already exceeds this amount). +# So setting the number of entries 1 will produce a full collapsed tree by +# default. 0 is a special value representing an infinite number of entries +# and will result in a full expanded tree by default. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files +# will be generated that can be used as input for Apple's Xcode 3 +# integrated development environment, introduced with OSX 10.5 (Leopard). +# To create a documentation set, doxygen will generate a Makefile in the +# HTML output directory. Running make will produce the docset in that +# directory and running "make install" will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find +# it at startup. +# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. + +GENERATE_DOCSET = NO + +# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the +# feed. A documentation feed provides an umbrella under which multiple +# documentation sets from a single provider (such as a company or product suite) +# can be grouped. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that +# should uniquely identify the documentation set bundle. This should be a +# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen +# will append .docset to the name. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely +# identify the documentation publisher. This should be a reverse domain-name +# style string, e.g. com.mycompany.MyDocSet.documentation. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING +# is used to encode HtmlHelp index (hhk), content (hhc) and project file +# content. + +CHM_INDEX_ENCODING = + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated +# that can be used as input for Qt's qhelpgenerator to generate a +# Qt Compressed Help (.qch) of the generated HTML documentation. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can +# be used to specify the file name of the resulting .qch file. +# The path specified is relative to the HTML output folder. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# http://doc.trolltech.com/qthelpproject.html#namespace + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# http://doc.trolltech.com/qthelpproject.html#virtual-folders + +QHP_VIRTUAL_FOLDER = doc + +# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to +# add. For more information please see +# http://doc.trolltech.com/qthelpproject.html#custom-filters + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see +# +# Qt Help Project / Custom Filters. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's +# filter section matches. +# +# Qt Help Project / Filter Attributes. + +QHP_SECT_FILTER_ATTRS = + +# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can +# be used to specify the location of Qt's qhelpgenerator. +# If non-empty doxygen will try to run qhelpgenerator on the generated +# .qhp file. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files +# will be generated, which together with the HTML files, form an Eclipse help +# plugin. To install this plugin and make it available under the help contents +# menu in Eclipse, the contents of the directory containing the HTML and XML +# files needs to be copied into the plugins directory of eclipse. The name of +# the directory within the plugins directory should be the same as +# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before +# the help appears. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have +# this name. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) +# at top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. Since the tabs have the same information as the +# navigation tree you can set this option to NO if you already set +# GENERATE_TREEVIEW to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. +# If the tag value is set to YES, a side panel will be generated +# containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). +# Windows users are probably better off using the HTML help feature. +# Since the tree basically has the same information as the tab index you +# could consider to set DISABLE_INDEX to NO when enabling this option. + +GENERATE_TREEVIEW = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values +# (range [0,1..20]) that doxygen will group on one line in the generated HTML +# documentation. Note that a value of 0 will completely suppress the enum +# values from appearing in the overview section. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open +# links to external symbols imported via tag files in a separate window. + +EXT_LINKS_IN_WINDOW = NO + +# Use this tag to change the font size of Latex formulas included +# as images in the HTML documentation. The default is 10. Note that +# when you change the font size after a successful doxygen run you need +# to manually remove any form_*.png images from the HTML output directory +# to force them to be regenerated. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are +# not supported properly for IE 6.0, but are supported on all modern browsers. +# Note that when changing this option you need to delete any form_*.png files +# in the HTML output before the changes have effect. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax +# (see http://www.mathjax.org) which uses client side Javascript for the +# rendering instead of using prerendered bitmaps. Use this if you do not +# have LaTeX installed or if you want to formulas look prettier in the HTML +# output. When enabled you may also need to install MathJax separately and +# configure the path to it using the MATHJAX_RELPATH option. + +USE_MATHJAX = NO + +# When MathJax is enabled you can set the default output format to be used for +# thA MathJax output. Supported types are HTML-CSS, NativeMML (i.e. MathML) and +# SVG. The default value is HTML-CSS, which is slower, but has the best +# compatibility. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the +# HTML output directory using the MATHJAX_RELPATH option. The destination +# directory should contain the MathJax.js script. For instance, if the mathjax +# directory is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to +# the MathJax Content Delivery Network so you can quickly see the result without +# installing MathJax. However, it is strongly recommended to install a local +# copy of MathJax from http://www.mathjax.org before deployment. + +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest + +# The MATHJAX_EXTENSIONS tag can be used to specify one or MathJax extension +# names that should be enabled during MathJax rendering. + +MATHJAX_EXTENSIONS = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box +# for the HTML output. The underlying search engine uses javascript +# and DHTML and should work on any modern browser. Note that when using +# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets +# (GENERATE_DOCSET) there is already a search function so this one should +# typically be disabled. For large projects the javascript based search engine +# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. + +SEARCHENGINE = NO + +# When the SERVER_BASED_SEARCH tag is enabled the search engine will be +# implemented using a web server instead of a web client using Javascript. +# There are two flavours of web server based search depending on the +# EXTERNAL_SEARCH setting. When disabled, doxygen will generate a PHP script for +# searching and an index file used by the script. When EXTERNAL_SEARCH is +# enabled the indexing and searching needs to be provided by external tools. +# See the manual for details. + +SERVER_BASED_SEARCH = NO + +# When EXTERNAL_SEARCH is enabled doxygen will no longer generate the PHP +# script for searching. Instead the search results are written to an XML file +# which needs to be processed by an external indexer. Doxygen will invoke an +# external search engine pointed to by the SEARCHENGINE_URL option to obtain +# the search results. Doxygen ships with an example indexer (doxyindexer) and +# search engine (doxysearch.cgi) which are based on the open source search engine +# library Xapian. See the manual for configuration details. + +EXTERNAL_SEARCH = NO + +# The SEARCHENGINE_URL should point to a search engine hosted by a web server +# which will returned the search results when EXTERNAL_SEARCH is enabled. +# Doxygen ships with an example search engine (doxysearch) which is based on +# the open source search engine library Xapian. See the manual for configuration +# details. + +SEARCHENGINE_URL = + +# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed +# search data is written to a file for indexing by an external tool. With the +# SEARCHDATA_FILE tag the name of this file can be specified. + +SEARCHDATA_FILE = searchdata.xml + +# When SERVER_BASED_SEARCH AND EXTERNAL_SEARCH are both enabled the +# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is +# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple +# projects and redirect the results back to the right project. + +EXTERNAL_SEARCH_ID = + +# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen +# projects other than the one defined by this configuration file, but that are +# all added to the same external search index. Each project needs to have a +# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id +# of to a relative location where the documentation can be found. +# The format is: EXTRA_SEARCH_MAPPINGS = id1=loc1 id2=loc2 ... + +EXTRA_SEARCH_MAPPINGS = + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. +# Note that when enabling USE_PDFLATEX this option is only used for +# generating bitmaps for formulas in the HTML output, but not in the +# Makefile that is written to the output directory. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4 + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for +# the generated latex document. The footer should contain everything after +# the last chapter. If it is left blank doxygen will generate a +# standard footer. Notice: only use this tag if you know what you are doing! + +LATEX_FOOTER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = YES + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = YES + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +# If LATEX_SOURCE_CODE is set to YES then doxygen will include +# source code with syntax highlighting in the LaTeX output. +# Note that which sources are shown also depends on other settings +# such as SOURCE_BROWSER. + +LATEX_SOURCE_CODE = NO + +# The LATEX_BIB_STYLE tag can be used to specify the style to use for the +# bibliography, e.g. plainnat, or ieeetr. The default style is "plain". See +# http://en.wikipedia.org/wiki/BibTeX for more info. + +LATEX_BIB_STYLE = plain + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load style sheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# pointed to by INCLUDE_PATH will be searched when a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition that +# overrules the definition found in the source code. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all references to function-like macros +# that are alone on a line, have an all uppercase name, and do not end with a +# semicolon, because these will confuse the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. For each +# tag file the location of the external documentation should be added. The +# format of a tag file without this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths +# or URLs. Note that each tag file must have a unique name (where the name does +# NOT include the path). If a tag file is not located in the directory in which +# doxygen is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option also works with HAVE_DOT disabled, but it is recommended to +# install and use dot, since it yields more powerful graphs. + +CLASS_DIAGRAMS = YES + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see +# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the +# documentation. The MSCGEN_PATH tag allows you to specify the directory where +# the mscgen tool resides. If left empty the tool is assumed to be found in the +# default search path. + +MSCGEN_PATH = + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is +# allowed to run in parallel. When set to 0 (the default) doxygen will +# base this on the number of processors available in the system. You can set it +# explicitly to a value larger than 0 to get control over the balance +# between CPU load and processing speed. + +DOT_NUM_THREADS = 0 + +# By default doxygen will use the Helvetica font for all dot files that +# doxygen generates. When you want a differently looking font you can specify +# the font name using DOT_FONTNAME. You need to make sure dot is able to find +# the font, which can be done by putting it in a standard location or by setting +# the DOTFONTPATH environment variable or by setting DOT_FONTPATH to the +# directory containing the font. + +DOT_FONTNAME = Helvetica + +# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. +# The default size is 10pt. + +DOT_FONTSIZE = 10 + +# By default doxygen will tell dot to use the Helvetica font. +# If you specify a different font using DOT_FONTNAME you can use DOT_FONTPATH to +# set the path where dot can find it. + +DOT_FONTPATH = + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If the UML_LOOK tag is enabled, the fields and methods are shown inside +# the class node. If there are many fields or methods and many nodes the +# graph may become too big to be useful. The UML_LIMIT_NUM_FIELDS +# threshold limits the number of items for each type to make the size more +# managable. Set this to 0 for no limit. Note that the threshold may be +# exceeded by 50% before the limit is enforced. + +UML_LIMIT_NUM_FIELDS = 10 + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT options are set to YES then +# doxygen will generate a call dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable call graphs +# for selected functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then +# doxygen will generate a caller dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable caller +# graphs for selected functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will generate a graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are svg, png, jpg, or gif. +# If left blank png will be used. If you choose svg you need to set +# HTML_FILE_EXTENSION to xhtml in order to make the SVG files +# visible in IE 9+ (other browsers do not have this requirement). + +DOT_IMAGE_FORMAT = png + +# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to +# enable generation of interactive SVG images that allow zooming and panning. +# Note that this requires a modern browser other than Internet Explorer. +# Tested and working are Firefox, Chrome, Safari, and Opera. For IE 9+ you +# need to set HTML_FILE_EXTENSION to xhtml in order to make the SVG files +# visible. Older versions of IE do not have SVG support. + +INTERACTIVE_SVG = NO + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MSCFILE_DIRS tag can be used to specify one or more directories that +# contain msc files that are included in the documentation (see the +# \mscfile command). + +MSCFILE_DIRS = + +# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# nodes that will be shown in the graph. If the number of nodes in a graph +# becomes larger than this value, doxygen will truncate the graph, which is +# visualized by representing a node as a red box. Note that doxygen if the +# number of direct children of the root node in a graph is already larger than +# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note +# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. + +DOT_GRAPH_MAX_NODES = 50 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, because dot on Windows does not +# seem to support this out of the box. Warning: Depending on the platform used, +# enabling this option may lead to badly anti-aliased labels on the edges of +# a graph (i.e. they become hard to read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES diff --git a/cmake/FindEigen3.cmake b/cmake/FindEigen3.cmake new file mode 100644 index 0000000..66ffe8e --- /dev/null +++ b/cmake/FindEigen3.cmake @@ -0,0 +1,80 @@ +# - Try to find Eigen3 lib +# +# This module supports requiring a minimum version, e.g. you can do +# find_package(Eigen3 3.1.2) +# to require version 3.1.2 or newer of Eigen3. +# +# Once done this will define +# +# EIGEN3_FOUND - system has eigen lib with correct version +# EIGEN3_INCLUDE_DIR - the eigen include directory +# EIGEN3_VERSION - eigen version + +# Copyright (c) 2006, 2007 Montel Laurent, +# Copyright (c) 2008, 2009 Gael Guennebaud, +# Copyright (c) 2009 Benoit Jacob +# Redistribution and use is allowed according to the terms of the 2-clause BSD license. + +if(NOT Eigen3_FIND_VERSION) + if(NOT Eigen3_FIND_VERSION_MAJOR) + set(Eigen3_FIND_VERSION_MAJOR 2) + endif(NOT Eigen3_FIND_VERSION_MAJOR) + if(NOT Eigen3_FIND_VERSION_MINOR) + set(Eigen3_FIND_VERSION_MINOR 91) + endif(NOT Eigen3_FIND_VERSION_MINOR) + if(NOT Eigen3_FIND_VERSION_PATCH) + set(Eigen3_FIND_VERSION_PATCH 0) + endif(NOT Eigen3_FIND_VERSION_PATCH) + + set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}") +endif(NOT Eigen3_FIND_VERSION) + +macro(_eigen3_check_version) + file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header) + + string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}") + set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}") + set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}") + set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}") + + set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION}) + if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + set(EIGEN3_VERSION_OK FALSE) + else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + set(EIGEN3_VERSION_OK TRUE) + endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + + if(NOT EIGEN3_VERSION_OK) + + message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, " + "but at least version ${Eigen3_FIND_VERSION} is required") + endif(NOT EIGEN3_VERSION_OK) +endmacro(_eigen3_check_version) + +if (EIGEN3_INCLUDE_DIR) + + # in cache already + _eigen3_check_version() + set(EIGEN3_FOUND ${EIGEN3_VERSION_OK}) + +else (EIGEN3_INCLUDE_DIR) + + find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library + PATHS + ${CMAKE_INSTALL_PREFIX}/include + ${KDE4_INCLUDE_DIR} + PATH_SUFFIXES eigen3 eigen + ) + + if(EIGEN3_INCLUDE_DIR) + _eigen3_check_version() + endif(EIGEN3_INCLUDE_DIR) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) + + mark_as_advanced(EIGEN3_INCLUDE_DIR) + +endif(EIGEN3_INCLUDE_DIR) diff --git a/cmake/FindLibAV.cmake b/cmake/FindLibAV.cmake new file mode 100644 index 0000000..a4f3b8d --- /dev/null +++ b/cmake/FindLibAV.cmake @@ -0,0 +1,221 @@ +# Module for locating libav. +# +# Customizable variables: +# LIBAV_ROOT_DIR +# Specifies libav's root directory. +# +# Read-only variables: +# LIBAV_FOUND +# Indicates whether the library has been found. +# +# LIBAV_INCLUDE_DIRS +# Specifies libav's include directory. +# +# LIBAV_LIBRARIES +# Specifies libav libraries that should be passed to target_link_libararies. +# +# LIBAV__LIBRARIES +# Specifies the libraries of a specific . +# +# LIBAV__FOUND +# Indicates whether the specified was found. +# +# +# Copyright (c) 2013 Sergiu Dotenco +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTLIBAVLAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +INCLUDE (FindPackageHandleStandardArgs) + +IF (CMAKE_VERSION VERSION_GREATER 2.8.7) + SET (_LIBAV_CHECK_COMPONENTS FALSE) +ELSE (CMAKE_VERSION VERSION_GREATER 2.8.7) + SET (_LIBAV_CHECK_COMPONENTS TRUE) +ENDIF (CMAKE_VERSION VERSION_GREATER 2.8.7) + +FIND_PATH (LIBAV_ROOT_DIR + NAMES include/libavcodec/avcodec.h + include/libavdevice/avdevice.h + include/libavfilter/avfilter.h + include/libavutil/avutil.h + include/libswscale/swscale.h + PATHS ENV LIBAVROOT + DOC "libav root directory") + +FIND_PATH (LIBAV_INCLUDE_DIR + NAMES libavcodec/avcodec.h + libavdevice/avdevice.h + libavfilter/avfilter.h + libavutil/avutil.h + libswscale/swscale.h + HINTS ${LIBAV_ROOT_DIR} + PATH_SUFFIXES include + DOC "libav include directory") + +if (NOT LibAV_FIND_COMPONENTS) + set (LibAV_FIND_COMPONENTS avcodec avdevice avfilter avformat avutil swscale) +endif (NOT LibAV_FIND_COMPONENTS) + +FOREACH (_LIBAV_COMPONENT ${LibAV_FIND_COMPONENTS}) + STRING (TOUPPER ${_LIBAV_COMPONENT} _LIBAV_COMPONENT_UPPER) + SET (_LIBAV_LIBRARY_BASE LIBAV_${_LIBAV_COMPONENT_UPPER}_LIBRARY) + + FIND_LIBRARY (${_LIBAV_LIBRARY_BASE} + NAMES ${_LIBAV_COMPONENT} + HINTS ${LIBAV_ROOT_DIR} + PATH_SUFFIXES bin lib + DOC "libav ${_LIBAV_COMPONENT} library") + + MARK_AS_ADVANCED (${_LIBAV_LIBRARY_BASE}) + + SET (LIBAV_${_LIBAV_COMPONENT_UPPER}_FOUND TRUE) + + IF (${_LIBAV_LIBRARY_BASE}) + # setup the LIBAV__LIBRARIES variable + SET (LIBAV_${_LIBAV_COMPONENT_UPPER}_LIBRARIES ${${_LIBAV_LIBRARY_BASE}}) + LIST (APPEND LIBAV_LIBRARIES ${LIBAV_${_LIBAV_COMPONENT_UPPER}_LIBRARIES}) + LIST (APPEND _LIBAV_ALL_LIBS ${${_LIBAV_LIBRARY_BASE}}) + ELSE (${_LIBAV_LIBRARY_BASE}) + SET (LIBAV_${_LIBAV_COMPONENT_UPPER}_FOUND FALSE) + + IF (_LIBAV_CHECK_COMPONENTS) + LIST (APPEND _LIBAV_MISSING_LIBRARIES ${_LIBAV_LIBRARY_BASE}) + ENDIF (_LIBAV_CHECK_COMPONENTS) + ENDIF (${_LIBAV_LIBRARY_BASE}) + + SET (LibAV_${_LIBAV_COMPONENT}_FOUND ${LIBAV_${_LIBAV_COMPONENT_UPPER}_FOUND}) +ENDFOREACH (_LIBAV_COMPONENT ${LibAV_FIND_COMPONENTS}) + +SET (LIBAV_INCLUDE_DIRS ${LIBAV_INCLUDE_DIR}) + +IF (DEFINED _LIBAV_MISSING_COMPONENTS AND _LIBAV_CHECK_COMPONENTS) + IF (NOT LibAV_FIND_QUIETLY) + MESSAGE (STATUS "One or more libav components were not found:") + # Display missing components indented, each on a separate line + FOREACH (_LIBAV_MISSING_COMPONENT ${_LIBAV_MISSING_COMPONENTS}) + MESSAGE (STATUS " " ${_LIBAV_MISSING_COMPONENT}) + ENDFOREACH (_LIBAV_MISSING_COMPONENT ${_LIBAV_MISSING_COMPONENTS}) + ENDIF (NOT LibAV_FIND_QUIETLY) +ENDIF (DEFINED _LIBAV_MISSING_COMPONENTS AND _LIBAV_CHECK_COMPONENTS) + +# Determine library's version + +FIND_PROGRAM (LIBAV_AVCONV_EXECUTABLE NAMES avconv + HINTS ${LIBAV_ROOT_DIR} + PATH_SUFFIXES bin + DOC "avconv executable") + +IF (LIBAV_AVCONV_EXECUTABLE) + EXECUTE_PROCESS (COMMAND ${LIBAV_AVCONV_EXECUTABLE} -version + OUTPUT_VARIABLE _LIBAV_AVCONV_OUTPUT ERROR_QUIET) + + STRING (REGEX REPLACE + ".*avconv(\\s+version)?[ \t]+([0-9]+(\\.[0-9]+(\\.[0-9]+)?)?).*" "\\2" + LIBAV_VERSION "${_LIBAV_AVCONV_OUTPUT}") + STRING (REGEX REPLACE "([0-9]+)\\.([0-9]+)(\\.([0-9]+))?" "\\1" + LIBAV_VERSION_MAJOR "${LIBAV_VERSION}") + STRING (REGEX REPLACE "([0-9]+)\\.([0-9]+)(\\.([0-9]+))?" "\\2" + LIBAV_VERSION_MINOR "${LIBAV_VERSION}") + + IF ("${LIBAV_VERSION}" MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$") + STRING (REGEX REPLACE "([0-9]+)\\.([0-9]+)(\\.([0-9]+))?" "\\3" + LIBAV_VERSION_PATCH "${LIBAV_VERSION}") + SET (LIBAV_VERSION_COMPONENTS 3) + ELSEIF ("${LIBAV_VERSION}" MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$") + SET (LIBAV_VERSION_COMPONENTS 2) + ELSEIF ("${LIBAV_VERSION}" MATCHES "^([0-9]+)$") + # mostly developer/alpha/beta versions + SET (LIBAV_VERSION_COMPONENTS 2) + SET (LIBAV_VERSION_MINOR 0) + SET (LIBAV_VERSION "${LIBAV_VERSION}.0") + ENDIF ("${LIBAV_VERSION}" MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$") +ENDIF (LIBAV_AVCONV_EXECUTABLE) + +IF (WIN32) + FIND_PROGRAM (LIB_EXECUTABLE NAMES lib + HINTS "$ENV{VS110COMNTOOLS}/../../VC/bin" + "$ENV{VS100COMNTOOLS}/../../VC/bin" + "$ENV{VS90COMNTOOLS}/../../VC/bin" + "$ENV{VS71COMNTOOLS}/../../VC/bin" + "$ENV{VS80COMNTOOLS}/../../VC/bin" + DOC "Library manager") + + MARK_AS_ADVANCED (LIB_EXECUTABLE) +ENDIF (WIN32) + +MACRO (GET_LIB_REQUISITES LIB REQUISITES) + IF (LIB_EXECUTABLE) + GET_FILENAME_COMPONENT (_LIB_PATH ${LIB_EXECUTABLE} PATH) + + IF (MSVC) + # Do not redirect the output + UNSET (ENV{VS_UNICODE_OUTPUT}) + ENDIF (MSVC) + + EXECUTE_PROCESS (COMMAND ${LIB_EXECUTABLE} /nologo /list ${LIB} + WORKING_DIRECTORY ${_LIB_PATH}/../../Common7/IDE + OUTPUT_VARIABLE _LIB_OUTPUT ERROR_QUIET) + + STRING (REPLACE "\n" ";" "${REQUISITES}" "${_LIB_OUTPUT}") + LIST (REMOVE_DUPLICATES ${REQUISITES}) + ENDIF (LIB_EXECUTABLE) +ENDMACRO (GET_LIB_REQUISITES) + +IF (_LIBAV_ALL_LIBS) + # collect lib requisites using the lib tool + FOREACH (_LIBAV_COMPONENT ${_LIBAV_ALL_LIBS}) + GET_LIB_REQUISITES (${_LIBAV_COMPONENT} _LIBAV_REQUISITES) + ENDFOREACH (_LIBAV_COMPONENT) +ENDIF (_LIBAV_ALL_LIBS) + +IF (NOT LIBAV_BINARY_DIR) + SET (_LIBAV_UPDATE_BINARY_DIR TRUE) +ELSE (NOT LIBAV_BINARY_DIR) + SET (_LIBAV_UPDATE_BINARY_DIR FALSE) +ENDIF (NOT LIBAV_BINARY_DIR) + +SET (_LIBAV_BINARY_DIR_HINTS bin) + +IF (_LIBAV_REQUISITES) + FIND_FILE (LIBAV_BINARY_DIR NAMES ${_LIBAV_REQUISITES} + HINTS ${LIBAV_ROOT_DIR} + PATH_SUFFIXES ${_LIBAV_BINARY_DIR_HINTS} NO_DEFAULT_PATH) +ENDIF (_LIBAV_REQUISITES) + +IF (LIBAV_BINARY_DIR AND _LIBAV_UPDATE_BINARY_DIR) + SET (_LIBAV_BINARY_DIR ${LIBAV_BINARY_DIR}) + UNSET (LIBAV_BINARY_DIR CACHE) + + IF (_LIBAV_BINARY_DIR) + GET_FILENAME_COMPONENT (LIBAV_BINARY_DIR ${_LIBAV_BINARY_DIR} PATH) + ENDIF (_LIBAV_BINARY_DIR) +ENDIF (LIBAV_BINARY_DIR AND _LIBAV_UPDATE_BINARY_DIR) + +SET (LIBAV_BINARY_DIR ${LIBAV_BINARY_DIR} CACHE PATH "libav binary directory") + +MARK_AS_ADVANCED (LIBAV_INCLUDE_DIR LIBAV_BINARY_DIR) + +IF (NOT _LIBAV_CHECK_COMPONENTS) + SET (_LIBAV_FPHSA_ADDITIONAL_ARGS HANDLE_COMPONENTS) +ENDIF (NOT _LIBAV_CHECK_COMPONENTS) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS (LibAV REQUIRED_VARS LIBAV_ROOT_DIR + LIBAV_INCLUDE_DIR ${_LIBAV_MISSING_LIBRARIES} VERSION_VAR LIBAV_VERSION + ${_LIBAV_FPHSA_ADDITIONAL_ARGS}) + diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..1f004a6 --- /dev/null +++ b/config.h.in @@ -0,0 +1,10 @@ +/* config.h.in */ + +/* Version number of package */ +#define MUSLY_VERSION "@MUSLY_VERSION@" + +/* Major version number as integer */ +#define MUSLY_VERSION_MAJOR @MUSLY_VERSION_MAJOR@ + +/* Minor version number as integer */ +#define MUSLY_VERSION_MINOR @MUSLY_VERSION_MINOR@ diff --git a/doc/MIREX-DistanceMatrix.md b/doc/MIREX-DistanceMatrix.md new file mode 100644 index 0000000..695face --- /dev/null +++ b/doc/MIREX-DistanceMatrix.md @@ -0,0 +1,71 @@ +**Copied from on 8 Jan 2014** + + +**Distance matrix output files** + +Participants should return one of two available output file formats, a full distance matrix or a sparse distance matrix. The sparse distance matrix format is preferred (as the dense distance matrices can be very large). + + +------------------------ +*Sparse Distance Matrix* +------------------------ + +If computation or exhaustive search is a concern or not a normal output of the indexing algorithm employed, the sparse distance matric format detailed below may be used: + +A simple ASCII file listing a name for the algorithm and the top 100 search results for every track in the collection. + +This file should start with a header line with a name for the algorithm and should be followed by the results for one query per line, prefixed by the filename portion of the query path. This should be followed by a tab character and a tab separated, ordered list of the top 100 search results. Each result should include the result filename (e.g. a034728.wav) and the distance (e.g. 17.1 or 0.23) separated by a a comma. + +MyAlgorithm (my.email@address.com) +\t,,\t,, ... \t, +\t,,\t,, ... \t, +... + +which might look like: + +MyAlgorithm (my.email@address.com) +a009342.wav b229311.wav,0.16 a023821.wav,0.19 a001329,0.24 ... etc. +a009343.wav a661931.wav,0.12 a043322.wav,0.17 c002346,0.21 ... etc. +a009347.wav a671239.wav,0.13 c112393.wav,0.20 b083293,0.25 ... etc. +... + +The path to which this list file should be written must be accepted as a parameter on the command line. + +---------------------- +*Full Distance Matrix* +---------------------- + +Full distance matrix files should be generated in the the following format: + + A simple ASCII file listing a name for the algorithm on the first line, + Numbered paths for each file appearing in the matrix, these can be in any order (i.e. the files don't have to be i the same order as they appeared in the list file) but should index into the columns/rows of of the distance matrix. + A line beginning with 'Q/R' followed by a tab and tab separated list of the numbers 1 to N, where N is the files covered by the matrix. + One line per file in the matrix give the distances of that files to each other file in the matrix. All distances should be zero or positive (0.0+) and should not be infinite or NaN. Values should be separated by a single tab character. Obviously the diagonal of the matrix (distance or a track to itself) should be zero. + +Distance matrix header text with system name +1\t +2\t +3\t +... +N\t +Q/R\t1\t2\t3\t...\tN +1\t0.0\t\t\t...\t +2\t\t0.0\t\t...\t +3\t\t\t0.0\t...\t +...\t...\t...\t...\t...\t... +N\t\t\t\t...\t0.0 + +which might look like: + +Example distance matrix 0.1 +1 /path/to/audio/file/1.wav +2 /path/to/audio/file/2.wav +3 /path/to/audio/file/3.wav +4 /path/to/audio/file/4.wav +Q/R 1 2 3 4 +1 0.00000 1.24100 0.2e-4 0.42559 +2 1.24100 0.00000 0.62640 0.23564 +3 50.2e-4 0.62640 0.00000 0.38000 +4 0.42559 0.23567 0.38000 0.00000 + + diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 0000000..d529d22 --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1,10 @@ +# CMake buildfile generator file. +# Process with cmake to create your desired buildfiles. +# +# (c) 2013, Dominik Schnitzer + +install(FILES + musly/musly.h + musly/musly_types.h + DESTINATION include/musly) + diff --git a/include/minilog.h b/include/minilog.h new file mode 100644 index 0000000..f8f2d64 --- /dev/null +++ b/include/minilog.h @@ -0,0 +1,246 @@ +/** + * This is MINILOG, a minimal header only C++ logger system. + * + * Copyright (c) 2013-2014, Dominik Schnitzer + * 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. + * + * 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 HOLDER 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. + * + * + * Minimal Documentation + * Currently MINILOG only logs to STDERR, however all is in place to log + * to files. + * + * Usage in your C++ project: + * MiniLog::current_level() = logINFO; // set debug level to INFO + * MINILOG(logDEBUG) << "DEBUG Log message"; // log at debug level + * MINILOG(logINFO) << "INFO Log message"; // log at info level + * + * Yields: + * 16:20:33.130 INFO: INFO Log message // show only info level + * // output, since DEBUG > INFO + */ + +#ifndef MINILOG_H_ +#define MINILOG_H_ + +#include +#include +#include + +enum minilog_level { + logNONE, + logERROR, + logWARNING, + logINFO, + logDEBUG, + logTRACE, + minilog_level_max }; + + +// minilog_get_timestr() for Windows +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) + +#include + +inline std::string +minilog_get_timestr() +{ + const int MAX_LEN = 100; + char buffer[MAX_LEN]; + + if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0, + "HH':'mm':'ss", buffer, MAX_LEN) == 0) { + return ""; + } + + char result[MAX_LEN*2] = {0}; + static DWORD first = GetTickCount(); + sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000); + + return result; +} + +// get_timestr() for Linux, OSX +#else + +#include + +inline std::string +minilog_get_timestr() +{ + const int MAX_LEN = 100; + char buffer[MAX_LEN]; + + time_t t; + time(&t); + tm r = {0}; + strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r)); + + char result[MAX_LEN*2] = {0}; + struct timeval tv; + gettimeofday(&tv, 0); + sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000); + + return result; +} +#endif // minilog_get_timestr() + + +template +class Log +{ +public: + Log(); + + virtual + ~Log(); + + std::ostringstream& + get( + minilog_level level); + + static minilog_level& + current_level(); + + static std::string + to_string( + minilog_level level); + + static minilog_level + from_string( + const std::string& level); + +protected: + std::ostringstream os; + +private: + Log( + const Log&); + + Log& + operator =( + const Log&); +}; + +template +Log::Log() { +} + +template +std::ostringstream& Log::get( + minilog_level level) { + os << minilog_get_timestr() << " " << to_string(level) << ": "; + return os; +} + +template +Log::~Log() { + os << std::endl; + T::write(os.str()); +} + +template +minilog_level& +Log::current_level() { + static minilog_level current_level = logNONE; + return current_level; +} + +template +std::string +Log::to_string( + minilog_level level) { + static const char* const buffer[] = { + "NONE", + "ERROR", + "WARNING", + "INFO", + "DEBUG", + "TRACE"}; + return buffer[level]; +} + +template +minilog_level +Log::from_string( + const std::string& level) { + if (level == "TRACE") + return logTRACE; + else if (level == "DEBUG") + return logDEBUG; + else if (level == "INFO") + return logINFO; + else if (level == "WARNING") + return logWARNING; + else if (level == "ERROR") + return logERROR; + else if (level == "NONE") + return logNONE; + else { + Log().Get(logWARNING) << "Unknown logging level '" << level + << "'. Using INFO level as default."; + return logINFO; + } +} + +class FileLogger +{ +public: + static FILE*& + get_stream(); + + static void + write( + const std::string& msg); +}; + +inline FILE*& +FileLogger::get_stream() { + static FILE* stream = stderr; + return stream; +} + +inline void +FileLogger::write( + const std::string& msg) { + + FILE* stream = get_stream(); + if (!stream) { + return; + } + fprintf(stream, "%s", msg.c_str()); + fflush(stream); +} + +class MiniLog : + public Log +{ +}; + +#define MINILOG(level) \ + if (level > MiniLog::current_level() || !FileLogger::get_stream()) ; \ + else MiniLog().get(level) + + +#endif /* MINILOG_H_ */ diff --git a/include/musly/musly.h b/include/musly/musly.h new file mode 100644 index 0000000..ef05c9f --- /dev/null +++ b/include/musly/musly.h @@ -0,0 +1,387 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_H_ +#define MUSLY_H_ + +#include + +#include + +#ifdef WIN32 + /** \hideinitializer */ + #define MUSLY_EXPORT __declspec(dllexport) +#else + /** \hideinitializer */ + #define MUSLY_EXPORT __attribute__ ((visibility("default"))) +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** Return the version of Musly. + * \returns the version as a null terminated string. + */ +MUSLY_EXPORT const char* +musly_version(); + + +/** Set the musly debug level. Valid levels are 0 (Quiet, DEFAULT), 1 (Error), + * 2 (Warning), 3 (Info), 4 (Debug), 5 (Trace). All output will be sent to + * stderr. + * + * \param[in] level The musly library debug level, if the level is invalid it + * will be set to the closest valid level. + */ +MUSLY_EXPORT void +musly_debug( + int level); + + +/** Lists all available music similarity methods. The methods are returned as + * a single null terminated string. The methods are separated by a comma (,). + * Use a method name to power on a Musly jukebox. + * + * \returns all available methods + * + * \sa musly_jukebox_poweron() + */ +MUSLY_EXPORT const char* +musly_jukebox_listmethods(); + + +/** Lists all available audio file decoders. The decoders are returned as + * a single null terminated string. The decoders are separated by a comma (,). + * Use a decoder name to power on a Musly jukebox musly_jukebox_poweron() + * The decoders are used in musly_track_analyze_audiofile(). + * + * \returns all available audio file decoders. + * + * \sa musly_jukebox_poweron() + */ +MUSLY_EXPORT const char* +musly_jukebox_listdecoders(); + + +/** Describe the initialized method. This call describes the used music + * similarity method of the referenced musly_jukebox in more detail. + * + * \param[in] jukebox an initialized reference to a Musly jukebox. + * \returns a description of the currently initialized music similarity + * method as a null terminated string. + * + * \sa musly_jukebox_poweron() + */ +MUSLY_EXPORT const char* +musly_jukebox_aboutmethod( + musly_jukebox* jukebox); + + +/** Returns a reference to an initialized Musly jukebox object. To initialize + * Musly you need to specify a music similarity method to use and a decoder. + * You can set both values to 0 (NULL) to initialize the default method and + * decoder. To list all available music similarity methods use + * musly_jukebox_listmethods(). To list all available audio file decoders + * use musly_jukebox_listdecoders(). If the initialization fails, NULL + * is returned. To get more information about the initialized music similarity + * method use musly_jukebox_aboutmethod(). + * + * The returned reference is required for almost all subsequent calls to Musly + * library calls. To add a music track to the jukebox inventory use + * musly_jukebox_addtrack(). To compute recommendations with the jukebox use + * musly_jukebox_similarity(). Note that before computation of similarity, the + * music style needs to be set with musly_jukebox_setmusicstyle(). + * + * \param[in] method the desired music similarity method. + * \param[in] decoder the desired decoder to initialize. + * \returns a reference to an initialized Musly jukebox object. + * + * \sa musly_jukebox_poweroff(), musly_jukebox_addtrack(), + * musly_jukebox_setmusicstyle(), musly_jukebox_similarity() + */ +MUSLY_EXPORT musly_jukebox* +musly_jukebox_poweron( + const char* method, + const char* decoder); + + +/** Deinitializes the given Musly jukebox. The referenced method and decoder + * objects are freed. Previously allocated Musly tracks allocated with + * musly_track_alloc() need to be freed separately. The referenced Musly + * jukebox object is invalidated by this call. + * + * \param[in] jukebox the Musly jukebox to deinitialize. + * + * \sa musly_jukebox_poweron() + */ +MUSLY_EXPORT void +musly_jukebox_poweroff( + musly_jukebox* jukebox); + + +/** Initialize the jukebox music style. To properly use the similarity function + * it is necessary to give the algorithms a hint about the music we are working + * with. Do this by passing a random sample of the tracks you want to analyze. + * As a rule of thumb use a maximum of 1000 randomly selected tracks to set + * the music style. The a copy of the musly_track array is stored internally. + * The referenced array can be safely deallocated after the call if required. + * + * \param[in] jukebox the Musly jukebox to set the music stlye. + * \param[in] tracks a random sample array of Musly tracks to use for + * the initialization. + * \parma[in] num_tracks the number of Musly tracks. + * + * \sa musly_jukebox_poweron(), musly_track_analyze_pcm(), + * musly_track_analyze_audiofile() + */ +MUSLY_EXPORT int +musly_jukebox_setmusicstyle( + musly_jukebox* jukebox, + musly_track** tracks, + size_t num_tracks); + + +/** Add a track to the Musly jukebox. To use the music similarity routines + * each Musly track has to be added to a jukebox. Internally Musly allocates an + * initialization vector for each track computed with the tracks passed to + * musly_jukebox_setmusicstyle(). + * + * \param[in] jukebox the Musly jukebox to add the track to. + * \param[in] the musly_track to add to the jukebox. + * \returns the track identifier for the track added to the jukebox. It is + * unique within this Musly jukebox object. + * + * \sa musly_jukebox_setmusicstyle(), musly_jukebox_similarity() + */ +MUSLY_EXPORT musly_trackid +musly_jukebox_addtrack( + musly_jukebox* jukebox, + musly_track* track); + + +/** Computes the similarity between a seed track and a list of other music + * tracks. To compute similarities between two music tracks the following + * steps have to been taken: + * + * - initialize a musly_jukebox object with: musly_jukebox_poweron() + * - analyze audio files, e.g. with musly_track_analyze_audiofile() + * - set the music style of the jukebox by using a small random sample of + * the audio tracks analyzed: musly_jukebox_setmusicstyle() + * - add the audio tracks to the musly_jukebox: musly_jukebox_addtrack() + * - use this function to compute similarities. + * + * \param[in] jukebox The Musly jukebox to use. + * \param[in] seed_track The seed track to compute similarities to + * \param[in] seed_trackid The id of the seed track as returned by + * musly_jukebox_addtrack(). + * \param[in] tracks An array of musly_track objects to compute the + * similarities to. + * \param[in] trackids An array of musly_trackids corresponding to the tracks + * array. The musly_trackids are returned after adding them to the + * musly_jukebox + * \param[in] num_tracks the size of the tracks and trackids arrays + * \param[out] similarities a preallocated float array to hold the computed + * similarities. + * \returns 0 on success and -1 on an error. + * + * \sa musly_jukebox_poweron(), musly_track_analyze_audiofile(), + * musly_track_analyze_pcm(), musly_jukebox_setmusicstyle(), + * musly_jukebox_addtrack() + */ +MUSLY_EXPORT int +musly_jukebox_similarity( + musly_jukebox* jukebox, + musly_track* seed_track, + musly_trackid seed_trackid, + musly_track** tracks, + musly_trackid* trackids, + size_t num_tracks, + float* similarities); + + +/** Allocates a musly_track in memory. As the size of a musly_track varies for + * each music similarity method, an initialized Musly jukebox object reference + * needs to be passed argument. You need to free the allocated musly_track with + * musly_track_free(). + * + * \param[in] jukebox A reference to an initialized Musly jukebox object. + * \returns An allocated musly_track float array. + * + * \sa musly_track_free() + */ +MUSLY_EXPORT musly_track* +musly_track_alloc( + musly_jukebox* jukebox); + + +/** Frees a musly_track previously allocated with musly_track_alloc(). + * + * \param track[in] The musly track you want to free. + * + * \sa musly_track_alloc() + */ +MUSLY_EXPORT void +musly_track_free( + musly_track* track); + + +/** Returns the size of a musly_track in bytes. In case you want to allocate + * the musly_track yourself, allocate the memory and cast the memory to a + * musly_track. The size of each musly_track varies from music similarity + * method to method, that is, the size depends on the method musly has been + * initialized with (musly_jukebox_poweron()). For safe serializing and + * deserializing of a musly_track to/from memory use musly_track_tobin() and + * musly_track_frombin(). + * + * \param[in] jukebox A reference to an initialized musly_jukebox object. + * + * \returns The number of bytes of a musly_track for the given musly_jukebox. + * + * \sa musly_jukebox_poweron(), musly_track_tobin(), musly_track_frombin(). + */ +MUSLY_EXPORT int +musly_track_size( + musly_jukebox* jukebox); + + +/** Returns the buffer size in bytes required to hold a musly_track. To + * serialize a musly_track for persistent use musly_track_tobin(). The buffer + * size varies for each music similarity method. + * + * \param[in] jukebox A reference to an initialized musly_jukebox object. + * + * \returns The required minimum buffer size required to hold a musly_track. + * + * \sa musly_jukebox_poweron(), musly_track_tobin(), musly_track_frombin(). + */ +MUSLY_EXPORT int +musly_track_binsize( + musly_jukebox* jukebox); + + +/** Serializes a musly_track to a byte buffer. Use this method to store or + * transmit a musly_track. musly_track_binsize() bytes will be written to + * to_buffer. To deserialize a buffer use musly_track_frombin(). + * + * \param[in] jukebox A reference to an initialized musly_jukebox object. + * + * \retuns The number of bytes written (musly_track_binsize()) in case of + * success, -1 in case an error occurred. + * + * \sa musly_jukebox_poweron(), musly_track_binsize(), musly_track_frombin(). + */ +MUSLY_EXPORT int +musly_track_tobin( + musly_jukebox* jukebox, + musly_track* from_track, + unsigned char* to_buffer); + + +/** Deserializes a byte buffer to a musly_track. Use this method re-transform a + * previously serialized byte buffer (musly_track_tobin()) to a musly_track. + * From the buffer musly_track_binsize() bytes will be read. + * + * \param[in] jukebox A reference to an initialized musly_jukebox object. + * \param[in] from_buffer the buffer to use for deserialization + * \param[out] to_track the musyl_track to store the deserialized track. + * + * \returns The number of bytes read (musly_track_binsize()) in case of + * success, -1 in case an error occurred. + * + * \sa musly_jukebox_poweron(), musly_track_binsize(), musly_track_tobin(). + */ +MUSLY_EXPORT int +musly_track_frombin( + musly_jukebox* jukebox, + unsigned char* from_buffer, + musly_track* to_track); + + +/** This function displays a string representation of the given musly_track. + * The data is displayed in a flat format. All data structures (matrices, + * covariance matrices) are exported as vectors. This call can be used to + * export the feature data for further analysis. + * Note: This function is not threadsafe! + * + * \param[in] jukenbox The Musly jukenbox to use. + * \param[in] from_track the musly_track to convert into a string + * representation. + * + * \returns a constant null terminated string representing from_track. + * + * \sa musly_track_tobin(), musly_track_frombin() + */ +const char* +musly_track_tostr( + musly_jukebox* jukebox, + musly_track* from_track); + + +/** Compute a music similarity model (musly_track) from the given PCM signal. + * The audio is analyzed according to the initialized music similarity method + * and the musly_track is filled with the feature data. The musly_track can + * then be used to compute the music similarity between other musly_track + * features (use musly_jukebox_similarity()). + * If you are analyzing music files, use musly_track_analyze_audiofile() which + * does the decoding and down-/re-sampling of audio itself. + * + * \param[in] jukebox A reference to an initialized musly_jukebox object. + * \param[in] mono_22khz_pcm The audio signal to analyze represented as a PCM float + * array. The audio signal has to be mono and sampled at 22050hz with float + * values between -1.0 and +1.0. + * \param[in] length_pcm The length of the input float array. + * \param[out] track The musly_track to write the music similarity features. + * + * \returns 0 on success, -1 on failure. + * + * \sa musly_track_analyze_audiofile(), musly_jukebox_poweron(). + */ +MUSLY_EXPORT int +musly_track_analyze_pcm( + musly_jukebox* jukebox, + float* mono_22khz_pcm, + size_t length_pcm, + musly_track* track); + + +/** Compute a music similarity model (musly_track) from the audio file. + * The audio file is decoded with the decoder selected when initializing + * the musly_jukebox, down- and re-sampled to a 22050Hz mono signal before + * a musly_track is computed. The audio is analyzed according to the + * initialized music similarity method and the musly_track is filled with the + * feature data. To compute the similarity to other musly_track objects, + * use the musly_jukebox_similarity() function. If you already decoded the + * PCM signal of the music you want to analyze, use musly_track_analyze_pcm(). + * + * \param[in] jukebox A reference to an initialized musly_jukebox object. + * \param[in] An audio file. The file will be decoded with the audio decoder. + * \param[in] The maximum number of seconds to decode. If set to zero the whole + * audio file is decoded. + * \param[out] track The musly_track to write the music similarity features. + * + * \returns 0 on success, -1 on failure. + * + * \sa musly_track_analyze_audiofile(), musly_jukebox_poweron(). + */ +MUSLY_EXPORT int +musly_track_analyze_audiofile( + musly_jukebox* jukebox, + const char* audiofile, + int max_seconds, + musly_track* track); + +#ifdef __cplusplus +} +#endif + +#endif // MUSLY_H_ diff --git a/include/musly/musly_types.h b/include/musly/musly_types.h new file mode 100644 index 0000000..fbec12f --- /dev/null +++ b/include/musly/musly_types.h @@ -0,0 +1,57 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_TYPES_H_ +#define MUSLY_TYPES_H_ + +/** The Musly base object storing the initialized music similarity method and + * audio decoder information. A reference to an initialized musly_jukebox + * object is required for almost any Musly call. + * + * \sa musly_jukebox_poweron(), musly_jukebox_poweroff() + */ +typedef struct { + /** A reference to the initialized music similarity method. Hides a C++ + * musly::method object. + */ + void* method; + + /** Method name as null terminated string + */ + char* method_name; + + /** A reference to the initialized audio file decoder. Hides a C++ + * musly::decoder object. + */ + void* decoder; + + /** Decoder name as null terminated string + */ + char* decoder_name; +} musly_jukebox; + + +/** A musly_track object typically represents the features extracted with an + * music similarity method. The features are stored linearly in a float* array. + * Each music similarity method may write different features into this + * structure. Thus the size of the structure will vary too. To allocate a + * Musly track use musly_track_alloc(). To get the size (in bytes) of a + * Musly track use musly_track_size(). + */ +typedef float musly_track; + + +/** Not yet used. + */ +typedef int musly_trackid; + + +#endif // MUSLY_TYPES_H_ diff --git a/libmusly/CMakeLists.txt b/libmusly/CMakeLists.txt new file mode 100644 index 0000000..b91e5d5 --- /dev/null +++ b/libmusly/CMakeLists.txt @@ -0,0 +1,41 @@ +# CMake buildfile generator file. +# Process with cmake to create your desired buildfiles. + +# (c) 2013-2014, Dominik Schnitzer + +add_subdirectory( + libresample) + +include_directories( + ${EIGEN3_INCLUDE_DIR} + ${LIBAV_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}) + +add_library(libmusly + kissfft/kiss_fft.c + kissfft/kiss_fftr.c + methods/mandelellis.cpp + methods/timbre.cpp + decoders/libav_0_8.cpp + resampler.cpp + plugins.cpp + method.cpp + decoder.cpp + windowfunction.cpp + powerspectrum.cpp + melspectrum.cpp + discretecosinetransform.cpp + mfcc.cpp + gaussianstatistics.cpp + mutualproximity.cpp + lib.cpp) + +target_link_libraries(libmusly + libmusly_resample + ${LIBAV_LIBRARIES}) + +set_target_properties(libmusly + PROPERTIES PREFIX "") + +install(TARGETS libmusly + DESTINATION lib) diff --git a/libmusly/decoder.cpp b/libmusly/decoder.cpp new file mode 100644 index 0000000..7d03cf5 --- /dev/null +++ b/libmusly/decoder.cpp @@ -0,0 +1,26 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "decoder.h" +#include "plugins.h" + +namespace musly { + + +decoder::decoder() +{ +} + +decoder::~decoder() +{ +} + +} /* namespace musly */ diff --git a/libmusly/decoder.h b/libmusly/decoder.h new file mode 100644 index 0000000..21ec40d --- /dev/null +++ b/libmusly/decoder.h @@ -0,0 +1,44 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_DECODER_H_ +#define MUSLY_DECODER_H_ + +#include +#include +#include "plugins.h" + +namespace musly { + +class decoder : + public plugin +{ +public: + decoder(); + virtual ~decoder(); + + virtual std::vector + decodeto_22050hz_mono_float( + const std::string& file, + int max_seconds) = 0; + +}; + +#define MUSLY_DECODER_REGCLASS(classname) \ +private: \ + static const plugin_creator_impl creator; + +#define MUSLY_DECODER_REGIMPL(classname, priority) \ + const plugin_creator_impl classname::creator(#classname, \ + plugins::DECODER_TYPE, priority); + +} /* namespace musly */ +#endif /* MUSLY_DECODER_H_ */ diff --git a/libmusly/decoders/libav_0_8.cpp b/libmusly/decoders/libav_0_8.cpp new file mode 100644 index 0000000..6d78098 --- /dev/null +++ b/libmusly/decoders/libav_0_8.cpp @@ -0,0 +1,280 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#define __STDC_CONSTANT_MACROS +#define __STDC_FORMAT_MACROS + +#include +#include +#include +#include +extern "C" { + #include + #include +} + +#include "minilog.h" +#include "resampler.h" +#include "libav_0_8.h" + +namespace musly { +namespace decoders { + +MUSLY_DECODER_REGIMPL(libav_0_8, 0); + +libav_0_8::libav_0_8() +{ + av_register_all(); + avcodec_register_all(); +} + +int +libav_0_8::samples_tofloat( + void* const out, + const void* const in, + const int in_stride, + const AVSampleFormat in_fmt, + int len) +{ + const int is = in_stride; + const uint8_t* pi = (uint8_t*)in; + uint8_t* po = (uint8_t*)out; + uint8_t* end = po + sizeof(float)*len; + +#define CONVFLOAT(ifmt, expr)\ +if (in_fmt == ifmt) {\ + do{\ + *(float*)po = expr; pi += is; po += sizeof(float);\ + } while(po < end);\ +} + CONVFLOAT(AV_SAMPLE_FMT_U8, (*(const uint8_t*)pi - 0x80)*(1.0 / (1<<7))) + else CONVFLOAT(AV_SAMPLE_FMT_S16, *(const int16_t*)pi*(1.0 / (1<<15))) + else CONVFLOAT(AV_SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1U<<31))) + else CONVFLOAT(AV_SAMPLE_FMT_FLT, *(const float*)pi) + else CONVFLOAT(AV_SAMPLE_FMT_DBL, *(const double*)pi) + else return -1; + + return 0; +} + +std::vector +libav_0_8::decodeto_22050hz_mono_float( + const std::string& file, + int max_seconds) +{ + MINILOG(logTRACE) << "Decoding: " << file << " started."; + + int target_rate = 22050; + + // silence libav + av_log_set_level(0); + + + // guess input format + AVFormatContext* fmtx = NULL; + int avret = avformat_open_input(&fmtx, file.c_str(), NULL, NULL); + if (avret < 0) { + MINILOG(logERROR) << "Could not open file, or detect file format"; + return std::vector(0); + } + + // retrieve stream information + if (avformat_find_stream_info(fmtx, NULL) < 0) { + MINILOG(logERROR) << "Could not find stream info"; + + avformat_close_input(&fmtx); + return std::vector(0); + } + + // if there are multiple audio streams, find the best one.. + int audio_stream_idx = + av_find_best_stream(fmtx, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0); + if (audio_stream_idx < 0) { + MINILOG(logERROR) << "Could not find audio stream in input file"; + + avformat_close_input(&fmtx); + return std::vector(0); + } + AVStream *st = fmtx->streams[audio_stream_idx]; + + // find a decoder for the stream + AVCodecContext *decx = st->codec; + AVCodec *dec = avcodec_find_decoder(decx->codec_id); + if (!dec) { + MINILOG(logERROR) << "Could not find codec."; + + avformat_close_input(&fmtx); + return std::vector(0); + } + + // open the decoder + avret = avcodec_open2(decx, dec, NULL); + if (avret < 0) { + MINILOG(logERROR) << "Could not open codec."; + + avformat_close_input(&fmtx); + return std::vector(0); + } + + // Currently only mono and stereo files are supported. + if ((decx->channels != 1) && (decx->channels != 2)) { + MINILOG(logWARNING) << "Unsupported number of channels: " + << decx->channels; + + avformat_close_input(&fmtx); + return std::vector(0); + } + + // check if we have a planar audio file + if (av_sample_fmt_is_planar(decx->sample_fmt)) { + MINILOG(logERROR) << "Unsupported sample format: planar"; + + avformat_close_input(&fmtx); + return std::vector(0); + } + + // allocate a frame + AVFrame* frame = avcodec_alloc_frame(); + if (!frame) { + MINILOG(logWARNING) << "Could not allocate frame"; + + avformat_close_input(&fmtx); + return std::vector(0); + } + + // allocate and initialize a packet + AVPacket pkt; + av_init_packet(&pkt); + pkt.data = NULL; + pkt.size = 0; + int got_frame = 0; + + // configuration + int input_stride = av_get_bytes_per_sample(decx->sample_fmt); + + // read packets + float* buffer = NULL; + int buffersize = 0; + std::vector decoded_pcm; + int subsequent_errors = 0; + int subsequent_errors_max = 20; + while ((av_read_frame(fmtx, &pkt) >= 0) && + ((max_seconds == 0) || + ((int)decoded_pcm.size() < (max_seconds*decx->sample_rate)))) + { + // use only audio frames + if (pkt.stream_index == audio_stream_idx) { + uint8_t* data = pkt.data; + int size = pkt.size; + while (pkt.size > 0) { + + // try to decode a frame + avcodec_get_frame_defaults(frame); + + int len = avcodec_decode_audio4(decx, frame, &got_frame, &pkt); + if (len < 0) { + MINILOG(logWARNING) << "Error decoding an audio frame"; + + // allow some frames to fail + if (subsequent_errors < subsequent_errors_max) { + subsequent_errors++; + break; + } + + // if too many frames failed decoding, abort + MINILOG(logERROR) << "Too many errors, aborting."; + av_free(frame); + av_free_packet(&pkt); + avformat_close_input(&fmtx); + if (buffer) { + delete[] buffer; + } + return std::vector(0); + } else { + subsequent_errors = 0; + } + + // if we got a frame + if (got_frame) { + // do we need to increase the buffer size? + int input_samples = frame->nb_samples*decx->channels; + if (input_samples > buffersize) { + if (buffer) { + delete[] buffer; + } + buffer = new float[input_samples]; + } + + // convert samples to float + if (samples_tofloat(buffer, frame->data[0], input_stride, + decx->sample_fmt, input_samples) < 0) { + MINILOG(logERROR) << "Strange sample format. Abort."; + + av_free(frame); + av_free_packet(&pkt); + avformat_close_input(&fmtx); + if (buffer) { + delete[] buffer; + } + return decoded_pcm; + } + + // inplace downmix to mono, if required + if (decx->channels == 2) { + for (int i = 0; i < frame->nb_samples; i++) { + buffer[i] = (buffer[i*2] + buffer[i*2+1]) / 2.0f; + } + } + + // store raw pcm data + decoded_pcm.insert(decoded_pcm.end(), buffer, + buffer+frame->nb_samples); + } + + // consume the packet + pkt.data += len; + pkt.size -= len; + } + pkt.data = data; + pkt.size = size; + } + + av_free_packet(&pkt); + } + MINILOG(logTRACE) << "Decoding loop finished."; + + // do we need to resample? + std::vector pcm; + if (target_rate != decx->sample_rate) { + MINILOG(logTRACE) << "Resampling signal. input=" + << decx->sample_rate << ", target=" << target_rate; + resampler r(decx->sample_rate, target_rate); + pcm = r.resample(decoded_pcm.data(), decoded_pcm.size()); + MINILOG(logTRACE) << "Resampling finished."; + } else { + pcm.resize(decoded_pcm.size()); + std::copy(decoded_pcm.begin(), decoded_pcm.end(), pcm.begin()); + } + + // cleanup + if (buffer) { + delete[] buffer; + } + av_free(frame); + avcodec_close(decx); + avformat_close_input(&fmtx); + + MINILOG(logTRACE) << "Decoding: " << file << " finalized."; + return pcm; +} + +} /* namespace decoders */ +} /* namespace musly */ diff --git a/libmusly/decoders/libav_0_8.h b/libmusly/decoders/libav_0_8.h new file mode 100644 index 0000000..8bbc9af --- /dev/null +++ b/libmusly/decoders/libav_0_8.h @@ -0,0 +1,45 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_DECODERS_LIBAV_0_8_H_ +#define MUSLY_DECODERS_LIBAV_0_8_H_ + +#include "decoder.h" + +namespace musly { +namespace decoders { + +class libav_0_8 : + public musly::decoder +{ + MUSLY_DECODER_REGCLASS(libav_0_8); + +private: + int + samples_tofloat( + void* const out, + const void* const in, + const int in_stride, + const AVSampleFormat in_fmt, + int len); + +public: + libav_0_8(); + + virtual std::vector + decodeto_22050hz_mono_float( + const std::string& file, + int max_seconds); +}; + +} /* namespace decoders */ +} /* namespace musly */ +#endif /* MUSLY_DECODERS_LIBAV_0_8_H_ */ diff --git a/libmusly/discretecosinetransform.cpp b/libmusly/discretecosinetransform.cpp new file mode 100644 index 0000000..e800c61 --- /dev/null +++ b/libmusly/discretecosinetransform.cpp @@ -0,0 +1,50 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include "minilog.h" +#include "discretecosinetransform.h" + +namespace musly { + + +discretecosinetransform::discretecosinetransform(int in_bins, int out_bins) : + m(in_bins, out_bins) +{ + // DCT-II + Eigen::VectorXf coeff1 = + Eigen::ArrayXf::LinSpaced(out_bins, 0, out_bins-1.0f); + Eigen::VectorXf coeff2 = + (2.0f*Eigen::ArrayXf::LinSpaced(in_bins, 0, in_bins-1.0f) + 1.0f); + m = 1.0f/std::sqrt(in_bins/2.0f) * + ((coeff1 * coeff2.transpose()) * M_PI_2/in_bins).array().cos(); + + // special scaling for first row + m.row(0) = m.row(0) * std::sqrt(2.0f)/2.0f; + + MINILOG(logTRACE) << "DCT-II filterbank: " << m; +} + +Eigen::MatrixXf discretecosinetransform::compress(const Eigen::MatrixXf& in) +{ + MINILOG(logTRACE) << "Computing DCT, input=" << in.rows() + << "x" << in.cols(); + + Eigen::MatrixXf out = (in.transpose() * m.transpose()).transpose(); + + MINILOG(logTRACE) << "Finished DCT, output=" << out.rows() + << "x" << out.cols(); + return out; +} + + +} /* namespace musly */ diff --git a/libmusly/discretecosinetransform.h b/libmusly/discretecosinetransform.h new file mode 100644 index 0000000..7f5bbe7 --- /dev/null +++ b/libmusly/discretecosinetransform.h @@ -0,0 +1,42 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_DISCRETECOSINETRANSFORM_H_ +#define MUSLY_DISCRETECOSINETRANSFORM_H_ + +#include + +namespace musly { + +/** Class implementing a DCT-II (Discrete Cosine Transform). It is implemented + * as a rather slow matrix multiplication. A faster variant would use DFTs. + */ +class discretecosinetransform { +private: + Eigen::MatrixXf m; + +public: + /** Construct a Discrete Cosine Transform (DCT-II) compression matrix. + * \param in_bins The numnber of input bins, i.e. the input DCT dimension. + * \param out_bins The number of bins to use after the DCT. + */ + discretecosinetransform(int in_bins, int out_bins); + + /** Compress the given vectors using a DCT-II. + * \param in The input matrix, each vector is compressed using a DCT. The + * matrix has to have in_bins rows. + * \returns The compressed matrix with out_bins rows. + */ + Eigen::MatrixXf compress(const Eigen::MatrixXf& in); +}; + +} /* namespace musly */ +#endif /* MUSLY_DISCRETECOSINETRANSFORM_H_ */ diff --git a/libmusly/gaussian.h b/libmusly/gaussian.h new file mode 100644 index 0000000..e4e0e4f --- /dev/null +++ b/libmusly/gaussian.h @@ -0,0 +1,26 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_GAUSSIAN_H_ +#define MUSLY_GAUSSIAN_H_ + +/** A structure modeling a multivariate Gaussian. + * + */ +struct gaussian { + float* mu; + float* covar; + float* covar_inverse; + float* covar_logdet; +}; + + +#endif /* MUSLY_GAUSSIAN_H_ */ diff --git a/libmusly/gaussianstatistics.cpp b/libmusly/gaussianstatistics.cpp new file mode 100644 index 0000000..ae09af2 --- /dev/null +++ b/libmusly/gaussianstatistics.cpp @@ -0,0 +1,246 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include "minilog.h" +#include "gaussianstatistics.h" + + +namespace musly { + +gaussian_statistics::gaussian_statistics( + int gaussian_dim) : + d(gaussian_dim), + covar_elems((d*(d+1)/2)) +{ +} + +int +gaussian_statistics::get_covarelems() +{ + return covar_elems; +} + +int +gaussian_statistics::get_dim() +{ + return d; +} + + +bool +gaussian_statistics::estimate_gaussian( + const Eigen::MatrixXf& m, + gaussian& g) +{ + MINILOG(logTRACE) << "Estimating Gaussian from matrix: " << m.rows() + << "x" << m.cols(); + + if (m.cols() <= d) { + MINILOG(logTRACE) << "could not estimate Gaussian. " + << "Too few input samples. m.cols=" << m.cols(); + return false; + } + + if (m.rows() != d) { + MINILOG(logTRACE) << "could not estimate Gaussian. " + << "Wrong dimension (d=" << d << " vs. m.rows=" + << m.rows() << ")"; + return false; + } + + // always compute sample mean + Eigen::VectorXf mu = m.rowwise().mean(); + if (g.mu) { + for (int i = 0; i < d; i++) { + g.mu[i] = mu(i); + } + } + + // always compute sample covariance + Eigen::MatrixXf covar = (m.colwise()-mu) * (m.colwise()-mu).transpose() + / (static_cast(m.cols()) - 1.0f); + + // Add Gaussian noise to the data to avoid singular covariance matrices + // in case the input data was silence. + covar.diagonal().array() += 1e-4; + if (g.covar) { + int idx_ij = 0; + for (int i = 0; i < d; i++) { + for (int j = i; j < d; j++) { + g.covar[idx_ij] = covar(i, j); + idx_ij++; + } + } + } + + // Check if we need to set logdet or inversecovar fields of the Gaussian + if (g.covar_inverse || g.covar_logdet) { + Eigen::FullPivHouseholderQR qr = + covar.fullPivHouseholderQr(); +/* if (!qr.isInvertible()) { + MINILOG(logDEBUG1) << "Could not compute inverse Gaussian " + << "covariance matrix"; + return false; + } +*/ + if (g.covar_inverse) { + Eigen::MatrixXf covar_inverse = qr.inverse(); + int idx_ij = 0; + for (int i = 0; i < d; i++) { + for (int j = i; j < d; j++) { + g.covar_inverse[idx_ij] = covar_inverse(i, j); + idx_ij++; + } + } + } + + if (g.covar_logdet) { + *(g.covar_logdet) = qr.logAbsDeterminant(); + } + } + + + return true; +} + + +float +gaussian_statistics::jensenshannon( + const gaussian& g0, + const gaussian& g1, + gaussian& tmp) +{ + // return 0 if the models to compare are the same + if ((g0.covar == g1.covar) && (g0.mu == g1.mu)) { + return 0; + } + float jsd = -0.25f * (*(g0.covar_logdet) + *(g1.covar_logdet)); + + // merge the mean and covariance matrices to get the merged Gaussian + for (int i = 0; i < d; i++) { + tmp.mu[i] = 0.5*(g0.mu[i] - g1.mu[i]); + } + int idx_covar = 0; + for (int i = 0; i < d; i++) { + for (int j = i; j < d; j++) { + tmp.covar[idx_covar] = 0.5f* + (g0.covar[idx_covar] + g1.covar[idx_covar]) + + tmp.mu[i]*tmp.mu[j]; + idx_covar++; + } + } + + // Do an inplace cholesky decompositon and compute logdet of the merged + // Gaussian. + int idx_ii = 0; + for (int i = 0; i < d; i++) { + int idx_k = i; + for (int k = 0; k < i; k++) { + tmp.covar[idx_ii] -= + tmp.covar[idx_k]*tmp.covar[idx_k]; + idx_k += d - k - 1; + } + + if (tmp.covar[idx_ii] <= 0) { + return -1; + } + tmp.covar[idx_ii] = std::sqrt(tmp.covar[idx_ii]); + jsd += std::log(tmp.covar[idx_ii]); + + int idx_ij = idx_ii; + for (int j = i+1; j < d; j++) { + idx_ij++; + + int idx_k = 0; + for (int k = 0; k < i; k++) { + tmp.covar[idx_ij] -= + tmp.covar[idx_k+i] * tmp.covar[idx_k+j]; + idx_k += d - k - 1; + } + tmp.covar[idx_ij] /= tmp.covar[idx_ii]; + } + + idx_ii += d - i; + } + + if (isnan(jsd) || isinf(jsd)) { + return std::numeric_limits::max(); + } + + return std::sqrt(std::max(0.0f, jsd)); +} + +float +gaussian_statistics::symmetric_kullbackleibler( + const gaussian& g0, + const gaussian& g1, + gaussian& tmp) +{ + // distance value + float skld = 0; + + // return 0 if the models to compare are the same + if ((g0.covar == g1.covar) && (g0.mu == g1.mu)) { + return skld; + } + + + // add the two inverted covariances + for (int i = 0; i < covar_elems; i++) { + tmp.covar_inverse[i] = g0.covar_inverse[i] + g1.covar_inverse[i]; + } + + for (int i = 0; i < d; i++) { + int idx = i*d - (i*i+i)/2; + + skld += g0.covar[idx+i] * g1.covar_inverse[idx+i] + + g1.covar[idx+i] * g0.covar_inverse[idx+i]; + + for (int k = i+1; k < d; k++) { + skld += 2*g0.covar[idx+k] * g1.covar_inverse[idx+k] + + 2*g1.covar[idx+k] * g0.covar_inverse[idx+k]; + } + } + + // compute the difference of the two means + for (int i = 0; i < d; i++) { + tmp.mu[i] = g0.mu[i] - g1.mu[i]; + } + + for (int i = 0; i < d; i++) { + int idx = i - d; + float tmp1 = 0; + + for (int k = 0; k <= i; k++) { + idx += d - k; + tmp1 += tmp.covar_inverse[idx] * tmp.mu[k]; + } + + for (int k = i + 1; k < d; k++) { + idx++; + tmp1 += tmp.covar_inverse[idx] * tmp.mu[k]; + } + skld += tmp1 * tmp.mu[i]; + } + + if (isnan(skld) || isinf(skld)) { + return std::numeric_limits::max(); + } + + return std::max(skld/4 - d/2, 0.0f); +} + +} /* namespace musly */ diff --git a/libmusly/gaussianstatistics.h b/libmusly/gaussianstatistics.h new file mode 100644 index 0000000..17c7e44 --- /dev/null +++ b/libmusly/gaussianstatistics.h @@ -0,0 +1,60 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_GAUSSIANSTATISTICS_H_ +#define MUSLY_GAUSSIANSTATISTICS_H_ + +#include +#include "gaussian.h" + + +namespace musly { + +/** A class to compute + * + */ +class gaussian_statistics { +private: + int d; + + int covar_elems; + +public: + /** A musly Gaussian representation. + * + */ + gaussian_statistics( + int gaussian_dim); + + int get_covarelems(); + + int get_dim(); + + bool + estimate_gaussian( + const Eigen::MatrixXf& m, + gaussian& g); + + float + jensenshannon( + const gaussian &g0, + const gaussian &g1, + gaussian &tmp); + + float + symmetric_kullbackleibler( + const gaussian& g0, + const gaussian& g1, + gaussian& tmp); +}; + +} /* namespace musly */ +#endif /* MUSLY_GAUSSIANSTATISTICS_H_ */ diff --git a/libmusly/kissfft/CHANGELOG b/libmusly/kissfft/CHANGELOG new file mode 100644 index 0000000..2dd3603 --- /dev/null +++ b/libmusly/kissfft/CHANGELOG @@ -0,0 +1,123 @@ +1.3.0 2012-07-18 + removed non-standard malloc.h from kiss_fft.h + + moved -lm to end of link line + + checked various return values + + converted python Numeric code to NumPy + + fixed test of int32_t on 64 bit OS + + added padding in a couple of places to allow SIMD alignment of structs + +1.2.9 2010-05-27 + threadsafe ( including OpenMP ) + + first edition of kissfft.hh the C++ template fft engine + +1.2.8 + Changed memory.h to string.h -- apparently more standard + + Added openmp extensions. This can have fairly linear speedups for larger FFT sizes. + +1.2.7 + Shrank the real-fft memory footprint. Thanks to Galen Seitz. + +1.2.6 (Nov 14, 2006) The "thanks to GenArts" release. + Added multi-dimensional real-optimized FFT, see tools/kiss_fftndr + Thanks go to GenArts, Inc. for sponsoring the development. + +1.2.5 (June 27, 2006) The "release for no good reason" release. + Changed some harmless code to make some compilers' warnings go away. + Added some more digits to pi -- why not. + Added kiss_fft_next_fast_size() function to help people decide how much to pad. + Changed multidimensional test from 8 dimensions to only 3 to avoid testing + problems with fixed point (sorry Buckaroo Banzai). + +1.2.4 (Oct 27, 2005) The "oops, inverse fixed point real fft was borked" release. + Fixed scaling bug for inverse fixed point real fft -- also fixed test code that should've been failing. + Thanks to Jean-Marc Valin for bug report. + + Use sys/types.h for more portable types than short,int,long => int16_t,int32_t,int64_t + If your system does not have these, you may need to define them -- but at least it breaks in a + loud and easily fixable way -- unlike silently using the wrong size type. + + Hopefully tools/psdpng.c is fixed -- thanks to Steve Kellog for pointing out the weirdness. + +1.2.3 (June 25, 2005) The "you want to use WHAT as a sample" release. + Added ability to use 32 bit fixed point samples -- requires a 64 bit intermediate result, a la 'long long' + + Added ability to do 4 FFTs in parallel by using SSE SIMD instructions. This is accomplished by + using the __m128 (vector of 4 floats) as kiss_fft_scalar. Define USE_SIMD to use this. + + I know, I know ... this is drifting a bit from the "kiss" principle, but the speed advantages + make it worth it for some. Also recent gcc makes it SOO easy to use vectors of 4 floats like a POD type. + +1.2.2 (May 6, 2005) The Matthew release + Replaced fixed point division with multiply&shift. Thanks to Jean-Marc Valin for + discussions regarding. Considerable speedup for fixed-point. + + Corrected overflow protection in real fft routines when using fixed point. + Finder's Credit goes to Robert Oschler of robodance for pointing me at the bug. + This also led to the CHECK_OVERFLOW_OP macro. + +1.2.1 (April 4, 2004) + compiles cleanly with just about every -W warning flag under the sun + + reorganized kiss_fft_state so it could be read-only/const. This may be useful for embedded systems + that are willing to predeclare twiddle factors, factorization. + + Fixed C_MUL,S_MUL on 16-bit platforms. + + tmpbuf will only be allocated if input & output buffers are same + scratchbuf will only be allocated for ffts that are not multiples of 2,3,5 + + NOTE: The tmpbuf,scratchbuf changes may require synchronization code for multi-threaded apps. + + +1.2 (Feb 23, 2004) + interface change -- cfg object is forward declaration of struct instead of void* + This maintains type saftey and lets the compiler warn/error about stupid mistakes. + (prompted by suggestion from Erik de Castro Lopo) + + small speed improvements + + added psdpng.c -- sample utility that will create png spectrum "waterfalls" from an input file + ( not terribly useful yet) + +1.1.1 (Feb 1, 2004 ) + minor bug fix -- only affects odd rank, in-place, multi-dimensional FFTs + +1.1 : (Jan 30,2004) + split sample_code/ into test/ and tools/ + + Removed 2-D fft and added N-D fft (arbitrary) + + modified fftutil.c to allow multi-d FFTs + + Modified core fft routine to allow an input stride via kiss_fft_stride() + (eased support of multi-D ffts) + + Added fast convolution filtering (FIR filtering using overlap-scrap method, with tail scrap) + + Add kfc.[ch]: the KISS FFT Cache. It takes care of allocs for you ( suggested by Oscar Lesta ). + +1.0.1 (Dec 15, 2003) + fixed bug that occurred when nfft==1. Thanks to Steven Johnson. + +1.0 : (Dec 14, 2003) + changed kiss_fft function from using a single buffer, to two buffers. + If the same buffer pointer is supplied for both in and out, kiss will + manage the buffer copies. + + added kiss_fft2d and kiss_fftr as separate source files (declarations in kiss_fft.h ) + +0.4 :(Nov 4,2003) optimized for radix 2,3,4,5 + +0.3 :(Oct 28, 2003) woops, version 2 didn't actually factor out any radices other than 2. + Thanks to Steven Johnson for finding this one. + +0.2 :(Oct 27, 2003) added mixed radix, only radix 2,4 optimized versions + +0.1 :(May 19 2003) initial release, radix 2 only diff --git a/libmusly/kissfft/COPYING b/libmusly/kissfft/COPYING new file mode 100644 index 0000000..2fc6685 --- /dev/null +++ b/libmusly/kissfft/COPYING @@ -0,0 +1,11 @@ +Copyright (c) 2003-2010 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. diff --git a/libmusly/kissfft/README b/libmusly/kissfft/README new file mode 100644 index 0000000..03b2e7a --- /dev/null +++ b/libmusly/kissfft/README @@ -0,0 +1,134 @@ +KISS FFT - A mixed-radix Fast Fourier Transform based up on the principle, +"Keep It Simple, Stupid." + + There are many great fft libraries already around. Kiss FFT is not trying +to be better than any of them. It only attempts to be a reasonably efficient, +moderately useful FFT that can use fixed or floating data types and can be +incorporated into someone's C program in a few minutes with trivial licensing. + +USAGE: + + The basic usage for 1-d complex FFT is: + + #include "kiss_fft.h" + + kiss_fft_cfg cfg = kiss_fft_alloc( nfft ,is_inverse_fft ,0,0 ); + + while ... + + ... // put kth sample in cx_in[k].r and cx_in[k].i + + kiss_fft( cfg , cx_in , cx_out ); + + ... // transformed. DC is in cx_out[0].r and cx_out[0].i + + free(cfg); + + Note: frequency-domain data is stored from dc up to 2pi. + so cx_out[0] is the dc bin of the FFT + and cx_out[nfft/2] is the Nyquist bin (if exists) + + Declarations are in "kiss_fft.h", along with a brief description of the +functions you'll need to use. + +Code definitions for 1d complex FFTs are in kiss_fft.c. + +You can do other cool stuff with the extras you'll find in tools/ + + * multi-dimensional FFTs + * real-optimized FFTs (returns the positive half-spectrum: (nfft/2+1) complex frequency bins) + * fast convolution FIR filtering (not available for fixed point) + * spectrum image creation + +The core fft and most tools/ code can be compiled to use float, double, + Q15 short or Q31 samples. The default is float. + + +BACKGROUND: + + I started coding this because I couldn't find a fixed point FFT that didn't +use assembly code. I started with floating point numbers so I could get the +theory straight before working on fixed point issues. In the end, I had a +little bit of code that could be recompiled easily to do ffts with short, float +or double (other types should be easy too). + + Once I got my FFT working, I was curious about the speed compared to +a well respected and highly optimized fft library. I don't want to criticize +this great library, so let's call it FFT_BRANDX. +During this process, I learned: + + 1. FFT_BRANDX has more than 100K lines of code. The core of kiss_fft is about 500 lines (cpx 1-d). + 2. It took me an embarrassingly long time to get FFT_BRANDX working. + 3. A simple program using FFT_BRANDX is 522KB. A similar program using kiss_fft is 18KB (without optimizing for size). + 4. FFT_BRANDX is roughly twice as fast as KISS FFT in default mode. + + It is wonderful that free, highly optimized libraries like FFT_BRANDX exist. +But such libraries carry a huge burden of complexity necessary to extract every +last bit of performance. + + Sometimes simpler is better, even if it's not better. + +FREQUENTLY ASKED QUESTIONS: + Q: Can I use kissfft in a project with a ___ license? + A: Yes. See LICENSE below. + + Q: Why don't I get the output I expect? + A: The two most common causes of this are + 1) scaling : is there a constant multiplier between what you got and what you want? + 2) mixed build environment -- all code must be compiled with same preprocessor + definitions for FIXED_POINT and kiss_fft_scalar + + Q: Will you write/debug my code for me? + A: Probably not unless you pay me. I am happy to answer pointed and topical questions, but + I may refer you to a book, a forum, or some other resource. + + +PERFORMANCE: + (on Athlon XP 2100+, with gcc 2.96, float data type) + + Kiss performed 10000 1024-pt cpx ffts in .63 s of cpu time. + For comparison, it took md5sum twice as long to process the same amount of data. + + Transforming 5 minutes of CD quality audio takes less than a second (nfft=1024). + +DO NOT: + ... use Kiss if you need the Fastest Fourier Transform in the World + ... ask me to add features that will bloat the code + +UNDER THE HOOD: + + Kiss FFT uses a time decimation, mixed-radix, out-of-place FFT. If you give it an input buffer + and output buffer that are the same, a temporary buffer will be created to hold the data. + + No static data is used. The core routines of kiss_fft are thread-safe (but not all of the tools directory). + + No scaling is done for the floating point version (for speed). + Scaling is done both ways for the fixed-point version (for overflow prevention). + + Optimized butterflies are used for factors 2,3,4, and 5. + + The real (i.e. not complex) optimization code only works for even length ffts. It does two half-length + FFTs in parallel (packed into real&imag), and then combines them via twiddling. The result is + nfft/2+1 complex frequency bins from DC to Nyquist. If you don't know what this means, search the web. + + The fast convolution filtering uses the overlap-scrap method, slightly + modified to put the scrap at the tail. + +LICENSE: + Revised BSD License, see COPYING for verbiage. + Basically, "free to use&change, give credit where due, no guarantees" + Note this license is compatible with GPL at one end of the spectrum and closed, commercial software at + the other end. See http://www.fsf.org/licensing/licenses + + A commercial license is available which removes the requirement for attribution. Contact me for details. + + +TODO: + *) Add real optimization for odd length FFTs + *) Document/revisit the input/output fft scaling + *) Make doc describing the overlap (tail) scrap fast convolution filtering in kiss_fastfir.c + *) Test all the ./tools/ code with fixed point (kiss_fastfir.c doesn't work, maybe others) + +AUTHOR: + Mark Borgerding + Mark@Borgerding.net diff --git a/libmusly/kissfft/README.simd b/libmusly/kissfft/README.simd new file mode 100644 index 0000000..b0fdac5 --- /dev/null +++ b/libmusly/kissfft/README.simd @@ -0,0 +1,78 @@ +If you are reading this, it means you think you may be interested in using the SIMD extensions in kissfft +to do 4 *separate* FFTs at once. + +Beware! Beyond here there be dragons! + +This API is not easy to use, is not well documented, and breaks the KISS principle. + + +Still reading? Okay, you may get rewarded for your patience with a considerable speedup +(2-3x) on intel x86 machines with SSE if you are willing to jump through some hoops. + +The basic idea is to use the packed 4 float __m128 data type as a scalar element. +This means that the format is pretty convoluted. It performs 4 FFTs per fft call on signals A,B,C,D. + +For complex data, the data is interlaced as follows: +rA0,rB0,rC0,rD0, iA0,iB0,iC0,iD0, rA1,rB1,rC1,rD1, iA1,iB1,iC1,iD1 ... +where "rA0" is the real part of the zeroth sample for signal A + +Real-only data is laid out: +rA0,rB0,rC0,rD0, rA1,rB1,rC1,rD1, ... + +Compile with gcc flags something like +-O3 -mpreferred-stack-boundary=4 -DUSE_SIMD=1 -msse + +Be aware of SIMD alignment. This is the most likely cause of segfaults. +The code within kissfft uses scratch variables on the stack. +With SIMD, these must have addresses on 16 byte boundaries. +Search on "SIMD alignment" for more info. + + + +Robin at Divide Concept was kind enough to share his code for formatting to/from the SIMD kissfft. +I have not run it -- use it at your own risk. It appears to do 4xN and Nx4 transpositions +(out of place). + +void SSETools::pack128(float* target, float* source, unsigned long size128) +{ + __m128* pDest = (__m128*)target; + __m128* pDestEnd = pDest+size128; + float* source0=source; + float* source1=source0+size128; + float* source2=source1+size128; + float* source3=source2+size128; + + while(pDest + +#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) ) + + +#ifdef KISS_FFT_USE_ALLOCA +// define this to allow use of alloca instead of malloc for temporary buffers +// Temporary buffers are used in two case: +// 1. FFT sizes that have "bad" factors. i.e. not 2,3 and 5 +// 2. "in-place" FFTs. Notice the quotes, since kissfft does not really do an in-place transform. +#include +#define KISS_FFT_TMP_ALLOC(nbytes) alloca(nbytes) +#define KISS_FFT_TMP_FREE(ptr) +#else +#define KISS_FFT_TMP_ALLOC(nbytes) KISS_FFT_MALLOC(nbytes) +#define KISS_FFT_TMP_FREE(ptr) KISS_FFT_FREE(ptr) +#endif diff --git a/libmusly/kissfft/kiss_fft.c b/libmusly/kissfft/kiss_fft.c new file mode 100644 index 0000000..465d6c9 --- /dev/null +++ b/libmusly/kissfft/kiss_fft.c @@ -0,0 +1,408 @@ +/* +Copyright (c) 2003-2010, 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 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; ur += 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; + + kiss_fft_cpx * scratch = (kiss_fft_cpx*)KISS_FFT_TMP_ALLOC(sizeof(kiss_fft_cpx)*p); + + for ( u=0; u=Norig) twidx-=Norig; + C_MUL(t,scratch[q] , twiddles[twidx] ); + C_ADDTO( Fout[ k ] ,t); + } + k += m; + } + } + KISS_FFT_TMP_FREE(scratch); +} + +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; + +#ifdef _OPENMP + // use openmp extensions at the + // top-level (not recursive) + if (fstride==1 && p<=5) + { + int k; + + // execute the p different work units in different threads +# pragma omp parallel for + for (k=0;k 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;iinverse) + 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) { + //NOTE: this is not really an in-place FFT algorithm. + //It just performs an out-of-place FFT into a temp buffer + kiss_fft_cpx * tmpbuf = (kiss_fft_cpx*)KISS_FFT_TMP_ALLOC( sizeof(kiss_fft_cpx)*st->nfft); + kf_work(tmpbuf,fin,1,in_stride, st->factors,st); + memcpy(fout,tmpbuf,sizeof(kiss_fft_cpx)*st->nfft); + KISS_FFT_TMP_FREE(tmpbuf); + }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); +} + + +void kiss_fft_cleanup(void) +{ + // nothing needed any more +} + +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/libmusly/kissfft/kiss_fft.h b/libmusly/kissfft/kiss_fft.h new file mode 100644 index 0000000..64c50f4 --- /dev/null +++ b/libmusly/kissfft/kiss_fft.h @@ -0,0 +1,124 @@ +#ifndef KISS_FFT_H +#define KISS_FFT_H + +#include +#include +#include +#include + +#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 +# define kiss_fft_scalar __m128 +#define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16) +#define KISS_FFT_FREE _mm_free +#else +#define KISS_FFT_MALLOC malloc +#define KISS_FFT_FREE free +#endif + + +#ifdef FIXED_POINT +#include +# 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); + +/* for real ffts, we need an even size */ +#define kiss_fftr_next_fast_size_real(n) \ + (kiss_fft_next_fast_size( ((n)+1)>>1)<<1) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libmusly/kissfft/kiss_fftr.c b/libmusly/kissfft/kiss_fftr.c new file mode 100644 index 0000000..b8e238b --- /dev/null +++ b/libmusly/kissfft/kiss_fftr.c @@ -0,0 +1,159 @@ +/* +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_fftr.h" +#include "_kiss_fft_guts.h" + +struct kiss_fftr_state{ + kiss_fft_cfg substate; + kiss_fft_cpx * tmpbuf; + kiss_fft_cpx * super_twiddles; +#ifdef USE_SIMD + void * pad; +#endif +}; + +kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem) +{ + int i; + kiss_fftr_cfg st = NULL; + size_t subsize, memneeded; + + if (nfft & 1) { + fprintf(stderr,"Real FFT optimization must be even.\n"); + return NULL; + } + nfft >>= 1; + + kiss_fft_alloc (nfft, inverse_fft, NULL, &subsize); + memneeded = sizeof(struct kiss_fftr_state) + subsize + sizeof(kiss_fft_cpx) * ( nfft * 3 / 2); + + if (lenmem == NULL) { + st = (kiss_fftr_cfg) KISS_FFT_MALLOC (memneeded); + } else { + if (*lenmem >= memneeded) + st = (kiss_fftr_cfg) mem; + *lenmem = memneeded; + } + if (!st) + return NULL; + + st->substate = (kiss_fft_cfg) (st + 1); /*just beyond kiss_fftr_state struct */ + st->tmpbuf = (kiss_fft_cpx *) (((char *) st->substate) + subsize); + st->super_twiddles = st->tmpbuf + nfft; + kiss_fft_alloc(nfft, inverse_fft, st->substate, &subsize); + + for (i = 0; i < nfft/2; ++i) { + double phase = + -3.14159265358979323846264338327 * ((double) (i+1) / nfft + .5); + if (inverse_fft) + phase *= -1; + kf_cexp (st->super_twiddles+i,phase); + } + return st; +} + +void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata) +{ + /* input buffer timedata is stored row-wise */ + int k,ncfft; + kiss_fft_cpx fpnk,fpk,f1k,f2k,tw,tdc; + + if ( st->substate->inverse) { + fprintf(stderr,"kiss fft usage error: improper alloc\n"); + exit(1); + } + + ncfft = st->substate->nfft; + + /*perform the parallel fft of two real signals packed in real,imag*/ + kiss_fft( st->substate , (const kiss_fft_cpx*)timedata, st->tmpbuf ); + /* The real part of the DC element of the frequency spectrum in st->tmpbuf + * contains the sum of the even-numbered elements of the input time sequence + * The imag part is the sum of the odd-numbered elements + * + * The sum of tdc.r and tdc.i is the sum of the input time sequence. + * yielding DC of input time sequence + * The difference of tdc.r - tdc.i is the sum of the input (dot product) [1,-1,1,-1... + * yielding Nyquist bin of input time sequence + */ + + tdc.r = st->tmpbuf[0].r; + tdc.i = st->tmpbuf[0].i; + C_FIXDIV(tdc,2); + CHECK_OVERFLOW_OP(tdc.r ,+, tdc.i); + CHECK_OVERFLOW_OP(tdc.r ,-, tdc.i); + freqdata[0].r = tdc.r + tdc.i; + freqdata[ncfft].r = tdc.r - tdc.i; +#ifdef USE_SIMD + freqdata[ncfft].i = freqdata[0].i = _mm_set1_ps(0); +#else + freqdata[ncfft].i = freqdata[0].i = 0; +#endif + + for ( k=1;k <= ncfft/2 ; ++k ) { + fpk = st->tmpbuf[k]; + fpnk.r = st->tmpbuf[ncfft-k].r; + fpnk.i = - st->tmpbuf[ncfft-k].i; + C_FIXDIV(fpk,2); + C_FIXDIV(fpnk,2); + + C_ADD( f1k, fpk , fpnk ); + C_SUB( f2k, fpk , fpnk ); + C_MUL( tw , f2k , st->super_twiddles[k-1]); + + freqdata[k].r = HALF_OF(f1k.r + tw.r); + freqdata[k].i = HALF_OF(f1k.i + tw.i); + freqdata[ncfft-k].r = HALF_OF(f1k.r - tw.r); + freqdata[ncfft-k].i = HALF_OF(tw.i - f1k.i); + } +} + +void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata) +{ + /* input buffer timedata is stored row-wise */ + int k, ncfft; + + if (st->substate->inverse == 0) { + fprintf (stderr, "kiss fft usage error: improper alloc\n"); + exit (1); + } + + ncfft = st->substate->nfft; + + st->tmpbuf[0].r = freqdata[0].r + freqdata[ncfft].r; + st->tmpbuf[0].i = freqdata[0].r - freqdata[ncfft].r; + C_FIXDIV(st->tmpbuf[0],2); + + for (k = 1; k <= ncfft / 2; ++k) { + kiss_fft_cpx fk, fnkc, fek, fok, tmp; + fk = freqdata[k]; + fnkc.r = freqdata[ncfft - k].r; + fnkc.i = -freqdata[ncfft - k].i; + C_FIXDIV( fk , 2 ); + C_FIXDIV( fnkc , 2 ); + + C_ADD (fek, fk, fnkc); + C_SUB (tmp, fk, fnkc); + C_MUL (fok, tmp, st->super_twiddles[k-1]); + C_ADD (st->tmpbuf[k], fek, fok); + C_SUB (st->tmpbuf[ncfft - k], fek, fok); +#ifdef USE_SIMD + st->tmpbuf[ncfft - k].i *= _mm_set1_ps(-1.0); +#else + st->tmpbuf[ncfft - k].i *= -1; +#endif + } + kiss_fft (st->substate, st->tmpbuf, (kiss_fft_cpx *) timedata); +} diff --git a/libmusly/kissfft/kiss_fftr.h b/libmusly/kissfft/kiss_fftr.h new file mode 100644 index 0000000..72e5a57 --- /dev/null +++ b/libmusly/kissfft/kiss_fftr.h @@ -0,0 +1,46 @@ +#ifndef KISS_FTR_H +#define KISS_FTR_H + +#include "kiss_fft.h" +#ifdef __cplusplus +extern "C" { +#endif + + +/* + + Real optimized version can save about 45% cpu time vs. complex fft of a real seq. + + + + */ + +typedef struct kiss_fftr_state *kiss_fftr_cfg; + + +kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenmem); +/* + nfft must be even + + If you don't care to allocate space, use mem = lenmem = NULL +*/ + + +void kiss_fftr(kiss_fftr_cfg cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata); +/* + input timedata has nfft scalar points + output freqdata has nfft/2+1 complex points +*/ + +void kiss_fftri(kiss_fftr_cfg cfg,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata); +/* + input freqdata has nfft/2+1 complex points + output timedata has nfft scalar points +*/ + +#define kiss_fftr_free free + +#ifdef __cplusplus +} +#endif +#endif diff --git a/libmusly/lib.cpp b/libmusly/lib.cpp new file mode 100644 index 0000000..a72829e --- /dev/null +++ b/libmusly/lib.cpp @@ -0,0 +1,353 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "config.h" + +#include +#include + +#include "musly/musly.h" +#include "minilog.h" +#include "plugins.h" +#include "decoder.h" +#include "method.h" + + +const char* +musly_version() +{ + return MUSLY_VERSION; +} + +void +musly_debug( + int level) +{ + // Set the log level, too high/low values are set to the closest valid + // log level. + MiniLog::current_level() = minilog_level( + std::min(std::max(0, level), (int)(minilog_level_max)-1)); +} + +const char* +musly_jukebox_listmethods() +{ + return musly::plugins::get_plugins(musly::plugins::METHOD_TYPE).c_str(); +} + +const char* +musly_jukebox_listdecoders() +{ + return musly::plugins::get_plugins(musly::plugins::DECODER_TYPE).c_str(); +} + +const char* +musly_jukebox_aboutmethod( + musly_jukebox* jukebox) +{ + if (jukebox->method) { + musly::method* m = reinterpret_cast(jukebox->method); + + return m->about(); + } + + return ""; +} + +musly_jukebox* +musly_jukebox_poweron( + const char* method, + const char* decoder) +{ + // try initializing the similarity method + std::string method_str; + if (!method) { + method_str = ""; + } else { + method_str = method; + } + musly::method* m = reinterpret_cast( + musly::plugins::instantiate_plugin( + musly::plugins::METHOD_TYPE, method_str)); + if (!m) { + return NULL; + } + + // try initializing the selected decoder + std::string decoder_str; + if (!decoder) { + decoder_str = ""; + } else { + decoder_str = decoder; + } + musly::decoder* d = reinterpret_cast( + musly::plugins::instantiate_plugin( + musly::plugins::DECODER_TYPE, decoder_str)); + if (!d) { + delete m; + return NULL; + } + + // if we succeeded in both, return the jukebox! + musly_jukebox* mj = new musly_jukebox; + mj->method = reinterpret_cast(m); + mj->method_name = new char[method_str.size()+1]; + method_str.copy(mj->method_name, method_str.size()); + mj->method_name[method_str.size()] = '\0'; + + mj->decoder = reinterpret_cast(d); + mj->decoder_name = new char[decoder_str.size()+1]; + decoder_str.copy(mj->decoder_name, decoder_str.size()); + mj->decoder_name[decoder_str.size()] = '\0'; + return mj; +} + +void +musly_jukebox_poweroff( + musly_jukebox* jukebox) +{ + if (!jukebox) { + return; + } + if (jukebox->method) { + musly::method* m = reinterpret_cast(jukebox->method); + delete m; + } + if (jukebox->method_name) { + delete[] jukebox->method_name; + } + + if (jukebox->decoder) { + musly::decoder* d = reinterpret_cast(jukebox->decoder); + delete d; + } + if (jukebox->decoder_name) { + delete[] jukebox->decoder_name; + } + + delete jukebox; +} + + +int +musly_jukebox_setmusicstyle( + musly_jukebox* jukebox, + musly_track** tracks, + size_t num_tracks) +{ + if (jukebox && jukebox->method) { + musly::method* m = reinterpret_cast(jukebox->method); + return m->set_musicstyle(tracks, num_tracks); + } else { + return -1; + } + + return -1; +} + +musly_trackid +musly_jukebox_addtrack( + musly_jukebox* jukebox, + musly_track* track) +{ + if (jukebox && jukebox->method) { + musly::method* m = reinterpret_cast(jukebox->method); + return m->add_track(track); + } else { + return -1; + } + + return -1; +} + +int +musly_jukebox_similarity( + musly_jukebox* jukebox, + musly_track* seed_track, + musly_trackid seed_trackid, + musly_track** tracks, + musly_trackid* trackids, + size_t num_tracks, + float* similarities) +{ + // TODO implement full call + + if (jukebox && jukebox->method) { + musly::method* m = reinterpret_cast(jukebox->method); + return m->similarity( + seed_track, seed_trackid, + tracks, trackids, + num_tracks, similarities); + } else { + return -1; + } +} + + + +musly_track* +musly_track_alloc( + musly_jukebox* jukebox) +{ + if (jukebox && jukebox->method) { + musly::method* m = reinterpret_cast(jukebox->method); + return m->track_alloc(); + } else { + return NULL; + } +} + +void +musly_track_free( + musly_track* track) +{ + if (track) { + delete[] track; + } +} + +int +musly_track_size( + musly_jukebox* jukebox) +{ + if (jukebox && jukebox->method) { + musly::method* m = reinterpret_cast(jukebox->method); + return m->track_getsize() * sizeof(float); + } else { + return -1; + } +} + +int +musly_track_binsize( + musly_jukebox* jukebox) +{ + return musly_track_size(jukebox); +} + +int +musly_track_tobin( + musly_jukebox* jukebox, + musly_track* from_track, + unsigned char* to_buffer) +{ + if (jukebox && jukebox->method && from_track && to_buffer) { + musly::method* m = reinterpret_cast(jukebox->method); + + // check if buffer is big enough + int len = m->track_getsize(); + int sz = len*sizeof(float); + + // serialize to uint32 and convert to network byte order + union v { + float f; + uint32_t i; + } val; + uint32_t* raw_uint32 = reinterpret_cast(to_buffer); + for (int i = 0; i < len; i++) { + val.f = from_track[i]; + raw_uint32[i] = htonl(val.i); + } + + return sz; + + } else { + return -1; + } +} + +int +musly_track_frombin( + musly_jukebox* jukebox, + unsigned char* from_buffer, + musly_track* to_track) +{ + if (jukebox && jukebox->method && to_track && from_buffer) { + musly::method* m = reinterpret_cast(jukebox->method); + + // check if buffer is big enough + int len = m->track_getsize(); + int sz = len*sizeof(float); + + // deserialize from uint32 and convert from network byte order to + // host byte order. + union v { + float f; + uint32_t i; + } val; + uint32_t* raw_uint32 = reinterpret_cast(from_buffer); + for (int i = 0; i < len; i++) { + val.i = ntohl(raw_uint32[i]); + to_track[i] = val.f; + } + + return sz; + + } else { + return -1; + } +} + +const char* +musly_track_tostr(musly_jukebox* jukebox, + musly_track* from_track) +{ + if (jukebox && jukebox->method) { + musly::method* m = reinterpret_cast(jukebox->method); + return m->track_tostr(from_track); + } else { + return ""; + } +} + +int +musly_track_analyze_pcm( + musly_jukebox* jukebox, + float* mono_22khz_pcm, + size_t length_pcm, + musly_track* track) +{ + if (jukebox && jukebox->method) { + musly::method* m = reinterpret_cast(jukebox->method); + return m->analyze_track(mono_22khz_pcm, length_pcm, track); + } else { + return -1; + } +} + + +int +musly_track_analyze_audiofile( + musly_jukebox* jukebox, + const char* audiofile, + int max_seconds, + musly_track* track) +{ + if (jukebox && jukebox->decoder) { + + // try decoding the given audio file + musly::decoder* d = reinterpret_cast(jukebox->decoder); + + // decode a maximum of 60 seconds + std::vector pcm = + d->decodeto_22050hz_mono_float(audiofile, max_seconds); + if (pcm.size() == 0) { + return -1; + } + + return musly_track_analyze_pcm(jukebox, pcm.data(), pcm.size(), track); + + } else { + return -1; + } + return 0; +} + diff --git a/libmusly/libresample/CMakeLists.txt b/libmusly/libresample/CMakeLists.txt new file mode 100644 index 0000000..153d71b --- /dev/null +++ b/libmusly/libresample/CMakeLists.txt @@ -0,0 +1,15 @@ +# CMake buildfile generator file. +# Process with cmake to create your desired buildfiles. + +# (c) 2013-2014, Dominik Schnitzer + +add_library(libmusly_resample + filterkit.c + resamplesubs.c + resample.c) + +set_target_properties(libmusly_resample + PROPERTIES PREFIX "") + +install(TARGETS libmusly_resample + DESTINATION lib) diff --git a/libmusly/libresample/LICENSE.txt b/libmusly/libresample/LICENSE.txt new file mode 100644 index 0000000..4ccd6cc --- /dev/null +++ b/libmusly/libresample/LICENSE.txt @@ -0,0 +1,463 @@ + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations +below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control +compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply, and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License +may add an explicit geographical distribution limitation excluding those +countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + diff --git a/libmusly/libresample/README.txt b/libmusly/libresample/README.txt new file mode 100644 index 0000000..14be45b --- /dev/null +++ b/libmusly/libresample/README.txt @@ -0,0 +1,84 @@ +libresample + +Real-time library interface by Dominic Mazzoni + +Based on resample-1.7: + http://www-ccrma.stanford.edu/~jos/resample/ + +License: LGPL - see the file LICENSE.txt for more information + +History: + +This library is not the highest-quality resampling library +available, nor is it the most flexible, nor is it the +fastest. But it is pretty good in all of these regards, and +it is quite portable. The best resampling library I am aware +of is libsamplerate by Erik de Castro Lopo. It's small, fast, +and very high quality. However, it uses the GPL for its +license (with commercial options available) and I needed +a more free library. So I wrote this library, using +the LGPL resample-1.7 library by Julius Smith as a basis. + +Resample-1.7 is a fixed-point resampler, and as a result +has only limited precision. I rewrote it to use single-precision +floating-point arithmetic instead and increased the number +of filter coefficients between time steps significantly. +On modern processors it can resample in real time even +with this extra overhead. + +Resample-1.7 was designed to read and write from files, so +I removed all of that code and replaced it with an API that +lets you pass samples in small chunks. It should be easy +to link to resample-1.7 as a library. + +Changes in version 0.1.3: + +* Fixed two bugs that were causing subtle problems + on Intel x86 processors due to differences in roundoff errors. + +* Prefixed most function names with lrs and changed header file + from resample.h to libresample.h, to avoid namespace + collisions with existing programs and libraries. + +* Added resample_dup (thanks to Glenn Maynard) + +* Argument to resample_get_filter_width takes a const void * + (thanks to Glenn Maynard) + +* resample-sndfile clips output to -1...1 (thanks to Glenn Maynard) + +Usage notes: + +- If the output buffer you pass is too small, resample_process + may not use any input samples because its internal output + buffer is too full to process any more. So do not assume + that it is an error just because no input samples were + consumed. Just keep passing valid output buffers. + +- Given a resampling factor f > 1, and a number of input + samples n, the number of output samples should be between + floor(n - f) and ceil(n + f). In other words, if you + resample 1000 samples at a factor of 8, the number of + output samples might be between 7992 and 8008. Do not + assume that it will be exactly 8000. If you need exactly + 8000 outputs, pad the input with extra zeros as necessary. + +License and warranty: + +All of the files in this package are Copyright 2003 by Dominic +Mazzoni . This library was based heavily +on Resample-1.7, Copyright 1994-2002 by Julius O. Smith III +, all rights reserved. + +Permission to use and copy is granted subject to the terms of the +"GNU Lesser General Public License" (LGPL) as published by the +Free Software Foundation; either version 2.1 of the License, +or any later version. In addition, Julius O. Smith III requests +that a copy of any modified files be sent by email to +jos@ccrma.stanford.edu so that he may incorporate them into the +CCRMA version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. diff --git a/libmusly/libresample/filterkit.c b/libmusly/libresample/filterkit.c new file mode 100644 index 0000000..bc92285 --- /dev/null +++ b/libmusly/libresample/filterkit.c @@ -0,0 +1,215 @@ +/********************************************************************** + + resamplesubs.c + + Real-time library interface by Dominic Mazzoni + + Based on resample-1.7: + http://www-ccrma.stanford.edu/~jos/resample/ + + License: LGPL - see the file LICENSE.txt for more information + + This file provides Kaiser-windowed low-pass filter support, + including a function to create the filter coefficients, and + two functions to apply the filter at a particular point. + +**********************************************************************/ + +/* Definitions */ +#include "resample_defs.h" + +#include "filterkit.h" + +#include +#include +#include +#include + +/* LpFilter() + * + * reference: "Digital Filters, 2nd edition" + * R.W. Hamming, pp. 178-179 + * + * Izero() computes the 0th order modified bessel function of the first kind. + * (Needed to compute Kaiser window). + * + * LpFilter() computes the coeffs of a Kaiser-windowed low pass filter with + * the following characteristics: + * + * c[] = array in which to store computed coeffs + * frq = roll-off frequency of filter + * N = Half the window length in number of coeffs + * Beta = parameter of Kaiser window + * Num = number of coeffs before 1/frq + * + * Beta trades the rejection of the lowpass filter against the transition + * width from passband to stopband. Larger Beta means a slower + * transition and greater stopband rejection. See Rabiner and Gold + * (Theory and Application of DSP) under Kaiser windows for more about + * Beta. The following table from Rabiner and Gold gives some feel + * for the effect of Beta: + * + * All ripples in dB, width of transition band = D*N where N = window length + * + * BETA D PB RIP SB RIP + * 2.120 1.50 +-0.27 -30 + * 3.384 2.23 0.0864 -40 + * 4.538 2.93 0.0274 -50 + * 5.658 3.62 0.00868 -60 + * 6.764 4.32 0.00275 -70 + * 7.865 5.0 0.000868 -80 + * 8.960 5.7 0.000275 -90 + * 10.056 6.4 0.000087 -100 + */ + +#define IzeroEPSILON 1E-21 /* Max error acceptable in Izero */ + +static double Izero(double x) +{ + double sum, u, halfx, temp; + int n; + + sum = u = n = 1; + halfx = x/2.0; + do { + temp = halfx/(double)n; + n += 1; + temp *= temp; + u *= temp; + sum += u; + } while (u >= IzeroEPSILON*sum); + return(sum); +} + +void lrsLpFilter(double c[], int N, double frq, double Beta, int Num) +{ + double IBeta, temp, temp1, inm1; + int i; + + /* Calculate ideal lowpass filter impulse response coefficients: */ + c[0] = 2.0*frq; + for (i=1; i +#include +#include +#include + +typedef struct { + float *Imp; + float *ImpD; + float LpScl; + UWORD Nmult; + UWORD Nwing; + double minFactor; + double maxFactor; + UWORD XSize; + float *X; + UWORD Xp; /* Current "now"-sample pointer for input */ + UWORD Xread; /* Position to put new samples */ + UWORD Xoff; + UWORD YSize; + float *Y; + UWORD Yp; + double Time; +} rsdata; + +void *resample_dup(const void * handle) +{ + const rsdata *cpy = (const rsdata *)handle; + rsdata *hp = (rsdata *)malloc(sizeof(rsdata)); + + hp->minFactor = cpy->minFactor; + hp->maxFactor = cpy->maxFactor; + hp->Nmult = cpy->Nmult; + hp->LpScl = cpy->LpScl; + hp->Nwing = cpy->Nwing; + + hp->Imp = (float *)malloc(hp->Nwing * sizeof(float)); + memcpy(hp->Imp, cpy->Imp, hp->Nwing * sizeof(float)); + hp->ImpD = (float *)malloc(hp->Nwing * sizeof(float)); + memcpy(hp->ImpD, cpy->ImpD, hp->Nwing * sizeof(float)); + + hp->Xoff = cpy->Xoff; + hp->XSize = cpy->XSize; + hp->X = (float *)malloc((hp->XSize + hp->Xoff) * sizeof(float)); + memcpy(hp->X, cpy->X, (hp->XSize + hp->Xoff) * sizeof(float)); + hp->Xp = cpy->Xp; + hp->Xread = cpy->Xread; + hp->YSize = cpy->YSize; + hp->Y = (float *)malloc(hp->YSize * sizeof(float)); + memcpy(hp->Y, cpy->Y, hp->YSize * sizeof(float)); + hp->Yp = cpy->Yp; + hp->Time = cpy->Time; + + return (void *)hp; +} + +void *resample_open(int highQuality, double minFactor, double maxFactor) +{ + double *Imp64; + double Rolloff, Beta; + rsdata *hp; + UWORD Xoff_min, Xoff_max; + int i; + + /* Just exit if we get invalid factors */ + if (minFactor <= 0.0 || maxFactor <= 0.0 || maxFactor < minFactor) { + #if DEBUG + fprintf(stderr, + "libresample: " + "minFactor and maxFactor must be positive real numbers,\n" + "and maxFactor should be larger than minFactor.\n"); + #endif + return 0; + } + + hp = (rsdata *)malloc(sizeof(rsdata)); + + hp->minFactor = minFactor; + hp->maxFactor = maxFactor; + + if (highQuality) + hp->Nmult = 35; + else + hp->Nmult = 11; + + hp->LpScl = 1.0; + hp->Nwing = Npc*(hp->Nmult-1)/2; /* # of filter coeffs in right wing */ + + Rolloff = 0.90; + Beta = 6; + + Imp64 = (double *)malloc(hp->Nwing * sizeof(double)); + + lrsLpFilter(Imp64, hp->Nwing, 0.5*Rolloff, Beta, Npc); + + hp->Imp = (float *)malloc(hp->Nwing * sizeof(float)); + hp->ImpD = (float *)malloc(hp->Nwing * sizeof(float)); + for(i=0; iNwing; i++) + hp->Imp[i] = Imp64[i]; + + /* Storing deltas in ImpD makes linear interpolation + of the filter coefficients faster */ + for (i=0; iNwing-1; i++) + hp->ImpD[i] = hp->Imp[i+1] - hp->Imp[i]; + + /* Last coeff. not interpolated */ + hp->ImpD[hp->Nwing-1] = - hp->Imp[hp->Nwing-1]; + + free(Imp64); + + /* Calc reach of LP filter wing (plus some creeping room) */ + Xoff_min = ((hp->Nmult+1)/2.0) * MAX(1.0, 1.0/minFactor) + 10; + Xoff_max = ((hp->Nmult+1)/2.0) * MAX(1.0, 1.0/maxFactor) + 10; + hp->Xoff = MAX(Xoff_min, Xoff_max); + + /* Make the inBuffer size at least 4096, but larger if necessary + in order to store the minimum reach of the LP filter and then some. + Then allocate the buffer an extra Xoff larger so that + we can zero-pad up to Xoff zeros at the end when we reach the + end of the input samples. */ + hp->XSize = MAX(2*hp->Xoff+10, 4096); + hp->X = (float *)malloc((hp->XSize + hp->Xoff) * sizeof(float)); + hp->Xp = hp->Xoff; + hp->Xread = hp->Xoff; + + /* Need Xoff zeros at begining of X buffer */ + for(i=0; iXoff; i++) + hp->X[i]=0; + + /* Make the outBuffer long enough to hold the entire processed + output of one inBuffer */ + hp->YSize = (int)(((double)hp->XSize)*maxFactor+2.0); + hp->Y = (float *)malloc(hp->YSize * sizeof(float)); + hp->Yp = 0; + + hp->Time = (double)hp->Xoff; /* Current-time pointer for converter */ + + return (void *)hp; +} + +int resample_get_filter_width(const void *handle) +{ + const rsdata *hp = (const rsdata *)handle; + return hp->Xoff; +} + +int resample_process(void *handle, + double factor, + float *inBuffer, + int inBufferLen, + int lastFlag, + int *inBufferUsed, /* output param */ + float *outBuffer, + int outBufferLen) +{ + rsdata *hp = (rsdata *)handle; + float *Imp = hp->Imp; + float *ImpD = hp->ImpD; + float LpScl = hp->LpScl; + UWORD Nwing = hp->Nwing; + BOOL interpFilt = FALSE; /* TRUE means interpolate filter coeffs */ + int outSampleCount; + UWORD Nout, Ncreep, Nreuse; + int Nx; + int i, len; + + #if DEBUG + fprintf(stderr, "resample_process: in=%d, out=%d lastFlag=%d\n", + inBufferLen, outBufferLen, lastFlag); + #endif + + /* Initialize inBufferUsed and outSampleCount to 0 */ + *inBufferUsed = 0; + outSampleCount = 0; + + if (factor < hp->minFactor || factor > hp->maxFactor) { + #if DEBUG + fprintf(stderr, + "libresample: factor %f is not between " + "minFactor=%f and maxFactor=%f", + factor, hp->minFactor, hp->maxFactor); + #endif + return -1; + } + + /* Start by copying any samples still in the Y buffer to the output + buffer */ + if (hp->Yp && (outBufferLen-outSampleCount)>0) { + len = MIN(outBufferLen-outSampleCount, hp->Yp); + for(i=0; iY[i]; + outSampleCount += len; + for(i=0; iYp-len; i++) + hp->Y[i] = hp->Y[i+len]; + hp->Yp -= len; + } + + /* If there are still output samples left, return now - we need + the full output buffer available to us... */ + if (hp->Yp) + return outSampleCount; + + /* Account for increased filter gain when using factors less than 1 */ + if (factor < 1) + LpScl = LpScl*factor; + + for(;;) { + + /* This is the maximum number of samples we can process + per loop iteration */ + + #ifdef DEBUG + printf("XSize: %d Xoff: %d Xread: %d Xp: %d lastFlag: %d\n", + hp->XSize, hp->Xoff, hp->Xread, hp->Xp, lastFlag); + #endif + + /* Copy as many samples as we can from the input buffer into X */ + len = hp->XSize - hp->Xread; + + if (len >= (inBufferLen - (*inBufferUsed))) + len = (inBufferLen - (*inBufferUsed)); + + for(i=0; iX[hp->Xread + i] = inBuffer[(*inBufferUsed) + i]; + + *inBufferUsed += len; + hp->Xread += len; + + if (lastFlag && (*inBufferUsed == inBufferLen)) { + /* If these are the last samples, zero-pad the + end of the input buffer and make sure we process + all the way to the end */ + Nx = hp->Xread - hp->Xoff; + for(i=0; iXoff; i++) + hp->X[hp->Xread + i] = 0; + } + else + Nx = hp->Xread - 2 * hp->Xoff; + + #ifdef DEBUG + fprintf(stderr, "new len=%d Nx=%d\n", len, Nx); + #endif + + if (Nx <= 0) + break; + + /* Resample stuff in input buffer */ + if (factor >= 1) { /* SrcUp() is faster if we can use it */ + Nout = lrsSrcUp(hp->X, hp->Y, factor, &hp->Time, Nx, + Nwing, LpScl, Imp, ImpD, interpFilt); + } + else { + Nout = lrsSrcUD(hp->X, hp->Y, factor, &hp->Time, Nx, + Nwing, LpScl, Imp, ImpD, interpFilt); + } + + #ifdef DEBUG + printf("Nout: %d\n", Nout); + #endif + + hp->Time -= Nx; /* Move converter Nx samples back in time */ + hp->Xp += Nx; /* Advance by number of samples processed */ + + /* Calc time accumulation in Time */ + Ncreep = (int)(hp->Time) - hp->Xoff; + if (Ncreep) { + hp->Time -= Ncreep; /* Remove time accumulation */ + hp->Xp += Ncreep; /* and add it to read pointer */ + } + + /* Copy part of input signal that must be re-used */ + Nreuse = hp->Xread - (hp->Xp - hp->Xoff); + + for (i=0; iX[i] = hp->X[i + (hp->Xp - hp->Xoff)]; + + #ifdef DEBUG + printf("New Xread=%d\n", Nreuse); + #endif + + hp->Xread = Nreuse; /* Pos in input buff to read new data into */ + hp->Xp = hp->Xoff; + + /* Check to see if output buff overflowed (shouldn't happen!) */ + if (Nout > hp->YSize) { + #ifdef DEBUG + printf("Nout: %d YSize: %d\n", Nout, hp->YSize); + #endif + fprintf(stderr, "libresample: Output array overflow!\n"); + return -1; + } + + hp->Yp = Nout; + + /* Copy as many samples as possible to the output buffer */ + if (hp->Yp && (outBufferLen-outSampleCount)>0) { + len = MIN(outBufferLen-outSampleCount, hp->Yp); + for(i=0; iY[i]; + outSampleCount += len; + for(i=0; iYp-len; i++) + hp->Y[i] = hp->Y[i+len]; + hp->Yp -= len; + } + + /* If there are still output samples left, return now, + since we need the full output buffer available */ + if (hp->Yp) + break; + } + + return outSampleCount; +} + +void resample_close(void *handle) +{ + rsdata *hp = (rsdata *)handle; + free(hp->X); + free(hp->Y); + free(hp->Imp); + free(hp->ImpD); + free(hp); +} + diff --git a/libmusly/libresample/resample_defs.h b/libmusly/libresample/resample_defs.h new file mode 100644 index 0000000..576c1bc --- /dev/null +++ b/libmusly/libresample/resample_defs.h @@ -0,0 +1,86 @@ +/********************************************************************** + + resample_defs.h + + Real-time library interface by Dominic Mazzoni + + Based on resample-1.7: + http://www-ccrma.stanford.edu/~jos/resample/ + + License: LGPL - see the file LICENSE.txt for more information + +**********************************************************************/ + +#ifndef __RESAMPLE_DEFS__ +#define __RESAMPLE_DEFS__ + +#if !defined(WIN32) && !defined(__CYGWIN__) +#include "config.h" +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef PI +#define PI (3.14159265358979232846) +#endif + +#ifndef PI2 +#define PI2 (6.28318530717958465692) +#endif + +#define D2R (0.01745329348) /* (2*pi)/360 */ +#define R2D (57.29577951) /* 360/(2*pi) */ + +#ifndef MAX +#define MAX(x,y) ((x)>(y) ?(x):(y)) +#endif +#ifndef MIN +#define MIN(x,y) ((x)<(y) ?(x):(y)) +#endif + +#ifndef ABS +#define ABS(x) ((x)<0 ?(-(x)):(x)) +#endif + +#ifndef SGN +#define SGN(x) ((x)<0 ?(-1):((x)==0?(0):(1))) +#endif + +#if HAVE_INTTYPES_H + #include + typedef char BOOL; + typedef int32_t WORD; + typedef uint32_t UWORD; +#else + typedef char BOOL; + typedef int WORD; + typedef unsigned int UWORD; +#endif + +#ifdef DEBUG +#define INLINE +#else +#define INLINE inline +#endif + +/* Accuracy */ + +#define Npc 4096 + +/* Function prototypes */ + +int lrsSrcUp(float X[], float Y[], double factor, double *Time, + UWORD Nx, UWORD Nwing, float LpScl, + float Imp[], float ImpD[], BOOL Interp); + +int lrsSrcUD(float X[], float Y[], double factor, double *Time, + UWORD Nx, UWORD Nwing, float LpScl, + float Imp[], float ImpD[], BOOL Interp); + +#endif diff --git a/libmusly/libresample/resamplesubs.c b/libmusly/libresample/resamplesubs.c new file mode 100644 index 0000000..c3c095d --- /dev/null +++ b/libmusly/libresample/resamplesubs.c @@ -0,0 +1,123 @@ +/********************************************************************** + + resamplesubs.c + + Real-time library interface by Dominic Mazzoni + + Based on resample-1.7: + http://www-ccrma.stanford.edu/~jos/resample/ + + License: LGPL - see the file LICENSE.txt for more information + + This file provides the routines that do sample-rate conversion + on small arrays, calling routines from filterkit. + +**********************************************************************/ + +/* Definitions */ +#include "resample_defs.h" + +#include "filterkit.h" + +#include +#include +#include +#include + +/* Sampling rate up-conversion only subroutine; + * Slightly faster than down-conversion; + */ +int lrsSrcUp(float X[], + float Y[], + double factor, + double *TimePtr, + UWORD Nx, + UWORD Nwing, + float LpScl, + float Imp[], + float ImpD[], + BOOL Interp) +{ + float *Xp, *Ystart; + float v; + + double CurrentTime = *TimePtr; + double dt; /* Step through input signal */ + double endTime; /* When Time reaches EndTime, return to user */ + + dt = 1.0/factor; /* Output sampling period */ + + Ystart = Y; + endTime = CurrentTime + Nx; + while (CurrentTime < endTime) + { + double LeftPhase = CurrentTime-floor(CurrentTime); + double RightPhase = 1.0 - LeftPhase; + + Xp = &X[(int)CurrentTime]; /* Ptr to current input sample */ + /* Perform left-wing inner product */ + v = lrsFilterUp(Imp, ImpD, Nwing, Interp, Xp, + LeftPhase, -1); + /* Perform right-wing inner product */ + v += lrsFilterUp(Imp, ImpD, Nwing, Interp, Xp+1, + RightPhase, 1); + + v *= LpScl; /* Normalize for unity filter gain */ + + *Y++ = v; /* Deposit output */ + CurrentTime += dt; /* Move to next sample by time increment */ + } + + *TimePtr = CurrentTime; + return (Y - Ystart); /* Return the number of output samples */ +} + +/* Sampling rate conversion subroutine */ + +int lrsSrcUD(float X[], + float Y[], + double factor, + double *TimePtr, + UWORD Nx, + UWORD Nwing, + float LpScl, + float Imp[], + float ImpD[], + BOOL Interp) +{ + float *Xp, *Ystart; + float v; + + double CurrentTime = (*TimePtr); + double dh; /* Step through filter impulse response */ + double dt; /* Step through input signal */ + double endTime; /* When Time reaches EndTime, return to user */ + + dt = 1.0/factor; /* Output sampling period */ + + dh = MIN(Npc, factor*Npc); /* Filter sampling period */ + + Ystart = Y; + endTime = CurrentTime + Nx; + while (CurrentTime < endTime) + { + double LeftPhase = CurrentTime-floor(CurrentTime); + double RightPhase = 1.0 - LeftPhase; + + Xp = &X[(int)CurrentTime]; /* Ptr to current input sample */ + /* Perform left-wing inner product */ + v = lrsFilterUD(Imp, ImpD, Nwing, Interp, Xp, + LeftPhase, -1, dh); + /* Perform right-wing inner product */ + v += lrsFilterUD(Imp, ImpD, Nwing, Interp, Xp+1, + RightPhase, 1, dh); + + v *= LpScl; /* Normalize for unity filter gain */ + *Y++ = v; /* Deposit output */ + + CurrentTime += dt; /* Move to next sample by time increment */ + } + + *TimePtr = CurrentTime; + return (Y - Ystart); /* Return the number of output samples */ +} diff --git a/libmusly/melspectrum.cpp b/libmusly/melspectrum.cpp new file mode 100644 index 0000000..beea402 --- /dev/null +++ b/libmusly/melspectrum.cpp @@ -0,0 +1,98 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "minilog.h" +#include "melspectrum.h" + +namespace musly { + + +melspectrum::melspectrum( + int powerspectrum_bins, + int mel_bins, + int sample_rate) : + filterbank(mel_bins, powerspectrum_bins) +{ + // our mel filters start at a minimum frequency of 20hz + float min_freq = 20; + + // determine the frequency of each powerspectrum bin + Eigen::VectorXf ps_freq = Eigen::VectorXf::LinSpaced(powerspectrum_bins, + 0.0f, sample_rate/2.0f); + + + // determine the best mel bin for each frequency + Eigen::VectorXf freq = Eigen::VectorXf::LinSpaced(sample_rate/2-min_freq, + min_freq, sample_rate/2); + Eigen::VectorXf mel = ((freq/700.0f).array() + 1.0f).log() * 1127.01048f; + Eigen::VectorXf mel_idx = Eigen::VectorXf::LinSpaced(mel_bins+2, + 1.0f, mel.maxCoeff()); + + // construct the triangular filters + Eigen::VectorXf left(mel_bins); + Eigen::VectorXf center(mel_bins); + Eigen::VectorXf right(mel_bins); + Eigen::VectorXf::Index min_idx; + for (int i = 0; i < mel_bins; i++) { + ((mel.array() - mel_idx(i)).abs()).minCoeff(&min_idx); + left(i) = freq(min_idx); + + ((mel.array() - mel_idx(i+1)).abs()).minCoeff(&min_idx); + center(i) = freq(min_idx); + + ((mel.array() - mel_idx(i+2)).abs()).minCoeff(&min_idx); + right(i) = freq(min_idx); + } + Eigen::VectorXf heights = 2.0f / (right.array() - left.array()); + + // construct filterbank + for (int i = 0; i < mel_bins; i++) { + for (int j = 0; j < powerspectrum_bins; j++) { + if ((ps_freq(j) > left(i)) && (ps_freq(j) <= center(i))) { + float weight = heights(i) * + ((ps_freq(j) - left(i)) / (center(i) - left(i))); + filterbank.insert(i, j) = weight; + } + + if ((ps_freq(j) > center(i)) && (ps_freq(j) < right(i))) { + float weight = heights(i) * + ((right(i) - ps_freq(j)) / (right(i) - center(i))); + filterbank.insert(i, j) = weight; + } + } + } + + MINILOG(logTRACE) << "Mel filterbank: " << filterbank; +} + +melspectrum::~melspectrum() +{ +} + +Eigen::MatrixXf +melspectrum::from_powerspectrum(const Eigen::MatrixXf& ps) +{ + MINILOG(logTRACE) << "Mel filtering specturm. size=" << ps.rows() + << "x" << ps.cols(); + + // iterate over each frame and apply the triangular mel filters + Eigen::MatrixXf mels(filterbank.rows(), ps.cols()); + for (int i = 0; i < ps.cols(); i++) { + mels.col(i) = filterbank * ps.col(i); + } + + MINILOG(logTRACE) << "Mel specturm computed. size=" << mels.rows() + << "x" << mels.cols(); + return mels; +} + + +} /* namespace musly */ diff --git a/libmusly/melspectrum.h b/libmusly/melspectrum.h new file mode 100644 index 0000000..f3b70e5 --- /dev/null +++ b/libmusly/melspectrum.h @@ -0,0 +1,54 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_MELSPECTRUM_H_ +#define MUSLY_MELSPECTRUM_H_ + +#include +#include +#include + +namespace musly { + +class melspectrum { +private: + /** Stores the triangular filterbank for each mel bin. + */ + Eigen::SparseMatrix filterbank; + +public: + /** Initializes the Mel filterbanks. The Mel filterbanks are computed using + * the sample rate and number of bins in the powerspectum. + * \param powerspectrum_bins The number of input powerspectrum bins. + * \param mel_bins The number of mel filters or bins to compute from the + * powerspectrum. + * \param sample_rate The original sample rate of the PCM signal. + */ + melspectrum( + int powerspectrum_bins, + int mel_bins, + int sample_rate); + + /** Currently empty destructor + */ + virtual ~melspectrum(); + + /** Computes the Mel spectrum from the given powerspectrum. The triangular + * filterbank is precomputed in the constructor. + * \param ps The powerspectrum as a matrix (frequency, time). + * \returns The Mel spectrum as a matrix (frequency, time). Column major. + */ + Eigen::MatrixXf from_powerspectrum( + const Eigen::MatrixXf& ps); +}; + +} /* namespace musly */ +#endif /* MUSLY_MELSPECTRUM_H_ */ diff --git a/libmusly/method.cpp b/libmusly/method.cpp new file mode 100644 index 0000000..a6098e0 --- /dev/null +++ b/libmusly/method.cpp @@ -0,0 +1,109 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include "method.h" + +namespace musly { + +method::method() : + track_size(0), + current_tid(0) +{ +} + +method::~method() +{ +} + + +int +method::track_addfield_floats( + const std::string& name, + int num_floats) +{ + // save the field name and field size + track_field_name.push_back(name); + track_field_size.push_back(num_floats); + + // compute the starting offset for the feature + int offs = track_size; + + // update the musly_track size + track_size += num_floats; + + return offs; +} + +int +method::track_getsize() +{ + return track_size; +} + +musly_track* +method::track_alloc() +{ + return new musly_track[track_size]; +} + +const char* +method::track_tostr( + musly_track* track) +{ + // TODO: Use and reuse a string buffer + trackstr = ""; + int offs = 0; + int buffer_size = 256; + char buffer[buffer_size]; + for (int i = 0; i < (int)track_field_name.size(); i++) { + trackstr += track_field_name[i] + ":"; + for (int j = 0; j < (int)track_field_size[i]; j++) { + snprintf(buffer, buffer_size-1, " %f", track[offs]); + trackstr += buffer; + offs++; + } + trackstr += "\n"; + } + + return trackstr.c_str(); +} + +musly_trackid +method::add_track( + musly_track* track) +{ + //get next trackid + musly_trackid trackid = current_tid; + current_tid++; + + init_track(track, trackid); + return trackid; +} + +int +method::set_musicstyle( + musly_track** tracks, + int length) +{ + return 0; +} + + +int +method::init_track( + musly_track* track, + musly_trackid trackid) +{ + return 0; +} + +} /* namespace musly */ diff --git a/libmusly/method.h b/libmusly/method.h new file mode 100644 index 0000000..8a2d158 --- /dev/null +++ b/libmusly/method.h @@ -0,0 +1,173 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_METHOD_H_ +#define MUSLY_METHOD_H_ + +#include +#include +#include "plugins.h" +#include "musly/musly_types.h" + +namespace musly { + +class method : + public plugin +{ +private: + /** A list of feature names as initialized with \sa track_addfield_floats(). + */ + std::vector track_field_name; + + /** A list of feature sizes as initialized with \sa track_addfield_floats(). + */ + std::vector track_field_size; + + /** The number of elements of a musly_track float array. + */ + int track_size; + + /** Holds tracks serialized to a string + */ + std::string trackstr; + + /** Current trackid + */ + musly_trackid current_tid; + +protected: + /** Add features to the Musly method track model. Each musly::method music + * similarity method needs to store the features for each music track in a + * musly_track structure. The structure is a simple array of floats, + * initially of size 0. To define the structure of your methods features + * and add space for them in a musly_track, use this function. The function + * returns the offset where the currently added features start. + * + * I.e., if you initialized your features with: + * \code + * int zc_offset = track_addfield_floats("zerocrossings", 1); + * \endcode + * you can access the allocated feature with: + * \code + * musly_track* t = ... // allocated, analyzed track + * fload zc = t[zc_offset]; + * \endcode + * + * \param name The name of the features. + * \param num_floats The number of elements (float values) that will be + * used to store the features. + * \returns The offset of the added feature relative to a musly_track. + */ + int + track_addfield_floats( + const std::string& name, + int num_floats); + +public: + method(); + virtual ~method(); + + /** A short description of the implemented music similarity method. Give a + * short description or reference the music similarity method implemented + * by your object. + * + * \returns A null terminated string describing th music similarity method. + */ + virtual const char* + about() = 0; + + /** Return the number of floats in a musly_track in bytes. The is dependent + * on how the music similarity method initialized it with \sa + * track_addfield_floats(). + * + * \returns the number of elements of a musly_track. + */ + int + track_getsize(); + + /** Allocate a musly_track. + */ + musly_track* + track_alloc(); + + /** + * + */ + virtual const char* + track_tostr( + musly_track* track); + + /** + * + */ + virtual int + analyze_track( + float* pcm, + int length, + musly_track* track) = 0; + + /** + * + */ + virtual int + similarity( + musly_track* track, + musly_trackid seed_trackid, + musly_track** tracks, + musly_trackid* trackids, + int length, + float* similarities) = 0; + + /** + * + */ + virtual int + set_musicstyle( + musly_track** tracks, + int length); + + /** + * + */ + musly_trackid + add_track( + musly_track* track); + + /** + * + */ + virtual int + init_track( + musly_track* track, + musly_trackid trackid); + +}; + +/** A macro to facilitating registering a method class with musly. This macro + * has to be used in the header and class declaration. Call it with the class + * name as parameter. + */ +#define MUSLY_METHOD_REGCLASS(classname) \ +private: \ + static const plugin_creator_impl creator; + +/** A macro to facilitate registering a method class with musly. This macro has + * to be used in the source file, it has two parameters. Call it with the name + * of your class and the priority. The priority value is used if the user + * does not request a special musly::method when calling \sa + * musly_jukebox_poweron(). The method with the lowest priority value is used. + */ +#define MUSLY_METHOD_REGIMPL(classname, priority) \ + const plugin_creator_impl classname::creator(#classname, \ + plugins::METHOD_TYPE, priority); + +} /* namespace musly */ +#endif /* MUSLY_METHOD_H_ */ diff --git a/libmusly/methods/mandelellis.cpp b/libmusly/methods/mandelellis.cpp new file mode 100644 index 0000000..a443f38 --- /dev/null +++ b/libmusly/methods/mandelellis.cpp @@ -0,0 +1,158 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include "minilog.h" +#include "windowfunction.h" +#include "mandelellis.h" + + +namespace musly { +namespace methods { + +/** Register mandelellis with musly with a low priority (0) + */ +MUSLY_METHOD_REGIMPL(mandelellis, 0); + +mandelellis::mandelellis() : + + // initialize method configuration parameters + sample_rate(22050), + window_size(1024), + hop(0.5f), + max_pcmlength(60*sample_rate), + ps_bins(window_size/2+1), + mel_bins(36), + mfcc_bins(20), + + // spectra and filters + ps(windowfunction::hann(window_size), hop), + mel(ps_bins, mel_bins, sample_rate), + mfccs(mel_bins, mfcc_bins), + gs(mfcc_bins) +{ + // Configure the musly_track features and save the musly_track offsets + + // the feature mean + track_mu = track_addfield_floats("gaussian.mu", gs.get_dim()); + // add the covariance (symmetric matrix) + track_covar = track_addfield_floats("gaussian.covar", gs.get_covarelems()); + // add the covariance (symmetric matrix) + track_covar_inverse = track_addfield_floats("gaussian.covar_inverse", + gs.get_covarelems()); +} + +mandelellis::~mandelellis() +{ +} + +const char* +mandelellis::about() +{ + return + "A basic music similarity measure implementing \n" + "M. Mandel and D. Ellis in: Song-level features and support vector\n" + "machines for music classification. In the proceedings of the 6th\n" + "International Conference on Music Information Retrieval,\n" + "ISMIR, 2005.\n" + "MUSLY computes a single Gaussian representation from the songs\n" + "The similarity between two tracks represented as Gaussians\n" + "is computed with the symmetrized Kullback-Leibler divergence"; +} + +int +mandelellis::analyze_track( + float* pcm, + int length, + musly_track* track) +{ + MINILOG(logTRACE) << "ME analysis started. samples=" << length; + + // select the central max_pcmlength (usually 30s) of the piece + int start = 0; + if (length > max_pcmlength) { + start = (length - max_pcmlength) / 2; + length = max_pcmlength; + } + + // PCM --> powerspectrum + Eigen::Map pcm_vector(pcm+start, length); + Eigen::MatrixXf power_spectrum = ps.from_pcm(pcm_vector); + + // powerspectrum -> Mel + Eigen::MatrixXf mel_spectrum = mel.from_powerspectrum(power_spectrum); + + // Mel -> MFCC representation + Eigen::MatrixXf mfcc_representation = + mfccs.from_melspectrum(mel_spectrum); + + // estimate the Gaussian from the MFCC representation + gaussian g = {0, 0, 0, 0}; + g.mu = &track[track_mu]; + g.covar = &track[track_covar]; + g.covar_inverse = &track[track_covar_inverse]; + if (gs.estimate_gaussian(mfcc_representation, g) == false) { + MINILOG(logTRACE) << "ME Gaussian model estimation failed."; + return 2; + } + + MINILOG(logTRACE) << "ME analysis finished!"; + + return 0; +} + + +int +mandelellis::similarity( + musly_track* track, + musly_trackid seed_trackid, + musly_track** tracks, + musly_trackid* trackids, + int length, + float* similarities) +{ + if ((length <= 0) || !track || ! tracks || !similarities) { + return -1; + } + + // map seed track to gaussian structure + gaussian g0; + g0.mu = &track[track_mu]; + g0.covar = &track[track_covar]; + g0.covar_inverse = &track[track_covar_inverse]; + + // create the temporary buffer required for the Kullback-Leibler divergence + musly_track* tmp_t = track_alloc(); + gaussian tmp; + tmp.mu = &tmp_t[track_mu]; + tmp.covar = &tmp_t[track_covar]; + tmp.covar_inverse = &tmp_t[track_covar_inverse]; + + // iterate over all musly_tracks to compute the Kullback-Leibler divergence + for (int i = 0; i < length; i++) { + gaussian gi; + musly_track* track1 = tracks[i]; + gi.mu = &track1[track_mu]; + gi.covar = &track1[track_covar]; + gi.covar_inverse = &track1[track_covar_inverse]; + + similarities[i] = gs.symmetric_kullbackleibler(g0, gi, tmp); + } + + delete[] tmp_t; + + return 0; +} + + +} /* namespace methods */ +} /* namespace musly */ diff --git a/libmusly/methods/mandelellis.h b/libmusly/methods/mandelellis.h new file mode 100644 index 0000000..1604e40 --- /dev/null +++ b/libmusly/methods/mandelellis.h @@ -0,0 +1,85 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_METHODS_MANDELELLIS_H_ +#define MUSLY_METHODS_MANDELELLIS_H_ + +#include "method.h" +#include "powerspectrum.h" +#include "melspectrum.h" +#include "mfcc.h" +#include "gaussianstatistics.h" +#include "mutualproximity.h" + +namespace musly { +namespace methods { + +class mandelellis : + public musly::method + +{ +MUSLY_METHOD_REGCLASS(mandelellis); + +private: + + const int sample_rate; + const int window_size; + const float hop; + const int max_pcmlength; + const int ps_bins; + const int mel_bins; + const int mfcc_bins; + + int track_mu; + int track_covar; + int track_covar_inverse; + + powerspectrum ps; + melspectrum mel; + mfcc mfccs; + gaussian_statistics gs; + + void + similarity_raw( + musly_track* track, + musly_track** tracks, + int length, + float* similarities); + +public: + mandelellis(); + + virtual + ~mandelellis(); + + virtual const char* + about(); + + virtual int + analyze_track( + float* pcm, + int length, + musly_track* track); + + virtual int + similarity( + musly_track* track, + musly_trackid seed_trackid, + musly_track** tracks, + musly_trackid* trackids, + int length, + float* similarities); + +}; + +} /* namespace methods */ +} /* namespace musly */ +#endif /* MUSLY_METHODS_MANDELELLIS_H_ */ diff --git a/libmusly/methods/timbre.cpp b/libmusly/methods/timbre.cpp new file mode 100644 index 0000000..d7b7e2c --- /dev/null +++ b/libmusly/methods/timbre.cpp @@ -0,0 +1,207 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include "minilog.h" +#include "windowfunction.h" +#include "timbre.h" + + +namespace musly { +namespace methods { + +/** Register timbre with musly with piority (1) + */ +MUSLY_METHOD_REGIMPL(timbre, 1); + + + +timbre::timbre() : + + // initialize method configuration parameters + sample_rate(22050), + window_size(1024), + hop(0.5f), + max_pcmlength(60*sample_rate), + ps_bins(window_size/2+1), + mel_bins(36), + mfcc_bins(25), + + // spectra and filters + ps(windowfunction::hann(window_size), hop), + mel(ps_bins, mel_bins, sample_rate), + mfccs(mel_bins, mfcc_bins), + gs(mfcc_bins), + mp(this) +{ + // Configure the musly_track features and save the musly_track offsets + + // the feature mean + track_mu = track_addfield_floats("gaussian.mu", gs.get_dim()); + // add the covariance (symmetric matrix) + track_covar = track_addfield_floats("gaussian.covar", gs.get_covarelems()); + // add the log(det(covar)) of the covariance for performance reasons + track_logdet = track_addfield_floats("gaussian.covar_logdet", 1); +} + +timbre::~timbre() +{ +} + +const char* +timbre::about() +{ + return + "A basic music similarity measure based on the the one proposed by\n" + "M. Mandel and D. Ellis in: Song-level features and support vector\n" + "machines for music classification. In the proceedings of the 6th\n" + "International Conference on Music Information Retrieval,\n" + "ISMIR, 2005.\n" + "MUSLY computes a single Gaussian representation from the songs\n" + "It uses 25 MFCCs. The similarity between two tracks which are\n" + "represented as Gaussians, is computed with the Jensen-Shannon\n" + "divergence. Similarities are normalized with Mutual Proximity\n" + "(D. Schnitzer et al.: Using mutual proximity to improve\n" + "content-based audio similarity. In the proceedings of the 12th\n" + "International Society for Music Information Retrieval\n" + "Conference, ISMIR, 2011)."; +} + +int +timbre::analyze_track( + float* pcm, + int length, + musly_track* track) +{ + MINILOG(logTRACE) << "T analysis started. samples=" << length; + + // select the central max_pcmlength (usually 30s) of the piece + int start = 0; + if (length > max_pcmlength) { + start = (length - max_pcmlength) / 2; + length = max_pcmlength; + } + + // PCM --> powerspectrum + Eigen::Map pcm_vector(pcm+start, length); + Eigen::MatrixXf power_spectrum = ps.from_pcm(pcm_vector); + + // powerspectrum -> Mel + Eigen::MatrixXf mel_spectrum = mel.from_powerspectrum(power_spectrum); + + // Mel -> MFCC representation + Eigen::MatrixXf mfcc_representation = + mfccs.from_melspectrum(mel_spectrum); + + // estimate the Gaussian from the MFCC representation + gaussian g = {0, 0, 0, 0}; + g.mu = &track[track_mu]; + g.covar = &track[track_covar]; + g.covar_logdet = &track[track_logdet]; + if (gs.estimate_gaussian(mfcc_representation, g) == false) { + MINILOG(logTRACE) << "T Gaussian model estimation failed."; + return 2; + } + + MINILOG(logTRACE) << "T analysis finished!"; + + return 0; +} + + +void +timbre::similarity_raw( + musly_track* track, + musly_track** tracks, + int length, + float* similarities) +{ + // map seed track to gaussian structure + gaussian g0; + g0.mu = &track[track_mu]; + g0.covar = &track[track_covar]; + g0.covar_logdet = &track[track_logdet]; + + // create the temporary buffer required for the Jensen-Shannon divergence + musly_track* tmp_t = track_alloc(); + gaussian tmp; + tmp.mu = &tmp_t[track_mu]; + tmp.covar = &tmp_t[track_covar]; + tmp.covar_logdet = &tmp_t[track_logdet]; + + // iterate over all musly_tracks to compute the Jensen-Shannon divergence + for (int i = 0; i < length; i++) { + gaussian gi; + musly_track* track1 = tracks[i]; + gi.mu = &track1[track_mu]; + gi.covar = &track1[track_covar]; + gi.covar_logdet = &track1[track_logdet]; + + similarities[i] = gs.jensenshannon(g0, gi, tmp); + } + + delete[] tmp_t; +} + + + +int +timbre::similarity( + musly_track* track, + musly_trackid seed_trackid, + musly_track** tracks, + musly_trackid* trackids, + int length, + float* similarities) +{ + if ((length <= 0) || !track || ! tracks || !similarities) { + return -1; + } + + // compute raw similarities + similarity_raw(track, tracks, length, similarities); + + // normalize with mp + mp.normalize(seed_trackid, trackids, length, similarities); + + return 0; +} + +int +timbre::set_musicstyle( + musly_track** tracks, + int length) +{ + MINILOG(logTRACE) << "T initializing mutual proximity!"; + + // save the mp normalization tracks + return mp.set_normtracks(tracks, length); +} + +int +timbre::init_track( + musly_track* track, + musly_trackid trackid) +{ + Eigen::VectorXf sim(mp.get_normtracks()->size()); + + similarity_raw(track, mp.get_normtracks()->data(), + mp.get_normtracks()->size(), sim.data()); + + mp.set_normfacts(trackid, sim); + + return 0; +} + + +} /* namespace methods */ +} /* namespace musly */ diff --git a/libmusly/methods/timbre.h b/libmusly/methods/timbre.h new file mode 100644 index 0000000..9852a5e --- /dev/null +++ b/libmusly/methods/timbre.h @@ -0,0 +1,95 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_METHODS_TIMBRE_H_ +#define MUSLY_METHODS_TIMBRE_H_ + +#include "method.h" +#include "powerspectrum.h" +#include "melspectrum.h" +#include "mfcc.h" +#include "gaussianstatistics.h" +#include "mutualproximity.h" + +namespace musly { +namespace methods { + +class timbre : + public musly::method + +{ +MUSLY_METHOD_REGCLASS(timbre); + +private: + + const int sample_rate; + const int window_size; + const float hop; + const int max_pcmlength; + const int ps_bins; + const int mel_bins; + const int mfcc_bins; + + int track_mu; + int track_covar; + int track_logdet; + + powerspectrum ps; + melspectrum mel; + mfcc mfccs; + gaussian_statistics gs; + mutualproximity mp; + + void + similarity_raw( + musly_track* track, + musly_track** tracks, + int length, + float* similarities); + +public: + timbre(); + + virtual + ~timbre(); + + virtual const char* + about(); + + virtual int + analyze_track( + float* pcm, + int length, + musly_track* track); + + virtual int + similarity( + musly_track* track, + musly_trackid seed_trackid, + musly_track** tracks, + musly_trackid* trackids, + int length, + float* similarities); + + virtual int + set_musicstyle( + musly_track** tracks, + int length); + + virtual int + init_track( + musly_track* track, + musly_trackid trackid); +}; + +} /* namespace methods */ +} /* namespace musly */ +#endif /* MUSLY_METHODS_TIMBRE_H_ */ diff --git a/libmusly/mfcc.cpp b/libmusly/mfcc.cpp new file mode 100644 index 0000000..72f3569 --- /dev/null +++ b/libmusly/mfcc.cpp @@ -0,0 +1,33 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "minilog.h" +#include "mfcc.h" + +namespace musly { + +mfcc::mfcc(int mel_bins, int mfcc_bins) : + dct(mel_bins, mfcc_bins) +{ +} + +Eigen::MatrixXf mfcc::from_melspectrum(const Eigen::MatrixXf& mel) +{ + MINILOG(logTRACE) << "Computing MFCCs."; + + Eigen::MatrixXf mfcc_coeffs = dct.compress((1.0f + mel.array()).log()); + MINILOG(logTRACE) << "MFCCS: " << mfcc_coeffs; + + MINILOG(logTRACE) << "Finished Computing MFCCs."; + return mfcc_coeffs; +} + +} /* namespace musly */ diff --git a/libmusly/mfcc.h b/libmusly/mfcc.h new file mode 100644 index 0000000..099d5f8 --- /dev/null +++ b/libmusly/mfcc.h @@ -0,0 +1,45 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_MFCC_H_ +#define MUSLY_MFCC_H_ + +#include +#include "discretecosinetransform.h" + +namespace musly { + +/** Compute the Mel Frequency Cepstrum Coefficients (MFCC) from a given + * MEL spectrum. + */ +class mfcc { +private: + /** A DCT-II filter for the compression of the spectrum. + */ + discretecosinetransform dct; + +public: + /** Preinitialize the MFCC class by specifying the number of input MEL + * bins and output MFCC bins. + * \param mel_bins The input MEL bins. + * \param mfcc_bins The number of MFCC bins to compute from the mel_bins. + */ + mfcc(int mel_bins, int mfcc_bins); + + /** Compute the MFCCs from a given MEL spectrum. + * \param mel The MEL spectrum computed with melspecturm + * \returns The DCT compressed MFCC representation of the input specturm. + */ + Eigen::MatrixXf from_melspectrum(const Eigen::MatrixXf& mel); +}; + +} /* namespace musly */ +#endif /* MUSLY_MFCC_H_ */ diff --git a/libmusly/mutualproximity.cpp b/libmusly/mutualproximity.cpp new file mode 100644 index 0000000..ac67411 --- /dev/null +++ b/libmusly/mutualproximity.cpp @@ -0,0 +1,147 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include "musly/musly_types.h" +#include "mutualproximity.h" + +namespace musly { + +mutualproximity::mutualproximity(method* m) : + m(m) +{ +} + +mutualproximity::~mutualproximity() +{ + // clear cache + new_cache(0); +} + +void +mutualproximity::new_cache(int size) +{ + for (int i = 0; i < (int)norm_tracks.size(); i++) { + delete[] norm_tracks[i]; + } + + norm_tracks.clear(); + for (int i = 0; i < size; i++) { + norm_tracks.push_back(m->track_alloc()); + } +} + +int +mutualproximity::set_normtracks( + musly_track** tracks, + int length) +{ + new_cache(length); + + int track_size = m->track_getsize(); + for (int i = 0; i < length; i++) { + std::copy(tracks[i], tracks[i]+track_size, norm_tracks[i]); + } + + return 0; +} + +std::vector* +mutualproximity::get_normtracks() +{ + return &norm_tracks; +} + +void +mutualproximity::set_normfacts( + musly_trackid trackid, + Eigen::VectorXf& sim) +{ + float mu = sim.mean(); + Eigen::VectorXf sim_mu = sim.array() - mu; + float std = (sim_mu.transpose() * sim_mu); + std /= (static_cast(sim.size()) - 1.0f); + + // allocate space + if (trackid >= (int)norm_facts.size()) { + norm_facts.resize(trackid+1); + norm_facts[trackid].mu = mu; + norm_facts[trackid].std = std; + } +} + +double +mutualproximity::normcdf(double x) +{ + // constants + const double a1 = 0.254829592; + const double a2 = -0.284496736; + const double a3 = 1.421413741; + const double a4 = -1.453152027; + const double a5 = 1.061405429; + const double p = 0.3275911; + + // Save the sign of x + int sign = 1; + if (x < 0) { + sign = -1; + } + x = fabs(x)/M_SQRT2; + + // A&S formula 7.1.26 + double t = 1.0/(1.0 + p*x); + double y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x); + + return 0.5*(1.0 + sign*y); +} + +int +mutualproximity::normalize( + musly_trackid seed_trackid, + musly_trackid* trackids, + int length, + float* sim) +{ + if (seed_trackid >= (int)norm_facts.size()) { + return -1; + } + float seed_mu = norm_facts[seed_trackid].mu; + float seed_std = norm_facts[seed_trackid].std; + for (int i = 0; i < length; i++) { + int tid = trackids[i]; + if (tid >= (int)norm_facts.size()) { + return -1; + } + if (tid == seed_trackid) { + sim[i] = 0; + continue; + } + + float d = sim[i]; + if (isnan(d)) { + continue; + } + + sim[i] = 0.5*((d - seed_mu)/seed_std + + (d - norm_facts[tid].mu)/norm_facts[tid].std); +/* + double p1 = 1 - normcdf((d - seed_mu)/seed_std); + double p2 = 1 - normcdf((d - norm_facts[tid].mu)/norm_facts[tid].std); + sim[i] = 1 - p1*p2; + */ + } + return 0; +} + + + +} /* namespace musly */ diff --git a/libmusly/mutualproximity.h b/libmusly/mutualproximity.h new file mode 100644 index 0000000..b915278 --- /dev/null +++ b/libmusly/mutualproximity.h @@ -0,0 +1,67 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_MUTUALPROXIMITY_H_ +#define MUSLY_MUTUALPROXIMITY_H_ + +#include +#include "musly/musly_types.h" +#include "method.h" + +namespace musly { + +class mutualproximity { +public: + mutualproximity(method* m); + virtual ~mutualproximity(); + + virtual int + set_normtracks( + musly_track** tracks, + int length); + + std::vector* + get_normtracks(); + + void + set_normfacts( + musly_trackid trackid, + Eigen::VectorXf& sim); + + int + normalize( + musly_trackid seed_trackid, + musly_trackid* trackids, + int length, + float* sim); + +private: + method* m; + std::vector norm_tracks; + struct normfact { + float mu; + float std; + }; + std::vector norm_facts; + + + void + new_cache( + int size); + + double + normcdf( + double x); + +}; + +} /* namespace musly */ +#endif /* MUSLY_MUTUALPROXIMITY_H_ */ diff --git a/libmusly/plugins.cpp b/libmusly/plugins.cpp new file mode 100644 index 0000000..2771140 --- /dev/null +++ b/libmusly/plugins.cpp @@ -0,0 +1,118 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include + +#include "plugins.h" + +namespace musly { + +const int plugins::METHOD_TYPE = 0; +const int plugins::DECODER_TYPE = 1; + + +plugin* +plugins::instantiate_plugin( + int type, + std::string& classname) +{ + std::map::iterator i; + + if (classname.length() > 0) { + i = get_plugin_table().find(classname); + if (i != get_plugin_table().end()) { + if (i->second->get_type() == type) { + plugin* pl = i->second->create(); + return pl; + } + } + } else { + + // search for the default plugin, i.e. the highest priority. + i = get_plugin_table().begin(); + int p = INT_MIN; + plugin_creator* pc = NULL; + std::string name; + while (i != get_plugin_table().end()) { + if (i->second->get_type() == type) { + int cur_p = i->second->get_priority(); + if (cur_p > p) { + p = cur_p; + pc = i->second; + name = i->first; + } + } + i++; + } + + // return the plugin with the highest priority + if (pc) { + plugin* pl = pc->create(); + classname = name; + return pl; + } + } + + return NULL; +} + +void +plugins::register_plugin( + const std::string& classname, + plugin_creator* c) +{ + get_plugin_table()[classname] = c; + +} + +const std::string& +plugins::get_plugins( + int type) +{ + std::map p = get_plugin_table(); + std::map::iterator i = p.begin(); + + static std::string pn; + pn = ""; + + int added = 0; + while (i != p.end()) { + if (i->second->get_type() == type) { + if (added != 0) { + pn.append(","); + } + pn.append(i->first); + added++; + } + i++; + } + + return pn; + +} + +std::map& +plugins::get_plugin_table() +{ + static std::map table; + return table; +} + +plugin_creator::plugin_creator(const std::string& classname) +{ + plugins::register_plugin(classname, this); +} + + + +} /* namespace musly */ diff --git a/libmusly/plugins.h b/libmusly/plugins.h new file mode 100644 index 0000000..6ac108b --- /dev/null +++ b/libmusly/plugins.h @@ -0,0 +1,86 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_PLUGINS_H_ +#define MUSLY_PLUGINS_H_ + +#include +#include + +namespace musly { + +class plugin { +}; + +class plugin_creator +{ +public: + plugin_creator( + const std::string& classname); + + virtual ~plugin_creator() { }; + + virtual int get_type() = 0; + virtual int get_priority() = 0; + virtual plugin* create() = 0; +}; + +template +class plugin_creator_impl : public plugin_creator +{ +private: + int type; + int priority; + +public: + plugin_creator_impl( + const std::string& classname, + int type, + int priority) : + plugin_creator(classname), + type(type), + priority(priority) { }; + + virtual int get_type() { + return type; + } + virtual int get_priority() { + return priority; + } + virtual plugin* create() { return new T; }; +}; + +class plugins +{ +public: + static plugin* + instantiate_plugin( + int type, + std::string& classname); + + static void + register_plugin( + const std::string& classname, + plugin_creator* c); + + static const std::string& + get_plugins(int type); + + static const int METHOD_TYPE; + static const int DECODER_TYPE; + +private: + static std::map& + get_plugin_table(); +}; + +} /* namespace musly */ +#endif /* MUSLY_PLUGINS_H_ */ diff --git a/libmusly/powerspectrum.cpp b/libmusly/powerspectrum.cpp new file mode 100644 index 0000000..f9ce9d0 --- /dev/null +++ b/libmusly/powerspectrum.cpp @@ -0,0 +1,87 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "minilog.h" +#include "powerspectrum.h" + + +namespace musly { + + +powerspectrum::powerspectrum( + const Eigen::VectorXf& win_funct, + float hop) +{ + this->win_funct = win_funct; + this->win_size = win_funct.size(); + this->hop_size = hop*win_size; + + // initialize kiss fft + kiss_pcm = (kiss_fft_scalar*)malloc(sizeof(kiss_fft_scalar) * win_size); + kiss_freq = (kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx) * (win_size/2 + 1)); + kiss_status = kiss_fftr_alloc(win_size, 0, NULL, NULL); +} + +Eigen::MatrixXf +powerspectrum::from_pcm(const Eigen::VectorXf& pcm_samples) +{ + MINILOG(logTRACE) << "Powerspectrum computation. input samples=" + << pcm_samples.size(); + // check if inputs are sane + if ((pcm_samples.size() < win_size) || (hop_size > win_size)) { + return Eigen::MatrixXf(0, 0); + } + size_t frames = (pcm_samples.size() - (win_size-hop_size)) / hop_size; + size_t freq_bins = win_size/2 + 1; + + // initialize power spectrum + Eigen::MatrixXf ps(freq_bins, frames); + + // peak normalization value + float pcm_scale = std::max(fabs(pcm_samples.minCoeff()), + fabs(pcm_samples.maxCoeff())); + + // scale signal to 96db (16bit) + pcm_scale = std::pow(10.0f, 96.0f/20.0f) / pcm_scale; + + // compute the power spectrum + for (size_t i = 0; i < frames; i++) { + + // fill pcm + for (int j = 0; j < win_size; j++) { + kiss_pcm[j] = pcm_samples(i*hop_size+j) * pcm_scale * win_funct(j); + } + + // fft + kiss_fftr(kiss_status, kiss_pcm, kiss_freq); + + // save powerspectrum frame + Eigen::MatrixXf::ColXpr psc(ps.col(i)); + for (int j = 0; j < win_size/2+1; j++) { + psc(j) = + std::pow(kiss_freq[j].r, 2) + std::pow(kiss_freq[j].i, 2); + } + } + + MINILOG(logTRACE) << "Powerspectrum finished. size=" << ps.rows() << "x" + << ps.cols(); + return ps; +} + +powerspectrum::~powerspectrum() +{ + free(kiss_status); + free(kiss_pcm); + free(kiss_freq); +} + + +} /* namespace musly */ diff --git a/libmusly/powerspectrum.h b/libmusly/powerspectrum.h new file mode 100644 index 0000000..6957db4 --- /dev/null +++ b/libmusly/powerspectrum.h @@ -0,0 +1,78 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_POWERSPECTRUM_H_ +#define MUSLY_POWERSPECTRUM_H_ + +#include +extern "C" { + #include "kissfft/kiss_fftr.h" +} + + +namespace musly { + +class powerspectrum { +private: + /** The hop size in samples. + */ + int hop_size; + + /** The window size to analyze in samples. + */ + int win_size; + + /** The window function, as a vector of scalars. The window function is + * multiplied with the signal before applying the FFT. + */ + Eigen::VectorXf win_funct; + + /** KissFFT internal representation of the PCM data. + */ + kiss_fft_scalar* kiss_pcm; + + /** KissFFT internal of the frequency spectrum. + */ + kiss_fft_cpx* kiss_freq; + + /** KissFFT internal of the FFT status. + */ + kiss_fftr_cfg kiss_status; + +public: + /** Initialize the powerspectrum with the window function and hop size. + * \param win_funct The window function as a vector of scalars. It is + * multipled with the signal before the FFT. The length of the vector + * also specifies the window size. + * \param hop the length of a hop when analyzing a pcm signal relative to + * the size of the window, i.e., a value >0 and <=1 is reasonable. + */ + powerspectrum( + const Eigen::VectorXf& win_funct, + float hop); + + /** Get the powerspectum from the given PCM samples. The spectrum is + * computed with the parameters from the initialization. + * \param pcm_samples A vector of PCM samles. + * \returns The powerspectrum computed from the given PCM samples as + * matrix. The matrix has the dimension (Frequency, Time) and is in + * column major format. + */ + Eigen::MatrixXf from_pcm( + const Eigen::VectorXf& pcm_samples); + + /** Cleanup. Frees the internal KissFFT variables. + */ + virtual ~powerspectrum(); +}; + +} /* namespace musly */ +#endif /* MUSLY_POWERSPECTRUM_H_ */ diff --git a/libmusly/resampler.cpp b/libmusly/resampler.cpp new file mode 100644 index 0000000..48dfed0 --- /dev/null +++ b/libmusly/resampler.cpp @@ -0,0 +1,76 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "resampler.h" + +namespace musly { + +resampler::resampler(int input_rate, int output_rate): + input_rate(input_rate), + output_rate(output_rate), + resample_factor((double)output_rate/(double)input_rate) +{ + libresample = resample_open(1, resample_factor, resample_factor); +} + +resampler::~resampler() +{ + resample_close(libresample); +} + +std::vector resampler::resample( + float* pcm_input, + int pcm_len) +{ + std::vector pcm_out(pcm_len*resample_factor); + + int srclen = 4096; + int dstlen = (srclen*resample_factor + 1000); + float* dst = new float[dstlen]; + + int in_pos = 0; + int out_pos = 0; + + while (in_pos < pcm_len) { + + int block_len = std::min(srclen, pcm_len-in_pos); + int is_last_iteration = (in_pos+block_len == pcm_len); + + int input_read = 0; + int out_written = resample_process(libresample, resample_factor, + pcm_input+in_pos, block_len, is_last_iteration, + &input_read, dst, dstlen); + + for (int i = 0; i < out_written; i++) { + if (dst[i] < -1) { + pcm_out[out_pos + i] = -1; + } else if (dst[i] > 1) { + pcm_out[out_pos + i] = 1; + } else { + pcm_out[out_pos + i] = dst[i]; + } + } + + in_pos += input_read; + out_pos += out_written; + } + + if (out_pos < (int)pcm_out.size()) { + pcm_out.resize(out_pos); + } + + delete[] dst; + + return pcm_out; +} + + +} /* namespace musly */ diff --git a/libmusly/resampler.h b/libmusly/resampler.h new file mode 100644 index 0000000..df8aaa4 --- /dev/null +++ b/libmusly/resampler.h @@ -0,0 +1,38 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_RESAMPLER_H_ +#define MUSLY_RESAMPLER_H_ + +#include +extern "C" { + #include "libresample/libresample.h" +} + +namespace musly { + +class resampler { +private: + int input_rate; + int output_rate; + double resample_factor; + + void* libresample; + +public: + resampler(int input_rate, int output_rate); + virtual ~resampler(); + + std::vector resample(float* pcm_input, int pcm_len); +}; + +} /* namespace musly */ +#endif /* MUSLY_RESAMPLER_H_ */ diff --git a/libmusly/windowfunction.cpp b/libmusly/windowfunction.cpp new file mode 100644 index 0000000..55b6f49 --- /dev/null +++ b/libmusly/windowfunction.cpp @@ -0,0 +1,28 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include "windowfunction.h" + +namespace musly { + +Eigen::VectorXf windowfunction::hann( + int window_size) +{ + int N = window_size - 1; + Eigen::VectorXf n = Eigen::VectorXf::LinSpaced(window_size, 0, N); + Eigen::VectorXf w = 0.5f * (1.0f - (2.0f*M_PI*n/N).array().cos()); + return w; +} + +} /* namespace musly */ diff --git a/libmusly/windowfunction.h b/libmusly/windowfunction.h new file mode 100644 index 0000000..4559f8c --- /dev/null +++ b/libmusly/windowfunction.h @@ -0,0 +1,31 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_WINDOWFUNCTION_H_ +#define MUSLY_WINDOWFUNCTION_H_ + +#include + +namespace musly { + +class windowfunction { +public: + + /** Return a Hann window of the given size. + * \window_size The size of the Hann window. + * \returns The hann window weights vector. + */ + static Eigen::VectorXf hann( + int window_size); +}; + +} /* namespace musly */ +#endif /* MUSLY_WINDOWFUNCTION_H_ */ diff --git a/musly/CMakeLists.txt b/musly/CMakeLists.txt new file mode 100644 index 0000000..88d153b --- /dev/null +++ b/musly/CMakeLists.txt @@ -0,0 +1,20 @@ +# CMake buildfile generator file. +# Process with cmake to create your desired buildfiles. + +# (c) 2013, Dominik Schnitzer + +include_directories( + ${EIGEN3_INCLUDE_DIR}) + + +add_executable(musly + tools.cpp + fileiterator.cpp + programoptions.cpp + collectionfile.cpp + main.cpp) + +target_link_libraries(musly + libmusly) + +install(TARGETS musly DESTINATION bin) diff --git a/musly/collectionfile.cpp b/musly/collectionfile.cpp new file mode 100644 index 0000000..c8b2bb1 --- /dev/null +++ b/musly/collectionfile.cpp @@ -0,0 +1,202 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "tools.h" +#include "collectionfile.h" + +collection_file::collection_file( + const std::string& coll) : + coll(coll), + version("0"), + header("MUSLY"), + dash("-"), + fid(0) +{ +} + + +collection_file::~collection_file() +{ + if (fid) { + fclose(fid); + } +} + + +bool +collection_file::open(std::string mode) +{ + if (fid) { + fclose(fid); + } + fid = fopen(coll.c_str(), mode.c_str()); + if (!fid) { + return false; + } else { + return true; + } +} + + +bool +collection_file::exists() +{ + struct stat buffer; + return (stat (coll.c_str(), &buffer) == 0); +} + + +bool +collection_file::write_header(const std::string& method) +{ + fwritestr(fid, header+dash+version+dash+method); + + return true; +} + + + +bool +collection_file::read_header() +{ + std::string headerstring = freadstr(fid, 255); + std::vector headersplit = split(headerstring, '-'); + if (headersplit.size() != 3) { + return false; + } + + if ((headersplit[0] != header) || (headersplit[1] != version)) { + return false; + } + + // save method + method = headersplit[2]; + + return true; +} + + +std::string +collection_file::get_method() +{ + return method; +} + +std::string +collection_file::get_file() +{ + return coll; +} + +bool +collection_file::contains_track(const std::string& trackfile) +{ + // check if we have analyzed the file already + std::map::iterator fm_iter = filemap.find(trackfile); + if (fm_iter == filemap.end()) { + return false; + } else { + return true; + } +} + +int +collection_file::read_track( + unsigned char* buffer, + int buffersize, + std::string& file) +{ + // save the file position of the current record, rewind in case + // of an error + fpos_t pos; + if (fgetpos(fid, &pos) != 0) { + return -1; + } + + // read the filename + file = freadstr(fid, 4096); + if (file.length() == 0) { + fsetpos(fid, &pos); + return -1; + } + + // if the current track was already loaded + // return an error. Maybe skip the track model in a later version. + if (contains_track(file)) { + fsetpos(fid, &pos); + return -1; + } + + // read the size of the data field + uint32_t sz; + if (fread(&sz, sizeof(uint32_t), 1, fid) != 1) { + fsetpos(fid, &pos); + return -1; + } + + // buffer insufficient + if ((int)sz > buffersize) { + fsetpos(fid, &pos); + return -1; + } + + // read the data, if size > 0 + if (sz > 0) { + if (fread(buffer, sizeof(unsigned char), sz, fid) != sz) { + fsetpos(fid, &pos); + return -1; + } + } + + // add the file to the map + filemap[file] = 1; + + return sz; +} + +bool +collection_file::append_track( + const std::string& filename, + const unsigned char* bindata, + int size) +{ + // write the filename + fwritestr(fid, filename); + + // write the size. A size of zero indicates an analysis error + uint32_t sz; + if ((size == 0) || (!bindata)) { + sz = 0; + } else { + sz = size; + } + if (fwrite(&sz, sizeof(uint32_t), 1, fid) != 1) { + return false; + } + + // write the serialized musly track + if ((size > 0) && bindata) { + if (fwrite(bindata, size, 1, fid) != 1) { + return false; + } + } + + return true; +} + diff --git a/musly/collectionfile.h b/musly/collectionfile.h new file mode 100644 index 0000000..9481653 --- /dev/null +++ b/musly/collectionfile.h @@ -0,0 +1,72 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#ifndef MUSLY_COLLECTIONFILE_H_ +#define MUSLY_COLLECTIONFILE_H_ + +#include +#include + +class collection_file { +private: + std::string coll; + std::string method; + std::string version; + std::string header; + std::string dash; + + FILE* fid; + + std::map filemap; + + bool + exists(); + + +public: + collection_file( + const std::string& coll); + + virtual + ~collection_file(); + + bool + open(std::string mode); + + bool + write_header( + const std::string& method); + + bool + read_header(); + + bool + append_track( + const std::string& filename, + const unsigned char* bindata, + int size); + + int + read_track( + unsigned char* buffer, + int buffersize, + std::string& file); + + bool + contains_track(const std::string& trackfile); + + std::string + get_method(); + + std::string + get_file(); +}; + +#endif /* MUSLY_COLLECTIONFILE_H_ */ diff --git a/musly/fileiterator.cpp b/musly/fileiterator.cpp new file mode 100644 index 0000000..cbc6e01 --- /dev/null +++ b/musly/fileiterator.cpp @@ -0,0 +1,165 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "fileiterator.h" + +fileiterator::fileiterator(const std::string& path, + const std::string& extension) : + scan_dir(false), + scan_file(false) + +{ + current_dir = path; + + // set scan extension + if (extension.length() > 0) { + search_ext = "." + extension; + + std::transform(search_ext.begin(), search_ext.end(), + search_ext.begin(), ::tolower); + } else { + search_ext = ""; + } + + // check if we have to scan a file or a directory + dir = opendir(path.c_str()); + if (dir) { + scan_dir = true; + + // try opening as file + } else { + + std::ifstream file(path.c_str()); + if (file.is_open()) { + scan_file = true; + file.close(); + } + } +} + + +fileiterator::~fileiterator() +{ + if (dir) { + closedir(dir); + dir = NULL; + } +} + +bool +fileiterator::has_extension(std::string path) +{ + if (search_ext.length() == 0) { + return true; + } + + std::transform(path.begin(), path.end(), path.begin(), ::tolower); + + if (path.length() >= search_ext.length()) { + return (0 == path.compare(path.length()-search_ext.length(), + search_ext.length(), search_ext)); + } else { + return false; + } +} + + +bool +fileiterator::get_nextfilename(std::string& file) +{ + if (scan_file) { + file = current_dir; + scan_file = false; + return true; + } else if (scan_dir) { + return get_nextfilename_dir(file); + } + return false; +} + + +bool +fileiterator::get_nextfilename_dir(std::string& file) +{ + if (!dir) { + return false; + } + + // first search directory entries + struct dirent* entry = readdir(dir); + struct stat s; + while (entry || !dir_queue.empty()){ + + // process current directory + if (entry) { + std::string p = entry->d_name; + std::string fp = current_dir + "/" + p; + + int stat_res = stat(fp.c_str(), &s); + if (stat_res != 0) { + // skip entry on error + continue; + } + + // Directory found + if (S_ISDIR(s.st_mode)) { + + // skip . and .. + // add to queue to process after the current directory is finished + if ((p.compare(".") != 0) && (p.compare("..") != 0)) { + dir_queue.push_back(fp); + } + + // file found + } else if ((S_ISREG(s.st_mode)) && (has_extension(fp))) { + file = fp; + return true; + } + + // process the next directory + } else if (!dir_queue.empty()) { + + // finish and close the current directory + closedir(dir); + dir = NULL; + + // try to get a new directory handle + while (!dir && !dir_queue.empty()) { + current_dir = dir_queue.front(); + dir_queue.pop_front(); + dir = opendir(current_dir.c_str()); + } + } + + // read the next directory entry + if (dir) { + entry = readdir(dir); + } + } + + if (dir) { + closedir(dir); + dir = NULL; + } + return false; +} + diff --git a/musly/fileiterator.h b/musly/fileiterator.h new file mode 100644 index 0000000..2f2d4ad --- /dev/null +++ b/musly/fileiterator.h @@ -0,0 +1,43 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_FILEITERATOR_H_ +#define MUSLY_FILEITERATOR_H_ + +#include +#include +#include +#include +#include + +class fileiterator { +private: + DIR* dir; + std::list dir_queue; + + std::string current_dir; + std::string search_ext; + + bool scan_dir; + bool scan_file; + + bool has_extension(std::string path); + bool get_nextfilename_file(std::string& f); + bool get_nextfilename_dir(std::string& f); + +public: + fileiterator(const std::string& path, const std::string& extension); + virtual ~fileiterator(); + + bool get_nextfilename(std::string& file); +}; + +#endif /* MUSLY_FILEITERATOR_H_ */ diff --git a/musly/main.cpp b/musly/main.cpp new file mode 100644 index 0000000..6bfb6bc --- /dev/null +++ b/musly/main.cpp @@ -0,0 +1,677 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + + +#include +#include +#include +#include +#include +#include + +#include "musly/musly.h" + +#include "tools.h" +#include "programoptions.h" +#include "fileiterator.h" +#include "collectionfile.h" + +musly_jukebox* mj = 0; + + +void +genre_from_filename( + const std::vector& tracks_files, + int e, + std::map& genre_ids, + std::vector& genres) +{ + int prefix_len = 0; + if (e < 0) { + prefix_len = longest_common_prefix(tracks_files).length(); + e = 0; + } + + std::map genre_idx; + int running_id = 0; + + for (size_t i = 0; i < tracks_files.size(); i++) { + + std::string file = tracks_files[i].substr(prefix_len, + tracks_files[i].length()-prefix_len); + + std::vector filesplit = split(file, '/'); + if (e < (int)filesplit.size()) { + std::string g = filesplit[e]; + int id; + if (genre_idx.find(g) != genre_idx.end()) { + id = genre_idx[g]; + } else { + genre_idx[g] = running_id; + genre_ids[running_id] = g; + id = running_id; + running_id++; + } + genres.push_back(id); + } else { + std::string g = "Unknown"; + int id = -1; + if (genre_idx.find(g) == genre_idx.end()) { + genre_ids[id] = g; + } + genres.push_back(id); + } + } +} + +int +read_collectionfile( + collection_file& cf, + char mode, + std::vector* tracks = 0, + std::vector* tracks_files = 0) +{ + // check if collection file is readable + if (!cf.open("r+b")) { + std::cerr << "Collection file: " << cf.get_file() << " not found." + << std::endl; + std::cerr << "Initialize with '-n'" << std::endl; + + return -1; + } + + // check if the file is valid + if (!cf.read_header()) { + std::cerr << "Collection file: " << cf.get_file() << " invalid." + << std::endl; + std::cerr << "Reinitialize with '-n'" << std::endl; + + return -1; + } + + // check if we can initialize musly with the given method + const std::string method = cf.get_method(); + mj = musly_jukebox_poweron(method.c_str(), 0); + if (!mj) { + std::cerr << "Unknown Musly method: " << method << std::endl; + return -1; + } else { + std::cout << "Initialized music similarity method: " << mj->method_name + << std::endl; + std::cout << "Installed audio decoder: " << mj->decoder_name + << std::endl; + std::cout << "~~~" << std::endl; + std::cout << musly_jukebox_aboutmethod(mj) << std::endl; + std::cout << "~~~" << std::endl << std::endl; + } + + // skip files && read files/tracks in database + std::string current_file; + int buffersize = musly_track_binsize(mj); + unsigned char* buffer = + new unsigned char[buffersize]; + musly_track* mt = musly_track_alloc(mj); + + // read the collection file, and position cursor after the last + // record + std::cout << "Reading collection file: " << cf.get_file() << std::endl; + int count = 0; + int read = 0; + while ((read = cf.read_track(buffer, buffersize, current_file)) >= 0) { + + // 'list files' mode + if (mode == 'l') { + std::cout << "track-id: " << count << ", track-size: " << read + << " bytes, track-origin: " << current_file << std::endl; + // 'dump tracks' mode + } else if (mode == 'd') { + std::cout << current_file << std::endl; + if (musly_track_frombin(mj, buffer, mt) > 0) { + std::cout << musly_track_tostr(mj, mt) << std::endl; + } + } else if (mode == 't') { + musly_track* current_mt = musly_track_alloc(mj); + if (musly_track_frombin(mj, buffer, current_mt) > 0) { + tracks->push_back(current_mt); + tracks_files->push_back(current_file); + } + } else if (mode == 'q') { + // do nothing, read the next track + } + + count++; + } + + delete[] buffer; + musly_track_free(mt); + + + + return count; +} + +std::vector +initialize_collection(std::vector& tracks) +{ + std::vector trackids; + + int ret = musly_jukebox_setmusicstyle(mj, tracks.data(), + tracks.size()); + if (ret != 0) { + return trackids; + } + + for (int i = 0; i < (int)tracks.size(); i++) { + musly_trackid tid = musly_jukebox_addtrack(mj, tracks[i]); + trackids.push_back(tid); + } + + return trackids; +} + + + +int +write_mirex( + std::vector& tracks, + std::vector& trackids, + std::vector& tracks_files, + const std::string& file, + const std::string& method) +{ + std::ofstream f; + f.open(file.c_str()); + if (!f.is_open()) { + return -1; + } + + f << "Musly MIREX similarity matrix (Version: " << musly_version() + << "), Method: " << + method << std::endl; + + for (int i = 0; i < (int)tracks_files.size(); i++) { + f << i+1 << "\t" << tracks_files[i] << std::endl; + } + + f << "Q/R"; + for (int i = 0; i < (int)tracks_files.size(); i++) { + f << "\t" << i+1; + } + f << std::endl; + + std::vector similarities(tracks.size()); + for (int i = 0; i < (int)tracks.size(); i++) { + int ret = musly_jukebox_similarity(mj, tracks[i], trackids[i], + tracks.data(), trackids.data(), + tracks.size(), similarities.data()); + if (ret != 0) { + fill(similarities.begin(), similarities.end(), + std::numeric_limits::max()); + } + + // write to file + f << i+1; + for (int j = 0; j < (int)similarities.size(); j++) { + f << '\t' << similarities[j]; + } + f << std::endl; + } + + f.close(); + + return 0; +} + + +class musly_distsort +{ +private: + float* dists; + +public: + musly_distsort( + float* dist) + { + this->dists = dist; + } + + int operator() ( + size_t i, + size_t j) + { + return (dists[i] < dists[j]); + } +}; + +std::string +compute_playlist( + std::vector& tracks, + std::vector& trackids, + std::vector& tracks_files, + musly_track* seed_track, + musly_trackid seed_trackid, + int k) +{ + k = std::min(k, (int)tracks.size()); + + std::vector similarities(tracks.size()); + Eigen::VectorXi track_ids(tracks.size()); + + int ret = musly_jukebox_similarity(mj, seed_track, seed_trackid, + tracks.data(), trackids.data(), + tracks.size(), similarities.data()); + if (ret != 0) { + return ""; + + } + + // TODO: use partial_sort + track_ids = + Eigen::VectorXi::LinSpaced(tracks.size(), 0, tracks.size()-1); + std::sort(track_ids.data(), track_ids.data()+track_ids.size(), + musly_distsort(similarities.data())); + + std::ostringstream pl; + int i = 0; + int ik = 0; + while ((ik < k) && (i < (int)tracks.size())) { + int j = track_ids(i); + float sim = similarities[j]; + if (sim >= 0) { + pl << tracks_files[j] << std::endl; + ik++; + } + i++; + } + + return pl.str(); +} + + + +Eigen::MatrixXi +evaluate_collection( + std::vector& tracks, + std::vector& trackids, + std::vector& genres, + int num_genres, + int k) +{ + std::vector similarities(tracks.size()); + Eigen::VectorXi genre_hist(num_genres); + Eigen::VectorXi track_ids(tracks.size()); + Eigen::MatrixXi genre_confusion = + Eigen::MatrixXi::Zero(num_genres, num_genres); + + k = std::min(k, (int)tracks.size()); + + for (int i = 0; i < (int)tracks.size(); i++) { + + // compute the similarities and find the k most similar tracks + int ret = musly_jukebox_similarity(mj, tracks[i], trackids[i], + tracks.data(), trackids.data(), + tracks.size(), similarities.data()); + if (ret != 0) { + std::cerr << "Failed to compute similar tracks. Skipping." + << std::endl; + continue; + } + + // TODO: use partial_sort + track_ids = + Eigen::VectorXi::LinSpaced(tracks.size(), 0, tracks.size()-1); + std::sort(track_ids.data(), track_ids.data()+track_ids.size(), + musly_distsort(similarities.data())); + + // retrieve the genre of the current music piece + int g = genres[i]; + + // handle the special case of the "Unknown" (-1) music genre + if (g < 0) { + g = num_genres-1; + } + + // predicted genre is decided by a majority vote of its closest k + // neighbors + genre_hist.fill(0); + int j = 0; + int jk = 0; + while (jk < k) { + // skip the track itself + if (track_ids[j] == i) { + j++; + continue; + } + + int gj = genres[track_ids[j]]; + if ((gj >= 0) && (gj < num_genres)) { + genre_hist[gj]++; + } else if (gj == -1) { + genre_hist[num_genres-1]++; + } else { + // invalid + std::cerr << "Something went wrong..." << std::endl; + } + j++; + jk++; + } + int g_predicted; + genre_hist.maxCoeff(&g_predicted); + + // update the confusion matrix + genre_confusion(g, g_predicted)++; + } + + std::cout << "Genre Confusion matrix:" << std::endl; + std::cout << genre_confusion << std::endl; + std::cout << "Correctly classified: " << genre_confusion.diagonal().sum() + << "/" << genre_confusion.sum() << " (" << + ((float)genre_confusion.diagonal().sum()/ + (float)genre_confusion.sum())*100.0 << "%)"<< std::endl; + + return genre_confusion; +} + +int +main(int argc, char *argv[]) +{ + std::cout << "Music Similarity Library (Musly) - http://www.musly.org" + << std::endl; + std::cout << "Version: " << musly_version() << std::endl; + std::cout << "(c) 2013-2014, Dominik Schnitzer " + << std::endl << std::endl; + + // Check if we compiled any music similarity methods + std::vector ms = split(musly_jukebox_listmethods(), ','); + if (ms.size() < 1) { + std::cerr << "No music similarity method found. Aborting." << std::endl; + return 1; + } + + int ret = 0; + + // Parse the program options + programoptions po(argc, argv, ms); + + // initialize the collection file. + // note: the file is not opened/read at this point + collection_file cf(po.get_option_str("c")); + + // set the debug level + int debug_level = po.get_option_int("v"); + if (debug_level > 0) { + std::cout << "Set debug level to: " << debug_level << std::endl; + musly_debug(debug_level); + } + + // -h: want help! + if (po.get_action() == "h") { + po.display_help(); + + // -A: about musly + } else if (po.get_action() == "i") { + std::cout << "Version: " << musly_version() << std::endl; + std::cout << "Available similarity methods: " << + musly_jukebox_listmethods() << std::endl; + std::cout << "Available audio file decoders: " << + musly_jukebox_listdecoders() << std::endl; + + // wrong parameter combination + } else if (po.get_action() == "error") { + std::cerr << "Error: Invalid parameter combination!" << std::endl; + std::cerr << "Use '-h' for more information." << std::endl; + + // indicate error + ret = 1; + + // -a: add a song to the collection + } else if (po.get_action() == "a") { + + // read the collection file in quiet ('q') mode + int track_count = read_collectionfile(cf, 'q'); + if (track_count < 0) { + // the error message was already displayed. just quit here. + if (mj) { + musly_jukebox_poweroff(mj); + } + return ret; + } + std::cout << "Read " << track_count << " musly tracks." << std::endl; + + // search for new files and analyze them + std::string file; + fileiterator fi(po.get_option_str("a"), po.get_option_str("x")); + int buffersize = musly_track_binsize(mj); + unsigned char* buffer = + new unsigned char[buffersize]; + musly_track* mt = musly_track_alloc(mj); + int count = 1; + if (fi.get_nextfilename(file)) { + do { + if (cf.contains_track(file)) { + std::cout << "Skipping file #" << count + << ", already in Musly collection: " + << cf.get_file() << std::endl; + std::cout << file << std::endl << std::endl; + count++; + + continue; + } + std::cout << "Musly analyzing file #" << count << std::endl; + std::cout << file << std::endl; + int ret = musly_track_analyze_audiofile(mj, file.c_str(), 120, mt); + if (ret == 0) { + int serialized_buffersize = + musly_track_tobin(mj, mt, buffer); + if (serialized_buffersize == buffersize) { + cf.append_track(file, buffer, buffersize); + std::cout << "Appending to collection file: " + << cf.get_file() + << std::endl; + count++; + } else { + std::cout << "Serialization failed." << std::endl; + // Do not append failed files + //cf.append_track(file, 0, 0); + } + + } else { + std::cout << "Analysis failed." << std::endl; + // Do not append failed files + //cf.append_track(file, 0, 0); + } + std::cout << std::endl; + + } while (fi.get_nextfilename(file)); + + // TODO: Make analysis run in parallel/multi-threaded + + } else { + std::cout << "No files found while scanning: " << + po.get_option_str("a") << std::endl; + } + delete[] buffer; + musly_track_free(mt); + + // -n: new collection file + } else if (po.get_action() == "n") { + // the selected method + std::string method = po.get_option_str("n"); + + // check if we can initialize musly here! + mj = musly_jukebox_poweron(method.c_str(), 0); + if (!mj) { + std::cerr << "Unknown Musly method: " << method << std::endl; + return 1; + } + + // check if we can initialize a new collection file + cf.open("wb"); + + std::cout << "Initialized music similarity method: " << mj->method_name + << std::endl; + std::cout << "Installed audio decoder: " << mj->decoder_name + << std::endl; + std::cout << "~~~" << std::endl; + std::cout << musly_jukebox_aboutmethod(mj) << std::endl; + std::cout << "~~~" << std::endl << std::endl; + std::cout << "Initializing new collection: " << + po.get_option_str("c") << std::endl; + std::cout << "Initialization result: "<< std::flush; + if (cf.write_header(mj->method_name)) { + std::cout << "OK." << std::endl; + } else { + std::cout << "failed." << std::endl; + } + + // -e: evaluation + } else if (po.get_action() == "e") { + + // read collection file to memory + std::vector tracks; + std::vector tracks_files; + int track_count = read_collectionfile(cf, 't', &tracks, &tracks_files); + if (track_count < 0) { + if (mj) { + musly_jukebox_poweroff(mj); + } + return -1; + } + std::cout << "Loaded " << track_count << " musly tracks to memory." + << std::endl; + + // initialize all loaded tracks + std::vector trackids = initialize_collection(tracks); + + // get the position of the genre in the path + int e = po.get_option_int("e"); + + // try to extract the genre from the filename + std::vector genres; + std::map genre_ids; + genre_from_filename(tracks_files, e, genre_ids, genres); + + int k = po.get_option_int("k"); + std::cout << "k-NN Genre classification (k=" << k << "): " + << cf.get_file() << std::endl; + evaluate_collection(tracks, trackids, genres, genre_ids.size(), k); + + // free the tracks + for (int i = 0; i < (int)tracks.size(); i++) { + musly_track* mti = tracks[i]; + musly_track_free(mti); + } + + // -l: list files in collection file + } else if (po.get_action() == "l") { + // read the collection file in listing ('l') mode + int track_count = read_collectionfile(cf, 'l'); + if (track_count < 0) { + ret = -1; + } + + // -d: dump the features in a human readable (text) format + } else if (po.get_action() == "d") { + // read collection file in dump ('d') mode + int track_count = read_collectionfile(cf, 'd'); + if (track_count < 0) { + ret = -1; + } + + // -m: write a MIREX similarity matrix to the given file + } else if (po.get_action() == "m") { + std::string file = po.get_option_str("m"); + + // read collection file to memory + std::vector tracks; + std::vector tracks_files; + int track_count = read_collectionfile(cf, 't', &tracks, &tracks_files); + if (track_count < 0) { + ret = -1; + } + std::cout << "Loaded " << track_count << " musly tracks to memory." + << std::endl; + + // initialize all loaded tracks + std::vector trackids = initialize_collection(tracks); + + // could all tracks be initialized correctly? + if (trackids.size() == tracks.size()) { + // compute a similarity matrix and write MIREX formatted to the + // given file + std::cout << "Computing and writing similarity matrix to: " << file + << std::endl; + ret = write_mirex(tracks, trackids, tracks_files, file, + cf.get_method()); + if (ret == 0) { + std::cout << "Success." << std::endl; + } else { + std::cerr << "Failed to open file for writing." << std::endl; + } + } + + // free the tracks + for (int i = 0; i < (int)tracks.size(); i++) { + musly_track* mti = tracks[i]; + musly_track_free(mti); + } + } else if (po.get_action() == "p") { + std::string seed_file = po.get_option_str("p"); + + // read collection file to memory + std::vector tracks; + std::vector tracks_files; + int track_count = read_collectionfile(cf, 't', &tracks, &tracks_files); + if (track_count < 0) { + ret = -1; + } + std::cout << "Loaded " << track_count << " musly tracks to memory." + << std::endl; + + // initialize all loaded tracks + std::vector trackids = initialize_collection(tracks); + if (trackids.size() != tracks.size()) { + // TODO + } + + // TODO: analyze or find given file in collection + + // compute a similarity matrix and write MIREX formatted to the + // given file + int k = po.get_option_int("k"); + std::cout << "Computing the k=" << k << " most similar tracks to: " + << seed_file << std::endl; + // TOOD: seek seed + std::string pl = compute_playlist(tracks, trackids, tracks_files, + tracks[1], 0, k); + if (pl == "") { + std::cerr << "Failed to compute similar tracks for given file." + << std::endl; + } else { + std::cout << pl; + } + + // free the tracks + for (int i = 0; i < (int)tracks.size(); i++) { + musly_track* mti = tracks[i]; + musly_track_free(mti); + } + + } + + // cleanup + if (mj) { + musly_jukebox_poweroff(mj); + } + + return ret; +} + diff --git a/musly/programoptions.cpp b/musly/programoptions.cpp new file mode 100644 index 0000000..adf781c --- /dev/null +++ b/musly/programoptions.cpp @@ -0,0 +1,192 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include + + +#include "programoptions.h" + +programoptions::programoptions(int argc, char *argv[], + const std::vector& methods) : + default_collection("collection.musly"), + default_k(5), + default_debuglevel(0), + action(""), + program_name(argv[0]) +{ + optionstr["c"] = default_collection; + optionstr["n"] = ""; + optionstr["x"] = ""; + std::stringstream kstr; + kstr << default_k; + optionstr["k"] = kstr.str(); + optionstr["e"] = "-1"; + + // Build a CSV string with all methods available. + all_methods = methods[0]; + for (int i = 1; i < (int)methods.size(); i++) { + all_methods += "," + methods[i]; + } + + opterr = 0; + while (1) { + + int c = getopt(argc, argv, "v:ihc:a:x:Ee:Nn:k:ldm:p:"); + if (c == -1) { + break; + } + + switch (c) { + + + // actions + case 'E': + case 'N': + if (action.length() != 0) { + action = "error"; + } else { + action = tolower(c); + } + break; + + case 'i': + case 'h': + case 'a': + case 'n': + case 'e': + case 'l': + case 'd': + case 'm': + case 'p': + if (action.length() != 0) { + action = "error"; + } else { + action = (char)(c); + if (optarg) { + optionstr[action] = optarg; + } + } + break; + + // parameters + case 'v': + case 'x': + case 'c': + case 'k': + if (optarg) { + std::string copt; + copt = (char)(c); + optionstr[copt] = optarg; + } + + break; + + // errors + case '?': + break; + default: + break; + } + } + if (optind < argc) { + action = "error"; + } + + // show help if no action given + if (action.length() == 0) { + action = "error"; + } +} + +programoptions::~programoptions() { +} + +std::string +programoptions::get_action() +{ + return action; +} + +std::string +programoptions::get_option_str( + const std::string& option) +{ + if (optionstr.find(option) != optionstr.end()) { + return optionstr[option]; + } + + return ""; +} + +int +programoptions::get_option_int( + const std::string& option) +{ + if (optionstr.find(option) != optionstr.end()) { + return atoi(optionstr[option].c_str()); + } + + return -1; +} + + +void +programoptions::display_help() +{ + using namespace std; +// Helper to format the output max 70 chars wide +// ====================================================================== +cout << "Options for " << program_name << endl; +cout << " -h this help screen." << endl; +cout << " -v 0-5 set the libmusly debug level: (0: none, 5: trace)." << endl; +cout << " DEFAULT: " << default_debuglevel << endl; +cout << " -i information about the music similarity library" << endl; +cout << " -c COLL set the file to write the music similarity features and" << endl + << " to use for computing similarities." << endl + << " DEFAULT: " << default_collection << endl; +cout << " -k NUM set number of similar songs display when computing" << endl + << " playlists ('-p') or evaluating the collection ('-e')." << endl + << " DEFAULT: " << default_k << endl; +cout << " INITIALIZATION:" << endl; +cout << " -n MTH | -N initialize the collection (set with '-c') using the" << endl + << " music similarity method MTH. Available methods:" << endl + << " " << all_methods << endl + << " '-N' automatically selects the best method." << endl; +cout << " MUSIC ANALYSIS/PLAYLIST GENERATION:" << endl; +cout << " -a DIR/FILE analyze and add the given audio FILE to the collection" << endl + << " file. If a Directory is given, the directory is scanned" << endl + << " recursively for audio files." << endl; +cout << " -x EXT only analyze files with file extension EXT when adding" << endl + << " audio files with '-a'. DEFAULT: '' (any)" << endl; +cout << " -p FILE print a playlist of the '-k' most similar tracks for" << endl + << " the given FILE. If FILE is not found in the collection" << endl + << " file, it is analyzed and then compared to all other" << endl + << " tracks found in the collection file ('-c')." << endl; +cout << " LISTING:" << endl; +cout << " -l list all files in the collection file." << endl; +cout << " -d dump the features in the collection file to the console" << endl; +cout << " EVALUATION:" << endl; +cout << " -e NUM | -E perform a basic k-nn (k-nearest neighbor) music genre" << endl + << " classification experiment using the selected collection" << endl + << " file. The parameter k is set with option '-k'. The" << endl + << " genre is inferred from the path element at position NUM." << endl + << " The genre position within the path is guessed with '-E'." << endl; +cout << " -m FILE compute the full similarity matrix for the specified" << endl + << " collection and write it to FILE. It is written in MIREX" << endl + << " text format (see http://www.music-ir.org/mirex)." << endl; +cout << endl; +// ====================================================================== +} diff --git a/musly/programoptions.h b/musly/programoptions.h new file mode 100644 index 0000000..76b366b --- /dev/null +++ b/musly/programoptions.h @@ -0,0 +1,54 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_PROGRAMOPTIONS_H_ +#define MUSLY_PROGRAMOPTIONS_H_ + +#include +#include +#include + +class programoptions { +private: + + std::string all_methods; + std::string default_collection; + int default_k; + int default_debuglevel; + std::string action; + std::string program_name; + std::map optionstr; + +public: + programoptions( + int argc, + char *argv[], + const std::vector& methods); + + virtual + ~programoptions(); + + void + display_help(); + + std::string + get_action(); + + std::string + get_option_str( + const std::string &option); + + int + get_option_int( + const std::string& option); +}; + +#endif /* MUSLY_PROGRAMOPTIONS_H_ */ diff --git a/musly/tools.cpp b/musly/tools.cpp new file mode 100644 index 0000000..16fe816 --- /dev/null +++ b/musly/tools.cpp @@ -0,0 +1,102 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "tools.h" + +std::string +freadstr( + FILE* fid, + int max_size) +{ + std::string str = ""; + + int count = -1; + do { + count++; + int c = fgetc(fid); + if (c == EOF) { + clearerr(fid); + return ""; + } if (c == 0) { + break; + } else { + str += (char)c; + } + } while (count < max_size); + + return str; +} + + +int +fwritestr( + FILE* fid, + const std::string& str) +{ + if (fwrite(str.c_str(), sizeof(char), str.length(), fid) == str.length()) { + if (fputc(0, fid) == 0) { + return str.length(); + } else { + return -1; + } + } else { + return -1; + } +} + + +std::vector& +split( + const std::string &s, + char delim, + std::vector &elems) +{ + std::stringstream ss(s); + std::string item; + while (std::getline(ss, item, delim)) { + elems.push_back(item); + } + return elems; +} + + +std::vector +split( + const std::string &s, + char delim) +{ + std::vector elems; + split(s, delim, elems); + return elems; +} + + +std::string +longest_common_prefix(const std::vector &strs) +{ + std::string prefix; + if(strs.size() > 0) { + prefix = strs[0]; + } + + for (size_t i = 1; i < strs.size(); ++i) { + std::string s = strs[i]; + size_t j = 0; + while (j < std::min(prefix.size(), s.size())) { + if (prefix[j] != s[j]) { + break; + } + j++; + } + prefix = prefix.substr(0, j); + } + return prefix; +} diff --git a/musly/tools.h b/musly/tools.h new file mode 100644 index 0000000..fbb2e22 --- /dev/null +++ b/musly/tools.h @@ -0,0 +1,42 @@ +/** + * Copyright 2013-2014, Dominik Schnitzer + * + * This file is part of Musly, a program for high performance music + * similarity computation: http://www.musly.org/. + * + * This Source Code Form is subject to the terms of the Mozilla + * Public License v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MUSLY_TOOLS_H_ +#define MUSLY_TOOLS_H_ + +#include +#include +#include +#include + + +int +fwritestr(FILE* fid, const std::string& str); + +std::string +freadstr(FILE* fid, int max_size); + +std::vector& +split( + const std::string &s, + char delim, + std::vector &elems); + +std::vector +split( + const std::string &s, + char delim); + +std::string +longest_common_prefix( + const std::vector &strs); + +#endif /* MUSLY_TOOLS_H_ */