Csound Csound-dev Csound-tekno Search About

[Csnd] trigger events from Csound WASM

Date2026-10-09 18:00
FromIain Duncan
Subject[Csnd] trigger events from Csound WASM
Hi all, related question to my other. Is there any way to have the WASM csound object trigger a JS callback once per k-period? I couldn't find such a thing in either Victor or Steven's examples. 

--
Iain Duncan
Interdisciplinary PhD Candidate, Computer Science & Music
University of Victoria, Canada
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2026-10-09 18:19
FromHlöðver Sigurðsson
SubjectRe: [Csnd] trigger events from Csound WASM
We used to have csound.on("perform", () => ... ) that triggered on every ksmps. But it was too CPU intensive. We recently re-introduce this in a different format

csound.on("debugCallback", () => {
  // Called once per k-period.
});
await csound.enableDebugCallback();
await csound.start();

it needs to be enabled explicitly. Warning that sending events so frequently trough worker channels may be CPU intensive. I would recommend rather using SAB for this, for which I just discovered a bug (so it doesn't work with SAB atm). I'm opening a PR to fix that. But to use SAB you need to be able to control your HTTP response headers, and set them correctly for browser security reasons.

On Fri, 9 Oct 2026 at 20:00, Iain Duncan <iainduncanlists@gmail.com> wrote:
Hi all, related question to my other. Is there any way to have the WASM csound object trigger a JS callback once per k-period? I couldn't find such a thing in either Victor or Steven's examples. 

--
Iain Duncan
Interdisciplinary PhD Candidate, Computer Science & Music
University of Victoria, Canada
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2026-10-09 18:52
FromIain Duncan
SubjectRe: [Csnd] trigger events from Csound WASM
Ah thanks. What is SAB though? :-)

iain

On Fri, Oct 9, 2026 at 10:19 AM Hlöðver Sigurðsson <hlolli@gmail.com> wrote:
We used to have csound.on("perform", () => ... ) that triggered on every ksmps. But it was too CPU intensive. We recently re-introduce this in a different format

csound.on("debugCallback", () => {
  // Called once per k-period.
});
await csound.enableDebugCallback();
await csound.start();

it needs to be enabled explicitly. Warning that sending events so frequently trough worker channels may be CPU intensive. I would recommend rather using SAB for this, for which I just discovered a bug (so it doesn't work with SAB atm). I'm opening a PR to fix that. But to use SAB you need to be able to control your HTTP response headers, and set them correctly for browser security reasons.

On Fri, 9 Oct 2026 at 20:00, Iain Duncan <iainduncanlists@gmail.com> wrote:
Hi all, related question to my other. Is there any way to have the WASM csound object trigger a JS callback once per k-period? I couldn't find such a thing in either Victor or Steven's examples. 

--
Iain Duncan
Interdisciplinary PhD Candidate, Computer Science & Music
University of Victoria, Canada
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


--
Iain Duncan
Interdisciplinary PhD Candidate, Computer Science & Music
University of Victoria, Canada
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here