Home Reference Source Repository
import OnsetDetection from 'music-tempo/src/OnsetDetection.js'
public class | source

OnsetDetection

Spectral flux calculating and peaks finding

Static Method Summary

Static Public Methods
public static

calculateSF(audioData: Float32Array, fft: Object, params: Object): Array

Get spectral flux

public static

findPeaks(spectralFlux: Array, params: Object): Array

Finding local maxima in an array

public static

normalize(data: Array)

Normalize data to have a mean of 0 and standard deviation of 1

Static Public Methods

public static calculateSF(audioData: Float32Array, fft: Object, params: Object): Array source

Get spectral flux

Params:

NameTypeAttributeDescription
audioData Float32Array

non-interleaved IEEE 32-bit linear PCM with a nominal range of -1 -> +1 (Web Audio API - Audio Buffer)

fft Object

object with methods for performing FFT

params Object
  • optional
  • default: {}

parameters

params.bufferSize Number
  • optional
  • default: 2048

FFT windows size

params.hopSize Number
  • optional
  • default: 441

spacing of audio frames in samples

Return:

Array

spectralFlux - the array of spectral flux values

public static findPeaks(spectralFlux: Array, params: Object): Array source

Finding local maxima in an array

Params:

NameTypeAttributeDescription
spectralFlux Array

input data

params Object
  • optional
  • default: {}

parametrs

params.decayRate Number
  • optional
  • default: 0.84

how quickly previous peaks are forgotten

params.peakFindingWindow Number
  • optional
  • default: 6

minimum distance between peaks

params.meanWndMultiplier Number
  • optional
  • default: 3

multiplier for peak finding window

params.peakThreshold Number
  • optional
  • default: 0.35

minimum value of peaks

Return:

Array

peaks - array of peak indexes

public static normalize(data: Array) source

Normalize data to have a mean of 0 and standard deviation of 1

Params:

NameTypeAttributeDescription
data Array

data array