# LibXtract [![CI](https://github.com/jamiebullock/LibXtract/actions/workflows/ci.yml/badge.svg)](https://github.com/jamiebullock/LibXtract/actions/workflows/ci.yml) LibXtract is a simple, portable, lightweight library of audio feature extraction functions. The purpose of the library is to provide a relatively exhaustive set of feature extraction primitives that are designed to be 'cascaded' to create extraction hierarchies. For example, 'variance', 'average deviation', 'skewness' and 'kurtosis', all require the 'mean' of the input vector to be precomputed. However, rather than compute the 'mean' 'inside' each function, it is expected that the 'mean' will be passed in as an argument. This means that if the user wishes to use all of these features, the mean is calculated only once, and then passed to any functions that require it. This philosophy of 'cascading' features is followed throughout the library, for example with features that operate on the magnitude spectrum of a signal vector (e.g. 'irregularity'), the magnitude spectrum is not calculated 'inside' the respective function, instead, a pointer to the first element in an array containing the magnitude spectrum is passed in as an argument. Hopefully this not only makes the library more efficient when computing large numbers of features, but also makes it more flexible because extraction functions can be combined arbitrarily (one can take the irregularity of the Mel Frequency Cepstral Coefficients for example). A complete list of features can be found by viewing the header files, or reading the doxygen documentation. ## Building ### Prerequisites - A C99 compiler (gcc, clang, MinGW) - make On macOS, the library uses Apple's Accelerate framework for FFT. On Linux and Windows, it uses the bundled Ooura FFT. On Windows, an MSYS2/MinGW environment is required to provide `make` and a POSIX-compatible shell. Install [MSYS2](https://www.msys2.org), then from the MinGW 64-bit shell run `pacman -S mingw-w64-x86_64-gcc make`. ### Build and test ```bash make # build library and examples make check # build and run tests ``` ### Install ```bash make install # install to /usr/local make install PREFIX=/somewhere/else # install elsewhere ``` ## Python bindings To build the Python bindings, [SWIG](http://www.swig.org) and Python are required: ```bash make swig ``` ## Documentation LibXtract headers are documented using [doxygen](https://www.doxygen.nl) comments. If you have doxygen installed: ```bash make doc ``` The generated HTML documentation can then be viewed by opening `doc/html/index.html`. ## Code standard LibXtract is written in **C99**. Declarations are placed at the top of the block (C89 style) as a project convention; both the standard and the convention are enforced by the build flags (`-std=c99 -pedantic -Wdeclaration-after-statement -Wstrict-prototypes`). Thread-local storage uses a portability macro that resolves to C11 `_Thread_local`, `__declspec(thread)` (MSVC) or `__thread` (GCC/Clang). Bundled third-party code (`ooura`, `c-ringbuf`, `dywapitchtrack`) keeps its upstream style. Initialisation convention: initialise a variable at its declaration when the initial value is known and meaningful (accumulators to zero, copies of parameters); otherwise declare it uninitialised and assign on every path before use. Never defensively zero a variable that is unconditionally assigned later — dead stores hide missing-assignment bugs from the compiler. This is checked by `-Wconditional-uninitialized` (clang builds) and by `make analyze`, which runs the clang static analyzer over the first-party sources and fails on any finding; CI runs it on Linux and macOS. Formatting follows the Allman brace style (the opening brace on its own line) with four-space indentation, no tabs, and the pointer asterisk bound to the variable (`const double *data`). It is the standard clang-format `Microsoft` preset, captured in `.clang-format` (the only deviations are disabling include sorting and line reflow). Run `make format-check` (or `clang-format --dry-run `) to check, and `make format` (or `clang-format -i `) to apply it. ## API stability LibXtract follows [Semantic Versioning](https://semver.org). The public API is the set of headers installed under `include/xtract/` — `libxtract.h` and the headers it includes. Symbols declared in `src/`, and the bundled third-party code (`ooura`, `c-ringbuf`, `dywapitchtrack`), are internal and not part of the public API. Within the 1.x series the library guarantees **source compatibility**: code that compiles against one 1.x release continues to compile against every later 1.x release. Concretely, across 1.x: - existing public functions are never removed and their signatures never change; - existing `XTRACT_*` enum and macro values are never renumbered or removed; - changes are additive — new functions, new enum values appended to the end, and new features may be added in a minor release. The following are explicitly **not** guaranteed within 1.x: - **Binary (ABI) compatibility.** There is no library-versioning (soname) mechanism yet, and struct layouts may change, so a new minor release may require recompiling and relinking dependent code rather than dropping in a replacement shared library. A formal ABI policy will be revisited once the context/handle API stabilises the layouts (planned for 2.0). - **Numerical output.** A feature function may return different values in a later release when a correctness fix changes a computation; buggy output is not frozen for compatibility. Such changes are called out in the release notes. Breaking changes — removing or renaming a public function, changing a signature, or renumbering an enum — are batched into the next major release (2.0) so that dependent code has a single migration. Where practical, a function to be removed in 2.0 is deprecated in a preceding 1.x release first. ## License Copyright (C) 2012 Jamie Bullock 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 PARTICULAR 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.