recursal/MDN huggingface dataset:
XPathEvaluator: createExpression() method
=========================================

 This method compiles an `XPathExpression` which can then be used for
 (repeated) evaluations of the XPath expression.

Syntax
------


```js
createExpression(expression)
createExpression(expression, resolver)
```

### Parameters

`expression`

A string representing the XPath expression to be created.

`resolver` Optional

 Permits translation of all prefixes, including the `xml` namespace
 prefix, within the XPath expression into appropriate namespace URIs.


### Return value

 A `XPathExpression` representing the compiled form of the XPath
 expression.

### Exceptions

#### INVALID\_EXPRESSION\_ERR

 If the expression is not legal according to the rules of the
 `XPathEvaluator`, an `XPathException` of type
 `INVALID_EXPRESSION_ERR` is raised.

#### NAMESPACE\_ERR

 If the expression contains namespace prefixes which cannot be resolved by the specified
 `XPathNSResolver`, a `DOMException` of type
 `NAMESPACE_ERROR` is raised.

Examples
--------

The following example shows the use of the `evaluate()` method.

### HTML


```html
<div>XPath example</div>
<div>Number of &lt;div&gt;s: <output></output></div>
```

### JavaScript


```js
const xpath = "//div";
const evaluator = new XPathEvaluator();
const expression = evaluator.createExpression(xpath);
const result = expression.evaluate(
  document,
  XPathResult.ORDERED\_NODE\_SNAPSHOT\_TYPE,
);
document.querySelector("output").textContent = result.snapshotLength;
```

### Result

Specifications
--------------

| Specification |
| --- |
| DOM Standard # dom-xpathevaluatorbase-createexpression |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Document.createExpression()`
* `XPathExpression`
XPathEvaluator: XPathEvaluator() constructor
============================================

The **`XPathEvaluator()`** constructor creates a new `XPathEvaluator`.

Syntax
------


```js
new XPathEvaluator()
```

### Parameters

None.

### Return value

A new `XPathEvaluator` object.

Examples
--------

### Count the number of `<div>` elements

The following example shows the use of the `XPathEvaluator` interface.

#### HTML


```html
<div>XPath example</div>
<div>Number of &lt;div&gt; elements: <output></output></div>
```


#### JavaScript


```js
const xpath = "//div";
const evaluator = new XPathEvaluator();
const expression = evaluator.createExpression(xpath);
const result = expression.evaluate(
  document,
  XPathResult.ORDERED\_NODE\_SNAPSHOT\_TYPE,
);
document.querySelector("output").textContent = result.snapshotLength;
```


#### Result

Specifications
--------------

| Specification |
| --- |
| DOM Standard # dom-xpathevaluator-xpathevaluator |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
XPathEvaluator: createNSResolver() method
=========================================

 This method adapts any DOM node to resolve namespaces so that an XPath expression can
 be easily evaluated relative to the context of the node where it appeared within the
 document.

 This adapter works like the DOM Level 3 method `Node.lookupNamespaceURI()` in resolving the namespace URI from a given prefix using
 the current information available in the node's hierarchy at the time the method is
 called, also correctly resolving the implicit `xml` prefix.

Syntax
------


```js
createNSResolver(nodeResolver)
```

### Parameters

`nodeResolver`

A `Node` to be used as a context for namespace resolution.

### Return value

 An `XPathNSResolver` object which resolves namespaces with respect to the
 definitions in scope for a specified node.

Specifications
--------------

| Specification |
| --- |
| DOM Standard # dom-xpathevaluatorbase-creatensresolver |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Document.createNSResolver()`
* `XPathExpression`
BaseAudioContext: currentTime property
======================================

 The `currentTime` read-only property of the `BaseAudioContext`
 interface returns a double representing an ever-increasing hardware timestamp in seconds that
 can be used for scheduling audio playback, visualizing timelines, etc. It starts at 0.

Value
-----

A floating point number.

Examples
--------


```js
const audioCtx = new AudioContext();
// Older webkit/blink browsers require a prefix

// …

console.log(audioCtx.currentTime);
```

Reduced time precision
----------------------

 To offer protection against timing attacks and fingerprinting, the precision of
 `audioCtx.currentTime` might get rounded depending on browser settings.
 In Firefox, the `privacy.reduceTimerPrecision` preference is enabled by
 default and defaults to 20us in Firefox 59; in 60 it will be 2ms.


```js
// reduced time precision (2ms) in Firefox 60
audioCtx.currentTime;
// 23.404
// 24.192
// 25.514
// …

// reduced time precision with `privacy.resistFingerprinting` enabled
audioCtx.currentTime;
// 49.8
// 50.6
// 51.7
// …
```


 In Firefox, you can also enabled `privacy.resistFingerprinting`, the
 precision will be 100ms or the value of
 `privacy.resistFingerprinting.reduceTimerPrecision.microseconds`, whichever
 is larger.

Specifications
--------------

| Specification |
| --- |
| Web Audio API # dom-baseaudiocontext-currenttime |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Using Web Audio API
BaseAudioContext: createDynamicsCompressor() method
===================================================

 The `createDynamicsCompressor()` method of the `BaseAudioContext` Interface is used to create a
 `DynamicsCompressorNode`, which can be used to apply compression to an
 audio signal.

 Compression lowers the volume of the loudest parts of the signal and raises the volume
 of the softest parts. Overall, a louder, richer, and fuller sound can be achieved. It is
 especially important in games and musical applications where large numbers of individual
 sounds are played simultaneously, where you want to control the overall signal level and
 help avoid clipping (distorting) of the audio output.


**Note:** The `DynamicsCompressorNode()`
 constructor is the recommended way to create a `DynamicsCompressorNode`; see
 Creating an AudioNode.


Syntax
------


```js
createDynamicsCompressor()
```

### Parameters

None.

### Return value

A `DynamicsCompressorNode`.

Examples
--------

 The code below demonstrates a simple usage of `createDynamicsCompressor()`
 to add compression to an audio track. For a more complete example, have a look at our basic Compressor example (view the source code).


```js
// Create a MediaElementAudioSourceNode
// Feed the HTMLMediaElement into it
const source = audioCtx.createMediaElementSource(myAudio);

// Create a compressor node
const compressor = audioCtx.createDynamicsCompressor();
compressor.threshold.setValueAtTime(-50, audioCtx.currentTime);
compressor.knee.setValueAtTime(40, audioCtx.currentTime);
compressor.ratio.setValueAtTime(12, audioCtx.currentTime);
compressor.attack.setValueAtTime(0, audioCtx.currentTime);
compressor.release.setValueAtTime(0.25, audioCtx.currentTime);

// connect the AudioBufferSourceNode to the destination
source.connect(audioCtx.destination);

button.onclick = () => {
  const active = button.getAttribute("data-active");
  if (active === "false") {
    button.setAttribute("data-active", "true");
    button.textContent = "Remove compression";

    source.disconnect(audioCtx.destination);
    source.connect(compressor);
    compressor.connect(audioCtx.destination);
  } else if (active === "true") {
    button.setAttribute("data-active", "false");
    button.textContent = "Add compression";

    source.disconnect(compressor);
    compressor.disconnect(audioCtx.destination);
    source.connect(audioCtx.destination);
  }
};
```

Specifications
--------------

| Specification |
| --- |
| Web Audio API # dom-baseaudiocontext-createdynamicscompressor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Using the Web Audio API
BaseAudioContext: state property
================================

 The `state` read-only property of the `BaseAudioContext`
 interface returns the current state of the `AudioContext`.

Value
-----

A string. Possible values are:

`suspended`

 The audio context has been suspended (with the
 `AudioContext.suspend()` method.)


`running`

The audio context is running normally.

`closed`

 The audio context has been closed (with the
 `AudioContext.close()` method.)


Examples
--------

### Handling state changes

 The following snippet is taken from our AudioContext states demo (see it running live.) The `onstatechange` handler is used to log the
 current state to the console every time it changes.


```js
audioCtx.onstatechange = () => {
  console.log(audioCtx.state);
};
```

### Resuming interrupted play states in iOS Safari

 In iOS Safari, when a user leaves the page (e.g. switches tabs, minimizes the browser, or
 turns off the screen)
 the audio context's state changes to "interrupted" and needs to be resumed. For example:


```js
function play() {
  if (audioCtx.state === "interrupted") {
    audioCtx.resume().then(() => play());
    return;
  }
  // rest of the play() function
}
```

Specifications
--------------

| Specification |
| --- |
| Web Audio API # dom-baseaudiocontext-state |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Using the Web Audio API
BaseAudioContext: createConstantSource() method
===============================================

 The **`createConstantSource()`**
 property of the `BaseAudioContext` interface creates a
 `ConstantSourceNode` object, which is an audio source that continuously
 outputs a monaural (one-channel) sound signal whose samples all have the same
 value.


**Note:** The `ConstantSourceNode()`
 constructor is the recommended way to create a `ConstantSourceNode`; see
 Creating an AudioNode.


Syntax
------


```js
createConstantSource()
```

### Parameters

None.

### Return value

A `ConstantSourceNode` instance.

Specifications
--------------

| Specification |
| --- |
| Web Audio API # dom-baseaudiocontext-createconstantsource |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
BaseAudioContext: createWaveShaper() method
===========================================

 The `createWaveShaper()` method of the `BaseAudioContext`
 interface creates a `WaveShaperNode`, which represents a non-linear
 distortion. It is used to apply distortion effects to your audio.


**Note:** The `WaveShaperNode()`
 constructor is the recommended way to create a `WaveShaperNode`; see
 Creating an AudioNode.


Syntax
------


```js
createWaveShaper()
```

### Parameters

None.

### Return value

A `WaveShaperNode`.

Examples
--------

 The following example shows basic usage of an AudioContext to create a wave shaper node.
 For more complete applied examples/information, check out our Voice-change-O-matic demo (see app.js lines 108–193 for relevant code).


**Note:** Sigmoid functions are commonly used for distortion curves
 because of their natural properties. Their S-shape, for instance, helps create a
 smoother sounding result. We found the below distortion curve code on Stack Overflow.



```js
const audioCtx = new AudioContext();
const distortion = audioCtx.createWaveShaper();

// …

function makeDistortionCurve(amount) {
  const k = typeof amount === "number" ? amount : 50;
  const n_samples = 44100;
  const curve = new Float32Array(n_samples);
  const deg = Math.PI / 180;

  for (let i = 0; i < n_samples; i++) {
    const x = (i \* 2) / n_samples - 1;
    curve[i] = ((3 + k) \* x \* 20 \* deg) / (Math.PI + k \* Math.abs(x));
  }
  return curve;
}

// …

distortion.curve = makeDistortionCurve(400);
distortion.oversample = "4x";
```

Specifications
--------------

| Specification |
| --- |
| Web Audio API # dom-baseaudiocontext-createwaveshaper |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Using the Web Audio API
BaseAudioContext: createIIRFilter() method
==========================================

 The **`createIIRFilter()`** method of the `BaseAudioContext` interface creates an `IIRFilterNode`,
 which represents a general **infinite impulse response** (IIR) filter which can be configured to serve as various types
 of filter.


**Note:** The `IIRFilterNode()`
 constructor is the recommended way to create a `IIRFilterNode`; see
 Creating an AudioNode.


Syntax
------


```js
createIIRFilter(feedforward, feedback)
```

### Parameters

`feedforward`

 An array of floating-point values specifying the feedforward (numerator)
 coefficients for the transfer function of the IIR filter. The maximum length of this
 array is 20, and at least one value must be nonzero.


`feedback`

 An array of floating-point values specifying the feedback (denominator) coefficients
 for the transfer function of the IIR filter. This array may have up to 20 members, the
 first of which must not be zero.


### Return value

 An `IIRFilterNode` implementing the filter with the specified feedback and
 feedforward coefficient arrays.

### Exceptions

`InvalidStateError` `DOMException`

 Thrown if all of the `feedforward` coefficients are 0, or if the first
 `feedback` coefficient is 0.


`NotSupportedError` `DOMException`

Thrown if one or both of the input arrays exceeds 20 members.

Specifications
--------------

| Specification |
| --- |
| Web Audio API # dom-baseaudiocontext-createiirfilter |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Using the Web Audio API
* `IIRFilterNode`
* `AudioNode`
BaseAudioContext: createBiquadFilter() method
=============================================

 The `createBiquadFilter()` method of the `BaseAudioContext`
 interface creates a `BiquadFilterNode`, which represents a second order
 filter configurable as several different common filter types.


**Note:** The `BiquadFilterNode()` constructor is the
 recommended way to create a `BiquadFilterNode`; see
 Creating an AudioNode.


Syntax
------


```js
createBiquadFilter()
```

### Parameters

None.

### Return value

A `BiquadFilterNode`.

Examples
--------

 The following example shows basic usage of an AudioContext to create a Biquad filter node.
 For more complete applied examples/information, check out our Voice-change-O-matic demo (see app.js lines 108–193 for relevant code).


```js
const audioCtx = new AudioContext();

//set up the different audio nodes we will use for the app
const analyser = audioCtx.createAnalyser();
const distortion = audioCtx.createWaveShaper();
const gainNode = audioCtx.createGain();
const biquadFilter = audioCtx.createBiquadFilter();
const convolver = audioCtx.createConvolver();

// connect the nodes together

source = audioCtx.createMediaStreamSource(stream);
source.connect(analyser);
analyser.connect(distortion);
distortion.connect(biquadFilter);
biquadFilter.connect(convolver);
convolver.connect(gainNode);
gainNode.connect(audioCtx.destination);

// Manipulate the Biquad filter

biquadFilter.type = "lowshelf";
biquadFilter.frequency.setValueAtTime(1000, audioCtx.currentTime);
biquadFilter.gain.setValueAtTime(25, audioCtx.currentTime);
```

Specifications
--------------

| Specification |
| --- |
| Web Audio API # dom-baseaudiocontext-createbiquadfilter |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Using the Web Audio API
BaseAudioContext: createChannelSplitter() method
================================================

 The `createChannelSplitter()` method of the `BaseAudioContext` Interface is used to create a `ChannelSplitterNode`,
 which is used to access the individual channels of an audio stream and process them separately.


**Note:** The `ChannelSplitterNode()`
 constructor is the recommended way to create a `ChannelSplitterNode`; see
 Creating an AudioNode.


Syntax
------


```js
createChannelSplitter(numberOfOutputs)
```

### Parameters

`numberOfOutputs`

 The number of channels in the input audio stream that you want to output separately;
 the default is 6 if this parameter is not specified.


### Return value

A `ChannelSplitterNode`.

Examples
--------

 The following simple example shows how you could separate a stereo track (say, a piece
 of music), and process the left and right channel differently. To use them, you need to
 use the second and third parameters of the `AudioNode.connect(AudioNode)`
 method, which allow you to specify the index of the channel to connect from and the
 index of the channel to connect to.


```js
const ac = new AudioContext();
ac.decodeAudioData(someStereoBuffer, (data) => {
  const source = ac.createBufferSource();
  source.buffer = data;
  const splitter = ac.createChannelSplitter(2);
  source.connect(splitter);
  const merger = ac.createChannelMerger(2);

  // Reduce the volume of the left channel only
  const gainNode = ac.createGain();
  gainNode.gain.setValueAtTime(0.5, ac.currentTime);
  splitter.connect(gainNode, 0);

  // Connect the splitter back to the second input of the merger: we
  // effectively swap the channels, here, reversing the stereo image.
  gainNode.connect(merger, 0, 1);
  splitter.connect(merger, 1, 0);

  const dest = ac.createMediaStreamDestination();

  // Because we have used a ChannelMergerNode, we now have a stereo
  // MediaStream we can use to pipe the Web Audio graph to WebRTC,
  // MediaRecorder, etc.
  merger.connect(dest);
});
```

Specifications
--------------

| Specification |
| --- |
| Web Audio API # dom-baseaudiocontext-createchannelsplitter |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Using the Web Audio API
BaseAudioContext: createOscillator() method
===========================================

 The `createOscillator()` method of the `BaseAudioContext`
 interface creates an `OscillatorNode`, a source representing a periodic
 waveform. It basically generates a constant tone.


**Note:** The `OscillatorNode()`
 constructor is the recommended way to create a `OscillatorNode`; see
 Creating an AudioNode.


Syntax
------


```js
createOscillator()
```

### Parameters

None.

### Return value

An `OscillatorNode`.

Examples
--------

 The following example shows basic usage of an AudioContext to create an oscillator
 node. For applied examples/information, check out our Violent Theremin demo (see app.js for relevant code); also see our `OscillatorNode` page for
 more information.


```js
// create web audio api context
const audioCtx = new AudioContext();

// create Oscillator node
const oscillator = audioCtx.createOscillator();

oscillator.type = "square";
oscillator.frequency.setValueAtTime(3000, audioCtx.currentTime); // value in hertz
oscillator.connect(audioCtx.destination);
oscillator.start();
```

Specifications
--------------

| Specification |
| --- |
| Web Audio API # dom-baseaudiocontext-createoscillator |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Using the Web Audio API
BaseAudioContext: createChannelMerger() method
==============================================

 The `createChannelMerger()` method of the `BaseAudioContext` interface creates a `ChannelMergerNode`,
 which combines channels from multiple audio streams into a single audio stream.


**Note:** The `ChannelMergerNode()` constructor is the
 recommended way to create a `ChannelMergerNode`; see
 Creating an AudioNode.


Syntax
------


```js
createChannelMerger(numberOfInputs)
```

### Parameters

`numberOfInputs`

 The number of channels in the input audio streams, which the output stream will
 contain; the default is 6 if this parameter is not specified.


### Return value

A `ChannelMergerNode`.

Examples
--------

 The following example shows how you could separate a stereo track (say, a piece of
 music), and process the left and right channel differently. To use them, you need to use
 the second and third parameters of the `AudioNode.connect(AudioNode)`
 method, which allow you to specify both the index of the channel to connect from and the
 index of the channel to connect to.


```js
const ac = new AudioContext();
ac.decodeAudioData(someStereoBuffer, (data) => {
  const source = ac.createBufferSource();
  source.buffer = data;
  const splitter = ac.createChannelSplitter(2);
  source.connect(splitter);
  const merger = ac.createChannelMerger(2);

  // Reduce the volume of the left channel only
  const gainNode = ac.createGain();
  gainNode.gain.setValueAtTime(0.5, ac.currentTime);
  splitter.connect(gainNode, 0);

  // Connect the splitter back to the second input of the merger: we
  // effectively swap the channels, here, reversing the stereo image.
  gainNode.connect(merger, 0, 1);
  splitter.connect(merger, 1, 0);

  const dest = ac.createMediaStreamDestination();

  // Because we have used a ChannelMergerNode, we now have a stereo
  // MediaStream we can use to pipe the Web Audio graph to WebRTC,
  // MediaRecorder, etc.
  merger.connect(dest);
});
```

Specifications
--------------

| Specification |
| --- |
| Web Audio API # dom-baseaudiocontext-createchannelmerger |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Using the Web Audio API