From 7559b9607de6f0ec056e00c9fa64df9ec6ad8067 Mon Sep 17 00:00:00 2001 From: jbphet Date: Tue, 16 Feb 2021 14:54:47 -0700 Subject: [PATCH] make sound when rubbing on wall, see #479 --- .../view/BalloonNode.js | 4 ++-- ...tor.js => BalloonRubbingSoundGenerator.js} | 21 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) rename js/balloons-and-static-electricity/view/{BalloonOnSweaterSoundGenerator.js => BalloonRubbingSoundGenerator.js} (81%) diff --git a/js/balloons-and-static-electricity/view/BalloonNode.js b/js/balloons-and-static-electricity/view/BalloonNode.js index 68c29466..79bced06 100644 --- a/js/balloons-and-static-electricity/view/BalloonNode.js +++ b/js/balloons-and-static-electricity/view/BalloonNode.js @@ -42,7 +42,7 @@ import BASEQueryParameters from '../BASEQueryParameters.js'; import BalloonDirectionEnum from '../model/BalloonDirectionEnum.js'; import PlayAreaMap from '../model/PlayAreaMap.js'; import BalloonInteractionCueNode from './BalloonInteractionCueNode.js'; -import BalloonOnSweaterSoundGenerator from './BalloonOnSweaterSoundGenerator.js'; +import BalloonRubbingSoundGenerator from './BalloonRubbingSoundGenerator.js'; import BalloonVelocitySoundGenerator from './BalloonVelocitySoundGenerator.js'; import BalloonDescriber from './describers/BalloonDescriber.js'; import MinusChargeNode from './MinusChargeNode.js'; @@ -220,7 +220,7 @@ class BalloonNode extends Node { // sound generation for when the balloon is being rubbed on the sweater soundManager.addSoundGenerator( - new BalloonOnSweaterSoundGenerator( model.dragVelocityProperty, model.onSweaterProperty ) + new BalloonRubbingSoundGenerator( model.dragVelocityProperty, model.onSweaterProperty, model.touchingWallProperty ) ); // pdom diff --git a/js/balloons-and-static-electricity/view/BalloonOnSweaterSoundGenerator.js b/js/balloons-and-static-electricity/view/BalloonRubbingSoundGenerator.js similarity index 81% rename from js/balloons-and-static-electricity/view/BalloonOnSweaterSoundGenerator.js rename to js/balloons-and-static-electricity/view/BalloonRubbingSoundGenerator.js index c91b83fd..e624e26a 100644 --- a/js/balloons-and-static-electricity/view/BalloonOnSweaterSoundGenerator.js +++ b/js/balloons-and-static-electricity/view/BalloonRubbingSoundGenerator.js @@ -1,7 +1,7 @@ // Copyright 2018-2020, University of Colorado Boulder /** - * BalloonOnSweaterSoundGenerator is used to produces a sound effect for when a balloon is rubbing on the sweater. It + * BalloonRubbingSoundGenerator is used to produces a sound effect for when a balloon is rubbing on the something. It * is meant to be somewhat realistic as opposed to "cartoonish", so it uses a filtered noise generator. * * @author John Blanco @@ -22,14 +22,15 @@ const UPDATE_PERIOD = 100; // ms const SMOOTHED_SPEED_TAPER_RATE = 0.01; // model units per second, empirically determined const MAP_DRAG_SPEED_TO_OUTPUT_LEVEL = new LinearFunction( 0, 2, 0, 1, true ); -class BalloonOnSweaterSoundGenerator extends NoiseGenerator { +class BalloonRubbingSoundGenerator extends NoiseGenerator { /** * {Property.} dragVelocityProperty - velocity of the balloon drag * {Property.} onSweaterProperty - whether the balloon is on the sweater + * {Property.} touchingWallProperty - whether the balloon is touching the wall * {Object} [options] */ - constructor( dragVelocityProperty, onSweaterProperty, options ) { + constructor( dragVelocityProperty, onSweaterProperty, touchingWallProperty, options ) { options = merge( { noiseType: 'brown', @@ -38,7 +39,7 @@ class BalloonOnSweaterSoundGenerator extends NoiseGenerator { // {number} - The amount of sound produced by this sound generator varies based on what's going on with the input // properties, and this value sets the maximum. - maxOutputLevel: 0.4 + maxOutputLevel: 0.8 }, options ); @@ -69,9 +70,9 @@ class BalloonOnSweaterSoundGenerator extends NoiseGenerator { // Use the smoothed speed and the on-sweater information to set the volume and pitch of the output. Property.multilink( - [ smoothedSpeedProperty, onSweaterProperty ], - ( smoothedDragSpeed, onSweater ) => { - if ( smoothedDragSpeed > 0 && onSweater ) { + [ smoothedSpeedProperty, onSweaterProperty, touchingWallProperty ], + ( smoothedDragSpeed, onSweater, touchingWall ) => { + if ( smoothedDragSpeed > 0 && ( onSweater || touchingWall ) ){ // Start the production of the sound if needed. if ( !this.isPlaying ) { @@ -94,7 +95,7 @@ class BalloonOnSweaterSoundGenerator extends NoiseGenerator { } this.setBandpassFilterCenterFrequency( CENTER_FREQUENCY + sign * FREQUENCY_CHANGE_WITH_DIRECTION ); } - else if ( ( smoothedDragSpeed === 0 || !onSweater ) && this.isPlaying ) { + else if ( ( smoothedDragSpeed === 0 || !( onSweater || touchingWall ) ) && this.isPlaying ) { // The smoothed speed has dropped to zero, turn off sound production. this.stop(); @@ -104,6 +105,6 @@ class BalloonOnSweaterSoundGenerator extends NoiseGenerator { } } -balloonsAndStaticElectricity.register( 'BalloonOnSweaterSoundGenerator', BalloonOnSweaterSoundGenerator ); +balloonsAndStaticElectricity.register( 'BalloonRubbingSoundGenerator', BalloonRubbingSoundGenerator ); -export default BalloonOnSweaterSoundGenerator; \ No newline at end of file +export default BalloonRubbingSoundGenerator; \ No newline at end of file