You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39Lines changed: 39 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,7 @@ If you prefer to load fluid-js as an ES module, you can use `import` statement s
64
64
Notes:
65
65
66
66
*`fluid.js` intends the ES2015-supported environment. If you need to run the script without errors on non-ES2015 environment such as IE11 (to notify 'unsupported'), you should load those scripts dynamically, or use transpiler such as babel.
67
+
* When just after the scripts loaded, some APIs may fail since libfluidsynth is not ready. To avoid this, you can use the Promise object returned by `Fluid.waitForReady`.
67
68
* libfluidsynth JS file is not `import`-able and its license (LGPL v2.1) is differ from fluid-js's (BSD-3-Clause).
fluid-js and libfluidsynth can be executed on a Web Worker. Executing on a Web Worker prevents from blocking main thread while rendering.
103
+
104
+
To use fluid-js on a Web Worker, simply call `importScripts` as followings:
105
+
106
+
```js
107
+
self.importScripts('libfluidsynth-2.0.1.js');
108
+
self.importScripts('fluid.js');
109
+
```
110
+
111
+
(You can also load fluid-js as an ES Module from the Web Worker.)
112
+
113
+
Note that since the Web Audio is not supported on the Web Worker, the APIs/methods related to the Web Audio will not work. If you want to use both Web Worker and AudioWorklet, you should implement AudioWorkletProcessor manually as followings:
114
+
115
+
* main thread -- create AudioWorkletNode and establish connections between Web Worker and AudioWorklet
116
+
* You must transfer rendered audio frames from Web Worker to AudioWorklet because AudioWorklet environment does not support creating Web Worker. By creating `MessageChannel` and sending its port instances to Web Worker and AudioWorklet, they can communicate each other directly.
117
+
* Web Worker thread -- render audio frames into raw buffers and send it for AudioWorklet thread
118
+
* AudioWorklet thread -- receive audio frames and 'render' it in the `process` method
119
+
99
120
## API
100
121
101
122
### Creation of Synthesizer instance
@@ -106,6 +127,24 @@ These classes implement the interface named `Fluid.ISynthesizer`.
106
127
* Creates the general synthesizer instance. No parameters are available.
* Returns the Promise object that resolves with `Fluid.ISequencer` instance. The instance can be used with `Fluid.AudioWorkletNodeSynthesizer` instances which handled `createSequencer` calls.
140
+
141
+
### `Fluid` methods
142
+
143
+
#### `waitForReady`
144
+
145
+
Can be used to wait for the synthesizer engine's ready.
146
+
147
+
Return: `Promise` object (resolves when the synthesizer engine (libfluidsynth) is ready)
0 commit comments