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,23 +1,38 @@
1
1
  import {
2
- audioNative, audioHandle, audioAsync, AudioQueue, type AudioHandle,
2
+ audioNative,
3
+ audioHandle,
4
+ audioAsync,
5
+ AudioQueue,
6
+ type AudioHandle,
3
7
  type AudioBufferMapping,
4
8
  } from '../internal/audio-native';
5
9
  import { nativeStruct } from '../internal/struct-view';
6
10
  import { Time } from '../system/time';
7
11
  import type { InputStream } from '../system/input-stream';
8
12
  import { AudioInputStream } from '../internal/audio-input-stream';
9
- import { audioReaders, audioWriters } from '../internal/audio-codec-registry';
13
+ import {
14
+ audioReaders,
15
+ audioWriters,
16
+ } from '../internal/audio-codec-registry';
10
17
  import { InputSoundFile } from './input-sound-file';
11
18
  import { OutputSoundFile } from './output-sound-file';
12
19
  import {
13
- channels, unsigned, samples, type SoundChannel, type ReadonlySamples,
20
+ channels,
21
+ unsigned,
22
+ samples,
23
+ type SoundChannel,
24
+ type ReadonlySamples,
14
25
  type ChannelMap,
15
26
  } from './value';
16
27
 
17
28
  function view(mapping: AudioBufferMapping) {
18
29
  return nativeStruct<{
19
- sampleCount: bigint; sampleRate: number; channelCount: number;
20
- duration: bigint; samples: Int16Array; channelMap: Int32Array;
30
+ sampleCount: bigint;
31
+ sampleRate: number;
32
+ channelCount: number;
33
+ duration: bigint;
34
+ samples: Int16Array;
35
+ channelMap: Int32Array;
21
36
  }>(mapping.info, {
22
37
  samples: new Int16Array(mapping.samples),
23
38
  channelMap: new Int32Array(mapping.channelMap),
@@ -32,9 +47,19 @@ function view(mapping: AudioBufferMapping) {
32
47
  * @ko 오디오 버퍼의 읽기 전용 인터페이스입니다.
33
48
  * 샘플 뷰는 해당 네이티브 저장소를 유지합니다.
34
49
  */
35
- export type ReadonlySoundBuffer = Readonly<Pick<SoundBuffer,
36
- typeof audioHandle | 'getSamples' | 'getSampleCount' | 'getSampleRate' |
37
- 'getChannelCount' | 'getChannelMap' | 'getDuration' | 'saveToFile'>>;
50
+ export type ReadonlySoundBuffer = Readonly<
51
+ Pick<
52
+ SoundBuffer,
53
+ | typeof audioHandle
54
+ | 'getSamples'
55
+ | 'getSampleCount'
56
+ | 'getSampleRate'
57
+ | 'getChannelCount'
58
+ | 'getChannelMap'
59
+ | 'getDuration'
60
+ | 'saveToFile'
61
+ >
62
+ >;
38
63
 
39
64
  export const adoptAudioBuffer: unique symbol = Symbol('Audio.adoptBuffer');
40
65
 
@@ -65,15 +90,26 @@ export class SoundBuffer {
65
90
  * @ko 16비트 인터리브 PCM을 복사합니다. 샘플 레이트는 Hz 단위이며
66
91
  * channelMap은 각 채널 위치를 지정합니다.
67
92
  */
68
- constructor(samples: Int16Array, channelCount: number, sampleRate: number,
69
- channelMap: Iterable<SoundChannel>);
70
- constructor(source?: ReadonlySoundBuffer | Int16Array,
71
- channelCount?: number, sampleRate?: number,
72
- channelMap?: Iterable<SoundChannel>) {
93
+ constructor(
94
+ samples: Int16Array,
95
+ channelCount: number,
96
+ sampleRate: number,
97
+ channelMap: Iterable<SoundChannel>,
98
+ );
99
+ constructor(
100
+ source?: ReadonlySoundBuffer | Int16Array,
101
+ channelCount?: number,
102
+ sampleRate?: number,
103
+ channelMap?: Iterable<SoundChannel>,
104
+ ) {
73
105
  let mapping: AudioBufferMapping & { handle: AudioHandle<'buffer'> };
74
106
  if (source instanceof Int16Array) {
75
- mapping = audioNative.createAudioBuffer(source, unsigned(sampleRate!),
76
- unsigned(channelCount!), channels(channelMap!));
107
+ mapping = audioNative.createAudioBuffer(
108
+ source,
109
+ unsigned(sampleRate!),
110
+ unsigned(channelCount!),
111
+ channels(channelMap!),
112
+ );
77
113
  } else {
78
114
  if (source !== undefined && !(source instanceof SoundBuffer)) {
79
115
  throw new TypeError('Expected a SoundBuffer or Int16Array');
@@ -95,15 +131,20 @@ export class SoundBuffer {
95
131
  if (!(source instanceof SoundBuffer)) {
96
132
  throw new TypeError('Expected a SoundBuffer');
97
133
  }
98
- if (source === this) return this;
99
- this.state = view(audioNative.assignAudioBuffer(
100
- this[audioHandle], source[audioHandle]));
134
+ if (source === this) {
135
+ return this;
136
+ }
137
+ this.state = view(
138
+ audioNative.assignAudioBuffer(this[audioHandle], source[audioHandle]),
139
+ );
101
140
  return this;
102
141
  }
103
142
  /** @internal */
104
143
  static [adoptAudioBuffer](data: AudioHandle<'bufferData'>): SoundBuffer {
105
144
  const result = new SoundBuffer();
106
- result.state = view(audioNative.commitAudioBuffer(result[audioHandle], data));
145
+ result.state = view(
146
+ audioNative.commitAudioBuffer(result[audioHandle], data),
147
+ );
107
148
  return result;
108
149
  }
109
150
  /**
@@ -116,7 +157,9 @@ export class SoundBuffer {
116
157
  * 성공 여부를 반환합니다.
117
158
  */
118
159
  loadFromFile(filename: string): Promise<boolean> {
119
- return audioReaders.size ? this.loadDecoded(filename) : this.load(filename);
160
+ return audioReaders.size
161
+ ? this.loadDecoded(filename)
162
+ : this.load(filename);
120
163
  }
121
164
  /**
122
165
  * Asynchronously decode encoded audio bytes and replace the PCM,
@@ -140,7 +183,8 @@ export class SoundBuffer {
140
183
  * 스트림 오류는 Promise를 거부합니다.
141
184
  */
142
185
  loadFromStream(stream: InputStream): Promise<boolean> {
143
- return audioReaders.size ? this.loadDecoded(stream)
186
+ return audioReaders.size
187
+ ? this.loadDecoded(stream)
144
188
  : this.load(new AudioInputStream(stream));
145
189
  }
146
190
 
@@ -153,13 +197,25 @@ export class SoundBuffer {
153
197
  * @ko 16비트 인터리브 PCM을 동기적으로 복사하여 내용을 교체합니다.
154
198
  * sampleRate는 Hz 단위이며 성공 여부를 반환합니다.
155
199
  */
156
- loadFromSamples(data: Int16Array, channelCount: number, sampleRate: number,
157
- channelMap: Iterable<SoundChannel>): boolean {
200
+ loadFromSamples(
201
+ data: Int16Array,
202
+ channelCount: number,
203
+ sampleRate: number,
204
+ channelMap: Iterable<SoundChannel>,
205
+ ): boolean {
158
206
  samples(data);
159
- const result = audioNative.audioBufferSamples(data, unsigned(sampleRate),
160
- unsigned(channelCount), channels(channelMap));
161
- if (!result) return false;
162
- this.state = view(audioNative.commitAudioBuffer(this[audioHandle], result));
207
+ const result = audioNative.audioBufferSamples(
208
+ data,
209
+ unsigned(sampleRate),
210
+ unsigned(channelCount),
211
+ channels(channelMap),
212
+ );
213
+ if (!result) {
214
+ return false;
215
+ }
216
+ this.state = view(
217
+ audioNative.commitAudioBuffer(this[audioHandle], result),
218
+ );
163
219
  return true;
164
220
  }
165
221
  /**
@@ -181,35 +237,45 @@ export class SoundBuffer {
181
237
  * @ja 全チャンネルのサンプル総数を返します。
182
238
  * @ko 모든 채널의 샘플 총수를 반환합니다.
183
239
  */
184
- getSampleCount(): bigint { return this.state.sampleCount; }
240
+ getSampleCount(): bigint {
241
+ return this.state.sampleCount;
242
+ }
185
243
  /**
186
244
  * Return the sample rate per channel, in Hz.
187
245
  * @zh 返回每声道采样率,单位为 Hz。
188
246
  * @ja チャンネルごとのサンプルレートを Hz で返します。
189
247
  * @ko 채널별 샘플 레이트를 Hz 단위로 반환합니다.
190
248
  */
191
- getSampleRate(): number { return this.state.sampleRate; }
249
+ getSampleRate(): number {
250
+ return this.state.sampleRate;
251
+ }
192
252
  /**
193
253
  * Return the number of channels.
194
254
  * @zh 返回声道数量。
195
255
  * @ja チャンネル数を返します。
196
256
  * @ko 채널 수를 반환합니다.
197
257
  */
198
- getChannelCount(): number { return this.state.channelCount; }
258
+ getChannelCount(): number {
259
+ return this.state.channelCount;
260
+ }
199
261
  /**
200
262
  * Return a read-only view of channel positions in interleaved order.
201
263
  * @zh 返回交错声道位置顺序的只读视图。
202
264
  * @ja インターリーブ順のチャンネル位置の読み取り専用ビューを返します。
203
265
  * @ko 인터리브 순서의 채널 위치를 나타내는 읽기 전용 뷰를 반환합니다.
204
266
  */
205
- getChannelMap(): ChannelMap { return this.state.channelMap; }
267
+ getChannelMap(): ChannelMap {
268
+ return this.state.channelMap;
269
+ }
206
270
  /**
207
271
  * Return a copy of the total audio duration.
208
272
  * @zh 返回音频总时长副本。
209
273
  * @ja 音声全体の長さのコピーを返します。
210
274
  * @ko 오디오 전체 길이의 복사본을 반환합니다.
211
275
  */
212
- getDuration(): Time { return new Time(this.state.duration); }
276
+ getDuration(): Time {
277
+ return new Time(this.state.duration);
278
+ }
213
279
  /**
214
280
  * Asynchronously encode and save using the file extension to select the
215
281
  * format, returning whether it succeeded.
@@ -223,53 +289,95 @@ export class SoundBuffer {
223
289
  return this.queue.run(async () => {
224
290
  const output = new OutputSoundFile();
225
291
  try {
226
- const ok = await output.openFromFile(filename, this.getSampleRate(),
227
- this.getChannelCount(), this.getChannelMap());
228
- if (!ok) return false;
229
- if (this.state.samples.length) await output.write(this.state.samples);
292
+ const ok = await output.openFromFile(
293
+ filename,
294
+ this.getSampleRate(),
295
+ this.getChannelCount(),
296
+ this.getChannelMap(),
297
+ );
298
+ if (!ok) {
299
+ return false;
300
+ }
301
+ if (this.state.samples.length) {
302
+ await output.write(this.state.samples);
303
+ }
230
304
  return true;
231
- } finally { await output.close(); }
305
+ } finally {
306
+ await output.close();
307
+ }
232
308
  });
233
309
  }
234
- return this.queue.run(() => audioAsync(callback =>
235
- audioNative.saveAudioBuffer(this[audioHandle], filename, callback)));
310
+ return this.queue.run(() =>
311
+ audioAsync(callback =>
312
+ audioNative.saveAudioBuffer(this[audioHandle], filename, callback),
313
+ ),
314
+ );
236
315
  }
237
- private loadDecoded(input: string | Uint8Array | InputStream):
238
- Promise<boolean> {
316
+ private loadDecoded(
317
+ input: string | Uint8Array | InputStream,
318
+ ): Promise<boolean> {
239
319
  return this.queue.run(async () => {
240
320
  const file = new InputSoundFile();
241
321
  try {
242
- const ok = typeof input === 'string' ? await file.openFromFile(input)
243
- : input instanceof Uint8Array ? await file.openFromMemory(input)
244
- : await file.openFromStream(input);
245
- if (!ok) return false;
322
+ const ok =
323
+ typeof input === 'string'
324
+ ? await file.openFromFile(input)
325
+ : input instanceof Uint8Array
326
+ ? await file.openFromMemory(input)
327
+ : await file.openFromStream(input);
328
+ if (!ok) {
329
+ return false;
330
+ }
246
331
  const count = file.getSampleCount();
247
- if (count > 0xffffffffn) throw new RangeError('Sample buffer is too large');
332
+ if (count > 0xffffffffn) {
333
+ throw new RangeError('Sample buffer is too large');
334
+ }
248
335
  const data = new Int16Array(
249
- audioNative.allocateAudioSamples(Number(count)));
336
+ audioNative.allocateAudioSamples(Number(count)),
337
+ );
250
338
  let position = 0;
251
339
  while (position < data.length) {
252
340
  const read = Number(await file.read(data.subarray(position)));
253
- if (!read) return false;
341
+ if (!read) {
342
+ return false;
343
+ }
254
344
  position += read;
255
345
  }
256
- return this.loadFromSamples(data, file.getChannelCount(),
257
- file.getSampleRate(), file.getChannelMap());
258
- } finally { await file.close(); }
346
+ return this.loadFromSamples(
347
+ data,
348
+ file.getChannelCount(),
349
+ file.getSampleRate(),
350
+ file.getChannelMap(),
351
+ );
352
+ } finally {
353
+ await file.close();
354
+ }
259
355
  });
260
356
  }
261
- private load(input: string | Uint8Array | AudioInputStream): Promise<boolean> {
357
+ private load(
358
+ input: string | Uint8Array | AudioInputStream,
359
+ ): Promise<boolean> {
262
360
  return this.queue.run(async () => {
263
361
  const stream = input instanceof AudioInputStream ? input : undefined;
264
362
  try {
265
- const load = () => audioAsync<AudioHandle<'bufferData'> | undefined>(
266
- callback => audioNative.loadAudioBuffer(
267
- stream ? stream.handle : input as string | Uint8Array, callback));
363
+ const load = () =>
364
+ audioAsync<AudioHandle<'bufferData'> | undefined>(callback =>
365
+ audioNative.loadAudioBuffer(
366
+ stream ? stream.handle : (input as string | Uint8Array),
367
+ callback,
368
+ ),
369
+ );
268
370
  const data = await (stream ? stream.run(load) : load());
269
- if (!data) return false;
270
- this.state = view(audioNative.commitAudioBuffer(this[audioHandle], data));
371
+ if (!data) {
372
+ return false;
373
+ }
374
+ this.state = view(
375
+ audioNative.commitAudioBuffer(this[audioHandle], data),
376
+ );
271
377
  return true;
272
- } finally { stream?.close(); }
378
+ } finally {
379
+ stream?.close();
380
+ }
273
381
  });
274
382
  }
275
383
  }
@@ -1,52 +1,84 @@
1
1
  import {
2
- audioNative, audioAsync, AudioQueue, type AudioHandle,
2
+ audioNative,
3
+ audioAsync,
4
+ AudioQueue,
5
+ type AudioHandle,
3
6
  type AudioReaderInfoMapping,
4
7
  } from '../internal/audio-native';
5
8
  import { AudioInputStream } from '../internal/audio-input-stream';
6
9
  import {
7
- audioReaders, audioWriters, findAudioReaderInput, findAudioWriter,
10
+ audioReaders,
11
+ audioWriters,
12
+ findAudioReaderInput,
13
+ findAudioWriter,
8
14
  } from '../internal/audio-codec-registry';
9
- import { SoundFileReader, SoundFileReaderInfo,
10
- type SoundFileReaderConstructor } from './sound-file-reader';
11
- import { SoundFileWriter,
12
- type SoundFileWriterConstructor } from './sound-file-writer';
15
+ import {
16
+ SoundFileReader,
17
+ SoundFileReaderInfo,
18
+ type SoundFileReaderConstructor,
19
+ } from './sound-file-reader';
20
+ import {
21
+ SoundFileWriter,
22
+ type SoundFileWriterConstructor,
23
+ } from './sound-file-writer';
13
24
  import { channels, unsigned, samples, type SoundChannel } from './value';
14
25
  import type { InputStream } from '../system/input-stream';
15
26
 
16
27
  class NativeReader extends SoundFileReader {
17
28
  private readonly queue = new AudioQueue();
18
29
  private stream?: AudioInputStream;
19
- constructor(private readonly handle: AudioHandle<'reader'>) { super(); }
30
+ constructor(private readonly handle: AudioHandle<'reader'>) {
31
+ super();
32
+ }
20
33
  open(stream: InputStream): Promise<SoundFileReaderInfo | undefined> {
21
34
  return this.queue.run(async () => {
22
35
  const next = new AudioInputStream(stream);
23
36
  try {
24
- if (await stream.seek(0n) !== 0n) return undefined;
37
+ if ((await stream.seek(0n)) !== 0n) {
38
+ return undefined;
39
+ }
25
40
  const mapping = await next.run(() =>
26
41
  audioAsync<AudioReaderInfoMapping | undefined>(callback =>
27
- audioNative.openAudioReader(this.handle, next.handle, callback)));
28
- if (!mapping) return undefined;
42
+ audioNative.openAudioReader(this.handle, next.handle, callback),
43
+ ),
44
+ );
45
+ if (!mapping) {
46
+ return undefined;
47
+ }
29
48
  this.stream?.close();
30
49
  this.stream = next;
31
50
  return new SoundFileReaderInfo(undefined, mapping);
32
51
  } finally {
33
- if (this.stream !== next) next.close();
52
+ if (this.stream !== next) {
53
+ next.close();
54
+ }
34
55
  }
35
56
  });
36
57
  }
37
58
  read(data: Int16Array): Promise<bigint> {
38
59
  samples(data);
39
- return this.queue.run(() => this.run(() => audioAsync(callback =>
40
- audioNative.readAudioReader(this.handle, data, callback))));
60
+ return this.queue.run(() =>
61
+ this.run(() =>
62
+ audioAsync(callback =>
63
+ audioNative.readAudioReader(this.handle, data, callback),
64
+ ),
65
+ ),
66
+ );
41
67
  }
42
68
  seek(offset: bigint): Promise<void> {
43
- return this.queue.run(() => this.run(() => audioAsync(callback =>
44
- audioNative.seekAudioReader(this.handle, offset, callback))));
69
+ return this.queue.run(() =>
70
+ this.run(() =>
71
+ audioAsync(callback =>
72
+ audioNative.seekAudioReader(this.handle, offset, callback),
73
+ ),
74
+ ),
75
+ );
45
76
  }
46
77
  close(): Promise<void> {
47
78
  return this.queue.run(async () => {
48
79
  await audioAsync<void>(callback =>
49
- audioNative.closeAudioReader(this.handle, callback));
80
+ audioNative.closeAudioReader(this.handle, callback),
81
+ );
50
82
  this.stream?.close();
51
83
  this.stream = undefined;
52
84
  });
@@ -59,31 +91,48 @@ class NativeReader extends SoundFileReader {
59
91
  class NativeWriter extends SoundFileWriter {
60
92
  private readonly queue = new AudioQueue();
61
93
  private opened = false;
62
- constructor(private readonly handle: AudioHandle<'writer'>) { super(); }
63
- open(filename: string, rate: number, count: number,
64
- map: Iterable<SoundChannel>): Promise<boolean> {
94
+ constructor(private readonly handle: AudioHandle<'writer'>) {
95
+ super();
96
+ }
97
+ open(
98
+ filename: string,
99
+ rate: number,
100
+ count: number,
101
+ map: Iterable<SoundChannel>,
102
+ ): Promise<boolean> {
65
103
  const channelMap = channels(map);
66
104
  unsigned(rate);
67
105
  unsigned(count);
68
106
  return this.queue.run(async () => {
69
107
  this.opened = await audioAsync<boolean>(callback =>
70
- audioNative.openAudioWriter(this.handle, filename, rate, count,
71
- channelMap, callback));
108
+ audioNative.openAudioWriter(
109
+ this.handle,
110
+ filename,
111
+ rate,
112
+ count,
113
+ channelMap,
114
+ callback,
115
+ ),
116
+ );
72
117
  return this.opened;
73
118
  });
74
119
  }
75
120
  write(data: Int16Array): Promise<void> {
76
121
  samples(data);
77
122
  return this.queue.run(async () => {
78
- if (!this.opened) throw new Error('Writer is not open');
123
+ if (!this.opened) {
124
+ throw new Error('Writer is not open');
125
+ }
79
126
  await audioAsync<void>(callback =>
80
- audioNative.writeAudioWriter(this.handle, data, callback));
127
+ audioNative.writeAudioWriter(this.handle, data, callback),
128
+ );
81
129
  });
82
130
  }
83
131
  close(): Promise<void> {
84
132
  return this.queue.run(async () => {
85
133
  await audioAsync<void>(callback =>
86
- audioNative.closeAudioWriter(this.handle, callback));
134
+ audioNative.closeAudioWriter(this.handle, callback),
135
+ );
87
136
  this.opened = false;
88
137
  });
89
138
  }
@@ -106,10 +155,14 @@ export class SoundFileFactory {
106
155
  * 현재 Node 환경에 등록합니다.
107
156
  */
108
157
  static registerReader(reader: SoundFileReaderConstructor): void {
109
- if (typeof reader !== 'function' ||
110
- !(reader.prototype instanceof SoundFileReader) ||
111
- typeof reader.check !== 'function') {
112
- throw new TypeError('Expected a SoundFileReader class with static check()');
158
+ if (
159
+ typeof reader !== 'function' ||
160
+ !(reader.prototype instanceof SoundFileReader) ||
161
+ typeof reader.check !== 'function'
162
+ ) {
163
+ throw new TypeError(
164
+ 'Expected a SoundFileReader class with static check()',
165
+ );
113
166
  }
114
167
  audioReaders.add(reader);
115
168
  }
@@ -141,10 +194,14 @@ export class SoundFileFactory {
141
194
  * 현재 Node 환경에 등록합니다.
142
195
  */
143
196
  static registerWriter(writer: SoundFileWriterConstructor): void {
144
- if (typeof writer !== 'function' ||
145
- !(writer.prototype instanceof SoundFileWriter) ||
146
- typeof writer.check !== 'function') {
147
- throw new TypeError('Expected a SoundFileWriter class with static check()');
197
+ if (
198
+ typeof writer !== 'function' ||
199
+ !(writer.prototype instanceof SoundFileWriter) ||
200
+ typeof writer.check !== 'function'
201
+ ) {
202
+ throw new TypeError(
203
+ 'Expected a SoundFileWriter class with static check()',
204
+ );
148
205
  }
149
206
  audioWriters.add(writer);
150
207
  }
@@ -175,8 +232,11 @@ export class SoundFileFactory {
175
232
  * @ko 파일을 탐지하여 일치하는 디코더를 생성합니다.
176
233
  * 일치 항목이 없으면 undefined이며, 사용 전 open을 호출해야 합니다.
177
234
  */
178
- static createReaderFromFilename(filename: string):
179
- Promise<SoundFileReader | undefined> { return this.createReader(filename); }
235
+ static createReaderFromFilename(
236
+ filename: string,
237
+ ): Promise<SoundFileReader | undefined> {
238
+ return this.createReader(filename);
239
+ }
180
240
  /**
181
241
  * Probe encoded audio bytes and create a matching decoder, or return
182
242
  * undefined if none matches.
@@ -186,8 +246,11 @@ export class SoundFileFactory {
186
246
  * @ko 인코딩된 오디오 바이트를 탐지하여 일치하는 디코더를 생성합니다.
187
247
  * 일치 항목이 없으면 undefined를 반환합니다.
188
248
  */
189
- static createReaderFromMemory(data: Uint8Array):
190
- Promise<SoundFileReader | undefined> { return this.createReader(data); }
249
+ static createReaderFromMemory(
250
+ data: Uint8Array,
251
+ ): Promise<SoundFileReader | undefined> {
252
+ return this.createReader(data);
253
+ }
191
254
  /**
192
255
  * Probe stream contents and create a matching decoder, or return undefined
193
256
  * if none matches.
@@ -197,8 +260,11 @@ export class SoundFileFactory {
197
260
  * @ko 스트림 내용을 탐지하여 일치하는 디코더를 생성합니다.
198
261
  * 일치 항목이 없으면 undefined를 반환합니다.
199
262
  */
200
- static createReaderFromStream(stream: InputStream):
201
- Promise<SoundFileReader | undefined> { return this.createReader(stream); }
263
+ static createReaderFromStream(
264
+ stream: InputStream,
265
+ ): Promise<SoundFileReader | undefined> {
266
+ return this.createReader(stream);
267
+ }
202
268
  /**
203
269
  * Create an encoder by filename; return undefined if none matches.
204
270
  * Calling open is still required before writing.
@@ -208,28 +274,40 @@ export class SoundFileFactory {
208
274
  * @ko 파일명을 기준으로 인코더를 생성합니다. 일치 항목이 없으면 undefined이며,
209
275
  * 쓰기 전에 open을 호출해야 합니다.
210
276
  */
211
- static async createWriterFromFilename(filename: string):
212
- Promise<SoundFileWriter | undefined> {
277
+ static async createWriterFromFilename(
278
+ filename: string,
279
+ ): Promise<SoundFileWriter | undefined> {
213
280
  const custom = await findAudioWriter(filename);
214
- if (custom) return custom;
281
+ if (custom) {
282
+ return custom;
283
+ }
215
284
  const handle = audioNative.createAudioWriter(filename);
216
285
  return handle ? new NativeWriter(handle) : undefined;
217
286
  }
218
- private static async createReader(input: string | Uint8Array | InputStream):
219
- Promise<SoundFileReader | undefined> {
287
+ private static async createReader(
288
+ input: string | Uint8Array | InputStream,
289
+ ): Promise<SoundFileReader | undefined> {
220
290
  const custom = await findAudioReaderInput(input);
221
291
  if (custom) {
222
292
  await custom.owned?.close();
223
293
  return custom.reader;
224
294
  }
225
- const bridge = typeof input === 'string' || input instanceof Uint8Array
226
- ? undefined : new AudioInputStream(input);
295
+ const bridge =
296
+ typeof input === 'string' || input instanceof Uint8Array
297
+ ? undefined
298
+ : new AudioInputStream(input);
227
299
  try {
228
- const create = () => audioAsync<AudioHandle<'reader'> | undefined>(
229
- callback => audioNative.createAudioReader(
230
- bridge ? bridge.handle : input as string | Uint8Array, callback));
300
+ const create = () =>
301
+ audioAsync<AudioHandle<'reader'> | undefined>(callback =>
302
+ audioNative.createAudioReader(
303
+ bridge ? bridge.handle : (input as string | Uint8Array),
304
+ callback,
305
+ ),
306
+ );
231
307
  const handle = await (bridge ? bridge.run(create) : create());
232
308
  return handle ? new NativeReader(handle) : undefined;
233
- } finally { bridge?.close(); }
309
+ } finally {
310
+ bridge?.close();
311
+ }
234
312
  }
235
313
  }