{"id":50890925,"url":"https://github.com/olilarkin/librosa.cpp","last_synced_at":"2026-06-28T14:30:34.900Z","repository":{"id":360610551,"uuid":"1208345977","full_name":"olilarkin/librosa.cpp","owner":"olilarkin","description":"C++17 port of librosa with wasm and SPM package. Done with agents. YMMV.","archived":false,"fork":false,"pushed_at":"2026-06-03T06:30:31.000Z","size":451,"stargazers_count":35,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-03T07:29:23.486Z","etag":null,"topics":["audio-analysis","audio-analyzer","beat-tracking","librosa","music-information-retrieval","pitch-detection","spectrogram","swift","wasm"],"latest_commit_sha":null,"homepage":"https://olilarkin.github.io/librosa.cpp/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/olilarkin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":"NOTICE.md","maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-12T06:30:01.000Z","updated_at":"2026-06-03T06:14:40.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/olilarkin/librosa.cpp","commit_stats":null,"previous_names":["olilarkin/librosa.cpp"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/olilarkin/librosa.cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olilarkin%2Flibrosa.cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olilarkin%2Flibrosa.cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olilarkin%2Flibrosa.cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olilarkin%2Flibrosa.cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olilarkin","download_url":"https://codeload.github.com/olilarkin/librosa.cpp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olilarkin%2Flibrosa.cpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34892546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio-analysis","audio-analyzer","beat-tracking","librosa","music-information-retrieval","pitch-detection","spectrogram","swift","wasm"],"created_at":"2026-06-15T21:00:24.331Z","updated_at":"2026-06-28T14:30:34.893Z","avatar_url":"https://github.com/olilarkin.png","language":"C++","funding_links":[],"categories":["Music Information Retrieval Libraries (C/C++)"],"sub_categories":[],"readme":"# librosa.cpp\n\nA C++17 port of the [librosa](https://github.com/librosa/librosa) audio and music\nanalysis library, built on [Eigen](https://eigen.tuxfamily.org/). Tracks upstream\n`librosa==0.11.0`.\n\n\u003e This is a derivative work. All algorithmic credit belongs to the librosa\n\u003e development team; this repository re-implements their library in C++. See\n\u003e `AUTHORS.md` for the full contributor list and `LICENSE` for the ISC grant\n\u003e inherited from upstream.\n\n## Features\n\n- STFT / ISTFT, CQT, mel-spectrograms, chroma\n- MFCC and other spectral features (centroid, bandwidth, flatness, rolloff, contrast)\n- Onset detection and onset strength\n- Tempo estimation and beat tracking\n- HPSS (harmonic-percussive source separation), NMF decomposition\n- Pitch (YIN, pYIN), tuning estimation\n- Viterbi decoding, DTW, sequence utilities\n- Effects (time stretching, pitch shifting, trimming, remixing)\n- `rosa` CLI for quick analysis from the terminal\n- SwiftPM package with a Swift API and C ABI target for Apple platforms\n- WebAssembly/npm package with a TypeScript API and browser demo\n\nCorrectness is pinned to the Python reference via a cross-validation harness\nthat generates JSON reference outputs with `librosa==0.11.0` and diffs the C++\nimplementation against them — see [Cross-validation](#cross-validation) below.\n\n## Dependencies\n\nBuild-time:\n\n- CMake ≥ 3.16, a C++17 compiler, `pkg-config`\n- Audio file I/O:\n  - Apple platforms use AudioToolbox by default; no `libsndfile` install is\n    required for SwiftPM or default Apple CMake builds.\n  - Non-Apple CMake builds use [libsndfile](http://libsndfile.github.io/libsndfile/)\n    when available.\n- An FFT backend — see [FFT backend](#fft-backend). Default is FFTW3 on\n  Linux/Windows and Apple's Accelerate framework (zero extra dependency) on\n  macOS.\n- An internal Kaiser-windowed sinc resampler provides the `kaiser_*` modes used\n  by the CQT/default resample path, including `kaiser_hq`. No libsoxr\n  install or LGPL resampler link is required.\n- Optional SOXR resampling modes (`soxr_vhq`, `soxr_hq`, `soxr_mq`,\n  `soxr_lq`, `soxr_qq`) can be enabled with `-DLIBROSA_USE_SOXR=ON` for\n  Python-librosa parity checks. This is off by default because libsoxr is LGPL.\n\nBundled (no action needed):\n\n- Eigen (git submodule at `modules/eigen`)\n- `fnnls`, `incbeta` (vendored in `vendor/`)\n- GoogleTest, Google Benchmark, and CLI11 fetched on demand via CMake\n  `FetchContent`\n\nOn Ubuntu:\n\n```bash\nsudo apt-get install cmake ninja-build pkg-config \\\n    libsndfile1-dev libfftw3-dev\n```\n\nOn macOS with Homebrew (FFTW is only needed if you override the default\nAccelerate backend):\n\n```bash\nbrew install cmake ninja\n```\n\nTo enable optional SOXR resampling modes in CMake builds, install libsoxr and\nconfigure with `-DLIBROSA_USE_SOXR=ON`:\n\n```bash\nbrew install libsoxr\ncmake -S . -B build-soxr -DLIBROSA_USE_SOXR=ON\n```\n\n## Build\n\n```bash\ngit clone --recurse-submodules https://github.com/olilarkin/librosa.cpp.git\ncd librosa.cpp\n\ncmake -S . -B build -G Ninja \\\n    -DLIBROSA_BUILD_TESTS=ON \\\n    -DLIBROSA_BUILD_CLI=ON\ncmake --build build\n```\n\nIf you already cloned without `--recurse-submodules`:\n\n```bash\ngit submodule update --init --recursive\n```\n\n## FFT backend\n\nlibrosa.cpp can be built against one of four interchangeable FFT backends,\nselected at configure time with `-DLIBROSA_FFT_BACKEND=\u003cbackend\u003e`:\n\n| Value         | Library                                         | Notes                                                 |\n|---------------|-------------------------------------------------|-------------------------------------------------------|\n| `auto` (default) | Accelerate on Apple, otherwise FFTW3         | Zero-config for typical dev machines.                 |\n| `fftw`        | [FFTW3](https://www.fftw.org/) (double precision) | Default everywhere except Apple platforms.            |\n| `accelerate`  | Apple Accelerate / vDSP                          | macOS/iOS only; no extra dependency.                  |\n| `pocketfft`   | [mreineck/pocketfft](https://github.com/mreineck/pocketfft) (double precision) | Header-only C++, no system FFT library. Same FFT NumPy / SciPy use internally. Supports arbitrary transform lengths (including primes \u003e 5) via Bluestein. Good default when avoiding FFTW's GPL or when building for Emscripten/WASM. |\n| `pffft`       | [marton78/pffft](https://github.com/marton78/pffft) (double precision) | Pure C with SIMD. Restricted to FFT lengths with small prime factors (2, 3, 5); code paths that require arbitrary-length FFTs (fft-based resample, recursive-downsample CQT) are not available under this backend. Prefer `pocketfft` unless you specifically need pffft's SIMD throughput on 5-smooth sizes. |\n\nExample:\n\n```bash\ncmake -S . -B build -G Ninja -DLIBROSA_FFT_BACKEND=pocketfft\n```\n\nThe `pocketfft` and `pffft` backends require their respective submodule in\n`modules/` to be populated (`git submodule update --init --recursive`\nhandles both).\n\n## Run the test suite\n\n```bash\nctest --test-dir build --output-on-failure\n```\n\nThe default unit tests are self-contained — they synthesise their own signals\nand do not require any external data.\n\n## Run performance benchmarks\n\nGoogle Benchmark targets are optional and off by default:\n\n```bash\ncmake -S . -B build-perf \\\n    -DCMAKE_BUILD_TYPE=Release \\\n    -DLIBROSA_BUILD_TESTS=OFF \\\n    -DLIBROSA_BUILD_BENCHMARKS=ON\ncmake --build build-perf --target librosa_benchmarks\n./build-perf/librosa_benchmarks\n```\n\nReal-file beat/onset benchmarks are disabled unless `LIBROSA_BENCH_AUDIO` is\nset. This keeps local paths out of the build while still allowing benchmarks on\nlong production tracks:\n\n```bash\nLIBROSA_BENCH_AUDIO=\"/path/to/file.wav\" \\\n    ./build-perf/librosa_benchmarks --benchmark_filter=RealAudio\n```\n\n## Swift Package\n\nThis repository is also a Swift 5.9+ package for Apple platforms. The package\nbuilds the C++ implementation behind a small C ABI and exposes a Swift API that\nuses `[Double]` buffers and a row-major `LibrosaMatrix`.\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/olilarkin/librosa.cpp.git\", branch: \"main\")\n]\n```\n\n```swift\n.product(name: \"Librosa\", package: \"librosa.cpp\")\n```\n\n```swift\nimport Librosa\n\nlet audio = try Librosa.load(path: \"/path/to/file.wav\", sampleRate: 22_050)\nlet mfcc = try Librosa.mfcc(audio.mono, sampleRate: audio.sampleRate, nMFCC: 13)\nprint(mfcc.rows, mfcc.columns)\n```\n\nSwiftPM Apple builds use Accelerate for FFTs and AudioToolbox for audio file\nloading, so they do not link `libsndfile`.\n\nRun the Swift package tests, including Python-reference cross-validation cases:\n\n```bash\nswift test\n```\n\nTo produce a binary C ABI XCFramework for macOS, iOS, iOS Simulator, visionOS,\nand visionOS Simulator:\n\n```bash\n./scripts/build-xcframework.sh\n```\n\nThe output is written to `.build/xcframework/CLibrosa.xcframework` and includes\na Clang module header that can be imported from Swift as `CLibrosa`.\nSet `LIBROSA_XCFRAMEWORK_PLATFORMS` to a space-separated subset such as\n`\"macos ios\"` when you only want selected slices.\n\n## WebAssembly / npm\n\nThe `packages/librosa-wasm` package builds librosa.cpp with Emscripten, the\n`pffft` FFT backend, and WASM SIMD enabled:\n\n```bash\ncd packages/librosa-wasm\nnpm install\nnpm run build\nnpm test\n```\n\nThe package entrypoint is asynchronous because it loads a `.wasm` module:\n\n```ts\nimport { createLibrosa } from \"@olilarkin/librosa-wasm\";\n\nconst librosa = await createLibrosa();\nconst y = librosa.tone(440, { sr: 22050, duration: 1 });\nconst mfcc = librosa.mfcc(y, { sr: 22050, nMfcc: 13 });\n```\n\nMatrices are row-major `{ rows, cols, data }` objects. Complex matrices use\ninterleaved real/imaginary `Float64Array` data.\n\nThe `examples/web` demo consumes the local package in a browser worker and is\ndeployed by the `web-pages.yml` workflow. On GitHub releases,\n`npm-publish.yml` builds, tests, and publishes `@olilarkin/librosa-wasm` to\nGitHub Packages, while `cli-release.yml` attaches packaged native CLI binaries\nand a `CLibrosa.xcframework` as release assets.\n\n## Cross-validation\n\nThe `tests/crossval/` harness generates reference outputs by running the real\nPython librosa (`==0.11.0`) and diffs the C++ implementation against them.\n\n```bash\npython -m venv .venv \u0026\u0026 source .venv/bin/activate\npip install -r requirements-dev.txt\n\npython tests/crossval/generate_references.py      # writes JSON into tests/crossval/reference_data/\n\ncmake -S . -B build -DLIBROSA_BUILD_CROSSVAL_TESTS=ON\ncmake --build build\n./build/crossval_tests\n```\n\nSee `tests/crossval/README.md` for the full list of modules covered and how to\nadd new cases.\n\n## CLI\n\nWith `-DLIBROSA_BUILD_CLI=ON` (on by default in CI), a `rosa` binary is\nbuilt at `build/rosa`. Usage:\n\n```bash\n./build/rosa \u003cfile.wav\u003e info\n./build/rosa \u003cfile.wav\u003e tempo\n./build/rosa \u003cfile.wav\u003e mfcc --n-mfcc 20\n```\n\nFull reference: `cli/CLI.md`.\n\n## Consuming from CMake\n\n```cmake\nadd_subdirectory(path/to/librosa.cpp)\ntarget_link_libraries(my_target PRIVATE librosa::librosa)\n```\n\nOr after `cmake --install build`, use the installed `librosaTargets.cmake`.\nInstalled consumers also need to satisfy the Eigen dependency themselves,\nsince Eigen is only linked via `BUILD_INTERFACE`:\n\n```cmake\nfind_package(Eigen3 REQUIRED)\nfind_package(librosa REQUIRED)\ntarget_link_libraries(my_target PRIVATE librosa::librosa Eigen3::Eigen)\n```\n\n## License\n\nISC, inherited from upstream librosa — see `LICENSE`. Bundled third-party\ncomponents retain their own licenses; see `NOTICE.md` for the full inventory.\n\n## Citation\n\nIf you use this library in academic work, please cite the original librosa\nproject. See the upstream Zenodo record linked from\n\u003chttps://github.com/librosa/librosa\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folilarkin%2Flibrosa.cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folilarkin%2Flibrosa.cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folilarkin%2Flibrosa.cpp/lists"}