Csound.start() directly starts performance

Dear Csounders!

in JS, when I execute await csound.start(); my csound object directly starts with performance but in docs (https://www.npmjs.com/package/@csound/browser#CsoundObj.start) it says that it “Prepares Csound for performance”. I would like to ‘drive’ my csound object manually using performKsmps() function.

I did this many times in python and c++ but never in JS so I’m not sure is this expected behavior? Should I do something different?

I think this is expected behavior as CsoundObj.start() is different than calling csoundStart() in the C API, as it does more work to deal with threads and things. I think if you want very fine control of Csound, you might have to use libcsound WASM directly (i.e., use @csound/wasm-bin).

thanks @stevenyi ! I can definitely try that but is there any documentation/examples on how to work with csound/wasm-bin? i looked a bit but i havent found much…

There isn’t any documentation. The @csound/browser codebase does load the .wasm and uses it but it is not particularly straightforward. The browser library does a lot to supply FS and other things for wasm to use.

I did some work with AI to build out an example here:

There’s a lot of ceremony to be done to communicate values to/from WASM but you can see that done in the example.

1 Like

thanks @stevenyi ! that helped me a lot!

Also i had to strugle a bit to read values from the table so here if anyone else need it in the future:

  1. get table length: const tableLength = exports.csoundTableLength(csound, tableId);
  2. allocate the buffer in WASM memory for tableLength number of floats const outputPtr = exports.allocFloatArray(tableLength);
  3. copy the table data into that buffer exports.csoundTableCopyOut(csound, tableId, outputPtr);
  4. Read values from the table
// Csound defaults to 64-bit floats (Float64Array).         
const resultTable = new Float64Array(memory.buffer, outputPtr, tableLength);
// Make a copy so your can own the data in JS
const dataCopy = resultTable.slice();   
1 Like