Detector

abstract class Detector : AutoCloseable

Realtime pitch detector for processing audio buffers.

Handles variable buffer sizes by internally accumulating samples until it has enough for pitch detection. This is important because:

  • iOS delivers audio at hardware sample rate (48kHz) in ~100ms chunks

  • After resampling to 16kHz, buffers may be smaller than required frame size

Implementations:

  • YinRealtimeDetector: YIN algorithm - frame-by-frame DSP, no ML dependency

  • SwiftF0RealtimeDetector: SwiftF0 neural network - batch-oriented, higher accuracy

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

The configuration used to create this detector

Link copied to clipboard
abstract val hasProcessing: Boolean

Check if post-processing is active

Link copied to clipboard
abstract val latencyMs: Float

Detection latency in milliseconds.

Link copied to clipboard
abstract val livePitchContour: StateFlow<PitchContour>

Live pitch contour accumulated during recording.

Link copied to clipboard

Whether post-processing is currently enabled. Set to enable/disable at runtime.

Functions

Link copied to clipboard
abstract fun clearPitchContour()

Clear the accumulated pitch contour.

Link copied to clipboard
open override fun close()

AutoCloseable implementation - delegates to release()

Link copied to clipboard
abstract fun detect(samples: FloatArray, sampleRate: Int): PitchPoint

Detect pitch from audio samples.

Link copied to clipboard

Create a duplicate detector with the same configuration.

Link copied to clipboard
abstract fun getAmplitude(samples: FloatArray, sampleRate: Int): Float

Get the amplitude (RMS) of the audio samples.

Link copied to clipboard
abstract fun release()

Release all resources. Must be called when done.

Link copied to clipboard
abstract fun reset()

Reset state and internal buffer. Call when starting a new audio stream.

Link copied to clipboard
abstract fun setContourMaxDuration(seconds: Float)

Set the maximum duration for the live pitch contour.