Skip to content

Commit

Permalink
make sound when rubbing on wall, see #479
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Feb 16, 2021
1 parent bf9bcca commit 7559b96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions js/balloons-and-static-electricity/view/BalloonNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.<number>} dragVelocityProperty - velocity of the balloon drag
* {Property.<boolean>} onSweaterProperty - whether the balloon is on the sweater
* {Property.<boolean>} touchingWallProperty - whether the balloon is touching the wall
* {Object} [options]
*/
constructor( dragVelocityProperty, onSweaterProperty, options ) {
constructor( dragVelocityProperty, onSweaterProperty, touchingWallProperty, options ) {

options = merge( {
noiseType: 'brown',
Expand All @@ -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 );

Expand Down Expand Up @@ -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 ) {
Expand All @@ -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();
Expand All @@ -104,6 +105,6 @@ class BalloonOnSweaterSoundGenerator extends NoiseGenerator {
}
}

balloonsAndStaticElectricity.register( 'BalloonOnSweaterSoundGenerator', BalloonOnSweaterSoundGenerator );
balloonsAndStaticElectricity.register( 'BalloonRubbingSoundGenerator', BalloonRubbingSoundGenerator );

export default BalloonOnSweaterSoundGenerator;
export default BalloonRubbingSoundGenerator;

0 comments on commit 7559b96

Please sign in to comment.