Spectrum Data

The Spectrum Data object allows for processing of a vector representing the audio in the frequency domain as an array of magnitudes.

Constructor

The SpectrumData() has the following two constructors:

// Some Globals
var N = 1024;
var sample_rate = 44100.0;

// Creates a SpectrumData with no sample_rate defined
// Automatically defines a data size of 1024 elements
var spectrumData = new SpectrumData(N);

// Creates a SpectrumData with a sample_rate defined
// Automatically defines a data size of 1024 elements
var spectrumData2 = new SpectrumData(N,sample_rate);

Variables

Variable Name Method Get Set
Sample Rate this.sample_rate Returns sample rate Set the sample rate if sample_rate is undefined
Fundamental Frequency this.f0 Returns the f0 Set the f0
Length this.length Return the length of the vector Read only

Methods

General Methods

clearResult()

Clear the result object to an empty object

SpectrumData().clearResult();

Returns: Nothing

getData

Get the data store view (including both magnitudes and frequency arrays);

SpectrumData().getData();

Returns: Float64Array

zeroData

Fill the maginitude array with zeros.

SpectrumData().zeroData();

Returns: Nothing

copyDataFrom

Copy the data from a source array into the Object. src must be a defined array with at least one element. number defines the number of elements to copy from source, will be set to number=Math.min(number,Math.min(src.length, SpectrumData().length));. offset defines the starting point in the destination array. See Using the Object Oriented calls for more details.

SpectrumData().copyDataFrom(src);
SpectrumData().copyDataFrom(src, number);
SpectrumData().copyDataFrom(src, number, offset);

Returns: Nothing

duplicate

Duplicate the object with another SpectrumData object with the data elements copied. Does not copy the current results node.

SpectrumData().duplicate();

Returns: SpectrumData();

Features

All these functions return their computed features and store them in the results. Any intermediary results which are calculated are also stored.

Minimum

Return the minimum value from the magnitude array

value = SpectrumData().minimum();
SpectrumData().result.minimum = Number();

Maximum

Return the maximum value from the magnitude array

value = SpectrumData().minimum();
SpectrumData().result.maximum = Number();

Sum

Return the sum of the magnitude array

value = SpectrumData().sum();
SpectrumData().result.sum = Number();

Spectral Centroid

Return the spectral centroid

value = SpectrumData().spectral_centroid();
SpectrumData().result.spectral_centroid = Number();

Spectral Mean

Return the spectral mean

value = SpectrumData().spectral_mean();
SpectrumData().result.spectral_mean = Number();

Spectral Variance

Return the spread of the spectrum

value = SpectrumData().spectral_variance();
SpectrumData().result.spectral_mean = Number();
SpectrumData().result.spectral_variance = Number();

Spectral Standard Deviation

value = SpectrumData().spectral_standard_deviation();
SpectrumData().result.spectral_mean = Number();
SpectrumData().result.spectral_variance = Number();
SpectrumData().result.spectral_standard_deviation = Number();

Spectral Skewness

Calculate the skewness of the magnitude spectrum

value = SpectrumData().spectral_skewness();
SpectrumData().result.spectral_mean = Number();
SpectrumData().result.spectral_variance = Number();
SpectrumData().result.spectral_standard_deviation = Number();
SpectrumData().result.spectral_skewness = Number();

Spectral Kutosis

Calculate the flatness of the magnitude spectrum

value = SpectrumData().spectral_kurtosis();
SpectrumData().result.spectral_mean = Number();
SpectrumData().result.spectral_variance = Number();
SpectrumData().result.spectral_standard_deviation = Number();

Irregularity K

value = SpectrumData().irregularity_k();
SpectrumData().result.irregularity_k = Number();

Irregularity J

value = SpectrumData().irregularity_j();
SpectrumData().result.irregularity_j = Number();

Tristimulus 1

Calculate the tristimulus 1. Note the f0 attribute must be set

value = SpectrumData().tristimulus_1();
SpectrumData().result.tristimulus_1 = Number();

Tristimulus 2

Calculate the tristimulus 2. Note the f0 attribute must be set

value = SpectrumData().tristimulus_2();
SpectrumData().result.tristimulus_2 = Number();

Tristimulus 3

Calculate the tristimulus 3. Note the f0 attribute must be set

value = SpectrumData().tristimulus_3();
SpectrumData().result.tristimulus_3 = Number();

Smoothness

Calculate the spectral smoothness.

value = SpectrumData().smoothness();
SpectrumData().result.smoothness = Number();

Rolloff

Calculate the rolloff of the spectrum. If argument threshold is undefined, then threshold=95.

value = SpectrumData().rolloff(threshold);
SpectrumData().result.rolloff = {
    'data': Number(),
    'threshold': threshold
}

Loudness

Calculate the loudness from the bark bands. The sample_rate argument the node must have already been set.

value = SpectrumData().loudness();
SpectrumData().result.barkBands = Float64Array();
SpectrumData().result.loudness = Number();

Sharpness

Calculate the sharpness from the bark bands. The sample_rate argument for the node must have already been set.

value = SpectrumData().sharpness();
SpectrumData().result.barkBands = Float64Array();
SpectrumData().result.loudness = Number();

Flatness

Calculate the flatness of the magnitude spectrum

value = SpectrumData().flatness();
SpectrumData().result.flatness = Number();

Flatness dB

Calculate the flatness of the spectrum in decibels

value = SpectrumData().flatness_db();
SpectrumData().result.flatness = Number();
SpectrumData().result.flatness_db = Number();

Tonality

Calculate the tonality (peakiness) of the spectrum

value = SpectrumData().tonality();
SpectrumData().result.flatness = Number();
SpectrumData().result.flatness_db = Number();
SpectrumData().result.tonality = Number();

Spectral Crest Factor

Calculate the crest factor of the magnitude spectrum

value = SpectrumData().spectral_crest_factor();
SpectrumData().result.maximum = Number();
SpectrumData().result.mean = Number();
SpectrumData().result.spectral_crest_factor = Number();

Spectral Slope

Calculate the slope of the spectrum

value = SpectrumData().spectral_slope();
SpectrumData().result.spectral_slope = Number();

Spectral Fundamental

Calculate the slope of the spectrum

value = SpectrumData().spectral_fundamental();
SpectrumData().result.spectral_fundamental = Number();

Non-Zero Count

Count the number of non-zero elements

value = SpectrumData().nonzero_count();
SpectrumData().result.nonzero_count = Number();

HPS

value = SpectrumData().hps();
SpectrumData().result.hps = Number();

MFCC

Calculate the MFCC spectrum. Note, the init_mfcc() function must have been called to generate an MFCC filter-bank, otherwise an error is thrown.

value = SpectrumData().mfcc();
SpectrumData().result.mfcc = Float64Array();

DCT

Perform the DCT on the magnitude spectrum.

value = SpectrumData().dct();
SpectrumData().result.dct = Float64Array();

Peak Spectrum

Generate the peak spectrum of the signal and return a PeakSpectrumData() object. If threshold is undefined then threshold=20.

value = SpectrumData().peak_spectrum(threshold);
SpectrumData().result.peak_spectrum = PeakSpectrumData();