Mercurial > hg > webaudioevaluationtool
comparison core.js @ 1434:35432335cd6c
Bug #1497: If the playback is looped, the buffer is copied to the audioObject not referenced to allow non-destructive editing.
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Thu, 17 Dec 2015 11:11:57 +0000 |
parents | 252c35ba2ba3 |
children | 43801b3d6131 |
comparison
equal
deleted
inserted
replaced
1433:252c35ba2ba3 | 1434:35432335cd6c |
---|---|
782 for (var i=0; i<bufferObj.users.length; i++) | 782 for (var i=0; i<bufferObj.users.length; i++) |
783 { | 783 { |
784 bufferObj.users[i].state = 1; | 784 bufferObj.users[i].state = 1; |
785 if (bufferObj.users[i].interfaceDOM != null) | 785 if (bufferObj.users[i].interfaceDOM != null) |
786 { | 786 { |
787 bufferObj.users[i].interfaceDOM.enable(); | 787 bufferObj.users[i].bufferLoaded(bufferObj); |
788 } | 788 } |
789 } | 789 } |
790 calculateLoudness(bufferObj.buffer,"I"); | 790 calculateLoudness(bufferObj.buffer,"I"); |
791 }, function(){ | 791 }, function(){ |
792 // Should only be called if there was an error, but sometimes gets called continuously | 792 // Should only be called if there was an error, but sometimes gets called continuously |
902 buffer.getMedia(URL); | 902 buffer.getMedia(URL); |
903 this.buffers.push(buffer); | 903 this.buffers.push(buffer); |
904 } | 904 } |
905 this.audioObjects[audioObjectId].specification = element; | 905 this.audioObjects[audioObjectId].specification = element; |
906 this.audioObjects[audioObjectId].url = URL; | 906 this.audioObjects[audioObjectId].url = URL; |
907 this.audioObjects[audioObjectId].buffer = buffer; | 907 buffer.users.push(this.audioObjects[audioObjectId]); |
908 var targetLUFS = this.audioObjects[audioObjectId].specification.parent.loudness; | |
909 if (typeof targetLUFS === "number") | |
910 { | |
911 buffer.buffer.gain = decibelToLinear(targetLUFS - buffer.buffer.lufs); | |
912 } else { | |
913 buffer.buffer.gain = 1.0; | |
914 } | |
915 if (buffer.buffer != null) | 908 if (buffer.buffer != null) |
916 { | 909 { |
917 this.audioObjects[audioObjectId].state = 1; | 910 this.audioObjects[audioObjectId].bufferLoaded(buffer); |
918 } | 911 } |
919 buffer.users.push(this.audioObjects[audioObjectId]); | |
920 return this.audioObjects[audioObjectId]; | 912 return this.audioObjects[audioObjectId]; |
921 }; | 913 }; |
922 | 914 |
923 this.newTestPage = function() { | 915 this.newTestPage = function() { |
924 this.state = 0; | 916 this.state = 0; |
1009 this.outputGain.connect(audioEngineContext.outputGain); | 1001 this.outputGain.connect(audioEngineContext.outputGain); |
1010 | 1002 |
1011 // the audiobuffer is not designed for multi-start playback | 1003 // the audiobuffer is not designed for multi-start playback |
1012 // When stopeed, the buffer node is deleted and recreated with the stored buffer. | 1004 // When stopeed, the buffer node is deleted and recreated with the stored buffer. |
1013 this.buffer; | 1005 this.buffer; |
1006 | |
1007 this.bufferLoaded = function(callee) | |
1008 { | |
1009 // Called by the associated buffer when it has finished loading, will then 'bind' the buffer to the | |
1010 // audioObject and trigger the interfaceDOM.enable() function for user feedback | |
1011 if (audioEngineContext.loopPlayback){ | |
1012 // First copy the buffer into this.buffer | |
1013 this.buffer = new audioEngineContext.bufferObj(); | |
1014 this.buffer.url = callee.url; | |
1015 this.buffer.buffer = audioContext.createBuffer(callee.buffer.numberOfChannels, callee.buffer.length, callee.buffer.sampleRate); | |
1016 for (var c=0; c<callee.buffer.numberOfChannels; c++) | |
1017 { | |
1018 var src = callee.buffer.getChannelData(c); | |
1019 var dst = this.buffer.buffer.getChannelData(c); | |
1020 for (var n=0; n<src.length; n++) | |
1021 { | |
1022 dst[n] = src[n]; | |
1023 } | |
1024 } | |
1025 } else { | |
1026 this.buffer = callee; | |
1027 } | |
1028 this.state = 1; | |
1029 this.buffer.buffer.gain = callee.buffer.gain; | |
1030 this.buffer.buffer.lufs = callee.buffer.lufs; | |
1031 var targetLUFS = this.specification.parent.loudness; | |
1032 if (typeof targetLUFS === "number") | |
1033 { | |
1034 this.buffer.buffer.gain = decibelToLinear(targetLUFS - this.buffer.buffer.lufs); | |
1035 } else { | |
1036 this.buffer.buffer.gain = 1.0; | |
1037 } | |
1038 if (this.interfaceDOM != null) { | |
1039 this.interfaceDOM.enable(); | |
1040 } | |
1041 }; | |
1014 | 1042 |
1015 this.loopStart = function() { | 1043 this.loopStart = function() { |
1016 this.outputGain.gain.value = this.specification.gain*this.buffer.buffer.gain; | 1044 this.outputGain.gain.value = this.specification.gain*this.buffer.buffer.gain; |
1017 this.metric.startListening(audioEngineContext.timer.getTestTime()); | 1045 this.metric.startListening(audioEngineContext.timer.getTestTime()); |
1018 }; | 1046 }; |