1

I am able to successfully play oscillating tone of type square-wave with 100hz frequency.

However, the tone does not "gracefully" stop. Moreover, your speakers will make a "thud" sound when the tone stops, and the "thud" is worse when your speaker volume is too high. To fix that, I would like to add a fadeOut effect. ToneJS library supports this: here. However, I am not able to set the fadeOut property or activate it.

What am I doing wrong?

$( "#btnPlay" ).click(function(e) {
  var player = new Tone.Oscillator(100, "square").toDestination();

  player.fadeOut = 5; // set fadeOut time value

  player.start();
  player.stop(1); // stop playing after 1 second
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.5/Tone.js"></script>

<input id = "btnPlay" type="submit" value="Play!"/>
lucidgold
  • 4,432
  • 5
  • 31
  • 51

1 Answers1

1

Your fadeOut value is too long so you won't hear it. The value is in seconds, so try providing 0.05 (i.e. 50ms) instead.

player.fadeOut = 0.05; // value is in seconds
djr
  • 11
  • 2