home/ atoms/ glicol-js-embedding-api

Glicol's JavaScript API embeds the audio engine in any browser app via CDN or NPM

The glicol-js package exposes the Glicol audio engine to JavaScript as a simple API: run(code) starts or updates the audio graph; stop() restarts the engine. When loaded via CDN, all methods are bound to the global window object, making them callable from browser console or button-mapped UI. The run() function handles both first-time code execution and live updates — calling it again with new code performs an LCS diff and updates only changed nodes. This makes Glicol usable as an embedded audio engine for browser-based music apps without any server infrastructure. Cross-origin isolation headers must be enabled on the hosting server for the SharedArrayBuffer to work.

Examples

<script src="https://cdn.jsdelivr.net/gh/chaosprint/glicol@latest/js/src/glicol.js"></script>

Then in console: run('hello: sin 440') starts audio; calling run('hello: sin 220') while running crossfades to the new frequency.

Assessment

Build a minimal HTML page with two buttons (440 Hz and 220 Hz) that toggle a Glicol sine tone using the CDN API. Identify which server header is required and why.

“Call it for the first time will run the code: ```run(`hello: sin 440`)``` Glicol engine knows you are updating the code if you call the func again.”
corpus · glicol-language-playground-and-guide-graph-oriented-live-cod · chunk 3