Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.41k stars 976 forks source link

When I tried to chain a filter, envelope and panner to an OmniOscillator I get an error when I add the envelope #875

Closed cordial closed 3 years ago

cordial commented 3 years ago

Describe the bug

When I try and chain a filter, envelope and panner to an oscillator I get an error

To Reproduce

In Wrapper Machine component -

function initialiseEnvelope() { return new Tone.Envelope({ attack: 0.2, decay: 0.7, sustain: 0.9, release: 2, }); }

Envelope is then passed into the Oscillator component (the italic line is where the error is thrown when you add in the envelope component)

function initialiseOscillator(panner:Tone.Panner, filter:Tone.Filter, envelope:Tone.Envelope){ const oscillator = new Tone.OmniOscillator(0, 'sine'); oscillator.chain( panner, filter, envelope, Tone.Destination); oscillator.volume.value = -50; return oscillator; };

Expected behavior Envelope changes the wave shape of the filtered oscillator

Additional context Error message displayed -

Screenshot 2021-04-14 at 15 47 04

Here is the goal in diagram form (although we are ok with just one Volume Shaper now which is an ADSR on the overall sound output, rather than two different ones with one on each output).

Screenshot 2021-04-14 at 15 51 23
tambien commented 3 years ago

Tone.Envelope is actually an envelope generator, just has an output but no input. If you want an amplitude envelope, you can either connect the envelope signal output to Tone.Gain or simpler would be to use Tone.AmplitudeEnvelope.

cordial commented 3 years ago

If I use AmplitudeEnvelope, I have two issues - i) If I use oscillator.chain( panner, filter, envelope, Tone.Destination); as before, there is no noise from the oscillator. ii) If I use oscillator.connect(envelope) for testing/isolating purposes I can hear the oscillator noise but when I try and change attack, release, sustain, decay while its running the noise doesnt' change. I have tried this via a combination of (with attack example) -

function handleAttackChange(name, newAttack, envelope) { envelope.attack = newAttack; envelope.triggerAttack();

newAttack correctly has a new value you in it but there is no change of noise (i initially tried without the triggerAttack part).