From bc2bea0129d69efef93e8716a1e74652be94bf12 Mon Sep 17 00:00:00 2001 From: Chris Malley Date: Thu, 22 Apr 2021 14:56:18 -0600 Subject: [PATCH] cleanup in AudibleSlider, https://github.com/phetsims/fourier-making-waves/issues/56 --- js/common/view/AudibleSlider.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/js/common/view/AudibleSlider.js b/js/common/view/AudibleSlider.js index dcc1909c..aa3d86f6 100644 --- a/js/common/view/AudibleSlider.js +++ b/js/common/view/AudibleSlider.js @@ -20,7 +20,8 @@ import fourierMakingWaves from '../../fourierMakingWaves.js'; // constants const DEFAULT_MIN_MAX_SOUND = generalBoundaryBoopSoundPlayer; const DEFAULT_SNAP_SOUND = generalSoftClickSoundPlayer; -const MIN_SOUND_INTERVAL = 100; // minimum time between sounds, in milliseconds +const SNAP_SOUND_DURATION = 25; //TODO generalSoftClickSoundPlayer.duration, https://github.com/phetsims/tandem/issues/234 +const SNAP_SOUND_MIN_SILENCE = 15; // minimum silence between snap sounds, in milliseconds class AudibleSlider extends Slider { @@ -43,25 +44,30 @@ class AudibleSlider extends Slider { let previousValue = property.value; // The time at which the most recent sound started playing, in milliseconds. - let tPlay = Date.now(); + let tPlay = 0; assert && assert( !options.drag, 'AudibleSlider defines drag' ); options.drag = () => { // options.drag is called after the Property is set, so this is the current value. const currentValue = property.value; - + const dtPlay = Date.now() - tPlay; - if ( currentValue !== previousValue && dtPlay >= MIN_SOUND_INTERVAL ) { + if ( currentValue !== previousValue ) { options.snapSound.isPlaying && options.snapSound.stop(); options.minMaxSound.isPlaying && options.minMaxSound.stop(); if ( currentValue === range.min || currentValue === range.max ) { + + // Play min/max sound regardless of time since previous sound, otherwise we will sometime not hear them. options.minMaxSound.play(); } - else { + else if ( dtPlay >= SNAP_SOUND_DURATION + SNAP_SOUND_MIN_SILENCE ) { + + // Play snap sound at some minimum interval, so that moving the slider doesn't create a bunch of sounds + // playing on top of each other, which sounds like garbage. options.snapSound.play(); }