Documentation Index
Fetch the complete documentation index at: https://mintlify.com/hitenpatel/songprint/llms.txt
Use this file to discover all available pages before exploring further.
SignatureGenerator is the core class of songprint. It accepts 16kHz mono 16-bit PCM samples and produces a binary signature in the Shazam constellation-map format. The algorithm applies a Hanning-windowed 2048-point FFT every 128 samples, spreads and recognises spectral peaks across four frequency bands, and encodes them into the compact binary format that Shazam clients send to the discovery endpoint.
Class declaration
Each call to
generateSignature resets all internal state — the same instance can be called multiple times sequentially without creating a new object. Instances are cheap to create.Constructor
generateSignature call.
Methods
generateSignature
16kHz mono 16-bit PCM samples. Use
Pcm.resampleToMono16k to convert from other sample rates or channel counts. The generator processes up to MAX_TIME_SECONDS (3.1 s) of audio and stops early once MAX_PEAKS peaks have been collected; samples beyond that point are ignored. Provide at least a few seconds of audio for the most reliable results.ByteArray — the binary signature ready to pass to RecognitionClient.recognise. A typical signature is a few kilobytes in size.
Processing stops early if both conditions are met: the elapsed audio time reaches MAX_TIME_SECONDS and the total collected peak count reaches MAX_PEAKS. Samples beyond that point are ignored.
Companion object constants
These constants define the fixed parameters of the fingerprinting algorithm. They are exposed publicly so that callers can correctly size buffers and interpret timing values without hard-coding magic numbers.| Constant | Value | Description |
|---|---|---|
SAMPLE_RATE | 16000 | Required input sample rate in Hz. Pass samples at exactly this rate; use Pcm.resampleToMono16k to convert. |
FFT_SIZE | 2048 | FFT window size in samples. Each transform covers 128ms of audio at 16kHz. |
HOP_SIZE | 128 | FFT hop/stride in samples (~8ms per frame). Determines the time resolution of the spectrogram. |
FFT_OUTPUT_SIZE | 1025 | Number of frequency bins per frame (FFT_SIZE / 2 + 1). |
MAX_TIME_SECONDS | 3.1 | Maximum audio duration (in seconds) processed before peak collection stops — used in conjunction with MAX_PEAKS. |
MAX_PEAKS | 255 | Maximum total peaks collected across all bands before processing stops early. |
Nested data class
Peak
The zero-based index of the FFT frame in which this peak was detected. Multiplying by
HOP_SIZE and dividing by SAMPLE_RATE gives the approximate time offset in seconds.The log-scaled magnitude of the peak, computed as
ln(magnitude) * 1477.3 + 6144.0 and truncated to an integer. Stored as a little-endian unsigned 16-bit value in the binary encoding.The frequency bin index refined to 1/64-bin precision using parabolic interpolation of the log-magnitudes of the peak and its immediate neighbours. Stored as a little-endian unsigned 16-bit value in the binary encoding.