Skip to content

Commit

Permalink
use slightly different drag sounds for the different balloons, see #479
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Mar 1, 2021
1 parent 3d61f75 commit 587011b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
10 changes: 8 additions & 2 deletions js/balloons-and-static-electricity/view/BASEView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import balloonsAndStaticElectricity from '../../balloonsAndStaticElectricity.js'
import BASEA11yStrings from '../BASEA11yStrings.js';
import BASEQueryParameters from '../BASEQueryParameters.js';
import BalloonNode from './BalloonNode.js';
import BalloonRubbingSoundGenerator from './BalloonRubbingSoundGenerator.js';
import BASESummaryNode from './BASESummaryNode.js';
import ControlPanel from './ControlPanel.js';
import PlayAreaGridNode from './PlayAreaGridNode.js';
Expand Down Expand Up @@ -83,7 +84,9 @@ class BASEView extends ScreenView {
greenBalloonLabelString,
this.layoutBounds,
tandem.createTandem( 'yellowBalloonNode' ),
{ labelContent: yellowBalloonLabelString }
{
labelContent: yellowBalloonLabelString
}
);
const tetherAnchorPoint = new Vector2(
model.yellowBalloon.positionProperty.get().x + 30, // a bit to the side of directly below the starting position
Expand All @@ -105,7 +108,10 @@ class BASEView extends ScreenView {
tandem.createTandem( 'greenBalloonNode' ),
{
labelContent: greenBalloonLabelString,
balloonVelocitySoundGeneratorOptions: { basisSound: greenBalloonDriftVelocityLoop }
balloonVelocitySoundGeneratorOptions: { basisSound: greenBalloonDriftVelocityLoop },
balloonRubbingSoundGeneratorOptions: {
centerFrequency: BalloonRubbingSoundGenerator.DEFAULT_CENTER_FREQUENCY * 1.25
}
}
);
this.greenBalloonTetherNode = new TetherNode(
Expand Down
12 changes: 9 additions & 3 deletions js/balloons-and-static-electricity/view/BalloonNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class BalloonNode extends Node {
// {Object} - options passed to the drift velocity sound generator
balloonVelocitySoundGeneratorOptions: {},

// {Object} - options passed to the balloon rubbing sound generator
balloonRubbingSoundGeneratorOptions: {},

// 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 @@ -244,9 +247,12 @@ class BalloonNode extends Node {
) );

// sound generation for when the balloon is being rubbed on the sweater
soundManager.addSoundGenerator(
new BalloonRubbingSoundGenerator( model.dragVelocityProperty, model.onSweaterProperty, model.touchingWallProperty )
);
soundManager.addSoundGenerator( new BalloonRubbingSoundGenerator(
model.dragVelocityProperty,
model.onSweaterProperty,
model.touchingWallProperty,
options.balloonRubbingSoundGeneratorOptions
) );

// sound generation for when the balloon contacts the sweater
const balloonHitsSweaterSoundClip = new SoundClip( balloonHitsSweaterSound, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import NoiseGenerator from '../../../../tambo/js/sound-generators/NoiseGenerator
import balloonsAndStaticElectricity from '../../balloonsAndStaticElectricity.js';

// constants
const CENTER_FREQUENCY = 900; // Hz
const DEFAULT_CENTER_FREQUENCY = 800; // Hz
const FREQUENCY_CHANGE_WITH_DIRECTION = 100; // Hz
const UPDATE_PERIOD = 100; // ms
const SMOOTHED_SPEED_TAPER_RATE = 0.01; // model units per second, empirically determined
Expand All @@ -34,7 +34,7 @@ class BalloonRubbingSoundGenerator extends NoiseGenerator {

options = merge( {
noiseType: 'brown',
centerFrequency: CENTER_FREQUENCY,
centerFrequency: DEFAULT_CENTER_FREQUENCY,
qFactor: 2,

// {number} - The amount of sound produced by this sound generator varies based on what's going on with the input
Expand Down Expand Up @@ -93,7 +93,7 @@ class BalloonRubbingSoundGenerator extends NoiseGenerator {
else if ( dragVelocity.y < 0 ) {
sign = -1;
}
this.setBandpassFilterCenterFrequency( CENTER_FREQUENCY + sign * FREQUENCY_CHANGE_WITH_DIRECTION );
this.setBandpassFilterCenterFrequency( options.centerFrequency + sign * FREQUENCY_CHANGE_WITH_DIRECTION );
}
else if ( ( smoothedDragSpeed === 0 || !( onSweater || touchingWall ) ) && this.isPlaying ) {

Expand All @@ -105,6 +105,9 @@ class BalloonRubbingSoundGenerator extends NoiseGenerator {
}
}

// statics
BalloonRubbingSoundGenerator.DEFAULT_CENTER_FREQUENCY = DEFAULT_CENTER_FREQUENCY;

balloonsAndStaticElectricity.register( 'BalloonRubbingSoundGenerator', BalloonRubbingSoundGenerator );

export default BalloonRubbingSoundGenerator;

0 comments on commit 587011b

Please sign in to comment.