1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
//! `audiofp` — audio fingerprinting SDK for Rust.
//!
//! `audiofp` extracts compact, codec-tolerant perceptual hashes from audio
//! so you can identify the same recording across re-encoding, modest
//! noise, and (for some algorithms) tempo or pitch changes — the
//! fundamental primitive behind systems like Shazam or AcoustID.
//!
//! The crate is **`no_std + alloc`** in API shape when the `std`
//! feature is disabled, but the current FFT dependency chain still
//! keeps the no_std path host-only today. The file decoder ([`io`]) and
//! watermark detector ([`watermark`]) live behind feature flags and
//! require `std`.
//!
//! # Quick tour
//!
//! - **Errors** — [`AfpError`] (`#[non_exhaustive]`) plus the
//! [`Result`] alias.
//! - **Value types** — [`SampleRate`] (newtype around `NonZeroU32` with
//! `HZ_*` constants) and [`TimestampMs`] (ordered millisecond
//! timestamp). Extraction takes `&[f32]` samples plus a
//! [`SampleRate`] directly (the old `AudioBuffer` wrapper was removed
//! in 0.4.0; see the migration guide in `CHANGELOG.md`).
//! - **Traits** — [`Fingerprinter`] for whole-buffer extraction,
//! [`StreamingFingerprinter`] for incremental extraction. Every
//! algorithm in the crate implements both.
//! - **Classical fingerprinters** — [`classical::Wang`] (Shazam-style
//! landmark pairs), [`classical::Panako`] (tempo-invariant triplets),
//! [`classical::Haitsma`] (Philips robust hash bands), each with a
//! streaming sibling.
//! - **Matching** — [`matching`] identifies recordings from fingerprints
//! in memory (`WangMatcher`, `HaitsmaMatcher`, `PanakoMatcher` with
//! tempo-invariant 2-D Hough + RANSAC, optional neural cosine), plus
//! `WangIndex` / `HaitsmaIndex` / `PanakoIndex` 1:N accelerators.
//! - **DSP primitives** — [`dsp`] exposes STFT, mel filterbank, peak
//! picker, resampler, and tapered windows for users building their
//! own pipelines on top of `audiofp`.
//!
//! # Panics in streaming APIs
//!
//! All `StreamingFingerprinter::push` / `flush` implementations are
//! fallible and return `Result` — including
//! [`neural::StreamingNeuralEmbedder::push`], which propagates ONNX
//! inference errors instead of panicking (use
//! [`neural::StreamingNeuralEmbedder::try_push`] / `try_push_with`
//! for the callback-style equivalents). Classical streaming
//! fingerprinters (Wang / Panako / Haitsma) never error on valid
//! input. Constructors named `new` (e.g. [`ShortTimeFFT::new`]) panic
//! on invalid configs; each has a `try_new` counterpart returning
//! `Result`.
//!
//! [`neural::StreamingNeuralEmbedder::push`]: crate::neural::StreamingNeuralEmbedder::push
//! [`neural::StreamingNeuralEmbedder::try_push`]: crate::neural::StreamingNeuralEmbedder::try_push
//! [`ShortTimeFFT::new`]: crate::dsp::stft::ShortTimeFFT::new
//!
//! # Example
//!
//! Match two Wang fingerprints with the offset-histogram voter:
//!
//! ```
//! extern crate alloc;
//! use audiofp::classical::{WangFingerprint, WangHash};
//! use audiofp::matching::{Matcher, WangMatchConfig, WangMatcher};
//!
//! let fp = WangFingerprint {
//! hashes: (0..8u32)
//! .map(|i| WangHash {
//! hash: i,
//! // 10 STFT frames apart (frame index in t_anchor).
//! t_anchor: i * 10,
//! })
//! .collect(),
//! frames_per_sec: 62.5,
//! };
//!
//! let matcher = WangMatcher::new(WangMatchConfig::default());
//! let m = matcher.match_one(&fp, &fp);
//! assert!(m.is_match);
//! assert_eq!(m.offset.frames, 0);
//! ```
//!
//! # Cargo features
//!
//! The default build is `no_std + alloc` with **no codecs**. File decoding
//! (`audiofp::io`) is opt-in per codec; each `std-*` feature pulls the
//! matching [`symphonia`](https://docs.rs/symphonia) decoder:
//!
//! | Feature | Default | Description |
//! | ------------ | :-----: | ----------------------------------------------------------------- |
//! | `std` | | Symphonia itself (no codecs; combine with a `std-*` feature). |
//! | `std-wav` | | WAV + raw PCM decoding → [`io`]. |
//! | `std-mp3` | | MP3 decoding → [`io`]. |
//! | `std-flac` | | FLAC decoding → [`io`]. |
//! | `std-ogg` | | Ogg-Vorbis decoding → [`io`]. |
//! | `std-aac` | | AAC decoding → [`io`]. |
//! | `std-mp4` | | AAC-in-MP4 / ISO-BMFF decoding → [`io`]. |
//! | `std-aiff` / `std-mkv` / `std-adpcm` / `std-alac` | | Extended codecs → [`io`]. |
//! | `all-codecs` | | Every format/codec above at once → [`io`] (the pre-0.4.0 `std`). |
//! | `rayon` | | Parallel batch fingerprinting via [`fingerprint_batch_parallel`] (implies `std`). |
//! | `watermark` | | Pulls in [`tract-onnx`](https://docs.rs/tract-onnx) → [`watermark`] (implies `std`). |
//! | `neural` | | Generic ONNX log-mel embedder ([`neural`]); pulls in [`tract-onnx`](https://docs.rs/tract-onnx) (implies `std`). |
//! | `mimalloc` | | Installs `mimalloc::MiMalloc` as the process-wide allocator (implies `std`). |
//!
//! [`fingerprint_batch_parallel`]: crate::fingerprint_batch_parallel
//!
//! See [`USAGE.md`](https://github.com/themankindproject/audiofp/blob/main/USAGE.md)
//! for the complete API guide.
// The `std` feature is a bare dependency on Symphonia; codec support is
// opt-in via the per-codec sub-features (`std-wav`, `std-mp3`, …) or the
// `all-codecs` feature (every codec at once). Enable one of them to get
// `audiofp::io`. Features that merely imply `std` (`neural`, `watermark`,
// `rayon`, `mimalloc`) are unaffected.
compile_error!;
extern crate alloc;
static GLOBAL: MiMalloc = MiMalloc;
/// Convenience re-exports of the most commonly used types. See
/// [`prelude`] for details.
pub use IoError;
pub use ;
pub use ;
pub use FingerprintEnvelope;
pub use ;
/// Convenience re-exports of the classical algorithm types at the crate
/// root. The canonical location remains [`classical`]; these are aliases
/// so `use audiofp::Wang;` works directly.
pub use ;
/// Multi-threaded batch fingerprinting (requires the `rayon` feature).
pub use fingerprint_batch_parallel;
/// Crate version string, sourced from `Cargo.toml`.
///
/// Useful when persisting fingerprints alongside the producer version,
/// or when emitting diagnostics that need to identify the SDK build.
///
/// # Example
///
/// ```
/// assert_eq!(audiofp::VERSION, env!("CARGO_PKG_VERSION"));
/// ```
pub const VERSION: &str = env!;
// Compile-time assertions: all public types must be Send + Sync so they are
// usable in async contexts and can be shared across threads.