mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-31 22:18:44 +00:00
27 lines
597 B
TypeScript
27 lines
597 B
TypeScript
/**
|
|
* The global audio context which is getable and assignable through
|
|
* getContext and setContext
|
|
*/
|
|
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;
|
|
}
|