Skip to content

Commit

Permalink
added the ability to specify alternative loops for balloon velocity s…
Browse files Browse the repository at this point in the history
…ounds, see #483
  • Loading branch information
jbphet committed Feb 22, 2021
1 parent 00fe347 commit 8a77735
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
32 changes: 25 additions & 7 deletions js/balloons-and-static-electricity/view/BASEView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion js/balloons-and-static-electricity/view/BalloonNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 8a77735

Please sign in to comment.