sfml.js 1.0.0 → 1.2.1
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.ja.md +10 -9
- package/README.ko.md +10 -9
- package/README.md +10 -9
- package/README.zh-CN.md +10 -9
- package/binding.gyp +23 -16
- package/dist/audio/effect-processor.js +9 -3
- package/dist/audio/input-sound-file.js +41 -15
- package/dist/audio/listener.js +33 -11
- package/dist/audio/music.js +41 -18
- package/dist/audio/output-sound-file.js +4 -2
- package/dist/audio/playback-device.js +11 -3
- package/dist/audio/sound-buffer-recorder.js +8 -5
- package/dist/audio/sound-buffer.js +40 -17
- package/dist/audio/sound-file-factory.js +21 -9
- package/dist/audio/sound-file-reader.js +21 -7
- package/dist/audio/sound-recorder.js +36 -15
- package/dist/audio/sound-source.js +117 -40
- package/dist/audio/sound-stream.js +14 -5
- package/dist/audio/sound.js +9 -4
- package/dist/audio/value.js +42 -16
- package/dist/graphics/blend-mode.js +2 -1
- package/dist/graphics/boolean-vector.d.ts +1 -2
- package/dist/graphics/boolean-vector.js +19 -9
- package/dist/graphics/color.js +2 -1
- package/dist/graphics/convex-shape.js +7 -3
- package/dist/graphics/font.js +52 -23
- package/dist/graphics/glsl-matrix.js +8 -3
- package/dist/graphics/glsl.js +47 -16
- package/dist/graphics/glyph.js +27 -10
- package/dist/graphics/image.js +30 -14
- package/dist/graphics/rect.js +15 -8
- package/dist/graphics/render-states.js +18 -9
- package/dist/graphics/render-target.js +49 -23
- package/dist/graphics/render-texture.js +24 -12
- package/dist/graphics/render-window.js +6 -3
- package/dist/graphics/shader.js +67 -32
- package/dist/graphics/shape.js +25 -13
- package/dist/graphics/sprite.js +19 -9
- package/dist/graphics/stencil-mode.js +10 -6
- package/dist/graphics/swap.js +2 -1
- package/dist/graphics/text.js +123 -48
- package/dist/graphics/texture.js +48 -24
- package/dist/graphics/transform.js +29 -13
- package/dist/graphics/transformable.js +2 -1
- package/dist/graphics/vertex-array.js +40 -18
- package/dist/graphics/vertex-buffer.js +39 -19
- package/dist/graphics/vertex.js +6 -3
- package/dist/graphics/view.js +30 -14
- package/dist/index.d.ts +4 -4
- package/dist/internal/audio-codec-registry.js +12 -6
- package/dist/internal/audio-input-stream.js +2 -1
- package/dist/internal/audio-music-pump.js +58 -24
- package/dist/internal/audio-recorder-session.js +17 -7
- package/dist/internal/audio-worker-session.js +28 -10
- package/dist/internal/audio-worker.js +40 -21
- package/dist/internal/glsl-value.d.ts +3 -1
- package/dist/internal/glsl-value.js +18 -8
- package/dist/internal/graphics-state.js +29 -15
- package/dist/internal/input-stream.d.ts +3 -1
- package/dist/internal/input-stream.js +16 -7
- package/dist/internal/numeric-properties.js +2 -1
- package/dist/internal/render-states.js +2 -1
- package/dist/internal/scalar.js +22 -13
- package/dist/internal/shaped-glyph.d.ts +3 -1
- package/dist/internal/shaped-glyph.js +12 -4
- package/dist/internal/struct-view.d.ts +3 -1
- package/dist/internal/struct-view.js +3 -1
- package/dist/internal/transformable.js +2 -1
- package/dist/network/common.js +23 -11
- package/dist/network/dns.js +25 -17
- package/dist/network/ftp.js +43 -18
- package/dist/network/http.js +126 -56
- package/dist/network/ip-address.js +50 -25
- package/dist/network/packet.js +63 -25
- package/dist/network/sftp.js +175 -74
- package/dist/network/socket-selector.js +28 -14
- package/dist/network/socket.js +71 -30
- package/dist/network/tcp-listener.js +42 -19
- package/dist/network/tcp-socket.js +111 -53
- package/dist/network/tls-material.js +2 -1
- package/dist/network/udp-socket.js +68 -33
- package/dist/system/angle.js +2 -1
- package/dist/system/clock.js +4 -2
- package/dist/system/err.js +5 -2
- package/dist/system/file-input-stream.js +8 -4
- package/dist/system/input-stream.js +6 -3
- package/dist/system/operators.d.ts +1 -1
- package/dist/system/operators.js +90 -50
- package/dist/system/sleep.js +4 -2
- package/dist/system/time.js +12 -6
- package/dist/system/vector2.js +6 -7
- package/dist/system/vector3.js +11 -6
- package/dist/window/clipboard.js +2 -1
- package/dist/window/context.js +10 -5
- package/dist/window/cursor.js +2 -1
- package/dist/window/event.js +9 -5
- package/dist/window/mouse.js +4 -2
- package/dist/window/video-mode.js +2 -1
- package/dist/window/window.js +19 -12
- package/native/addon.cc +25 -12
- package/native/audio-binding.cc +266 -126
- package/native/audio-codec-binding.cc +147 -77
- package/native/audio-device-binding.cc +76 -49
- package/native/audio-file-binding.cc +116 -67
- package/native/audio-recorder-binding.cc +147 -98
- package/native/audio-recorder.h +1 -1
- package/native/audio-state.h +53 -30
- package/native/audio-stream-binding.cc +148 -94
- package/native/audio-stream.h +5 -4
- package/native/audio-worker-binding.cc +163 -81
- package/native/audio-worker.h +35 -19
- package/native/batch-drawable.cc +29 -16
- package/native/batch-drawable.h +11 -8
- package/native/context-binding.cc +40 -27
- package/native/context-settings.h +15 -8
- package/native/deferred-delete.cc +9 -6
- package/native/deferred-delete.h +7 -8
- package/native/error-stream-binding.cc +42 -28
- package/native/font-binding.cc +89 -48
- package/native/graphics-binding.cc +122 -72
- package/native/graphics-state.h +50 -36
- package/native/image-binding.cc +38 -24
- package/native/image-state.h +26 -18
- package/native/input-binding.cc +42 -27
- package/native/render-window-binding.cc +38 -23
- package/native/shader-binding.cc +115 -50
- package/native/shape-binding.cc +94 -49
- package/native/shape-state.h +18 -9
- package/native/shaped-glyph-storage.h +9 -5
- package/native/stream-binding.cc +143 -117
- package/native/system-binding.cc +17 -12
- package/native/text-binding.cc +68 -35
- package/native/text-state.h +25 -18
- package/native/texture-binding.cc +42 -33
- package/native/texture-resource.h +20 -12
- package/native/time-value.h +3 -1
- package/native/transformable-binding.cc +12 -6
- package/native/transformable-state.h +6 -6
- package/native/value-binding.h +46 -28
- package/native/value-layout.h +10 -10
- package/native/values-binding.cc +29 -23
- package/native/vertex-binding.cc +18 -12
- package/native/vertex-buffer-binding.cc +38 -24
- package/native/vertex-storage.h +2 -2
- package/native/view-data.h +4 -3
- package/native/window-binding.cc +75 -45
- package/native/window-event.h +20 -11
- package/native/window-owner.h +15 -12
- package/package.json +44 -51
- package/src/audio/effect-processor.ts +9 -3
- package/src/audio/input-sound-file.ts +108 -36
- package/src/audio/listener.ts +39 -13
- package/src/audio/music.ts +112 -47
- package/src/audio/output-sound-file.ts +40 -11
- package/src/audio/playback-device.ts +23 -8
- package/src/audio/sound-buffer-recorder.ts +35 -13
- package/src/audio/sound-buffer.ts +166 -58
- package/src/audio/sound-file-factory.ts +127 -49
- package/src/audio/sound-file-reader.ts +49 -15
- package/src/audio/sound-recorder.ts +100 -34
- package/src/audio/sound-source.ts +142 -45
- package/src/audio/sound-stream.ts +15 -5
- package/src/audio/sound.ts +12 -4
- package/src/audio/value.ts +89 -26
- package/src/graphics/blend-mode.ts +3 -1
- package/src/graphics/boolean-vector.ts +56 -26
- package/src/graphics/color.ts +3 -1
- package/src/graphics/convex-shape.ts +10 -3
- package/src/graphics/font.ts +171 -50
- package/src/graphics/glsl-matrix.ts +9 -3
- package/src/graphics/glsl.ts +81 -35
- package/src/graphics/glyph.ts +67 -26
- package/src/graphics/image.ts +119 -45
- package/src/graphics/rect.ts +56 -24
- package/src/graphics/render-states.ts +31 -14
- package/src/graphics/render-target.ts +197 -81
- package/src/graphics/render-texture.ts +36 -12
- package/src/graphics/render-window.ts +9 -3
- package/src/graphics/shader.ts +186 -61
- package/src/graphics/shape.ts +93 -35
- package/src/graphics/sprite.ts +64 -25
- package/src/graphics/stencil-mode.ts +12 -6
- package/src/graphics/swap.ts +3 -2
- package/src/graphics/text.ts +229 -74
- package/src/graphics/texture.ts +180 -61
- package/src/graphics/transform.ts +132 -47
- package/src/graphics/transformable.ts +3 -1
- package/src/graphics/vertex-array.ts +87 -35
- package/src/graphics/vertex-buffer.ts +97 -33
- package/src/graphics/vertex.ts +9 -3
- package/src/graphics/view.ts +59 -21
- package/src/index.ts +101 -23
- package/src/internal/audio-codec-registry.ts +18 -6
- package/src/internal/audio-input-stream.ts +6 -2
- package/src/internal/audio-music-pump.ts +116 -41
- package/src/internal/audio-native.ts +249 -96
- package/src/internal/audio-recorder-session.ts +68 -24
- package/src/internal/audio-worker-session.ts +65 -21
- package/src/internal/audio-worker.ts +85 -41
- package/src/internal/glsl-value.ts +26 -11
- package/src/internal/graphics-state.ts +57 -20
- package/src/internal/input-stream.ts +23 -10
- package/src/internal/native.ts +252 -99
- package/src/internal/numeric-properties.ts +2 -1
- package/src/internal/render-states.ts +3 -1
- package/src/internal/scalar.ts +33 -14
- package/src/internal/shaped-glyph.ts +25 -12
- package/src/internal/struct-view.ts +40 -13
- package/src/internal/transformable.ts +3 -1
- package/src/network/common.ts +35 -11
- package/src/network/dns.ts +95 -38
- package/src/network/ftp.ts +129 -47
- package/src/network/http.ts +232 -77
- package/src/network/ip-address.ts +118 -48
- package/src/network/packet.ts +161 -54
- package/src/network/sftp.ts +498 -168
- package/src/network/socket-selector.ts +66 -26
- package/src/network/socket.ts +133 -46
- package/src/network/tcp-listener.ts +78 -29
- package/src/network/tcp-socket.ts +240 -95
- package/src/network/tls-material.ts +6 -2
- package/src/network/udp-socket.ts +147 -53
- package/src/system/angle.ts +3 -1
- package/src/system/clock.ts +12 -4
- package/src/system/err.ts +5 -2
- package/src/system/file-input-stream.ts +12 -4
- package/src/system/input-stream.ts +9 -3
- package/src/system/operators.ts +290 -115
- package/src/system/sleep.ts +6 -2
- package/src/system/time.ts +18 -6
- package/src/system/timeout-with-predicate.ts +19 -8
- package/src/system/vector2.ts +101 -49
- package/src/system/vector3.ts +85 -36
- package/src/window/clipboard.ts +3 -1
- package/src/window/context.ts +15 -5
- package/src/window/cursor.ts +3 -1
- package/src/window/event.ts +26 -12
- package/src/window/mouse.ts +6 -2
- package/src/window/video-mode.ts +3 -1
- package/src/window/window.ts +119 -37
- package/test/native/audio-probes.cc +74 -36
- package/test/native/deferred-delete-probes.cc +17 -11
- package/test/native/drawable-probes.cc +70 -36
- package/test/native/exception-probes.cc +14 -9
- package/test/native/image-probes.cc +20 -10
- package/test/native/matrix-probes.cc +8 -4
- package/test/native/network-oracle.cc +17 -11
- package/test/native/render-texture-probes.cc +33 -24
- package/test/native/shader-probes.cc +9 -9
- package/test/native/shape-probes.cc +37 -23
- package/test/native/sprite-probes.cc +41 -25
- package/test/native/system-probes.cc +58 -35
- package/test/native/text-probes.cc +77 -44
- package/test/native/texture-probes.cc +43 -26
- package/test/native/time-probes.cc +18 -12
- package/test/native/transform-probes.cc +15 -10
- package/test/native/transformable-probes.cc +23 -17
- package/test/native/value-oracle.h +9 -4
- package/test/native/value-probes.cc +31 -23
- package/test/native/vertex-array-probes.cc +22 -14
- package/test/native/vertex-buffer-probes.cc +28 -17
- package/test/native/view-probes.cc +29 -17
- package/test/native/window-probes.cc +66 -33
- package/tools/ensure-sfml.cjs +9 -0
- package/tools/generate-network-constants.cjs +11 -6
- package/tools/generate-window-constants.cjs +31 -12
- package/docs/README.ja.md +0 -30
- package/docs/README.ko.md +0 -30
- package/docs/README.md +0 -30
- package/docs/README.zh-CN.md +0 -30
- package/docs/api.ja.md +0 -84
- package/docs/api.ko.md +0 -84
- package/docs/api.md +0 -81
- package/docs/api.zh-CN.md +0 -81
- package/docs/audio.ja.md +0 -249
- package/docs/audio.ko.md +0 -251
- package/docs/audio.md +0 -252
- package/docs/audio.zh-CN.md +0 -252
- package/docs/concepts.ja.md +0 -130
- package/docs/concepts.ko.md +0 -130
- package/docs/concepts.md +0 -131
- package/docs/concepts.zh-CN.md +0 -131
- package/docs/development.ja.md +0 -144
- package/docs/development.ko.md +0 -144
- package/docs/development.md +0 -146
- package/docs/development.zh-CN.md +0 -146
- package/docs/getting-started.ja.md +0 -154
- package/docs/getting-started.ko.md +0 -154
- package/docs/getting-started.md +0 -156
- package/docs/getting-started.zh-CN.md +0 -156
- package/docs/graphics.ja.md +0 -256
- package/docs/graphics.ko.md +0 -254
- package/docs/graphics.md +0 -255
- package/docs/graphics.zh-CN.md +0 -257
- package/docs/network.ja.md +0 -214
- package/docs/network.ko.md +0 -216
- package/docs/network.md +0 -218
- package/docs/network.zh-CN.md +0 -218
- package/docs/system.ja.md +0 -169
- package/docs/system.ko.md +0 -171
- package/docs/system.md +0 -173
- package/docs/system.zh-CN.md +0 -173
- package/docs/window.ja.md +0 -138
- package/docs/window.ko.md +0 -140
- package/docs/window.md +0 -141
- package/docs/window.zh-CN.md +0 -141
- package/native/exception-boundary.h +0 -97
- package/native/numeric-fields.h +0 -96
- package/native/shared-handle.h +0 -107
- package/test/tsconfig.json +0 -8
- package/tools/configure-lsp.cjs +0 -23
- package/tools/lib_downloader.cjs +0 -92
- package/tools/lib_downloader_urls.cjs +0 -23
|
@@ -21,7 +21,8 @@ class AudioMusicPump {
|
|
|
21
21
|
this.rejectReady = reject;
|
|
22
22
|
});
|
|
23
23
|
void this.ready.catch(() => { });
|
|
24
|
-
this.done = Promise.resolve()
|
|
24
|
+
this.done = Promise.resolve()
|
|
25
|
+
.then(() => this.run(token))
|
|
25
26
|
.catch((error) => {
|
|
26
27
|
if (!this.closed || !(0, audio_input_stream_1.isAudioInputCancellation)(error)) {
|
|
27
28
|
this.failure ?? (this.failure = error instanceof Error ? error : new Error(String(error)));
|
|
@@ -31,11 +32,17 @@ class AudioMusicPump {
|
|
|
31
32
|
.finally(() => this.resolveReady(false));
|
|
32
33
|
}
|
|
33
34
|
/** 最近的解码或用户回调错误。 */
|
|
34
|
-
get error() {
|
|
35
|
+
get error() {
|
|
36
|
+
return this.failure;
|
|
37
|
+
}
|
|
35
38
|
/** 读取 Native 队列的累计统计。 */
|
|
36
39
|
getStats() {
|
|
37
40
|
const fields = new BigUint64Array(audio_native_1.audioNative.audioWorkerStats(this.handle));
|
|
38
|
-
return {
|
|
41
|
+
return {
|
|
42
|
+
underruns: fields[0],
|
|
43
|
+
overruns: fields[1],
|
|
44
|
+
processed: fields[2],
|
|
45
|
+
};
|
|
39
46
|
}
|
|
40
47
|
/** 请求关闭但不等待当前用户回调,允许在回调内安全调用。 */
|
|
41
48
|
requestClose() {
|
|
@@ -48,8 +55,9 @@ class AudioMusicPump {
|
|
|
48
55
|
async close() {
|
|
49
56
|
this.requestClose();
|
|
50
57
|
await this.done;
|
|
51
|
-
if (this.failure)
|
|
58
|
+
if (this.failure) {
|
|
52
59
|
throw this.failure;
|
|
60
|
+
}
|
|
53
61
|
}
|
|
54
62
|
/** 默认解码实现;只能由当前会话的 onGetData 调用。 */
|
|
55
63
|
async onGetData(chunk) {
|
|
@@ -62,41 +70,54 @@ class AudioMusicPump {
|
|
|
62
70
|
const position = this.file.getSampleOffset();
|
|
63
71
|
const end = counts[3] + counts[4];
|
|
64
72
|
let size = chunk.samples.length;
|
|
65
|
-
if (fields[4] &&
|
|
66
|
-
|
|
73
|
+
if (fields[4] &&
|
|
74
|
+
counts[4] &&
|
|
75
|
+
position <= end &&
|
|
76
|
+
position + BigInt(size) > end) {
|
|
67
77
|
size = Number(end - position);
|
|
78
|
+
}
|
|
68
79
|
let count;
|
|
69
80
|
try {
|
|
70
81
|
count = await this.file.read(chunk.samples.subarray(0, size));
|
|
71
82
|
}
|
|
72
83
|
catch (error) {
|
|
73
|
-
if (!this.closed || !(0, audio_input_stream_1.isAudioInputCancellation)(error))
|
|
84
|
+
if (!this.closed || !(0, audio_input_stream_1.isAudioInputCancellation)(error)) {
|
|
74
85
|
throw error;
|
|
86
|
+
}
|
|
75
87
|
chunk.sampleCount = 0;
|
|
76
88
|
return false;
|
|
77
89
|
}
|
|
78
90
|
const next = position + count;
|
|
79
91
|
const loopEnd = fields[4] !== 0 && counts[4] !== 0n && next === end;
|
|
80
92
|
chunk.sampleCount = Number(count);
|
|
81
|
-
this.loopOffset = loopEnd
|
|
93
|
+
this.loopOffset = loopEnd
|
|
94
|
+
? counts[3]
|
|
95
|
+
: next >= counts[2]
|
|
96
|
+
? 0n
|
|
97
|
+
: undefined;
|
|
82
98
|
return count !== 0n && next < counts[2] && !loopEnd;
|
|
83
99
|
}
|
|
84
100
|
/** 默认定位文件;时间以微秒表示。 */
|
|
85
101
|
async onSeek(offset) {
|
|
86
|
-
if (this.closed)
|
|
102
|
+
if (this.closed) {
|
|
87
103
|
return;
|
|
104
|
+
}
|
|
88
105
|
const target = this.seekTarget?.time === offset.asMicroseconds()
|
|
89
|
-
? this.seekTarget.sample
|
|
106
|
+
? this.seekTarget.sample
|
|
107
|
+
: offset;
|
|
90
108
|
try {
|
|
91
109
|
await this.file.seek(target);
|
|
92
110
|
}
|
|
93
111
|
catch (error) {
|
|
94
|
-
if (!this.closed || !(0, audio_input_stream_1.isAudioInputCancellation)(error))
|
|
112
|
+
if (!this.closed || !(0, audio_input_stream_1.isAudioInputCancellation)(error)) {
|
|
95
113
|
throw error;
|
|
114
|
+
}
|
|
96
115
|
}
|
|
97
116
|
}
|
|
98
117
|
/** 返回默认文件解码的下一轮交错样本位置。 */
|
|
99
|
-
onLoop() {
|
|
118
|
+
onLoop() {
|
|
119
|
+
return this.loopOffset;
|
|
120
|
+
}
|
|
100
121
|
/** 用户回调错误独立于取消状态保留,并进入 ready/close 错误通道。 */
|
|
101
122
|
async dispatch(callback) {
|
|
102
123
|
try {
|
|
@@ -121,18 +142,22 @@ class AudioMusicPump {
|
|
|
121
142
|
try {
|
|
122
143
|
for (;;) {
|
|
123
144
|
const operation = audio_native_1.audioNative.pollAudioWorker(mapping.handle);
|
|
124
|
-
if (operation === -3)
|
|
145
|
+
if (operation === -3) {
|
|
125
146
|
break;
|
|
147
|
+
}
|
|
126
148
|
if (operation === -2) {
|
|
127
149
|
const offset = new time_1.Time(times[0]);
|
|
128
|
-
this.seekTarget =
|
|
129
|
-
|
|
150
|
+
this.seekTarget =
|
|
151
|
+
times[5] >= 0n
|
|
152
|
+
? { time: times[0], sample: times[5] }
|
|
153
|
+
: undefined;
|
|
130
154
|
try {
|
|
131
155
|
if (this.callbacks) {
|
|
132
156
|
await this.dispatch(() => this.callbacks.onSeek(offset, this));
|
|
133
157
|
}
|
|
134
|
-
else
|
|
158
|
+
else {
|
|
135
159
|
await this.onSeek(offset);
|
|
160
|
+
}
|
|
136
161
|
}
|
|
137
162
|
finally {
|
|
138
163
|
this.seekTarget = undefined;
|
|
@@ -142,8 +167,9 @@ class AudioMusicPump {
|
|
|
142
167
|
if (operation === -1) {
|
|
143
168
|
await new Promise(resolve => {
|
|
144
169
|
this.timer = setTimeout(resolve, 2);
|
|
145
|
-
if (this.primed && !this.closed)
|
|
170
|
+
if (this.primed && !this.closed) {
|
|
146
171
|
this.timer.unref();
|
|
172
|
+
}
|
|
147
173
|
});
|
|
148
174
|
this.timer = undefined;
|
|
149
175
|
continue;
|
|
@@ -154,26 +180,34 @@ class AudioMusicPump {
|
|
|
154
180
|
const more = await (this.callbacks
|
|
155
181
|
? this.dispatch(() => this.callbacks.onGetData(chunk, this))
|
|
156
182
|
: this.onGetData(chunk));
|
|
157
|
-
if (this.closed)
|
|
183
|
+
if (this.closed) {
|
|
158
184
|
break;
|
|
185
|
+
}
|
|
159
186
|
if (typeof more !== 'boolean') {
|
|
160
187
|
throw new TypeError('onGetData must return a boolean');
|
|
161
188
|
}
|
|
162
189
|
if (chunk.samples !== samples) {
|
|
163
190
|
throw new TypeError('Fill the provided native sample buffer');
|
|
164
191
|
}
|
|
165
|
-
if (!Number.isInteger(chunk.sampleCount) ||
|
|
192
|
+
if (!Number.isInteger(chunk.sampleCount) ||
|
|
193
|
+
chunk.sampleCount < 0 ||
|
|
166
194
|
chunk.sampleCount > samples.length) {
|
|
167
195
|
throw new RangeError('Invalid stream sample count');
|
|
168
196
|
}
|
|
169
197
|
fields[2] = chunk.sampleCount;
|
|
170
198
|
fields[3] = +more;
|
|
171
|
-
const loop = more
|
|
172
|
-
?
|
|
173
|
-
|
|
199
|
+
const loop = more
|
|
200
|
+
? undefined
|
|
201
|
+
: await (this.callbacks
|
|
202
|
+
? this.dispatch(() => this.callbacks.onLoop(this))
|
|
203
|
+
: this.onLoop());
|
|
204
|
+
if (this.closed) {
|
|
174
205
|
break;
|
|
175
|
-
|
|
176
|
-
|
|
206
|
+
}
|
|
207
|
+
if (loop !== undefined &&
|
|
208
|
+
(typeof loop !== 'bigint' ||
|
|
209
|
+
loop < 0n ||
|
|
210
|
+
loop > 0x7fffffffffffffffn)) {
|
|
177
211
|
throw new RangeError('Invalid loop sample offset');
|
|
178
212
|
}
|
|
179
213
|
times[1] = loop ?? -1n;
|
|
@@ -9,13 +9,15 @@ const invocation = new node_async_hooks_1.AsyncLocalStorage();
|
|
|
9
9
|
function currentRecorderSession(recorder) {
|
|
10
10
|
const context = invocation.getStore();
|
|
11
11
|
return context?.active && context.session.recorder === recorder
|
|
12
|
-
? context.session
|
|
12
|
+
? context.session
|
|
13
|
+
: undefined;
|
|
13
14
|
}
|
|
14
15
|
exports.currentRecorderSession = currentRecorderSession;
|
|
15
16
|
/** 取得 super 默认实现对应的会话;拒绝过期或阶段不匹配的异步调用。 */
|
|
16
17
|
function recorderCallbackSession(recorder, phase) {
|
|
17
18
|
const context = invocation.getStore();
|
|
18
|
-
if (!context?.active ||
|
|
19
|
+
if (!context?.active ||
|
|
20
|
+
context.phase !== phase ||
|
|
19
21
|
context.session.recorder !== recorder) {
|
|
20
22
|
throw new Error(`${phase} must run inside its active Recorder callback`);
|
|
21
23
|
}
|
|
@@ -87,8 +89,9 @@ class AudioRecorderSession {
|
|
|
87
89
|
this.draining = true;
|
|
88
90
|
this.timer?.ref();
|
|
89
91
|
await this.done;
|
|
90
|
-
if (this.error)
|
|
92
|
+
if (this.error) {
|
|
91
93
|
throw this.error;
|
|
94
|
+
}
|
|
92
95
|
}
|
|
93
96
|
/** 停止设备并等待本会话完整结束。 */
|
|
94
97
|
async stop() {
|
|
@@ -98,7 +101,11 @@ class AudioRecorderSession {
|
|
|
98
101
|
/** 返回 Native 队列统计,processed 的单位为交错样本。 */
|
|
99
102
|
getStats() {
|
|
100
103
|
const fields = new BigUint64Array(audio_native_1.audioNative.audioWorkerStats(this.handle));
|
|
101
|
-
return {
|
|
104
|
+
return {
|
|
105
|
+
underruns: fields[0],
|
|
106
|
+
overruns: fields[1],
|
|
107
|
+
processed: fields[2],
|
|
108
|
+
};
|
|
102
109
|
}
|
|
103
110
|
/** 保留首个错误,避免清理异常覆盖原始回调错误。 */
|
|
104
111
|
fail(error) {
|
|
@@ -131,17 +138,20 @@ class AudioRecorderSession {
|
|
|
131
138
|
started = await this.devices.run(() => (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.startAudioRecorder(this.recorder, callback)));
|
|
132
139
|
}
|
|
133
140
|
resolveReady(started && !this.stopping);
|
|
134
|
-
if (!started)
|
|
141
|
+
if (!started) {
|
|
135
142
|
return;
|
|
143
|
+
}
|
|
136
144
|
for (;;) {
|
|
137
145
|
const status = audio_native_1.audioNative.pollAudioWorker(this.handle);
|
|
138
|
-
if (status === -3)
|
|
146
|
+
if (status === -3) {
|
|
139
147
|
break;
|
|
148
|
+
}
|
|
140
149
|
if (status === -1) {
|
|
141
150
|
await new Promise(resolve => {
|
|
142
151
|
this.timer = setTimeout(resolve, 1);
|
|
143
|
-
if (!this.draining)
|
|
152
|
+
if (!this.draining) {
|
|
144
153
|
this.timer.unref();
|
|
154
|
+
}
|
|
145
155
|
});
|
|
146
156
|
this.timer = undefined;
|
|
147
157
|
continue;
|
|
@@ -11,25 +11,36 @@ class AudioWorkerSession {
|
|
|
11
11
|
constructor(handle, token, kind, options, context, onStop) {
|
|
12
12
|
this.handle = handle;
|
|
13
13
|
this.failure = {};
|
|
14
|
-
const module = options.module instanceof URL
|
|
14
|
+
const module = options.module instanceof URL
|
|
15
|
+
? options.module.href
|
|
15
16
|
: (0, node_url_1.pathToFileURL)((0, node_path_1.resolve)(options.module)).href;
|
|
16
17
|
const worker = new node_worker_threads_1.Worker((0, node_path_1.join)(__dirname, 'audio-worker.js'), {
|
|
17
|
-
workerData: {
|
|
18
|
-
|
|
18
|
+
workerData: {
|
|
19
|
+
token,
|
|
20
|
+
kind,
|
|
21
|
+
module,
|
|
22
|
+
exportName: options.exportName,
|
|
23
|
+
data: options.data,
|
|
24
|
+
context,
|
|
25
|
+
},
|
|
19
26
|
});
|
|
20
27
|
this.worker = worker;
|
|
21
28
|
const failure = this.failure;
|
|
22
29
|
let completed = false;
|
|
23
30
|
this.ready = new Promise((resolveReady, reject) => {
|
|
24
31
|
worker.on('message', (message) => {
|
|
25
|
-
if (message.type === 'closed')
|
|
32
|
+
if (message.type === 'closed') {
|
|
26
33
|
completed = true;
|
|
27
|
-
|
|
34
|
+
}
|
|
35
|
+
if (message.type === 'ready') {
|
|
28
36
|
resolveReady(true);
|
|
29
|
-
|
|
37
|
+
}
|
|
38
|
+
if (message.type === 'aborted') {
|
|
30
39
|
resolveReady(false);
|
|
31
|
-
|
|
40
|
+
}
|
|
41
|
+
if (message.type === 'stop') {
|
|
32
42
|
onStop?.();
|
|
43
|
+
}
|
|
33
44
|
if (message.type === 'error') {
|
|
34
45
|
failure.error = new error_1.SFMLError(message.error ?? 'Audio worker failed');
|
|
35
46
|
audio_native_1.audioNative.closeAudioWorker(handle);
|
|
@@ -62,10 +73,16 @@ class AudioWorkerSession {
|
|
|
62
73
|
});
|
|
63
74
|
cleanup.register(this, handle, this);
|
|
64
75
|
}
|
|
65
|
-
get error() {
|
|
76
|
+
get error() {
|
|
77
|
+
return this.failure.error;
|
|
78
|
+
}
|
|
66
79
|
getStats() {
|
|
67
80
|
const fields = new BigUint64Array(audio_native_1.audioNative.audioWorkerStats(this.handle));
|
|
68
|
-
return {
|
|
81
|
+
return {
|
|
82
|
+
underruns: fields[0],
|
|
83
|
+
overruns: fields[1],
|
|
84
|
+
processed: fields[2],
|
|
85
|
+
};
|
|
69
86
|
}
|
|
70
87
|
async close() {
|
|
71
88
|
cleanup.unregister(this);
|
|
@@ -75,8 +92,9 @@ class AudioWorkerSession {
|
|
|
75
92
|
async drain() {
|
|
76
93
|
this.worker.ref();
|
|
77
94
|
await this.done;
|
|
78
|
-
if (this.error)
|
|
95
|
+
if (this.error) {
|
|
79
96
|
throw this.error;
|
|
97
|
+
}
|
|
80
98
|
}
|
|
81
99
|
}
|
|
82
100
|
exports.AudioWorkerSession = AudioWorkerSession;
|
|
@@ -13,12 +13,15 @@ async function run() {
|
|
|
13
13
|
const handle = mapping.handle;
|
|
14
14
|
const fields = new Int32Array(mapping.fields);
|
|
15
15
|
const time = new BigInt64Array(mapping.time);
|
|
16
|
-
const pcm = setup.kind === 'effect'
|
|
16
|
+
const pcm = setup.kind === 'effect'
|
|
17
|
+
? []
|
|
17
18
|
: mapping.input.map(buffer => new Int16Array(buffer));
|
|
18
19
|
const input = setup.kind === 'effect'
|
|
19
|
-
? mapping.input.map(buffer => new Float32Array(buffer))
|
|
20
|
+
? mapping.input.map(buffer => new Float32Array(buffer))
|
|
21
|
+
: [];
|
|
20
22
|
const output = setup.kind === 'effect'
|
|
21
|
-
? mapping.output.map(buffer => new Float32Array(buffer))
|
|
23
|
+
? mapping.output.map(buffer => new Float32Array(buffer))
|
|
24
|
+
: [];
|
|
22
25
|
let callbacks = {};
|
|
23
26
|
try {
|
|
24
27
|
const module = await importModule(setup.module);
|
|
@@ -26,28 +29,33 @@ async function run() {
|
|
|
26
29
|
if (typeof factory !== 'function') {
|
|
27
30
|
throw new TypeError('Audio worker export must be a factory');
|
|
28
31
|
}
|
|
29
|
-
callbacks = await factory(setup.context, setup.data);
|
|
32
|
+
callbacks = (await factory(setup.context, setup.data));
|
|
30
33
|
const required = setup.kind === 'stream'
|
|
31
|
-
? ['onGetData', 'onSeek']
|
|
32
|
-
|
|
34
|
+
? ['onGetData', 'onSeek']
|
|
35
|
+
: setup.kind === 'recorder'
|
|
36
|
+
? ['onProcessSamples']
|
|
37
|
+
: ['process'];
|
|
33
38
|
for (const name of required) {
|
|
34
39
|
if (typeof callbacks[name] !== 'function') {
|
|
35
40
|
throw new TypeError(`Audio worker requires ${name}()`);
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
|
-
if (setup.kind === 'recorder' &&
|
|
39
|
-
|
|
43
|
+
if (setup.kind === 'recorder' &&
|
|
44
|
+
callbacks.onStart &&
|
|
45
|
+
!(await callbacks.onStart())) {
|
|
40
46
|
node_worker_threads_1.parentPort.postMessage({ type: 'aborted' });
|
|
41
47
|
return;
|
|
42
48
|
}
|
|
43
49
|
let ready = setup.kind !== 'stream';
|
|
44
|
-
if (ready)
|
|
50
|
+
if (ready) {
|
|
45
51
|
node_worker_threads_1.parentPort.postMessage({ type: 'ready' });
|
|
52
|
+
}
|
|
46
53
|
let primed = 0;
|
|
47
54
|
for (;;) {
|
|
48
55
|
const operation = audio_native_1.audioNative.pollAudioWorker(handle);
|
|
49
|
-
if (operation === -3)
|
|
56
|
+
if (operation === -3) {
|
|
50
57
|
break;
|
|
58
|
+
}
|
|
51
59
|
if (operation === -2) {
|
|
52
60
|
await callbacks.onSeek(new time_1.Time(time[0]));
|
|
53
61
|
continue;
|
|
@@ -65,7 +73,8 @@ async function run() {
|
|
|
65
73
|
if (chunk.samples !== pcm[fields[0]]) {
|
|
66
74
|
throw new TypeError('Fill the provided native sample buffer');
|
|
67
75
|
}
|
|
68
|
-
if (!Number.isInteger(chunk.sampleCount) ||
|
|
76
|
+
if (!Number.isInteger(chunk.sampleCount) ||
|
|
77
|
+
chunk.sampleCount < 0 ||
|
|
69
78
|
chunk.sampleCount > chunk.samples.length) {
|
|
70
79
|
throw new RangeError('Invalid stream sample count');
|
|
71
80
|
}
|
|
@@ -73,8 +82,10 @@ async function run() {
|
|
|
73
82
|
fields[3] = +more;
|
|
74
83
|
if (!more) {
|
|
75
84
|
const loop = callbacks.onLoop ? await callbacks.onLoop() : 0n;
|
|
76
|
-
if (loop !== undefined &&
|
|
77
|
-
loop
|
|
85
|
+
if (loop !== undefined &&
|
|
86
|
+
(typeof loop !== 'bigint' ||
|
|
87
|
+
loop < 0n ||
|
|
88
|
+
loop > 0x7fffffffffffffffn)) {
|
|
78
89
|
throw new RangeError('Invalid loop sample offset');
|
|
79
90
|
}
|
|
80
91
|
time[1] = loop ?? -1n;
|
|
@@ -97,12 +108,14 @@ async function run() {
|
|
|
97
108
|
}
|
|
98
109
|
else {
|
|
99
110
|
const channels = fields[3];
|
|
100
|
-
const result = await callbacks.process(fields[5]
|
|
111
|
+
const result = await callbacks.process(fields[5]
|
|
112
|
+
? null
|
|
101
113
|
: input[fields[0]].subarray(fields[4], fields[4] + fields[2]), fields[7], output[fields[1]].subarray(0, fields[6] * channels), fields[6], channels);
|
|
102
114
|
if (result) {
|
|
103
115
|
if (!Number.isInteger(result.inputFrameCount) ||
|
|
104
116
|
!Number.isInteger(result.outputFrameCount) ||
|
|
105
|
-
result.inputFrameCount < 0 ||
|
|
117
|
+
result.inputFrameCount < 0 ||
|
|
118
|
+
result.inputFrameCount > fields[7] ||
|
|
106
119
|
result.outputFrameCount < 0 ||
|
|
107
120
|
result.outputFrameCount > fields[6]) {
|
|
108
121
|
throw new RangeError('Effect frame counts exceed the leased block');
|
|
@@ -119,16 +132,22 @@ async function run() {
|
|
|
119
132
|
}
|
|
120
133
|
finally {
|
|
121
134
|
audio_native_1.audioNative.closeAudioWorker(handle);
|
|
122
|
-
if (setup.kind === 'recorder')
|
|
135
|
+
if (setup.kind === 'recorder') {
|
|
123
136
|
await callbacks.onStop?.();
|
|
124
|
-
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
125
139
|
await callbacks.onClose?.();
|
|
140
|
+
}
|
|
126
141
|
}
|
|
127
142
|
}
|
|
128
|
-
void run()
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
143
|
+
void run()
|
|
144
|
+
.catch((error) => {
|
|
145
|
+
node_worker_threads_1.parentPort.postMessage({
|
|
146
|
+
type: 'error',
|
|
147
|
+
error: error instanceof Error ? error.stack : String(error),
|
|
148
|
+
});
|
|
149
|
+
})
|
|
150
|
+
.finally(() => {
|
|
132
151
|
node_worker_threads_1.parentPort.postMessage({ type: 'closed' });
|
|
133
152
|
node_worker_threads_1.parentPort.close();
|
|
134
153
|
});
|
|
@@ -3,7 +3,9 @@ import type { NativeValueHandle, NativeValueMapping } from './native';
|
|
|
3
3
|
import { mutableValue } from './value-storage';
|
|
4
4
|
export declare const glslStorage: unique symbol;
|
|
5
5
|
export declare const glslNative: unique symbol;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Internal storage only; concrete GLSL types define their own component API.
|
|
8
|
+
*/
|
|
7
9
|
export declare abstract class GlslValue<K extends string, A extends ValueArray> {
|
|
8
10
|
readonly [mutableValue] = true;
|
|
9
11
|
private readonly state;
|
|
@@ -6,7 +6,9 @@ const lazy_value_1 = require("./lazy-value");
|
|
|
6
6
|
const value_storage_1 = require("./value-storage");
|
|
7
7
|
exports.glslStorage = Symbol('Glsl.storage');
|
|
8
8
|
exports.glslNative = Symbol('Glsl.native');
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Internal storage only; concrete GLSL types define their own component API.
|
|
11
|
+
*/
|
|
10
12
|
class GlslValue {
|
|
11
13
|
constructor(values, wrap) {
|
|
12
14
|
this[_a] = true;
|
|
@@ -32,9 +34,9 @@ class BooleanComponents extends GlslValue {
|
|
|
32
34
|
this.scalarType = 'bool';
|
|
33
35
|
for (let i = 0; i < components.length; i++) {
|
|
34
36
|
// C++ conversion treats NaN as nonzero, unlike JavaScript Boolean(NaN).
|
|
35
|
-
this[exports.glslStorage][i] =
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
this[exports.glslStorage][i] = Number(components[i] !== 0 &&
|
|
38
|
+
components[i] !== 0n &&
|
|
39
|
+
components[i] !== false);
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
/**
|
|
@@ -43,27 +45,35 @@ class BooleanComponents extends GlslValue {
|
|
|
43
45
|
* @ja X の真偽値成分。
|
|
44
46
|
* @ko X 불리언 성분.
|
|
45
47
|
*/
|
|
46
|
-
get x() {
|
|
48
|
+
get x() {
|
|
49
|
+
return this[exports.glslStorage][0] !== 0;
|
|
50
|
+
}
|
|
47
51
|
/**
|
|
48
52
|
* Set the X boolean component.
|
|
49
53
|
* @zh 设置 X 布尔分量。
|
|
50
54
|
* @ja X の真偽値成分を設定します。
|
|
51
55
|
* @ko X 불리언 성분을 설정합니다.
|
|
52
56
|
*/
|
|
53
|
-
set x(value) {
|
|
57
|
+
set x(value) {
|
|
58
|
+
this[exports.glslStorage][0] = value ? 1 : 0;
|
|
59
|
+
}
|
|
54
60
|
/**
|
|
55
61
|
* Y boolean component.
|
|
56
62
|
* @zh Y 布尔分量。
|
|
57
63
|
* @ja Y の真偽値成分。
|
|
58
64
|
* @ko Y 불리언 성분.
|
|
59
65
|
*/
|
|
60
|
-
get y() {
|
|
66
|
+
get y() {
|
|
67
|
+
return this[exports.glslStorage][1] !== 0;
|
|
68
|
+
}
|
|
61
69
|
/**
|
|
62
70
|
* Set the Y boolean component.
|
|
63
71
|
* @zh 设置 Y 布尔分量。
|
|
64
72
|
* @ja Y の真偽値成分を設定します。
|
|
65
73
|
* @ko Y 불리언 성분을 설정합니다.
|
|
66
74
|
*/
|
|
67
|
-
set y(value) {
|
|
75
|
+
set y(value) {
|
|
76
|
+
this[exports.glslStorage][1] = value ? 1 : 0;
|
|
77
|
+
}
|
|
68
78
|
}
|
|
69
79
|
exports.BooleanComponents = BooleanComponents;
|
|
@@ -36,10 +36,12 @@ exports.registerTarget = registerTarget;
|
|
|
36
36
|
function flushGraphics() {
|
|
37
37
|
for (const reference of targets) {
|
|
38
38
|
const target = reference.deref();
|
|
39
|
-
if (target)
|
|
39
|
+
if (target) {
|
|
40
40
|
target[exports.graphicsFlush]();
|
|
41
|
-
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
42
43
|
targets.delete(reference);
|
|
44
|
+
}
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
exports.flushGraphics = flushGraphics;
|
|
@@ -47,18 +49,21 @@ exports.flushGraphics = flushGraphics;
|
|
|
47
49
|
function flushShapeReaders(shape) {
|
|
48
50
|
for (const reference of targets) {
|
|
49
51
|
const target = reference.deref();
|
|
50
|
-
if (!target)
|
|
52
|
+
if (!target) {
|
|
51
53
|
targets.delete(reference);
|
|
52
|
-
|
|
54
|
+
}
|
|
55
|
+
else if (target[exports.graphicsShapeReads]?.().has(shape)) {
|
|
53
56
|
target[exports.graphicsFlush]();
|
|
57
|
+
}
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
exports.flushShapeReaders = flushShapeReaders;
|
|
57
61
|
/** Reject feedback or a new cycle before reserving any command/vertex space. */
|
|
58
62
|
function validateTextureRead(reader, texture) {
|
|
59
63
|
const owner = texture?.[exports.textureOwner];
|
|
60
|
-
if (!owner)
|
|
64
|
+
if (!owner) {
|
|
61
65
|
return;
|
|
66
|
+
}
|
|
62
67
|
if (owner === reader) {
|
|
63
68
|
throw new error_1.SFMLError('Cannot sample a render target from its own texture');
|
|
64
69
|
}
|
|
@@ -69,13 +74,15 @@ function validateTextureRead(reader, texture) {
|
|
|
69
74
|
if (target === reader) {
|
|
70
75
|
throw new error_1.SFMLError('Cyclic texture dependency: display an intermediate target');
|
|
71
76
|
}
|
|
72
|
-
if (visited.has(target))
|
|
77
|
+
if (visited.has(target)) {
|
|
73
78
|
continue;
|
|
79
|
+
}
|
|
74
80
|
visited.add(target);
|
|
75
81
|
for (const source of target[exports.graphicsReads]()) {
|
|
76
82
|
const dependency = source[exports.textureOwner];
|
|
77
|
-
if (dependency)
|
|
83
|
+
if (dependency) {
|
|
78
84
|
pending.push(dependency);
|
|
85
|
+
}
|
|
79
86
|
}
|
|
80
87
|
}
|
|
81
88
|
}
|
|
@@ -91,11 +98,13 @@ function flushTextureReaders(writer) {
|
|
|
91
98
|
}
|
|
92
99
|
for (const texture of target[exports.graphicsReads]()) {
|
|
93
100
|
const owner = texture[exports.textureOwner];
|
|
94
|
-
if (!owner)
|
|
101
|
+
if (!owner) {
|
|
95
102
|
continue;
|
|
103
|
+
}
|
|
96
104
|
let consumers = readers.get(owner);
|
|
97
|
-
if (!consumers)
|
|
98
|
-
readers.set(owner, consumers = new Set());
|
|
105
|
+
if (!consumers) {
|
|
106
|
+
readers.set(owner, (consumers = new Set()));
|
|
107
|
+
}
|
|
99
108
|
consumers.add(target);
|
|
100
109
|
}
|
|
101
110
|
}
|
|
@@ -103,21 +112,26 @@ function flushTextureReaders(writer) {
|
|
|
103
112
|
const visiting = new Set();
|
|
104
113
|
const done = new Set();
|
|
105
114
|
const visit = (source) => {
|
|
106
|
-
if (visiting.has(source))
|
|
115
|
+
if (visiting.has(source)) {
|
|
107
116
|
throw new error_1.SFMLError('Cyclic texture dependency');
|
|
108
|
-
|
|
117
|
+
}
|
|
118
|
+
if (done.has(source)) {
|
|
109
119
|
return;
|
|
120
|
+
}
|
|
110
121
|
visiting.add(source);
|
|
111
|
-
for (const target of readers.get(source) ?? [])
|
|
122
|
+
for (const target of readers.get(source) ?? []) {
|
|
112
123
|
visit(target);
|
|
124
|
+
}
|
|
113
125
|
visiting.delete(source);
|
|
114
126
|
done.add(source);
|
|
115
|
-
if (source !== writer)
|
|
127
|
+
if (source !== writer) {
|
|
116
128
|
ordered.push(source);
|
|
129
|
+
}
|
|
117
130
|
};
|
|
118
131
|
visit(writer);
|
|
119
132
|
// Collect the complete order before performing any native submissions.
|
|
120
|
-
for (const target of ordered)
|
|
133
|
+
for (const target of ordered) {
|
|
121
134
|
target[exports.graphicsFlush]();
|
|
135
|
+
}
|
|
122
136
|
}
|
|
123
137
|
exports.flushTextureReaders = flushTextureReaders;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { InputStream } from '../system/input-stream';
|
|
2
2
|
import type { NativeStreamDispatch } from './native';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Keep the stream alive until native decoding and every pending read finish.
|
|
5
|
+
*/
|
|
4
6
|
export declare function streamDispatch(stream: InputStream, onError: (error: unknown) => void): NativeStreamDispatch;
|