The BaseAudioContext
interface of the Web Audio API acts as a base definition for online and offline audio-processing graphs, as represented by AudioContext
and OfflineAudioContext
respectively. You wouldn't use BaseAudioContext
directly — you'd use its features via one of these two inheriting interfaces.
A BaseAudioContext
can be a target of events, therefore it implements the EventTarget
interface.
<div id="interfaceDiagram" style="display: inline-block; position: relative; width: 100%; padding-bottom: 11.666666666666666%; vertical-align: middle; overflow: hidden;"><svg style="display: inline-block; position: absolute; top: 0; left: 0;" viewbox="-50 0 600 70" preserveAspectRatio="xMinYMin meet"><a xlink:href="/docs/Web/API/EventTarget" target="_top"><rect x="1" y="1" width="110" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="56" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">EventTarget</text></a><polyline points="111,25 121,20 121,30 111,25" stroke="#D4DDE4" fill="none"/><line x1="121" y1="25" x2="151" y2="25" stroke="#D4DDE4"/><a xlink:href="/docs/Web/API/BaseAudioContext" target="_top"><rect x="151" y="1" width="160" height="50" fill="#F4F7F8" stroke="#D4DDE4" stroke-width="2px" /><text x="231" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">BaseAudioContext</text></a></svg></div>
a:hover text { fill: #0095DD; pointer-events: all;}
Properties
BaseAudioContext.audioWorklet
Read only Secure context- Returns the
AudioWorklet
object, which can be used to create and manageAudioNode
s in which JavaScript code implementing theAudioWorkletProcessor
interface are run in the background to process audio data. BaseAudioContext.currentTime
Read only- Returns a double representing an ever-increasing hardware time in seconds used for scheduling. It starts at
0
. BaseAudioContext.destination
Read only- Returns an
AudioDestinationNode
representing the final destination of all audio in the context. It can be thought of as the audio-rendering device. BaseAudioContext.listener
Read only- Returns the
AudioListener
object, used for 3D spatialization. BaseAudioContext.sampleRate
Read only- Returns a float representing the sample rate (in samples per second) used by all nodes in this context. The sample-rate of an
AudioContext
cannot be changed. BaseAudioContext.state
Read only- Returns the current state of the
AudioContext
.
Event handlers
BaseAudioContext.onstatechange
- An event handler that runs when an event of type
statechange
has fired. This occurs when theAudioContext
's state changes, due to the calling of one of the state change methods (AudioContext.suspend
,AudioContext.resume
, orAudioContext.close
).
Methods
Also implements methods from the interface EventTarget
.
BaseAudioContext.createAnalyser()
- Creates an
AnalyserNode
, which can be used to expose audio time and frequency data and for example to create data visualisations. BaseAudioContext.createBiquadFilter()
- Creates a
BiquadFilterNode
, which represents a second order filter configurable as several different common filter types: high-pass, low-pass, band-pass, etc
BaseAudioContext.createBuffer()
- Creates a new, empty
AudioBuffer
object, which can then be populated by data and played via anAudioBufferSourceNode
. BaseAudioContext.createBufferSource()
- Creates an
AudioBufferSourceNode
, which can be used to play and manipulate audio data contained within anAudioBuffer
object.AudioBuffer
s are created usingAudioContext.createBuffer
or returned byAudioContext.decodeAudioData
when it successfully decodes an audio track. BaseAudioContext.createConstantSource()
- 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. BaseAudioContext.createChannelMerger()
- Creates a
ChannelMergerNode
, which is used to combine channels from multiple audio streams into a single audio stream. BaseAudioContext.createChannelSplitter()
- Creates a
ChannelSplitterNode
, which is used to access the individual channels of an audio stream and process them separately. BaseAudioContext.createConvolver()
- Creates a
ConvolverNode
, which can be used to apply convolution effects to your audio graph, for example a reverberation effect. BaseAudioContext.createDelay()
- Creates a
DelayNode
, which is used to delay the incoming audio signal by a certain amount. This node is also useful to create feedback loops in a Web Audio API graph. BaseAudioContext.createDynamicsCompressor()
- Creates a
DynamicsCompressorNode
, which can be used to apply acoustic compression to an audio signal. BaseAudioContext.createGain()
- Creates a
GainNode
, which can be used to control the overall volume of the audio graph. BaseAudioContext.createIIRFilter()
- Creates an
IIRFilterNode
, which represents a second order filter configurable as several different common filter types. BaseAudioContext.createOscillator()
- Creates an
OscillatorNode
, a source representing a periodic waveform. It basically generates a tone. BaseAudioContext.createPanner()
- Creates a
PannerNode
, which is used to spatialise an incoming audio stream in 3D space. BaseAudioContext.createPeriodicWave()
- Creates a
PeriodicWave
, used to define a periodic waveform that can be used to determine the output of anOscillatorNode
. BaseAudioContext.createScriptProcessor()
- Creates a
ScriptProcessorNode
, which can be used for direct audio processing via JavaScript. BaseAudioContext.createStereoPanner()
- Creates a
StereoPannerNode
, which can be used to apply stereo panning to an audio source. BaseAudioContext.createWaveShaper()
- Creates a
WaveShaperNode
, which is used to implement non-linear distortion effects. BaseAudioContext.decodeAudioData()
- Asynchronously decodes audio file data contained in an
ArrayBuffer
. In this case, the ArrayBuffer is usually loaded from anXMLHttpRequest
'sresponse
attribute after setting theresponseType
toarraybuffer
. This method only works on complete files, not fragments of audio files.
Examples
Basic audio context declaration:
const audioContext = new AudioContext();
Cross browser variant:
const AudioContext = window.AudioContext || window.webkitAudioContext; const audioContext = new AudioContext(); const oscillatorNode = audioContext.createOscillator(); const gainNode = audioContext.createGain(); const finish = audioContext.destination;
Specifications
Specification | Status | Comment |
---|---|---|
Web Audio API The definition of 'BaseAudioContext' in that specification. |
Working Draft |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
BaseAudioContext | Chrome Full support Yes | Edge Full support ≤18 | Firefox Full support 53 | IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 53 | Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support Yes |
audioWorklet | Chrome Full support 66 | Edge Full support 79 | Firefox ? | IE No support No | Opera Full support Yes | Safari No support No | WebView Android Full support 66 | Chrome Android Full support 66 | Firefox Android ? | Opera Android Full support Yes | Safari iOS No support No | Samsung Internet Android Full support 9.0 |
createAnalyser | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
createBiquadFilter | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
createBuffer | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
createBufferSource | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
createChannelMerger | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
createChannelSplitter | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
createConstantSource | Chrome Full support 56 | Edge Full support ≤79 | Firefox Full support 53 | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 56 | Chrome Android Full support 56 | Firefox Android Full support 53 | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 6.0 |
createConvolver | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
createDelay | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
createDynamicsCompressor | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
createGain | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
createIIRFilter | Chrome Full support 49 | Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera Full support Yes | Safari No support No | WebView Android Full support 49 | Chrome Android Full support 49 | Firefox Android
Full support
53
| Opera Android Full support Yes | Safari iOS No support No | Samsung Internet Android Full support 5.0 |
createOscillator | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
createPanner | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
createPeriodicWave | Chrome
Full support
59
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android
Full support
59
| Chrome Android
Full support
59
| Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android
Full support
7.0
|
createScriptProcessor | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
createStereoPanner | Chrome Full support 42 | Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera No support No | Safari No support No | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android
Full support
53
| Opera Android No support No | Safari iOS No support No | Samsung Internet Android Full support Yes |
createWaveShaper | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
currentTime | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
decodeAudioData | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
destination | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
listener | Chrome
Full support
10
| Edge Full support ≤18 | Firefox Full support 53 | IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android Full support 53 | Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
onstatechange | Chrome Full support 43 | Edge Full support ≤79 | Firefox
Full support
53
| IE No support No | Opera Full support Yes | Safari
Full support
9
| WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android
Full support
53
| Opera Android Full support Yes | Safari iOS
Full support
9
| Samsung Internet Android Full support Yes |
sampleRate | Chrome
Full support
10
| Edge Full support ≤18 | Firefox
Full support
53
| IE No support No | Opera
Full support
22
| Safari
Full support
6
| WebView Android Full support Yes | Chrome Android Full support 33 | Firefox Android
Full support
53
| Opera Android
Full support
22
| Safari iOS
Full support
6
| Samsung Internet Android Full support 2.0 |
state | Chrome Full support 43 | Edge Full support ≤79 | Firefox
Full support
53
| IE No support No | Opera Full support Yes | Safari
Full support
9
| WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android
Full support
53
| Opera Android Full support Yes | Safari iOS
Full support
9
| Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- See implementation notes.
- See implementation notes.
- Requires a vendor prefix or different name for use.
- Requires a vendor prefix or different name for use.