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.
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:
- Recursive corpus scan — searches WAV, AIFF, AIF and FLAC files, optionally including subfolders.
- Spectral-root analysis — uses harmonic summation plus direct-fundamental support rather than relying only on a conventional monophonic pitch track.
- Multichannel-safe analysis — channel power spectra are summed; stereo channels are never phase-cancellingly folded to mono.
- Sub-bin pitch refinement — H1–H6 are refined by parabolic interpolation and combined by a power/harmonic-weighted log mean.
- Weak-fundamental rescue — low-string samples may still match when H2 is stronger than H1, while true octave-up samples remain rejected.
- Ranked retrieval — accepted files are ranked by pitch error, root confidence and direct fundamental support.
- Memory-safe corpus workflow — files are loaded only temporarily during scanning; only the requested top matches remain in the Praat Objects window.
- Persistent results Table — pitch, confidence, ranking and spectral descriptors remain available for inspection or export.
- Corpus-level visualization — accepted and rejected files are shown together so threshold choices and octave errors can be evaluated visually.
Corpus → matches
Quick start
- Run
Spectral_Sample_Finder.praatfrom the Praat Objects window. No Sound selection is required. - Leave Folder blank to choose a folder after clicking Apply, or type/paste a folder path directly.
- Leave Include_subfolders enabled when the library is organized into nested articulation, dynamic or instrument folders.
- Choose the target input type: Note name, Frequency in Hz, or MIDI number.
- Enter the target, for example
C2. - Set Pitch_tolerance_cents. The default ±35 cents is deliberately selective without requiring laboratory tuning.
- Set Minimum_root_confidence. The default is 0.20.
- Set Maximum_results to limit how many matching Sounds are finally loaded.
- Leave Create_results_table and Draw_visualization enabled for a complete diagnostic run.
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.
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.
Controls
Main form
| Control | Default | Function |
|---|---|---|
| Folder | blank | Corpus folder. Leave blank to open a native folder chooser after Apply. |
| Include_subfolders | On | Scans nested folders using an iterative breadth-first queue. |
| Pitch_input | Note name | Selects note-name, Hz or MIDI interpretation for Target_pitch. |
| Target_pitch | C2 | Requested sounding pitch. Examples: C2, F#3, Bb1, 65.406 Hz, or MIDI 36. |
| Pitch_tolerance_cents | 35 | Maximum absolute pitch deviation allowed for acceptance. |
| Minimum_root_confidence | 0.20 | Minimum confidence required in addition to the pitch-tolerance test. |
| Maximum_results | 12 | Maximum number of top-ranked matching Sounds to load into Praat. |
| Load_matching_sounds | On | Loads the top accepted files at the end of the scan. |
| Create_results_table | On | Keeps the ranked SampleFinder_Results Table. |
| Draw_visualization | On | Draws the corpus map, ranked matches, reference spectrum and summary strip. |
| Advanced_settings | Off | Opens analysis, ranking and rescue controls. |
Advanced settings
| Control | Default | Purpose |
|---|---|---|
| Root search span cents | 1200 | Search width around the target. A one-octave span on either side helps expose octave competitors. |
| Root grid cents | 25 | Coarse grid for the initial root candidates before sub-bin refinement. |
| Maximum harmonics | 12 | Number of harmonics used by the coarse harmonic-summation score. |
| Minimum duration s | 0.03 | Files shorter than this are skipped. |
| Confidence weight | 0.25 | Contribution of root-confidence deficit to the ranking score. |
| Direct support weight | 0.10 | Contribution of weak direct-fundamental support to the ranking score. |
| Weak fundamental rescue | On | Allows a guarded target-pitch rescue when H1 is weak but the target still has measurable direct and harmonic support. |
| Rescue min direct ratio | 0.01 | Minimum target-frequency direct support required by the rescue path. |
| Rescue min harmonic ratio | 0.70 | Minimum harmonic evidence required before rescue is allowed. |
Acceptance & ranking
Acceptance and ranking are deliberately separate. A file first has to pass both hard tests:
Only accepted files receive a retrieval rank. Their score is:
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.
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.
- the pitch-tolerance region is shaded;
- the confidence threshold is shown;
- octave and fifth guides reveal common root-selection errors;
- accepted, rejected and weak-fundamental-rescued samples can be distinguished visually.
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
| Output | When created | Purpose |
|---|---|---|
| Top matching Sound objects | Load_matching_sounds enabled and matches exist | Only the highest-ranked files up to Maximum_results are loaded for immediate audition or further processing. |
SampleFinder_Results | Create_results_table enabled | Persistent ranked report containing pitch, confidence, support, spectral descriptors, rescue state and source paths. |
| Picture-window report | Draw_visualization enabled | Corpus map, ranked matches, spectrum and summary QC. |
Results Table fields
| Field | Meaning |
|---|---|
Rank | Retrieval order after sorting by MatchScore. |
FileName / Path | Source file name and complete corpus path. |
ObjectName | Praat Sound object name when loaded. |
TargetNote / Target_Hz | Resolved user target. |
DetectedNote / Detected_Hz / Detected_MIDI | Refined sounding-root estimate. |
CentsError / AbsCentsError | Signed and absolute pitch deviation from the target. |
RootConfidence | Confidence of the root estimate against distinct alternatives. |
DirectSupport | Strength of direct spectral evidence at the detected root. |
MatchScore | Final lower-is-better ranking score for accepted files. |
Duration_s, Channels, SampleRate_Hz | Source-audio metadata. |
Centroid_Hz / Spread_Hz | Descriptive spectral diagnostics. |
WeakFundamentalRescue | 1 when the guarded lower-root rescue was used. |
Loaded | 1 when the file was among the final Sounds loaded into Praat. |
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.
- Short samples: final pitch is refined between FFT bins, reducing coarse tuning errors when a file is brief.
- Vibrato: moderate pitch modulation can still return a stable central estimate when the sample remains clearly pitched.
- Stereo material: channel power spectra are summed, so antiphase stereo content is not cancelled by waveform fold-down.
- Weak fundamentals: a guarded rescue can recover low-string samples whose second harmonic is stronger than the fundamental, while checking for real energy around the requested lower pitch.
- Recursive folders: subfolders are scanned as part of the corpus when Include_subfolders is enabled.
- Clean Objects window: files used during scanning are temporary; only the requested final matches and optional Results Table remain.
Notes & limitations
- Pitch retrieval, not instrument recognition. The script does not determine whether a file is a contrabass, bassoon or synthesizer. Folder organization supplies that semantic context.
- Designed primarily for pitched samples. Strongly noisy or unstable material may still produce a root candidate. Confidence is therefore part of acceptance.
- Confidence threshold is corpus-dependent. No single value is ideal for every library. Increase the threshold when noisy or unstable files are being admitted; lower it cautiously when quiet or weak-fundamental samples are being missed.
- Whole-file analysis. The current version estimates one root per file. A recording that changes pitch substantially over time is represented by one global result.
- Weak-fundamental rescue is guarded but heuristic. It is designed for low-string and related spectra, not as a general missing-fundamental theorem.
- Centroid and spread are descriptive only. They do not yet implement timbral matching against a selected orchestral context.
- Maximum recursion depth: the internal limit is 64 folder levels.
- Native Praat implementation. No Python, subprocess or external DSP engine is required.
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.