UNPKG

1.74 kBJavaScriptView Raw
1import { AudioContext as stdAudioContext, AudioWorkletNode as stdAudioWorkletNode, OfflineAudioContext as stdOfflineAudioContext, } from "standardized-audio-context";
2import { assert } from "../util/Debug.js";
3import { isDefined } from "../util/TypeCheck.js";
4/**
5 * Create a new AudioContext
6 */
7export function createAudioContext(options) {
8 return new stdAudioContext(options);
9}
10/**
11 * Create a new OfflineAudioContext
12 */
13export function createOfflineAudioContext(channels, length, sampleRate) {
14 return new stdOfflineAudioContext(channels, length, sampleRate);
15}
16/**
17 * A reference to the window object
18 * @hidden
19 */
20export const theWindow = typeof self === "object" ? self : null;
21/**
22 * If the browser has a window object which has an AudioContext
23 * @hidden
24 */
25export const hasAudioContext = theWindow &&
26 (theWindow.hasOwnProperty("AudioContext") ||
27 theWindow.hasOwnProperty("webkitAudioContext"));
28export function createAudioWorkletNode(context, name, options) {
29 assert(isDefined(stdAudioWorkletNode), "AudioWorkletNode only works in a secure context (https or localhost)");
30 return new (context instanceof (theWindow === null || theWindow === void 0 ? void 0 : theWindow.BaseAudioContext)
31 ? theWindow === null || theWindow === void 0 ? void 0 : theWindow.AudioWorkletNode
32 : stdAudioWorkletNode)(context, name, options);
33}
34/**
35 * This promise resolves to a boolean which indicates if the
36 * functionality is supported within the currently used browse.
37 * Taken from [standardized-audio-context](https://github.com/chrisguttandin/standardized-audio-context#issupported)
38 */
39export { isSupported as supported } from "standardized-audio-context";
40//# sourceMappingURL=AudioContext.js.map
\No newline at end of file