[Csnd] Webcsound and Soundfiles
Date | 2025-02-12 14:03 |
From | Philipp Neumann <0000119f78f3a4f9-dmarc-request@LISTSERV.HEANET.IE> |
Subject | [Csnd] Webcsound and Soundfiles |
I’m currently working with WebCsound ( https://kunstmusik.github.io/icsc2022-csound-web/ ) which is amazing! Thanks a lot for this! Super easy to setup and to use. I need a hint how i can work with soundfiles there. For example loading a soundfile, which is on the server, into a table via GEN_01. Does someone has a short example snippet for JS and Csound which shows this? Greetings, Philipp 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 |
Date | 2025-02-12 14:08 |
From | Steven Yi |
Subject | Re: [Csnd] Webcsound and Soundfiles |
Hi Philipp, You can check out this example: https://kunstmusik.github.io/webaudio-csound-samples-example/ with code at: https://github.com/kunstmusik/webaudio-csound-samples-example On Wed, Feb 12, 2025 at 9:03 AM Philipp Neumann <0000119f78f3a4f9-dmarc-request@listserv.heanet.ie> wrote: I’m currently working with WebCsound ( https://kunstmusik.github.io/icsc2022-csound-web/ ) |
Date | 2025-02-18 15:56 |
From | Philipp Neumann <0000119f78f3a4f9-dmarc-request@LISTSERV.HEANET.IE> |
Subject | Re: [Csnd] Webcsound and Soundfiles |
Thank you for your answer! I / we could need some more support for my / our project. We are struggling a little bit with the Csound performance The Project is quite an ambitious webdesign project, based on Svelte, with a lot of live rendering. Weg get some data from js and these are transforming the sounds. But from time to time we have some problems with sound interruption, crackeling sounds and noises. The graphic rendering is running quite well, but csound falls behind. Do you have some advices how to make csound ran smoother? How should we run it? In a webworker? I noticed the webcsound is ignoring my ksmps and sr settings from the csound file. How can i adjust them? Also could it help the make the software buffer bigger? And how can i do it with webcsound? Any advice would be helpful. Another question is, what is the best way to clean them RAM? We use this in our code. Is there a better way? async disposeSound() { await this.csound?.stop(); await this.csound?.cleanup(); await this.csound?.destroy(); this.csound = undefined; } All the best, Philipp > Am 12.02.2025 um 15:08 schrieb Steven Yi |
Date | 2025-02-18 16:54 |
From | Hlöðver Sigurðsson |
Subject | Re: [Csnd] Webcsound and Soundfiles |
I made a big hammer await cs.terminateInstance(); which Im not sure is documented anywhere, for a ram cleaning purposes. But this is maybe signaling an underlying cleanup but that I hope to catch once I refactor this wrapper code into typescript (on my todo list for 2025) On Tue, 18 Feb 2025 at 17:56, Philipp Neumann <0000119f78f3a4f9-dmarc-request@listserv.heanet.ie> wrote: Thank you for your answer! |
Date | 2025-02-18 20:10 |
From | Steven Yi |
Subject | Re: [Csnd] Webcsound and Soundfiles |
Hi Philipp, Hard to know exactly without seeing code and how you're setting things up. Is it available somewhere to look at? steven On Tue, Feb 18, 2025 at 10:56 AM Philipp Neumann <0000119f78f3a4f9-dmarc-request@listserv.heanet.ie> wrote: Thank you for your answer! |
Date | 2025-02-18 20:20 |
From | Philipp Neumann <0000119f78f3a4f9-dmarc-request@LISTSERV.HEANET.IE> |
Subject | Re: [Csnd] Webcsound and Soundfiles |
This is how we set the csound part: import { browser } from "$app/environment"; import csd from '$lib/csound/main.csd?raw' import helper from '$lib/csound/helper.udo?raw' import additivStruct from '$lib/csound/additivStruct.csd?raw' import subBeatings from '$lib/csound/subBeatings.csd?raw' import type { CsoundObj } from "@csound/browser"; let Csound: typeof import("@csound/browser").Csound; class SoundAdapter { csound: CsoundObj | undefined; soundPaused = $state(false); async toggleSound() { this.soundPaused = !this.soundPaused; if (this.csound) { if (this.soundPaused) { this.csound.pause(); } else { if (await this.csound.getScoreTime() === 0) { // this is the case, if a user has turned the sound off before entering. In that case we need to start the sound here for the first time. await this.csound.start(); } else { this.csound.resume(); } } } } async prepareSound() { // Csound throws an error when using it on the server side, so we only import it on the client if (browser) { ({ Csound } = await import("@csound/browser")); } if (this.csound) return; this.csound = await Csound({ useWorker: false, }); // useWorker, so it runs in a separate thread, inputChannelCount: 0, so it doesn't expect any input // console.log(csound) // await csound?.setOption("-m0"); const encoder = new TextEncoder(); const helperBinary = encoder.encode(helper); await this.csound?.fs.writeFile("helper.udo", helperBinary); const additivStructBinary = encoder.encode(additivStruct); await this.csound?.fs.writeFile("additivStruct.csd", additivStructBinary); const subBeatingsBinary = encoder.encode(subBeatings); await this.csound?.fs.writeFile("subBeatings.csd", subBeatingsBinary); const filePaths = await this.csound?.fs.readdir("/"); console.log("Csound File System:", filePaths); await this.csound?.compileCsdText(csd); } async startSound() { const csoundContext = await this.csound?.getAudioContext(); csoundContext?.resume(); // since the browser blocks the audioContext from starting automatically, we need to resume it here on a use action if (!this.soundPaused) { // check if the user has turned the sound off before entering the page await this.csound?.start(); } // you can add some initial sound interaction here, too } async cursorPosXHandler(value: number) { // value is a number between 0 and 1 (left-right screen position) await this.csound?.setControlChannel('cursorPosXHandler', value); } async cursorPosYHandler(value: number) { // value is a number between 0 and 1 (top-bottom screen position) await this.csound?.setControlChannel('cursorPosYHandler', value); } async transitionStartedInteraction() { // this gets called when the user clicks on one of the image cards around the origin // TODO: implement sound here // Example: // await this.csound?.evalCode(` // schedule("Flourish", next_time(.25), 0, 0) // `) await this.csound?.evalCode(`schedule("transitionSound", 0, 2.75, i(gkSubBeatings))`); } async disposeSound() { await this.csound?.stop(); await this.csound?.cleanup(); await this.csound?.destroy(); this.csound = undefined; } } export const soundAdapter = new SoundAdapter(); > Am 18.02.2025 um 21:10 schrieb Steven Yi |
Date | 2025-02-19 19:11 |
From | Steven Yi |
Subject | Re: [Csnd] Webcsound and Soundfiles |
Seems to me that compileCSDText should work here; you could try using a series of setOption calls like done here: https://github.com/kunstmusik/csound-live-code/blob/main/site/src/actions.ts#L13-L18 after creating your csound instance. I wonder if you're getting very small ksmps if the app isn't reading your csd settings? That could account for some performance issues. On Tue, Feb 18, 2025 at 3:20 PM Philipp Neumann <0000119f78f3a4f9-dmarc-request@listserv.heanet.ie> wrote: This is how we set the csound part: |
Date | 2025-02-26 10:45 |
From | Philipp Neumann <0000119f78f3a4f9-dmarc-request@LISTSERV.HEANET.IE> |
Subject | Re: [Csnd] Webcsound and Soundfiles |
Thanks Steven! I do it now like you did: compiling it as .orc with some options. This helped a lot! > Am 19.02.2025 um 20:11 schrieb Steven Yi |