Initializing CsoundObj in Web Csound

Hi,

I’m seeing two ways people are initializing CsoundObj in Web Csound.

  1. CsoundObj.importScripts("./csound/").then(() => {setupCsound();}); (example here)
  2. CsoundObj.initialize().then(() => {startCsound();}); (example here)

Can someone explain the difference between the two in terms of how they initialize CsoundObj?

Thanks!
Jason

importScripts() was what was in the API for a long while, but I modified it in 6.15.0 to initialize() and added the ability to send in an AudioContext to use, which was important for making the Csound nodes work in a larger Webaudio graph.

That said, the new version of WebAudio Csound has undergone many changes for 6.16.0 and the process has changed again. New code looks like:

const cs = await Csound();  // may pass in arguments as object to Csound

Or since it is a promise you can use:

Csound().then(() => {
});

6.16.0-beta is already published to NPM for testing though we are waiting for a few more changes to publish beta4, which we’ll then announce for testing. We’ll have the above documented in tutorials.

Fantastic, thanks for the explanation, Steven! Makes sense. I’m looking forward to 6.16.0!

Jason

Hello!

I’m trying to connect to the audio context created by my custom op in Cables.gl

const cablesAudioContext = CABLES.WEBAUDIO.createAudioContext(op);

const cs = await Csound({
        audioContext: cablesAudioContext,
});

Should the above be sufficient?

I get the Csound orc/score playing, but it seems to be playing though it’s own audioContext, not the one that I’ve passed to the Csound constructor. (this is verified by adjusting levels downstream of the custom op in Cables)

thanks

Seems like you need to connect csound node to a target node in Cable’s audio graph. By default, csound will connect directly to the audioContext. You can see an example of re-routing the signal to another webaudio node here:

1 Like

Brilliant - creating the gainNode was the key (I was reconnecting to the context destination i.e the speakers everytime):

https://cables.gl/p/yGSsXC

Thanks

Great to hear that worked out. BTW: The patch is private (I sent a request for access). :slight_smile:

Sorry - you should have access now! Does it work for you? First time sharing a patch :slight_smile:

Cheers!

Works now, nice demo!

1 Like