51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
// js/plugins/SuperSaw.js
|
|
import * as Tone from "https://esm.sh/tone";
|
|
|
|
export class SuperSaw {
|
|
constructor(toneContext, data = {}) {
|
|
// Tenta pegar dados de qualquer um dos plugins que usam esse motor
|
|
this.params = data.zynaddsubfx || data.watsyn || data || {};
|
|
|
|
// O "FatSawtooth" do Tone.js cria 3 serras desafinadas automaticamente
|
|
this.synth = new Tone.PolySynth(Tone.Synth, {
|
|
oscillator: {
|
|
type: "fatsawtooth",
|
|
count: 3, // 3 serras por voz
|
|
spread: 20 // Desafinação entre elas (o "gordura")
|
|
},
|
|
envelope: {
|
|
attack: 0.01, // Ataque rápido (lead)
|
|
decay: 0.1,
|
|
sustain: 0.6,
|
|
release: 0.4 // Release médio para "encher" o som
|
|
},
|
|
volume: -6 // Reduz um pouco pois o Fatsawtooth é alto
|
|
});
|
|
|
|
// Efeitos para dar "largura" estéreo (O segredo do SuperSaw)
|
|
// Chorus: duplica o sinal e desafina levemente
|
|
this.chorus = new Tone.Chorus(4, 2.5, 0.5).start();
|
|
|
|
// Filtro para cortar frequências muito agudas e evitar chiado digital
|
|
this.filter = new Tone.Filter(8000, "lowpass");
|
|
|
|
// Cadeia: Synth -> Chorus -> Filter -> Output
|
|
this.synth.chain(this.chorus, this.filter);
|
|
|
|
this.output = this.filter;
|
|
}
|
|
|
|
triggerAttackRelease(note, duration, time) {
|
|
this.synth.triggerAttackRelease(note, duration, time);
|
|
}
|
|
|
|
connect(dest) {
|
|
this.output.connect(dest);
|
|
}
|
|
|
|
dispose() {
|
|
this.synth.dispose();
|
|
this.chorus.dispose();
|
|
this.filter.dispose();
|
|
}
|
|
} |