Documentation
¶
Overview ¶
Package yinfft implements the YinFFT pitch detection algorithm, which is a variant of the Yin algorithm that uses Fast Fourier Transform (FFT) for efficient pitch detection.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( DefaultParams = Params{ FrameSize: 8192, SampleRate: 44100, ShouldInterpolate: true, Tolerance: 1, WeightingType: "CUSTOM", MinFrequency: 20, MaxFrequency: 22050, } )
Functions ¶
This section is empty.
Types ¶
type Params ¶
type Params struct {
FrameSize int // Length of the input audio frame in samples.
SampleRate float64 // Audio sampling rate in Hz.
ShouldInterpolate bool // Whether to apply interpolation to the detected frequency.
Tolerance float64 // Peak detection tolerance.
WeightingType string // Type of weighting curve to apply (e.g., "A", "B", "C", "D", "CUSTOM").
MinFrequency float64 // Minimum detectable frequency in Hz.
MaxFrequency float64 // Maximum detectable frequency in Hz.
Logger logger // Optional logger for debug messages.
}
Params defines configuration options for the YinFFT pitch detector.
type PitchDetector ¶
type PitchDetector struct {
// contains filtered or unexported fields
}
PitchDetector is the main structure for detecting pitch using the YinFFT algorithm.
func New ¶
func New(params Params) (*PitchDetector, error)
New creates a new PitchDetector instance using the provided Params.
func NewWithDefaultParams ¶
func NewWithDefaultParams() (*PitchDetector, error)
NewWithDefaultParams creates a PitchDetector with built-in default settings.
func (*PitchDetector) DetectFromFrame ¶
func (pd *PitchDetector) DetectFromFrame(frame []float64) (frequency float64, confidence float64, err error)
DetectFromFrame applies windowing and FFT to the input audio frame, then detects the fundamental frequency. The input frame must match the configured FrameSize. Returns the detected frequency, confidence, and any error encountered.
func (*PitchDetector) DetectFromSpectrum ¶
func (pd *PitchDetector) DetectFromSpectrum(spectrum []float64) (frequency float64, confidence float64, err error)
DetectFromSpectrum detects the fundamental frequency assuming the input is a magnitude spectrum. The spectrum should be obtained via FFT, windowed with a Hann window and should represent FrameSize/2+1 bins. Returns the detected frequency, confidence, and any error encountered.