Skip to content

Commit bf853b1

Browse files
committed
remove multiple calls to setContext, do it in audiocontext
When we load tone.js modules we need to ensure that they run in the same audio context. Calling setContext multiple times results in multiple message handlers in the Tone worker node (a separate issue we should look into!)
1 parent 8e5e312 commit bf853b1

File tree

4 files changed

+6
-10
lines changed

4 files changed

+6
-10
lines changed

src/audiocontext.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict';
22

3-
define(['StartAudioContext'], function (require, StartAudioContext) {
3+
define(['StartAudioContext', 'Tone/core/Context', 'Tone/core/Tone'], function (require, StartAudioContext, Context, Tone) {
44
// Create the Audio Context
5-
var audiocontext = new window.AudioContext();
5+
const audiocontext = new window.AudioContext();
6+
Tone.context.dispose();
7+
Tone.setContext(audiocontext);
68

79
/**
810
* <p>Returns the Audio Context for this sketch. Useful for users

src/envelope.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ define(function (require) {
88
var Scale = require('Tone/signal/Scale');
99
var TimelineSignal = require('Tone/signal/TimelineSignal');
1010

11-
var Tone = require('Tone/core/Tone');
12-
Tone.setContext( p5sound.audiocontext);
13-
1411
/**
1512
* <p>Envelopes are pre-defined amplitude distribution over time.
1613
* Typically, envelopes are used to control the output volume

src/master.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
'use strict';
22

3+
const audiocontext = require('audiocontext');
4+
35
define(function () {
46

57
/**
68
* Master contains AudioContext and the master sound output.
79
*/
810
var Master = function() {
9-
var audiocontext = p5.prototype.getAudioContext();
1011
this.input = audiocontext.createGain();
1112
this.output = audiocontext.createGain();
1213

src/signal.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ define(function (require) {
99
var Mult = require('Tone/signal/Multiply');
1010
var Scale = require('Tone/signal/Scale');
1111

12-
var Tone = require('Tone/core/Tone');
13-
var p5sound = require('master');
14-
Tone.setContext( p5sound.audiocontext);
15-
1612
/**
1713
* <p>p5.Signal is a constant audio-rate signal used by p5.Oscillator
1814
* and p5.Envelope for modulation math.</p>

0 commit comments

Comments
 (0)