Remove tone.js dependency

This commit is contained in:
Eric Rosenbaum 2017-06-19 17:25:11 -04:00
parent 09b017ccf4
commit 5e6e33264d

View file

@ -1,5 +1,3 @@
const Tone = require('tone');
/**
* A pitch change effect, which changes the playback rate of the sound in order
* to change its pitch: reducing the playback rate lowers the pitch, increasing the rate
@ -21,7 +19,6 @@ class PitchEffect {
constructor () {
this.value = 0; // effect value
this.ratio = 1; // the playback rate ratio
this.tone = new Tone();
}
/**
@ -52,9 +49,19 @@ class PitchEffect {
* @returns {number} a playback ratio
*/
getRatio (val) {
return this.tone.intervalToFrequencyRatio(val / 10);
return intervalToFrequencyRatio(val / 10);
}
/**
* Convert a musical interval to a frequency ratio.
* With thanks to Tone.js: https://github.com/Tonejs/Tone.js
* @param {number} interval - a musical interval, in semitones
* @returns {number} a frequency ratio
*/
intervalToFrequencyRatio (interval) {
return Math.pow(2, (interval/12));
};
/**
* Update a sound player's playback rate using the current ratio for the effect
* @param {object} player - a SoundPlayer object