chromaprint 0.1.0 copy "chromaprint: ^0.1.0" to clipboard
chromaprint: ^0.1.0 copied to clipboard

Dart FFI bindings for the Chromaprint audio fingerprinting library (AcoustID).

chromaprint #

Dart FFI bindings for Chromaprint, the audio fingerprinting library used by AcoustID.

Generates compact fingerprints from raw PCM audio data that can be used to identify recordings via the AcoustID database.

Supported platforms #

Platform Status
Android Yes
Linux Yes
iOS Planned
macOS Planned
Windows Planned

Usage #

Basic fingerprinting #

import 'package:chromaprint/chromaprint.dart';

void main() {
  final cp = Chromaprint();
  cp.start(44100, 1); // 44.1 kHz, mono

  // Feed raw PCM samples (16-bit signed integers, native byte order).
  // For stereo, channels are interleaved (L, R, L, R, ...).
  cp.feed(audioData);

  cp.finish();

  // Compressed fingerprint (base64, ready for AcoustID)
  final fingerprint = cp.getFingerprint();

  // 32-bit hash for quick comparison
  final hash = cp.getFingerprintHash();

  cp.dispose();
}

Encoding / decoding fingerprints #

// Get raw fingerprint data
final raw = cp.getRawFingerprint();

// Encode to a compressed base64 string
final encoded = encodeFingerprint(raw, ChromaprintAlgorithm.defaultAlgorithm);

// Decode back to raw data
final decoded = decodeFingerprint(encoded);
print(decoded.algorithm);        // ChromaprintAlgorithm.test2
print(decoded.rawFingerprint);   // List<int>

// Compute a 32-bit hash of raw fingerprint data
final hash = hashFingerprint(raw);

Getting the library version #

final version = getVersion(); // e.g. "1.6.0"

API reference #

Chromaprint class #

High-level wrapper around the Chromaprint C library.

Method / Property Description
Chromaprint({algorithm}) Create a new fingerprinter instance.
algorithm The algorithm used by this instance.
sampleRate Configured sample rate (after start).
numChannels Configured channel count (after start).
setOption(name, value) Set an option (e.g. "silence_threshold"). Must be called before start.
start(sampleRate, numChannels) Begin the fingerprinting process.
feed(data) Feed 16-bit signed integer PCM samples.
feedRaw(ptr, size) Feed samples from a native pointer.
finish() Complete the fingerprinting process.
getFingerprint() Get the compressed base64 fingerprint string.
getRawFingerprint() Get the raw fingerprint as List<int>.
getRawFingerprintSize() Number of elements in the raw fingerprint.
getFingerprintHash() 32-bit hash of the fingerprint.
clearFingerprint() Clear fingerprint data to reuse the instance.
dispose() Release native resources.

Top-level functions #

Function Description
getVersion() Returns the chromaprint library version string.
encodeFingerprint(raw, algorithm, {base64}) Encode raw fingerprint data to compressed format.
decodeFingerprint(encoded, {base64}) Decode a compressed fingerprint to raw data.
hashFingerprint(raw) Compute a 32-bit hash of raw fingerprint data.

ChromaprintAlgorithm enum #

Value Description
test1 Algorithm test variant 1
test2 Default. Recommended for general use.
test3 Algorithm test variant 3
test4 Algorithm test variant 4
test5 Algorithm test variant 5

Development setup #

Prerequisites #

  • Flutter SDK >= 3.3.0
  • Dart SDK >= 3.11.4
  • CMake >= 3.10
  • A C/C++ toolchain for your target platform

Clone with submodule #

git clone --recurse-submodules <repo-url>

If you already cloned without --recurse-submodules:

git submodule init
git submodule update

Build the example app #

cd example
flutter run

The example app generates a fingerprint from a synthetic 440 Hz sine wave and displays the result.

Regenerate FFI bindings #

The low-level bindings in lib/chromaprint_bindings_generated.dart are generated by package:ffigen. You need chromaprint.h installed on your system (e.g. libchromaprint-dev on Debian/Ubuntu, chromaprint on Arch Linux).

dart run ffigen --config ffigen.yaml

How it works #

The native library is compiled directly from the Chromaprint source in the chromaprint/ git submodule. The build is configured in src/CMakeLists.txt and uses:

  • KissFFT (bundled with Chromaprint) for FFT computation
  • Internal avresample for audio resampling
  • No external dependencies beyond the C/C++ standard library and libm

The src/config.h header provides build configuration (version, FFT backend, etc.) that replaces the autoconf-generated header from the upstream Chromaprint build system.

0
likes
155
points
--
downloads

Documentation

API reference

Publisher

verified publisherassoz.org

Weekly Downloads

Dart FFI bindings for the Chromaprint audio fingerprinting library (AcoustID).

Repository (GitHub)

License

MIT (license)

Dependencies

ffi, flutter, plugin_platform_interface

More

Packages that depend on chromaprint

Packages that implement chromaprint