-
Notifications
You must be signed in to change notification settings - Fork 130
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
Oscilloscope not connecting to Tone.js audio context #89
Comments
Great question, yes there is an easy remedy. Tell NexusUI to use Tone's AudioContext: Nexus.context = Tone.context You'll want to put that line of code towards the beginning of your script (before you create any NexusUI components). Fuller explanation: the error is that NexusUI has its own AudioContext (Nexus.context) which it uses for timing and to run the audio analysis for components such as the oscilloscope. Tone also has its own audio context (Tone.context). Web audio doesn't allow you to make audio connections across different contexts. By setting them equal ( The full working JS for your codepen would be: Nexus.context = Tone.context
var mute = new Nexus.Toggle('#mute'),
oscilloscope = {},
synth = new Tone.Oscillator(110, 'square'),
vol = new Tone.Volume(-15);
synth.chain(vol, Tone.Master);
Tone.Master.mute = true;
oscilloscope = new Nexus.Oscilloscope('#scope');
oscilloscope.connect(Tone.Master);
mute.on('change', function(v) {
if(v) Tone.Master.mute = false;
else Tone.Master.mute = true;
});
synth.start(); I'll be sure to add this to the documentation. |
@taylorbf Thanks so much! 👏 |
Hey, thought I'd put this out there since I just spent several very confused hours troubleshooting this exact issue. For some reason including Instead, I noticed a properly formatted AudioContext object hanging out in the hidden variable I've put my marked-up code here incase anyone's curious—it also includes a function that uses promises to load libraries that deal with AudioContexts upon a user interaction, so that you don't run into problems with modern browsers trying to disable automatic audio. |
Seems to be, that latest versions provide new API in tone.js, that produce errors during assigning context to nexusui |
To solve this specific issue, should I submit a PR that changes the following?:
I already have PR #190 that I can modify to do this. Regards |
I've tried to set the source two different ways based on what the documentation is showing and looking at the library itself.
First attempt
throws this error:
Uncaught Error: error connecting to node: [object AnalyserNode] InvalidAccessError: Failed to execute 'connect' on 'AudioNode': cannot connect to a destination belonging to a different audio context.
Second attempt
I dug into the library a little and also tried:
This didn't produce any errors, but it also didn't work.
I'm kind of at a loss, and would appreciate any help or if this something that needs to get fixed or if I'm misunderstanding how to use this feature. I attached a simple example using the snippets I pasted above to a Pen: https://codepen.io/jonahvsweb/pen/gxREQE?editors=1010
The text was updated successfully, but these errors were encountered: