From 4dfa89f0a0dfe23e95a722c9377c9ad064e45323 Mon Sep 17 00:00:00 2001
From: Paul Kaplan <pkaplan@media.mit.edu>
Date: Mon, 14 Aug 2017 15:36:19 -0400
Subject: [PATCH] Use callback method and vendor prefix offline audio contexts

---
 src/containers/sound-editor.jsx | 6 +++---
 src/lib/audio/audio-effects.js  | 7 ++++---
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/containers/sound-editor.jsx b/src/containers/sound-editor.jsx
index 67c4b1b5f..4a1b98b56 100644
--- a/src/containers/sound-editor.jsx
+++ b/src/containers/sound-editor.jsx
@@ -112,9 +112,9 @@ class SoundEditor extends React.Component {
     }
     handleEffect (name) {
         const effects = new AudioEffects(this.audioBufferPlayer.buffer, name);
-        effects.process().then(newBuffer => {
-            const samples = newBuffer.getChannelData(0);
-            const sampleRate = newBuffer.sampleRate;
+        effects.process(({renderedBuffer}) => {
+            const samples = renderedBuffer.getChannelData(0);
+            const sampleRate = renderedBuffer.sampleRate;
             this.submitNewSamples(samples, sampleRate);
             this.handlePlay();
         });
diff --git a/src/lib/audio/audio-effects.js b/src/lib/audio/audio-effects.js
index 187c6ce6b..ead04bf50 100644
--- a/src/lib/audio/audio-effects.js
+++ b/src/lib/audio/audio-effects.js
@@ -38,7 +38,7 @@ class AudioEffects {
             buffer.getChannelData(0).reverse();
             break;
         }
-
+        const OfflineAudioContext = window.OfflineAudioContext || window.webkitOfflineAudioContext;
         this.audioContext = new OfflineAudioContext(1, sampleCount, buffer.sampleRate);
         this.buffer = buffer;
         this.source = this.audioContext.createBufferSource();
@@ -46,7 +46,7 @@ class AudioEffects {
         this.source.playbackRate.value = playbackRate;
         this.name = name;
     }
-    process () {
+    process (done) {
         // Some effects need to use more nodes and must expose an input and output
         let input;
         let output;
@@ -75,7 +75,8 @@ class AudioEffects {
 
         this.source.start();
 
-        return this.audioContext.startRendering();
+        this.audioContext.startRendering();
+        this.audioContext.oncomplete = done;
     }
 }
 
-- 
GitLab