diff --git a/HISTORY.md b/HISTORY.md index 5959a990..ce1d3980 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -59,6 +59,7 @@ ### 2019-04-05 * Objects: eliminated "clicks" when playing music notes +* Objects: eliminated "clicks" when playing a frequency ### 2019-04-04 * Objects, Threads: new "play frequency" commands in the Sounds category diff --git a/src/objects.js b/src/objects.js index 180680b2..edbb1211 100644 --- a/src/objects.js +++ b/src/objects.js @@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize, TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph, AlignmentMorph, Process, XML_Element, VectorPaintEditorMorph*/ -modules.objects = '2019-April-04'; +modules.objects = '2019-April-05'; var SpriteMorph; var StageMorph; @@ -3445,6 +3445,7 @@ SpriteMorph.prototype.playFreq = function (hz) { this.freqPlayer = new Note(); } note = this.freqPlayer; + note.fader = ctx.createGain(); if (note.oscillator) { note.oscillator.frequency.value = hz; } else { @@ -3458,7 +3459,8 @@ SpriteMorph.prototype.playFreq = function (hz) { note.setInstrument(this.instrument); note.oscillator.frequency.value = hz; this.setVolume(this.getVolume()); - note.oscillator.connect(gain); + note.oscillator.connect(note.fader); + note.fader.connect(gain); if (pan) { gain.connect(pan); pan.connect(ctx.destination); @@ -3473,6 +3475,11 @@ SpriteMorph.prototype.playFreq = function (hz) { return !snd.ended && !snd.terminated; }); } + note.fader.gain.setValueCurveAtTime( + note.fadeIn, + ctx.currentTime, + note.fadeTime + ); note.oscillator.start(0); } };