supersonic-scsynth 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,11 +8,11 @@ A WebAssembly port of SuperCollider's scsynth audio synthesis engine for the bro
8
8
 
9
9
  ```html
10
10
  <script type="module">
11
- import { SuperSonic } from 'https://unpkg.com/supersonic-scsynth@latest';
11
+ import { SuperSonic } from './dist/supersonic.js';
12
12
 
13
13
  const sonic = new SuperSonic({
14
- sampleBaseURL: 'https://unpkg.com/supersonic-scsynth-samples@latest/samples/',
15
- synthdefBaseURL: 'https://unpkg.com/supersonic-scsynth-synthdefs@latest/synthdefs/'
14
+ sampleBaseURL: './dist/samples/',
15
+ synthdefBaseURL: './dist/synthdefs/'
16
16
  });
17
17
 
18
18
  await sonic.init();
@@ -29,11 +29,11 @@ A WebAssembly port of SuperCollider's scsynth audio synthesis engine for the bro
29
29
  </script>
30
30
  ```
31
31
 
32
- **Note:** Requires specific HTTP headers (COOP/COEP) for SharedArrayBuffer support. See [Browser Requirements](#browser-requirements) below.
32
+ **Important:** SuperSonic requires self-hosting (cannot load from CDN). See [CDN Usage](#cdn-usage) below.
33
33
 
34
34
  ## Installation
35
35
 
36
- **Via npm:**
36
+ **Via npm (for local bundling):**
37
37
  ```bash
38
38
  # Core engine only (~450KB)
39
39
  npm install supersonic-scsynth
@@ -42,15 +42,15 @@ npm install supersonic-scsynth
42
42
  npm install supersonic-scsynth-bundle
43
43
  ```
44
44
 
45
- **Via CDN:**
45
+ **Pre-built distribution (recommended):**
46
+ Download the pre-built package (~35MB with all synthdefs and samples) and serve from your own domain:
47
+ https://samaaron.github.io/supersonic/supersonic-dist.zip
48
+
49
+ Extract to your web server and import as:
46
50
  ```javascript
47
- import { SuperSonic } from 'https://unpkg.com/supersonic-scsynth@latest';
51
+ import { SuperSonic } from './dist/supersonic.js';
48
52
  ```
49
53
 
50
- **Pre-built distribution:**
51
- Download the 'nightly' build (~35MB with all synthdefs and samples):
52
- https://samaaron.github.io/supersonic/supersonic-dist.zip
53
-
54
54
  ## Packages
55
55
 
56
56
  SuperSonic is split into multiple packages:
@@ -69,8 +69,8 @@ All synthdefs and samples are from [Sonic Pi](https://github.com/sonic-pi-net/so
69
69
  **Creating an instance:**
70
70
  ```javascript
71
71
  const sonic = new SuperSonic({
72
- sampleBaseURL: 'https://unpkg.com/supersonic-scsynth-samples@latest/samples/',
73
- synthdefBaseURL: 'https://unpkg.com/supersonic-scsynth-synthdefs@latest/synthdefs/',
72
+ sampleBaseURL: './dist/samples/',
73
+ synthdefBaseURL: './dist/synthdefs/',
74
74
  audioPathMap: { /* optional custom path mappings */ }
75
75
  });
76
76
  ```
@@ -121,6 +121,41 @@ Cross-Origin-Resource-Policy: cross-origin
121
121
 
122
122
  See `example/server.rb` for a reference implementation.
123
123
 
124
+ ## CDN Usage
125
+
126
+ SuperSonic cannot be loaded from a CDN. The core library must be self-hosted on your domain.
127
+
128
+ ### Why Self-Hosting is Required
129
+
130
+ SuperSonic uses `SharedArrayBuffer` for real-time audio performance. Browsers require workers that use `SharedArrayBuffer` to come from the same origin as the page. Even with proper COOP/COEP headers, cross-origin workers with shared memory are blocked. This is a fundamental browser security requirement stemming from Spectre attack mitigation.
131
+
132
+ What this means:
133
+ - You cannot use `import { SuperSonic } from 'https://unpkg.com/supersonic/...'`
134
+ - You must download and self-host the core library on your own domain
135
+ - The npm packages exist for convenience but must be bundled and deployed to your server
136
+
137
+ ### Synthdefs and Samples Can Use CDN
138
+
139
+ Pre-compiled synthdefs and audio samples can be loaded from CDNs. They're just data files, not workers.
140
+
141
+ ```javascript
142
+ // Self-hosted core library
143
+ import { SuperSonic } from './dist/supersonic.js';
144
+
145
+ // CDN-hosted synthdefs and samples work fine
146
+ const sonic = new SuperSonic({
147
+ sampleBaseURL: 'https://unpkg.com/supersonic-scsynth-samples@0.1.6/samples/',
148
+ synthdefBaseURL: 'https://unpkg.com/supersonic-scsynth-synthdefs@0.1.6/synthdefs/'
149
+ });
150
+
151
+ await sonic.init();
152
+ await sonic.loadSynthDefs(['sonic-pi-beep', 'sonic-pi-tb303']);
153
+ ```
154
+
155
+ ### Hybrid Approach
156
+
157
+ Self-host the SuperSonic core (JS, WASM, workers) with COOP/COEP headers. Use CDN for synthdefs and samples to save bandwidth. See `example/simple-cdn.html` for a working example.
158
+
124
159
  ## Building from Source
125
160
 
126
161
  **Prerequisites:**
@@ -799,9 +799,9 @@ var ScsynthOSC = class {
799
799
  this.ringBufferBase = ringBufferBase;
800
800
  this.bufferConstants = bufferConstants;
801
801
  try {
802
- this.workers.oscOut = new Worker(new URL("./workers/osc_out_prescheduler_worker.js", import.meta.url));
803
- this.workers.oscIn = new Worker(new URL("./workers/osc_in_worker.js", import.meta.url));
804
- this.workers.debug = new Worker(new URL("./workers/debug_worker.js", import.meta.url));
802
+ this.workers.oscOut = new Worker(new URL("./workers/osc_out_prescheduler_worker.js", import.meta.url), { type: "module" });
803
+ this.workers.oscIn = new Worker(new URL("./workers/osc_in_worker.js", import.meta.url), { type: "module" });
804
+ this.workers.debug = new Worker(new URL("./workers/debug_worker.js", import.meta.url), { type: "module" });
805
805
  this.setupWorkerHandlers();
806
806
  const initPromises = [
807
807
  this.initWorker(this.workers.oscOut, "OSC SCHEDULER+WRITER"),
@@ -2324,7 +2324,7 @@ var SuperSonic = class _SuperSonic {
2324
2324
  }
2325
2325
  if (!this.sampleBaseURL) {
2326
2326
  throw new Error(
2327
- 'sampleBaseURL not configured. Please set it in SuperSonic constructor options.\nExample: new SuperSonic({ sampleBaseURL: "https://unpkg.com/supersonic-scsynth-samples@latest/samples/" })\nOr install sample packages: npm install supersonic-scsynth-samples'
2327
+ 'sampleBaseURL not configured. Please set it in SuperSonic constructor options.\nExample: new SuperSonic({ sampleBaseURL: "./dist/samples/" })\nOr use CDN: new SuperSonic({ sampleBaseURL: "https://unpkg.com/supersonic-scsynth-samples@latest/samples/" })\nOr install: npm install supersonic-scsynth-samples'
2328
2328
  );
2329
2329
  }
2330
2330
  return this.sampleBaseURL + scPath;
@@ -2525,7 +2525,7 @@ var SuperSonic = class _SuperSonic {
2525
2525
  }
2526
2526
  if (!this.synthdefBaseURL) {
2527
2527
  throw new Error(
2528
- 'synthdefBaseURL not configured. Please set it in SuperSonic constructor options.\nExample: new SuperSonic({ synthdefBaseURL: "https://unpkg.com/supersonic-scsynth-synthdefs@latest/synthdefs/" })\nOr install: npm install supersonic-scsynth-synthdefs'
2528
+ 'synthdefBaseURL not configured. Please set it in SuperSonic constructor options.\nExample: new SuperSonic({ synthdefBaseURL: "./dist/synthdefs/" })\nOr use CDN: new SuperSonic({ synthdefBaseURL: "https://unpkg.com/supersonic-scsynth-synthdefs@latest/synthdefs/" })\nOr install: npm install supersonic-scsynth-synthdefs'
2529
2529
  );
2530
2530
  }
2531
2531
  const results = {};
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "wasmFile": "scsynth-nrt.wasm",
3
- "buildId": "20251114-215318",
4
- "buildTime": "2025-11-14T21:53:18Z",
5
- "gitHash": "402d831"
3
+ "buildId": "20251115-234621",
4
+ "buildTime": "2025-11-15T23:46:21Z",
5
+ "gitHash": "ec0ed48"
6
6
  }
Binary file
@@ -243,7 +243,7 @@ function clear() {
243
243
  /**
244
244
  * Handle messages from main thread
245
245
  */
246
- self.onmessage = function(event) {
246
+ self.addEventListener('message', function(event) {
247
247
  var data = event.data;
248
248
 
249
249
  try {
@@ -282,6 +282,6 @@ self.onmessage = function(event) {
282
282
  error: error.message
283
283
  });
284
284
  }
285
- };
285
+ });
286
286
 
287
287
  debugWorkerLog('[DebugWorker] Script loaded');
@@ -243,7 +243,7 @@ function stop() {
243
243
  /**
244
244
  * Handle messages from main thread
245
245
  */
246
- self.onmessage = function(event) {
246
+ self.addEventListener('message', function(event) {
247
247
  var data = event.data;
248
248
 
249
249
  try {
@@ -278,6 +278,6 @@ self.onmessage = function(event) {
278
278
  error: error.message
279
279
  });
280
280
  }
281
- };
281
+ });
282
282
 
283
283
  oscInLog('[OSCInWorker] Script loaded');
@@ -482,7 +482,7 @@ function processImmediate(oscData) {
482
482
  }
483
483
 
484
484
  // Message handling
485
- self.onmessage = function(event) {
485
+ self.addEventListener('message', function(event) {
486
486
  var data = event.data;
487
487
 
488
488
  try {
@@ -570,6 +570,6 @@ self.onmessage = function(event) {
570
570
  error: error.message
571
571
  });
572
572
  }
573
- };
573
+ });
574
574
 
575
575
  schedulerLog('[OSCPreSchedulerWorker] Script loaded');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supersonic-scsynth",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "SuperCollider scsynth WebAssembly port for AudioWorklet - Run SuperCollider synthesis in the browser",
5
5
  "main": "dist/supersonic.js",
6
6
  "unpkg": "dist/supersonic.js",