diff --git a/Tone/source/Player.js b/Tone/source/Player.js index a629be87..a2ff0fdf 100644 --- a/Tone/source/Player.js +++ b/Tone/source/Player.js @@ -1,11 +1,13 @@ -/////////////////////////////////////////////////////////////////////////////// -// -// AUDIO PLAYER -// -/////////////////////////////////////////////////////////////////////////////// - define(["Tone/core/Tone"], function(Tone){ - + /** + * Audio Player + * + * Audio file player with start, loop, stop. + * + * @constructor + * @extends {Tone.Source} + * @param {string} url + */ Tone.Player = function(url){ //extend Unit Tone.call(this); @@ -22,7 +24,11 @@ define(["Tone/core/Tone"], function(Tone){ /** * makes an xhr reqest for the selected url - * @param {function(Tone.Player)=} callback invoked when the sample is loaded + * Load the audio file as an audio buffer. + * Decodes the audio asynchronously and invokes + * the callback once the audio buffer loads. + * + * @param {function(Tone.Player)} callback */ Tone.Player.prototype.load = function(callback){ if (!this.buffer){ @@ -61,18 +67,26 @@ define(["Tone/core/Tone"], function(Tone){ startTime = this.defaultArg(startTime, this.now()); offset = this.defaultArg(offset, 0); duration = this.defaultArg(duration, this.buffer.duration - offset); - volume = this.defaultArg(volume, 1); //make the source this.source = this.context.createBufferSource(); this.source.buffer = this.buffer; this.source.loop = false; this.source.start(this.toSeconds(startTime), this.toSeconds(offset), this.toSeconds(duration)); this.source.onended = this._onended.bind(this); - this.chain(this.source, gain, this.output); + this.chain(this.source, this.output); } }; - //play the buffer from start to finish at a time + /** + * Loop the buffer from start to finish at a time + * + * @param {Tone.Time} startTime + * @param {Tone.Time} loopStart + * @param {Tone.Time} loopEnd + * @param {Tone.Time} offset + * @param {Tone.Time} duration + * @param {Tone.Time} volume + */ Tone.Player.prototype.loop = function(startTime, loopStart, loopEnd, offset, duration, volume){ if (this.buffer){ //default args @@ -90,8 +104,9 @@ define(["Tone/core/Tone"], function(Tone){ }; /** - * stop the playback of the sample - * @param {Tone.Time} stopTime + * Stop playback. + * + * @param {Tone.Time} stopTime */ Tone.Player.prototype.stop = function(stopTime){ if (this.buffer && this.source){ diff --git a/examples/noiseEffect.html b/examples/noiseEffect.html index 86830cc5..bf9b9087 100644 --- a/examples/noiseEffect.html +++ b/examples/noiseEffect.html @@ -7,8 +7,15 @@ +
+ Noise Type: + brown + pink + white +
\ No newline at end of file diff --git a/examples/panner.html b/examples/panner.html index 63033a96..d9a8f82e 100644 --- a/examples/panner.html +++ b/examples/panner.html @@ -47,11 +47,17 @@ var range = document.querySelector("input"); - range.onchange = function(){ - var val = range.value; + range.oninput = function(e){ + var val = e.target.value; pan.setPan(val/100, "+.1"); } + var mouseX, mouseY; + window.onmousemove = function(e) { + mouseX = e.x; + mouseY = e.y; + }; + - \ No newline at end of file + diff --git a/examples/signalProcessing.html b/examples/signalProcessing.html index ed1ea109..8fe5cb9f 100644 --- a/examples/signalProcessing.html +++ b/examples/signalProcessing.html @@ -17,13 +17,13 @@ var dryMeter = new Tone.Meter(); signal.connect(dryMeter); - + //the adder var adder = new Tone.Add(100); var addMeter = new Tone.Meter(); adder.connect(addMeter); signal.connect(adder); - + //the scaler var scaler = new Tone.Scale(99, 101, 5, 10); var scaleMeter = new Tone.Meter(); diff --git a/test/test.js b/test/test.js index 13fa7b8a..5dd0faac 100644 --- a/test/test.js +++ b/test/test.js @@ -12,7 +12,7 @@ require.config({ } }); -require(["tests/Timing", "tests/Signal", "tests/Math", "tests/Transport"], function(){ +require(["tests/Timing", "tests/Signal", "tests/Math", "tests/Transport", "tests/Sources"], function(){ if (window.mochaPhantomJS) { mochaPhantomJS.run(); } else { diff --git a/test/testAudio/kick.mp3 b/test/testAudio/kick.mp3 new file mode 100644 index 00000000..83283402 Binary files /dev/null and b/test/testAudio/kick.mp3 differ diff --git a/test/tests/Sources.js b/test/tests/Sources.js new file mode 100644 index 00000000..d800eceb --- /dev/null +++ b/test/tests/Sources.js @@ -0,0 +1,33 @@ +define(["chai", "Tone/source/Player"], function(chai, Player){ + var expect = chai.expect; + + describe("Tone.Player", function(){ + this.timeout(100); + var player = new Player("./testAudio/kick.mp3"); + + it("loads a file", function(done){ + player.load(function(){ + done(); + }); + }); + + it("returns correct file duration", function(){ + expect(player.getDuration()).to.equal(0.2361678034067154); + }); + + it("plays a file", function(){ + var ended = false; + player._onended = function(){ + ended = true; + }; + expect(ended).to.equal(false); + player.start(); + setTimeout(function(){ + expect(ended).to.equal(true); + }, 0.5); + }); + + }); + + +}); \ No newline at end of file