### Build libkeyfinder with CMake Source: https://github.com/mixxxdj/libkeyfinder/blob/main/README.md Standard procedure to configure, build, and install the libkeyfinder library using CMake. Ensure dependencies like FFTW3 and Catch2 are installed. ```sh cmake -DCMAKE_INSTALL_PREFIX=/where/you/want/to/install/to -S . -B build cmake --build build --parallel number-of-cpu-cores cmake --install build ``` -------------------------------- ### Progressive Key Estimation Source: https://github.com/mixxxdj/libkeyfinder/blob/main/docs/Introduction.txt This example demonstrates progressive key estimation from an audio stream, suitable for real-time analysis or when processing audio in packets. It involves creating a Workspace for memory allocations and iteratively updating the chromagram. ```cpp KeyFinder::AudioData a; a.setFrameRate(yourAudioStream.framerate); a.setChannels(yourAudioStream.channels); a.addToSampleCount(yourAudioStream.packetLength); static KeyFinder::KeyFinder k; // the workspace holds the memory allocations for analysis of a single track KeyFinder::Workspace w; while (someType yourPacket = newAudioPacket()) { for (int i = 0; i < yourPacket.length; i++) { a.setSample(i, yourPacket[i]); } k.progressiveChromagram(a, w); // if you want to grab progressive key estimates... KeyFinder::key_t key = k.keyOfChromagram(w); doSomethingWithMostRecentKeyEstimate(key); } // if you only want a single key estimate, or to squeeze // every last bit of audio from the working buffer after // progressive estimates... k.finalChromagram(w); // and finally... KeyFinder::key key = k.keyOfChromagram(w); doSomethingWithFinalKeyEstimate(key); ``` -------------------------------- ### Basic Key Estimation Source: https://github.com/mixxxdj/libkeyfinder/blob/main/docs/Introduction.txt Use this snippet for a straightforward estimation of the musical key of an entire audio stream. Initialize KeyFinder and AudioData objects, populate AudioData with your audio samples, and then call keyOfAudio. ```cpp // Static because it retains useful resources for repeat use static KeyFinder::KeyFinder k; // Build an empty audio object KeyFinder::AudioData a; // Prepare the object for your audio stream a.setFrameRate(yourAudioStream.framerate); a.setChannels(yourAudioStream.channels); a.addToSampleCount(yourAudioStream.length); // Copy your audio into the object for (int i = 0; i < yourAudioStream.length; i++) { a.setSample(i, yourAudioStream[i]); } // Run the analysis KeyFinder::key_t key = k.keyOfAudio(a); // And do something with the result doSomethingWith(key); ``` -------------------------------- ### Run libkeyfinder Tests Source: https://github.com/mixxxdj/libkeyfinder/blob/main/README.md Execute the unit tests for libkeyfinder after building the library. Navigate to the build directory and run 'ctest'. ```sh cd build ctest --parallel number-of-cpu-cores ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/mixxxdj/libkeyfinder/blob/main/examples/CMakeLists.txt This snippet shows the essential CMake commands to configure a project that uses libkeyfinder. It sets the minimum CMake version, defines the project name, adds a module path, finds the KeyFinder package, and links the executable to the keyfinder library. ```cmake cmake_minimum_required(VERSION 3.1.0) project(KeyFinderBasicExample) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") find_package(KeyFinder CONFIG REQUIRED) add_executable(basic basic.cpp) target_link_libraries(basic PRIVATE KeyFinder::keyfinder) ``` -------------------------------- ### Find and Fetch Catch2 Source: https://github.com/mixxxdj/libkeyfinder/blob/main/tests/CMakeLists.txt Attempts to find the Catch2 configuration. If not found, it fetches Catch2 from GitHub using FetchContent and makes it available. ```cmake find_package(Catch2 CONFIG) if(NOT TARGET Catch2::Catch2) message(STATUS "Fetching Catch2 from GitHub") include(FetchContent) FetchContent_Declare( Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_TAG v3.3.2) FetchContent_MakeAvailable(Catch2) list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/contrib) endif() ``` -------------------------------- ### Link Libraries Source: https://github.com/mixxxdj/libkeyfinder/blob/main/tests/CMakeLists.txt Links the test executable against the main library ('keyfinder') and the Catch2 testing framework. 'Catch2WithMain' includes the necessary main function for running tests. ```cmake target_link_libraries(keyfinder-tests PRIVATE keyfinder) ``` ```cmake target_link_libraries(keyfinder-tests PRIVATE Catch2::Catch2WithMain) ``` -------------------------------- ### Build libkeyfinder Statically with CMake Source: https://github.com/mixxxdj/libkeyfinder/blob/main/README.md Configure libkeyfinder to build as a static library by adding the -DBUILD_SHARED_LIBS=OFF flag during the CMake configuration step. ```sh cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/where/you/want/to/install/to -S . -B build cmake --build build --parallel number-of-cpu-cores cmake --install build ``` -------------------------------- ### Discover Tests Source: https://github.com/mixxxdj/libkeyfinder/blob/main/tests/CMakeLists.txt Uses the Catch2 module to automatically discover and register tests within the 'keyfinder-tests' executable. ```cmake include(Catch) catch_discover_tests(keyfinder-tests) ``` -------------------------------- ### Set Include Directories Source: https://github.com/mixxxdj/libkeyfinder/blob/main/tests/CMakeLists.txt Specifies private include directories for the test executable. This allows the test code to find headers from the project's source directory. ```cmake target_include_directories(keyfinder-tests PRIVATE ../src) ``` -------------------------------- ### Define Test Executable Source: https://github.com/mixxxdj/libkeyfinder/blob/main/tests/CMakeLists.txt Defines the main executable for running tests. It lists all source files that will be compiled into the test executable. ```cmake add_executable(keyfinder-tests _testhelpers.cpp audiodatatest.cpp binodetest.cpp chromagramtest.cpp chromatransformtest.cpp chromatransformfactorytest.cpp constantstest.cpp downsamplershortcuttest.cpp fftadaptertest.cpp keyclassifiertest.cpp keyfindertest.cpp lowpassfiltertest.cpp lowpassfilterfactorytest.cpp spectrumanalysertest.cpp temporalwindowfactorytest.cpp toneprofilestest.cpp windowfunctiontest.cpp workspacetest.cpp) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.