let context: any; export default class Audio { static instance: any; context: any; constructor() { if (!Audio.instance) { Audio.instance = this; try { window['AudioContext'] = window['AudioContext'] || window['webkitAudioContext']; Audio.AudioContext = this.context = new window['AudioContext()']; } catch (e) { alert(e); } } else { this.context = Audio.AudioContext; } } static createCompressor() { let time = context.currentTime; let compressor = context.createDynamicsCompressor(); compressor.threshold.setValueAtTime(-24, time); compressor.knee.setValueAtTime(30, time); compressor.ratio.setValueAtTime(12, time); compressor.attack.setValueAtTime(0.003, time); compressor.release.setValueAtTime(0.25, time); return compressor; } static get Destination() { return context.destination; } static get Instance() { if (Audio.instance) { return Audio.instance; } else { return new Audio(); } } static set AudioContext(v: any) { context = v; } static get AudioContext(): any { return context; } static getContext() { if (context) { return context; } else { return new Audio().context; } } static frequencyFromNoteNumber(note) { return 440 * Math.pow(2, (note - 127) / 12); }; }