Time Data

The Time Data object allows for processing of a vector representing the audio in the time domain.


The TimeData() has the following constructors:

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

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

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

// Create a timeData by passing in the array to copy
// Must be a Float32Array or Float64Array
var timeData3 = new TimeData(Float32Array());
var timeData3 = new TimeData(Float64Array());

// Create a timeData by passing in another TimeData
// Copies the data over (deep copy)
var timeData4 = new TimeData(TimeData());


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


General Methods


Clear the result object to an empty object


Returns: Nothing


Get the data store view


Returns: Float64Array


Fill the data array with zeros.


Returns: Nothing


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, TimeData().length));. offset defines the starting point in the destination array. See Using the Object Oriented calls for more details.

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

Returns: Nothing


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


Returns: TimeData();


Convert the results table into a JSON string for transmission. Copies all child data including child object results.


Returns: String()


Creates multiple TimeData() objects representing a frame of the parent TimeData() object. Each created object is independant from the parent (the data is deep copied, not referred to). The data is returned inside an Array() object. If the argument frameSize is undefined an error is thrown. If the argument hopSize is undefined it will equal frameSize.

TimeData().decimate(frameSize, hopSize);

Returns: Array()


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


Return the minimum value from the data

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


Return the maximum value from the data

value = TimeData().maximum();
TimeData().result.maximum = Number();


Return the sum of the array

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


Return the mean value of the array

value = TimeData().mean();
TimeData().result.mean = Number();

Temporal Centroid

Return the center of gravity of the array. If window_ms is undefined then window_ms = 100.0.

value = TimeData().temporal_centroid();
TimeData().result.energy = {
    'data': Float64Array(),
    'window_ms': window_ms
TimeData().result.temporal_centroid = Number();


Return the spread of the array

value = TimeData().variance();
TimeData().result.mean = Number();
TimeData().result.variance = Number();

Standard deviation

Calculate the standard deviation

value = TimeData().standard_deviation();
TimeData().result.mean = Number();
TimeData().result.variance = Number();

Average Deviation

Calculate the average deviation from the mean

value = TimeData().average_deviation();
TimeData().result.mean = Number();
TimeData().result.average_deviation = Number();


Calculate the skew of the distribution about the mean

value = TimeData().skewness();
TimeData().result.mean = Number();
TimeData().result.variance = Number();
TimeData().result.standard_deviation = Number();
TimeData().result.skewness = Number();


Calculate the flatness of the distribution

value = TimeData().kurtosis();
TimeData().result.mean = Number();
TimeData().result.variance = Number();
TimeData().result.standard_deviation = Number();
TimeData().result.kurtosis = Number();

Zero Crossing Rate

Count the number of times the signal crosses the zero

value = TimeData().zcr();
TimeData().result.zcr = Number();

Crest factor

Calculate the crest factor

value = TimeData().crest();
TimeData().result.maximum = Number();
TimeData().result.mean = Number();
TimeData().result.crest = Number();

RMS Amplitude

Calculate the RMS amplitude

value = TimeData().rms_amplitude();
TimeData().result.rms_amplitude() = Number();

Non-zero Count

Count the number of elements which are not equal to zero

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

Fundamental Frequency

Compute the fundamental frequency

value = TimeData().f0();
TimeData().result.f0 = Number();


Return the vector of energy from the signal. If argument window_ms is undefined, will default to 100ms.

value = TimeData().energy(window_ms);
TimeData().result.energy = {
    'data': Float64Array(),
    'window_ms' : Number()


Return a SpectrumData() object containing the spectrum. Argument withDC will default to true and normalise to false.

value = TimeData().spectrum(withDC,normalise);
TimeData().result.spectrum = SpectrumData();


Perform the Discrete Cosine Transform

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


Calculate the autocorrelation

value = TimeData().autocorrelation();
TimeData().result.autocorrelation = Float64Array();


Calculate the AMDF:

value = TimeData().amdf();
TimeData().result.amdf = Float64Array();


Calculate the ASDF:

value = TimeData().asdf();
TimeData().result.amdf = Float64Array();


Perform the Yin function for fundamental frequency detection

value = TimeData().yin();
TimeData().result.yin = Float64Array();


Detect the onset using the complex domain onset detection function. If the argument frameSize is undefined an error will be thrown.

value = TimeData().onset(frameSize);
TimeData().result.onset = {
    'data': Float64Array(),
    'frameSize': frameSize


Perform a resampling of the data from the source sample rate to the target sample rate and return in a new TimeData() object. If the source sample rate is not set an error is thrown (this.sampleRate == undefined). If the argument targetSampleRate is not set an error is thrown. If multiple resample functions are sent it will replace any previous resample currently stored in the results node.

value = TimeData().resample(targetSampleRate);
TimeData().result.resample = TimeData();


Extract the pitch using a filterbank. The TimeData object sample rate must be defined.

value = TimeData().pitch();
TimeData().result.pitch = Number();