new robotic effect using comb filter, remove vocoder

This commit is contained in:
Eric Rosenbaum 2016-11-21 18:26:31 -05:00
parent ec558d9821
commit b169ac8875

View file

@ -2,7 +2,6 @@ var log = require('./log');
var Tone = require('tone'); var Tone = require('tone');
var SoundPlayer = require('./SoundPlayer'); var SoundPlayer = require('./SoundPlayer');
var Soundfont = require('soundfont-player'); var Soundfont = require('soundfont-player');
var Vocoder = require('./vocoder');
var ADPCMSoundLoader = require('./ADPCMSoundLoader'); var ADPCMSoundLoader = require('./ADPCMSoundLoader');
function AudioEngine (sounds) { function AudioEngine (sounds) {
@ -19,7 +18,12 @@ function AudioEngine (sounds) {
this.reverb = new Tone.Freeverb(); this.reverb = new Tone.Freeverb();
this.distortion = new Tone.Distortion(1); this.distortion = new Tone.Distortion(1);
this.pitchEffectValue; this.pitchEffectValue;
this.vocoder = new Vocoder();
this.robotic = new Tone.Effect();
// use the period of a musical note to set the feedback filter delay time
var delayTime = 1 / Tone.Frequency('Gb3').eval();
var robotFilter = new Tone.FeedbackCombFilter(delayTime, 0.9);
this.robotic.effectSend.chain(robotFilter, this.robotic.effectReturn);
this.wobble = new Tone.Effect(); this.wobble = new Tone.Effect();
var wobbleLFO = new Tone.LFO(10, 0, 1).start(); var wobbleLFO = new Tone.LFO(10, 0, 1).start();
@ -39,13 +43,15 @@ function AudioEngine (sounds) {
// note that the pitch effect works differently - it sets the playback rate for each player // note that the pitch effect works differently - it sets the playback rate for each player
this.effectsNode = new Tone.Gain(); this.effectsNode = new Tone.Gain();
this.effectsNode.chain( this.effectsNode.chain(
// this.vocoder, this.robotic, this.distortion, this.delay, this.telephone,
this.distortion, this.delay, this.telephone,
this.wobble, this.panner, this.reverb, Tone.Master); this.wobble, this.panner, this.reverb, Tone.Master);
// reset effects to their default parameters // reset effects to their default parameters
this.clearEffects(); this.clearEffects();
this.effectNames = ['PITCH', 'PAN', 'ECHO', 'REVERB', 'FUZZ', 'TELEPHONE', 'WOBBLE', 'ROBOTIC'];
// load sounds // load sounds
this.soundPlayers = []; this.soundPlayers = [];
@ -196,6 +202,10 @@ AudioEngine.prototype.stopAllSounds = function () {
}; };
AudioEngine.prototype.setEffect = function (effect, value) { AudioEngine.prototype.setEffect = function (effect, value) {
if (Number.isInteger(effect)) {
effect = this._clamp(effect, 0, this.effectNames.length);
effect = this.effectNames[effect];
}
switch (effect) { switch (effect) {
case 'PITCH': case 'PITCH':
this._setPitchShift(value); this._setPitchShift(value);
@ -219,7 +229,7 @@ AudioEngine.prototype.setEffect = function (effect, value) {
this.wobble.wet.value = value / 100; this.wobble.wet.value = value / 100;
break; break;
case 'ROBOTIC' : case 'ROBOTIC' :
this.vocoder.wet.value = value / 100; this.robotic.wet.value = value / 100;
break; break;
} }
}; };
@ -254,8 +264,8 @@ AudioEngine.prototype.changeEffect = function (effect, value) {
this.wobble.wet.value = this._clamp(this.wobble.wet.value, 0, 1); this.wobble.wet.value = this._clamp(this.wobble.wet.value, 0, 1);
break; break;
case 'ROBOTIC' : case 'ROBOTIC' :
this.vocoder.wet.value += value / 100; this.robotic.wet.value += value / 100;
this.vocoder.wet.value = this._clamp(this.vocoder.wet.value, 0, 1); this.robotic.wet.value = this._clamp(this.robotic.wet.value, 0, 1);
break; break;
} }
@ -264,9 +274,6 @@ AudioEngine.prototype.changeEffect = function (effect, value) {
AudioEngine.prototype._setPitchShift = function (value) { AudioEngine.prototype._setPitchShift = function (value) {
this.pitchEffectValue = value; this.pitchEffectValue = value;
var freq = this._getPitchRatio() * Tone.Frequency('C3').eval();
this.vocoder.setCarrierOscFrequency(freq);
if (!this.soundPlayers) { if (!this.soundPlayers) {
return; return;
} }
@ -302,7 +309,7 @@ AudioEngine.prototype.clearEffects = function () {
this.panner.pan.value = 0; this.panner.pan.value = 0;
this.reverb.wet.value = 0; this.reverb.wet.value = 0;
this.distortion.wet.value = 0; this.distortion.wet.value = 0;
this.vocoder.wet.value = 0; this.robotic.wet.value = 0;
this.wobble.wet.value = 0; this.wobble.wet.value = 0;
this.telephone.wet.value = 0; this.telephone.wet.value = 0;
this._setPitchShift(0); this._setPitchShift(0);