2019-06-23 18:47:21 +00:00
|
|
|
/**
|
|
|
|
* The global audio context which is getable and assignable through
|
2019-07-23 15:28:33 +00:00
|
|
|
* getAudioContext and setAudioContext
|
2019-06-23 18:47:21 +00:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|