-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2019, University of Colorado Boulder | ||
|
||
/** | ||
* sound generator for mass changes | ||
* | ||
* @author John Blanco (PhET Interactive Simulations) | ||
*/ | ||
define( require => { | ||
'use strict'; | ||
|
||
// modules | ||
const SoundClip = require( 'TAMBO/sound-generators/SoundClip' ); | ||
const gravityForceLabBasics = require( 'GRAVITY_FORCE_LAB_BASICS/gravityForceLabBasics' ); | ||
const GFLBConstants = require( 'GRAVITY_FORCE_LAB_BASICS/gravity-force-lab-basics/GFLBConstants' ); | ||
|
||
// sounds | ||
const massSound = require( 'sound!GRAVITY_FORCE_LAB_BASICS/rubber-band-v2-middle-c.mp3' ); | ||
|
||
// constants | ||
const PITCH_RANGE_IN_SEMI_TONES = 30; | ||
|
||
class MassSoundGenerator extends SoundClip { | ||
|
||
/** | ||
* @param {NumberProperty} massProperty | ||
* @param {BooleanProperty} resetInProgressProperty | ||
* @param {Object} [options] | ||
* @constructor | ||
*/ | ||
constructor( massProperty, resetInProgressProperty, options ) { | ||
|
||
super( massSound, options ); | ||
|
||
// function for playing the mass sound | ||
const massListener = mass => { | ||
if ( !resetInProgressProperty.value ) { | ||
|
||
// convert the mass to a playback rate, see the design document for an explanation | ||
const massRange = GFLBConstants.MASS_RANGE; | ||
const normalizedMass = ( mass - massRange.min ) / ( massRange.max - massRange.min ); | ||
const centerAndFlippedNormMass = ( ( 1 - normalizedMass ) - 0.5 ); | ||
const midiNote = PITCH_RANGE_IN_SEMI_TONES / 2 * centerAndFlippedNormMass; | ||
const playbackSpeed = Math.pow( 2, midiNote / 12 ); | ||
this.setPlaybackRate( playbackSpeed ); | ||
this.play(); | ||
} | ||
}; | ||
massProperty.link( massListener ); | ||
|
||
// @private {function} | ||
this.disposeMassSoundGenerator = () => { massProperty.unlink( massListener ); }; | ||
} | ||
|
||
/** | ||
* @public | ||
*/ | ||
dispose() { | ||
this.disposeMassSoundGenerator(); | ||
super.dispose(); | ||
} | ||
} | ||
|
||
gravityForceLabBasics.register( 'MassSoundGenerator', MassSoundGenerator ); | ||
|
||
return MassSoundGenerator; | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"rubber-band-v2-middle-c.mp3": { | ||
"text": [ | ||
"Copyright 2002-2019 University of Colorado Boulder" | ||
], | ||
"projectURL": "http://phet.colorado.edu", | ||
"license": "contact [email protected]", | ||
"notes": "created by Ashton Morris (PhET Interactive Simulations)" | ||
} | ||
} |
Binary file not shown.