From 8a777352f8fe61a6f7453fac8ea7e32e2e2f1e81 Mon Sep 17 00:00:00 2001 From: jbphet Date: Mon, 22 Feb 2021 16:34:11 -0700 Subject: [PATCH] added the ability to specify alternative loops for balloon velocity sounds, see https://github.com/phetsims/balloons-and-static-electricity/issues/483 --- .../view/BASEView.js | 32 +++++++++++++++---- .../view/BalloonNode.js | 10 +++++- .../view/BalloonVelocitySoundGenerator.js | 7 ++-- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/js/balloons-and-static-electricity/view/BASEView.js b/js/balloons-and-static-electricity/view/BASEView.js index c8680cc9..eebb21bc 100644 --- a/js/balloons-and-static-electricity/view/BASEView.js +++ b/js/balloons-and-static-electricity/view/BASEView.js @@ -17,12 +17,13 @@ import PitchedPopGenerator from '../../../../tambo/js/sound-generators/PitchedPo import soundManager from '../../../../tambo/js/soundManager.js'; import balloonGreen from '../../../images/balloon-green_png.js'; import balloonYellow from '../../../images/balloon-yellow_png.js'; +import greenBalloonDriftVelocityLoop from '../../../sounds/carrier-002_wav.js'; import balloonsAndStaticElectricity from '../../balloonsAndStaticElectricity.js'; import BASEA11yStrings from '../BASEA11yStrings.js'; import BASEConstants from '../BASEConstants.js'; import BASEQueryParameters from '../BASEQueryParameters.js'; -import BASESummaryNode from './BASESummaryNode.js'; import BalloonNode from './BalloonNode.js'; +import BASESummaryNode from './BASESummaryNode.js'; import ControlPanel from './ControlPanel.js'; import PlayAreaGridNode from './PlayAreaGridNode.js'; import SweaterNode from './SweaterNode.js'; @@ -77,9 +78,16 @@ class BASEView extends ScreenView { const controlPanel = new ControlPanel( model, this.layoutBounds, tandem.createTandem( 'controlPanel' ) ); - this.yellowBalloonNode = new BalloonNode( model.yellowBalloon, balloonYellow, model, yellowBalloonLabelString, greenBalloonLabelString, this.layoutBounds, tandem.createTandem( 'yellowBalloonNode' ), { - labelContent: yellowBalloonLabelString - } ); + this.yellowBalloonNode = new BalloonNode( + model.yellowBalloon, + balloonYellow, + model, + yellowBalloonLabelString, + greenBalloonLabelString, + this.layoutBounds, + tandem.createTandem( 'yellowBalloonNode' ), + { labelContent: yellowBalloonLabelString } + ); const tetherAnchorPoint = new Vector2( model.yellowBalloon.positionProperty.get().x + 30, // a bit to the side of directly below the starting position this.layoutBounds.height @@ -90,9 +98,19 @@ class BASEView extends ScreenView { new Vector2( this.yellowBalloonNode.width / 2, this.yellowBalloonNode.height - BALLOON_TIE_POINT_HEIGHT ), tandem.createTandem( 'yellowBalloonTetherNode' ) ); - this.greenBalloonNode = new BalloonNode( model.greenBalloon, balloonGreen, model, greenBalloonLabelString, yellowBalloonLabelString, this.layoutBounds, tandem.createTandem( 'greenBalloonNode' ), { - labelContent: greenBalloonLabelString - } ); + this.greenBalloonNode = new BalloonNode( + model.greenBalloon, + balloonGreen, + model, + greenBalloonLabelString, + yellowBalloonLabelString, + this.layoutBounds, + tandem.createTandem( 'greenBalloonNode' ), + { + labelContent: greenBalloonLabelString, + balloonVelocitySoundGeneratorOptions: { basisSound: greenBalloonDriftVelocityLoop } + } + ); this.greenBalloonTetherNode = new TetherNode( model.greenBalloon, tetherAnchorPoint, diff --git a/js/balloons-and-static-electricity/view/BalloonNode.js b/js/balloons-and-static-electricity/view/BalloonNode.js index 0e816320..c0cb59fd 100644 --- a/js/balloons-and-static-electricity/view/BalloonNode.js +++ b/js/balloons-and-static-electricity/view/BalloonNode.js @@ -75,6 +75,9 @@ class BalloonNode extends Node { options = merge( { cursor: 'pointer', + // {Object} - options passed to the drift velocity sound generator + balloonVelocitySoundGeneratorOptions: {}, + // pdom - this node will act as a container for more accessible content, its children will implement // most of the keyboard navigation containerTagName: 'div', @@ -213,7 +216,12 @@ class BalloonNode extends Node { // sound generation for drift velocity soundManager.addSoundGenerator( - new BalloonVelocitySoundGenerator( model.velocityProperty, model.onSweaterProperty, model.touchingWallProperty ) + new BalloonVelocitySoundGenerator( + model.velocityProperty, + model.onSweaterProperty, + model.touchingWallProperty, + options.balloonVelocitySoundGeneratorOptions + ) ); // sound generation for when the balloon is being rubbed on the sweater diff --git a/js/balloons-and-static-electricity/view/BalloonVelocitySoundGenerator.js b/js/balloons-and-static-electricity/view/BalloonVelocitySoundGenerator.js index d9dc31b5..a8f0d984 100644 --- a/js/balloons-and-static-electricity/view/BalloonVelocitySoundGenerator.js +++ b/js/balloons-and-static-electricity/view/BalloonVelocitySoundGenerator.js @@ -12,8 +12,6 @@ import LinearFunction from '../../../../dot/js/LinearFunction.js'; import merge from '../../../../phet-core/js/merge.js'; import SoundClip from '../../../../tambo/js/sound-generators/SoundClip.js'; import driftVelocityLoop from '../../../sounds/carrier-000_wav.js'; -// import driftVelocityLoop from '../../../sounds/carrier-001_wav.js'; -// import driftVelocityLoop from '../../../sounds/carrier-002_wav.js'; import balloonsAndStaticElectricity from '../../balloonsAndStaticElectricity.js'; // function for mapping the speed of the balloon to the playback rate of the carrier sound, empirically determined @@ -35,6 +33,9 @@ class BalloonVelocitySoundGenerator extends SoundClip { { loop: true, + // {WrappedAudioBuffer} - sound to use as the basis for the drifting velocity + basisSound: driftVelocityLoop, + // {number) The output level is set as a function of the speed at which the balloon is moving. This value // specifies the maximum value. It will generally be between 0 and 1. maxOutputLevel: 0.5 @@ -51,7 +52,7 @@ class BalloonVelocitySoundGenerator extends SoundClip { // Start the initial output level at zero so that the sound will fade in smoothly the first time it is played. options.initialOutputLevel = 0; - super( driftVelocityLoop, options ); + super( options.basisSound, options ); // Monitor the balloon velocity and modify the output sound as changes occur. If the balloon is on the sweater or // the wall, no sound should be produced.