Mercurial > hg > webaudioevaluationtool
comparison js/core.js @ 3030:192538967e67
Merge branch 'vnext' into Dev_main
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Mon, 25 Sep 2017 11:02:02 +0100 |
parents | b09e9b7ef246 6b76962f58af |
children | 63af2e23c3d2 |
comparison
equal
deleted
inserted
replaced
3028:9a201c63a0eb | 3030:192538967e67 |
---|---|
1726 function playNormal(id) { | 1726 function playNormal(id) { |
1727 var playTime = audioContext.currentTime + 0.1; | 1727 var playTime = audioContext.currentTime + 0.1; |
1728 var stopTime = playTime + specification.crossFade; | 1728 var stopTime = playTime + specification.crossFade; |
1729 this.audioObjects.forEach(function (ao) { | 1729 this.audioObjects.forEach(function (ao) { |
1730 if (ao.id === id) { | 1730 if (ao.id === id) { |
1731 ao.play(playTime); | 1731 ao.setupPlayback(); |
1732 ao.bufferStart(playTime); | |
1733 ao.listenStart(playTime); | |
1732 } else { | 1734 } else { |
1733 ao.stop(stopTime); | 1735 ao.listenStop(playTime); |
1736 ao.bufferStop(stopTime); | |
1734 } | 1737 } |
1735 }); | 1738 }); |
1736 } | 1739 } |
1737 | 1740 |
1738 function playLoopSync(id) { | 1741 function playSync(id) { |
1739 var playTime = audioContext.currentTime + 0.1; | 1742 var playTime = audioContext.currentTime + 0.1; |
1740 var stopTime = playTime + specification.crossFade; | 1743 var stopTime = playTime + specification.crossFade; |
1741 this.audioObjects.forEach(function (ao) { | 1744 this.audioObjects.forEach(function (ao) { |
1742 ao.play(playTime); | 1745 ao.setupPlayback(); |
1746 ao.bufferStart(playTime); | |
1743 if (ao.id === id) { | 1747 if (ao.id === id) { |
1744 ao.loopStart(playTime); | 1748 ao.listenStart(playTime); |
1745 } else { | 1749 } else { |
1746 ao.loopStop(stopTime); | 1750 ao.listenStop(playTime); |
1747 } | 1751 } |
1748 }); | 1752 }); |
1749 } | 1753 } |
1750 | 1754 |
1751 this.play = function (id) { | 1755 this.play = function (id) { |
1759 return; | 1763 return; |
1760 } | 1764 } |
1761 if (this.status === 1) { | 1765 if (this.status === 1) { |
1762 this.timer.startTest(); | 1766 this.timer.startTest(); |
1763 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]); | 1767 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]); |
1764 if (this.synchPlayback && this.loopPlayback) { | 1768 if (this.synchPlayback) { |
1765 // Traditional looped playback | 1769 // Traditional looped playback |
1766 playLoopSync.call(this, id); | 1770 playSync.call(this, id); |
1767 } else { | 1771 } else { |
1768 if (this.bufferReady(id) === false) { | 1772 if (this.bufferReady(id) === false) { |
1769 console.log("Cannot play. Buffer not ready"); | 1773 console.log("Cannot play. Buffer not ready"); |
1770 return; | 1774 return; |
1771 } | 1775 } |
1778 this.stop = function () { | 1782 this.stop = function () { |
1779 // Send stop and reset command to all playback buffers | 1783 // Send stop and reset command to all playback buffers |
1780 if (this.status == 1) { | 1784 if (this.status == 1) { |
1781 var setTime = audioContext.currentTime + 0.1; | 1785 var setTime = audioContext.currentTime + 0.1; |
1782 this.audioObjects.forEach(function (a) { | 1786 this.audioObjects.forEach(function (a) { |
1783 a.stop(setTime); | 1787 a.listenStop(setTime); |
1788 a.bufferStop(setTime); | |
1784 }); | 1789 }); |
1785 interfaceContext.playhead.stop(); | 1790 interfaceContext.playhead.stop(); |
1786 } | 1791 } |
1787 }; | 1792 }; |
1788 | 1793 |
1905 this.commentDOM = null; | 1910 this.commentDOM = null; |
1906 | 1911 |
1907 // Create a buffer and external gain control to allow internal patching of effects and volume leveling. | 1912 // Create a buffer and external gain control to allow internal patching of effects and volume leveling. |
1908 this.bufferNode = undefined; | 1913 this.bufferNode = undefined; |
1909 this.outputGain = audioContext.createGain(); | 1914 this.outputGain = audioContext.createGain(); |
1915 this.outputGain.gain.value = 0.0; | |
1910 | 1916 |
1911 this.onplayGain = 1.0; | 1917 this.onplayGain = 1.0; |
1912 | 1918 |
1913 // Connect buffer to the audio graph | 1919 // Connect buffer to the audio graph |
1914 this.outputGain.connect(audioEngineContext.outputGain); | 1920 this.outputGain.connect(audioEngineContext.outputGain); |
1971 return; | 1977 return; |
1972 } | 1978 } |
1973 this.storeDOM.setAttribute('presentedId', interfaceObject.getPresentedId()); | 1979 this.storeDOM.setAttribute('presentedId', interfaceObject.getPresentedId()); |
1974 }; | 1980 }; |
1975 | 1981 |
1976 this.loopStart = function (setTime) { | 1982 this.listenStart = function (setTime) { |
1977 this.outputGain.gain.linearRampToValueAtTime(this.onplayGain, setTime); | 1983 if (this.outputGain.gain.value !== this.onplayGain) { |
1978 this.metric.startListening(audioEngineContext.timer.getTestTime()); | 1984 playCounter++; |
1979 this.interfaceDOM.startPlayback(); | 1985 this.outputGain.gain.linearRampToValueAtTime(this.onplayGain, setTime); |
1980 }; | 1986 this.metric.startListening(audioEngineContext.timer.getTestTime()); |
1981 | 1987 this.bufferNode.playbackStartTime = audioEngineContext.timer.getTestTime(); |
1982 this.loopStop = function (setTime) { | 1988 this.interfaceDOM.startPlayback(); |
1989 } | |
1990 }; | |
1991 | |
1992 this.listenStop = function (setTime) { | |
1983 if (this.outputGain.gain.value !== 0.0) { | 1993 if (this.outputGain.gain.value !== 0.0) { |
1984 this.outputGain.gain.linearRampToValueAtTime(0.0, setTime); | 1994 this.outputGain.gain.linearRampToValueAtTime(0.0, setTime); |
1985 this.metric.stopListening(audioEngineContext.timer.getTestTime()); | 1995 this.metric.stopListening(audioEngineContext.timer.getTestTime(), this.getCurrentPosition()); |
1986 } | 1996 } |
1987 this.interfaceDOM.stopPlayback(); | 1997 this.interfaceDOM.stopPlayback(); |
1988 }; | 1998 }; |
1989 | 1999 |
1990 this.play = function (startTime) { | 2000 this.setupPlayback = function () { |
1991 if (this.bufferNode === undefined && this.buffer.buffer !== undefined) { | 2001 if (this.bufferNode === undefined && this.buffer.buffer !== undefined) { |
1992 playCounter++; | |
1993 this.bufferNode = audioContext.createBufferSource(); | 2002 this.bufferNode = audioContext.createBufferSource(); |
1994 this.bufferNode.owner = this; | 2003 this.bufferNode.owner = this; |
1995 this.bufferNode.connect(this.outputGain); | 2004 this.bufferNode.connect(this.outputGain); |
1996 this.bufferNode.buffer = this.buffer.buffer; | 2005 this.bufferNode.buffer = this.buffer.buffer; |
1997 this.bufferNode.loop = audioEngineContext.loopPlayback; | 2006 if (audioEngineContext.loopPlayback) { |
2007 this.bufferNode.loopStart = this.specification.startTime || 0; | |
2008 this.bufferNode.loopEnd = this.specification.stopTime - this.specification.startTime || this.buffer.buffer.duration; | |
2009 this.bufferNode.loop = true; | |
2010 } | |
1998 this.bufferNode.onended = function (event) { | 2011 this.bufferNode.onended = function (event) { |
1999 // Safari does not like using 'this' to reference the calling object! | 2012 // Safari does not like using 'this' to reference the calling object! |
2000 //event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition()); | 2013 //event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition()); |
2001 if (event.currentTarget !== null) { | 2014 if (event.currentTarget !== null) { |
2002 event.currentTarget.owner.stop(audioContext.currentTime + 0.1); | 2015 event.currentTarget.owner.bufferStop(audioContext.currentTime + 0.1); |
2003 } | 2016 } |
2004 }; | 2017 }; |
2005 this.outputGain.gain.cancelScheduledValues(audioContext.currentTime); | 2018 this.bufferNode.state = 0; |
2006 if (!audioEngineContext.loopPlayback || !audioEngineContext.synchPlayback) { | 2019 } |
2007 this.metric.startListening(audioEngineContext.timer.getTestTime()); | 2020 }; |
2008 if (this.outputGain.gain.value !== this.onplayGain) { | 2021 |
2009 this.outputGain.gain.linearRampToValueAtTime(this.onplayGain, startTime + Number(specification.crossFade)); | 2022 this.bufferStart = function (startTime) { |
2010 } | 2023 this.outputGain.gain.cancelScheduledValues(audioContext.currentTime); |
2011 this.interfaceDOM.startPlayback(); | 2024 if (this.bufferNode && this.bufferNode.state == 0) { |
2012 } else { | 2025 this.bufferNode.state = 1; |
2013 this.outputGain.gain.linearRampToValueAtTime(0.0, startTime); | 2026 if (this.bufferNode.loop == true) { |
2014 } | |
2015 if (audioEngineContext.loopPlayback) { | |
2016 this.bufferNode.loopStart = this.specification.startTime || 0; | |
2017 this.bufferNode.loopEnd = this.specification.stopTime - this.specification.startTime || this.buffer.buffer.duration; | |
2018 this.bufferNode.start(startTime); | 2027 this.bufferNode.start(startTime); |
2019 } else { | 2028 } else { |
2020 this.bufferNode.start(startTime, this.specification.startTime || 0, this.specification.stopTime - this.specification.startTime || this.buffer.buffer.duration); | 2029 this.bufferNode.start(startTime, this.specification.startTime || 0, this.specification.stopTime - this.specification.startTime || this.buffer.buffer.duration); |
2021 } | 2030 } |
2022 this.bufferNode.playbackStartTime = audioEngineContext.timer.getTestTime(); | 2031 } |
2023 } | 2032 }; |
2024 }; | 2033 |
2025 | 2034 this.bufferStop = function (stopTime) { |
2026 this.stop = function (stopTime) { | |
2027 this.outputGain.gain.cancelScheduledValues(audioContext.currentTime); | 2035 this.outputGain.gain.cancelScheduledValues(audioContext.currentTime); |
2028 if (this.bufferNode !== undefined) { | 2036 if (this.bufferNode !== undefined && this.bufferNode.state > 0) { |
2029 this.metric.stopListening(audioEngineContext.timer.getTestTime(), this.getCurrentPosition()); | |
2030 this.bufferNode.stop(stopTime); | 2037 this.bufferNode.stop(stopTime); |
2031 this.bufferNode = undefined; | 2038 this.bufferNode = undefined; |
2032 } | 2039 } |
2033 this.outputGain.gain.linearRampToValueAtTime(0.0, stopTime); | 2040 this.outputGain.gain.linearRampToValueAtTime(0.0, stopTime); |
2034 this.interfaceDOM.stopPlayback(); | 2041 this.interfaceDOM.stopPlayback(); |