Skip to content

Commit

Permalink
update reverb async
Browse files Browse the repository at this point in the history
  • Loading branch information
naomiaro committed Feb 24, 2022
1 parent f302e58 commit 30e2ddb
Show file tree
Hide file tree
Showing 8 changed files with 1,425 additions and 2,416 deletions.
23 changes: 22 additions & 1 deletion dist/waveform-playlist/js/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var playlist;
var toneCtx = Tone.getContext();
var audioCtx = toneCtx.rawContext;
var analyser = audioCtx.createAnalyser();
var offlineSetup = [];

var userMediaStream;
var constraints = { audio: true };
Expand Down Expand Up @@ -49,10 +50,11 @@ playlist = WaveformPlaylist.init({
//initialize the WAV exporter.
playlist.initExporter();

playlist.ee.on("audiorenderingstarting", function(offlineCtx) {
playlist.ee.on("audiorenderingstarting", function(offlineCtx, setup) {
// Set Tone offline to render effects properly.
const offlineContext = new Tone.OfflineContext(offlineCtx);
Tone.setContext(offlineContext);
offlineSetup = setup;
});

playlist.ee.on("audiorenderingfinished", function() {
Expand Down Expand Up @@ -83,6 +85,10 @@ playlist
effects: function(graphEnd, masterGainNode, isOffline) {
var reverb = new Tone.Reverb(1.2);

if (isOffline) {
offlineSetup.push(reverb.ready);
}

Tone.connect(graphEnd, reverb);
Tone.connect(reverb, masterGainNode);

Expand All @@ -99,6 +105,21 @@ playlist
{
src: "media/audio/BassDrums30.mp3",
name: "Drums",
effects: function(graphEnd, masterGainNode, isOffline) {
var reverb = new Tone.Reverb(5);

if (isOffline) {
offlineSetup.push(reverb.ready);
}

Tone.connect(graphEnd, reverb);
Tone.connect(reverb, masterGainNode);

return function cleanup() {
reverb.disconnect();
reverb.dispose();
}
}
},
])
.then(function () {
Expand Down
2 changes: 0 additions & 2 deletions dist/waveform-playlist/js/waveform-playlist.js

This file was deleted.

6 changes: 0 additions & 6 deletions dist/waveform-playlist/js/waveform-playlist.js.LICENSE.txt

This file was deleted.

23 changes: 22 additions & 1 deletion ghpages/js/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var playlist;
var toneCtx = Tone.getContext();
var audioCtx = toneCtx.rawContext;
var analyser = audioCtx.createAnalyser();
var offlineSetup = [];

var userMediaStream;
var constraints = { audio: true };
Expand Down Expand Up @@ -49,10 +50,11 @@ playlist = WaveformPlaylist.init({
//initialize the WAV exporter.
playlist.initExporter();

playlist.ee.on("audiorenderingstarting", function(offlineCtx) {
playlist.ee.on("audiorenderingstarting", function(offlineCtx, setup) {
// Set Tone offline to render effects properly.
const offlineContext = new Tone.OfflineContext(offlineCtx);
Tone.setContext(offlineContext);
offlineSetup = setup;
});

playlist.ee.on("audiorenderingfinished", function() {
Expand Down Expand Up @@ -83,6 +85,10 @@ playlist
effects: function(graphEnd, masterGainNode, isOffline) {
var reverb = new Tone.Reverb(1.2);

if (isOffline) {
offlineSetup.push(reverb.ready);
}

Tone.connect(graphEnd, reverb);
Tone.connect(reverb, masterGainNode);

Expand All @@ -99,6 +105,21 @@ playlist
{
src: "media/audio/BassDrums30.mp3",
name: "Drums",
effects: function(graphEnd, masterGainNode, isOffline) {
var reverb = new Tone.Reverb(5);

if (isOffline) {
offlineSetup.push(reverb.ready);
}

Tone.connect(graphEnd, reverb);
Tone.connect(reverb, masterGainNode);

return function cleanup() {
reverb.disconnect();
reverb.dispose();
}
}
},
])
.then(function () {
Expand Down
Loading

0 comments on commit 30e2ddb

Please sign in to comment.