Home Reference Source Test

Function

Static Public Summary
public

FFT(bufferSize: Number, sampleRate: Number, windowFunc: Function, alpha: Number)

Calculate FFT - Based on https://github.com/corbanbrook/dsp.js

public

absMax(values: Array): Number

Get the largest absolute value in an array

since 4.3.0
public

clamp(val: number, min: number, max: number): number

Returns a number limited to the given range.

public

Load a file using fetch.

public

frame(func: function): func

Create a function which will be called at the next requestAnimationFrame cycle

public

getId(prefix: String): String

Get a random prefixed ID

public

Ignores device silence mode when using the WebAudio backend.

since 5.2.0
public

max(values: Array): Number

Get the largest value

public

min(values: Array): Number

Get the smallest value

public

preventClick(values: object)

Starts listening for click event and prevent propagation

public

Apply a map of styles to an element

public

withOrientation(target: object, vertical: bool): Proxy

Returns an appropriately oriented object based on vertical.

since 5.0.0

Static Public

public FFT(bufferSize: Number, sampleRate: Number, windowFunc: Function, alpha: Number) source

Calculate FFT - Based on https://github.com/corbanbrook/dsp.js

Params:

NameTypeAttributeDescription
bufferSize Number

Buffer size

sampleRate Number

Sample rate

windowFunc Function

Window function

alpha Number

Alpha channel

public absMax(values: Array): Number since 4.3.0 source

Get the largest absolute value in an array

Params:

NameTypeAttributeDescription
values Array

Array of numbers

Return:

Number

Largest number found

Example:

console.log(max([-3, 2, 1]), max([-3, 2, 4])); // logs 3 4

Test:

public clamp(val: number, min: number, max: number): number source

Returns a number limited to the given range.

Params:

NameTypeAttributeDescription
val number

The number to be limited to a range

min number

The lower boundary of the limit range

max number

The upper boundary of the limit range

Return:

number

A number in the range [min, max]

public fetchFile(options: object): Observer source

import fetchFile from 'wavesurfer.js/src/util/fetch.js'

Load a file using fetch.

Params:

NameTypeAttributeDescription
options object

Request options to use. See example below.

Return:

Observer

Observer instance

Example:

// default options
let options = {
    url: undefined,
    method: 'GET',
    mode: 'cors',
    credentials: 'same-origin',
    cache: 'default',
    responseType: 'json',
    requestHeaders: [],
    redirect: 'follow',
    referrer: 'client'
};

// override some options
options.url = '../media/demo.wav';

// available types: 'arraybuffer', 'blob', 'json' or 'text'
options.responseType = 'arraybuffer';

// make fetch call
let request = util.fetchFile(options);

// listen for events
request.on('progress', e => {
    console.log('progress', e);
});

request.on('success', data => {
    console.log('success!', data);
});

request.on('error', e => {
    console.warn('fetchFile error: ', e);
});

public frame(func: function): func source

Create a function which will be called at the next requestAnimationFrame cycle

Params:

NameTypeAttributeDescription
func function

The function to call

Return:

func

The function wrapped within a requestAnimationFrame

public getId(prefix: String): String source

Get a random prefixed ID

Params:

NameTypeAttributeDescription
prefix String

Prefix to use. Default is 'wavesurfer_'.

Return:

String

Random prefixed ID

Example:

console.log(getId()); // logs 'wavesurfer_b5pors4ru6g'

let prefix = 'foo-';
console.log(getId(prefix)); // logs 'foo-b5pors4ru6g'

Test:

public ignoreSilenceMode() since 5.2.0 source

import ignoreSilenceMode from 'wavesurfer.js/src/util/silence-mode.js'

Ignores device silence mode when using the WebAudio backend.

Many mobile devices contain a hardware button to mute the ringtone for incoming calls and messages. Unfortunately, on some platforms like iOS, this also mutes wavesurfer's audio when using the WebAudio backend. This function creates a temporary <audio> element that makes sure the WebAudio backend keeps playing when muting the device ringer.

public max(values: Array): Number source

Get the largest value

Params:

NameTypeAttributeDescription
values Array

Array of numbers

Return:

Number

Largest number found

Example:

console.log(max([1, 2, 3])); // logs 3

Test:

public min(values: Array): Number source

Get the smallest value

Params:

NameTypeAttributeDescription
values Array

Array of numbers

Return:

Number

Smallest number found

Example:

console.log(min([1, 2, 3])); // logs 1

Test:

public preventClick(values: object) source

import preventClick from 'wavesurfer.js/src/util/prevent-click.js'

Starts listening for click event and prevent propagation

Params:

NameTypeAttributeDescription
values object

Values

public style(el: HTMLElement, styles: Object): HTMLElement source

Apply a map of styles to an element

Params:

NameTypeAttributeDescription
el HTMLElement

The element that the styles will be applied to

styles Object

The map of propName: attribute, both are used as-is

Return:

HTMLElement

el

public withOrientation(target: object, vertical: bool): Proxy since 5.0.0 source

import withOrientation from 'wavesurfer.js/src/util/orientation.js'

Returns an appropriately oriented object based on vertical. If vertical is true, attribute getting and setting will be mapped through verticalPropMap, so that e.g. getting the object's .width will give its .height instead. Certain methods of an oriented object will return oriented objects as well. Oriented objects can't be added to the DOM directly since they are Proxy objects and thus fail typechecks. Use domElement to get the actual element for this.

Params:

NameTypeAttributeDescription
target object

The object to be wrapped and oriented

vertical bool

Whether the element is oriented vertically

Return:

Proxy

An oriented object with attr translation via verticalAttrMap