scratch-audio/src/effects/PitchEffect.js

46 lines
825 B
JavaScript
Raw Normal View History

2016-11-29 18:33:09 -05:00
/*
A Pitch effect
*/
var Tone = require('tone');
function PitchEffect () {
2016-11-30 11:29:00 -05:00
this.value = 0;
this.ratio = 1;
2016-11-29 18:33:09 -05:00
2016-11-30 11:29:00 -05:00
this.tone = new Tone();
2016-11-29 18:33:09 -05:00
}
PitchEffect.prototype.set = function (val, players) {
this.value = val;
this.ratio = this.getRatio(this.value);
2016-11-29 18:33:09 -05:00
this.updatePlayers(players);
};
PitchEffect.prototype.changeBy = function (val, players) {
this.set(this.value + val, players);
};
PitchEffect.prototype.getRatio = function (val) {
return this.tone.intervalToFrequencyRatio(val / 10);
};
PitchEffect.prototype.updatePlayer = function (player) {
player.setPlaybackRate(this.ratio);
2016-11-29 18:33:09 -05:00
};
PitchEffect.prototype.updatePlayers = function (players) {
if (!players) return;
for (var md5 in players) {
this.updatePlayer(players[md5]);
2016-11-29 18:33:09 -05:00
}
};
2016-11-29 18:33:09 -05:00
module.exports = PitchEffect;