Delegate independent tasks to specialized agents working concurrently with isolated context.
iOS Audio DSP Expert Guidance
ios-audio-dsp
Expert knowledge for iOS audio processing, pitch detection algorithms (HPS, YIN, FFT), DSP implementation, and AudioKit integration. Use this when implementing pitch detection, debugging audio accuracy issues, working with AVAudioEngine, or optimizing audio DSP performance for mobile.
SKILL.md
Full skill instructions
iOS Audio DSP Expert Guidance
Use these instructions when working with iOS audio processing, pitch detection, DSP algorithms, or AudioKit integration in the saxjaxTunerIntelligent project.
Algorithm Recommendations
Professional Tuner Apps Reference
- Peterson iStroboSoft (0.1 cent accuracy): FFT + Enhanced spectrum analyzer with strobe simulation
- Cleartune (1-2 cent accuracy): FFT + Zero-crossing hybrid approach
Recommended Algorithms for Guitar/Instrument Tuners
- HPS (Harmonic Product Spectrum) - BEST for harmonic instruments
- FFT Direct Peak - Fast, good for strong fundamentals
- YIN - Academic reference, harder to implement correctly
Avoid: Pure time-domain autocorrelation (too slow for mobile)
HPS (Harmonic Product Spectrum) - RECOMMENDED
Algorithm Steps
- Compute FFT of windowed signal (Hann window)
- Downsample spectrum by factors: 2, 3, 4, 5
- Multiply all downsampled spectra together
- Find peak (harmonics align at fundamental)
- Apply parabolic interpolation for sub-bin accuracy
Strengths
- ✅ Robust to missing fundamental
- ✅ Easy to implement correctly
- ✅ Real-time capable on mobile
- ✅ Good accuracy (1-3 cents achievable)
Weaknesses
- ⚠️ Can have octave errors (detectable and filterable)
- ⚠️ Less effective below 50 Hz (not issue for guitar)
Implementation
// After FFT, for each bin i:
let compressed2 = spectrum[i/2]
let compressed3 = spectrum[i/3]
let compressed4 = spectrum[i/4]
let compressed5 = spectrum[i/5]
hpsSpectrum[i] = spectrum[i] * compressed2 * compressed3 * compressed4 * compressed5
// Find peak, then parabolic interpolation for sub-bin accuracy
YIN Algorithm - Complex Implementation
WARNING
FFT-based YIN is complex and error-prone. Consider HPS instead.
Key Issues
- Factor-of-2 Confusion: FFT zero-padding changes normalization semantics
- Windowing Ambiguity: Windowing can make accuracy WORSE for autocorrelation
- Sample Rate: Always capture once at initialization from
AVAudioSession.sharedInstance().sampleRate - Parabolic Interpolation: Essential for sub-sample accuracy
- CMNDF: Must be implemented correctly:
d'(tau) = d(tau) * tau / sum(d[1..tau])
Empirical Reality
- Theory says one thing, practice shows another
- "Mathematically correct" implementations often fail
- Empirical corrections (e.g.,
tau * 1.003) often work better
FFT Implementation Details
Window Functions
Periodic (for FFT): w(n) = 0.5 * (1 - cos(2πn/N)) for n = 0..N-1
Symmetric (for filter design): w(n) = 0.5 * (1 - cos(2πn/(N-1))) for n = 0..N-1
When to use:
- FFT spectral analysis (HPS, direct peak): Use PERIODIC
- Time-domain autocorrelation: Use SYMMETRIC
- FFT-based autocorrelation: Test both, use what works
Buffer Sizing
- Power of 2 required (1024, 2048, 4096)
- YIN autocorrelation: Use 2x buffer size for zero-padding
- HPS: Standard FFT size = buffer size
Parabolic Interpolation
func parabolicInterpolation(_ bins: [Float], _ peakIndex: Int) -> Float {
guard peakIndex > 0 && peakIndex < bins.count - 1 else {
return Float(peakIndex)
}
let alpha = bins[peakIndex - 1]
let beta = bins[peakIndex]
let gamma = bins[peakIndex + 1]
let denominator = alpha - 2.0 * beta + gamma
guard denominator != 0 else { return Float(peakIndex) }
let p = 0.5 * (alpha - gamma) / denominator
return Float(peakIndex) + p
}
AVAudioSession Configuration
For Real-Time Tuner Apps
let session = AVAudioSession.sharedInstance()
try session.setCategory(.playAndRecord, mode: .measurement, options: [])
try session.setPreferredIOBufferDuration(0.005) // ~5ms latency
try session.setActive(true)
// Capture ONCE at init
let sampleRate = AVAudioSession.sharedInstance().sampleRate // Usually 48000.0
Common Accuracy Issues
Error Patterns
- Constant Offset: Sample rate mismatch or tau calculation off-by-one
- Frequency-Dependent Drift: FFT circular correlation bias or incorrect interpolation
- Octave Errors: Tau search range too narrow or harmonic stronger than fundamental
Debugging Strategy
- Gather test data across frequency range (Low: A1-55Hz, Mid: A3-220Hz, High: A5-880Hz)
- Identify error pattern (Hz offset vs cents offset vs frequency-dependent)
- Apply ONE targeted fix and test
- Verify across octaves (target: ±1-2 cents, acceptable: ±5 cents)
AudioKit Integration
import AudioKit
import AudioKitEX
let mic = AudioEngine.InputNode()
let tap = PitchTap(mic) { pitch, amp in
// Process here
}
let sampleRate = Settings.sampleRate // Usually 48000.0
try AudioKit.start()
tap.start()
Production Checklist
- Tested across 3+ octaves (low/mid/high)
- Accuracy ±2 cents or better at A440
- Sample rate captured correctly from AVAudioSession
- Confidence threshold prevents false positives
- Handles silence gracefully
- No production debug logging
- Works on physical device (not just simulator)
Code Quality
- Use
Floatfor audio buffers (vDSP optimized) - Use
Doublefor frequency calculations (precision matters) - Comment all empirical correction factors with rationale
Tuning Standards (A440)
- A0: 27.5 Hz, A1: 55 Hz, A2: 110 Hz, A3: 220 Hz
- A4: 440 Hz (reference)
- A5: 880 Hz, A6: 1760 Hz, A7: 3520 Hz
Cent Calculation: cents = 1200 × log₂(f_detected / f_expected)
Acceptable Errors: Professional: ±1-2 cents, Good: ±3-5 cents, Human perception: ~5-6 cents
More Other skills
brand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.
internal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).
Fundamental design principles for writing maintainable, testable Python code.
responsive-design
Modern responsive layouts using container queries, fluid typography, CSS Grid, and mobile-first strategies.
Generate Playwright tests from scenarios using interactive browser exploration and validation.
Automated website exploration and test case generation using Playwright.
Modern React state management with Redux Toolkit, Zustand, Jotai, and React Query for every state category.
gdpr-data-handling
GDPR-compliant data handling with consent management, data subject rights, and privacy controls.
Python error handling patterns including input validation, exception hierarchies, and partial failure handling. Use when implementing validation logic, designing exception strategies, handling batch processing failures, or building robust APIs.
refactor-plan
Detailed multi-file refactor planning with safety checks and rollback guidance.
