C library for audio noise reduction and other spectral effects
This library is a standalone, modular spectral processing engine originally based on noise-repellent. It decouples the DSP algorithms from any specific plugin API (like LV2), allowing for easy integration into various applications.
The core architecture uses a unified spectral processor concept. The library currently implements advanced spectral denoising using efficient circular buffering (SbSpectralCircularBuffer) and modern STFT processing. It is designed to be extensible, supporting future additions like de-crackle or de-click algorithms.
The library implements a sophisticated spectral gating algorithm enhanced by several psychoacoustic and statistical techniques:
The fundamental noise reduction method uses spectral subtraction with proprietary framing and windowing to minimize artifacts.
A Non-Local Means (NLM) algorithm filters the spectrogram in both time and frequency domains simultaneously. This preserving structural details of the signal while reducing musical noise and "burbling" artifacts often associated with simple spectral subtraction. Note: This feature is computationally intensive and requires SIMD optimization (enabled in Release builds).
To preserve transients and prevent over-processing, a psychoacoustic masking model estimates the auditory masking threshold. If the signal components are strong enough to mask the noise naturally, the "veto" system prevents unnecessary noise reduction, preserving the natural character of the audio.
Specialized handling for tonal noise components allows for more aggressive reduction of static hums and whines without affecting broadband characteristics.
The whitening feature (noise floor recovery) has been refined to be transparent at 0dB reduction, ensuring that the noise floor texture is natural and consistent with the reduction amount.
In addition to manual noise profile capture, the library supports adaptive noise usage for changing noise environments.
If you wish to compile yourself and install the library you will need:
- A C compiling toolchain (GCC or Clang)
- Meson build system (0.60.0 or newer)
- Ninja build tool
- FFTW3 library (float version)
- OpenMP for parallel processing
- libsndfile (optional, for examples)
git clone https://github.com/lucianodato/libspecbleach.git
cd libspecbleach
meson setup build --buildtype=release
meson compile -C build
sudo meson install -C buildYou can configure the build using -Doption=value:
enable_examples: Build example applications (default:false). Requireslibsndfile.enable_tests: Build unit and integration tests (default:false). Requireslibsndfile.static_deps: Link internal dependencies (like FFTW3) statically (default:false). Useful for creating self-contained libraries.custom_warning_level: 0-3 (default:2). Controls compiler warning verbosity.treat_warnings_as_errors: Treat compiler warnings as errors (default:false).enable_sanitizers: Enable sanitizers in debug builds (default:false).sanitize_address: Enable AddressSanitizer (default:false).sanitize_undefined: Enable UndefinedBehaviorSanitizer (default:false).lv2dir: Install directory for LV2 bundles (absolute path or relative to prefix) (default: '').
Important
Critical Performance Note for Packagers: The advanced "2D Denoising" (NLM) feature is computationally intensive and relies heavily on SIMD vectorization, function inlining, and multi-core parallelization via OpenMP.
You MUST compile with --buildtype=release (or -O3) to ensure usability. Debug or unoptimized builds will result in excessive CPU usage and audio dropouts/xruns.
Note on DSP Usage: In DAW environments (like Ardour), the multi-threaded NLM processing may cause the DSP meter to show high usage peaks during the processing cycle.
The library defaults to 4 threads for NLM processing if not specified. You can fine-tune the thread usage using the OMP_NUM_THREADS environment variable (e.g., export OMP_NUM_THREADS=2). Lower thread counts will result in lower DSP peaks but higher total processing time per buffer.
Example for a static build with examples:
meson setup build -Dstatic_deps=true -Denable_examples=true
meson compile -C buildSimple console apps examples are provided to demonstrate how to use the library. It needs libsndfile to compile successfully. You can build them with:
meson setup build --buildtype=release -Denable_examples=true
meson compile -C buildTo process a file using a manually captured noise profile (first N frames):
./build/example/denoiser_demo --learn-frames 10 input.wav output.wavTo use the adaptive noise estimator:
./build/example/denoiser_demo --adaptive input.wav output.wav./build/example/denoiser_demo \
--adaptive \
--reduction 20 \
--whitening 50 \
--smoothing 0.0 \
input.wav output.wavIt will recognize any libsndfile supported format.
For development builds with debugging symbols:
meson setup build --buildtype=debug
meson compile -C buildThe project uses clang-format for code formatting. To format the code:
meson compile format -C buildIf tests are enabled:
meson setup build -Denable_tests=true
meson test -C buildTo generate coverage reports locally, you will need gcovr or lcov installed.
meson setup build --buildtype=debug -Db_coverage=true
meson compile -C build
meson test -C build
ninja -C build coverage-htmlThe report will be available in build/meson-logs/coveragereport/index.html.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
See LICENSE for more details.