fennec

package module
v0.0.0-...-639b7ca Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2020 License: MIT Imports: 16 Imported by: 0

README

fennec-tiny

Минимальный (полный не позволяет NDA) пример индексации и сравнения аудио записей, на основе которого была построена внутренняя система матчинга аудиозаписей во ВКонтакте.

Видео и тестовая "расшифровка" по теме:

Архитектура и алгоритмы для индексации всей музыки ВКонтакте

https://habr.com/ru/company/vk/blog/330988/

Documentation

Index

Constants

View Source
const (
	// Максимально допустимое отклонение масштабирования от 1 (без масштабирования)
	ScaleAllowedDiff = 0.3

	// ScaleEpsilon задает порог учета временного масштабирования трека, ниже которого считаем все без учета масштаба
	ScaleEpsilon = 0.001
)
View Source
const (
	// целевая Hz при получении PCM звука
	SampleRate = 11025

	// Размер окна FFT
	FFTWinSize = 1 << (binBits + 1)
	// Величина перекрывания окон FFT
	FFTOverlap = FFTWinSize / 2
	// Половина ширины окна FFT
	FFTHalfWinSize = FFTWinSize / 2
)

Variables

View Source
var (
	ErrWrongParams = errors.New(`Wrong params`)
	ErrMmapFail    = errors.New(`mmap fail`)
)

Functions

func HashColsInOneSec

func HashColsInOneSec() float64

Сколько колонок (элементов []Hash) в одной секунде трека

func NewMP3Reader

func NewMP3Reader(path string, sampleRate int, bits int) (*mp3Reader, error)

func SaveToPng

func SaveToPng(img image.Image, path string) error

func VisualizeSpectre

func VisualizeSpectre(spectre [][]Float, peaks []Peak, hashes []Hash) image.Image

Types

type Float

type Float float32

func ReadMp3

func ReadMp3(path string) (pcm []Float, err error)

type Gaussian

type Gaussian struct {
	// contains filtered or unexported fields
}

func (*Gaussian) Make

func (g *Gaussian) Make(n int, width float64) []float64

type Hash

type Hash struct {
	Time uint32
	Hash uint32
}

func (Hash) ToPeakPair

func (h Hash) ToPeakPair() PeakPair

type Hashes

type Hashes []Hash

Hashes сортирует по возрастанию значения поля Hash

func FindHashes

func FindHashes(peaks []Peak) (hashes Hashes)

func PeakPairsToHashes

func PeakPairsToHashes(pairs []PeakPair) (hashes Hashes)

func (Hashes) Len

func (h Hashes) Len() int

func (Hashes) Less

func (h Hashes) Less(i, j int) bool

func (Hashes) Swap

func (h Hashes) Swap(i, j int)

type HashesByTime

type HashesByTime []Hash

HashesByTime сортирует по возрастанию времени, а при равных - по возрастанию Hash.TimeDiff

func (HashesByTime) Len

func (h HashesByTime) Len() int

func (HashesByTime) Less

func (h HashesByTime) Less(i, j int) bool

func (HashesByTime) Swap

func (h HashesByTime) Swap(i, j int)

type Matcher

type Matcher struct {
	// contains filtered or unexported fields
}

func NewMatcher

func NewMatcher() *Matcher

func (*Matcher) Match

func (m *Matcher) Match(songA Hashes, songB Hashes) (
	score float64, offsetInSec float64, descr string,
)

type Peak

type Peak struct {
	Time uint // X axis
	Bin  uint // Y axis
}

func GenPeaksFromMp3

func GenPeaksFromMp3(path string) ([]Peak, error)

func GenPeaksFromMp3WithSpectre

func GenPeaksFromMp3WithSpectre(path string) ([]Peak, [][]Float, error)

type PeakPair

type PeakPair struct {
	Time1    uint
	Bin1     uint
	Bin2     uint
	TimeDiff uint
}

func NewPeakPair

func NewPeakPair(time1, bin1, time2, bin2 uint) PeakPair

func PeaksToPairs

func PeaksToPairs(peaks []Peak) (pairs []PeakPair)

func (PeakPair) Time2

func (pp PeakPair) Time2() uint

func (PeakPair) ToHash

func (pp PeakPair) ToHash() uint32

type PeakSpectr

type PeakSpectr struct {
	Val Float
	Idx uint
}

type PeakSpectrSlice

type PeakSpectrSlice []PeakSpectr

PeakSpectrSlice сортирует по убыванию Val

func (PeakSpectrSlice) Len

func (p PeakSpectrSlice) Len() int

func (PeakSpectrSlice) Less

func (p PeakSpectrSlice) Less(i, j int) bool

func (PeakSpectrSlice) Swap

func (p PeakSpectrSlice) Swap(i, j int)

type ValIdx

type ValIdx struct {
	Val uint32
	Idx uint32
}

type ValIdxs

type ValIdxs []ValIdx

ValIdxs сортирует по возрастанию Val, а при равных - по убыванию Idx

func (ValIdxs) Len

func (a ValIdxs) Len() int

func (ValIdxs) Less

func (a ValIdxs) Less(i, j int) bool

func (ValIdxs) Swap

func (a ValIdxs) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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