From faa4019b27089b8f6f8d041011ed02e1d3d52ebb Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sat, 18 Jun 2022 00:54:36 +0200 Subject: [PATCH] dont use tone audio context --- packages/webaudio/webaudio.mjs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/webaudio/webaudio.mjs b/packages/webaudio/webaudio.mjs index 8cd3b70b..1eebb09c 100644 --- a/packages/webaudio/webaudio.mjs +++ b/packages/webaudio/webaudio.mjs @@ -7,9 +7,18 @@ This program is free software: you can redistribute it and/or modify it under th // import { Pattern, getFrequency, patternify2 } from '@strudel.cycles/core'; import * as strudel from '@strudel.cycles/core'; import { fromMidi } from '@strudel.cycles/core'; -import { Tone } from '@strudel.cycles/tone'; const { Pattern } = strudel; +// export const getAudioContext = () => Tone.getContext().rawContext; + +let audioContext; +export const getAudioContext = () => { + if (!audioContext) { + audioContext = new AudioContext(); + } + return audioContext; +}; + const getFilter = (ac, type, frequency, Q) => { const filter = ac.createBiquadFilter(); filter.type = type; @@ -31,7 +40,7 @@ const getADSR = (ac, attack, decay, sustain, release, velocity, begin, end) => { Pattern.prototype.out = function () { return this.onTrigger((t, hap, ct) => { - const ac = Tone.getContext().rawContext; + const ac = getAudioContext(); // calculate correct time (tone.js workaround) t = ac.currentTime + t - ct; // destructure value