comparison 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
comparison
equal deleted inserted replaced
1352:1a9545a4799f 1353:41574c5bc5ee
989 989
990 var bufferObj = this; 990 var bufferObj = this;
991 991
992 // Create callback to decode the data asynchronously 992 // Create callback to decode the data asynchronously
993 this.xmlRequest.onloadend = function() { 993 this.xmlRequest.onloadend = function() {
994 audioContext.decodeAudioData(bufferObj.xmlRequest.response, function(decodedData) { 994 // Use inbuilt WAVE decoder first
995 bufferObj.buffer = decodedData; 995 var waveObj = new WAVE();
996 calculateLoudness(bufferObj,"I"); 996 if (waveObj.open(bufferObj.xmlRequest.response) == 0)
997 997 {
998 }, function(){ 998 bufferObj.buffer = audioContext.createBuffer(waveObj.num_channels,waveObj.num_samples,waveObj.sample_rate);
999 // Should only be called if there was an error, but sometimes gets called continuously 999 for (var c=0; c<waveObj.num_channels; c++)
1000 // Check here if the error is genuine 1000 {
1001 if (bufferObj.buffer == undefined) { 1001 var buffer_ptr = bufferObj.buffer.getChannelData(c);
1002 // Genuine error 1002 for (var n=0; n<waveObj.num_samples; n++)
1003 console.log('FATAL - Error loading buffer on '+audioObj.id); 1003 {
1004 if (request.status == 404) 1004 buffer_ptr[n] = waveObj.decoded_data[c][n];
1005 { 1005 }
1006 console.log('FATAL - Fragment '+audioObj.id+' 404 error'); 1006 }
1007 console.log('URL: '+audioObj.url); 1007 delete waveObj;
1008 errorSessionDump('Fragment '+audioObj.id+' 404 error'); 1008 } else {
1009 } 1009 audioContext.decodeAudioData(bufferObj.xmlRequest.response, function(decodedData) {
1010 } 1010 bufferObj.buffer = decodedData;
1011 }); 1011 }, function(e){
1012 // Should only be called if there was an error, but sometimes gets called continuously
1013 // Check here if the error is genuine
1014 if (bufferObj.xmlRequest.response == undefined) {
1015 // Genuine error
1016 console.log('FATAL - Error loading buffer on '+audioObj.id);
1017 if (request.status == 404)
1018 {
1019 console.log('FATAL - Fragment '+audioObj.id+' 404 error');
1020 console.log('URL: '+audioObj.url);
1021 errorSessionDump('Fragment '+audioObj.id+' 404 error');
1022 }
1023 }
1024 });
1025 }
1026 if (bufferObj.buffer != undefined)
1027 {
1028 calculateLoudness(bufferObj,"I");
1029 }
1012 }; 1030 };
1013 this.progress = 0; 1031 this.progress = 0;
1014 this.progressCallback = function(event){ 1032 this.progressCallback = function(event){
1015 if (event.lengthComputable) 1033 if (event.lengthComputable)
1016 { 1034 {