Spectral Sample Finder — User Guide

Pitch-aware sample retrieval for orchestration: recursively scan an audio library, estimate each file's sounding root with the SpectraScore spectral engine, rank the files that fall within a requested pitch tolerance, and load only the best matches into Praat.

Author: Shai Cohen Affiliation: Department of Music, Bar-Ilan University, Israel Version: 0.2.0 (2026) License: MIT License Repo: Praat AudioTools
Contents:

What this does

Spectral Sample Finder searches an audio sample library for files whose detected sounding pitch matches a requested target. The target may be entered as a note name such as C2, F#3 or Bb1, as a frequency in Hz, or as a MIDI note number.

The script is designed for orchestration and sample-library work. A typical use is to ask for a contrabass around C2, scan a folder containing many contrabass recordings, and return only the files that are actually close enough to C2 to be useful.

Key Features:

Design principle: the script is a retrieval tool, not a retuning tool. It does not pitch-shift the corpus. It finds files whose measured sounding pitch is already close to the pitch requested by the user.

Corpus → matches

AUDIO SAMPLE FOLDER ↓ ITERATIVE RECURSIVE SCAN WAV / AIFF / AIF / FLAC ↓ TEMPORARY FILE LOAD file is analysed and then removed ↓ MULTICHANNEL POWER SPECTRUM channel powers summed, not waveform-mixed ↓ SPECTRAL ROOT ESTIMATION harmonic summation + direct support ↓ SUB-BIN REFINEMENT parabolic H1–H6 peak interpolation ↓ ACCEPTANCE TEST pitch tolerance + minimum root confidence ↓ RANK ACCEPTED FILES pitch error + confidence + direct support ↓ LOAD ONLY TOP N MATCHES ↓ RESULTS TABLE + OPTIONAL VISUALIZATION

Quick start

  1. Run Spectral_Sample_Finder.praat from the Praat Objects window. No Sound selection is required.
  2. Leave Folder blank to choose a folder after clicking Apply, or type/paste a folder path directly.
  3. Leave Include_subfolders enabled when the library is organized into nested articulation, dynamic or instrument folders.
  4. Choose the target input type: Note name, Frequency in Hz, or MIDI number.
  5. Enter the target, for example C2.
  6. Set Pitch_tolerance_cents. The default ±35 cents is deliberately selective without requiring laboratory tuning.
  7. Set Minimum_root_confidence. The default is 0.20.
  8. Set Maximum_results to limit how many matching Sounds are finally loaded.
  9. Leave Create_results_table and Draw_visualization enabled for a complete diagnostic run.
Example — adding contrabass: point the script to a contrabass sample folder, request C2, and keep the default ±35-cent tolerance. The corpus is scanned silently; only the best C2 candidates are loaded for immediate audition.

Pitch-detection method

1. Power-summed multichannel spectrum

Every channel is transformed separately. Spectral power is summed across channels before root estimation, avoiding the cancellations that can occur when opposite-phase stereo channels are mixed to mono.

2. Target-centred root search

The search is centred on the requested pitch but deliberately extends around it so octave competitors can win when the file is actually an octave away. With the default advanced setting, the root search spans ±1200 cents around the target.

candidate score = harmonic sum × direct-fundamental support

For every candidate root, the engine measures energy near its harmonics and weights higher harmonics progressively less. A direct-support term reduces phantom subharmonic solutions that are supported only because a strong higher harmonic happens to fit.

3. Root confidence

Confidence describes how clearly the best root candidate wins over a distinct alternative. Acceptance therefore depends not only on closeness to the requested note, but also on whether the spectrum supports a stable root interpretation.

4. Sub-bin refinement in v0.2

Version 0.2 replaces the earlier 2.5-cent band search with parabolic interpolation around the measured H1–H6 spectral peaks. The interpolated harmonic estimates are combined using power and harmonic-number weighting in the logarithmic frequency domain.

f_refined = weighted geometric mean of interpolated H1…H6 fundamentals
Why this matters: a whole-file FFT has finite bin spacing. Searching the spectrum in 2.5-cent steps cannot create resolution finer than those bins. Parabolic interpolation estimates the local peak position between bins and therefore removes the structural quantization error of v0.1.

Controls

Main form

ControlDefaultFunction
FolderblankCorpus folder. Leave blank to open a native folder chooser after Apply.
Include_subfoldersOnScans nested folders using an iterative breadth-first queue.
Pitch_inputNote nameSelects note-name, Hz or MIDI interpretation for Target_pitch.
Target_pitchC2Requested sounding pitch. Examples: C2, F#3, Bb1, 65.406 Hz, or MIDI 36.
Pitch_tolerance_cents35Maximum absolute pitch deviation allowed for acceptance.
Minimum_root_confidence0.20Minimum confidence required in addition to the pitch-tolerance test.
Maximum_results12Maximum number of top-ranked matching Sounds to load into Praat.
Load_matching_soundsOnLoads the top accepted files at the end of the scan.
Create_results_tableOnKeeps the ranked SampleFinder_Results Table.
Draw_visualizationOnDraws the corpus map, ranked matches, reference spectrum and summary strip.
Advanced_settingsOffOpens analysis, ranking and rescue controls.

Advanced settings

ControlDefaultPurpose
Root search span cents1200Search width around the target. A one-octave span on either side helps expose octave competitors.
Root grid cents25Coarse grid for the initial root candidates before sub-bin refinement.
Maximum harmonics12Number of harmonics used by the coarse harmonic-summation score.
Minimum duration s0.03Files shorter than this are skipped.
Confidence weight0.25Contribution of root-confidence deficit to the ranking score.
Direct support weight0.10Contribution of weak direct-fundamental support to the ranking score.
Weak fundamental rescueOnAllows a guarded target-pitch rescue when H1 is weak but the target still has measurable direct and harmonic support.
Rescue min direct ratio0.01Minimum target-frequency direct support required by the rescue path.
Rescue min harmonic ratio0.70Minimum harmonic evidence required before rescue is allowed.

Acceptance & ranking

Acceptance and ranking are deliberately separate. A file first has to pass both hard tests:

|pitch error| ≤ pitch tolerance AND root confidence ≥ minimum confidence

Only accepted files receive a retrieval rank. Their score is:

MatchScore = |cents error| / tolerance + confidence_weight × (1 − root confidence) + direct_support_weight × (1 − direct support)

Lower scores are better. This means a sample that is exactly on pitch normally outranks a less accurate sample, while confidence and direct support resolve cases in which pitch error alone is not enough.

Important: spectral centroid and spectral spread are diagnostic fields in v0.2. They are not part of the acceptance decision. The script answers “does this file already contain the requested sounding pitch?”, not “does its timbre match another sound?”

Weak-fundamental rescue

Low orchestral strings and some other instrumental samples can have a fundamental that is much weaker than H2. A naive harmonic-sum detector can therefore label a true C2 sample as C3.

When the rescue option is enabled, Spectral Sample Finder checks whether the requested lower pitch has real direct spectral support and a sufficiently coherent harmonic pattern. If the guard conditions are met, the file may be accepted at the requested lower root.

Octave protection

The rescue is target-aware and guarded. It is not a blanket “divide the detected pitch by two” rule. A true octave-up sample is rejected unless the target pitch itself has the required physical spectral evidence.

Rescued files are explicitly marked in the Results Table and use the secondary colour in the visualization.

Visualization

Version 0.2 uses the AudioTools 8 × 9.6 inch report format and draws even when no file is accepted.

A · Corpus map

Every successfully analysed file appears in the map, not only accepted files. The horizontal axis is detected pitch in cents relative to the target; the vertical axis is root confidence.

This panel is intended as threshold QC: it shows whether a corpus naturally clusters around the requested pitch, whether the tolerance is too strict, and whether octave errors are common.

B · Ranked matches

The accepted files are shown in retrieval order. The panel combines file-name labels, pitch-error lollipops and root-confidence bars. The confidence threshold is drawn directly on the plot.

C · Spectrum

The best match is shown as a spectrum against the target's harmonic grid, with the detected F0 marked. If nothing matches, the closest rejected file is shown instead, making no-match runs diagnostically useful rather than blank.

Summary strip

The bottom strip reports corpus size, readable and analysed counts, accepted and loaded files, rejection categories, skipped-file counts, the ranking formula and the pitch-analysis method.

Outputs

OutputWhen createdPurpose
Top matching Sound objectsLoad_matching_sounds enabled and matches existOnly the highest-ranked files up to Maximum_results are loaded for immediate audition or further processing.
SampleFinder_ResultsCreate_results_table enabledPersistent ranked report containing pitch, confidence, support, spectral descriptors, rescue state and source paths.
Picture-window reportDraw_visualization enabledCorpus map, ranked matches, spectrum and summary QC.

Results Table fields

FieldMeaning
RankRetrieval order after sorting by MatchScore.
FileName / PathSource file name and complete corpus path.
ObjectNamePraat Sound object name when loaded.
TargetNote / Target_HzResolved user target.
DetectedNote / Detected_Hz / Detected_MIDIRefined sounding-root estimate.
CentsError / AbsCentsErrorSigned and absolute pitch deviation from the target.
RootConfidenceConfidence of the root estimate against distinct alternatives.
DirectSupportStrength of direct spectral evidence at the detected root.
MatchScoreFinal lower-is-better ranking score for accepted files.
Duration_s, Channels, SampleRate_HzSource-audio metadata.
Centroid_Hz / Spread_HzDescriptive spectral diagnostics.
WeakFundamentalRescue1 when the guarded lower-root rescue was used.
Loaded1 when the file was among the final Sounds loaded into Praat.
Object-window hygiene: corpus files used during scanning are temporary and removed immediately after analysis. The script leaves only the requested top matching Sounds and/or the Results Table.

Reliability & practical notes

The matcher combines spectral-root analysis, sub-bin pitch refinement, multichannel power-spectrum analysis and guarded weak-fundamental recovery. These choices are intended to make retrieval useful with real sample libraries rather than only with clean sustained tones.

Practical threshold advice: the default confidence threshold is intentionally permissive. If a library contains noisy, percussive or unstable material, increase Minimum_root_confidence and use the corpus map to see how clearly pitched files separate from rejected material.

Notes & limitations

Natural next step: a future mode can read a pitch directly from a SpectraScore_Results row and search the corresponding instrument sample folder automatically, linking orchestration analysis to sample retrieval.

Citation

Praat AudioTools: Cohen, S. (2026). Praat AudioTools: An Offline Analysis–Resynthesis Toolkit for Experimental Composition.