W3cubDocs

/DOM

OfflineAudioContext.constructor

The OfflineAudioContext() constructor creates a new OfflineAudioContext object instance.

Syntax

var myOfflineAudio = new OfflineAudioContext(numOfChannels,length,sampleRate);

Parameters

numOfChannels
An integer representing the number of channels this buffer should have. Implementations must support a minimum 32 channels.
length
An integer representing the size of the buffer in sample-frames.
sampleRate
The sample-rate of the linear audio data in sample-frames per second. An implementation must support sample-rates in at least the range 22050 to 96000, with 44100 being the most commonly used.

It is important to note that, whereas you can create a new AudioContext using the new AudioContext() constructor with no arguments, the OfflineAudioContext() constructor requires three arguments. This works in exactly the same way as when you create a new AudioBuffer with the AudioContext.createBuffer method. For more detail, read Audio buffers: frames, samples and channels from our Basic concepts guide.

Note: Like a regular AudioContext, an OfflineAudioContext can be the target of events, therefore it implements the EventTarget interface.

Example

// define online and offline audio context

var audioCtx = new AudioContext();
var offlineCtx = new OfflineAudioContext(2,44100*40,44100);

source = offlineCtx.createBufferSource();

// etc...

Note: For a full working example, see our offline-audio-context-promise Github repo (see the source code too.)

Specifications

Specification Status Comment
Web Audio API
The definition of 'OfflineAudioContext' in that specification.
Working Draft

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes)
(Yes) No support

(Yes)

No support
Feature Android Android Webview Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support No support (Yes)
(Yes) No support (Yes) No support (Yes)

© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext/OfflineAudioContext