Mercurial > hg > webaudioevaluationtool
comparison core.js @ 1535:d31600062d1c
Feature #1287: Padding added when looping is enabled to give synchronised looping.
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Thu, 23 Jul 2015 10:10:38 +0100 |
parents | f9e50328a26a |
children | 97ae294cdfb8 |
comparison
equal
deleted
inserted
replaced
1534:f9e50328a26a | 1535:d31600062d1c |
---|---|
805 }; | 805 }; |
806 } | 806 } |
807 return ready; | 807 return ready; |
808 }; | 808 }; |
809 | 809 |
810 this.setSynchronousLoop = function() { | |
811 // Pads the signals so they are all exactly the same length | |
812 if (this.audioObjectsReady) | |
813 { | |
814 var length = 0; | |
815 var lens = []; | |
816 var maxId; | |
817 for (var i=0; i<this.audioObjects.length; i++) | |
818 { | |
819 lens.push(this.audioObjects[i].buffer.length); | |
820 if (length < this.audioObjects[i].buffer.length) | |
821 { | |
822 length = this.audioObjects[i].buffer.length; | |
823 maxId = i; | |
824 } | |
825 } | |
826 // Perform difference | |
827 for (var i=0; i<lens.length; i++) | |
828 { | |
829 lens[i] = length - lens[i]; | |
830 } | |
831 // Extract the audio and zero-pad | |
832 for (var i=0; i<lens.length; i++) | |
833 { | |
834 var orig = this.audioObjects[i].buffer; | |
835 var hold = audioContext.createBuffer(orig.numberOfChannels,length,orig.sampleRate); | |
836 for (var c=0; c<orig.numberOfChannels; c++) | |
837 { | |
838 var inData = hold.getChannelData(c); | |
839 var outData = orig.getChannelData(c); | |
840 for (var n=0; n<orig.length; n++) | |
841 {inData[n] = outData[n];} | |
842 } | |
843 this.audioObjects[i].buffer = hold; | |
844 delete orig; | |
845 } | |
846 } | |
847 }; | |
848 | |
810 } | 849 } |
811 | 850 |
812 function audioObject(id) { | 851 function audioObject(id) { |
813 // The main buffer object with common control nodes to the AudioEngine | 852 // The main buffer object with common control nodes to the AudioEngine |
814 | 853 |