qurantathbit 0.0.0-stage → 1.0.2
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/LICENSE +48 -0
- package/README.npm.md +43 -0
- package/decks/quran/001/001001.mp3 +0 -0
- package/decks/quran/001/001002.mp3 +0 -0
- package/decks/quran/002/001003.mp3 +0 -0
- package/decks/quran/003/001004.mp3 +0 -0
- package/decks/quran/004/001005.mp3 +0 -0
- package/decks/quran/005/001006.mp3 +0 -0
- package/decks/quran/006/001007.mp3 +0 -0
- package/decks/quran/007/002001.mp3 +0 -0
- package/decks/quran/008/002002.mp3 +0 -0
- package/decks/quran/009/002003.mp3 +0 -0
- package/decks/quran/010/002004.mp3 +0 -0
- package/decks/quran/011/002005.mp3 +0 -0
- package/decks/quran/012/002006.mp3 +0 -0
- package/decks/quran/013/002007.mp3 +0 -0
- package/decks/quran/014/002008.mp3 +0 -0
- package/decks/quran/015/002009.mp3 +0 -0
- package/decks/quran/016/002010.mp3 +0 -0
- package/decks/quran/017/002011.mp3 +0 -0
- package/decks/quran/018/002012.mp3 +0 -0
- package/decks/quran/019/002013.mp3 +0 -0
- package/decks/quran/020/002014.mp3 +0 -0
- package/decks/quran/021/002015.mp3 +0 -0
- package/decks/quran/022/002016.mp3 +0 -0
- package/decks/quran/023/002017.mp3 +0 -0
- package/decks/quran/024/002018.mp3 +0 -0
- package/decks/quran/025/002019.mp3 +0 -0
- package/decks/quran/026/002020.mp3 +0 -0
- package/decks/quran/027/002021.mp3 +0 -0
- package/decks/quran/028/002022.mp3 +0 -0
- package/decks/quran/029/002023.mp3 +0 -0
- package/decks/quran/030/002024.mp3 +0 -0
- package/decks/quran/031/002025.mp3 +0 -0
- package/decks/quran/032/002026.mp3 +0 -0
- package/decks/quran/033/002027.mp3 +0 -0
- package/decks/quran/034/002028.mp3 +0 -0
- package/decks/quran/035/002029.mp3 +0 -0
- package/decks/quran/036/002030.mp3 +0 -0
- package/decks/quran/037/002031.mp3 +0 -0
- package/decks/quran/038/002032.mp3 +0 -0
- package/decks/quran/039/002033.mp3 +0 -0
- package/decks/quran/040/002034.mp3 +0 -0
- package/decks/quran/041/002035.mp3 +0 -0
- package/decks/quran/042/002036.mp3 +0 -0
- package/decks/quran/043/002037.mp3 +0 -0
- package/decks/quran/044/002038.mp3 +0 -0
- package/decks/quran/045/002039.mp3 +0 -0
- package/decks/quran/046/002040.mp3 +0 -0
- package/decks/quran/047/002041.mp3 +0 -0
- package/decks/quran/048/002042.mp3 +0 -0
- package/decks/quran/049/002043.mp3 +0 -0
- package/decks/quran/050/002044.mp3 +0 -0
- package/decks/quran/051/002045.mp3 +0 -0
- package/decks/quran/052/002046.mp3 +0 -0
- package/decks/quran/053/002047.mp3 +0 -0
- package/decks/quran/054/002048.mp3 +0 -0
- package/decks/quran/055/002049.mp3 +0 -0
- package/decks/quran/056/002050.mp3 +0 -0
- package/decks/quran/057/002051.mp3 +0 -0
- package/decks/quran/058/002052.mp3 +0 -0
- package/decks/quran/059/002053.mp3 +0 -0
- package/decks/quran/060/002054.mp3 +0 -0
- package/decks/quran/061/002055.mp3 +0 -0
- package/decks/quran/062/002056.mp3 +0 -0
- package/decks/quran/063/002057.mp3 +0 -0
- package/decks/quran/064/002058.mp3 +0 -0
- package/decks/quran/065/002059.mp3 +0 -0
- package/decks/quran/066/002060.mp3 +0 -0
- package/decks/quran/067/002061.mp3 +0 -0
- package/decks/quran/068/002062.mp3 +0 -0
- package/decks/quran/069/002063.mp3 +0 -0
- package/decks/quran/070/002064.mp3 +0 -0
- package/decks/quran/071/002065.mp3 +0 -0
- package/decks/quran/072/002066.mp3 +0 -0
- package/decks/quran/073/002067.mp3 +0 -0
- package/decks/quran/074/002068.mp3 +0 -0
- package/decks/quran/075/002069.mp3 +0 -0
- package/decks/quran/076/002070.mp3 +0 -0
- package/decks/quran/077/002071.mp3 +0 -0
- package/decks/quran/078/002072.mp3 +0 -0
- package/decks/quran/079/002073.mp3 +0 -0
- package/decks/quran/080/002074.mp3 +0 -0
- package/decks/quran/081/002075.mp3 +0 -0
- package/decks/quran/082/002076.mp3 +0 -0
- package/decks/quran/083/002077.mp3 +0 -0
- package/decks/quran/084/002078.mp3 +0 -0
- package/decks/quran/085/002079.mp3 +0 -0
- package/decks/quran/086/002080.mp3 +0 -0
- package/decks/quran/087/002081.mp3 +0 -0
- package/decks/quran/088/002082.mp3 +0 -0
- package/decks/quran/089/002083.mp3 +0 -0
- package/decks/quran/090/002084.mp3 +0 -0
- package/decks/quran/091/002085.mp3 +0 -0
- package/decks/quran/092/002086.mp3 +0 -0
- package/decks/quran/093/002087.mp3 +0 -0
- package/decks/quran/094/002088.mp3 +0 -0
- package/decks/quran/095/002089.mp3 +0 -0
- package/decks/quran/096/002090.mp3 +0 -0
- package/decks/quran/097/002091.mp3 +0 -0
- package/decks/quran/098/002092.mp3 +0 -0
- package/decks/quran/099/002093.mp3 +0 -0
- package/index.apple-touch-icon.png +0 -0
- package/index.audio.position.worklet.js +66 -0
- package/index.audio.worklet.js +213 -0
- package/index.html +220 -0
- package/index.icon.png +0 -0
- package/index.js +909 -0
- package/index.pck +0 -0
- package/index.png +0 -0
- package/index.wasm +4 -0
- package/package.json +44 -4
- package/start.js +109 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mlibre
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
------------------------------------------------------------------------------
|
|
24
|
+
Data attribution
|
|
25
|
+
------------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
The deck shipped with this application — the Qur'anic verses (Arabic text),
|
|
28
|
+
their Persian translation, and the recitation audio — is data extracted from
|
|
29
|
+
the public export quran-cards-2026-10-14.apkg, whose contents come from:
|
|
30
|
+
|
|
31
|
+
https://quran.makarem.ir/
|
|
32
|
+
|
|
33
|
+
No other source is used for the card data. That data belongs to its source
|
|
34
|
+
above and is not itself licensed under the MIT terms above; it is included
|
|
35
|
+
solely as attributed content. The typefaces bundled in assets/fonts/ carry
|
|
36
|
+
their own open licenses (see the OFL files beside them).
|
|
37
|
+
|
|
38
|
+
------------------------------------------------------------------------------
|
|
39
|
+
Algorithm attribution
|
|
40
|
+
------------------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
The scheduling algorithm used by this application is a port of Anki's SM-2
|
|
43
|
+
review scheduler (itself derived from the classic SuperMemo-2 algorithm),
|
|
44
|
+
including Anki's deck defaults, ease adjustments, learning steps, lapse
|
|
45
|
+
handling, interval fuzzing and review queue. Anki is licensed under the GNU
|
|
46
|
+
AGPLv3; this project ships an independent reimplementation of the algorithm's
|
|
47
|
+
math (no Anki source code is included) and is not affiliated with or endorsed
|
|
48
|
+
by the Anki project. See https://apps.ankiweb.net/ for the original.
|
package/README.npm.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# QuranTathbit (web build)
|
|
2
|
+
|
|
3
|
+
A quiet companion for keeping the Qur'an close — one deck, one card at a time,
|
|
4
|
+
with your own GitHub as the cloud.
|
|
5
|
+
|
|
6
|
+
This npm package contains the prebuilt **web build** of QuranTathbit, ready to
|
|
7
|
+
serve from any static host or run with a single command.
|
|
8
|
+
|
|
9
|
+
## Use it
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx qurantathbit
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
That downloads the package and starts a small static server at
|
|
16
|
+
<http://localhost:8080>. Open it in your browser, press **Study**, and you are
|
|
17
|
+
in.
|
|
18
|
+
|
|
19
|
+
If you prefer to serve the files yourself, every file in this package is
|
|
20
|
+
static — `index.html`, the engine's `.js` and `.wasm`, the deck's `.pck`, and
|
|
21
|
+
the `decks/quran/` folder the recitations stream from. Drop them on any static
|
|
22
|
+
host (nginx, Caddy, GitHub Pages, an S3 bucket, anything) and they just work.
|
|
23
|
+
|
|
24
|
+
## What it is
|
|
25
|
+
|
|
26
|
+
- A small Godot 4.7 web app for memorising the Qur'an.
|
|
27
|
+
- 99 cards from Al-Fātiḥah and Al-Baqarah: the verse, the Persian translation,
|
|
28
|
+
and a recitation, all from [quran.makarem.ir](https://quran.makarem.ir).
|
|
29
|
+
- Spaced repetition (SM-2) that learns how well you remember.
|
|
30
|
+
- Optional sync through your own private GitHub repository.
|
|
31
|
+
|
|
32
|
+
## More
|
|
33
|
+
|
|
34
|
+
- **Project home:** <https://github.com/mlibre/QuranTathbit>
|
|
35
|
+
- **Play it on GitHub Pages:** <https://mlibre.github.io/QuranTathbit/>
|
|
36
|
+
- **Desktop builds:** <https://github.com/mlibre/QuranTathbit/releases>
|
|
37
|
+
- **License:** MIT (code); card data carries its own attribution (see LICENSE).
|
|
38
|
+
|
|
39
|
+
## 🇵🇸 In support of Palestine
|
|
40
|
+
|
|
41
|
+
This project stands with Palestine. If you are able, please consider donating
|
|
42
|
+
to [UNRWA](https://www.unrwa.org) or a trusted aid organization of your
|
|
43
|
+
choice.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**************************************************************************/
|
|
2
|
+
/* godot.audio.position.worklet.js */
|
|
3
|
+
/**************************************************************************/
|
|
4
|
+
/* This file is part of: */
|
|
5
|
+
/* GODOT ENGINE */
|
|
6
|
+
/* https://godotengine.org */
|
|
7
|
+
/**************************************************************************/
|
|
8
|
+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
9
|
+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
10
|
+
/* */
|
|
11
|
+
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
12
|
+
/* a copy of this software and associated documentation files (the */
|
|
13
|
+
/* "Software"), to deal in the Software without restriction, including */
|
|
14
|
+
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
15
|
+
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
16
|
+
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
17
|
+
/* the following conditions: */
|
|
18
|
+
/* */
|
|
19
|
+
/* The above copyright notice and this permission notice shall be */
|
|
20
|
+
/* included in all copies or substantial portions of the Software. */
|
|
21
|
+
/* */
|
|
22
|
+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
23
|
+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
24
|
+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
25
|
+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
26
|
+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
27
|
+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
28
|
+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
29
|
+
/**************************************************************************/
|
|
30
|
+
|
|
31
|
+
class GodotPositionReportingProcessor extends AudioWorkletProcessor {
|
|
32
|
+
static get parameterDescriptors() {
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
name: 'reset',
|
|
36
|
+
defaultValue: 0,
|
|
37
|
+
minValue: 0,
|
|
38
|
+
maxValue: 1,
|
|
39
|
+
automationRate: 'k-rate',
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
constructor(...args) {
|
|
45
|
+
super(...args);
|
|
46
|
+
this.position = 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
process(inputs, _outputs, parameters) {
|
|
50
|
+
if (parameters['reset'][0] > 0) {
|
|
51
|
+
this.position = 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (inputs.length > 0) {
|
|
55
|
+
const input = inputs[0];
|
|
56
|
+
if (input.length > 0) {
|
|
57
|
+
this.position += input[0].length;
|
|
58
|
+
this.port.postMessage({ type: 'position', data: this.position });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
registerProcessor('godot-position-reporting-processor', GodotPositionReportingProcessor);
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**************************************************************************/
|
|
2
|
+
/* audio.worklet.js */
|
|
3
|
+
/**************************************************************************/
|
|
4
|
+
/* This file is part of: */
|
|
5
|
+
/* GODOT ENGINE */
|
|
6
|
+
/* https://godotengine.org */
|
|
7
|
+
/**************************************************************************/
|
|
8
|
+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
9
|
+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
10
|
+
/* */
|
|
11
|
+
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
12
|
+
/* a copy of this software and associated documentation files (the */
|
|
13
|
+
/* "Software"), to deal in the Software without restriction, including */
|
|
14
|
+
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
15
|
+
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
16
|
+
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
17
|
+
/* the following conditions: */
|
|
18
|
+
/* */
|
|
19
|
+
/* The above copyright notice and this permission notice shall be */
|
|
20
|
+
/* included in all copies or substantial portions of the Software. */
|
|
21
|
+
/* */
|
|
22
|
+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
23
|
+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
24
|
+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
25
|
+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
26
|
+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
27
|
+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
28
|
+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
29
|
+
/**************************************************************************/
|
|
30
|
+
|
|
31
|
+
class RingBuffer {
|
|
32
|
+
constructor(p_buffer, p_state, p_threads) {
|
|
33
|
+
this.buffer = p_buffer;
|
|
34
|
+
this.avail = p_state;
|
|
35
|
+
this.threads = p_threads;
|
|
36
|
+
this.rpos = 0;
|
|
37
|
+
this.wpos = 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
data_left() {
|
|
41
|
+
return this.threads ? Atomics.load(this.avail, 0) : this.avail;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
space_left() {
|
|
45
|
+
return this.buffer.length - this.data_left();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
read(output) {
|
|
49
|
+
const size = this.buffer.length;
|
|
50
|
+
let from = 0;
|
|
51
|
+
let to_write = output.length;
|
|
52
|
+
if (this.rpos + to_write > size) {
|
|
53
|
+
const high = size - this.rpos;
|
|
54
|
+
output.set(this.buffer.subarray(this.rpos, size));
|
|
55
|
+
from = high;
|
|
56
|
+
to_write -= high;
|
|
57
|
+
this.rpos = 0;
|
|
58
|
+
}
|
|
59
|
+
if (to_write) {
|
|
60
|
+
output.set(this.buffer.subarray(this.rpos, this.rpos + to_write), from);
|
|
61
|
+
}
|
|
62
|
+
this.rpos += to_write;
|
|
63
|
+
if (this.threads) {
|
|
64
|
+
Atomics.add(this.avail, 0, -output.length);
|
|
65
|
+
Atomics.notify(this.avail, 0);
|
|
66
|
+
} else {
|
|
67
|
+
this.avail -= output.length;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
write(p_buffer) {
|
|
72
|
+
const to_write = p_buffer.length;
|
|
73
|
+
const mw = this.buffer.length - this.wpos;
|
|
74
|
+
if (mw >= to_write) {
|
|
75
|
+
this.buffer.set(p_buffer, this.wpos);
|
|
76
|
+
this.wpos += to_write;
|
|
77
|
+
if (mw === to_write) {
|
|
78
|
+
this.wpos = 0;
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
const high = p_buffer.subarray(0, mw);
|
|
82
|
+
const low = p_buffer.subarray(mw);
|
|
83
|
+
this.buffer.set(high, this.wpos);
|
|
84
|
+
this.buffer.set(low);
|
|
85
|
+
this.wpos = low.length;
|
|
86
|
+
}
|
|
87
|
+
if (this.threads) {
|
|
88
|
+
Atomics.add(this.avail, 0, to_write);
|
|
89
|
+
Atomics.notify(this.avail, 0);
|
|
90
|
+
} else {
|
|
91
|
+
this.avail += to_write;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
class GodotProcessor extends AudioWorkletProcessor {
|
|
97
|
+
constructor() {
|
|
98
|
+
super();
|
|
99
|
+
this.threads = false;
|
|
100
|
+
this.running = true;
|
|
101
|
+
this.lock = null;
|
|
102
|
+
this.notifier = null;
|
|
103
|
+
this.output = null;
|
|
104
|
+
this.output_buffer = new Float32Array();
|
|
105
|
+
this.input = null;
|
|
106
|
+
this.input_buffer = new Float32Array();
|
|
107
|
+
this.port.onmessage = (event) => {
|
|
108
|
+
const cmd = event.data['cmd'];
|
|
109
|
+
const data = event.data['data'];
|
|
110
|
+
this.parse_message(cmd, data);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
process_notify() {
|
|
115
|
+
if (this.notifier) {
|
|
116
|
+
Atomics.add(this.notifier, 0, 1);
|
|
117
|
+
Atomics.notify(this.notifier, 0);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
parse_message(p_cmd, p_data) {
|
|
122
|
+
if (p_cmd === 'start' && p_data) {
|
|
123
|
+
const state = p_data[0];
|
|
124
|
+
let idx = 0;
|
|
125
|
+
this.threads = true;
|
|
126
|
+
this.lock = state.subarray(idx, ++idx);
|
|
127
|
+
this.notifier = state.subarray(idx, ++idx);
|
|
128
|
+
const avail_in = state.subarray(idx, ++idx);
|
|
129
|
+
const avail_out = state.subarray(idx, ++idx);
|
|
130
|
+
this.input = new RingBuffer(p_data[1], avail_in, true);
|
|
131
|
+
this.output = new RingBuffer(p_data[2], avail_out, true);
|
|
132
|
+
} else if (p_cmd === 'stop') {
|
|
133
|
+
this.running = false;
|
|
134
|
+
this.output = null;
|
|
135
|
+
this.input = null;
|
|
136
|
+
this.lock = null;
|
|
137
|
+
this.notifier = null;
|
|
138
|
+
} else if (p_cmd === 'start_nothreads') {
|
|
139
|
+
this.output = new RingBuffer(p_data[0], p_data[0].length, false);
|
|
140
|
+
} else if (p_cmd === 'chunk') {
|
|
141
|
+
this.output.write(p_data);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
static array_has_data(arr) {
|
|
146
|
+
return arr.length && arr[0].length && arr[0][0].length;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
process(inputs, outputs, parameters) {
|
|
150
|
+
if (!this.running) {
|
|
151
|
+
return false; // Stop processing.
|
|
152
|
+
}
|
|
153
|
+
if (this.output === null) {
|
|
154
|
+
return true; // Not ready yet, keep processing.
|
|
155
|
+
}
|
|
156
|
+
const process_input = GodotProcessor.array_has_data(inputs);
|
|
157
|
+
if (process_input) {
|
|
158
|
+
const input = inputs[0];
|
|
159
|
+
const chunk = input[0].length * input.length;
|
|
160
|
+
if (this.input_buffer.length !== chunk) {
|
|
161
|
+
this.input_buffer = new Float32Array(chunk);
|
|
162
|
+
}
|
|
163
|
+
if (!this.threads) {
|
|
164
|
+
GodotProcessor.write_input(this.input_buffer, input);
|
|
165
|
+
this.port.postMessage({ 'cmd': 'input', 'data': this.input_buffer });
|
|
166
|
+
} else if (this.input.space_left() >= chunk) {
|
|
167
|
+
GodotProcessor.write_input(this.input_buffer, input);
|
|
168
|
+
this.input.write(this.input_buffer);
|
|
169
|
+
} else {
|
|
170
|
+
// this.port.postMessage('Input buffer is full! Skipping input frame.'); // Uncomment this line to debug input buffer.
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const process_output = GodotProcessor.array_has_data(outputs);
|
|
174
|
+
if (process_output) {
|
|
175
|
+
const output = outputs[0];
|
|
176
|
+
const chunk = output[0].length * output.length;
|
|
177
|
+
if (this.output_buffer.length !== chunk) {
|
|
178
|
+
this.output_buffer = new Float32Array(chunk);
|
|
179
|
+
}
|
|
180
|
+
if (this.output.data_left() >= chunk) {
|
|
181
|
+
this.output.read(this.output_buffer);
|
|
182
|
+
GodotProcessor.write_output(output, this.output_buffer);
|
|
183
|
+
if (!this.threads) {
|
|
184
|
+
this.port.postMessage({ 'cmd': 'read', 'data': chunk });
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
// this.port.postMessage('Output buffer has not enough frames! Skipping output frame.'); // Uncomment this line to debug output buffer.
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
this.process_notify();
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
static write_output(dest, source) {
|
|
195
|
+
const channels = dest.length;
|
|
196
|
+
for (let ch = 0; ch < channels; ch++) {
|
|
197
|
+
for (let sample = 0; sample < dest[ch].length; sample++) {
|
|
198
|
+
dest[ch][sample] = source[sample * channels + ch];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
static write_input(dest, source) {
|
|
204
|
+
const channels = source.length;
|
|
205
|
+
for (let ch = 0; ch < channels; ch++) {
|
|
206
|
+
for (let sample = 0; sample < source[ch].length; sample++) {
|
|
207
|
+
dest[sample * channels + ch] = source[ch][sample];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
registerProcessor('godot-processor', GodotProcessor);
|