sfml.js 1.0.0 → 1.1.0
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 +40 -48
- 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
|
@@ -68,19 +68,25 @@ export class EffectProcessor {
|
|
|
68
68
|
* @ja ブロック処理とキューのアンダーラン・オーバーランの統計を返します。
|
|
69
69
|
* @ko 블록 처리 및 큐 언더런과 오버런 통계를 반환합니다.
|
|
70
70
|
*/
|
|
71
|
-
getWorkerStats(): AudioWorkerStats {
|
|
71
|
+
getWorkerStats(): AudioWorkerStats {
|
|
72
|
+
return this.session.getStats();
|
|
73
|
+
}
|
|
72
74
|
/**
|
|
73
75
|
* Return the Worker error, or undefined if there is none.
|
|
74
76
|
* @zh 返回 Worker 错误;没有错误时为 undefined。
|
|
75
77
|
* @ja Worker のエラーを返します。エラーがなければ undefined。
|
|
76
78
|
* @ko Worker 오류를 반환합니다. 오류가 없으면 undefined입니다.
|
|
77
79
|
*/
|
|
78
|
-
getWorkerError(): Error | undefined {
|
|
80
|
+
getWorkerError(): Error | undefined {
|
|
81
|
+
return this.session.error;
|
|
82
|
+
}
|
|
79
83
|
/**
|
|
80
84
|
* Asynchronously close the effect Worker session.
|
|
81
85
|
* @zh 异步关闭效果 Worker 会话。
|
|
82
86
|
* @ja エフェクト Worker セッションを非同期で閉じます。
|
|
83
87
|
* @ko 효과 Worker 세션을 비동기로 닫습니다.
|
|
84
88
|
*/
|
|
85
|
-
close(): Promise<void> {
|
|
89
|
+
close(): Promise<void> {
|
|
90
|
+
return this.session.close();
|
|
91
|
+
}
|
|
86
92
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
audioNative,
|
|
2
|
+
audioNative,
|
|
3
|
+
audioHandle,
|
|
4
|
+
audioAsync,
|
|
5
|
+
AudioQueue,
|
|
6
|
+
type AudioHandle,
|
|
3
7
|
type AudioFileMapping,
|
|
4
8
|
} from '../internal/audio-native';
|
|
5
9
|
import { Time } from '../system/time';
|
|
@@ -28,7 +32,9 @@ export class InputSoundFile {
|
|
|
28
32
|
private u32: Uint32Array;
|
|
29
33
|
private channelMap: Int32Array;
|
|
30
34
|
private stream?: AudioInputStream;
|
|
31
|
-
private custom?: NonNullable<
|
|
35
|
+
private custom?: NonNullable<
|
|
36
|
+
Awaited<ReturnType<typeof findAudioReaderInput>>
|
|
37
|
+
>;
|
|
32
38
|
private customMetadata?: AudioHandle<'fileMetadata'>;
|
|
33
39
|
|
|
34
40
|
/**
|
|
@@ -52,14 +58,18 @@ export class InputSoundFile {
|
|
|
52
58
|
* @ja 音声ファイルを非同期で開いて形式情報を読み取り、成功したかどうかを返します。
|
|
53
59
|
* @ko 오디오 파일을 비동기로 열고 형식 정보를 읽어 성공 여부를 반환합니다.
|
|
54
60
|
*/
|
|
55
|
-
openFromFile(filename: string): Promise<boolean> {
|
|
61
|
+
openFromFile(filename: string): Promise<boolean> {
|
|
62
|
+
return this.open(filename);
|
|
63
|
+
}
|
|
56
64
|
/**
|
|
57
65
|
* Asynchronously open encoded audio bytes, returning whether it succeeded.
|
|
58
66
|
* @zh 异步打开编码音频字节,返回是否成功。
|
|
59
67
|
* @ja エンコード済み音声バイトを非同期で開き、成功したかどうかを返します。
|
|
60
68
|
* @ko 인코딩된 오디오 바이트를 비동기로 열고 성공 여부를 반환합니다.
|
|
61
69
|
*/
|
|
62
|
-
openFromMemory(data: Uint8Array): Promise<boolean> {
|
|
70
|
+
openFromMemory(data: Uint8Array): Promise<boolean> {
|
|
71
|
+
return this.open(data);
|
|
72
|
+
}
|
|
63
73
|
/**
|
|
64
74
|
* Asynchronously open a seekable stream, retaining the data source reference
|
|
65
75
|
* during reading.
|
|
@@ -76,51 +86,67 @@ export class InputSoundFile {
|
|
|
76
86
|
* @ja 全チャンネルのサンプル総数を返します。
|
|
77
87
|
* @ko 모든 채널의 샘플 총수를 반환합니다.
|
|
78
88
|
*/
|
|
79
|
-
getSampleCount(): bigint {
|
|
89
|
+
getSampleCount(): bigint {
|
|
90
|
+
return this.u64[0];
|
|
91
|
+
}
|
|
80
92
|
/**
|
|
81
93
|
* Return the current sample offset, including all interleaved channels.
|
|
82
94
|
* @zh 返回当前样本偏移,包含所有交错声道。
|
|
83
95
|
* @ja 全インターリーブチャンネルを含む現在のサンプルオフセットを返します。
|
|
84
96
|
* @ko 모든 인터리브 채널을 포함하는 현재 샘플 오프셋을 반환합니다.
|
|
85
97
|
*/
|
|
86
|
-
getSampleOffset(): bigint {
|
|
98
|
+
getSampleOffset(): bigint {
|
|
99
|
+
return this.u64[1];
|
|
100
|
+
}
|
|
87
101
|
/**
|
|
88
102
|
* Return the total audio duration.
|
|
89
103
|
* @zh 返回音频总时长。
|
|
90
104
|
* @ja 音声全体の長さを返します。
|
|
91
105
|
* @ko 오디오의 전체 길이를 반환합니다.
|
|
92
106
|
*/
|
|
93
|
-
getDuration(): Time {
|
|
107
|
+
getDuration(): Time {
|
|
108
|
+
return new Time(this.i64[2]);
|
|
109
|
+
}
|
|
94
110
|
/**
|
|
95
111
|
* Return the time corresponding to the current decoding position.
|
|
96
112
|
* @zh 返回当前解码位置对应的时间。
|
|
97
113
|
* @ja 現在のデコード位置に対応する時刻を返します。
|
|
98
114
|
* @ko 현재 디코딩 위치에 해당하는 시간을 반환합니다.
|
|
99
115
|
*/
|
|
100
|
-
getTimeOffset(): Time {
|
|
116
|
+
getTimeOffset(): Time {
|
|
117
|
+
return new Time(this.i64[3]);
|
|
118
|
+
}
|
|
101
119
|
/**
|
|
102
120
|
* Return the sample rate per channel, in Hz.
|
|
103
121
|
* @zh 返回每声道采样率,单位为 Hz。
|
|
104
122
|
* @ja チャンネルごとのサンプルレートを Hz で返します。
|
|
105
123
|
* @ko 채널별 샘플 레이트를 Hz 단위로 반환합니다.
|
|
106
124
|
*/
|
|
107
|
-
getSampleRate(): number {
|
|
125
|
+
getSampleRate(): number {
|
|
126
|
+
return this.u32[10];
|
|
127
|
+
}
|
|
108
128
|
/**
|
|
109
129
|
* Return the number of channels.
|
|
110
130
|
* @zh 返回声道数。
|
|
111
131
|
* @ja チャンネル数を返します。
|
|
112
132
|
* @ko 채널 수를 반환합니다.
|
|
113
133
|
*/
|
|
114
|
-
getChannelCount(): number {
|
|
134
|
+
getChannelCount(): number {
|
|
135
|
+
return this.u32[11];
|
|
136
|
+
}
|
|
115
137
|
/**
|
|
116
138
|
* Return the position mapping of interleaved channels.
|
|
117
139
|
* @zh 返回交错声道的位置映射。
|
|
118
140
|
* @ja インターリーブチャンネルの位置マッピングを返します。
|
|
119
141
|
* @ko 인터리브 채널의 위치 매핑을 반환합니다.
|
|
120
142
|
*/
|
|
121
|
-
getChannelMap(): ChannelMap {
|
|
143
|
+
getChannelMap(): ChannelMap {
|
|
144
|
+
return this.channelMap;
|
|
145
|
+
}
|
|
122
146
|
/** @internal */
|
|
123
|
-
[cancelAudioInput](): void {
|
|
147
|
+
[cancelAudioInput](): void {
|
|
148
|
+
this.stream?.close();
|
|
149
|
+
}
|
|
124
150
|
/**
|
|
125
151
|
* Asynchronously decode into data, returning the actual number of samples
|
|
126
152
|
* written; return 0n at the end. Do not modify the buffer before completion.
|
|
@@ -134,16 +160,24 @@ export class InputSoundFile {
|
|
|
134
160
|
samples(data);
|
|
135
161
|
return this.queue.run(async () => {
|
|
136
162
|
if (this.custom) {
|
|
137
|
-
const count = data.length
|
|
138
|
-
|
|
139
|
-
|
|
163
|
+
const count = data.length
|
|
164
|
+
? await this.custom.reader.read(data)
|
|
165
|
+
: 0n;
|
|
166
|
+
if (
|
|
167
|
+
typeof count !== 'bigint' ||
|
|
168
|
+
count < 0n ||
|
|
169
|
+
count > BigInt(data.length)
|
|
170
|
+
) {
|
|
140
171
|
throw new RangeError('Reader returned an invalid sample count');
|
|
141
172
|
}
|
|
142
173
|
audioNative.updateAudioFileMetadata(this.customMetadata!, 0, count);
|
|
143
174
|
return count;
|
|
144
175
|
}
|
|
145
|
-
await this.runStream(() =>
|
|
146
|
-
|
|
176
|
+
await this.runStream(() =>
|
|
177
|
+
audioAsync<void>(callback =>
|
|
178
|
+
audioNative.readAudioInput(this[audioHandle], data, callback),
|
|
179
|
+
),
|
|
180
|
+
);
|
|
147
181
|
return this.u64[4];
|
|
148
182
|
});
|
|
149
183
|
}
|
|
@@ -160,17 +194,30 @@ export class InputSoundFile {
|
|
|
160
194
|
const time = offset instanceof Time;
|
|
161
195
|
const value = time ? duration(offset) : offset;
|
|
162
196
|
if (typeof value !== 'bigint' || (!time && value < 0n)) {
|
|
163
|
-
throw new RangeError(
|
|
197
|
+
throw new RangeError(
|
|
198
|
+
'Expected a non-negative sample offset or a Time',
|
|
199
|
+
);
|
|
164
200
|
}
|
|
165
201
|
return this.queue.run(async () => {
|
|
166
202
|
if (this.custom) {
|
|
167
|
-
audioNative.updateAudioFileMetadata(
|
|
168
|
-
|
|
203
|
+
audioNative.updateAudioFileMetadata(
|
|
204
|
+
this.customMetadata!,
|
|
205
|
+
time ? 2 : 1,
|
|
206
|
+
value,
|
|
207
|
+
);
|
|
169
208
|
await this.custom.reader.seek(this.u64[4]);
|
|
170
209
|
audioNative.updateAudioFileMetadata(this.customMetadata!, 3);
|
|
171
210
|
} else {
|
|
172
|
-
await this.runStream(() =>
|
|
173
|
-
|
|
211
|
+
await this.runStream(() =>
|
|
212
|
+
audioAsync<void>(callback =>
|
|
213
|
+
audioNative.seekAudioInput(
|
|
214
|
+
this[audioHandle],
|
|
215
|
+
value,
|
|
216
|
+
time,
|
|
217
|
+
callback,
|
|
218
|
+
),
|
|
219
|
+
),
|
|
220
|
+
);
|
|
174
221
|
}
|
|
175
222
|
});
|
|
176
223
|
}
|
|
@@ -183,8 +230,11 @@ export class InputSoundFile {
|
|
|
183
230
|
*/
|
|
184
231
|
close(): Promise<void> {
|
|
185
232
|
return this.queue.run(async () => {
|
|
186
|
-
this.map(
|
|
187
|
-
|
|
233
|
+
this.map(
|
|
234
|
+
await audioAsync<AudioFileMapping>(callback =>
|
|
235
|
+
audioNative.closeAudioInput(this[audioHandle], callback),
|
|
236
|
+
),
|
|
237
|
+
);
|
|
188
238
|
this.stream?.close();
|
|
189
239
|
this.stream = undefined;
|
|
190
240
|
await this.releaseCustom();
|
|
@@ -203,7 +253,11 @@ export class InputSoundFile {
|
|
|
203
253
|
const custom = this.custom;
|
|
204
254
|
this.custom = undefined;
|
|
205
255
|
this.customMetadata = undefined;
|
|
206
|
-
try {
|
|
256
|
+
try {
|
|
257
|
+
await custom?.reader.close();
|
|
258
|
+
} finally {
|
|
259
|
+
await custom?.owned?.close();
|
|
260
|
+
}
|
|
207
261
|
}
|
|
208
262
|
private open(input: string | Uint8Array | InputStream): Promise<boolean> {
|
|
209
263
|
return this.queue.run(async () => {
|
|
@@ -212,13 +266,20 @@ export class InputSoundFile {
|
|
|
212
266
|
let opened = false;
|
|
213
267
|
try {
|
|
214
268
|
const info = await custom.reader.open(custom.stream);
|
|
215
|
-
if (info === undefined)
|
|
269
|
+
if (info === undefined) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
216
272
|
if (!(info instanceof SoundFileReaderInfo)) {
|
|
217
|
-
throw new TypeError(
|
|
273
|
+
throw new TypeError(
|
|
274
|
+
'Reader.open must return SoundFileReader.Info',
|
|
275
|
+
);
|
|
218
276
|
}
|
|
219
|
-
const mapping = audioNative.createAudioFileMetadata(
|
|
277
|
+
const mapping = audioNative.createAudioFileMetadata(
|
|
278
|
+
info[audioHandle],
|
|
279
|
+
);
|
|
220
280
|
await audioAsync<AudioFileMapping>(callback =>
|
|
221
|
-
audioNative.closeAudioInput(this[audioHandle], callback)
|
|
281
|
+
audioNative.closeAudioInput(this[audioHandle], callback),
|
|
282
|
+
);
|
|
222
283
|
await this.releaseCustom();
|
|
223
284
|
this.stream?.close();
|
|
224
285
|
this.stream = undefined;
|
|
@@ -229,19 +290,28 @@ export class InputSoundFile {
|
|
|
229
290
|
return true;
|
|
230
291
|
} finally {
|
|
231
292
|
if (!opened) {
|
|
232
|
-
try {
|
|
293
|
+
try {
|
|
294
|
+
await custom.reader.close();
|
|
295
|
+
} finally {
|
|
233
296
|
await custom.owned?.close();
|
|
234
297
|
}
|
|
235
298
|
}
|
|
236
299
|
}
|
|
237
300
|
}
|
|
238
|
-
const stream =
|
|
239
|
-
|
|
301
|
+
const stream =
|
|
302
|
+
typeof input === 'string' || input instanceof Uint8Array
|
|
303
|
+
? undefined
|
|
304
|
+
: new AudioInputStream(input);
|
|
240
305
|
let opened = false;
|
|
241
306
|
try {
|
|
242
|
-
const load = () =>
|
|
243
|
-
|
|
244
|
-
|
|
307
|
+
const load = () =>
|
|
308
|
+
audioAsync<AudioFileMapping | undefined>(callback =>
|
|
309
|
+
audioNative.openAudioInput(
|
|
310
|
+
this[audioHandle],
|
|
311
|
+
stream ? stream.handle : (input as string | Uint8Array),
|
|
312
|
+
callback,
|
|
313
|
+
),
|
|
314
|
+
);
|
|
245
315
|
const mapping = await (stream ? stream.run(load) : load());
|
|
246
316
|
if (mapping) {
|
|
247
317
|
await this.releaseCustom();
|
|
@@ -252,7 +322,9 @@ export class InputSoundFile {
|
|
|
252
322
|
}
|
|
253
323
|
return opened;
|
|
254
324
|
} finally {
|
|
255
|
-
if (!opened)
|
|
325
|
+
if (!opened) {
|
|
326
|
+
stream?.close();
|
|
327
|
+
}
|
|
256
328
|
}
|
|
257
329
|
});
|
|
258
330
|
}
|
package/src/audio/listener.ts
CHANGED
|
@@ -5,13 +5,20 @@ import type { ReadonlyValue as R } from '../internal/value-storage';
|
|
|
5
5
|
import { Cone, type ConeInput, float, vector, angle } from './value';
|
|
6
6
|
|
|
7
7
|
export { Cone } from './value';
|
|
8
|
-
let state:
|
|
9
|
-
|
|
8
|
+
let state:
|
|
9
|
+
| {
|
|
10
|
+
handle: ReturnType<typeof audioNative.createAudioListener>['handle'];
|
|
11
|
+
values: Float32Array;
|
|
12
|
+
}
|
|
13
|
+
| undefined;
|
|
10
14
|
|
|
11
15
|
function listener() {
|
|
12
16
|
if (!state) {
|
|
13
17
|
const mapping = audioNative.createAudioListener();
|
|
14
|
-
state = {
|
|
18
|
+
state = {
|
|
19
|
+
handle: mapping.handle,
|
|
20
|
+
values: new Float32Array(mapping.buffer),
|
|
21
|
+
};
|
|
15
22
|
}
|
|
16
23
|
return state;
|
|
17
24
|
}
|
|
@@ -57,49 +64,63 @@ export function getGlobalVolume(): number {
|
|
|
57
64
|
* @ja リスナーの 3D 位置のコピーを返します。
|
|
58
65
|
* @ko 리스너의 3차원 위치 복사본을 반환합니다.
|
|
59
66
|
*/
|
|
60
|
-
export function getPosition(): Vector3f {
|
|
67
|
+
export function getPosition(): Vector3f {
|
|
68
|
+
return getVector(1);
|
|
69
|
+
}
|
|
61
70
|
/**
|
|
62
71
|
* Set the listener's position in world coordinates.
|
|
63
72
|
* @zh 设置监听者的世界坐标位置。
|
|
64
73
|
* @ja リスナーのワールド座標での位置を設定します。
|
|
65
74
|
* @ko 리스너의 월드 좌표 위치를 설정합니다.
|
|
66
75
|
*/
|
|
67
|
-
export function setPosition(value: R<Vector3f>): void {
|
|
76
|
+
export function setPosition(value: R<Vector3f>): void {
|
|
77
|
+
setVector(1, value);
|
|
78
|
+
}
|
|
68
79
|
/**
|
|
69
80
|
* Return a copy of the listener's facing direction.
|
|
70
81
|
* @zh 返回监听者的朝向副本。
|
|
71
82
|
* @ja リスナーの向きのコピーを返します。
|
|
72
83
|
* @ko 리스너가 향하는 방향의 복사본을 반환합니다.
|
|
73
84
|
*/
|
|
74
|
-
export function getDirection(): Vector3f {
|
|
85
|
+
export function getDirection(): Vector3f {
|
|
86
|
+
return getVector(4);
|
|
87
|
+
}
|
|
75
88
|
/**
|
|
76
89
|
* Set the listener's forward direction.
|
|
77
90
|
* @zh 设置监听者的正前方方向。
|
|
78
91
|
* @ja リスナーの前方方向を設定します。
|
|
79
92
|
* @ko 리스너의 정면 방향을 설정합니다.
|
|
80
93
|
*/
|
|
81
|
-
export function setDirection(value: R<Vector3f>): void {
|
|
94
|
+
export function setDirection(value: R<Vector3f>): void {
|
|
95
|
+
setVector(4, value);
|
|
96
|
+
}
|
|
82
97
|
/**
|
|
83
98
|
* Return a copy of the listener's velocity.
|
|
84
99
|
* @zh 返回监听者的速度副本。
|
|
85
100
|
* @ja リスナーの速度のコピーを返します。
|
|
86
101
|
* @ko 리스너 속도의 복사본을 반환합니다.
|
|
87
102
|
*/
|
|
88
|
-
export function getVelocity(): Vector3f {
|
|
103
|
+
export function getVelocity(): Vector3f {
|
|
104
|
+
return getVector(7);
|
|
105
|
+
}
|
|
89
106
|
/**
|
|
90
107
|
* Set the listener's velocity for the Doppler effect, in position units/second.
|
|
91
108
|
* @zh 设置监听者的速度,用于多普勒效应,单位为位置单位/秒。
|
|
92
109
|
* @ja ドップラー効果用のリスナー速度を設定します。単位は位置単位/秒です。
|
|
93
110
|
* @ko 도플러 효과에 사용할 리스너 속도를 설정합니다. 단위는 위치 단위/초입니다.
|
|
94
111
|
*/
|
|
95
|
-
export function setVelocity(value: R<Vector3f>): void {
|
|
112
|
+
export function setVelocity(value: R<Vector3f>): void {
|
|
113
|
+
setVector(7, value);
|
|
114
|
+
}
|
|
96
115
|
/**
|
|
97
116
|
* Return a copy of the listener's up direction.
|
|
98
117
|
* @zh 返回监听者上方方向的副本。
|
|
99
118
|
* @ja リスナーの上方向のコピーを返します。
|
|
100
119
|
* @ko 리스너 위쪽 방향의 복사본을 반환합니다.
|
|
101
120
|
*/
|
|
102
|
-
export function getUpVector(): Vector3f {
|
|
121
|
+
export function getUpVector(): Vector3f {
|
|
122
|
+
return getVector(10);
|
|
123
|
+
}
|
|
103
124
|
/**
|
|
104
125
|
* Set the listener's up direction, which defines orientation together with the
|
|
105
126
|
* forward direction.
|
|
@@ -107,7 +128,9 @@ export function getUpVector(): Vector3f { return getVector(10); }
|
|
|
107
128
|
* @ja リスナーの上方向を設定します。前方方向とともに空間内の向きを決めます。
|
|
108
129
|
* @ko 리스너의 위쪽 방향을 설정합니다. 정면 방향과 함께 공간상의 방향을 결정합니다.
|
|
109
130
|
*/
|
|
110
|
-
export function setUpVector(value: R<Vector3f>): void {
|
|
131
|
+
export function setUpVector(value: R<Vector3f>): void {
|
|
132
|
+
setVector(10, value);
|
|
133
|
+
}
|
|
111
134
|
/**
|
|
112
135
|
* Copy directional cone parameters and update the native listener.
|
|
113
136
|
* @zh 复制方向锥参数并更新原生监听者。
|
|
@@ -131,6 +154,9 @@ export function setCone(value: Readonly<ConeInput>): void {
|
|
|
131
154
|
export function getCone(): Cone {
|
|
132
155
|
const { handle, values } = listener();
|
|
133
156
|
audioNative.audioListenerField(handle, 13, false);
|
|
134
|
-
return new Cone({
|
|
135
|
-
|
|
157
|
+
return new Cone({
|
|
158
|
+
innerAngle: radians(values[13]),
|
|
159
|
+
outerAngle: radians(values[14]),
|
|
160
|
+
outerGain: values[15],
|
|
161
|
+
});
|
|
136
162
|
}
|