Tone.js/Tone/core/context/AudioContext.ts
2019-07-23 11:28:33 -04:00

27 lines
607 B
TypeScript

/**
* The global audio context which is getable and assignable through
* getAudioContext and setAudioContext
*/
let globalContext: BaseAudioContext;
// @ts-ignore
globalContext = window.TONE_AUDIO_CONTEXT;
/**
* Returns the default system-wide AudioContext
*/
export function getAudioContext(): BaseAudioContext {
if (!globalContext) {
setAudioContext(new AudioContext());
}
return globalContext;
}
/**
* Set the default audio context
*/
export function setAudioContext(context: BaseAudioContext): void {
globalContext = context;
// @ts-ignore
window.TONE_AUDIO_CONTEXT = globalContext;
}