comparison core.js @ 1523:ed1d17b94752

Bug #1391: Fixed for non-looped playback
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Mon, 14 Sep 2015 11:22:38 +0100
parents 40face84bd13
children 3d13f019c3e6
comparison
equal deleted inserted replaced
1522:40face84bd13 1523:ed1d17b94752
712 this.fooGain = audioContext.createGain(); 712 this.fooGain = audioContext.createGain();
713 this.fooGain.gain = 0; 713 this.fooGain.gain = 0;
714 714
715 // Use this to detect playback state: 0 - stopped, 1 - playing 715 // Use this to detect playback state: 0 - stopped, 1 - playing
716 this.status = 0; 716 this.status = 0;
717 this.audioObjectsReady = false;
718 717
719 // Connect both gains to output 718 // Connect both gains to output
720 this.outputGain.connect(audioContext.destination); 719 this.outputGain.connect(audioContext.destination);
721 this.fooGain.connect(audioContext.destination); 720 this.fooGain.connect(audioContext.destination);
722 721
730 // Create store for new audioObjects 729 // Create store for new audioObjects
731 this.audioObjects = []; 730 this.audioObjects = [];
732 731
733 this.play = function(id) { 732 this.play = function(id) {
734 // Start the timer and set the audioEngine state to playing (1) 733 // Start the timer and set the audioEngine state to playing (1)
735 if (this.status == 0) { 734 if (this.status == 0 && this.loopPlayback) {
736 // Check if all audioObjects are ready 735 // Check if all audioObjects are ready
737 if (this.audioObjectsReady == false) { 736 if(this.checkAllReady())
738 this.audioObjectsReady = this.checkAllReady(); 737 {
739 }
740 if (this.audioObjectsReady == true) {
741 this.timer.startTest();
742 if (this.loopPlayback)
743 {this.setSynchronousLoop();}
744 this.status = 1; 738 this.status = 1;
745 } 739 this.setSynchronousLoop();
740 }
741 }
742 else
743 {
744 this.status = 1;
746 } 745 }
747 if (this.status== 1) { 746 if (this.status== 1) {
747 this.timer.startTest();
748 if (id == undefined) { 748 if (id == undefined) {
749 id = -1; 749 id = -1;
750 console.log('FATAL - Passed id was undefined - AudioEngineContext.play(id)');
751 return;
750 } else { 752 } else {
751 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]); 753 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]);
752 } 754 }
753 if (this.loopPlayback) { 755 if (this.loopPlayback) {
754 for (var i=0; i<this.audioObjects.length; i++) 756 for (var i=0; i<this.audioObjects.length; i++)
831 return ready; 833 return ready;
832 }; 834 };
833 835
834 this.setSynchronousLoop = function() { 836 this.setSynchronousLoop = function() {
835 // Pads the signals so they are all exactly the same length 837 // Pads the signals so they are all exactly the same length
836 if (this.audioObjectsReady) 838 var length = 0;
839 var lens = [];
840 var maxId;
841 for (var i=0; i<this.audioObjects.length; i++)
837 { 842 {
838 var length = 0; 843 lens.push(this.audioObjects[i].buffer.length);
839 var lens = []; 844 if (length < this.audioObjects[i].buffer.length)
840 var maxId;
841 for (var i=0; i<this.audioObjects.length; i++)
842 { 845 {
843 lens.push(this.audioObjects[i].buffer.length); 846 length = this.audioObjects[i].buffer.length;
844 if (length < this.audioObjects[i].buffer.length) 847 maxId = i;
845 { 848 }
846 length = this.audioObjects[i].buffer.length; 849 }
847 maxId = i; 850 // Perform difference
848 } 851 for (var i=0; i<lens.length; i++)
849 } 852 {
850 // Perform difference 853 lens[i] = length - lens[i];
851 for (var i=0; i<lens.length; i++) 854 }
855 // Extract the audio and zero-pad
856 for (var i=0; i<lens.length; i++)
857 {
858 var orig = this.audioObjects[i].buffer;
859 var hold = audioContext.createBuffer(orig.numberOfChannels,length,orig.sampleRate);
860 for (var c=0; c<orig.numberOfChannels; c++)
852 { 861 {
853 lens[i] = length - lens[i]; 862 var inData = hold.getChannelData(c);
854 } 863 var outData = orig.getChannelData(c);
855 // Extract the audio and zero-pad 864 for (var n=0; n<orig.length; n++)
856 for (var i=0; i<lens.length; i++) 865 {inData[n] = outData[n];}
857 { 866 }
858 var orig = this.audioObjects[i].buffer; 867 this.audioObjects[i].buffer = hold;
859 var hold = audioContext.createBuffer(orig.numberOfChannels,length,orig.sampleRate); 868 delete orig;
860 for (var c=0; c<orig.numberOfChannels; c++)
861 {
862 var inData = hold.getChannelData(c);
863 var outData = orig.getChannelData(c);
864 for (var n=0; n<orig.length; n++)
865 {inData[n] = outData[n];}
866 }
867 this.audioObjects[i].buffer = hold;
868 delete orig;
869 }
870 } 869 }
871 }; 870 };
872 871
873 } 872 }
874 873