wavio

wavio — Architecture and Design Decisions

This document details the architectural design, signal processing pipeline, bit-packing layouts, and engineering trade-offs of the wavio peak-based acoustic fingerprinting engine.


1. Pipeline Overview

The wavio pipeline ingests raw audio, generates a 2D time-frequency power spectrogram, extracts key local maxima (constellation points), and constructs combinatorial pairs of these points to produce search hashes.

               +-----------------------+
               |     Audio Source      |
               | (WAV/MP3/FLAC/AAC/..) |
               +-----------------------+
                           |
                           v
               +-----------------------+
               |     Mono Downmix      |
               |     & Normalization   |
               +-----------------------+
                           |
                           v
               +-----------------------+
               |  Resampler (Linear)   |
               |    to 22,050 Hz       |
               +-----------------------+
                           |
                           v
               +-----------------------+
               |  Hann Window & FFT    |
               |  (2048 Size, 512 Hop) |
               +-----------------------+
                           |
                           v
               +-----------------------+
               | dB Power Spectrogram  |
               |  (ndarray Shape: FxB) |
               +-----------------------+
                           |
                           v
               +-----------------------+
               | 2D Local-Max Filter   |
               |  (Constellation Peaks)|
               +-----------------------+
                           |
                           v
               +-----------------------+
               | Combinatorial Hash    |
               |   (Pairing Target)    |
               +-----------------------+
                           |
                           v
               +-----------------------+
               | Bit-Packing (64-bit)  |
               |   (u64 Fingerprints)  |
               +-----------------------+

2. DSP & Algorithmic Parameters

A. Internal Sample Rate (22,050 Hz)

B. Spectrogram Windowing & FFT Size (2048 Samples / 512 Hop)

C. 2D Peak Neighborhood (10 Frames x 10 Bins)


3. Combinatorial Hashing & Bit-Packing

To achieve robustness against noise and time-stretching, peaks are not hashed individually. Instead, they are paired.

For each anchor peak, up to fan_value (default: 15) target peaks are selected within a time-delta window (0.0s to 1.0s).

64-bit Hash Bit Layout

The pair is packed into a single u64 integer:

 63          60 59                  40 39                  20 19                   0
+--------------+----------------------+----------------------+----------------------+
|   Reserved   |      freq1_bin       |      freq2_bin       |       delta_t        |
|   (4 bits)   |      (20 bits)       |      (20 bits)       |      (20 bits)       |
+--------------+----------------------+----------------------+----------------------+

4. Known Limitations