diff core.js @ 1353:41574c5bc5ee

Added WAVE.js, conversion of some C scripts to JS for WAVE file manipulation. By default, will use the WAVE decoder first before fallback to browser decoders. All browsers now support Integer 8-/16-/24-/34-bit and IEEE Float 32 WAVE files.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Sat, 16 Jan 2016 14:51:02 +0000
parents a2b096969d59
children 3ba07a441364
line wrap: on
line diff
--- a/core.js	Fri Jan 15 11:04:23 2016 +0000
+++ b/core.js	Sat Jan 16 14:51:02 2016 +0000
@@ -991,24 +991,42 @@
 			
 			// Create callback to decode the data asynchronously
 			this.xmlRequest.onloadend = function() {
-				audioContext.decodeAudioData(bufferObj.xmlRequest.response, function(decodedData) {
-					bufferObj.buffer = decodedData;
-					calculateLoudness(bufferObj,"I");
-					
-				}, function(){
-					// Should only be called if there was an error, but sometimes gets called continuously
-					// Check here if the error is genuine
-					if (bufferObj.buffer == undefined) {
-						// Genuine error
-						console.log('FATAL - Error loading buffer on '+audioObj.id);
-						if (request.status == 404)
-						{
-							console.log('FATAL - Fragment '+audioObj.id+' 404 error');
-							console.log('URL: '+audioObj.url);
-							errorSessionDump('Fragment '+audioObj.id+' 404 error');
-						}
-					}
-				});
+                // Use inbuilt WAVE decoder first
+                var waveObj = new WAVE();
+                if (waveObj.open(bufferObj.xmlRequest.response) == 0)
+                {
+                    bufferObj.buffer = audioContext.createBuffer(waveObj.num_channels,waveObj.num_samples,waveObj.sample_rate);
+                    for (var c=0; c<waveObj.num_channels; c++)
+                    {
+                        var buffer_ptr = bufferObj.buffer.getChannelData(c);
+                        for (var n=0; n<waveObj.num_samples; n++)
+                        {
+                            buffer_ptr[n] = waveObj.decoded_data[c][n];
+                        }
+                    }
+                    delete waveObj;
+                } else {
+                    audioContext.decodeAudioData(bufferObj.xmlRequest.response, function(decodedData) {
+                        bufferObj.buffer = decodedData;
+                    }, function(e){
+                        // Should only be called if there was an error, but sometimes gets called continuously
+                        // Check here if the error is genuine
+                        if (bufferObj.xmlRequest.response == undefined) {
+                            // Genuine error
+                            console.log('FATAL - Error loading buffer on '+audioObj.id);
+                            if (request.status == 404)
+                            {
+                                console.log('FATAL - Fragment '+audioObj.id+' 404 error');
+                                console.log('URL: '+audioObj.url);
+                                errorSessionDump('Fragment '+audioObj.id+' 404 error');
+                            }
+                        }
+                    });
+                }
+                if (bufferObj.buffer != undefined)
+                {
+                    calculateLoudness(bufferObj,"I");
+                }
 			};
 			this.progress = 0;
 			this.progressCallback = function(event){