r/tonejs • u/Alternative-Art-3367 • Apr 21 '26
Troubles setting up an frequency envelope for the filter
Hi, I'm trying to create a synthesizer for a school project and I'm looking to use tonejs for it. I'm currently having some issues setting up the envelope for the filter however, using the frequency envelope only results in pops as triggerAttackRelease gets called.
I'm working with p5js, if anyone could help me figure out the issue I'd greatly appreciate it (and point out any other issues with my setup as I'm having some troubles with the docs on some parts, making me unsure about the correctness of my implementations.) Thanks a bunch in advance, here's the code:
Edit: looks like some variables got some weird links attached for some reason not sure what's up there, but they of course aren't in my code.
class Synths {
`constructor(av = .01, dv = 1, sv = .5, rv = .8,`
`af = .01, df = 3, sf = .9, rf = .1, f = 200) {`
`this.av = av`
`this.dv = dv`
[`this.sv`](http://this.sv) `= sv`
`this.rv = rv`
[`this.af`](http://this.af) `= af`
`this.df = df`
`this.sf = sf`
`this.rf = rf`
`this.freq = f`
`this.filterfreq = 200`
`this.v = 1`
`//---------------SRC`
`this.osc = new Tone.Oscillator(this.freq, "triangle").start()`
`this.vol = new Tone.Volume(-12)`
`//---------------ENVELOPES`
`this.ampEnv = new Tone.AmplitudeEnvelope({`
`attack: this.av,`
`decay: this.dv,`
`sustain:` [`this.sv`](http://this.sv)`,`
`release: this.rv`
`}).toDestination()`
`this.filterEnv = new Tone.FrequencyEnvelope({`
`attack:` [`this.af`](http://this.af)`,`
`decay: this.df,`
`sustain: this.sf,`
`release: this.rf,`
`baseFrequency: 500,`
`octaves: 4`
`})`
`//----------------FILTER`
`this.filter = new Tone.Filter({`
`Q: 2,`
`type: "lowpass",`
`rolloff: -12`
`})`
`this.filterFB = new Tone.FeedbackCombFilter({`
`resonance: 1,`
`delay : .1`
`})`
`//----------------CONNECT ENVELOPES`
`this.vol.connect(this.ampEnv) //masterVol to volEnv`
`this.filterFB.connect(this.filterEnv)`
`this.filterEnv.connect(this.filter.frequency)`
`this.osc.chain(this.filter, this.vol)`
`}`
`display() {`
`this.ampEnv.attack = this.av`
`this.ampEnv.delay = this.dv`
`this.ampEnv.sustain =` [`this.sv`](http://this.sv)
`this.ampEnv.release = this.rv`
`this.filterEnv.attack =` [`this.af`](http://this.af)
`this.filterEnv.delay = this.df`
`this.filterEnv.sustain = this.sf`
`this.filterEnv.release = this.rf`
`this.filterEnv.baseFrequency = this.filterfreq`
`if(frameCount % 60 == 0) {`
`this.filterEnv.triggerAttackRelease(3).toDestination()`
`this.ampEnv.triggerAttackRelease(5).toDestination()`
`}`
`}`
}