Skip to content

Commit

Permalink
went back to exponential level changes due to problems with consisten…
Browse files Browse the repository at this point in the history
…t behavior of linear gain changes, see phetsims/tambo#61, #329,  phetsims/friction#159, and phetsims/resistance-in-a-wire#205
  • Loading branch information
jbphet committed Apr 8, 2019
1 parent e70234f commit cf2ab49
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions js/john-travoltage/view/FootDragSoundGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ define( function( require ) {
var VELOCITY_REDUCTION_RATE = 50; // amount per second, empirically determined for best sound
var STILLNESS_TIME = 0.064; // in seconds, if there are no angle updates for this long, the leg is considered still
var NOISE_CENTER_FREQUENCY = 1300; // Hz
var DIRECTION_FREQUENCY_DELTA = NOISE_CENTER_FREQUENCY / 12; // max difference for forward vs backward motion of foot
var DIRECTION_FREQUENCY_DELTA = NOISE_CENTER_FREQUENCY / 6; // max difference for forward vs backward motion of foot
var MAX_LEG_ANGULAR_VELOCITY = 10; // in radians/sec, see explanatory note where this is used
var MIN_SOUND_GAP = 0.05; // in seconds
var NOISE_START_RAMP_TIME = 0.05; // in seconds
var NOISE_STOP_RAMP_TIME = 0.02;
var NOISE_LEVEL_CHANGE_TIME_CONSTANT = 0.1;
var NOISE_START_TIME_CONSTANT = 0.01;
var NOISE_STOP_TIME_CONSTANT = 0.05;
var NOISE_LEVEL_CHANGE_TIME_CONSTANT = 0.02;
var NOISE_OFF_TIME = 0.05; // in seconds

/**
Expand Down Expand Up @@ -86,7 +86,7 @@ define( function( require ) {
if ( newMotionState !== self.motionState && self.motionState !== 'still' ) {

// the leg switched directions without stopping in between, so set a countdown that will create a sound gap
self.setOutputLevel( 0, NOISE_STOP_RAMP_TIME );
self.setOutputLevel( 0, NOISE_STOP_TIME_CONSTANT );
self.soundStartCountdown = MIN_SOUND_GAP;
}
else {
Expand All @@ -95,13 +95,13 @@ define( function( require ) {
if ( !self.isPlaying ) {
self.start();
}
self.adjustOutputLevel( mapVelocityToOutputLevel( self.legAngularVelocity ), NOISE_LEVEL_CHANGE_TIME_CONSTANT );
self.setOutputLevel( mapVelocityToOutputLevel( self.legAngularVelocity ), NOISE_LEVEL_CHANGE_TIME_CONSTANT );
}
}
else {
if ( self.isPlaying ) {
self.stop( now + NOISE_OFF_TIME );
self.setOutputLevel( 0, NOISE_STOP_RAMP_TIME );
self.setOutputLevel( 0, NOISE_STOP_TIME_CONSTANT );
}
}

Expand Down Expand Up @@ -147,7 +147,7 @@ define( function( require ) {
if ( this.soundStartCountdown > 0 ) {
this.soundStartCountdown = Math.max( this.soundStartCountdown - dt, 0 );
if ( this.soundStartCountdown === 0 && this.motionState !== 'still' ) {
this.setOutputLevel( mapVelocityToOutputLevel( this.legAngularVelocity ), NOISE_START_RAMP_TIME );
this.setOutputLevel( mapVelocityToOutputLevel( this.legAngularVelocity ), NOISE_START_TIME_CONSTANT );
}
}
else if ( this.audioContext.currentTime - this.legAngleUpdateTime > STILLNESS_TIME &&
Expand All @@ -161,10 +161,10 @@ define( function( require ) {
if ( this.legAngularVelocity === 0 ) {
this.motionState = 'still';
this.stop( this.audioContext.currentTime + NOISE_OFF_TIME );
this.setOutputLevel( 0, NOISE_STOP_RAMP_TIME );
this.setOutputLevel( 0, NOISE_STOP_TIME_CONSTANT );
}
else {
this.setOutputLevel( mapVelocityToOutputLevel( this.legAngularVelocity ), NOISE_START_RAMP_TIME );
this.setOutputLevel( mapVelocityToOutputLevel( this.legAngularVelocity ), NOISE_START_TIME_CONSTANT );
}
}
}
Expand Down

0 comments on commit cf2ab49

Please sign in to comment.