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.
Files changed (313) hide show
  1. package/README.ja.md +10 -9
  2. package/README.ko.md +10 -9
  3. package/README.md +10 -9
  4. package/README.zh-CN.md +10 -9
  5. package/binding.gyp +23 -16
  6. package/dist/audio/effect-processor.js +9 -3
  7. package/dist/audio/input-sound-file.js +41 -15
  8. package/dist/audio/listener.js +33 -11
  9. package/dist/audio/music.js +41 -18
  10. package/dist/audio/output-sound-file.js +4 -2
  11. package/dist/audio/playback-device.js +11 -3
  12. package/dist/audio/sound-buffer-recorder.js +8 -5
  13. package/dist/audio/sound-buffer.js +40 -17
  14. package/dist/audio/sound-file-factory.js +21 -9
  15. package/dist/audio/sound-file-reader.js +21 -7
  16. package/dist/audio/sound-recorder.js +36 -15
  17. package/dist/audio/sound-source.js +117 -40
  18. package/dist/audio/sound-stream.js +14 -5
  19. package/dist/audio/sound.js +9 -4
  20. package/dist/audio/value.js +42 -16
  21. package/dist/graphics/blend-mode.js +2 -1
  22. package/dist/graphics/boolean-vector.d.ts +1 -2
  23. package/dist/graphics/boolean-vector.js +19 -9
  24. package/dist/graphics/color.js +2 -1
  25. package/dist/graphics/convex-shape.js +7 -3
  26. package/dist/graphics/font.js +52 -23
  27. package/dist/graphics/glsl-matrix.js +8 -3
  28. package/dist/graphics/glsl.js +47 -16
  29. package/dist/graphics/glyph.js +27 -10
  30. package/dist/graphics/image.js +30 -14
  31. package/dist/graphics/rect.js +15 -8
  32. package/dist/graphics/render-states.js +18 -9
  33. package/dist/graphics/render-target.js +49 -23
  34. package/dist/graphics/render-texture.js +24 -12
  35. package/dist/graphics/render-window.js +6 -3
  36. package/dist/graphics/shader.js +67 -32
  37. package/dist/graphics/shape.js +25 -13
  38. package/dist/graphics/sprite.js +19 -9
  39. package/dist/graphics/stencil-mode.js +10 -6
  40. package/dist/graphics/swap.js +2 -1
  41. package/dist/graphics/text.js +123 -48
  42. package/dist/graphics/texture.js +48 -24
  43. package/dist/graphics/transform.js +29 -13
  44. package/dist/graphics/transformable.js +2 -1
  45. package/dist/graphics/vertex-array.js +40 -18
  46. package/dist/graphics/vertex-buffer.js +39 -19
  47. package/dist/graphics/vertex.js +6 -3
  48. package/dist/graphics/view.js +30 -14
  49. package/dist/index.d.ts +4 -4
  50. package/dist/internal/audio-codec-registry.js +12 -6
  51. package/dist/internal/audio-input-stream.js +2 -1
  52. package/dist/internal/audio-music-pump.js +58 -24
  53. package/dist/internal/audio-recorder-session.js +17 -7
  54. package/dist/internal/audio-worker-session.js +28 -10
  55. package/dist/internal/audio-worker.js +40 -21
  56. package/dist/internal/glsl-value.d.ts +3 -1
  57. package/dist/internal/glsl-value.js +18 -8
  58. package/dist/internal/graphics-state.js +29 -15
  59. package/dist/internal/input-stream.d.ts +3 -1
  60. package/dist/internal/input-stream.js +16 -7
  61. package/dist/internal/numeric-properties.js +2 -1
  62. package/dist/internal/render-states.js +2 -1
  63. package/dist/internal/scalar.js +22 -13
  64. package/dist/internal/shaped-glyph.d.ts +3 -1
  65. package/dist/internal/shaped-glyph.js +12 -4
  66. package/dist/internal/struct-view.d.ts +3 -1
  67. package/dist/internal/struct-view.js +3 -1
  68. package/dist/internal/transformable.js +2 -1
  69. package/dist/network/common.js +23 -11
  70. package/dist/network/dns.js +25 -17
  71. package/dist/network/ftp.js +43 -18
  72. package/dist/network/http.js +126 -56
  73. package/dist/network/ip-address.js +50 -25
  74. package/dist/network/packet.js +63 -25
  75. package/dist/network/sftp.js +175 -74
  76. package/dist/network/socket-selector.js +28 -14
  77. package/dist/network/socket.js +71 -30
  78. package/dist/network/tcp-listener.js +42 -19
  79. package/dist/network/tcp-socket.js +111 -53
  80. package/dist/network/tls-material.js +2 -1
  81. package/dist/network/udp-socket.js +68 -33
  82. package/dist/system/angle.js +2 -1
  83. package/dist/system/clock.js +4 -2
  84. package/dist/system/err.js +5 -2
  85. package/dist/system/file-input-stream.js +8 -4
  86. package/dist/system/input-stream.js +6 -3
  87. package/dist/system/operators.d.ts +1 -1
  88. package/dist/system/operators.js +90 -50
  89. package/dist/system/sleep.js +4 -2
  90. package/dist/system/time.js +12 -6
  91. package/dist/system/vector2.js +6 -7
  92. package/dist/system/vector3.js +11 -6
  93. package/dist/window/clipboard.js +2 -1
  94. package/dist/window/context.js +10 -5
  95. package/dist/window/cursor.js +2 -1
  96. package/dist/window/event.js +9 -5
  97. package/dist/window/mouse.js +4 -2
  98. package/dist/window/video-mode.js +2 -1
  99. package/dist/window/window.js +19 -12
  100. package/native/addon.cc +25 -12
  101. package/native/audio-binding.cc +266 -126
  102. package/native/audio-codec-binding.cc +147 -77
  103. package/native/audio-device-binding.cc +76 -49
  104. package/native/audio-file-binding.cc +116 -67
  105. package/native/audio-recorder-binding.cc +147 -98
  106. package/native/audio-recorder.h +1 -1
  107. package/native/audio-state.h +53 -30
  108. package/native/audio-stream-binding.cc +148 -94
  109. package/native/audio-stream.h +5 -4
  110. package/native/audio-worker-binding.cc +163 -81
  111. package/native/audio-worker.h +35 -19
  112. package/native/batch-drawable.cc +29 -16
  113. package/native/batch-drawable.h +11 -8
  114. package/native/context-binding.cc +40 -27
  115. package/native/context-settings.h +15 -8
  116. package/native/deferred-delete.cc +9 -6
  117. package/native/deferred-delete.h +7 -8
  118. package/native/error-stream-binding.cc +42 -28
  119. package/native/font-binding.cc +89 -48
  120. package/native/graphics-binding.cc +122 -72
  121. package/native/graphics-state.h +50 -36
  122. package/native/image-binding.cc +38 -24
  123. package/native/image-state.h +26 -18
  124. package/native/input-binding.cc +42 -27
  125. package/native/render-window-binding.cc +38 -23
  126. package/native/shader-binding.cc +115 -50
  127. package/native/shape-binding.cc +94 -49
  128. package/native/shape-state.h +18 -9
  129. package/native/shaped-glyph-storage.h +9 -5
  130. package/native/stream-binding.cc +143 -117
  131. package/native/system-binding.cc +17 -12
  132. package/native/text-binding.cc +68 -35
  133. package/native/text-state.h +25 -18
  134. package/native/texture-binding.cc +42 -33
  135. package/native/texture-resource.h +20 -12
  136. package/native/time-value.h +3 -1
  137. package/native/transformable-binding.cc +12 -6
  138. package/native/transformable-state.h +6 -6
  139. package/native/value-binding.h +46 -28
  140. package/native/value-layout.h +10 -10
  141. package/native/values-binding.cc +29 -23
  142. package/native/vertex-binding.cc +18 -12
  143. package/native/vertex-buffer-binding.cc +38 -24
  144. package/native/vertex-storage.h +2 -2
  145. package/native/view-data.h +4 -3
  146. package/native/window-binding.cc +75 -45
  147. package/native/window-event.h +20 -11
  148. package/native/window-owner.h +15 -12
  149. package/package.json +44 -51
  150. package/src/audio/effect-processor.ts +9 -3
  151. package/src/audio/input-sound-file.ts +108 -36
  152. package/src/audio/listener.ts +39 -13
  153. package/src/audio/music.ts +112 -47
  154. package/src/audio/output-sound-file.ts +40 -11
  155. package/src/audio/playback-device.ts +23 -8
  156. package/src/audio/sound-buffer-recorder.ts +35 -13
  157. package/src/audio/sound-buffer.ts +166 -58
  158. package/src/audio/sound-file-factory.ts +127 -49
  159. package/src/audio/sound-file-reader.ts +49 -15
  160. package/src/audio/sound-recorder.ts +100 -34
  161. package/src/audio/sound-source.ts +142 -45
  162. package/src/audio/sound-stream.ts +15 -5
  163. package/src/audio/sound.ts +12 -4
  164. package/src/audio/value.ts +89 -26
  165. package/src/graphics/blend-mode.ts +3 -1
  166. package/src/graphics/boolean-vector.ts +56 -26
  167. package/src/graphics/color.ts +3 -1
  168. package/src/graphics/convex-shape.ts +10 -3
  169. package/src/graphics/font.ts +171 -50
  170. package/src/graphics/glsl-matrix.ts +9 -3
  171. package/src/graphics/glsl.ts +81 -35
  172. package/src/graphics/glyph.ts +67 -26
  173. package/src/graphics/image.ts +119 -45
  174. package/src/graphics/rect.ts +56 -24
  175. package/src/graphics/render-states.ts +31 -14
  176. package/src/graphics/render-target.ts +197 -81
  177. package/src/graphics/render-texture.ts +36 -12
  178. package/src/graphics/render-window.ts +9 -3
  179. package/src/graphics/shader.ts +186 -61
  180. package/src/graphics/shape.ts +93 -35
  181. package/src/graphics/sprite.ts +64 -25
  182. package/src/graphics/stencil-mode.ts +12 -6
  183. package/src/graphics/swap.ts +3 -2
  184. package/src/graphics/text.ts +229 -74
  185. package/src/graphics/texture.ts +180 -61
  186. package/src/graphics/transform.ts +132 -47
  187. package/src/graphics/transformable.ts +3 -1
  188. package/src/graphics/vertex-array.ts +87 -35
  189. package/src/graphics/vertex-buffer.ts +97 -33
  190. package/src/graphics/vertex.ts +9 -3
  191. package/src/graphics/view.ts +59 -21
  192. package/src/index.ts +101 -23
  193. package/src/internal/audio-codec-registry.ts +18 -6
  194. package/src/internal/audio-input-stream.ts +6 -2
  195. package/src/internal/audio-music-pump.ts +116 -41
  196. package/src/internal/audio-native.ts +249 -96
  197. package/src/internal/audio-recorder-session.ts +68 -24
  198. package/src/internal/audio-worker-session.ts +65 -21
  199. package/src/internal/audio-worker.ts +85 -41
  200. package/src/internal/glsl-value.ts +26 -11
  201. package/src/internal/graphics-state.ts +57 -20
  202. package/src/internal/input-stream.ts +23 -10
  203. package/src/internal/native.ts +252 -99
  204. package/src/internal/numeric-properties.ts +2 -1
  205. package/src/internal/render-states.ts +3 -1
  206. package/src/internal/scalar.ts +33 -14
  207. package/src/internal/shaped-glyph.ts +25 -12
  208. package/src/internal/struct-view.ts +40 -13
  209. package/src/internal/transformable.ts +3 -1
  210. package/src/network/common.ts +35 -11
  211. package/src/network/dns.ts +95 -38
  212. package/src/network/ftp.ts +129 -47
  213. package/src/network/http.ts +232 -77
  214. package/src/network/ip-address.ts +118 -48
  215. package/src/network/packet.ts +161 -54
  216. package/src/network/sftp.ts +498 -168
  217. package/src/network/socket-selector.ts +66 -26
  218. package/src/network/socket.ts +133 -46
  219. package/src/network/tcp-listener.ts +78 -29
  220. package/src/network/tcp-socket.ts +240 -95
  221. package/src/network/tls-material.ts +6 -2
  222. package/src/network/udp-socket.ts +147 -53
  223. package/src/system/angle.ts +3 -1
  224. package/src/system/clock.ts +12 -4
  225. package/src/system/err.ts +5 -2
  226. package/src/system/file-input-stream.ts +12 -4
  227. package/src/system/input-stream.ts +9 -3
  228. package/src/system/operators.ts +290 -115
  229. package/src/system/sleep.ts +6 -2
  230. package/src/system/time.ts +18 -6
  231. package/src/system/timeout-with-predicate.ts +19 -8
  232. package/src/system/vector2.ts +101 -49
  233. package/src/system/vector3.ts +85 -36
  234. package/src/window/clipboard.ts +3 -1
  235. package/src/window/context.ts +15 -5
  236. package/src/window/cursor.ts +3 -1
  237. package/src/window/event.ts +26 -12
  238. package/src/window/mouse.ts +6 -2
  239. package/src/window/video-mode.ts +3 -1
  240. package/src/window/window.ts +119 -37
  241. package/test/native/audio-probes.cc +74 -36
  242. package/test/native/deferred-delete-probes.cc +17 -11
  243. package/test/native/drawable-probes.cc +70 -36
  244. package/test/native/exception-probes.cc +14 -9
  245. package/test/native/image-probes.cc +20 -10
  246. package/test/native/matrix-probes.cc +8 -4
  247. package/test/native/network-oracle.cc +17 -11
  248. package/test/native/render-texture-probes.cc +33 -24
  249. package/test/native/shader-probes.cc +9 -9
  250. package/test/native/shape-probes.cc +37 -23
  251. package/test/native/sprite-probes.cc +41 -25
  252. package/test/native/system-probes.cc +58 -35
  253. package/test/native/text-probes.cc +77 -44
  254. package/test/native/texture-probes.cc +43 -26
  255. package/test/native/time-probes.cc +18 -12
  256. package/test/native/transform-probes.cc +15 -10
  257. package/test/native/transformable-probes.cc +23 -17
  258. package/test/native/value-oracle.h +9 -4
  259. package/test/native/value-probes.cc +31 -23
  260. package/test/native/vertex-array-probes.cc +22 -14
  261. package/test/native/vertex-buffer-probes.cc +28 -17
  262. package/test/native/view-probes.cc +29 -17
  263. package/test/native/window-probes.cc +66 -33
  264. package/tools/ensure-sfml.cjs +9 -0
  265. package/tools/generate-network-constants.cjs +11 -6
  266. package/tools/generate-window-constants.cjs +31 -12
  267. package/docs/README.ja.md +0 -30
  268. package/docs/README.ko.md +0 -30
  269. package/docs/README.md +0 -30
  270. package/docs/README.zh-CN.md +0 -30
  271. package/docs/api.ja.md +0 -84
  272. package/docs/api.ko.md +0 -84
  273. package/docs/api.md +0 -81
  274. package/docs/api.zh-CN.md +0 -81
  275. package/docs/audio.ja.md +0 -249
  276. package/docs/audio.ko.md +0 -251
  277. package/docs/audio.md +0 -252
  278. package/docs/audio.zh-CN.md +0 -252
  279. package/docs/concepts.ja.md +0 -130
  280. package/docs/concepts.ko.md +0 -130
  281. package/docs/concepts.md +0 -131
  282. package/docs/concepts.zh-CN.md +0 -131
  283. package/docs/development.ja.md +0 -144
  284. package/docs/development.ko.md +0 -144
  285. package/docs/development.md +0 -146
  286. package/docs/development.zh-CN.md +0 -146
  287. package/docs/getting-started.ja.md +0 -154
  288. package/docs/getting-started.ko.md +0 -154
  289. package/docs/getting-started.md +0 -156
  290. package/docs/getting-started.zh-CN.md +0 -156
  291. package/docs/graphics.ja.md +0 -256
  292. package/docs/graphics.ko.md +0 -254
  293. package/docs/graphics.md +0 -255
  294. package/docs/graphics.zh-CN.md +0 -257
  295. package/docs/network.ja.md +0 -214
  296. package/docs/network.ko.md +0 -216
  297. package/docs/network.md +0 -218
  298. package/docs/network.zh-CN.md +0 -218
  299. package/docs/system.ja.md +0 -169
  300. package/docs/system.ko.md +0 -171
  301. package/docs/system.md +0 -173
  302. package/docs/system.zh-CN.md +0 -173
  303. package/docs/window.ja.md +0 -138
  304. package/docs/window.ko.md +0 -140
  305. package/docs/window.md +0 -141
  306. package/docs/window.zh-CN.md +0 -141
  307. package/native/exception-boundary.h +0 -97
  308. package/native/numeric-fields.h +0 -96
  309. package/native/shared-handle.h +0 -107
  310. package/test/tsconfig.json +0 -8
  311. package/tools/configure-lsp.cjs +0 -23
  312. package/tools/lib_downloader.cjs +0 -92
  313. package/tools/lib_downloader_urls.cjs +0 -23
@@ -1,8 +1,16 @@
1
1
  import {
2
- audioNative, audioHandle, type AudioHandle, type AudioReaderInfoMapping,
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 { channels, unsigned, type SoundChannel, type ChannelMap } from './value';
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(value?: SoundFileReaderInfoInput,
65
- mapping: AudioReaderInfoMapping = audioNative.createAudioReaderInfo()) {
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 { return this.count[0]; }
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 (typeof value !== 'bigint' || value < 0n || value > 0xffffffffffffffffn) {
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 { return this.channels[0]; }
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) { this.channels[0] = unsigned(value); }
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 { return this.rate[0]; }
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) { this.rate[0] = unsigned(value); }
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 { return this.map; }
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(audioNative.setAudioReaderChannels(
147
- this[audioHandle], channels(value)));
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(stream: InputStream): SoundFileReaderInfo | undefined |
176
- Promise<SoundFileReaderInfo | undefined>;
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, audioHandle, audioAsync, AudioQueue, type AudioHandle,
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, currentRecorderSession, type AudioRecorderCallbacks,
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 { return audioNative.audioCaptureDevices(2); }
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 { return this.values[0]; }
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 { return this.values[1]; }
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 { return this.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(new Error('Cannot change device inside a Recorder callback'));
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 = () => audioAsync<boolean>(callback =>
144
- audioNative.audioRecorderDevice(this[audioHandle], name, callback));
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(audioNative.audioRecorderChannels(
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(new Error('Cannot start Recorder inside its callback'));
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]) return false;
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'>; token?: bigint;
196
- }>(callback => audioNative.prepareAudioRecorder(this[audioHandle],
197
- sampleRate, frames, unsigned(this.options?.queueBlocks ?? 8), callback,
198
- !!callbacks));
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(this[audioHandle],
201
- mapping.token!, callbacks, version !== this.stopVersion);
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) await session.drain();
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(mapping.handle, mapping.token!,
216
- 'recorder', this.options, { sampleRate,
217
- channelCount: this.getChannelCount(), blockFrames: frames }, () => {
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) void recorder.stop().catch(() => {});
220
- });
221
- if (!await this.session.ready) {
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
- if (!ok) await this.session?.close();
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) return current.requestStop();
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<AudioHandle<'bufferData'> | undefined>(
264
- callback => audioNative.stopAudioRecorder(this[audioHandle], callback));
265
- if (buffer) this.onBuffer(buffer);
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 { void buffer; }
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(() => { --this.pendingOperations; });
377
+ return this.queue.run(action).finally(() => {
378
+ --this.pendingOperations;
379
+ });
314
380
  }
315
381
  }