Skip to content
This repository has been archived by the owner on Jun 9, 2019. It is now read-only.

Loading wav's from a file not working on Chrome(59.0.3071.86) and Opera(45.0.2552.888). #66

Open
0x4C4A opened this issue Jun 15, 2017 · 0 comments

Comments

@0x4C4A
Copy link

0x4C4A commented Jun 15, 2017

Posting this to help out anyone else, who stumbles upon this problem. I don't really know how to properly implement this, but here's a diff of a solution that helped me.

Breakage seems to have been caused by a changing in the web audio API.

--- a/timbre.dev.js
+++ b/timbre.dev.js
@@ -3527,34 +3527,39 @@
 
                 var buffer;
                 try {
-                    buffer = ctx.createBuffer(data.buffer, false);
+                    buffer = ctx.decodeAudioData(data.buffer).then(success, failure);
                 } catch (e) {
                     return onloadedmetadata(false);
                 }
 
-                samplerate = ctx.sampleRate;
-                channels   = buffer.numberOfChannels;
-                if (channels === 2) {
-                    bufferL = buffer.getChannelData(0);
-                    bufferR = buffer.getChannelData(1);
-                } else {
-                    bufferL = bufferR = buffer.getChannelData(0);
-                }
-                duration = bufferL.length / samplerate;
+                function success(buffer){
+                    samplerate = ctx.sampleRate;
+                    channels   = buffer.numberOfChannels;
+                    if (channels === 2) {
+                        bufferL = buffer.getChannelData(0);
+                        bufferR = buffer.getChannelData(1);
+                    } else {
+                        bufferL = bufferR = buffer.getChannelData(0);
+                    }
+                    duration = bufferL.length / samplerate;
 
-                var mixdown = new Float32Array(bufferL);
-                for (var i = 0, imax = mixdown.length; i < imax; ++i) {
-                    mixdown[i] = (mixdown[i] + bufferR[i]) * 0.5;
-                }
+                    var mixdown = new Float32Array(bufferL);
+                    for (var i = 0, imax = mixdown.length; i < imax; ++i) {
+                        mixdown[i] = (mixdown[i] + bufferR[i]) * 0.5;
+                    }
 
-                onloadedmetadata({
-                    samplerate: samplerate,
-                    channels  : channels,
-                    buffer    : [mixdown, bufferL, bufferR],
-                    duration  : duration
-                });
+                    onloadedmetadata({
+                        samplerate: samplerate,
+                        channels  : channels,
+                        buffer    : [mixdown, bufferL, bufferR],
+                        duration  : duration
+                    });
 
-                onloadeddata();
+                    onloadeddata();
+                }
+                function failure(){
+                    onloadedmetadata(false);
+                }
             };
 
             return function(src, onloadedmetadata, onloadeddata) {
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant