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
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
audioNative,
|
|
2
|
+
audioNative,
|
|
3
|
+
audioHandle,
|
|
4
|
+
type AudioHandle,
|
|
5
|
+
type AudioReaderInfoMapping,
|
|
3
6
|
} from '../internal/audio-native';
|
|
4
7
|
import type { InputStream } from '../system/input-stream';
|
|
5
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
channels,
|
|
10
|
+
unsigned,
|
|
11
|
+
type SoundChannel,
|
|
12
|
+
type ChannelMap,
|
|
13
|
+
} from './value';
|
|
6
14
|
|
|
7
15
|
/**
|
|
8
16
|
* Format information returned by a custom audio decoder.
|
|
@@ -61,8 +69,10 @@ export class SoundFileReaderInfo {
|
|
|
61
69
|
* @ko 빈 형식 정보를 생성하거나 value를 복사합니다.
|
|
62
70
|
* mapping은 네이티브 디코더의 내부 매핑용입니다.
|
|
63
71
|
*/
|
|
64
|
-
constructor(
|
|
65
|
-
|
|
72
|
+
constructor(
|
|
73
|
+
value?: SoundFileReaderInfoInput,
|
|
74
|
+
mapping: AudioReaderInfoMapping = audioNative.createAudioReaderInfo(),
|
|
75
|
+
) {
|
|
66
76
|
this[audioHandle] = mapping.handle;
|
|
67
77
|
const region = (name: string) => {
|
|
68
78
|
const [ , index, offset ] = mapping.info.fields[name];
|
|
@@ -88,7 +98,9 @@ export class SoundFileReaderInfo {
|
|
|
88
98
|
* @ja 全チャンネルのサンプル総数。
|
|
89
99
|
* @ko 모든 채널의 샘플 총수입니다.
|
|
90
100
|
*/
|
|
91
|
-
get sampleCount(): bigint {
|
|
101
|
+
get sampleCount(): bigint {
|
|
102
|
+
return this.count[0];
|
|
103
|
+
}
|
|
92
104
|
/**
|
|
93
105
|
* Set the total sample count as an unsigned 64-bit integer.
|
|
94
106
|
* @zh 设置无符号 64 位样本总数。
|
|
@@ -96,7 +108,11 @@ export class SoundFileReaderInfo {
|
|
|
96
108
|
* @ko 샘플 총수를 부호 없는 64비트 정수로 설정합니다.
|
|
97
109
|
*/
|
|
98
110
|
set sampleCount(value: bigint) {
|
|
99
|
-
if (
|
|
111
|
+
if (
|
|
112
|
+
typeof value !== 'bigint' ||
|
|
113
|
+
value < 0n ||
|
|
114
|
+
value > 0xffffffffffffffffn
|
|
115
|
+
) {
|
|
100
116
|
throw new RangeError('Expected uint64 sample count');
|
|
101
117
|
}
|
|
102
118
|
this.count[0] = value;
|
|
@@ -107,35 +123,45 @@ export class SoundFileReaderInfo {
|
|
|
107
123
|
* @ja チャンネル数。
|
|
108
124
|
* @ko 채널 수입니다.
|
|
109
125
|
*/
|
|
110
|
-
get channelCount(): number {
|
|
126
|
+
get channelCount(): number {
|
|
127
|
+
return this.channels[0];
|
|
128
|
+
}
|
|
111
129
|
/**
|
|
112
130
|
* Set the number of channels.
|
|
113
131
|
* @zh 设置声道数量。
|
|
114
132
|
* @ja チャンネル数を設定します。
|
|
115
133
|
* @ko 채널 수를 설정합니다.
|
|
116
134
|
*/
|
|
117
|
-
set channelCount(value: number) {
|
|
135
|
+
set channelCount(value: number) {
|
|
136
|
+
this.channels[0] = unsigned(value);
|
|
137
|
+
}
|
|
118
138
|
/**
|
|
119
139
|
* Sample rate per channel, in Hz.
|
|
120
140
|
* @zh 每声道采样率,单位为 Hz。
|
|
121
141
|
* @ja チャンネルごとのサンプルレート。単位は Hz。
|
|
122
142
|
* @ko 채널별 샘플 레이트이며 단위는 Hz입니다.
|
|
123
143
|
*/
|
|
124
|
-
get sampleRate(): number {
|
|
144
|
+
get sampleRate(): number {
|
|
145
|
+
return this.rate[0];
|
|
146
|
+
}
|
|
125
147
|
/**
|
|
126
148
|
* Set the sample rate in Hz.
|
|
127
149
|
* @zh 设置采样率,单位为 Hz。
|
|
128
150
|
* @ja サンプルレートを Hz で設定します。
|
|
129
151
|
* @ko 샘플 레이트를 Hz 단위로 설정합니다.
|
|
130
152
|
*/
|
|
131
|
-
set sampleRate(value: number) {
|
|
153
|
+
set sampleRate(value: number) {
|
|
154
|
+
this.rate[0] = unsigned(value);
|
|
155
|
+
}
|
|
132
156
|
/**
|
|
133
157
|
* Read-only view of interleaved channel positions.
|
|
134
158
|
* @zh 交错声道位置的只读视图。
|
|
135
159
|
* @ja インターリーブチャンネル位置の読み取り専用ビュー。
|
|
136
160
|
* @ko 인터리브 채널 위치의 읽기 전용 뷰입니다.
|
|
137
161
|
*/
|
|
138
|
-
get channelMap(): ChannelMap {
|
|
162
|
+
get channelMap(): ChannelMap {
|
|
163
|
+
return this.map;
|
|
164
|
+
}
|
|
139
165
|
/**
|
|
140
166
|
* Copy the channel position mapping.
|
|
141
167
|
* @zh 复制声道位置映射。
|
|
@@ -143,8 +169,12 @@ export class SoundFileReaderInfo {
|
|
|
143
169
|
* @ko 채널 위치 매핑을 복사합니다.
|
|
144
170
|
*/
|
|
145
171
|
set channelMap(value: Iterable<SoundChannel>) {
|
|
146
|
-
this.map = new Int32Array(
|
|
147
|
-
|
|
172
|
+
this.map = new Int32Array(
|
|
173
|
+
audioNative.setAudioReaderChannels(
|
|
174
|
+
this[audioHandle],
|
|
175
|
+
channels(value),
|
|
176
|
+
),
|
|
177
|
+
);
|
|
148
178
|
}
|
|
149
179
|
}
|
|
150
180
|
|
|
@@ -172,8 +202,12 @@ export abstract class SoundFileReader {
|
|
|
172
202
|
* @ja 入力ストリームを開いて形式情報を返します。開けない場合は undefined。
|
|
173
203
|
* @ko 입력 스트림을 열고 형식 정보를 반환합니다. 열 수 없으면 undefined입니다.
|
|
174
204
|
*/
|
|
175
|
-
abstract open(
|
|
176
|
-
|
|
205
|
+
abstract open(
|
|
206
|
+
stream: InputStream,
|
|
207
|
+
):
|
|
208
|
+
| SoundFileReaderInfo
|
|
209
|
+
| undefined
|
|
210
|
+
| Promise<SoundFileReaderInfo | undefined>;
|
|
177
211
|
/**
|
|
178
212
|
* Seek to the specified zero-based interleaved sample offset.
|
|
179
213
|
* @zh 移动到指定交错样本偏移,偏移从零开始。
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
audioNative,
|
|
2
|
+
audioNative,
|
|
3
|
+
audioHandle,
|
|
4
|
+
audioAsync,
|
|
5
|
+
AudioQueue,
|
|
6
|
+
type AudioHandle,
|
|
3
7
|
} from '../internal/audio-native';
|
|
4
8
|
import { AudioWorkerSession } from '../internal/audio-worker-session';
|
|
5
9
|
import {
|
|
6
|
-
AudioRecorderSession,
|
|
10
|
+
AudioRecorderSession,
|
|
11
|
+
currentRecorderSession,
|
|
12
|
+
type AudioRecorderCallbacks,
|
|
7
13
|
} from '../internal/audio-recorder-session';
|
|
8
14
|
import { unsigned, type ChannelMap } from './value';
|
|
9
15
|
import type { AudioWorkerOptions, AudioWorkerStats } from './worker';
|
|
@@ -95,28 +101,36 @@ export class SoundRecorder {
|
|
|
95
101
|
* @ja システムが音声キャプチャに対応しているかどうかを返します。
|
|
96
102
|
* @ko 시스템의 오디오 캡처 지원 여부를 반환합니다.
|
|
97
103
|
*/
|
|
98
|
-
static isAvailable(): boolean {
|
|
104
|
+
static isAvailable(): boolean {
|
|
105
|
+
return audioNative.audioCaptureDevices(2);
|
|
106
|
+
}
|
|
99
107
|
/**
|
|
100
108
|
* Return the current sample rate in Hz.
|
|
101
109
|
* @zh 返回当前采样率,单位为 Hz。
|
|
102
110
|
* @ja 現在のサンプルレートを Hz で返します。
|
|
103
111
|
* @ko 현재 샘플 레이트를 Hz 단위로 반환합니다.
|
|
104
112
|
*/
|
|
105
|
-
getSampleRate(): number {
|
|
113
|
+
getSampleRate(): number {
|
|
114
|
+
return this.values[0];
|
|
115
|
+
}
|
|
106
116
|
/**
|
|
107
117
|
* Return the number of capture channels.
|
|
108
118
|
* @zh 返回采集声道数。
|
|
109
119
|
* @ja キャプチャのチャンネル数を返します。
|
|
110
120
|
* @ko 캡처 채널 수를 반환합니다.
|
|
111
121
|
*/
|
|
112
|
-
getChannelCount(): number {
|
|
122
|
+
getChannelCount(): number {
|
|
123
|
+
return this.values[1];
|
|
124
|
+
}
|
|
113
125
|
/**
|
|
114
126
|
* Return the speaker position mapping of the capture channels.
|
|
115
127
|
* @zh 返回采集声道的扬声器位置映射。
|
|
116
128
|
* @ja キャプチャチャンネルのスピーカー位置マッピングを返します。
|
|
117
129
|
* @ko 캡처 채널의 스피커 위치 매핑을 반환합니다.
|
|
118
130
|
*/
|
|
119
|
-
getChannelMap(): ChannelMap {
|
|
131
|
+
getChannelMap(): ChannelMap {
|
|
132
|
+
return this.channelMap;
|
|
133
|
+
}
|
|
120
134
|
/**
|
|
121
135
|
* Return the current recording device name.
|
|
122
136
|
* @zh 返回当前录音设备名称。
|
|
@@ -137,11 +151,19 @@ export class SoundRecorder {
|
|
|
137
151
|
*/
|
|
138
152
|
setDevice(name: string): Promise<boolean> {
|
|
139
153
|
if (currentRecorderSession(this[audioHandle])) {
|
|
140
|
-
return Promise.reject(
|
|
154
|
+
return Promise.reject(
|
|
155
|
+
new Error('Cannot change device inside a Recorder callback'),
|
|
156
|
+
);
|
|
141
157
|
}
|
|
142
158
|
return this.run(() => {
|
|
143
|
-
const change = () =>
|
|
144
|
-
|
|
159
|
+
const change = () =>
|
|
160
|
+
audioAsync<boolean>(callback =>
|
|
161
|
+
audioNative.audioRecorderDevice(
|
|
162
|
+
this[audioHandle],
|
|
163
|
+
name,
|
|
164
|
+
callback,
|
|
165
|
+
),
|
|
166
|
+
);
|
|
145
167
|
return this.directSession?.runDeviceOperation(change) ?? change();
|
|
146
168
|
});
|
|
147
169
|
}
|
|
@@ -158,8 +180,9 @@ export class SoundRecorder {
|
|
|
158
180
|
if (this.pendingOperations) {
|
|
159
181
|
throw new Error('Wait for the pending recorder operation');
|
|
160
182
|
}
|
|
161
|
-
this.channelMap = new Int32Array(
|
|
162
|
-
this[audioHandle], unsigned(count))
|
|
183
|
+
this.channelMap = new Int32Array(
|
|
184
|
+
audioNative.audioRecorderChannels(this[audioHandle], unsigned(count)),
|
|
185
|
+
);
|
|
163
186
|
}
|
|
164
187
|
/**
|
|
165
188
|
* Asynchronously initialize capture, defaulting to 44100 Hz; return false if
|
|
@@ -179,11 +202,15 @@ export class SoundRecorder {
|
|
|
179
202
|
start(sampleRate = 44100): Promise<boolean> {
|
|
180
203
|
unsigned(sampleRate);
|
|
181
204
|
if (currentRecorderSession(this[audioHandle])) {
|
|
182
|
-
return Promise.reject(
|
|
205
|
+
return Promise.reject(
|
|
206
|
+
new Error('Cannot start Recorder inside its callback'),
|
|
207
|
+
);
|
|
183
208
|
}
|
|
184
209
|
const version = this.stopVersion;
|
|
185
210
|
return this.run(async () => {
|
|
186
|
-
if (this.values[2])
|
|
211
|
+
if (this.values[2]) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
187
214
|
if (this.directSession) {
|
|
188
215
|
await this.directSession.drain().catch(() => {});
|
|
189
216
|
cleanup.unregister(this);
|
|
@@ -192,18 +219,32 @@ export class SoundRecorder {
|
|
|
192
219
|
const callbacks = this.recorderCallbacks();
|
|
193
220
|
const frames = unsigned(this.options?.blockFrames ?? 1024);
|
|
194
221
|
const mapping = await audioAsync<{
|
|
195
|
-
handle?: AudioHandle<'worker'>;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
222
|
+
handle?: AudioHandle<'worker'>;
|
|
223
|
+
token?: bigint;
|
|
224
|
+
}>(callback =>
|
|
225
|
+
audioNative.prepareAudioRecorder(
|
|
226
|
+
this[audioHandle],
|
|
227
|
+
sampleRate,
|
|
228
|
+
frames,
|
|
229
|
+
unsigned(this.options?.queueBlocks ?? 8),
|
|
230
|
+
callback,
|
|
231
|
+
!!callbacks,
|
|
232
|
+
),
|
|
233
|
+
);
|
|
199
234
|
if (callbacks && mapping.handle) {
|
|
200
|
-
const session = new AudioRecorderSession(
|
|
201
|
-
|
|
235
|
+
const session = new AudioRecorderSession(
|
|
236
|
+
this[audioHandle],
|
|
237
|
+
mapping.token!,
|
|
238
|
+
callbacks,
|
|
239
|
+
version !== this.stopVersion,
|
|
240
|
+
);
|
|
202
241
|
this.directSession = session;
|
|
203
242
|
cleanup.register(this, session, this);
|
|
204
243
|
try {
|
|
205
244
|
const ok = await session.ready;
|
|
206
|
-
if (!ok)
|
|
245
|
+
if (!ok) {
|
|
246
|
+
await session.drain();
|
|
247
|
+
}
|
|
207
248
|
return ok;
|
|
208
249
|
} catch (error) {
|
|
209
250
|
await session.drain();
|
|
@@ -212,20 +253,34 @@ export class SoundRecorder {
|
|
|
212
253
|
}
|
|
213
254
|
if (mapping.handle && this.options) {
|
|
214
255
|
const weak = new WeakRef(this);
|
|
215
|
-
this.session = new AudioWorkerSession(
|
|
216
|
-
|
|
217
|
-
|
|
256
|
+
this.session = new AudioWorkerSession(
|
|
257
|
+
mapping.handle,
|
|
258
|
+
mapping.token!,
|
|
259
|
+
'recorder',
|
|
260
|
+
this.options,
|
|
261
|
+
{
|
|
262
|
+
sampleRate,
|
|
263
|
+
channelCount: this.getChannelCount(),
|
|
264
|
+
blockFrames: frames,
|
|
265
|
+
},
|
|
266
|
+
() => {
|
|
218
267
|
const recorder = weak.deref();
|
|
219
|
-
if (recorder)
|
|
220
|
-
|
|
221
|
-
|
|
268
|
+
if (recorder) {
|
|
269
|
+
void recorder.stop().catch(() => {});
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
);
|
|
273
|
+
if (!(await this.session.ready)) {
|
|
222
274
|
await this.session.close();
|
|
223
275
|
return false;
|
|
224
276
|
}
|
|
225
277
|
}
|
|
226
278
|
const ok = await audioAsync<boolean>(callback =>
|
|
227
|
-
audioNative.startAudioRecorder(this[audioHandle], callback)
|
|
228
|
-
|
|
279
|
+
audioNative.startAudioRecorder(this[audioHandle], callback),
|
|
280
|
+
);
|
|
281
|
+
if (!ok) {
|
|
282
|
+
await this.session?.close();
|
|
283
|
+
}
|
|
229
284
|
return ok;
|
|
230
285
|
});
|
|
231
286
|
}
|
|
@@ -249,7 +304,9 @@ export class SoundRecorder {
|
|
|
249
304
|
stop(): Promise<void> {
|
|
250
305
|
++this.stopVersion;
|
|
251
306
|
const current = currentRecorderSession(this[audioHandle]);
|
|
252
|
-
if (current)
|
|
307
|
+
if (current) {
|
|
308
|
+
return current.requestStop();
|
|
309
|
+
}
|
|
253
310
|
// Cancel an onStart callback immediately, even while start owns the queue.
|
|
254
311
|
// @zh 即使 start 占用队列,也立即取消 onStart 回调。
|
|
255
312
|
// @ja start がキューを占有中でも、onStart コールバックを即座に取り消します。
|
|
@@ -260,9 +317,14 @@ export class SoundRecorder {
|
|
|
260
317
|
await this.directSession.stop();
|
|
261
318
|
return;
|
|
262
319
|
}
|
|
263
|
-
const buffer = await audioAsync<
|
|
264
|
-
|
|
265
|
-
|
|
320
|
+
const buffer = await audioAsync<
|
|
321
|
+
AudioHandle<'bufferData'> | undefined
|
|
322
|
+
>(callback =>
|
|
323
|
+
audioNative.stopAudioRecorder(this[audioHandle], callback),
|
|
324
|
+
);
|
|
325
|
+
if (buffer) {
|
|
326
|
+
this.onBuffer(buffer);
|
|
327
|
+
}
|
|
266
328
|
await this.session?.drain();
|
|
267
329
|
});
|
|
268
330
|
}
|
|
@@ -307,9 +369,13 @@ export class SoundRecorder {
|
|
|
307
369
|
* @ja 完成した Native 録音バッファーを受け取ります。
|
|
308
370
|
* @ko 완성된 Native 녹음 버퍼를 받습니다.
|
|
309
371
|
*/
|
|
310
|
-
protected onBuffer(buffer: AudioHandle<'bufferData'>): void {
|
|
372
|
+
protected onBuffer(buffer: AudioHandle<'bufferData'>): void {
|
|
373
|
+
void buffer;
|
|
374
|
+
}
|
|
311
375
|
private run<T>(action: () => Promise<T>): Promise<T> {
|
|
312
376
|
++this.pendingOperations;
|
|
313
|
-
return this.queue.run(action).finally(() => {
|
|
377
|
+
return this.queue.run(action).finally(() => {
|
|
378
|
+
--this.pendingOperations;
|
|
379
|
+
});
|
|
314
380
|
}
|
|
315
381
|
}
|