Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audioparam (Signal) value stays ignored #1186

Open
wictorsson opened this issue May 9, 2023 · 6 comments
Open

Audioparam (Signal) value stays ignored #1186

wictorsson opened this issue May 9, 2023 · 6 comments

Comments

@wictorsson
Copy link

Hi,
when I connect and then disconnect to a parameter, the parameter.value stays ignored. I tried to connect a LFO to both filter frequency and to Oscillator frequency. Once connected and then disconnected I cant change the value anymore unless I reconnect the same LFO. Here is my example code

 var filter = new Tone.Filter(1200, "lowpass");
 filter.frequency.value = 200;
 console.log(filter.frequency.value); //OUTPUTS 200
 var lfo = new Tone.LFO(4, 200, 1200);
 lfo.connect(filter.frequency);
 filter.frequency.cancelScheduledValues();
 lfo.disconnect(filter.frequency);
 filter.frequency.value = 200;
 console.log(filter.frequency.value); //OUTPUTS 0
@chrisguttandin
Copy link
Contributor

As far as I can tell this seems to be a bug somewhere in Tone.js. I tried to replicate the test case with the native Web Audio API and with standardized-audio-context but couldn't reproduce the problem.

https://stackblitz.com/edit/js-jrh9jh?file=index.js

However the code is not entirely equivalent. There is a good chance that I missed something.

@chrisguttandin
Copy link
Contributor

I guess this is the part of the code which is causing the problem.

/**
* When connecting from a signal, it's necessary to zero out the node destination
* node if that node is also a signal. If the destination is not 0, then the values
* will be summed. This method insures that the output of the destination signal will
* be the same as the source signal, making the destination signal a pass through node.
* @param signal The output signal to connect from
* @param destination the destination to connect to
* @param outputNum the optional output number
* @param inputNum the input number
*/
export function connectSignal(signal: OutputNode, destination: InputNode, outputNum?: number, inputNum?: number): void {
if (destination instanceof Param || isAudioParam(destination) ||
(destination instanceof Signal && destination.override)) {
// cancel changes
destination.cancelScheduledValues(0);
// reset the value
destination.setValueAtTime(0, 0);
// mark the value as overridden
if (destination instanceof Signal) {
destination.overridden = true;
}
}
connect(signal, destination, outputNum, inputNum);
}

@chrisguttandin
Copy link
Contributor

It's possible to avoid this behavior by piping the audio through a raw GainNode from standardized-audio-context at first.

https://stackblitz.com/edit/js-vot4qi?file=index.js

@mikezaby
Copy link

I'm facing the same problem as well. I'm trying to build a modular system and dynamically connecting and disconnecting modules, so it's a significant issue for me.

@wictorsson
Copy link
Author

I'm facing the same problem as well. I'm trying to build a modular system and dynamically connecting and disconnecting modules, so it's a significant issue for me.

I can confirm that chrisguttandins workaround above using a GainNode works. I’m also building a modular system.

@mikezaby
Copy link

mikezaby commented May 22, 2023

overridden

Based on what you sent, I tried to changed to oscillator.frequency.overridden = false after the disconnect, and seems that works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants