yinfft

package module
v0.0.0-...-4470139 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 8 Imported by: 0

README

go-yinfft

Go Report Card

This is a Go port of the YinFFT algorithm, originally implemented in the Essentia library by the Music Technology Group at Universitat Pompeu Fabra, Barcelona. It uses an FFT-based approach derived from the original Yin algorithm, optimized for performance in the frequency domain. It is suitable for real-time applications like guitar tuners, pitch analyzers, and audio feature extraction.

Installation

go get github.com/FreibergVlad/go-yinfft

Usage

Quick Start
package main

import (
	"fmt"
	"github.com/FreibergVlad/go-yinfft"
)

func main() {
	detector, _ := yinfft.NewWithDefaultParams()
	var frame []float64 = getAudioFrame() // You must provide 4096-sample audio frame

	freq, confidence, _ := detector.DetectFromFrame(frame)
	if confidence > 0.8 {
		fmt.Printf("Detected pitch: %.2f Hz\n", freq)
	}
}
Customization
params := yinfft.Params{
	FrameSize:         4096,
	SampleRate:        44100,
	ShouldInterpolate: true,
	Tolerance:         1,
	WeightingType:     "CUSTOM",
	MinFrequency:      20,
	MaxFrequency:      22050,
}
detector, _ := yinfft.New(params)

License

This library is released under the MIT License. Original algorithm by Essentia, ported to Go with respect and attribution.

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

View Source
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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL